Class IFD

All Implemented Interfaces:
Serializable, Cloneable, Map<Integer,Object>

public class IFD extends HashMap<Integer,Object>
Data structure for working with TIFF Image File Directories (IFDs).
Author:
Curtis Rueden ctrueden at wisc.edu, Eric Kjellman egkjellman at wisc.edu, Melissa Linkert melissa at glencoesoftware.com, Chris Allan callan at blackcat.ca
See Also:
  • Field Details

  • Constructor Details

    • IFD

      public IFD()
    • IFD

      public IFD(IFD ifd)
  • Method Details

    • getByteCount

      public long getByteCount(boolean bigTiff) throws FormatException
      Get the maximum number of bytes needed to represent this IFD.
      Throws:
      FormatException
    • isBigTiff

      public boolean isBigTiff() throws FormatException
      Gets whether this is a BigTIFF IFD.
      Throws:
      FormatException
    • isLittleEndian

      public boolean isLittleEndian() throws FormatException
      Gets whether the TIFF information in this IFD is little-endian.
      Throws:
      FormatException
    • getIFDValue

      public Object getIFDValue(int tag)
      Gets the given directory entry value from this IFD.
    • getIFDValue

      public Object getIFDValue(int tag, Class checkClass) throws FormatException
      Gets the given directory entry value from this IFD, performing some error checking.
      Throws:
      FormatException
    • getIFDLongValue

      public long getIFDLongValue(int tag, long defaultValue) throws FormatException
      Gets the given directory entry value in long format from this IFD, performing some error checking.
      Throws:
      FormatException
    • getIFDIntValue

      public int getIFDIntValue(int tag)
      Gets the given directory entry value in int format from this IFD, or -1 if the given directory does not exist.
    • getIFDIntValue

      public int getIFDIntValue(int tag, int defaultValue) throws FormatException
      Gets the given directory entry value in int format from this IFD, performing some error checking.
      Throws:
      FormatException
    • getIFDRationalValue

      public TiffRational getIFDRationalValue(int tag) throws FormatException
      Gets the given directory entry value in rational format from this IFD, performing some error checking.
      Throws:
      FormatException
    • getIFDStringValue

      public String getIFDStringValue(int tag) throws FormatException
      Gets the given directory entry value as a string from this IFD, performing some error checking.
      Throws:
      FormatException
    • getIFDTextValue

      public String getIFDTextValue(int tag)
      Gets the given directory entry value as a string (regardless of type).
    • getIFDLongArray

      public long[] getIFDLongArray(int tag) throws FormatException
      Gets the given directory entry values in long format from this IFD, performing some error checking.
      Throws:
      FormatException
    • getIFDIntArray

      public int[] getIFDIntArray(int tag) throws FormatException
      Gets the given directory entry values in int format from this IFD, performing some error checking.
      Throws:
      FormatException
    • getIFDShortArray

      public short[] getIFDShortArray(int tag) throws FormatException
      Gets the given directory entry values in short format from this IFD, performing some error checking.
      Throws:
      FormatException
    • getComment

      public String getComment()
      Convenience method for obtaining the ImageDescription from this IFD.
    • getTileWidth

      public long getTileWidth() throws FormatException
      Returns the width of an image tile.
      Throws:
      FormatException
    • getTileLength

      public long getTileLength() throws FormatException
      Returns the length of an image tile.
      Throws:
      FormatException
    • getTilesPerRow

      public long getTilesPerRow() throws FormatException
      Returns the number of image tiles per row.
      Throws:
      FormatException
    • getTilesPerColumn

      public long getTilesPerColumn() throws FormatException
      Returns the number of image tiles per column.
      Throws:
      FormatException
    • isTiled

      public boolean isTiled() throws FormatException
      Throws:
      FormatException
    • getImageWidth

      public long getImageWidth() throws FormatException
      Retrieves the image's width (TIFF tag ImageWidth) from a given TIFF IFD.
      Returns:
      the image's width.
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
    • getImageLength

      public long getImageLength() throws FormatException
      Retrieves the image's length (TIFF tag ImageLength) from a given TIFF IFD.
      Returns:
      the image's length.
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
    • getBitsPerSample

      public int[] getBitsPerSample() throws FormatException
      Retrieves the image's bits per sample (TIFF tag BitsPerSample) from a given TIFF IFD.
      Returns:
      the image's bits per sample. The length of the array is equal to the number of samples per pixel.
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
      See Also:
    • getPixelType

      public int getPixelType() throws FormatException
      Retrieves the image's pixel type based on the BitsPerSample tag.
      Returns:
      the pixel type. This is one of:
    • FormatTools.INT8
    • FormatTools.UINT8
    • FormatTools.INT16
    • FormatTools.UINT16
    • FormatTools.INT32
    • FormatTools.UINT32
    • FormatTools.FLOAT
    • FormatTools.DOUBLE
    • Throws:
      FormatException - if there is a problem parsing the IFD metadata.
      See Also:
    • getBytesPerSample

      public int[] getBytesPerSample() throws FormatException
      Retrieves the image's bytes per sample (derived from tag BitsPerSample) from this IFD.
      Returns:
      the image's bytes per sample. The length of the array is equal to the number of samples per pixel.
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
      See Also:
    • getSamplesPerPixel

      public int getSamplesPerPixel() throws FormatException
      Retrieves the number of samples per pixel for the image (TIFF tag SamplesPerPixel) from this IFD.
      Returns:
      the number of samples per pixel.
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
    • getCompression

      public TiffCompression getCompression() throws FormatException
      Retrieves the image's compression type (TIFF tag Compression) from this IFD.
      Returns:
      the image's compression type. As of TIFF 6.0 this is one of:
      • Uncompressed (1)
      • CCITT 1D (2)
      • Group 3 Fax (3)
      • Group 4 Fax (4)
      • LZW (5)
      • JPEG (6)
      • PackBits (32773)
      Other proprietary compression types are also possible; see TiffCompression for more details.
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
    • getPhotometricInterpretation

      public PhotoInterp getPhotometricInterpretation() throws FormatException
      Retrieves the image's photometric interpretation (TIFF tag PhotometricInterpretation) from this IFD.
      Returns:
      the image's photometric interpretation. As of TIFF 6.0 this is one of:
      • WhiteIsZero (0)
      • BlackIsZero (1)
      • RGB (2)
      • RGB Palette (3)
      • Transparency mask (4)
      • CMYK (5)
      • YbCbCr (6)
      • CIELab (8)
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
    • getPlanarConfiguration

      public int getPlanarConfiguration() throws FormatException
      Retrieves the image's planar configuration (TIFF tag PlanarConfiguration) from this IFD.
      Returns:
      the image's planar configuration. As of TIFF 6.0 this is one of:
      • Chunky (1)
      • Planar (2)
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
    • getStripOffsets

      public long[] getStripOffsets() throws FormatException
      Retrieves the strip offsets for the image (TIFF tag StripOffsets) from this IFD.
      Returns:
      the strip offsets for the image. The length of the array is equal to the number of strips per image. StripsPerImage = floor ((ImageLength + RowsPerStrip - 1) / RowsPerStrip).
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
      See Also:
    • getOnDemandStripOffsets

      public OnDemandLongArray getOnDemandStripOffsets() throws FormatException
      Throws:
      FormatException
    • getStripByteCounts

      public long[] getStripByteCounts() throws FormatException
      Retrieves strip byte counts for the image (TIFF tag StripByteCounts) from this IFD.
      Returns:
      the byte counts for each strip. The length of the array is equal to the number of strips per image. StripsPerImage = floor((ImageLength + RowsPerStrip - 1) / RowsPerStrip).
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
      See Also:
    • getRowsPerStrip

      public long[] getRowsPerStrip() throws FormatException
      Retrieves the number of rows per strip for image (TIFF tag RowsPerStrip) from this IFD.
      Returns:
      the number of rows per strip.
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
    • getResolutionMultiplier

      public int getResolutionMultiplier()
      Retrieve the value by which to multiply the X and Y resolution so that the resolutions are in microns per pixel.
    • getXResolution

      public double getXResolution() throws FormatException
      Retrieve the X resolution (TIFF tag XResolution) from this IFD. The resolution will be normalized to microns per pixel.
      Returns:
      the X resolution, in microns per pixel
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
    • getYResolution

      public double getYResolution() throws FormatException
      Retrieve the Y resolution (TIFF tag YResolution) from this IFD. The resolution will be normalized to microns per pixel.
      Returns:
      the Y resolution, in microns per pixel
      Throws:
      FormatException - if there is a problem parsing the IFD metadata.
    • putIFDValue

      public void putIFDValue(int tag, Object value)
      Adds a directory entry to this IFD.
    • putIFDValue

      public void putIFDValue(int tag, short value)
      Adds a directory entry of type BYTE to this IFD.
    • putIFDValue

      public void putIFDValue(int tag, int value)
      Adds a directory entry of type SHORT to this IFD.
    • putIFDValue

      public void putIFDValue(int tag, long value)
      Adds a directory entry of type LONG to this IFD.
    • printIFD

      public void printIFD()
      Prints the contents of this IFD.
    • getIFDTagName

      public static String getIFDTagName(int tag)
      Gets the name of the IFD tag encoded by the given number.
    • getFieldName

      public static String getFieldName(int value)
      This method uses reflection to scan the values of this class's static fields, returning the first matching field's name. It is probably not very efficient, and is mainly intended for debugging.