Java Code Examples for javax.imageio.metadata.IIOMetadata#getNativeMetadataFormatName()

The following examples show how to use javax.imageio.metadata.IIOMetadata#getNativeMetadataFormatName() . 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: ShortHistogramTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private IIOMetadata upgradeMetadata(IIOMetadata src, BufferedImage bi) {
    String format = src.getNativeMetadataFormatName();
    System.out.println("Native format: " + format);
    Node root = src.getAsTree(format);

    // add hIST node
    Node n = lookupChildNode(root, "hIST");
    if (n == null) {
        System.out.println("Appending new hIST node...");
        Node hIST = gethISTNode(bi);
        root.appendChild(hIST);
    }

    System.out.println("Upgraded metadata tree:");
    dump(root, "");

    System.out.println("Merging metadata...");
    try {
        src.mergeTree(format, root);
    } catch (IIOInvalidTreeException e) {
        throw new RuntimeException("Test FAILED!", e);
    }
    return src;
}
 
Example 2
Source File: ShortHistogramTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private IIOMetadata upgradeMetadata(IIOMetadata src, BufferedImage bi) {
    String format = src.getNativeMetadataFormatName();
    System.out.println("Native format: " + format);
    Node root = src.getAsTree(format);

    // add hIST node
    Node n = lookupChildNode(root, "hIST");
    if (n == null) {
        System.out.println("Appending new hIST node...");
        Node hIST = gethISTNode(bi);
        root.appendChild(hIST);
    }

    System.out.println("Upgraded metadata tree:");
    dump(root, "");

    System.out.println("Merging metadata...");
    try {
        src.mergeTree(format, root);
    } catch (IIOInvalidTreeException e) {
        throw new RuntimeException("Test FAILED!", e);
    }
    return src;
}
 
Example 3
Source File: ShortHistogramTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private IIOMetadata upgradeMetadata(IIOMetadata src, BufferedImage bi) {
    String format = src.getNativeMetadataFormatName();
    System.out.println("Native format: " + format);
    Node root = src.getAsTree(format);

    // add hIST node
    Node n = lookupChildNode(root, "hIST");
    if (n == null) {
        System.out.println("Appending new hIST node...");
        Node hIST = gethISTNode(bi);
        root.appendChild(hIST);
    }

    System.out.println("Upgraded metadata tree:");
    dump(root, "");

    System.out.println("Merging metadata...");
    try {
        src.mergeTree(format, root);
    } catch (IIOInvalidTreeException e) {
        throw new RuntimeException("Test FAILED!", e);
    }
    return src;
}
 
Example 4
Source File: ShortHistogramTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private IIOMetadata upgradeMetadata(IIOMetadata src, BufferedImage bi) {
    String format = src.getNativeMetadataFormatName();
    System.out.println("Native format: " + format);
    Node root = src.getAsTree(format);

    // add hIST node
    Node n = lookupChildNode(root, "hIST");
    if (n == null) {
        System.out.println("Appending new hIST node...");
        Node hIST = gethISTNode(bi);
        root.appendChild(hIST);
    }

    System.out.println("Upgraded metadata tree:");
    dump(root, "");

    System.out.println("Merging metadata...");
    try {
        src.mergeTree(format, root);
    } catch (IIOInvalidTreeException e) {
        throw new RuntimeException("Test FAILED!", e);
    }
    return src;
}
 
Example 5
Source File: ShortHistogramTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private IIOMetadata upgradeMetadata(IIOMetadata src, BufferedImage bi) {
    String format = src.getNativeMetadataFormatName();
    System.out.println("Native format: " + format);
    Node root = src.getAsTree(format);

    // add hIST node
    Node n = lookupChildNode(root, "hIST");
    if (n == null) {
        System.out.println("Appending new hIST node...");
        Node hIST = gethISTNode(bi);
        root.appendChild(hIST);
    }

    System.out.println("Upgraded metadata tree:");
    dump(root, "");

    System.out.println("Merging metadata...");
    try {
        src.mergeTree(format, root);
    } catch (IIOInvalidTreeException e) {
        throw new RuntimeException("Test FAILED!", e);
    }
    return src;
}
 
Example 6
Source File: ITXtTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void writeTo(File f, ITXtTest t) {
    BufferedImage src = createBufferedImage();
    try {
        ImageOutputStream imageOutputStream =
            ImageIO.createImageOutputStream(f);

        ImageTypeSpecifier imageTypeSpecifier =
            new ImageTypeSpecifier(src);
        ImageWriter imageWriter =
            ImageIO.getImageWritersByFormatName("PNG").next();

        imageWriter.setOutput(imageOutputStream);

        IIOMetadata m =
            imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);

        String format = m.getNativeMetadataFormatName();
        Node root = m.getAsTree(format);

        IIOMetadataNode iTXt = t.getNode();
        root.appendChild(iTXt);
        m.setFromTree(format, root);

        imageWriter.write(new IIOImage(src, null, m));
        imageOutputStream.close();
        System.out.println("Writing done.");
    } catch (Throwable e) {
        throw new RuntimeException("Writing test failed.", e);
    }
}
 
Example 7
Source File: PngDitDepthTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IIOInvalidTreeException {

        // getting the writer for the png format
        Iterator iter = ImageIO.getImageWritersByFormatName("png");
        ImageWriter writer = (ImageWriter) iter.next();

        // creating a color model
        ColorModel colorModel = ColorModel.getRGBdefault();

        // creating a sample model
        SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);

        // creating a default metadata object
        IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
        String formatName = metaData.getNativeMetadataFormatName();

        // first call
        Node metaDataNode = metaData.getAsTree(formatName);
        try {
            metaData.setFromTree(formatName, metaDataNode);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // second call (bitdepht is already set to an invalid value)
        metaDataNode = metaData.getAsTree(formatName);

        metaData.setFromTree(formatName, metaDataNode);

    }
 
Example 8
Source File: PngDitDepthTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IIOInvalidTreeException {

        // getting the writer for the png format
        Iterator iter = ImageIO.getImageWritersByFormatName("png");
        ImageWriter writer = (ImageWriter) iter.next();

        // creating a color model
        ColorModel colorModel = ColorModel.getRGBdefault();

        // creating a sample model
        SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);

        // creating a default metadata object
        IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
        String formatName = metaData.getNativeMetadataFormatName();

        // first call
        Node metaDataNode = metaData.getAsTree(formatName);
        try {
            metaData.setFromTree(formatName, metaDataNode);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // second call (bitdepht is already set to an invalid value)
        metaDataNode = metaData.getAsTree(formatName);

        metaData.setFromTree(formatName, metaDataNode);

    }
 
Example 9
Source File: GIFImageWriter.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Merges {@code inData} into {@code outData}. The supplied
 * metadata format name is attempted first and failing that the standard
 * metadata format name is attempted.
 */
private void convertMetadata(String metadataFormatName,
                             IIOMetadata inData,
                             IIOMetadata outData) {
    String formatName = null;

    String nativeFormatName = inData.getNativeMetadataFormatName();
    if (nativeFormatName != null &&
        nativeFormatName.equals(metadataFormatName)) {
        formatName = metadataFormatName;
    } else {
        String[] extraFormatNames = inData.getExtraMetadataFormatNames();

        if (extraFormatNames != null) {
            for (int i = 0; i < extraFormatNames.length; i++) {
                if (extraFormatNames[i].equals(metadataFormatName)) {
                    formatName = metadataFormatName;
                    break;
                }
            }
        }
    }

    if (formatName == null &&
        inData.isStandardMetadataFormatSupported()) {
        formatName = STANDARD_METADATA_NAME;
    }

    if (formatName != null) {
        try {
            Node root = inData.getAsTree(formatName);
            outData.mergeTree(formatName, root);
        } catch(IIOInvalidTreeException e) {
            // ignore
        }
    }
}
 
Example 10
Source File: ImageReader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private IIOMetadata getMetadata(String formatName,
                                Set nodeNames,
                                boolean wantStream,
                                int imageIndex) throws IOException {
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }
    if (nodeNames == null) {
        throw new IllegalArgumentException("nodeNames == null!");
    }
    IIOMetadata metadata =
        wantStream
        ? getStreamMetadata()
        : getImageMetadata(imageIndex);
    if (metadata != null) {
        if (metadata.isStandardMetadataFormatSupported() &&
            formatName.equals
            (IIOMetadataFormatImpl.standardMetadataFormatName)) {
            return metadata;
        }
        String nativeName = metadata.getNativeMetadataFormatName();
        if (nativeName != null && formatName.equals(nativeName)) {
            return metadata;
        }
        String[] extraNames = metadata.getExtraMetadataFormatNames();
        if (extraNames != null) {
            for (int i = 0; i < extraNames.length; i++) {
                if (formatName.equals(extraNames[i])) {
                    return metadata;
                }
            }
        }
    }
    return null;
}
 
Example 11
Source File: GIFImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Merges <code>inData</code> into <code>outData</code>. The supplied
 * metadata format name is attempted first and failing that the standard
 * metadata format name is attempted.
 */
private void convertMetadata(String metadataFormatName,
                             IIOMetadata inData,
                             IIOMetadata outData) {
    String formatName = null;

    String nativeFormatName = inData.getNativeMetadataFormatName();
    if (nativeFormatName != null &&
        nativeFormatName.equals(metadataFormatName)) {
        formatName = metadataFormatName;
    } else {
        String[] extraFormatNames = inData.getExtraMetadataFormatNames();

        if (extraFormatNames != null) {
            for (int i = 0; i < extraFormatNames.length; i++) {
                if (extraFormatNames[i].equals(metadataFormatName)) {
                    formatName = metadataFormatName;
                    break;
                }
            }
        }
    }

    if (formatName == null &&
        inData.isStandardMetadataFormatSupported()) {
        formatName = STANDARD_METADATA_NAME;
    }

    if (formatName != null) {
        try {
            Node root = inData.getAsTree(formatName);
            outData.mergeTree(formatName, root);
        } catch(IIOInvalidTreeException e) {
            // ignore
        }
    }
}
 
Example 12
Source File: GIFImageWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Merges <code>inData</code> into <code>outData</code>. The supplied
 * metadata format name is attempted first and failing that the standard
 * metadata format name is attempted.
 */
private void convertMetadata(String metadataFormatName,
                             IIOMetadata inData,
                             IIOMetadata outData) {
    String formatName = null;

    String nativeFormatName = inData.getNativeMetadataFormatName();
    if (nativeFormatName != null &&
        nativeFormatName.equals(metadataFormatName)) {
        formatName = metadataFormatName;
    } else {
        String[] extraFormatNames = inData.getExtraMetadataFormatNames();

        if (extraFormatNames != null) {
            for (int i = 0; i < extraFormatNames.length; i++) {
                if (extraFormatNames[i].equals(metadataFormatName)) {
                    formatName = metadataFormatName;
                    break;
                }
            }
        }
    }

    if (formatName == null &&
        inData.isStandardMetadataFormatSupported()) {
        formatName = STANDARD_METADATA_NAME;
    }

    if (formatName != null) {
        try {
            Node root = inData.getAsTree(formatName);
            outData.mergeTree(formatName, root);
        } catch(IIOInvalidTreeException e) {
            // ignore
        }
    }
}
 
Example 13
Source File: GIFImageWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Merges <code>inData</code> into <code>outData</code>. The supplied
 * metadata format name is attempted first and failing that the standard
 * metadata format name is attempted.
 */
private void convertMetadata(String metadataFormatName,
                             IIOMetadata inData,
                             IIOMetadata outData) {
    String formatName = null;

    String nativeFormatName = inData.getNativeMetadataFormatName();
    if (nativeFormatName != null &&
        nativeFormatName.equals(metadataFormatName)) {
        formatName = metadataFormatName;
    } else {
        String[] extraFormatNames = inData.getExtraMetadataFormatNames();

        if (extraFormatNames != null) {
            for (int i = 0; i < extraFormatNames.length; i++) {
                if (extraFormatNames[i].equals(metadataFormatName)) {
                    formatName = metadataFormatName;
                    break;
                }
            }
        }
    }

    if (formatName == null &&
        inData.isStandardMetadataFormatSupported()) {
        formatName = STANDARD_METADATA_NAME;
    }

    if (formatName != null) {
        try {
            Node root = inData.getAsTree(formatName);
            outData.mergeTree(formatName, root);
        } catch(IIOInvalidTreeException e) {
            // ignore
        }
    }
}
 
Example 14
Source File: PngDitDepthTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IIOInvalidTreeException {

        // getting the writer for the png format
        Iterator iter = ImageIO.getImageWritersByFormatName("png");
        ImageWriter writer = (ImageWriter) iter.next();

        // creating a color model
        ColorModel colorModel = ColorModel.getRGBdefault();

        // creating a sample model
        SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);

        // creating a default metadata object
        IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
        String formatName = metaData.getNativeMetadataFormatName();

        // first call
        Node metaDataNode = metaData.getAsTree(formatName);
        try {
            metaData.setFromTree(formatName, metaDataNode);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // second call (bitdepht is already set to an invalid value)
        metaDataNode = metaData.getAsTree(formatName);

        metaData.setFromTree(formatName, metaDataNode);

    }
 
Example 15
Source File: ITXtTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void writeTo(File f, ITXtTest t) {
    BufferedImage src = createBufferedImage();
    try {
        ImageOutputStream imageOutputStream =
            ImageIO.createImageOutputStream(f);

        ImageTypeSpecifier imageTypeSpecifier =
            new ImageTypeSpecifier(src);
        ImageWriter imageWriter =
            ImageIO.getImageWritersByFormatName("PNG").next();

        imageWriter.setOutput(imageOutputStream);

        IIOMetadata m =
            imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);

        String format = m.getNativeMetadataFormatName();
        Node root = m.getAsTree(format);

        IIOMetadataNode iTXt = t.getNode();
        root.appendChild(iTXt);
        m.setFromTree(format, root);

        imageWriter.write(new IIOImage(src, null, m));
        imageOutputStream.close();
        System.out.println("Writing done.");
    } catch (Throwable e) {
        throw new RuntimeException("Writing test failed.", e);
    }
}
 
Example 16
Source File: GIFImageWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Merges <code>inData</code> into <code>outData</code>. The supplied
 * metadata format name is attempted first and failing that the standard
 * metadata format name is attempted.
 */
private void convertMetadata(String metadataFormatName,
                             IIOMetadata inData,
                             IIOMetadata outData) {
    String formatName = null;

    String nativeFormatName = inData.getNativeMetadataFormatName();
    if (nativeFormatName != null &&
        nativeFormatName.equals(metadataFormatName)) {
        formatName = metadataFormatName;
    } else {
        String[] extraFormatNames = inData.getExtraMetadataFormatNames();

        if (extraFormatNames != null) {
            for (int i = 0; i < extraFormatNames.length; i++) {
                if (extraFormatNames[i].equals(metadataFormatName)) {
                    formatName = metadataFormatName;
                    break;
                }
            }
        }
    }

    if (formatName == null &&
        inData.isStandardMetadataFormatSupported()) {
        formatName = STANDARD_METADATA_NAME;
    }

    if (formatName != null) {
        try {
            Node root = inData.getAsTree(formatName);
            outData.mergeTree(formatName, root);
        } catch(IIOInvalidTreeException e) {
            // ignore
        }
    }
}
 
Example 17
Source File: PngDitDepthTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IIOInvalidTreeException {

        // getting the writer for the png format
        Iterator iter = ImageIO.getImageWritersByFormatName("png");
        ImageWriter writer = (ImageWriter) iter.next();

        // creating a color model
        ColorModel colorModel = ColorModel.getRGBdefault();

        // creating a sample model
        SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);

        // creating a default metadata object
        IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
        String formatName = metaData.getNativeMetadataFormatName();

        // first call
        Node metaDataNode = metaData.getAsTree(formatName);
        try {
            metaData.setFromTree(formatName, metaDataNode);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // second call (bitdepht is already set to an invalid value)
        metaDataNode = metaData.getAsTree(formatName);

        metaData.setFromTree(formatName, metaDataNode);

    }
 
Example 18
Source File: ITXtTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void writeTo(File f, ITXtTest t) {
    BufferedImage src = createBufferedImage();
    try {
        ImageOutputStream imageOutputStream =
            ImageIO.createImageOutputStream(f);

        ImageTypeSpecifier imageTypeSpecifier =
            new ImageTypeSpecifier(src);
        ImageWriter imageWriter =
            ImageIO.getImageWritersByFormatName("PNG").next();

        imageWriter.setOutput(imageOutputStream);

        IIOMetadata m =
            imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);

        String format = m.getNativeMetadataFormatName();
        Node root = m.getAsTree(format);

        IIOMetadataNode iTXt = t.getNode();
        root.appendChild(iTXt);
        m.setFromTree(format, root);

        imageWriter.write(new IIOImage(src, null, m));
        imageOutputStream.close();
        System.out.println("Writing done.");
    } catch (Throwable e) {
        throw new RuntimeException("Writing test failed.", e);
    }
}
 
Example 19
Source File: GIFImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Merges <code>inData</code> into <code>outData</code>. The supplied
 * metadata format name is attempted first and failing that the standard
 * metadata format name is attempted.
 */
private void convertMetadata(String metadataFormatName,
                             IIOMetadata inData,
                             IIOMetadata outData) {
    String formatName = null;

    String nativeFormatName = inData.getNativeMetadataFormatName();
    if (nativeFormatName != null &&
        nativeFormatName.equals(metadataFormatName)) {
        formatName = metadataFormatName;
    } else {
        String[] extraFormatNames = inData.getExtraMetadataFormatNames();

        if (extraFormatNames != null) {
            for (int i = 0; i < extraFormatNames.length; i++) {
                if (extraFormatNames[i].equals(metadataFormatName)) {
                    formatName = metadataFormatName;
                    break;
                }
            }
        }
    }

    if (formatName == null &&
        inData.isStandardMetadataFormatSupported()) {
        formatName = STANDARD_METADATA_NAME;
    }

    if (formatName != null) {
        try {
            Node root = inData.getAsTree(formatName);
            outData.mergeTree(formatName, root);
        } catch(IIOInvalidTreeException e) {
            // ignore
        }
    }
}
 
Example 20
Source File: ImageReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private IIOMetadata getMetadata(String formatName,
                                Set nodeNames,
                                boolean wantStream,
                                int imageIndex) throws IOException {
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }
    if (nodeNames == null) {
        throw new IllegalArgumentException("nodeNames == null!");
    }
    IIOMetadata metadata =
        wantStream
        ? getStreamMetadata()
        : getImageMetadata(imageIndex);
    if (metadata != null) {
        if (metadata.isStandardMetadataFormatSupported() &&
            formatName.equals
            (IIOMetadataFormatImpl.standardMetadataFormatName)) {
            return metadata;
        }
        String nativeName = metadata.getNativeMetadataFormatName();
        if (nativeName != null && formatName.equals(nativeName)) {
            return metadata;
        }
        String[] extraNames = metadata.getExtraMetadataFormatNames();
        if (extraNames != null) {
            for (int i = 0; i < extraNames.length; i++) {
                if (formatName.equals(extraNames[i])) {
                    return metadata;
                }
            }
        }
    }
    return null;
}