Java Code Examples for javax.imageio.ImageWriteParam#canWriteProgressive()
The following examples show how to use
javax.imageio.ImageWriteParam#canWriteProgressive() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GIFImageWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 2
Source File: GIFImageWriter.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 3
Source File: GIFImageWriter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 4
Source File: GIFImageWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != ImageWriteParam.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 5
Source File: GIFImageWriter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 6
Source File: GIFImageWriter.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != ImageWriteParam.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 7
Source File: GIFImageWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 8
Source File: GIFImageWriter.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 9
Source File: GIFImageWriter.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 10
Source File: GIFImageWriter.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 11
Source File: GIFImageWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example 12
Source File: GIFImageWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Writes any extension blocks, the Image Descriptor, and the image data * * @param iioimage The image and image metadata. * @param param The write parameters. * @param globalColorTable The Global Color Table. * @param sourceBounds The source region. * @param destSize The destination dimensions. */ private void writeImage(RenderedImage image, GIFWritableImageMetadata imageMetadata, ImageWriteParam param, byte[] globalColorTable, Rectangle sourceBounds, Dimension destSize) throws IOException { ColorModel colorModel = image.getColorModel(); SampleModel sampleModel = image.getSampleModel(); boolean writeGraphicsControlExtension; if (imageMetadata == null) { // Create default metadata. imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata( new ImageTypeSpecifier(image), param); // Set GraphicControlExtension flag only if there is // transparency. writeGraphicsControlExtension = imageMetadata.transparentColorFlag; } else { // Check for GraphicControlExtension element. NodeList list = null; try { IIOMetadataNode root = (IIOMetadataNode) imageMetadata.getAsTree(IMAGE_METADATA_NAME); list = root.getElementsByTagName("GraphicControlExtension"); } catch(IllegalArgumentException iae) { // Should never happen. } // Set GraphicControlExtension flag if element present. writeGraphicsControlExtension = list != null && list.getLength() > 0; // If progressive mode is not MODE_COPY_FROM_METADATA, ensure // the interlacing is set per the ImageWriteParam mode setting. if (param != null && param.canWriteProgressive()) { if (param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) { imageMetadata.interlaceFlag = false; } else if (param.getProgressiveMode() == ImageWriteParam.MODE_DEFAULT) { imageMetadata.interlaceFlag = true; } } } // Unset local color table if equal to global color table. if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) { imageMetadata.localColorTable = null; } // Override dimensions imageMetadata.imageWidth = destSize.width; imageMetadata.imageHeight = destSize.height; // Write Graphics Control Extension. if (writeGraphicsControlExtension) { writeGraphicControlExtension(imageMetadata); } // Write extension blocks. writePlainTextExtension(imageMetadata); writeApplicationExtension(imageMetadata); writeCommentExtension(imageMetadata); // Write Image Descriptor int bitsPerPixel = getNumBits(imageMetadata.localColorTable == null ? (globalColorTable == null ? sampleModel.getSampleSize(0) : globalColorTable.length/3) : imageMetadata.localColorTable.length/3); writeImageDescriptor(imageMetadata, bitsPerPixel); // Write image data writeRasterData(image, sourceBounds, destSize, param, imageMetadata.interlaceFlag); }
Example 13
Source File: GIFImageWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType, ImageWriteParam param) { GIFWritableImageMetadata imageMetadata = new GIFWritableImageMetadata(); // Image dimensions SampleModel sampleModel = imageType.getSampleModel(); Rectangle sourceBounds = new Rectangle(sampleModel.getWidth(), sampleModel.getHeight()); Dimension destSize = new Dimension(); computeRegions(sourceBounds, destSize, param); imageMetadata.imageWidth = destSize.width; imageMetadata.imageHeight = destSize.height; // Interlacing if (param != null && param.canWriteProgressive() && param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) { imageMetadata.interlaceFlag = false; } else { imageMetadata.interlaceFlag = true; } // Local color table ColorModel colorModel = imageType.getColorModel(); imageMetadata.localColorTable = createColorTable(colorModel, sampleModel); // Transparency if (colorModel instanceof IndexColorModel) { int transparentIndex = ((IndexColorModel)colorModel).getTransparentPixel(); if (transparentIndex != -1) { imageMetadata.transparentColorFlag = true; imageMetadata.transparentColorIndex = transparentIndex; } } return imageMetadata; }
Example 14
Source File: GIFImageWriter.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Writes any extension blocks, the Image Descriptor, and the image data * * @param iioimage The image and image metadata. * @param param The write parameters. * @param globalColorTable The Global Color Table. * @param sourceBounds The source region. * @param destSize The destination dimensions. */ private void writeImage(RenderedImage image, GIFWritableImageMetadata imageMetadata, ImageWriteParam param, byte[] globalColorTable, Rectangle sourceBounds, Dimension destSize) throws IOException { ColorModel colorModel = image.getColorModel(); SampleModel sampleModel = image.getSampleModel(); boolean writeGraphicsControlExtension; if (imageMetadata == null) { // Create default metadata. imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata( new ImageTypeSpecifier(image), param); // Set GraphicControlExtension flag only if there is // transparency. writeGraphicsControlExtension = imageMetadata.transparentColorFlag; } else { // Check for GraphicControlExtension element. NodeList list = null; try { IIOMetadataNode root = (IIOMetadataNode) imageMetadata.getAsTree(IMAGE_METADATA_NAME); list = root.getElementsByTagName("GraphicControlExtension"); } catch(IllegalArgumentException iae) { // Should never happen. } // Set GraphicControlExtension flag if element present. writeGraphicsControlExtension = list != null && list.getLength() > 0; // If progressive mode is not MODE_COPY_FROM_METADATA, ensure // the interlacing is set per the ImageWriteParam mode setting. if (param != null && param.canWriteProgressive()) { if (param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) { imageMetadata.interlaceFlag = false; } else if (param.getProgressiveMode() == ImageWriteParam.MODE_DEFAULT) { imageMetadata.interlaceFlag = true; } } } // Unset local color table if equal to global color table. if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) { imageMetadata.localColorTable = null; } // Override dimensions imageMetadata.imageWidth = destSize.width; imageMetadata.imageHeight = destSize.height; // Write Graphics Control Extension. if (writeGraphicsControlExtension) { writeGraphicControlExtension(imageMetadata); } // Write extension blocks. writePlainTextExtension(imageMetadata); writeApplicationExtension(imageMetadata); writeCommentExtension(imageMetadata); // Write Image Descriptor int bitsPerPixel = getNumBits(imageMetadata.localColorTable == null ? (globalColorTable == null ? sampleModel.getSampleSize(0) : globalColorTable.length/3) : imageMetadata.localColorTable.length/3); writeImageDescriptor(imageMetadata, bitsPerPixel); // Write image data writeRasterData(image, sourceBounds, destSize, param, imageMetadata.interlaceFlag); }
Example 15
Source File: GIFImageWriter.java From hottub with GNU General Public License v2.0 | 4 votes |
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType, ImageWriteParam param) { GIFWritableImageMetadata imageMetadata = new GIFWritableImageMetadata(); // Image dimensions SampleModel sampleModel = imageType.getSampleModel(); Rectangle sourceBounds = new Rectangle(sampleModel.getWidth(), sampleModel.getHeight()); Dimension destSize = new Dimension(); computeRegions(sourceBounds, destSize, param); imageMetadata.imageWidth = destSize.width; imageMetadata.imageHeight = destSize.height; // Interlacing if (param != null && param.canWriteProgressive() && param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) { imageMetadata.interlaceFlag = false; } else { imageMetadata.interlaceFlag = true; } // Local color table ColorModel colorModel = imageType.getColorModel(); imageMetadata.localColorTable = createColorTable(colorModel, sampleModel); // Transparency if (colorModel instanceof IndexColorModel) { int transparentIndex = ((IndexColorModel)colorModel).getTransparentPixel(); if (transparentIndex != -1) { imageMetadata.transparentColorFlag = true; imageMetadata.transparentColorIndex = transparentIndex; } } return imageMetadata; }
Example 16
Source File: GIFImageWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Writes any extension blocks, the Image Descriptor, and the image data * * @param iioimage The image and image metadata. * @param param The write parameters. * @param globalColorTable The Global Color Table. * @param sourceBounds The source region. * @param destSize The destination dimensions. */ private void writeImage(RenderedImage image, GIFWritableImageMetadata imageMetadata, ImageWriteParam param, byte[] globalColorTable, Rectangle sourceBounds, Dimension destSize) throws IOException { ColorModel colorModel = image.getColorModel(); SampleModel sampleModel = image.getSampleModel(); boolean writeGraphicsControlExtension; if (imageMetadata == null) { // Create default metadata. imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata( new ImageTypeSpecifier(image), param); // Set GraphicControlExtension flag only if there is // transparency. writeGraphicsControlExtension = imageMetadata.transparentColorFlag; } else { // Check for GraphicControlExtension element. NodeList list = null; try { IIOMetadataNode root = (IIOMetadataNode) imageMetadata.getAsTree(IMAGE_METADATA_NAME); list = root.getElementsByTagName("GraphicControlExtension"); } catch(IllegalArgumentException iae) { // Should never happen. } // Set GraphicControlExtension flag if element present. writeGraphicsControlExtension = list != null && list.getLength() > 0; // If progressive mode is not MODE_COPY_FROM_METADATA, ensure // the interlacing is set per the ImageWriteParam mode setting. if (param != null && param.canWriteProgressive()) { if (param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) { imageMetadata.interlaceFlag = false; } else if (param.getProgressiveMode() == ImageWriteParam.MODE_DEFAULT) { imageMetadata.interlaceFlag = true; } } } // Unset local color table if equal to global color table. if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) { imageMetadata.localColorTable = null; } // Override dimensions imageMetadata.imageWidth = destSize.width; imageMetadata.imageHeight = destSize.height; // Write Graphics Control Extension. if (writeGraphicsControlExtension) { writeGraphicControlExtension(imageMetadata); } // Write extension blocks. writePlainTextExtension(imageMetadata); writeApplicationExtension(imageMetadata); writeCommentExtension(imageMetadata); // Write Image Descriptor int bitsPerPixel = getNumBits(imageMetadata.localColorTable == null ? (globalColorTable == null ? sampleModel.getSampleSize(0) : globalColorTable.length/3) : imageMetadata.localColorTable.length/3); writeImageDescriptor(imageMetadata, bitsPerPixel); // Write image data writeRasterData(image, sourceBounds, destSize, param, imageMetadata.interlaceFlag); }
Example 17
Source File: GIFImageWriter.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Writes any extension blocks, the Image Descriptor, and the image data * * @param iioimage The image and image metadata. * @param param The write parameters. * @param globalColorTable The Global Color Table. * @param sourceBounds The source region. * @param destSize The destination dimensions. */ private void writeImage(RenderedImage image, GIFWritableImageMetadata imageMetadata, ImageWriteParam param, byte[] globalColorTable, Rectangle sourceBounds, Dimension destSize) throws IOException { ColorModel colorModel = image.getColorModel(); SampleModel sampleModel = image.getSampleModel(); boolean writeGraphicsControlExtension; if (imageMetadata == null) { // Create default metadata. imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata( new ImageTypeSpecifier(image), param); // Set GraphicControlExtension flag only if there is // transparency. writeGraphicsControlExtension = imageMetadata.transparentColorFlag; } else { // Check for GraphicControlExtension element. NodeList list = null; try { IIOMetadataNode root = (IIOMetadataNode) imageMetadata.getAsTree(IMAGE_METADATA_NAME); list = root.getElementsByTagName("GraphicControlExtension"); } catch(IllegalArgumentException iae) { // Should never happen. } // Set GraphicControlExtension flag if element present. writeGraphicsControlExtension = list != null && list.getLength() > 0; // If progressive mode is not MODE_COPY_FROM_METADATA, ensure // the interlacing is set per the ImageWriteParam mode setting. if (param != null && param.canWriteProgressive()) { if (param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) { imageMetadata.interlaceFlag = false; } else if (param.getProgressiveMode() == ImageWriteParam.MODE_DEFAULT) { imageMetadata.interlaceFlag = true; } } } // Unset local color table if equal to global color table. if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) { imageMetadata.localColorTable = null; } // Override dimensions imageMetadata.imageWidth = destSize.width; imageMetadata.imageHeight = destSize.height; // Write Graphics Control Extension. if (writeGraphicsControlExtension) { writeGraphicControlExtension(imageMetadata); } // Write extension blocks. writePlainTextExtension(imageMetadata); writeApplicationExtension(imageMetadata); writeCommentExtension(imageMetadata); // Write Image Descriptor int bitsPerPixel = getNumBits(imageMetadata.localColorTable == null ? (globalColorTable == null ? sampleModel.getSampleSize(0) : globalColorTable.length/3) : imageMetadata.localColorTable.length/3); writeImageDescriptor(imageMetadata, bitsPerPixel); // Write image data writeRasterData(image, sourceBounds, destSize, param, imageMetadata.interlaceFlag); }
Example 18
Source File: GIFImageWriter.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType, ImageWriteParam param) { GIFWritableImageMetadata imageMetadata = new GIFWritableImageMetadata(); // Image dimensions SampleModel sampleModel = imageType.getSampleModel(); Rectangle sourceBounds = new Rectangle(sampleModel.getWidth(), sampleModel.getHeight()); Dimension destSize = new Dimension(); computeRegions(sourceBounds, destSize, param); imageMetadata.imageWidth = destSize.width; imageMetadata.imageHeight = destSize.height; // Interlacing if (param != null && param.canWriteProgressive() && param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) { imageMetadata.interlaceFlag = false; } else { imageMetadata.interlaceFlag = true; } // Local color table ColorModel colorModel = imageType.getColorModel(); imageMetadata.localColorTable = createColorTable(colorModel, sampleModel); // Transparency if (colorModel instanceof IndexColorModel) { int transparentIndex = ((IndexColorModel)colorModel).getTransparentPixel(); if (transparentIndex != -1) { imageMetadata.transparentColorFlag = true; imageMetadata.transparentColorIndex = transparentIndex; } } return imageMetadata; }
Example 19
Source File: GIFImageWriter.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * Writes any extension blocks, the Image Descriptor, and the image data * * @param iioimage The image and image metadata. * @param param The write parameters. * @param globalColorTable The Global Color Table. * @param sourceBounds The source region. * @param destSize The destination dimensions. */ private void writeImage(RenderedImage image, GIFWritableImageMetadata imageMetadata, ImageWriteParam param, byte[] globalColorTable, Rectangle sourceBounds, Dimension destSize) throws IOException { ColorModel colorModel = image.getColorModel(); SampleModel sampleModel = image.getSampleModel(); boolean writeGraphicsControlExtension; if (imageMetadata == null) { // Create default metadata. imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata( new ImageTypeSpecifier(image), param); // Set GraphicControlExtension flag only if there is // transparency. writeGraphicsControlExtension = imageMetadata.transparentColorFlag; } else { // Check for GraphicControlExtension element. NodeList list = null; try { IIOMetadataNode root = (IIOMetadataNode) imageMetadata.getAsTree(IMAGE_METADATA_NAME); list = root.getElementsByTagName("GraphicControlExtension"); } catch(IllegalArgumentException iae) { // Should never happen. } // Set GraphicControlExtension flag if element present. writeGraphicsControlExtension = list != null && list.getLength() > 0; // If progressive mode is not MODE_COPY_FROM_METADATA, ensure // the interlacing is set per the ImageWriteParam mode setting. if (param != null && param.canWriteProgressive()) { if (param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) { imageMetadata.interlaceFlag = false; } else if (param.getProgressiveMode() == ImageWriteParam.MODE_DEFAULT) { imageMetadata.interlaceFlag = true; } } } // Unset local color table if equal to global color table. if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) { imageMetadata.localColorTable = null; } // Override dimensions imageMetadata.imageWidth = destSize.width; imageMetadata.imageHeight = destSize.height; // Write Graphics Control Extension. if (writeGraphicsControlExtension) { writeGraphicControlExtension(imageMetadata); } // Write extension blocks. writePlainTextExtension(imageMetadata); writeApplicationExtension(imageMetadata); writeCommentExtension(imageMetadata); // Write Image Descriptor int bitsPerPixel = getNumBits(imageMetadata.localColorTable == null ? (globalColorTable == null ? sampleModel.getSampleSize(0) : globalColorTable.length/3) : imageMetadata.localColorTable.length/3); writeImageDescriptor(imageMetadata, bitsPerPixel); // Write image data writeRasterData(image, sourceBounds, destSize, param, imageMetadata.interlaceFlag); }
Example 20
Source File: GIFImageWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Writes any extension blocks, the Image Descriptor, and the image data * * @param iioimage The image and image metadata. * @param param The write parameters. * @param globalColorTable The Global Color Table. * @param sourceBounds The source region. * @param destSize The destination dimensions. */ private void writeImage(RenderedImage image, GIFWritableImageMetadata imageMetadata, ImageWriteParam param, byte[] globalColorTable, Rectangle sourceBounds, Dimension destSize) throws IOException { ColorModel colorModel = image.getColorModel(); SampleModel sampleModel = image.getSampleModel(); boolean writeGraphicsControlExtension; if (imageMetadata == null) { // Create default metadata. imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata( new ImageTypeSpecifier(image), param); // Set GraphicControlExtension flag only if there is // transparency. writeGraphicsControlExtension = imageMetadata.transparentColorFlag; } else { // Check for GraphicControlExtension element. NodeList list = null; try { IIOMetadataNode root = (IIOMetadataNode) imageMetadata.getAsTree(IMAGE_METADATA_NAME); list = root.getElementsByTagName("GraphicControlExtension"); } catch(IllegalArgumentException iae) { // Should never happen. } // Set GraphicControlExtension flag if element present. writeGraphicsControlExtension = list != null && list.getLength() > 0; // If progressive mode is not MODE_COPY_FROM_METADATA, ensure // the interlacing is set per the ImageWriteParam mode setting. if (param != null && param.canWriteProgressive()) { if (param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) { imageMetadata.interlaceFlag = false; } else if (param.getProgressiveMode() == ImageWriteParam.MODE_DEFAULT) { imageMetadata.interlaceFlag = true; } } } // Unset local color table if equal to global color table. if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) { imageMetadata.localColorTable = null; } // Override dimensions imageMetadata.imageWidth = destSize.width; imageMetadata.imageHeight = destSize.height; // Write Graphics Control Extension. if (writeGraphicsControlExtension) { writeGraphicControlExtension(imageMetadata); } // Write extension blocks. writePlainTextExtension(imageMetadata); writeApplicationExtension(imageMetadata); writeCommentExtension(imageMetadata); // Write Image Descriptor int bitsPerPixel = getNumBits(imageMetadata.localColorTable == null ? (globalColorTable == null ? sampleModel.getSampleSize(0) : globalColorTable.length/3) : imageMetadata.localColorTable.length/3); writeImageDescriptor(imageMetadata, bitsPerPixel); // Write image data writeRasterData(image, sourceBounds, destSize, param, imageMetadata.interlaceFlag); }