Class TIFFImageReader
java.lang.Object
javax.imageio.ImageReader
com.twelvemonkeys.imageio.ImageReaderBase
com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader
ImageReader implementation for Aldus/Adobe Tagged Image File Format (TIFF).
The reader is supposed to be fully "Baseline TIFF" compliant, and supports the following image types:
- Class B (Bi-level), all relevant compression types, 1 bit per sample
- Class G (Gray), all relevant compression types, 2, 4, 8, 16 or 32 bits per sample, unsigned integer
- Class P (Palette/indexed color), all relevant compression types, 1, 2, 4, 8 or 16 bits per sample, unsigned integer
- Class R (RGB), all relevant compression types, 8 or 16 bits per sample, unsigned integer
- Tiling
- Class F (Facsimile), CCITT T.4 and T.6 compression (types 3 and 4), 1 bit per sample
- LZW Compression (type 5)
- "Old-style" JPEG Compression (type 6), as a best effort, as the spec is not well-defined
- JPEG Compression (type 7)
- ZLib (aka Adobe-style Deflate) Compression (type 8)
- Deflate Compression (type 32946)
- Horizontal differencing Predictor (type 2) for LZW, ZLib, Deflate and PackBits compression
- Alpha channel (ExtraSamples types 1/Associated Alpha and 2/Unassociated Alpha)
- Class S, CMYK data (PhotometricInterpretation type 5/Separated)
- Class Y, YCbCr data (PhotometricInterpretation type 6/YCbCr for both JPEG and other compressions
- Planar data (PlanarConfiguration type 2/Planar)
- ICC profiles (ICCProfile)
- BitsPerSample values up to 16 for most PhotometricInterpretations
- Multiple images (pages) in one file
- Version:
- $Id: TIFFImageReader.java,v 1.0 08.05.12 15:14 haraldk Exp$
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final double[]
private Directory
(package private) static final boolean
private CompoundDirectory
private int
(package private) static final double[]
Fields inherited from class com.twelvemonkeys.imageio.ImageReaderBase
imageInput
Fields inherited from class javax.imageio.ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
private void
clamp
(float[] rowDataFloat) private short
clampShort
(int val) private Raster
clipRowToRect
(Raster raster, Rectangle rect, int[] bands, int xSub) private WritableRaster
clipToRect
(WritableRaster raster, Rectangle rect, int[] bands) private Rectangle
computeTileRegion
(int imageIndex, int tileX, int tileY) private boolean
containsZero
(long[] byteCounts) private void
convertYCbCr2RGB
(short[] yCbCr, short[] rgb, double[] coefficients, double[] referenceBW, int offset) private InputStream
createDecompressorStream
(int compression, int width, int bands, InputStream stream) private InputStream
createFillOrderStream
(int fillOrder, InputStream stream) private ImageTypeSpecifier
createImageTypeSpecifier
(int planarConfiguration, ColorSpace cs, int dataType, int significantSamples, int samplesPerPixel, boolean alpha, boolean alphaPremultiplied) private IndexColorModel
createIndexColorModel
(int bitsPerSample, int dataType, int[] cmapShort) private static InputStream
createJFIFStream
(int bands, int stripTileWidth, int stripTileHeight, byte[][] qTables, byte[][] dcTables, byte[][] acTables, int subsampling) private ImageReader
private static int[]
createOffsets
(int samplesPerPixel) private InputStream
createUnpredictorStream
(int predictor, int width, int samplesPerPixel, int bitsPerSample, InputStream stream, ByteOrder byteOrder) private InputStream
createYCbCrUpsamplerStream
(int photometricInterpretation, int planarConfiguration, int plane, int transferType, int[] yCbCrSubsampling, int yCbCrPos, int colsInTile, InputStream stream, ByteOrder byteOrder) private int
findCCITTType
(int encodedCompression, InputStream stream) private int
private long
getCCITTOptions
(int compression) private int
getDataType
(int sampleFormat, int bitsPerSample) int
getHeight
(int imageIndex) private ICC_Profile
getImageMetadata
(int imageIndex) Default implementation that always returnsnull
.getImageTypes
(int imageIndex) private int
getJPEGSourceCS
(IIOMetadata imageMetadata) private IIOMetadataNode
getNode
(IIOMetadataNode parent, String tagName) int
getNumImages
(boolean allowSearch) Default implementation that always returns1
.private int
getOpaqueSamplesPerPixel
(int photometricInterpretation) private int
getRawImageType
(int imageIndex) private int
Default implementation that always returnsnull
.int
getTileHeight
(int imageIndex) int
getTileWidth
(int imageIndex) private double[]
getValueAsDoubleArray
(int tag, String tagName, boolean required, int expectedLength) private int
getValueAsInt
(int tag, String tagName) private int
getValueAsIntWithDefault
(int tag, Integer defaultValue) private int
getValueAsIntWithDefault
(int tag, String tagName, Integer defaultValue) private long[]
getValueAsLongArray
(int tag, String tagName, boolean required) private long
getValueAsLongWithDefault
(int tag, Long defaultValue) private long
getValueAsLongWithDefault
(int tag, String tagName, Long defaultValue) private Number
getValueAsNumberWithDefault
(int tag, String tagName, Number defaultValue) int
getWidth
(int imageIndex) (package private) static int
guessPhotometricInterpretation
(int compression, int samplesPerPixel, Entry extraSamples, Entry colorMap) (package private) static String
intToStr
(int value) boolean
isImageTiled
(int imageIndex) static void
private boolean
needsCSConversion
(int compression, int photometricInterpretation, IIOMetadata imageMetadata) private void
normalizeColor
(int photometricInterpretation, int numBands, byte[] data) private void
normalizeColor
(int photometricInterpretation, int numBands, float[] data) private void
normalizeColor
(int photometricInterpretation, int numBands, int[] data) private void
normalizeColor
(int photometricInterpretation, int numBands, short[] data) private void
normalizeColorPlanar
(int photometricInterpretation, WritableRaster raster) read
(int imageIndex, ImageReadParam param) private void
readIFD
(int imageIndex) private IIOMetadata
readJPEGMetadataSafe
(ImageReader jpegReader) private void
(package private) static String
readPascalString
(DataInput pInput) readRaster
(int imageIndex, ImageReadParam param) private void
readStripTileData
(Raster tileRowRaster, Rectangle srcRegion, int xSub, int ySub, int band, int numBands, int interpretation, WritableRaster raster, int startCol, int startRow, int colsInTile, int rowsInTile, ImageInputStream input) readTile
(int imageIndex, int tileX, int tileY) readTileRaster
(int imageIndex, int tileX, int tileY) private static void
protected void
Resets all member variables.protected static void
showIt
(BufferedImage image, String title) private void
toFloat
(short[] rowDataShort, float[] rowDataFloat) Methods inherited from class com.twelvemonkeys.imageio.ImageReaderBase
assertInput, checkBounds, dispose, fakeAOI, fakeSubsampling, getDestination, hasExplicitDestination, reset, setInput
Methods inherited from class javax.imageio.ImageReader
abort, abortRequested, addIIOReadProgressListener, addIIOReadUpdateListener, addIIOReadWarningListener, checkReadParamBandSettings, clearAbortRequest, computeRegions, getAspectRatio, getAvailableLocales, getDefaultReadParam, getFormatName, getImageMetadata, getInput, getLocale, getMinIndex, getNumThumbnails, getOriginatingProvider, getSourceRegion, getStreamMetadata, getThumbnailHeight, getThumbnailWidth, getTileGridXOffset, getTileGridYOffset, hasThumbnails, isIgnoringMetadata, isRandomAccessEasy, isSeekForwardOnly, processImageComplete, processImageProgress, processImageStarted, processImageUpdate, processPassComplete, processPassStarted, processReadAborted, processSequenceComplete, processSequenceStarted, processThumbnailComplete, processThumbnailPassComplete, processThumbnailPassStarted, processThumbnailProgress, processThumbnailStarted, processThumbnailUpdate, processWarningOccurred, processWarningOccurred, read, readAll, readAll, readAsRenderedImage, readerSupportsThumbnails, readThumbnail, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, setInput, setInput, setLocale
-
Field Details
-
DEBUG
static final boolean DEBUG -
CCIR_601_1_COEFFICIENTS
static final double[] CCIR_601_1_COEFFICIENTS -
REFERENCE_BLACK_WHITE_YCC_DEFAULT
static final double[] REFERENCE_BLACK_WHITE_YCC_DEFAULT -
IFDs
-
currentIFD
-
overrideCCITTCompression
private int overrideCCITTCompression -
BYTE_TO_UNDEFINED_NODES
-
-
Constructor Details
-
TIFFImageReader
TIFFImageReader(ImageReaderSpi provider)
-
-
Method Details
-
resetMembers
protected void resetMembers()Description copied from class:ImageReaderBase
Resets all member variables. This method is by default invoked from:- Specified by:
resetMembers
in classImageReaderBase
-
readMetadata
- Throws:
IOException
-
readPascalString
- Throws:
IOException
-
intToStr
-
readIFD
- Throws:
IOException
-
getNumImages
Description copied from class:ImageReaderBase
Default implementation that always returns1
.- Overrides:
getNumImages
in classImageReaderBase
- Parameters:
allowSearch
- ignored, unless overridden- Returns:
1
, unless overridden- Throws:
IOException
- never, unless overridden
-
getValueAsNumberWithDefault
private Number getValueAsNumberWithDefault(int tag, String tagName, Number defaultValue) throws IIOException - Throws:
IIOException
-
getValueAsLongWithDefault
private long getValueAsLongWithDefault(int tag, String tagName, Long defaultValue) throws IIOException - Throws:
IIOException
-
getValueAsLongWithDefault
- Throws:
IIOException
-
getValueAsIntWithDefault
private int getValueAsIntWithDefault(int tag, String tagName, Integer defaultValue) throws IIOException - Throws:
IIOException
-
getValueAsIntWithDefault
- Throws:
IIOException
-
getValueAsInt
- Throws:
IIOException
-
getWidth
- Specified by:
getWidth
in classImageReader
- Throws:
IOException
-
getHeight
- Specified by:
getHeight
in classImageReader
- Throws:
IOException
-
getRawImageType
- Overrides:
getRawImageType
in classImageReader
- Throws:
IOException
-
createImageTypeSpecifier
private ImageTypeSpecifier createImageTypeSpecifier(int planarConfiguration, ColorSpace cs, int dataType, int significantSamples, int samplesPerPixel, boolean alpha, boolean alphaPremultiplied) throws IIOException - Throws:
IIOException
-
createOffsets
private static int[] createOffsets(int samplesPerPixel) -
getPhotometricInterpretationWithFallback
- Throws:
IIOException
-
guessPhotometricInterpretation
-
getOpaqueSamplesPerPixel
- Throws:
IIOException
-
getDataType
- Throws:
IIOException
-
createIndexColorModel
-
getSampleFormat
- Throws:
IIOException
-
getBitsPerSample
- Throws:
IIOException
-
getImageTypes
- Specified by:
getImageTypes
in classImageReader
- Throws:
IOException
-
read
- Specified by:
read
in classImageReader
- Throws:
IOException
-
createYCbCrUpsamplerStream
private InputStream createYCbCrUpsamplerStream(int photometricInterpretation, int planarConfiguration, int plane, int transferType, int[] yCbCrSubsampling, int yCbCrPos, int colsInTile, InputStream stream, ByteOrder byteOrder) -
containsZero
private boolean containsZero(long[] byteCounts) -
readJPEGMetadataSafe
- Throws:
IOException
-
needsCSConversion
private boolean needsCSConversion(int compression, int photometricInterpretation, IIOMetadata imageMetadata) -
getJPEGSourceCS
-
getNode
-
createJPEGDelegate
- Throws:
IOException
-
createJFIFStream
private static InputStream createJFIFStream(int bands, int stripTileWidth, int stripTileHeight, byte[][] qTables, byte[][] dcTables, byte[][] acTables, int subsampling) throws IOException - Throws:
IOException
-
clipRowToRect
-
clipToRect
-
readStripTileData
private void readStripTileData(Raster tileRowRaster, Rectangle srcRegion, int xSub, int ySub, int band, int numBands, int interpretation, WritableRaster raster, int startCol, int startRow, int colsInTile, int rowsInTile, ImageInputStream input) throws IOException - Throws:
IOException
-
toFloat
private void toFloat(short[] rowDataShort, float[] rowDataFloat) -
clamp
private void clamp(float[] rowDataFloat) -
normalizeColorPlanar
private void normalizeColorPlanar(int photometricInterpretation, WritableRaster raster) throws IIOException - Throws:
IIOException
-
normalizeColor
private void normalizeColor(int photometricInterpretation, int numBands, byte[] data) throws IOException - Throws:
IOException
-
normalizeColor
private void normalizeColor(int photometricInterpretation, int numBands, short[] data) throws IIOException - Throws:
IIOException
-
normalizeColor
private void normalizeColor(int photometricInterpretation, int numBands, int[] data) -
normalizeColor
private void normalizeColor(int photometricInterpretation, int numBands, float[] data) -
convertYCbCr2RGB
private void convertYCbCr2RGB(short[] yCbCr, short[] rgb, double[] coefficients, double[] referenceBW, int offset) -
clampShort
private short clampShort(int val) -
createDecompressorStream
private InputStream createDecompressorStream(int compression, int width, int bands, InputStream stream) throws IOException - Throws:
IOException
-
findCCITTType
- Throws:
IOException
-
createFillOrderStream
-
getCCITTOptions
- Throws:
IIOException
-
createUnpredictorStream
private InputStream createUnpredictorStream(int predictor, int width, int samplesPerPixel, int bitsPerSample, InputStream stream, ByteOrder byteOrder) throws IOException - Throws:
IOException
-
getValueAsLongArray
- Throws:
IIOException
-
getValueAsDoubleArray
private double[] getValueAsDoubleArray(int tag, String tagName, boolean required, int expectedLength) throws IIOException - Throws:
IIOException
-
getICCProfile
-
canReadRaster
public boolean canReadRaster()- Overrides:
canReadRaster
in classImageReader
-
readRaster
- Overrides:
readRaster
in classImageReader
- Throws:
IOException
-
isImageTiled
- Overrides:
isImageTiled
in classImageReader
- Throws:
IOException
-
getTileWidth
- Overrides:
getTileWidth
in classImageReader
- Throws:
IOException
-
getTileHeight
- Overrides:
getTileHeight
in classImageReader
- Throws:
IOException
-
computeTileRegion
- Throws:
IOException
-
readTile
- Overrides:
readTile
in classImageReader
- Throws:
IOException
-
readTileRaster
- Overrides:
readTileRaster
in classImageReader
- Throws:
IOException
-
getImageMetadata
Description copied from class:ImageReaderBase
Default implementation that always returnsnull
.- Overrides:
getImageMetadata
in classImageReaderBase
- Parameters:
imageIndex
- ignored, unless overridden- Returns:
null
, unless overridden- Throws:
IOException
- never, unless overridden.
-
getStreamMetadata
Description copied from class:ImageReaderBase
Default implementation that always returnsnull
.- Overrides:
getStreamMetadata
in classImageReaderBase
- Returns:
null
, unless overridden- Throws:
IOException
- never, unless overridden.
-
main
- Throws:
IOException
-
replaceBytesWithUndefined
-
showIt
-