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 booleanprivate CompoundDirectoryprivate int(package private) static final double[]Fields inherited from class ImageReaderBase
imageInputFields inherited from class ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanprivate voidclamp(double[] data) private voidclamp(float[] data) private shortclampShort(int val) private RasterclipRowToRect(Raster raster, Rectangle rect, int[] bands, int xSub) private WritableRasterclipToRect(WritableRaster raster, Rectangle rect, int[] bands) private RectanglecomputeTileRegion(int imageIndex, int tileX, int tileY) private booleancontainsZero(long[] byteCounts) private voidconvertYCbCr2RGB(short[] yCbCr, short[] rgb, double[] coefficients, double[] referenceBW, int offset) private InputStreamcreateDecompressorStream(int compression, int width, int height, int bands, InputStream stream) private InputStreamcreateFillOrderStream(int fillOrder, InputStream stream) private ImageTypeSpecifiercreateImageTypeSpecifier(int planarConfiguration, ColorSpace cs, int dataType, int significantSamples, int samplesPerPixel, boolean alpha, boolean alphaPremultiplied) private IndexColorModelcreateIndexColorModel(int bitsPerSample, int dataType, int[] cmapShort) private static InputStreamcreateJFIFStream(int bands, int stripTileWidth, int stripTileHeight, byte[][] qTables, byte[][] dcTables, byte[][] acTables, int subsampling) private ImageReader(package private) static int[]createOffsets(int samplesPerPixel) private InputStreamcreateUnpredictorStream(int predictor, int width, int samplesPerPixel, int bitsPerSample, InputStream stream, ByteOrder byteOrder) private InputStreamcreateYCbCrUpsamplerStream(int photometricInterpretation, int planarConfiguration, int plane, int transferType, int[] yCbCrSubsampling, int yCbCrPos, int colsInTile, InputStream stream, ByteOrder byteOrder) private intfindCCITTType(int encodedCompression, InputStream stream) private intprivate longgetCCITTOptions(int compression) private intgetDataType(int sampleFormat, int bitsPerSample) intgetHeight(int imageIndex) private ICC_ProfilegetImageMetadata(int imageIndex) MetadatagetImageTypes(int imageIndex) private intgetJPEGSourceCS(IIOMetadata imageMetadata) private IIOMetadataNodegetNode(IIOMetadataNode parent, String tagName) intgetNumImages(boolean allowSearch) Default implementation that always returns1.private intgetOpaqueSamplesPerPixel(int photometricInterpretation) private intgetRawImageType(int imageIndex) private intDefault implementation that always returnsnull.intgetTileHeight(int imageIndex) intgetTileWidth(int imageIndex) private double[]getValueAsDoubleArray(int tag, String tagName, boolean required, int expectedLength) private intgetValueAsInt(int tag, String tagName) private intgetValueAsIntWithDefault(int tag, Integer defaultValue) private intgetValueAsIntWithDefault(int tag, String tagName, Integer defaultValue) private long[]getValueAsLongArray(int tag, String tagName, boolean required) private longgetValueAsLongWithDefault(int tag, Long defaultValue) private longgetValueAsLongWithDefault(int tag, String tagName, Long defaultValue) private NumbergetValueAsNumberWithDefault(int tag, String tagName, Number defaultValue) intgetWidth(int imageIndex) (package private) static intguessPhotometricInterpretation(int compression, int samplesPerPixel, Entry extraSamples, Entry colorMap) (package private) static StringintToStr(int value) booleanisImageTiled(int imageIndex) Tiling supportstatic voidprivate booleanneedsCSConversion(int compression, int photometricInterpretation, IIOMetadata imageMetadata) private voidnormalizeColor(int photometricInterpretation, int numBands, byte[] data) private voidnormalizeColor(int photometricInterpretation, int numBands, double[] data) private voidnormalizeColor(int photometricInterpretation, int numBands, float[] data) private voidnormalizeColor(int photometricInterpretation, int numBands, int[] data) private voidnormalizeColor(int photometricInterpretation, int numBands, short[] data) private voidnormalizeColorPlanar(int photometricInterpretation, WritableRaster raster) read(int imageIndex, ImageReadParam param) private BufferedImageread(int imageIndex, ImageReadParam param, boolean normalize) private voidreadIFD(int imageIndex) private IIOMetadatareadJPEGMetadataSafe(ImageReader jpegReader) private void(package private) static StringreadPascalString(DataInput pInput) readRaster(int imageIndex, ImageReadParam param) private voidreadStripTileData(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, boolean normalize) readTile(int imageIndex, int tileX, int tileY) readTileRaster(int imageIndex, int tileX, int tileY) private static voidprotected voidResets all member variables.protected static voidshowIt(BufferedImage image, String title) private voidtoFloat(short[] rowDataShort, float[] rowDataFloat) Methods inherited from class ImageReaderBase
assertInput, checkBounds, dispose, fakeAOI, fakeSubsampling, getDestination, hasExplicitDestination, reset, setInputMethods inherited from class 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:ImageReaderBaseResets all member variables. This method is by default invoked from:- Specified by:
resetMembersin classImageReaderBase
-
readMetadata
- Throws:
IOException
-
readPascalString
- Throws:
IOException
-
intToStr
-
readIFD
- Throws:
IOException
-
getNumImages
Description copied from class:ImageReaderBaseDefault implementation that always returns1.- Overrides:
getNumImagesin 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:
getWidthin classImageReader- Throws:
IOException
-
getHeight
- Specified by:
getHeightin classImageReader- Throws:
IOException
-
getRawImageType
- Overrides:
getRawImageTypein 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
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:
getImageTypesin classImageReader- Throws:
IOException
-
read
- Specified by:
readin classImageReader- Throws:
IOException
-
read
private BufferedImage read(int imageIndex, ImageReadParam param, boolean normalize) throws IOException - 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, boolean normalize) throws IOException - Throws:
IOException
-
toFloat
private void toFloat(short[] rowDataShort, float[] rowDataFloat) -
clamp
private void clamp(float[] data) -
clamp
private void clamp(double[] data) -
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) -
normalizeColor
private void normalizeColor(int photometricInterpretation, int numBands, double[] 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 height, 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:
canReadRasterin classImageReader
-
readRaster
- Overrides:
readRasterin classImageReader- Throws:
IOException
-
isImageTiled
Tiling support- Overrides:
isImageTiledin classImageReader- Throws:
IOException
-
getTileWidth
- Overrides:
getTileWidthin classImageReader- Throws:
IOException
-
getTileHeight
- Overrides:
getTileHeightin classImageReader- Throws:
IOException
-
computeTileRegion
- Throws:
IOException
-
readTile
- Overrides:
readTilein classImageReader- Throws:
IOException
-
readTileRaster
- Overrides:
readTileRasterin classImageReader- Throws:
IOException
-
getImageMetadata
Metadata- Overrides:
getImageMetadatain classImageReaderBase- Parameters:
imageIndex- ignored, unless overridden- Returns:
null, unless overridden- Throws:
IOException- never, unless overridden.
-
getStreamMetadata
Description copied from class:ImageReaderBaseDefault implementation that always returnsnull.- Overrides:
getStreamMetadatain classImageReaderBase- Returns:
null, unless overridden- Throws:
IOException- never, unless overridden.
-
main
- Throws:
IOException
-
replaceBytesWithUndefined
-
showIt
-