Search in sources :

Example 51 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project imageio-ext by geosolutions-it.

the class TIFFImageMetadata method getIFDAsTree.

private Node getIFDAsTree(TIFFIFD ifd, String parentTagName, int parentTagNumber) {
    IIOMetadataNode IFDRoot = new IIOMetadataNode("TIFFIFD");
    if (parentTagNumber != 0) {
        IFDRoot.setAttribute("parentTagNumber", Integer.toString(parentTagNumber));
    }
    if (parentTagName != null) {
        IFDRoot.setAttribute("parentTagName", parentTagName);
    }
    List tagSets = ifd.getTagSetList();
    if (tagSets.size() > 0) {
        Iterator iter = tagSets.iterator();
        String tagSetNames = "";
        while (iter.hasNext()) {
            TIFFTagSet tagSet = (TIFFTagSet) iter.next();
            tagSetNames += tagSet.getClass().getName();
            if (iter.hasNext()) {
                tagSetNames += ",";
            }
        }
        IFDRoot.setAttribute("tagSets", tagSetNames);
    }
    Iterator iter = ifd.iterator();
    while (iter.hasNext()) {
        TIFFField f = (TIFFField) iter.next();
        int tagNumber = f.getTagNumber();
        TIFFTag tag = TIFFIFD.getTag(tagNumber, tagSets);
        Node node = null;
        if (tag == null) {
            node = f.getAsNativeNode();
        } else if (tag.isIFDPointer()) {
            TIFFIFD subIFD = (TIFFIFD) f.getData();
            // Recurse
            node = getIFDAsTree(subIFD, tag.getName(), tag.getNumber());
        } else {
            node = f.getAsNativeNode();
        }
        if (node != null) {
            IFDRoot.appendChild(node);
        }
    }
    return IFDRoot;
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) TIFFField(it.geosolutions.imageio.plugins.tiff.TIFFField) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) BaselineTIFFTagSet(it.geosolutions.imageio.plugins.tiff.BaselineTIFFTagSet) TIFFTagSet(it.geosolutions.imageio.plugins.tiff.TIFFTagSet) EXIFParentTIFFTagSet(it.geosolutions.imageio.plugins.tiff.EXIFParentTIFFTagSet) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) TIFFTag(it.geosolutions.imageio.plugins.tiff.TIFFTag)

Example 52 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project imageio-ext by geosolutions-it.

the class TIFFImageMetadata method getStandardTransparencyNode.

public IIOMetadataNode getStandardTransparencyNode() {
    IIOMetadataNode transparency_node = new IIOMetadataNode("Transparency");
    // scratch node
    IIOMetadataNode node = null;
    TIFFField f;
    node = new IIOMetadataNode("Alpha");
    String value = "none";
    f = getTIFFField(BaselineTIFFTagSet.TAG_EXTRA_SAMPLES);
    if (f != null) {
        int[] extraSamples = f.getAsInts();
        for (int i = 0; i < extraSamples.length; i++) {
            if (extraSamples[i] == BaselineTIFFTagSet.EXTRA_SAMPLES_ASSOCIATED_ALPHA) {
                value = "premultiplied";
                break;
            } else if (extraSamples[i] == BaselineTIFFTagSet.EXTRA_SAMPLES_UNASSOCIATED_ALPHA) {
                value = "nonpremultiplied";
                break;
            }
        }
    }
    node.setAttribute("value", value);
    transparency_node.appendChild(node);
    return transparency_node;
}
Also used : TIFFField(it.geosolutions.imageio.plugins.tiff.TIFFField) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 53 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project imageio-ext by geosolutions-it.

the class TIFFBaseJPEGCompressor method pruneNodes.

/**
 * Removes nonessential nodes from a JPEG native image metadata tree.
 * All nodes derived from JPEG marker segments other than DHT, DQT,
 * SOF, SOS segments are removed unless <code>pruneTables</code> is
 * <code>true</code> in which case the nodes derived from the DHT and
 * DQT marker segments are also removed.
 *
 * @param tree A <tt>javax_imageio_jpeg_image_1.0</tt> tree.
 * @param pruneTables Whether to prune Huffman and quantization tables.
 * @throws IllegalArgumentException if <code>tree</code> is
 * <code>null</code> or is not the root of a JPEG native image
 * metadata tree.
 */
private static void pruneNodes(Node tree, boolean pruneTables) {
    if (tree == null) {
        throw new IllegalArgumentException("tree == null!");
    }
    if (!tree.getNodeName().equals(IMAGE_METADATA_NAME)) {
        throw new IllegalArgumentException("root node name is not " + IMAGE_METADATA_NAME + "!");
    }
    if (DEBUG) {
        System.out.println("pruneNodes(" + tree + "," + pruneTables + ")");
    }
    // Create list of required nodes.
    List wantedNodes = new ArrayList();
    wantedNodes.addAll(Arrays.asList(new String[] { "JPEGvariety", "markerSequence", "sof", "componentSpec", "sos", "scanComponentSpec" }));
    // Add Huffman and quantization table nodes if not pruning tables.
    if (!pruneTables) {
        wantedNodes.add("dht");
        wantedNodes.add("dhtable");
        wantedNodes.add("dqt");
        wantedNodes.add("dqtable");
    }
    IIOMetadataNode iioTree = (IIOMetadataNode) tree;
    List nodes = getAllNodes(iioTree, null);
    int numNodes = nodes.size();
    for (int i = 0; i < numNodes; i++) {
        Node node = (Node) nodes.get(i);
        if (!wantedNodes.contains(node.getNodeName())) {
            if (DEBUG) {
                System.out.println("Removing " + node.getNodeName());
            }
            node.getParentNode().removeChild(node);
        }
    }
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Point(java.awt.Point)

Example 54 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project imageio-ext by geosolutions-it.

the class TIFFBaseJPEGCompressor method getAllNodes.

private static List getAllNodes(IIOMetadataNode root, List nodes) {
    if (nodes == null)
        nodes = new ArrayList();
    if (root.hasChildNodes()) {
        Node sibling = root.getFirstChild();
        while (sibling != null) {
            nodes.add(sibling);
            nodes = getAllNodes((IIOMetadataNode) sibling, nodes);
            sibling = sibling.getNextSibling();
        }
    }
    return nodes;
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 55 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project imageio-ext by geosolutions-it.

the class BaseJP2KBox method getNativeNodeForSimpleBox.

/**
 * Creates an <code>IIOMetadataNode</code> from this box. The format of
 * this node is defined in the XML dtd and xsd for the JP2 image file.
 *
 * This method is designed for the types of boxes whose XML tree only has 2
 * levels.
 */
protected IIOMetadataNode getNativeNodeForSimpleBox() {
    try {
        Method m = this.getClass().getMethod("getElementNames", (Class[]) null);
        String[] elementNames = (String[]) m.invoke(null, (Object[]) null);
        IIOMetadataNode node = new IIOMetadataNode(BoxUtilities.getName(getType()));
        setDefaultAttributes(node);
        for (int i = 0; i < elementNames.length; i++) {
            IIOMetadataNode child = new IIOMetadataNode(elementNames[i]);
            m = this.getClass().getMethod("get" + elementNames[i], (Class[]) null);
            Object obj = m.invoke(this, (Object[]) null);
            child.setUserObject(obj);
            child.setNodeValue(ImageUtil.convertObjectToString(obj));
            node.appendChild(child);
        }
        return node;
    } catch (Exception e) {
        throw new IllegalArgumentException("Box0");
    }
}
Also used : Method(java.lang.reflect.Method) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException)

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