Search in sources :

Example 1 with IIOInvalidTreeException

use of javax.imageio.metadata.IIOInvalidTreeException in project jdk8u_jdk by JetBrains.

the class WriteMetadataTest method testWritableMetadata.

public static void testWritableMetadata(IIOMetadata m) {
    String nativeFormatName = m.getNativeMetadataFormatName();
    System.out.println("Format: " + nativeFormatName);
    IIOMetadataNode root = (IIOMetadataNode) m.getAsTree(nativeFormatName);
    if (m.isReadOnly()) {
        throw new RuntimeException("Metadata is read only!");
    }
    try {
        m.setFromTree(nativeFormatName, root);
    } catch (IIOInvalidTreeException e) {
        e.printStackTrace();
        throw new RuntimeException("Test failed!", e);
    } catch (IllegalStateException e) {
        throw new RuntimeException("Test failed!", e);
    }
    System.out.println("Test passed.\n\n");
}
Also used : IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 2 with IIOInvalidTreeException

use of javax.imageio.metadata.IIOInvalidTreeException in project jdk8u_jdk by JetBrains.

the class ShortHistogramTest method upgradeMetadata.

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;
}
Also used : IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node)

Example 3 with IIOInvalidTreeException

use of javax.imageio.metadata.IIOInvalidTreeException in project jdk8u_jdk by JetBrains.

the class PngDitDepthTest method main.

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);
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) SampleModel(java.awt.image.SampleModel) ColorModel(java.awt.image.ColorModel) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) ImageWriter(javax.imageio.ImageWriter) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException)

Example 4 with IIOInvalidTreeException

use of javax.imageio.metadata.IIOInvalidTreeException in project jdk8u_jdk by JetBrains.

the class JPEGMetadata method mergeSequenceSubtree.

private void mergeSequenceSubtree(Node sequenceTree) throws IIOInvalidTreeException {
    NodeList children = sequenceTree.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.item(i);
        String name = node.getNodeName();
        if (name.equals("dqt")) {
            mergeDQTNode(node);
        } else if (name.equals("dht")) {
            mergeDHTNode(node);
        } else if (name.equals("dri")) {
            mergeDRINode(node);
        } else if (name.equals("com")) {
            mergeCOMNode(node);
        } else if (name.equals("app14Adobe")) {
            mergeAdobeNode(node);
        } else if (name.equals("unknown")) {
            mergeUnknownNode(node);
        } else if (name.equals("sof")) {
            mergeSOFNode(node);
        } else if (name.equals("sos")) {
            mergeSOSNode(node);
        } else {
            throw new IIOInvalidTreeException("Invalid node: " + name, node);
        }
    }
}
Also used : IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException) NodeList(org.w3c.dom.NodeList) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) Point(java.awt.Point)

Example 5 with IIOInvalidTreeException

use of javax.imageio.metadata.IIOInvalidTreeException in project jdk8u_jdk by JetBrains.

the class JPEGMetadata method mergeTree.

public void mergeTree(String formatName, Node root) throws IIOInvalidTreeException {
    if (formatName == null) {
        throw new IllegalArgumentException("null formatName!");
    }
    if (root == null) {
        throw new IllegalArgumentException("null root!");
    }
    List copy = null;
    if (resetSequence == null) {
        // Deep copy
        resetSequence = cloneSequence();
        // Avoid cloning twice
        copy = resetSequence;
    } else {
        copy = cloneSequence();
    }
    if (isStream && (formatName.equals(JPEG.nativeStreamMetadataFormatName))) {
        mergeNativeTree(root);
    } else if (!isStream && (formatName.equals(JPEG.nativeImageMetadataFormatName))) {
        mergeNativeTree(root);
    } else if (!isStream && (formatName.equals(IIOMetadataFormatImpl.standardMetadataFormatName))) {
        mergeStandardTree(root);
    } else {
        throw new IllegalArgumentException("Unsupported format name: " + formatName);
    }
    if (!isConsistent()) {
        markerSequence = copy;
        throw new IIOInvalidTreeException("Merged tree is invalid; original restored", root);
    }
}
Also used : IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Aggregations

IIOInvalidTreeException (javax.imageio.metadata.IIOInvalidTreeException)20 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)12 Node (org.w3c.dom.Node)12 NodeList (org.w3c.dom.NodeList)9 Point (java.awt.Point)5 ArrayList (java.util.ArrayList)4 NamedNodeMap (org.w3c.dom.NamedNodeMap)4 SampleModel (java.awt.image.SampleModel)3 List (java.util.List)3 IIOException (javax.imageio.IIOException)3 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)3 IIOMetadata (javax.imageio.metadata.IIOMetadata)3 ColorModel (java.awt.image.ColorModel)2 ComponentSampleModel (java.awt.image.ComponentSampleModel)2 Iterator (java.util.Iterator)2 TIFFImageWriteParam (it.geosolutions.imageio.plugins.tiff.TIFFImageWriteParam)1 Rectangle (java.awt.Rectangle)1 ComponentColorModel (java.awt.image.ComponentColorModel)1 IndexColorModel (java.awt.image.IndexColorModel)1 IOException (java.io.IOException)1