Search in sources :

Example 1 with TIFFDirectory

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

the class TIFFFieldNode method initialize.

private synchronized void initialize() {
    if (isInitialized == Boolean.TRUE)
        return;
    if (isIFD) {
        TIFFDirectory dir = (TIFFDirectory) field.getData();
        TIFFField[] fields = dir.getTIFFFields();
        if (fields != null) {
            TIFFTagSet[] tagSets = dir.getTagSets();
            List tagSetList = Arrays.asList(tagSets);
            int numFields = fields.length;
            for (int i = 0; i < numFields; i++) {
                TIFFField f = fields[i];
                int tagNumber = f.getTagNumber();
                TIFFTag tag = TIFFIFD.getTag(tagNumber, tagSetList);
                Node node = f.getAsNativeNode();
                if (node != null) {
                    appendChild(node);
                }
            }
        }
    } else {
        IIOMetadataNode child;
        int count = field.getCount();
        if (field.getType() == TIFFTag.TIFF_UNDEFINED) {
            child = new IIOMetadataNode("TIFFUndefined");
            byte[] data = field.getAsBytes();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < count; i++) {
                sb.append(Integer.toString(data[i] & 0xff));
                if (i < count - 1) {
                    sb.append(",");
                }
            }
            child.setAttribute("value", sb.toString());
        } else {
            child = new IIOMetadataNode("TIFF" + field.getTypeName(field.getType()) + "s");
            TIFFTag tag = field.getTag();
            String tName = tag.getName();
            boolean proceed = true;
            if (EXCLUDE_ATTRIBUTES && tName != null && ATTRIBUTES_EXCLUSION_SET.contains(tName)) {
                proceed = false;
            }
            for (int i = 0; i < count && proceed; i++) {
                IIOMetadataNode cchild = new IIOMetadataNode("TIFF" + field.getTypeName(field.getType()));
                cchild.setAttribute("value", field.getValueAsString(i));
                if (tag.hasValueNames() && field.isIntegral()) {
                    int value = field.getAsInt(i);
                    String name = tag.getValueName(value);
                    if (name != null) {
                        cchild.setAttribute("description", name);
                    }
                }
                child.appendChild(cchild);
            }
        }
        appendChild(child);
    }
    isInitialized = Boolean.TRUE;
}
Also used : Node(org.w3c.dom.Node) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) TIFFDirectory(it.geosolutions.imageio.plugins.tiff.TIFFDirectory) TIFFField(it.geosolutions.imageio.plugins.tiff.TIFFField) List(java.util.List) TIFFTagSet(it.geosolutions.imageio.plugins.tiff.TIFFTagSet) TIFFTag(it.geosolutions.imageio.plugins.tiff.TIFFTag) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Aggregations

TIFFDirectory (it.geosolutions.imageio.plugins.tiff.TIFFDirectory)1 TIFFField (it.geosolutions.imageio.plugins.tiff.TIFFField)1 TIFFTag (it.geosolutions.imageio.plugins.tiff.TIFFTag)1 TIFFTagSet (it.geosolutions.imageio.plugins.tiff.TIFFTagSet)1 List (java.util.List)1 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)1 Node (org.w3c.dom.Node)1