Search in sources :

Example 26 with IIOException

use of javax.imageio.IIOException in project jdk8u_jdk by JetBrains.

the class GIFImageWriteParam method writeGraphicControlExtension.

private void writeGraphicControlExtension(int disposalMethod, boolean userInputFlag, boolean transparentColorFlag, int delayTime, int transparentColorIndex) throws IOException {
    try {
        stream.write(0x21);
        stream.write(0xf9);
        stream.write(4);
        int packedFields = (disposalMethod & 0x3) << 2;
        if (userInputFlag) {
            packedFields |= 0x2;
        }
        if (transparentColorFlag) {
            packedFields |= 0x1;
        }
        stream.write(packedFields);
        stream.writeShort((short) delayTime);
        stream.write(transparentColorIndex);
        stream.write(0x00);
    } catch (IOException e) {
        throw new IIOException("I/O error writing Graphic Control Extension!", e);
    }
}
Also used : IIOException(javax.imageio.IIOException) IIOException(javax.imageio.IIOException) IOException(java.io.IOException)

Example 27 with IIOException

use of javax.imageio.IIOException in project jdk8u_jdk by JetBrains.

the class GIFImageWriteParam method writePlainTextExtension.

private void writePlainTextExtension(GIFWritableImageMetadata im) throws IOException {
    if (im.hasPlainTextExtension) {
        try {
            stream.write(0x21);
            stream.write(0x1);
            stream.write(12);
            stream.writeShort(im.textGridLeft);
            stream.writeShort(im.textGridTop);
            stream.writeShort(im.textGridWidth);
            stream.writeShort(im.textGridHeight);
            stream.write(im.characterCellWidth);
            stream.write(im.characterCellHeight);
            stream.write(im.textForegroundColor);
            stream.write(im.textBackgroundColor);
            writeBlocks(im.text);
            stream.write(0x00);
        } catch (IOException e) {
            throw new IIOException("I/O error writing Plain Text Extension!", e);
        }
    }
}
Also used : IIOException(javax.imageio.IIOException) IIOException(javax.imageio.IIOException) IOException(java.io.IOException)

Example 28 with IIOException

use of javax.imageio.IIOException in project jdk8u_jdk by JetBrains.

the class GIFImageWriteParam method writeHeader.

private void writeHeader(String version, int logicalScreenWidth, int logicalScreenHeight, int colorResolution, int pixelAspectRatio, int backgroundColorIndex, boolean sortFlag, int bitsPerPixel, byte[] globalColorTable) throws IOException {
    try {
        // Signature
        stream.writeBytes("GIF" + version);
        // Screen Descriptor
        // Width
        stream.writeShort((short) logicalScreenWidth);
        // Height
        stream.writeShort((short) logicalScreenHeight);
        // Global Color Table
        // Packed fields
        int packedFields = globalColorTable != null ? 0x80 : 0x00;
        packedFields |= ((colorResolution - 1) & 0x7) << 4;
        if (sortFlag) {
            packedFields |= 0x8;
        }
        packedFields |= (bitsPerPixel - 1);
        stream.write(packedFields);
        // Background color index
        stream.write(backgroundColorIndex);
        // Pixel aspect ratio
        stream.write(pixelAspectRatio);
        // Global Color Table
        if (globalColorTable != null) {
            stream.write(globalColorTable);
        }
    } catch (IOException e) {
        throw new IIOException("I/O error writing header!", e);
    }
}
Also used : IIOException(javax.imageio.IIOException) IIOException(javax.imageio.IIOException) IOException(java.io.IOException)

Example 29 with IIOException

use of javax.imageio.IIOException in project jdk8u_jdk by JetBrains.

the class GIFImageWriteParam method writeApplicationExtension.

private void writeApplicationExtension(GIFWritableImageMetadata im) throws IOException {
    if (im.applicationIDs != null) {
        Iterator iterIDs = im.applicationIDs.iterator();
        Iterator iterCodes = im.authenticationCodes.iterator();
        Iterator iterData = im.applicationData.iterator();
        while (iterIDs.hasNext()) {
            try {
                stream.write(0x21);
                stream.write(0xff);
                stream.write(11);
                stream.write((byte[]) iterIDs.next(), 0, 8);
                stream.write((byte[]) iterCodes.next(), 0, 3);
                writeBlocks((byte[]) iterData.next());
                stream.write(0x00);
            } catch (IOException e) {
                throw new IIOException("I/O error writing Application Extension!", e);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) IIOException(javax.imageio.IIOException) IIOException(javax.imageio.IIOException) IOException(java.io.IOException)

Example 30 with IIOException

use of javax.imageio.IIOException in project jdk8u_jdk by JetBrains.

the class GIFImageReader method locateImage.

private int locateImage(int imageIndex) throws IIOException {
    readHeader();
    try {
        // Find closest known index
        int index = Math.min(imageIndex, imageStartPosition.size() - 1);
        // Seek to that position
        Long l = (Long) imageStartPosition.get(index);
        stream.seek(l.longValue());
        // Skip images until at desired index or last image found
        while (index < imageIndex) {
            if (!skipImage()) {
                --index;
                return index;
            }
            Long l1 = new Long(stream.getStreamPosition());
            imageStartPosition.add(l1);
            ++index;
        }
    } catch (IOException e) {
        throw new IIOException("Couldn't seek!", e);
    }
    if (currIndex != imageIndex) {
        imageMetadata = null;
    }
    currIndex = imageIndex;
    return imageIndex;
}
Also used : IIOException(javax.imageio.IIOException) IOException(java.io.IOException) IIOException(javax.imageio.IIOException) Point(java.awt.Point)

Aggregations

IIOException (javax.imageio.IIOException)60 Point (java.awt.Point)23 IOException (java.io.IOException)23 BufferedImage (java.awt.image.BufferedImage)12 Rectangle (java.awt.Rectangle)11 IndexColorModel (java.awt.image.IndexColorModel)7 SampleModel (java.awt.image.SampleModel)7 WritableRaster (java.awt.image.WritableRaster)7 Iterator (java.util.Iterator)7 ColorModel (java.awt.image.ColorModel)6 ArrayList (java.util.ArrayList)6 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)6 ImageInputStream (javax.imageio.stream.ImageInputStream)6 TIFFField (it.geosolutions.imageio.plugins.tiff.TIFFField)5 ColorSpace (java.awt.color.ColorSpace)5 ComponentSampleModel (java.awt.image.ComponentSampleModel)5 DataBufferByte (java.awt.image.DataBufferByte)5 ImageReader (javax.imageio.ImageReader)5 IIOMetadata (javax.imageio.metadata.IIOMetadata)5 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)4