Java Code Examples for javax.imageio.metadata.IIOMetadataNode#getElementsByTagName()
The following examples show how to use
javax.imageio.metadata.IIOMetadataNode#getElementsByTagName() .
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: ExifGpsWriter.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Main method to write the gps data to the exif * @param gps - gps position to be added * @throws IOException */ private void writeExif() throws IOException { IIOMetadata metadata = jpegReader.getImageMetadata(0); // names says which exif tree to get - 0 for jpeg 1 for the default String[] names = metadata.getMetadataFormatNames(); IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(names[0]); // exif is on the app1 node called unknown NodeList nList = root.getElementsByTagName("unknown"); IIOMetadataNode app1EXIFNode = (IIOMetadataNode) nList.item(0); ArrayList<IIOMetadata> md = readExif(app1EXIFNode); IIOMetadata exifMetadata = md.get(0); // insert the gps data into the exif exifMetadata = insertGPSCoords(exifMetadata); // create a new exif node IIOMetadataNode app1NodeNew = createNewExifNode(exifMetadata, null, null); // copy the user data accross app1EXIFNode.setUserObject(app1NodeNew.getUserObject()); // write to a new image file FileImageOutputStream out1 = new FileImageOutputStream(new File("GPS_" + imageFile.getName())); jpegWriter.setOutput(out1); metadata.setFromTree(names[0], root); IIOImage image = new IIOImage(jpegReader.readAsRenderedImage(0, jpegReader.getDefaultReadParam()), null, metadata); // write out the new image jpegWriter.write(jpegReader.getStreamMetadata(), image, jpegWriter.getDefaultWriteParam()); }
Example 2
Source File: ExifReader.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("nls") private void parseExifMeta( IIOMetadata exifMeta ) { outTags = new HashMap<String, ExifTag>(); IIOMetadataNode root = (IIOMetadataNode) exifMeta.getAsTree("com_sun_media_imageio_plugins_tiff_image_1.0"); NodeList imageDirectories = root.getElementsByTagName("TIFFIFD"); for( int i = 0; i < imageDirectories.getLength(); i++ ) { IIOMetadataNode directory = (IIOMetadataNode) imageDirectories.item(i); NodeList tiffTags = directory.getElementsByTagName("TIFFField"); for( int j = 0; j < tiffTags.getLength(); j++ ) { IIOMetadataNode tag = (IIOMetadataNode) tiffTags.item(j); String tagNumber = tag.getAttribute("number"); String tagName = tag.getAttribute("name"); String tagValue; StringBuilder tmp = new StringBuilder(); IIOMetadataNode values = (IIOMetadataNode) tag.getFirstChild(); if ("TIFFUndefined".equals(values.getNodeName())) { tmp.append(values.getAttribute("value")); } else { NodeList tiffNumbers = values.getChildNodes(); for( int k = 0; k < tiffNumbers.getLength(); k++ ) { tmp.append(((IIOMetadataNode) tiffNumbers.item(k)).getAttribute("value")); tmp.append(","); } tmp.deleteCharAt(tmp.length() - 1); } tagValue = tmp.toString(); ExifTag exifTag = new ExifTag(tagName, tagNumber, tagValue); outTags.put(tagName, exifTag); } } }
Example 3
Source File: ImageIOHelper.java From tess4j with Apache License 2.0 | 5 votes |
/** * Reads image meta data. * * @param oimage * @return a map of meta data */ public static Map<String, String> readImageData(IIOImage oimage) { Map<String, String> dict = new HashMap<String, String>(); IIOMetadata imageMetadata = oimage.getMetadata(); if (imageMetadata != null) { IIOMetadataNode dimNode = (IIOMetadataNode) imageMetadata.getAsTree("javax_imageio_1.0"); NodeList nodes = dimNode.getElementsByTagName("HorizontalPixelSize"); int dpiX; if (nodes.getLength() > 0) { float dpcWidth = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue()); dpiX = (int) Math.round(25.4f / dpcWidth); } else { dpiX = Toolkit.getDefaultToolkit().getScreenResolution(); } dict.put("dpiX", String.valueOf(dpiX)); nodes = dimNode.getElementsByTagName("VerticalPixelSize"); int dpiY; if (nodes.getLength() > 0) { float dpcHeight = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue()); dpiY = (int) Math.round(25.4f / dpcHeight); } else { dpiY = Toolkit.getDefaultToolkit().getScreenResolution(); } dict.put("dpiY", String.valueOf(dpiY)); } return dict; }
Example 4
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 5
Source File: GIFImageWriter.java From jdk8u-dev-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 6
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 7
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 8
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 9
Source File: GIFImageWriter.java From openjdk-8-source 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 10
Source File: GIFImageWriter.java From hottub 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 11
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 12
Source File: GIFImageWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Writes any extension blocks, the Image Descriptor, and the image data * * @param image The image. * @param imageMetadata The 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 Bytecoder with Apache License 2.0 | 4 votes |
/** * Writes any extension blocks, the Image Descriptor, and the image data * * @param image The image. * @param imageMetadata The 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 14
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 15
Source File: GIFImageWriter.java From openjdk-jdk8u 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 16
Source File: GIFImageWriter.java From JDKSourceCode1.8 with MIT License | 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 jdk8u60 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 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 19
Source File: GIFImageWriter.java From dragonwell8_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); }