Top Description Fields Constructors Methods
com.sun.imageio.plugins.tiff

public abstract Class TIFFDecompressor

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.imageio.plugins.tiff.TIFFDeflateDecompressor, com.sun.imageio.plugins.tiff.TIFFFaxDecompressor, com.sun.imageio.plugins.tiff.TIFFJPEGDecompressor, com.sun.imageio.plugins.tiff.TIFFLSBDecompressor, com.sun.imageio.plugins.tiff.TIFFLZWDecompressor, com.sun.imageio.plugins.tiff.TIFFNullDecompressor, com.sun.imageio.plugins.tiff.TIFFPackBitsDecompressor, com.sun.imageio.plugins.tiff.TIFFYCbCrDecompressor
Imports
java.awt.Rectangle, .Transparency, java.awt.color.ColorSpace, java.awt.image.BufferedImage, .ColorModel, .ComponentColorModel, .ComponentSampleModel, .DataBuffer, .DataBufferByte, .DataBufferDouble, .DataBufferFloat, .DataBufferInt, .DataBufferShort, .DataBufferUShort, .MultiPixelPackedSampleModel, .PixelInterleavedSampleModel, .Raster, .SampleModel, .SinglePixelPackedSampleModel, .WritableRaster, java.io.ByteArrayInputStream, .IOException, java.nio.ByteOrder, javax.imageio.IIOException, .ImageReader, .ImageTypeSpecifier, javax.imageio.metadata.IIOMetadata, javax.imageio.stream.ImageInputStream, .MemoryCacheImageInputStream, javax.imageio.plugins.tiff.BaselineTIFFTagSet, com.sun.imageio.plugins.common.ImageUtil, .BogusColorSpace, .SimpleCMYKColorSpace

A class defining a pluggable TIFF decompressor.

The mapping between source and destination Y coordinates is given by the equations:

dx = (sx - sourceXOffset)/subsampleX + dstXOffset;
dy = (sy - sourceYOffset)/subsampleY + dstYOffset;
Note that the mapping from source coordinates to destination coordinates is not one-to-one if subsampling is being used, since only certain source pixels are to be copied to the destination. However, * the inverse mapping is always one-to-one:
sx = (dx - dstXOffset)*subsampleX + sourceXOffset;
sy = (dy - dstYOffset)*subsampleY + sourceYOffset;

Decompressors may be written with various levels of complexity. The most complex decompressors will override the decode method, and will perform all the work of decoding, subsampling, offsetting, clipping, and format conversion. This approach may be the most efficient, since it is possible to avoid the use of extra image buffers, and it may be possible to avoid decoding portions of the image that will not be copied into the destination.

Less ambitious decompressors may override the decodeRaw method, which is responsible for decompressing the entire tile or strip into a byte array (or other appropriate datatype). The default implementation of decode will perform all necessary setup of buffers, call decodeRaw to perform the actual decoding, perform subsampling, and copy the results into the final destination image. Where possible, it will pass the real image buffer to decodeRaw in order to avoid making an extra copy.

Slightly more ambitious decompressors may override decodeRaw, but avoid writing pixels that will be discarded in the subsampling phase.

Field Summary

Modifier and TypeField and Description
protected int
activeSrcHeight

The height of the source region that will actually be copied into the destination image, taking into account all susbampling, offsetting, and clipping.

protected int
activeSrcMinX

The X coordinate of the upper-left source pixel that will actually be copied into the destination image, taking into account all subsampling, offsetting, and clipping.

protected int
activeSrcMinY

The Y coordinate of the upper-left source pixel that will actually be copied into the destination image, taking into account all subsampling, offsetting, and clipping.

protected int
activeSrcWidth

The width of the source region that will actually be copied into the destination image, taking into account all susbampling, offsetting, and clipping.

private boolean
private int[][]
protected int[]
bitsPerSample

The value of the BitsPerSample tag.

private int[]
protected int
byteCount

The number of bytes of data from the source ImageInputStream to be decompressed.

protected TIFFColorConverter
colorConverter

A TIFFColorConverter object describing the color space of the encoded pixel data, or null.

protected char[]
colorMap

The value of the ColorMap tag.

protected int
compression

The value of the Compression tag.

private int[]
protected int[]
destinationBands

The sequence of destination bands to receive the source data.

private int[]
protected int
dstHeight

The height of the region of the destination image to be written.

protected int
dstMinX

The X coordinate of the upper left pixel to be written in the destination image.

protected int
dstMinY

The Y coordinate of the upper left pixel to be written in the destination image.

protected int
dstWidth

The width of the region of the destination image to be written.

protected int
dstXOffset

The horizontal destination offset used, along with sourceXOffset and subsampleX, to map between horizontal source and destination pixel coordinates.

protected int
dstYOffset

The vertical destination offset used, along with sourceYOffset and subsampleY, to map between horizontal source and destination pixel coordinates.

protected int[]
extraSamples

The value of the ExtraSamples tag.

protected BufferedImage
image

The final destination image.

private boolean
private boolean
private boolean
private boolean
protected IIOMetadata
metadata

The IIOMetadata object containing metadata for the current image.

protected long
offset

The offset in the source ImageInputStream of the start of the data to be decompressed.

protected int
photometricInterpretation

The value of the PhotometricInterpretation tag.

protected boolean
planar

true if the image is encoded using separate planes.

protected int
planarBand

The planar band to decode; ignored for chunky (interleaved) images.

private boolean
protected BufferedImage
rawImage

A BufferedImage for the decodeRaw method to write into.

protected ImageReader
reader

The ImageReader calling this TIFFDecompressor.

protected int[]
sampleFormat

The value of the SampleFormat tag.

protected int
samplesPerPixel

The value of the SamplesPerPixel tag.

protected int[]
sourceBands

The sequence of source bands that are to be copied into the destination.

private int[]
protected int
sourceXOffset

The source X offset used, along with dstXOffset and subsampleX, to map between horizontal source and destination pixel coordinates.

protected int
sourceYOffset

The source Y offset used, along with dstYOffset and subsampleY, to map between vertical source and destination pixel coordinates.

protected int
srcHeight

The height of the source region being decoded from the source stream.

protected int
srcMinX

The X coordinate of the upper-left pixel of the source region being decoded from the source stream.

protected int
srcMinY

The Y coordinate of the upper-left pixel of the source region being decoded from the source stream.

protected int
srcWidth

The width of the source region being decoded from the source stream.

protected ImageInputStream
stream

The ImageInputStream containing the TIFF source data.

protected int
subsampleX

The horizontal subsampling factor.

protected int
subsampleY

The vertical subsampling factor.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static boolean
areIntArraysEqual(int[] a, int[] b)

private static boolean
areSampleSizesEqual(SampleModel sm)

Returns whether all samples have the same number of bits.

public void
beginDecoding()

This routine is called prior to a sequence of calls to the decode method, in order to allow any necessary tables or other structures to be initialized based on metadata values.

pack-priv static ColorModel
createComponentCM(ColorSpace colorSpace, int numBands, int[] bitsPerSample, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied)

Create a ComponentColorModel for use in creating an ImageTypeSpecifier.

pack-priv static SampleModel

Returns:

A PixelInterleavedSampleModel.
createInterleavedSM
(int
The data type (DataBuffer.TYPE_*).
dataType
,
int
The number of bands.
numBands
)

Create a PixelInterleavedSampleModel for use in creating an ImageTypeSpecifier.

private static int
createMask(int[] bitsPerSample, int band)

public BufferedImage

Returns:

a BufferedImage whose underlying data array has the same format as the raw source pixel data, or null if it is not possible to create such an image.
createRawImage
()

Creates a BufferedImage whose underlying data array will be suitable for holding the raw decoded output of the decodeRaw method.

public void
decode()

Decodes the input bit stream (located in the ImageInputStream stream, at offset offset, and continuing for byteCount bytes) into the output BufferedImage image.

public abstract void
decodeRaw(byte[]
a byte array to be written.
b
,
int
the starting offset in b to be written.
dstOffset
,
int
the number of bits for each pixel.
bitsPerPixel
,
int
the number of bytes to advance between that starting pixels of each scanline.
scanlineStride
)

Decodes the source data into the provided byte array b, starting at the offset given by dstOffset.

public void
decodeRaw(short[]
a short array to be written.
s
,
int
the starting offset in s to be written.
dstOffset
,
int
the number of bits for each pixel.
bitsPerPixel
,
int
the number of shorts to advance between that starting pixels of each scanline.
scanlineStride
)

Decodes the source data into the provided short array s, starting at the offset given by dstOffset.

public void
decodeRaw(int[]
an int array to be written.
i
,
int
the starting offset in i to be written.
dstOffset
,
int
the number of bits for each pixel.
bitsPerPixel
,
int
the number of ints to advance between that starting pixels of each scanline.
scanlineStride
)

Decodes the source data into the provided int array i, starting at the offset given by dstOffset.

public void
decodeRaw(float[]
a float array to be written.
f
,
int
the starting offset in f to be written.
dstOffset
,
int
the number of bits for each pixel.
bitsPerPixel
,
int
the number of floats to advance between that starting pixels of each scanline.
scanlineStride
)

Decodes the source data into the provided float array f, starting at the offset given by dstOffset.

public void
decodeRaw(double[]
a double array to be written.
d
,
int
the starting offset in f to be written.
dstOffset
,
int
the number of bits for each pixel.
bitsPerPixel
,
int
the number of doubles to advance between that starting pixels of each scanline.
scanlineStride
)

Decodes the source data into the provided double array f, starting at the offset given by dstOffset.

private static int
getBitsPerPixel(SampleModel sm)

Returns the number of bits per pixel.

private static int
getDataTypeFromNumBits(int numBits, boolean isSigned)

private static int
getDataTypeSize(int dataType)

Return the number of bits occupied by dataType which must be one of the DataBuffer TYPEs.

public ImageTypeSpecifier

Returns:

an ImageTypeSpecifier.
getRawImageType
()

Returns an ImageTypeSpecifier describing an image whose underlying data array has the same format as the raw source pixel data.

public static ImageTypeSpecifier

Returns:

a suitable ImageTypeSpecifier, or null if it is not possible to create one.
getRawImageTypeSpecifier
(int
the value of the PhotometricInterpretation field.
photometricInterpretation
,
int
the value of the Compression field.
compression
,
int
the value of the SamplesPerPixel field.
samplesPerPixel
,
int[]
the value of the BitsPerSample field.
bitsPerSample
,
int[]
the value of the SampleFormat field.
sampleFormat
,
int[]
the value of the ExtraSamples field.
extraSamples
,
char[]
the value of the ColorMap field.
colorMap
)

A utility method that returns an ImageTypeSpecifier suitable for decoding an image with the given parameters.

private static boolean
isDataBufferBitContiguous(SampleModel sm, int[] bitsPerSample)

Determines whether the DataBuffer is filled without any interspersed padding bits.

private static void
reformatData(byte[] buf, int bytesPerRow, int numRows, short[] shortData, int[] intData, int outOffset, int outStride)

Reformats data read as bytes into a short or int buffer.

private static void
reformatDiscontiguousData(byte[] buf, int[] bitsPerSample, int stride, int w, int h, WritableRaster raster)

Reformats bit-discontiguous data into the DataBuffer of the supplied WritableRaster.

public void
setActiveSrcHeight(int
the height of the active source region.
activeSrcHeight
)

Sets the value of the activeSrcHeight field.

public void
setActiveSrcMinX(int
the minimum X coordinate of the active source region.
activeSrcMinX
)

Sets the value of the activeSrcMinX field.

public void
setActiveSrcMinY(int
the minimum Y coordinate of the active source region.
activeSrcMinY
)

Sets the value of the activeSrcMinY field.

public void
setActiveSrcWidth(int
the width of the active source region.
activeSrcWidth
)

Sets the value of the activeSrcWidth field.

public void
setBitsPerSample(int[]
the number of bits for each source image sample.
bitsPerSample
)

Sets the value of the bitsPerSample field.

public void
setByteCount(int
the number of bytes of compressed data.
byteCount
)

Sets the value of the byteCount field.

public void
setColorConverter(TIFFColorConverter
a TIFFColorConverter object, or null.
colorConverter
)

Sets the TIFFColorConverter object describing the color space of the encoded data in the input stream.

public void
setColorMap(char[]
the color map to apply to the source data, as an array of chars.
colorMap
)

Sets the value of the colorMap field.

public void
setCompression(int
the compression type.
compression
)

Sets the value of the compression field.

public void
setDestinationBands(int[]
an array of ints specifying the destination bands to be written.
destinationBands
)

Sets the value of the destinationBands field.

public void
setDstHeight(int
the height of the destination region.
dstHeight
)

Sets the value of the dstHeight field.

public void
setDstMinX(int
the minimum X coordinate of the destination region.
dstMinX
)

Sets the value of the dstMinX field.

public void
setDstMinY(int
the minimum Y coordinate of the destination region.
dstMinY
)

Sets the value of the dstMinY field.

public void
setDstWidth(int
the width of the destination region.
dstWidth
)

Sets the value of the dstWidth field.

public void
setDstXOffset(int
the horizontal destination offset to be used when mapping between source and destination coordinates.
dstXOffset
)

Sets the value of the dstXOffset field.

public void
setDstYOffset(int
the vertical destination offset to be used when mapping between source and destination coordinates.
dstYOffset
)

Sets the value of the dstYOffset field.

public void
setExtraSamples(int[]
the interpretation of any samples in the source file beyond those used for basic color or grayscale information.
extraSamples
)

Sets the value of the extraSamples field.

public void
setImage(BufferedImage
the destination BufferedImage.
image
)

Sets the value of the image field.

public void
setMetadata(IIOMetadata
the IIOMetadata object for the image being read.
metadata
)

Sets the value of the metadata field.

public void
setOffset(long
the offset of the beginning of the compressed data.
offset
)

Sets the value of the offset field.

public void
setPhotometricInterpretation(int
the photometric interpretation value.
photometricInterpretation
)

Sets the value of the photometricInterpretation field.

public void
setPlanar(boolean
true if the image to be decoded is stored in planar format.
planar
)

Sets the value of the planar field.

public void
setPlanarBand(int
the index of the planar band to decode
planarBand
)

Sets the index of the planar configuration band to be decoded.

public void
setReader(ImageReader
the current ImageReader.
reader
)

Sets the value of the reader field.

public void
setSampleFormat(int[]
the format of the source image data, for example unsigned integer or floating-point.
sampleFormat
)

Sets the value of the sampleFormat field.

public void
setSamplesPerPixel(int
the number of samples in each source pixel.
samplesPerPixel
)

Sets the value of the samplesPerPixel field.

public void
setSourceBands(int[]
an array of ints specifying the source bands to be read.
sourceBands
)

Sets the value of the sourceBands field.

public void
setSourceXOffset(int
the horizontal source offset to be used when mapping between source and destination coordinates.
sourceXOffset
)

Sets the value of the sourceXOffset field.

public void
setSourceYOffset(int
the vertical source offset to be used when mapping between source and destination coordinates.
sourceYOffset
)

Sets the value of the sourceYOffset.

public void
setSrcHeight(int
the height of the source region being decoded, irrespective of how it will be copied into the destination.
srcHeight
)

Sets the value of the srcHeight field.

public void
setSrcMinX(int
the minimum X coordinate of the source region being decoded, irrespective of how it will be copied into the destination.
srcMinX
)

Sets the value of the srcMinX field.

public void
setSrcMinY(int
the minimum Y coordinate of the source region being decoded, irrespective of how it will be copied into the destination.
srcMinY
)

Sets the value of the srcMinY field.

public void
setSrcWidth(int
the width of the source region being decoded, irrespective of how it will be copied into the destination.
srcWidth
)

Sets the value of the srcWidth field.

public void
setStream(ImageInputStream
the ImageInputStream to be read.
stream
)

Sets the value of the stream field.

public void
setSubsampleX(int
the horizontal subsampling factor.
subsampleX
)

Sets the value of the subsampleX field.

public void
setSubsampleY(int
the vertical subsampling factor.
subsampleY
)

Sets the value of the subsampleY field.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait