Search in sources :

Example 71 with IIOMetadataNode

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

the class ITXtTest method getFromNode.

public static ITXtTest getFromNode(IIOMetadataNode n) {
    ITXtTest t = new ITXtTest();
    if (!"iTXt".equals(n.getNodeName())) {
        throw new RuntimeException("Invalid node");
    }
    IIOMetadataNode e = (IIOMetadataNode) n.getFirstChild();
    if (!"iTXtEntry".equals(e.getNodeName())) {
        throw new RuntimeException("Invalid entry node");
    }
    t.keyword = e.getAttribute("keyword");
    t.isCompressed = Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
    t.compression = Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
    t.language = e.getAttribute("languageTag");
    t.trasKeyword = e.getAttribute("translatedKeyword");
    t.text = e.getAttribute("text");
    return t;
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 72 with IIOMetadataNode

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

the class ITXtTest method getNode.

public IIOMetadataNode getNode() {
    IIOMetadataNode iTXt = new IIOMetadataNode("iTXt");
    IIOMetadataNode iTXtEntry = new IIOMetadataNode("iTXtEntry");
    iTXtEntry.setAttribute("keyword", keyword);
    iTXtEntry.setAttribute("compressionFlag", isCompressed ? "true" : "false");
    iTXtEntry.setAttribute("compressionMethod", Integer.toString(compression));
    iTXtEntry.setAttribute("languageTag", language);
    iTXtEntry.setAttribute("translatedKeyword", trasKeyword);
    iTXtEntry.setAttribute("text", text);
    iTXt.appendChild(iTXtEntry);
    return iTXt;
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 73 with IIOMetadataNode

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

the class GIFStreamMetadata method getNativeTree.

private Node getNativeTree() {
    // scratch node
    IIOMetadataNode node;
    IIOMetadataNode root = new IIOMetadataNode(nativeMetadataFormatName);
    node = new IIOMetadataNode("Version");
    node.setAttribute("value", version);
    root.appendChild(node);
    // Image descriptor
    node = new IIOMetadataNode("LogicalScreenDescriptor");
    /* NB: At the moment we use empty strings to support undefined
         * integer values in tree representation.
         * We need to add better support for undefined/default values later.
         */
    node.setAttribute("logicalScreenWidth", logicalScreenWidth == UNDEFINED_INTEGER_VALUE ? "" : Integer.toString(logicalScreenWidth));
    node.setAttribute("logicalScreenHeight", logicalScreenHeight == UNDEFINED_INTEGER_VALUE ? "" : Integer.toString(logicalScreenHeight));
    // Stored value plus one
    node.setAttribute("colorResolution", colorResolution == UNDEFINED_INTEGER_VALUE ? "" : Integer.toString(colorResolution));
    node.setAttribute("pixelAspectRatio", Integer.toString(pixelAspectRatio));
    root.appendChild(node);
    if (globalColorTable != null) {
        node = new IIOMetadataNode("GlobalColorTable");
        int numEntries = globalColorTable.length / 3;
        node.setAttribute("sizeOfGlobalColorTable", Integer.toString(numEntries));
        node.setAttribute("backgroundColorIndex", Integer.toString(backgroundColorIndex));
        node.setAttribute("sortFlag", sortFlag ? "TRUE" : "FALSE");
        for (int i = 0; i < numEntries; i++) {
            IIOMetadataNode entry = new IIOMetadataNode("ColorTableEntry");
            entry.setAttribute("index", Integer.toString(i));
            int r = globalColorTable[3 * i] & 0xff;
            int g = globalColorTable[3 * i + 1] & 0xff;
            int b = globalColorTable[3 * i + 2] & 0xff;
            entry.setAttribute("red", Integer.toString(r));
            entry.setAttribute("green", Integer.toString(g));
            entry.setAttribute("blue", Integer.toString(b));
            node.appendChild(entry);
        }
        root.appendChild(node);
    }
    return root;
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 74 with IIOMetadataNode

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

the class GIFStreamMetadata method getStandardCompressionNode.

public IIOMetadataNode getStandardCompressionNode() {
    IIOMetadataNode compression_node = new IIOMetadataNode("Compression");
    // scratch node
    IIOMetadataNode node = null;
    node = new IIOMetadataNode("CompressionTypeName");
    node.setAttribute("value", "lzw");
    compression_node.appendChild(node);
    node = new IIOMetadataNode("Lossless");
    node.setAttribute("value", "TRUE");
    compression_node.appendChild(node);
    return compression_node;
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 75 with IIOMetadataNode

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

the class GIFWritableImageMetadata method mergeNativeTree.

protected void mergeNativeTree(Node root) throws IIOInvalidTreeException {
    Node node = root;
    if (!node.getNodeName().equals(nativeMetadataFormatName)) {
        fatal(node, "Root must be " + nativeMetadataFormatName);
    }
    node = node.getFirstChild();
    while (node != null) {
        String name = node.getNodeName();
        if (name.equals("ImageDescriptor")) {
            imageLeftPosition = getIntAttribute(node, "imageLeftPosition", -1, true, true, 0, 65535);
            imageTopPosition = getIntAttribute(node, "imageTopPosition", -1, true, true, 0, 65535);
            imageWidth = getIntAttribute(node, "imageWidth", -1, true, true, 1, 65535);
            imageHeight = getIntAttribute(node, "imageHeight", -1, true, true, 1, 65535);
            interlaceFlag = getBooleanAttribute(node, "interlaceFlag", false, true);
        } else if (name.equals("LocalColorTable")) {
            int sizeOfLocalColorTable = getIntAttribute(node, "sizeOfLocalColorTable", true, 2, 256);
            if (sizeOfLocalColorTable != 2 && sizeOfLocalColorTable != 4 && sizeOfLocalColorTable != 8 && sizeOfLocalColorTable != 16 && sizeOfLocalColorTable != 32 && sizeOfLocalColorTable != 64 && sizeOfLocalColorTable != 128 && sizeOfLocalColorTable != 256) {
                fatal(node, "Bad value for LocalColorTable attribute sizeOfLocalColorTable!");
            }
            sortFlag = getBooleanAttribute(node, "sortFlag", false, true);
            localColorTable = getColorTable(node, "ColorTableEntry", true, sizeOfLocalColorTable);
        } else if (name.equals("GraphicControlExtension")) {
            String disposalMethodName = getStringAttribute(node, "disposalMethod", null, true, disposalMethodNames);
            disposalMethod = 0;
            while (!disposalMethodName.equals(disposalMethodNames[disposalMethod])) {
                disposalMethod++;
            }
            userInputFlag = getBooleanAttribute(node, "userInputFlag", false, true);
            transparentColorFlag = getBooleanAttribute(node, "transparentColorFlag", false, true);
            delayTime = getIntAttribute(node, "delayTime", -1, true, true, 0, 65535);
            transparentColorIndex = getIntAttribute(node, "transparentColorIndex", -1, true, true, 0, 65535);
        } else if (name.equals("PlainTextExtension")) {
            hasPlainTextExtension = true;
            textGridLeft = getIntAttribute(node, "textGridLeft", -1, true, true, 0, 65535);
            textGridTop = getIntAttribute(node, "textGridTop", -1, true, true, 0, 65535);
            textGridWidth = getIntAttribute(node, "textGridWidth", -1, true, true, 1, 65535);
            textGridHeight = getIntAttribute(node, "textGridHeight", -1, true, true, 1, 65535);
            characterCellWidth = getIntAttribute(node, "characterCellWidth", -1, true, true, 1, 65535);
            characterCellHeight = getIntAttribute(node, "characterCellHeight", -1, true, true, 1, 65535);
            textForegroundColor = getIntAttribute(node, "textForegroundColor", -1, true, true, 0, 255);
            textBackgroundColor = getIntAttribute(node, "textBackgroundColor", -1, true, true, 0, 255);
            // XXX The "text" attribute of the PlainTextExtension element
            // is not defined in the GIF image metadata format but it is
            // present in the GIFImageMetadata class. Consequently it is
            // used here but not required and with a default of "". See
            // bug 5082763.
            String textString = getStringAttribute(node, "text", "", false, null);
            text = fromISO8859(textString);
        } else if (name.equals("ApplicationExtensions")) {
            IIOMetadataNode applicationExtension = (IIOMetadataNode) node.getFirstChild();
            if (!applicationExtension.getNodeName().equals("ApplicationExtension")) {
                fatal(node, "Only a ApplicationExtension may be a child of a ApplicationExtensions!");
            }
            String applicationIDString = getStringAttribute(applicationExtension, "applicationID", null, true, null);
            String authenticationCodeString = getStringAttribute(applicationExtension, "authenticationCode", null, true, null);
            Object applicationExtensionData = applicationExtension.getUserObject();
            if (applicationExtensionData == null || !(applicationExtensionData instanceof byte[])) {
                fatal(applicationExtension, "Bad user object in ApplicationExtension!");
            }
            if (applicationIDs == null) {
                applicationIDs = new ArrayList();
                authenticationCodes = new ArrayList();
                applicationData = new ArrayList();
            }
            applicationIDs.add(fromISO8859(applicationIDString));
            authenticationCodes.add(fromISO8859(authenticationCodeString));
            applicationData.add(applicationExtensionData);
        } else if (name.equals("CommentExtensions")) {
            Node commentExtension = node.getFirstChild();
            if (commentExtension != null) {
                while (commentExtension != null) {
                    if (!commentExtension.getNodeName().equals("CommentExtension")) {
                        fatal(node, "Only a CommentExtension may be a child of a CommentExtensions!");
                    }
                    if (comments == null) {
                        comments = new ArrayList();
                    }
                    String comment = getStringAttribute(commentExtension, "value", null, true, null);
                    comments.add(fromISO8859(comment));
                    commentExtension = commentExtension.getNextSibling();
                }
            }
        } else {
            fatal(node, "Unknown child of root node!");
        }
        node = node.getNextSibling();
    }
}
Also used : Node(org.w3c.dom.Node) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) ArrayList(java.util.ArrayList) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Aggregations

IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)132 Node (org.w3c.dom.Node)20 IIOMetadata (javax.imageio.metadata.IIOMetadata)12 NodeList (org.w3c.dom.NodeList)12 TIFFField (it.geosolutions.imageio.plugins.tiff.TIFFField)10 Iterator (java.util.Iterator)9 BufferedImage (java.awt.image.BufferedImage)8 ArrayList (java.util.ArrayList)8 ASOCBoxMetadataNode (it.geosolutions.imageio.plugins.jp2k.box.ASOCBoxMetadataNode)5 UUIDBoxMetadataNode (it.geosolutions.imageio.plugins.jp2k.box.UUIDBoxMetadataNode)5 XMLBoxMetadataNode (it.geosolutions.imageio.plugins.jp2k.box.XMLBoxMetadataNode)5 IOException (java.io.IOException)5 ImageOutputStream (javax.imageio.stream.ImageOutputStream)5 File (java.io.File)4 IIOImage (javax.imageio.IIOImage)4 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)4 ImageWriter (javax.imageio.ImageWriter)4 TIFFTag (it.geosolutions.imageio.plugins.tiff.TIFFTag)3 Color (java.awt.Color)3 Point (java.awt.Point)3