Class TIFFField

java.lang.Object
com.itextpdf.io.codec.TIFFField
All Implemented Interfaces:
Comparable<TIFFField>

public class TIFFField extends Object implements Comparable<TIFFField>
A class representing a field in a TIFF 6.0 Image File Directory.

The TIFF file format is described in more detail in the comments for the TIFFDescriptor class.

A field in a TIFF Image File Directory (IFD). A field is defined as a sequence of values of identical data type. TIFF 6.0 defines 12 data types, which are mapped internally onto the Java data types byte, int, long, float, and double.

This class is not a committed part of the JAI API. It may be removed or changed in future releases of JAI.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Flag for null-terminated ASCII strings.
    static final int
    Flag for 8 bit unsigned integers.
    static final int
    Flag for 64 bit IEEE doubles.
    static final int
    Flag for 32 bit IEEE floats.
    static final int
    Flag for 32 bit unsigned integers.
    static final int
    Flag for pairs of 32 bit unsigned integers.
    static final int
    Flag for 8 bit signed integers.
    static final int
    Flag for 16 bit unsigned integers.
    static final int
    Flag for 32 bit signed integers.
    static final int
    Flag for pairs of 32 bit signed integers.
    static final int
    Flag for 16 bit signed integers.
    static final int
    Flag for 8 bit uninterpreted bytes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TIFFField(int tag, int type, int count, Object data)
    Constructs a TIFFField with arbitrary data.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares this TIFFField with another TIFFField by comparing the tags.
    byte[]
    Returns the data as an uninterpreted array of bytes.
    char[]
    Returns TIFF_SHORT data as an array of chars (unsigned 16-bit integers).
    double
    getAsDouble(int index)
    Returns data in any numerical format as a double.
    double[]
    Returns TIFF_DOUBLE data as an array of doubles.
    float
    getAsFloat(int index)
    Returns data in any numerical format as a float.
    float[]
    Returns TIFF_FLOAT data as an array of floats.
    int
    getAsInt(int index)
    Returns data in TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SHORT, TIFF_SSHORT, or TIFF_SLONG format as an int.
    int[]
    Returns TIFF_SLONG data as an array of ints (signed 32-bit integers).
    long
    getAsLong(int index)
    Returns data in TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SHORT, TIFF_SSHORT, TIFF_SLONG, or TIFF_LONG format as a long.
    long[]
    Returns TIFF_LONG data as an array of longs (signed 64-bit integers).
    long[]
    getAsRational(int index)
    Returns a TIFF_RATIONAL data item as a two-element array of ints.
    long[][]
    Returns TIFF_RATIONAL data as an array of 2-element arrays of longs.
    short[]
    Returns TIFF_SSHORT data as an array of shorts (signed 16-bit integers).
    int[]
    getAsSRational(int index)
    Returns a TIFF_SRATIONAL data item as a two-element array of ints.
    int[][]
    Returns TIFF_SRATIONAL data as an array of 2-element arrays of ints.
    getAsString(int index)
    Returns a TIFF_ASCII data item as a String.
    String[]
    Returns TIFF_ASCII data as an array of strings.
    int
    Returns the number of elements in the IFD.
    int
    getTag()
    Returns the tag number
    int
    Returns the type of the data stored in the IFD.

    Methods inherited from class java.lang.Object

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

    • TIFF_BYTE

      public static final int TIFF_BYTE
      Flag for 8 bit unsigned integers.
      See Also:
    • TIFF_ASCII

      public static final int TIFF_ASCII
      Flag for null-terminated ASCII strings.
      See Also:
    • TIFF_SHORT

      public static final int TIFF_SHORT
      Flag for 16 bit unsigned integers.
      See Also:
    • TIFF_LONG

      public static final int TIFF_LONG
      Flag for 32 bit unsigned integers.
      See Also:
    • TIFF_RATIONAL

      public static final int TIFF_RATIONAL
      Flag for pairs of 32 bit unsigned integers.
      See Also:
    • TIFF_SBYTE

      public static final int TIFF_SBYTE
      Flag for 8 bit signed integers.
      See Also:
    • TIFF_UNDEFINED

      public static final int TIFF_UNDEFINED
      Flag for 8 bit uninterpreted bytes.
      See Also:
    • TIFF_SSHORT

      public static final int TIFF_SSHORT
      Flag for 16 bit signed integers.
      See Also:
    • TIFF_SLONG

      public static final int TIFF_SLONG
      Flag for 32 bit signed integers.
      See Also:
    • TIFF_SRATIONAL

      public static final int TIFF_SRATIONAL
      Flag for pairs of 32 bit signed integers.
      See Also:
    • TIFF_FLOAT

      public static final int TIFF_FLOAT
      Flag for 32 bit IEEE floats.
      See Also:
    • TIFF_DOUBLE

      public static final int TIFF_DOUBLE
      Flag for 64 bit IEEE doubles.
      See Also:
  • Constructor Details

    • TIFFField

      public TIFFField (int tag, int type, int count, Object data)
      Constructs a TIFFField with arbitrary data. The data parameter must be an array of a Java type appropriate for the type of the TIFF field. Since there is no available 32-bit unsigned data type, long is used. The mapping between types is as follows:
      TIFF type Java type
      TIFF_BYTE byte
      TIFF_ASCII String
      TIFF_SHORT char
      TIFF_LONG long
      TIFF_RATIONAL long[2]
      TIFF_SBYTE byte
      TIFF_UNDEFINED byte
      TIFF_SSHORT short
      TIFF_SLONG int
      TIFF_SRATIONAL int[2]
      TIFF_FLOAT float
      TIFF_DOUBLE double
      Parameters:
      tag - the tag number
      type - the tag type
      count - the number of data items present in the field
      data - the field data
  • Method Details

    • getTag

      public int getTag()
      Returns the tag number
      Returns:
      the tag number, between 0 and 65535.
    • getType

      public int getType()
      Returns the type of the data stored in the IFD. For a TIFF6.0 file, the value will equal one of the TIFF_ constants defined in this class. For future revisions of TIFF, higher values are possible.
      Returns:
      The type of the data stored in the IFD
    • getCount

      public int getCount()
      Returns the number of elements in the IFD.
      Returns:
      The number of elements in the IFD
    • getAsBytes

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

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

      A ClassCastException will be thrown if the field is not of type TIFF_BYTE, TIFF_SBYTE, or TIFF_UNDEFINED.

      Returns:
      the data as an uninterpreted array of bytes
    • getAsChars

      public char[] getAsChars()
      Returns TIFF_SHORT data as an array of chars (unsigned 16-bit integers).

      A ClassCastException will be thrown if the field is not of type TIFF_SHORT.

      Returns:
      TIFF_SHORT data as an array of chars
    • getAsShorts

      public short[] getAsShorts()
      Returns TIFF_SSHORT data as an array of shorts (signed 16-bit integers).

      A ClassCastException will be thrown if the field is not of type TIFF_SSHORT.

      Returns:
      TIFF_SSHORT data as an array of shorts (signed 16-bit integers).
    • getAsInts

      public int[] getAsInts()
      Returns TIFF_SLONG data as an array of ints (signed 32-bit integers).

      A ClassCastException will be thrown if the field is not of type TIFF_SLONG.

      Returns:
      TIFF_SLONG data as an array of ints (signed 32-bit integers).
    • getAsLongs

      public long[] getAsLongs()
      Returns TIFF_LONG data as an array of longs (signed 64-bit integers).

      A ClassCastException will be thrown if the field is not of type TIFF_LONG.

      Returns:
      TIFF_LONG data as an array of longs (signed 64-bit integers).
    • getAsFloats

      public float[] getAsFloats()
      Returns TIFF_FLOAT data as an array of floats.

      A ClassCastException will be thrown if the field is not of type TIFF_FLOAT.

      Returns:
      TIFF_FLOAT data as an array of floats.
    • getAsDoubles

      public double[] getAsDoubles()
      Returns TIFF_DOUBLE data as an array of doubles.

      A ClassCastException will be thrown if the field is not of type TIFF_DOUBLE.

      Returns:
      TIFF_DOUBLE data as an array of doubles.
    • getAsStrings

      public String[] getAsStrings()
      Returns TIFF_ASCII data as an array of strings.

      A ClassCastException will be thrown if the field is not of type TIFF_ASCII.

      Returns:
      TIFF_ASCII data as an array of strings.
    • getAsSRationals

      public int[][] getAsSRationals()
      Returns TIFF_SRATIONAL data as an array of 2-element arrays of ints.

      A ClassCastException will be thrown if the field is not of type TIFF_SRATIONAL.

      Returns:
      TIFF_SRATIONAL data as an array of 2-element arrays of ints.
    • getAsRationals

      public long[][] getAsRationals()
      Returns TIFF_RATIONAL data as an array of 2-element arrays of longs.

      A ClassCastException will be thrown if the field is not of type TIFF_RATTIONAL.

      Returns:
      TIFF_RATIONAL data as an array of 2-element arrays of longs.
    • getAsInt

      public int getAsInt (int index)
      Returns data in TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SHORT, TIFF_SSHORT, or TIFF_SLONG format as an int.

      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].

      A ClassCastException will be thrown if the field is not of type TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SHORT, TIFF_SSHORT, or TIFF_SLONG.

      Parameters:
      index - The index
      Returns:
      data in TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SHORT, TIFF_SSHORT, or TIFF_SLONG format as an int.
    • getAsLong

      public long getAsLong (int index)
      Returns data in TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SHORT, TIFF_SSHORT, TIFF_SLONG, or TIFF_LONG format as a long.

      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].

      A ClassCastException will be thrown if the field is not of type TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SHORT, TIFF_SSHORT, TIFF_SLONG, or TIFF_LONG.

      Parameters:
      index - The index
      Returns:
      data in TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SHORT, TIFF_SSHORT, TIFF_SLONG, or TIFF_LONG format as a long.
    • getAsFloat

      public float getAsFloat (int index)
      Returns data in any numerical format as a float. Data in TIFF_SRATIONAL or TIFF_RATIONAL format are evaluated by dividing the numerator into the denominator using double-precision arithmetic and then truncating to single precision. Data in TIFF_SLONG, TIFF_LONG, or TIFF_DOUBLE format may suffer from truncation.

      A ClassCastException will be thrown if the field is of type TIFF_UNDEFINED or TIFF_ASCII.

      Parameters:
      index - The index
      Returns:
      data in any numerical format as a float.
    • getAsDouble

      public double getAsDouble (int index)
      Returns data in any numerical format as a double. Data in TIFF_SRATIONAL or TIFF_RATIONAL format are evaluated by dividing the numerator into the denominator using double-precision arithmetic.

      A ClassCastException will be thrown if the field is of type TIFF_UNDEFINED or TIFF_ASCII.

      Parameters:
      index - The index
      Returns:
      data in any numerical format as a double.
    • getAsString

      public String getAsString (int index)
      Returns a TIFF_ASCII data item as a String.

      A ClassCastException will be thrown if the field is not of type TIFF_ASCII.

      Parameters:
      index - The index
      Returns:
      a TIFF_ASCII data item as a String.
    • getAsSRational

      public int[] getAsSRational (int index)
      Returns a TIFF_SRATIONAL data item as a two-element array of ints.

      A ClassCastException will be thrown if the field is not of type TIFF_SRATIONAL.

      Parameters:
      index - The index
      Returns:
      a TIFF_SRATIONAL data item as a two-element array of ints.
    • getAsRational

      public long[] getAsRational (int index)
      Returns a TIFF_RATIONAL data item as a two-element array of ints.

      A ClassCastException will be thrown if the field is not of type TIFF_RATIONAL.

      Parameters:
      index - The index
      Returns:
      a TIFF_RATIONAL data item as a two-element array of ints
    • compareTo

      public int compareTo (TIFFField 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 Comparable<TIFFField>
      Throws:
      IllegalArgumentException - if the parameter is null.