Search in sources :

Example 6 with TIFFTagSet

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

the class TIFFIFD method getShallowClone.

/**
 * Returns a <code>TIFFIFD</code> wherein all fields from the
 * <code>BaselineTIFFTagSet</code> are copied by value and all other
 * fields copied by reference.
 */
public TIFFIFD getShallowClone() {
    // Get the baseline TagSet.
    TIFFTagSet baselineTagSet = BaselineTIFFTagSet.getInstance();
    // If the baseline TagSet is not included just return.
    List tagSetList = getTagSetList();
    if (!tagSetList.contains(baselineTagSet)) {
        return this;
    }
    // Create a new object.
    TIFFIFD shallowClone = new TIFFIFD(tagSetList, getParentTag());
    // Get the tag numbers in the baseline set.
    Set baselineTagNumbers = baselineTagSet.getTagNumbers();
    // Iterate over the fields in this IFD.
    Iterator fields = iterator();
    while (fields.hasNext()) {
        // Get the next field.
        TIFFField field = (TIFFField) fields.next();
        // Get its tag number.
        Integer tagNumber = new Integer(field.getTagNumber());
        // Branch based on membership in baseline set.
        TIFFField fieldClone;
        if (baselineTagNumbers.contains(tagNumber)) {
            // Copy by value.
            Object fieldData = field.getData();
            int fieldType = field.getType();
            try {
                switch(fieldType) {
                    case TIFFTag.TIFF_BYTE:
                    case TIFFTag.TIFF_SBYTE:
                    case TIFFTag.TIFF_UNDEFINED:
                        fieldData = ((byte[]) fieldData).clone();
                        break;
                    case TIFFTag.TIFF_ASCII:
                        fieldData = ((String[]) fieldData).clone();
                        break;
                    case TIFFTag.TIFF_SHORT:
                        fieldData = ((char[]) fieldData).clone();
                        break;
                    case TIFFTag.TIFF_LONG:
                    case TIFFTag.TIFF_IFD_POINTER:
                        fieldData = ((long[]) fieldData).clone();
                        break;
                    case TIFFTag.TIFF_RATIONAL:
                        fieldData = ((long[][]) fieldData).clone();
                        break;
                    case TIFFTag.TIFF_SSHORT:
                        fieldData = ((short[]) fieldData).clone();
                        break;
                    case TIFFTag.TIFF_SLONG:
                        fieldData = ((int[]) fieldData).clone();
                        break;
                    case TIFFTag.TIFF_SRATIONAL:
                        fieldData = ((int[][]) fieldData).clone();
                        break;
                    case TIFFTag.TIFF_FLOAT:
                        fieldData = ((float[]) fieldData).clone();
                        break;
                    case TIFFTag.TIFF_DOUBLE:
                        fieldData = ((double[]) fieldData).clone();
                        break;
                    default:
                }
            } catch (Exception e) {
            // Ignore it and copy by reference ...
            }
            fieldClone = new TIFFField(field.getTag(), fieldType, field.getCount(), fieldData);
        } else {
            // Copy by reference.
            fieldClone = field;
        }
        // Add the field to the clone.
        shallowClone.addTIFFField(fieldClone);
    }
    // Set positions.
    shallowClone.setPositions(stripOrTileOffsetsPosition, stripOrTileByteCountsPosition, lastPosition);
    return shallowClone;
}
Also used : BaselineTIFFTagSet(it.geosolutions.imageio.plugins.tiff.BaselineTIFFTagSet) Set(java.util.Set) TIFFTagSet(it.geosolutions.imageio.plugins.tiff.TIFFTagSet) Iterator(java.util.Iterator) TIFFField(it.geosolutions.imageio.plugins.tiff.TIFFField) ArrayList(java.util.ArrayList) List(java.util.List) BaselineTIFFTagSet(it.geosolutions.imageio.plugins.tiff.BaselineTIFFTagSet) TIFFTagSet(it.geosolutions.imageio.plugins.tiff.TIFFTagSet) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 7 with TIFFTagSet

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

the class TIFFIFD method getTag.

public static TIFFTag getTag(String tagName, List tagSets) {
    Iterator iter = tagSets.iterator();
    while (iter.hasNext()) {
        TIFFTagSet tagSet = (TIFFTagSet) iter.next();
        TIFFTag tag = tagSet.getTag(tagName);
        if (tag != null) {
            return tag;
        }
    }
    return null;
}
Also used : Iterator(java.util.Iterator) BaselineTIFFTagSet(it.geosolutions.imageio.plugins.tiff.BaselineTIFFTagSet) TIFFTagSet(it.geosolutions.imageio.plugins.tiff.TIFFTagSet) TIFFTag(it.geosolutions.imageio.plugins.tiff.TIFFTag)

Example 8 with TIFFTagSet

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

Example 9 with TIFFTagSet

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

the class TIFFImageMetadata method mergeNativeTree.

private void mergeNativeTree(Node root) throws IIOInvalidTreeException {
    Node node = root;
    if (!node.getNodeName().equals(nativeMetadataFormatName)) {
        fatal(node, "Root must be " + nativeMetadataFormatName);
    }
    node = node.getFirstChild();
    if (node == null || !node.getNodeName().equals("TIFFIFD")) {
        fatal(root, "Root must have \"TIFFIFD\" child");
    }
    TIFFIFD ifd = parseIFD(node);
    List rootIFDTagSets = rootIFD.getTagSetList();
    Iterator tagSetIter = ifd.getTagSetList().iterator();
    while (tagSetIter.hasNext()) {
        Object o = tagSetIter.next();
        if (o instanceof TIFFTagSet && !rootIFDTagSets.contains(o)) {
            rootIFD.addTagSet((TIFFTagSet) o);
        }
    }
    Iterator ifdIter = ifd.iterator();
    while (ifdIter.hasNext()) {
        TIFFField field = (TIFFField) ifdIter.next();
        rootIFD.addTIFFField(field);
    }
}
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)

Aggregations

TIFFTagSet (it.geosolutions.imageio.plugins.tiff.TIFFTagSet)9 BaselineTIFFTagSet (it.geosolutions.imageio.plugins.tiff.BaselineTIFFTagSet)7 Iterator (java.util.Iterator)7 List (java.util.List)7 TIFFField (it.geosolutions.imageio.plugins.tiff.TIFFField)6 TIFFTag (it.geosolutions.imageio.plugins.tiff.TIFFTag)6 ArrayList (java.util.ArrayList)5 EXIFParentTIFFTagSet (it.geosolutions.imageio.plugins.tiff.EXIFParentTIFFTagSet)4 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)3 Node (org.w3c.dom.Node)3 NodeList (org.w3c.dom.NodeList)3 EXIFTIFFTagSet (it.geosolutions.imageio.plugins.tiff.EXIFTIFFTagSet)1 TIFFDirectory (it.geosolutions.imageio.plugins.tiff.TIFFDirectory)1 TIFFImageReadParam (it.geosolutions.imageio.plugins.tiff.TIFFImageReadParam)1 TIFFImageWriteParam (it.geosolutions.imageio.plugins.tiff.TIFFImageWriteParam)1 Point (java.awt.Point)1 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)1 IndexColorModel (java.awt.image.IndexColorModel)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1