Search in sources :

Example 11 with TIFFField

use of it.geosolutions.imageio.plugins.tiff.TIFFField in project imageio-ext by geosolutions-it.

the class TIFFImageMetadata method getStandardCompressionNode.

public IIOMetadataNode getStandardCompressionNode() {
    IIOMetadataNode compression_node = new IIOMetadataNode("Compression");
    // scratch node
    IIOMetadataNode node = null;
    TIFFField f;
    f = getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
    if (f != null) {
        String compressionTypeName = null;
        int compression = f.getAsInt(0);
        // obligate initialization.
        boolean isLossless = true;
        if (compression == BaselineTIFFTagSet.COMPRESSION_NONE) {
            compressionTypeName = "None";
            isLossless = true;
        } else {
            int[] compressionNumbers = TIFFImageWriter.compressionNumbers;
            for (int i = 0; i < compressionNumbers.length; i++) {
                if (compression == compressionNumbers[i]) {
                    compressionTypeName = TIFFImageWriter.compressionTypes[i];
                    isLossless = TIFFImageWriter.isCompressionLossless[i];
                    break;
                }
            }
        }
        if (compressionTypeName != null) {
            node = new IIOMetadataNode("CompressionTypeName");
            node.setAttribute("value", compressionTypeName);
            compression_node.appendChild(node);
            node = new IIOMetadataNode("Lossless");
            node.setAttribute("value", isLossless ? "TRUE" : "FALSE");
            compression_node.appendChild(node);
        }
    }
    node = new IIOMetadataNode("NumProgressiveScans");
    node.setAttribute("value", "1");
    compression_node.appendChild(node);
    return compression_node;
}
Also used : TIFFField(it.geosolutions.imageio.plugins.tiff.TIFFField) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 12 with TIFFField

use of it.geosolutions.imageio.plugins.tiff.TIFFField in project imageio-ext by geosolutions-it.

the class TIFFImageMetadata method getStandardDocumentNode.

public IIOMetadataNode getStandardDocumentNode() {
    IIOMetadataNode document_node = new IIOMetadataNode("Document");
    // scratch node
    IIOMetadataNode node = null;
    TIFFField f;
    node = new IIOMetadataNode("FormatVersion");
    node.setAttribute("value", "6.0");
    document_node.appendChild(node);
    f = getTIFFField(BaselineTIFFTagSet.TAG_NEW_SUBFILE_TYPE);
    if (f != null) {
        int newSubFileType = f.getAsInt(0);
        String value = null;
        if ((newSubFileType & BaselineTIFFTagSet.NEW_SUBFILE_TYPE_TRANSPARENCY) != 0) {
            value = "TransparencyMask";
        } else if ((newSubFileType & BaselineTIFFTagSet.NEW_SUBFILE_TYPE_REDUCED_RESOLUTION) != 0) {
            value = "ReducedResolution";
        } else if ((newSubFileType & BaselineTIFFTagSet.NEW_SUBFILE_TYPE_SINGLE_PAGE) != 0) {
            value = "SinglePage";
        }
        if (value != null) {
            node = new IIOMetadataNode("SubimageInterpretation");
            node.setAttribute("value", value);
            document_node.appendChild(node);
        }
    }
    f = getTIFFField(BaselineTIFFTagSet.TAG_DATE_TIME);
    if (f != null) {
        String s = f.getAsString(0);
        // DateTime should be formatted as "YYYY:MM:DD hh:mm:ss".
        if (s.length() == 19) {
            node = new IIOMetadataNode("ImageCreationTime");
            // Files with incorrect DateTime format have been
            // observed so anticipate an exception from substring()
            // and only add the node if the format is presumably
            // correct.
            boolean appendNode;
            try {
                node.setAttribute("year", s.substring(0, 4));
                node.setAttribute("month", s.substring(5, 7));
                node.setAttribute("day", s.substring(8, 10));
                node.setAttribute("hour", s.substring(11, 13));
                node.setAttribute("minute", s.substring(14, 16));
                node.setAttribute("second", s.substring(17, 19));
                appendNode = true;
            } catch (IndexOutOfBoundsException e) {
                appendNode = false;
            }
            if (appendNode) {
                document_node.appendChild(node);
            }
        }
    }
    return document_node;
}
Also used : TIFFField(it.geosolutions.imageio.plugins.tiff.TIFFField) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 13 with TIFFField

use of it.geosolutions.imageio.plugins.tiff.TIFFField in project imageio-ext by geosolutions-it.

the class TIFFImageMetadata method addShortOrLongField.

public void addShortOrLongField(int tagNumber, int value) {
    TIFFField field = new TIFFField(rootIFD.getTag(tagNumber), value);
    rootIFD.addTIFFField(field);
}
Also used : TIFFField(it.geosolutions.imageio.plugins.tiff.TIFFField)

Example 14 with TIFFField

use of it.geosolutions.imageio.plugins.tiff.TIFFField 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 15 with TIFFField

use of it.geosolutions.imageio.plugins.tiff.TIFFField 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)

Aggregations

TIFFField (it.geosolutions.imageio.plugins.tiff.TIFFField)35 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)11 BaselineTIFFTagSet (it.geosolutions.imageio.plugins.tiff.BaselineTIFFTagSet)8 TIFFTag (it.geosolutions.imageio.plugins.tiff.TIFFTag)7 Iterator (java.util.Iterator)7 List (java.util.List)7 TIFFTagSet (it.geosolutions.imageio.plugins.tiff.TIFFTagSet)6 ArrayList (java.util.ArrayList)6 Point (java.awt.Point)5 IIOException (javax.imageio.IIOException)5 EXIFParentTIFFTagSet (it.geosolutions.imageio.plugins.tiff.EXIFParentTIFFTagSet)4 IOException (java.io.IOException)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 TIFFImageWriteParam (it.geosolutions.imageio.plugins.tiff.TIFFImageWriteParam)2 Rectangle (java.awt.Rectangle)2 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)2 IndexColorModel (java.awt.image.IndexColorModel)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 EOFException (java.io.EOFException)2