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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
}
}
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;
}
Aggregations