Package loci.formats.tiff
Class TiffParser
java.lang.Object
loci.formats.tiff.TiffParser
- All Implemented Interfaces:
Closeable,AutoCloseable
Parses TIFF data from an input source.
- 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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether or not the TIFF file contains BigTIFF data.private byte[]Cached tile buffer to avoid re-allocations when reading tiles.private booleanprivate CodecOptionsCodec options to be used when decoding compressed pixel data.private booleanprivate booleanprivate booleanWhether or not 64-bit offsets are used for non-BigTIFF files.private IFDCached first IFD in the current file.private IFDListCached list of IFDs in the current file.protected loci.common.RandomAccessInputStreamInput source from which to parse TIFF data.private static final org.slf4j.Loggerprivate Stringprivate boolean -
Constructor Summary
ConstructorsConstructorDescriptionTiffParser(String filename) Constructs a new TIFF parser from the given file name.TiffParser(loci.common.RandomAccessInputStream in) Constructs a new TIFF parser from the given input source. -
Method Summary
Modifier and TypeMethodDescriptionChecks the TIFF header.voidclose()Close the underlying stream, if this TiffParser was constructed with a file path.voidFill in IFD entries that are stored at an arbitrary offset.Retrieves the current set of codec options being used to decompress pixel data.int[]getColorMap(IFD ifd) Retrieve the color map associated with the given IFD.Convenience method for obtaining a stream's first ImageDescription.Returns EXIF IFDs.Gets the first IFD within the TIFF file, or null if the input source is not a valid TIFF file.getFirstIFDEntry(int tag) Retrieve a given entry from the first IFD in the stream.longGets offset to the first IFD, or -1 if stream is not TIFF.getIFD(long offset) Gets the IFD stored at the given offset.long[]Gets the offsets to every IFD in the file.getIFDs()Deprecated.getIFDValue(TiffIFDEntry entry) Retrieve the value corresponding to the given TiffIFDEntry.Returns the main list of IFDs in the file.(package private) longgetNextOffset(long previous) Read a file offset.Returns non-thumbnail IFDs.byte[]getSamples(IFD ifd, byte[] buf) byte[]getSamples(IFD ifd, byte[] buf, int x, int y, long width, long height) byte[]getSamples(IFD ifd, byte[] buf, int x, int y, long width, long height, int overlapX, int overlapY) loci.common.RandomAccessInputStreamGets the stream from which TIFF data is being parsed.getSubIFDs(IFD ifd) Returns the SUBIFDS belonging to a given IFD.Returns thumbnail IFDs.byte[]booleanReturns whether or not the current TIFF file contains BigTIFF data.booleanTests this stream to see if it represents a TIFF file.(package private) TiffIFDEntryvoidsetAssumeEqualStrips(boolean equalStrips) Sets whether or not to assume that strips are of equal size.voidsetCodecOptions(CodecOptions codecOptions) Sets the codec options to be used when decompressing pixel data.voidsetDoCaching(boolean doCaching) Sets whether or not IFD entries should be cached.voidsetEncoding(String encoding) Sets the encoding to use for tags with ASCII values.voidsetUse64BitOffsets(boolean use64Bit) Sets whether or not 64-bit offsets are used for non-BigTIFF files.voidsetYCbCrCorrection(boolean correctionAllowed) Sets whether or not YCbCr color correction is allowed.static voidunpackBytes(byte[] samples, int startIndex, byte[] bytes, IFD ifd) 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.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
in
protected transient loci.common.RandomAccessInputStream inInput source from which to parse TIFF data. -
cachedTileBuffer
private byte[] cachedTileBufferCached tile buffer to avoid re-allocations when reading tiles. -
bigTiff
private boolean bigTiffWhether or not the TIFF file contains BigTIFF data. -
fakeBigTiff
private boolean fakeBigTiffWhether or not 64-bit offsets are used for non-BigTIFF files. -
ycbcrCorrection
private boolean ycbcrCorrection -
equalStrips
private boolean equalStrips -
doCaching
private boolean doCaching -
ifdList
Cached list of IFDs in the current file. -
firstIFD
Cached first IFD in the current file. -
codecOptions
Codec options to be used when decoding compressed pixel data. -
canClose
private boolean canClose -
tagEncoding
-
-
Constructor Details
-
TiffParser
Constructs a new TIFF parser from the given file name.- Throws:
IOException
-
TiffParser
public TiffParser(loci.common.RandomAccessInputStream in) Constructs a new TIFF parser from the given input source.
-
-
Method Details
-
close
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- 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
Sets the codec options to be used when decompressing pixel data.- Parameters:
codecOptions- Codec options to use.
-
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
Sets the encoding to use for tags with ASCII values. Defaults to UTF-8 if unset. -
getStream
public loci.common.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
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
Returns the main list of IFDs in the file. This does not include SUBIFDS.- Throws:
IOException
-
getSubIFDs
Returns the SUBIFDS belonging to a given IFD.- Throws:
IOException
-
getIFDs
Deprecated.UsegetMainIFDs()andgetSubIFDs(IFD)instead.Returns all IFDs in the file, including SUBIFDS.- Throws:
IOException
-
getThumbnailIFDs
Returns thumbnail IFDs.- Throws:
IOException
-
getNonThumbnailIFDs
Returns non-thumbnail IFDs.- Throws:
IOException
-
getExifIFDs
Returns EXIF IFDs.- Throws:
FormatExceptionIOException
-
getIFDOffsets
Gets the offsets to every IFD in the file.- Throws:
IOException
-
getFirstIFD
Gets the first IFD within the TIFF file, or null if the input source is not a valid TIFF file.- Throws:
IOException
-
getFirstIFDEntry
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
Gets offset to the first IFD, or -1 if stream is not TIFF.- Throws:
IOException
-
getIFD
Gets the IFD stored at the given offset.- Throws:
IOException
-
fillInIFD
Fill in IFD entries that are stored at an arbitrary offset.- Throws:
IOException
-
getIFDValue
Retrieve the value corresponding to the given TiffIFDEntry.- Throws:
IOException
-
getComment
Convenience method for obtaining a stream's first ImageDescription.- Throws:
IOException
-
getColorMap
Retrieve the color map associated with the given IFD.- Throws:
IOException
-
getTile
- Throws:
FormatExceptionIOException
-
getSamples
- Throws:
FormatExceptionIOException
-
getSamples
public byte[] getSamples(IFD ifd, byte[] buf, int x, int y, long width, long height) throws FormatException, IOException - Throws:
FormatExceptionIOException
-
getSamples
public byte[] getSamples(IFD ifd, byte[] buf, int x, int y, long width, long height, int overlapX, int overlapY) throws FormatException, IOException - Throws:
FormatExceptionIOException
-
unpackBytes
public static void unpackBytes(byte[] samples, int startIndex, byte[] bytes, IFD ifd) throws 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:
FormatException
-
getNextOffset
Read a file offset. For bigTiff, a 64-bit number is read. For other Tiffs, a 32-bit number is read and possibly adjusted for a possible carry-over from the previous offset.- Throws:
IOException
-
readTiffIFDEntry
- Throws:
IOException
-
getMainIFDs()andgetSubIFDs(IFD)instead.