Class TIFFField

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int count
      The number of data items present in the field.
      private java.lang.Object data
      The field data.
      private static boolean[] isIntegral  
      private TIFFTag tag
      The tag.
      private int tagNumber
      The tag number.
      private int type
      The tag type.
      private static java.lang.String[] typeNames  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(java.lang.Object o)
      Compares this TIFFField with another TIFFField by comparing the tags.
      static java.lang.Object createArrayForType​(int dataType, int count)
      Creates an array appropriate for the indicated data type.
      static TIFFField createFromMetadataNode​(TIFFTagSet tagSet, org.w3c.dom.Node node)
      Creates a TIFFField from a TIFF native image metadata node.
      byte[] getAsBytes()
      Returns the data as an uninterpreted array of bytes.
      char[] getAsChars()
      Returns TIFFTag.TIFF_SHORT data as an array of chars (unsigned 16-bit integers).
      double getAsDouble​(int index)
      Returns data in any format as a double.
      double[] getAsDoubles()
      Returns TIFFTag.TIFF_DOUBLE data as an array of doubles (64-bit floating-point values).
      float getAsFloat​(int index)
      Returns data in any format as a float.
      float[] getAsFloats()
      Returns TIFFTag.TIFF_FLOAT data as an array of floats (32-bit floating-point values).
      int getAsInt​(int index)
      Returns data in any format as an int.
      int[] getAsInts()
      Returns TIFFTag.TIFF_SLONG data as an array of ints (signed 32-bit integers).
      long getAsLong​(int index)
      Returns data in any format as a long.
      long[] getAsLongs()
      Returns TIFFTag.TIFF_LONG or TIFF_IFD_POINTER data as an array of longs (signed 64-bit integers).
      org.w3c.dom.Node getAsNativeNode()
      Returns the TIFFField as a node named either "TIFFField" or "TIFFIFD" as described in the TIFF native image metadata specification.
      long[] getAsRational​(int index)
      Returns a TIFFTag.TIFF_RATIONAL data item as a two-element array of ints.
      long[][] getAsRationals()
      Returns TIFFTag.TIFF_RATIONAL data as an array of 2-element arrays of longs.
      short[] getAsShorts()
      Returns TIFFTag.TIFF_SSHORT data as an array of shorts (signed 16-bit integers).
      int[] getAsSRational​(int index)
      Returns a TIFFTag.TIFF_SRATIONAL data item as a two-element array of ints.
      int[][] getAsSRationals()
      Returns TIFFTag.TIFF_SRATIONAL data as an array of 2-element arrays of ints.
      java.lang.String getAsString​(int index)
      Returns a TIFFTag.TIFF_ASCII value as a String.
      private static java.lang.String getAttribute​(org.w3c.dom.Node node, java.lang.String attrName)  
      int getCount()
      Returns the number of data items present in the field.
      java.lang.Object getData()
      Returns a reference to the data object associated with the field.
      TIFFTag getTag()
      Retrieves the tag associated with this field.
      int getTagNumber()
      Retrieves the tag number in the range [0, 65535].
      int getType()
      Returns the type of the data stored in the field.
      static int getTypeByName​(java.lang.String typeName)
      Returns the data type constant corresponding to the supplied data type name.
      static java.lang.String getTypeName​(int dataType)
      Returns the name of the supplied data type constant.
      java.lang.String getValueAsString​(int index)
      Returns a String containing a human-readable version of the data item.
      private static void initData​(org.w3c.dom.Node node, int[] otype, int[] ocount, java.lang.Object[] odata)  
      boolean isIntegral()
      Indicates whether the value associated with the field is of integral data type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • typeNames

        private static final java.lang.String[] typeNames
      • isIntegral

        private static final boolean[] isIntegral
      • tag

        private TIFFTag tag
        The tag.
      • tagNumber

        private int tagNumber
        The tag number.
      • type

        private int type
        The tag type.
      • count

        private int count
        The number of data items present in the field.
      • data

        private java.lang.Object data
        The field data.
    • Constructor Detail

      • TIFFField

        private TIFFField()
        The default constructor.
      • TIFFField

        public TIFFField​(TIFFTag tag,
                         int type,
                         int count,
                         java.lang.Object data)
        Constructs a TIFFField with arbitrary data. The type parameter must be a value for which tag.isDataTypeOK() returns true. The data parameter must be an array of a Java type appropriate for the type of the TIFF field unless tag.isIFDPointer() returns true in which case it must be a TIFFDirectory instance.

        Neither the legality of type with respect to tag nor that or data with respect to type is verified by this constructor. The methods TIFFTag.isDataTypeOK() and createArrayForType() should be used programmatically to ensure that subsequent errors such as ClassCastExceptions do not occur as a result of providing inconsitent parameters to this constructor.

        Note that the value (data) of the TIFFField will always be the actual field value regardless of the number of bytes required for that value. This is the case despite the fact that the TIFF IFD Entry corresponding to the field may actually contain the offset to the field's value rather than the value itself (the latter occurring if and only if the value fits into 4 bytes). In other words, the value of the field will already have been read from the TIFF stream. This subsumes the case where tag.isIFDPointer() returns true and the value will be a TIFFDirectory rather than an array.

        Parameters:
        tag - The tag to associated with this field.
        type - One of the TIFFTag.TIFF_* constants indicating the data type of the field as written to the TIFF stream.
        count - The number of data values.
        data - The actual data content of the field.
        Throws:
        java.lang.IllegalArgumentException - if tag == null.
        java.lang.IllegalArgumentException - if dataType is not one of the TIFFTag.TIFF_* data type constants.
        java.lang.IllegalArgumentException - if count < 0.
      • TIFFField

        public TIFFField​(TIFFTag tag,
                         int value)
        Constructs a TIFFField with a single integral value. The field will have type TIFF_SHORT if val < 65536 and type TIFF_LONG otherwise. It is not verified whether the resulting type is legal for tag.
        Parameters:
        tag - The tag to associate with this field.
        value - The value to associate with this field.
        Throws:
        java.lang.IllegalArgumentException - if tag == null.
        java.lang.IllegalArgumentException - if value < 0.
    • Method Detail

      • getAttribute

        private static java.lang.String getAttribute​(org.w3c.dom.Node node,
                                                     java.lang.String attrName)
      • initData

        private static void initData​(org.w3c.dom.Node node,
                                     int[] otype,
                                     int[] ocount,
                                     java.lang.Object[] odata)
      • createFromMetadataNode

        public static TIFFField createFromMetadataNode​(TIFFTagSet tagSet,
                                                       org.w3c.dom.Node node)
        Creates a TIFFField from a TIFF native image metadata node. If the value of the "tagNumber" attribute of the node is not found in tagSet then a new TIFFTag with name "unknown" will be created and assigned to the field.
        Parameters:
        tagSet - The TIFFTagSet to which the TIFFTag of the field belongs.
        node - A native TIFF image metadata TIFFField node.
        Throws:
        java.lang.IllegalArgumentException - if node is null.
        java.lang.IllegalArgumentException - if the name of the node is not "TIFFField".
      • getTag

        public TIFFTag getTag()
        Retrieves the tag associated with this field.
        Returns:
        The associated TIFFTag.
      • getTagNumber

        public int getTagNumber()
        Retrieves the tag number in the range [0, 65535].
        Returns:
        The tag number.
      • getType

        public int getType()
        Returns the type of the data stored in the field. For a TIFF 6.0 stream, the value will equal one of the TIFFTag.TIFF_* constants. For future revisions of TIFF, higher values are possible.
        Returns:
        The data type of the field value.
      • getTypeName

        public static java.lang.String getTypeName​(int dataType)
        Returns the name of the supplied data type constant.
        Parameters:
        dataType - One of the TIFFTag.TIFF_* constants indicating the data type of the field as written to the TIFF stream.
        Returns:
        The type name corresponding to the supplied type constant.
        Throws:
        java.lang.IllegalArgumentException - if dataType is not one of the TIFFTag.TIFF_* data type constants.
      • getTypeByName

        public static int getTypeByName​(java.lang.String typeName)
        Returns the data type constant corresponding to the supplied data type name. If the name is unknown -1 will be returned.
        Returns:
        One of the TIFFTag.TIFF_* constants or -1 if the name is not recognized.
      • createArrayForType

        public static java.lang.Object createArrayForType​(int dataType,
                                                          int count)
        Creates an array appropriate for the indicated data type.
        Parameters:
        dataType - One of the TIFFTag.TIFF_* data type constants.
        count - The number of values in the array.
        Throws:
        java.lang.IllegalArgumentException - if dataType is not one of the TIFFTag.TIFF_* data type constants.
        java.lang.IllegalArgumentException - if count < 0.
      • getAsNativeNode

        public org.w3c.dom.Node getAsNativeNode()
        Returns the TIFFField as a node named either "TIFFField" or "TIFFIFD" as described in the TIFF native image metadata specification. The node will be named "TIFFIFD" if and only if the field's data object is an instance of TIFFDirectory or equivalently getTag.isIFDPointer() returns true.
        Returns:
        a Node named "TIFFField" or "TIFFIFD".
      • isIntegral

        public boolean isIntegral()
        Indicates whether the value associated with the field is of integral data type.
        Returns:
        Whether the field type is integral.
      • getCount

        public int getCount()
        Returns the number of data items present in the field. For TIFFTag.TIFF_ASCII fields, the value returned is the number of Strings, not the total length of the data as in the file representation.
      • getData

        public java.lang.Object getData()
        Returns a reference to the data object associated with the field.
        Returns:
        The data object of the field.
      • getAsBytes

        public byte[] getAsBytes()
        Returns the data as an uninterpreted array of bytes. The type of the field must be one of TIFFTag.TIFF_BYTE, TIFF_SBYTE, or TIFF_UNDEFINED.

        For data in TIFFTag.TIFF_BYTE format, the application must take care when promoting the data to longer integral types to avoid sign extension.

        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_BYTE, TIFF_SBYTE, or TIFF_UNDEFINED.
      • getAsChars

        public char[] getAsChars()
        Returns TIFFTag.TIFF_SHORT data as an array of chars (unsigned 16-bit integers).
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_SHORT.
      • getAsShorts

        public short[] getAsShorts()
        Returns TIFFTag.TIFF_SSHORT data as an array of shorts (signed 16-bit integers).
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_SSHORT.
      • getAsInts

        public int[] getAsInts()
        Returns TIFFTag.TIFF_SLONG data as an array of ints (signed 32-bit integers).
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_SHORT, TIFF_SSHORT, or TIFF_SLONG.
      • getAsLongs

        public long[] getAsLongs()
        Returns TIFFTag.TIFF_LONG or TIFF_IFD_POINTER data as an array of longs (signed 64-bit integers).
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_LONG or TIFF_IFD_POINTER.
      • getAsFloats

        public float[] getAsFloats()
        Returns TIFFTag.TIFF_FLOAT data as an array of floats (32-bit floating-point values).
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_FLOAT.
      • getAsDoubles

        public double[] getAsDoubles()
        Returns TIFFTag.TIFF_DOUBLE data as an array of doubles (64-bit floating-point values).
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_DOUBLE.
      • getAsSRationals

        public int[][] getAsSRationals()
        Returns TIFFTag.TIFF_SRATIONAL data as an array of 2-element arrays of ints.
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_SRATIONAL.
      • getAsRationals

        public long[][] getAsRationals()
        Returns TIFFTag.TIFF_RATIONAL data as an array of 2-element arrays of longs.
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_RATIONAL.
      • getAsInt

        public int getAsInt​(int index)
        Returns data in any format as an int.

        TIFFTag.TIFF_BYTE values are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255]. TIFF_SBYTE data will be returned in the range [-128, 127].

        A TIFF_UNDEFINED value is treated as though it were a TIFF_BYTE.

        Data in TIFF_SLONG, TIFF_LONG, TIFF_FLOAT, TIFF_DOUBLE or TIFF_IFD_POINTER format are simply cast to int and may suffer from truncation.

        Data in TIFF_SRATIONAL or TIFF_RATIONAL format are evaluated by dividing the numerator into the denominator using double-precision arithmetic and then casting to int. Loss of precision and truncation may occur.

        Data in TIFF_ASCII format will be parsed as by the Double.parseDouble method, with the result case to int.

      • getAsLong

        public long getAsLong​(int index)
        Returns data in any format as a long.

        TIFFTag.TIFF_BYTE and TIFF_UNDEFINED data are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255]. TIFF_SBYTE data will be returned in the range [-128, 127].

        Data in TIFF_ASCII format will be parsed as by the Double.parseDouble method, with the result cast to long.

      • getAsFloat

        public float getAsFloat​(int index)
        Returns data in any format as a float.

        TIFFTag.TIFF_BYTE and TIFF_UNDEFINED data are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255]. TIFF_SBYTE data will be returned in the range [-128, 127].

        Data in TIFF_SLONG, TIFF_LONG, TIFF_DOUBLE, or TIFF_IFD_POINTER format are simply cast to float and may suffer from truncation.

        Data in TIFF_SRATIONAL or TIFF_RATIONAL format are evaluated by dividing the numerator into the denominator using double-precision arithmetic and then casting to float.

        Data in TIFF_ASCII format will be parsed as by the Double.parseDouble method, with the result cast to float.

      • getAsDouble

        public double getAsDouble​(int index)
        Returns data in any format as a double.

        TIFFTag.TIFF_BYTE and TIFF_UNDEFINED data are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255]. TIFF_SBYTE data will be returned in the range [-128, 127].

        Data in TIFF_SRATIONAL or TIFF_RATIONAL format are evaluated by dividing the numerator into the denominator using double-precision arithmetic.

        Data in TIFF_ASCII format will be parsed as by the Double.parseDouble method.

      • getAsString

        public java.lang.String getAsString​(int index)
        Returns a TIFFTag.TIFF_ASCII value as a String.
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_ASCII.
      • getAsSRational

        public int[] getAsSRational​(int index)
        Returns a TIFFTag.TIFF_SRATIONAL data item as a two-element array of ints.
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_SRATIONAL.
      • getAsRational

        public long[] getAsRational​(int index)
        Returns a TIFFTag.TIFF_RATIONAL data item as a two-element array of ints.
        Throws:
        java.lang.ClassCastException - if the field is not of type TIFF_RATIONAL.
      • getValueAsString

        public java.lang.String getValueAsString​(int index)
        Returns a String containing a human-readable version of the data item. Data of type TIFFTag.TIFF_RATIONAL or TIFF_SRATIONAL are represented as a pair of integers separated by a '/' character.
        Throws:
        java.lang.ClassCastException - if the field is not of one of the legal field types.
      • compareTo

        public int compareTo​(java.lang.Object o)
        Compares this TIFFField with another TIFFField by comparing the tags.

        Note: this class has a natural ordering that is inconsistent with equals().

        Specified by:
        compareTo in interface java.lang.Comparable
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
        java.lang.ClassCastException - if the parameter is not a TIFFField.