Class TiffParser

java.lang.Object
loci.formats.tiff.TiffParser
All Implemented Interfaces:
Closeable, AutoCloseable

public class TiffParser extends Object implements Closeable
Parses TIFF data from an input source.
  • Field Details

  • Constructor Details

    • TiffParser

      public TiffParser(String filename) throws IOException
      Constructs a new TIFF parser from the given file name.
      Throws:
      IOException
    • TiffParser

      public TiffParser(RandomAccessInputStream in)
      Constructs a new TIFF parser from the given input source.
  • Method Details

    • close

      public void close() throws IOException
      Close the underlying stream, if this TiffParser was constructed with a file path. Closing a stream that was pre-initialized is potentially dangerous.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • setAssumeEqualStrips

      public void setAssumeEqualStrips(boolean equalStrips)
      Sets whether or not to assume that strips are of equal size.
      Parameters:
      equalStrips - Whether or not the strips are of equal size.
    • setCodecOptions

      public void setCodecOptions(loci.formats.codec.CodecOptions codecOptions)
      Sets the codec options to be used when decompressing pixel data.
      Parameters:
      codecOptions - Codec options to use.
    • getCodecOptions

      public loci.formats.codec.CodecOptions getCodecOptions()
      Retrieves the current set of codec options being used to decompress pixel data.
      Returns:
      See above.
    • setDoCaching

      public void setDoCaching(boolean doCaching)
      Sets whether or not IFD entries should be cached.
    • setUse64BitOffsets

      public void setUse64BitOffsets(boolean use64Bit)
      Sets whether or not 64-bit offsets are used for non-BigTIFF files.
    • setYCbCrCorrection

      public void setYCbCrCorrection(boolean correctionAllowed)
      Sets whether or not YCbCr color correction is allowed.
    • setEncoding

      public void setEncoding(String encoding)
      Sets the encoding to use for tags with ASCII values. Defaults to UTF-8 if unset.
    • getStream

      public RandomAccessInputStream getStream()
      Gets the stream from which TIFF data is being parsed.
    • isValidHeader

      public boolean isValidHeader()
      Tests this stream to see if it represents a TIFF file.
    • checkHeader

      public Boolean checkHeader() throws IOException
      Checks the TIFF header.
      Returns:
      true if little-endian, false if big-endian, or null if not a TIFF.
      Throws:
      IOException
    • isBigTiff

      public boolean isBigTiff()
      Returns whether or not the current TIFF file contains BigTIFF data.
    • getMainIFDs

      public IFDList getMainIFDs() throws IOException
      Returns the main list of IFDs in the file. This does not include SUBIFDS.
      Throws:
      IOException
    • getSubIFDs

      public IFDList getSubIFDs(IFD ifd) throws IOException
      Returns the SUBIFDS belonging to a given IFD.
      Throws:
      IOException
    • getIFDs

      @Deprecated public IFDList getIFDs() throws IOException
      Deprecated.
      Returns all IFDs in the file, including SUBIFDS.
      Throws:
      IOException
    • getThumbnailIFDs

      public IFDList getThumbnailIFDs() throws IOException
      Returns thumbnail IFDs.
      Throws:
      IOException
    • getNonThumbnailIFDs

      public IFDList getNonThumbnailIFDs() throws IOException
      Returns non-thumbnail IFDs.
      Throws:
      IOException
    • getExifIFDs

      public IFDList getExifIFDs() throws loci.formats.FormatException, IOException
      Returns EXIF IFDs.
      Throws:
      loci.formats.FormatException
      IOException
    • getIFDOffsets

      public long[] getIFDOffsets() throws IOException
      Gets the offsets to every IFD in the file.
      Throws:
      IOException
    • getFirstIFD

      public IFD getFirstIFD() throws IOException
      Gets the first IFD within the TIFF file, or null if the input source is not a valid TIFF file.
      Throws:
      IOException
    • getFirstIFDEntry

      public TiffIFDEntry getFirstIFDEntry(int tag) throws IOException
      Retrieve a given entry from the first IFD in the stream.
      Parameters:
      tag - the tag of the entry to be retrieved.
      Returns:
      an object representing the entry's fields.
      Throws:
      IOException - when there is an error accessing the stream.
      IllegalArgumentException - when the tag number is unknown.
    • getFirstOffset

      public long getFirstOffset() throws IOException
      Gets offset to the first IFD, or -1 if stream is not TIFF.
      Throws:
      IOException
    • getIFD

      public IFD getIFD(long offset) throws IOException
      Gets the IFD stored at the given offset.
      Throws:
      IOException
    • fillInIFD

      public void fillInIFD(IFD ifd) throws IOException
      Fill in IFD entries that are stored at an arbitrary offset.
      Throws:
      IOException
    • getIFDValue

      public Object getIFDValue(TiffIFDEntry entry) throws IOException
      Retrieve the value corresponding to the given TiffIFDEntry.
      Throws:
      IOException
    • getComment

      public String getComment() throws IOException
      Convenience method for obtaining a stream's first ImageDescription.
      Throws:
      IOException
    • getColorMap

      public int[] getColorMap(IFD ifd) throws IOException
      Retrieve the color map associated with the given IFD.
      Throws:
      IOException
    • getTile

      public byte[] getTile(IFD ifd, byte[] buf, int row, int col) throws loci.formats.FormatException, IOException
      Throws:
      loci.formats.FormatException
      IOException
    • getSamples

      public byte[] getSamples(IFD ifd, byte[] buf) throws loci.formats.FormatException, IOException
      Throws:
      loci.formats.FormatException
      IOException
    • getSamples

      public byte[] getSamples(IFD ifd, byte[] buf, int x, int y, long width, long height) throws loci.formats.FormatException, IOException
      Throws:
      loci.formats.FormatException
      IOException
    • getSamples

      public byte[] getSamples(IFD ifd, byte[] buf, int x, int y, long width, long height, int overlapX, int overlapY) throws loci.formats.FormatException, IOException
      Throws:
      loci.formats.FormatException
      IOException
    • unpackBytes

      public static void unpackBytes(byte[] samples, int startIndex, byte[] bytes, IFD ifd) throws loci.formats.FormatException
      Extracts pixel information from the given byte array according to the bits per sample, photometric interpretation and color map IFD directory entry values, and the specified byte ordering. No error checking is performed.
      Throws:
      loci.formats.FormatException