Class TIFFDecompressor
- Direct Known Subclasses:
TIFFDeflateDecompressor
,TIFFFaxDecompressor
,TIFFJPEGDecompressor
,TIFFLSBDecompressor
,TIFFLZWDecompressor
,TIFFNullDecompressor
,TIFFPackBitsDecompressor
,TIFFYCbCrDecompressor
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
FieldsModifier and TypeFieldDescriptionprotected int
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
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
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
The width of the source region that will actually be copied into the destination image, taking into account all susbampling, offsetting, and clipping.(package private) boolean
(package private) int[][]
protected int[]
The value of theBitsPerSample
tag.private int[]
protected int
The number of bytes of data from the sourceImageInputStream
to be decompressed.protected TIFFColorConverter
ATIFFColorConverter
object describing the color space of the encoded pixel data, ornull
.protected char[]
The value of theColorMap
tag.protected int
The value of theCompression
tag.private static final boolean
private int[]
protected int[]
The sequence of destination bands to receive the source data.private int[]
protected int
The height of the region of the destination image to be written.protected int
The X coordinate of the upper left pixel to be written in the destination image.protected int
The Y coordinate of the upper left pixel to be written in the destination image.protected int
The width of the region of the destination image to be written.protected int
The horizontal destination offset used, along withsourceXOffset
andsubsampleX
, to map between horizontal source and destination pixel coordinates.protected int
The vertical destination offset used, along withsourceYOffset
andsubsampleY
, to map between horizontal source and destination pixel coordinates.protected int[]
The value of theExtraSamples
tag.protected BufferedImage
The final destination image.(package private) boolean
(package private) boolean
private boolean
(package private) boolean
protected IIOMetadata
TheIIOMetadata
object containing metadata for the current image.protected long
The offset in the sourceImageInputStream
of the start of the data to be decompressed.protected int
The value of thePhotometricInterpretation
tag.protected boolean
true
if the image is encoded using separate planes.private boolean
protected BufferedImage
ABufferedImage
for thedecodeRaw
method to write into.protected ImageReader
TheImageReader
calling thisTIFFDecompressor
.protected int[]
The value of theSampleFormat
tag.protected int
The value of theSamplesPerPixel
tag.protected int[]
The sequence of source bands that are to be copied into the destination.private int[]
protected int
The source X offset used, along withdstXOffset
andsubsampleX
, to map between horizontal source and destination pixel coordinates.protected int
The source Y offset used, along withdstYOffset
andsubsampleY
, to map between vertical source and destination pixel coordinates.protected int
The height of the source region being decoded from the source stream.protected int
The X coordinate of the upper-left pixel of the source region being decoded from the source stream.protected int
The Y coordinate of the upper-left pixel of the source region being decoded from the source stream.protected int
The width of the source region being decoded from the source stream.protected ImageInputStream
TheImageInputStream
containing the TIFF source data.protected int
The horizontal subsampling factor.protected int
The vertical subsampling factor. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
areIntArraysEqual
(int[] a, int[] b) private static boolean
Returns whether all samples have the same number of bits.void
This routine is called prior to a sequence of calls to thedecode
method, in order to allow any necessary tables or other structures to be initialized based on metadata values.(package private) static ColorModel
createComponentCM
(ColorSpace colorSpace, int numBands, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) Create aComponentColorModel
for use in creating anImageTypeSpecifier
.(package private) static SampleModel
createInterleavedSM
(int dataType, int numBands) Create aPixelInterleavedSampleModel
for use in creating anImageTypeSpecifier
.private static int
createMask
(int[] bitsPerSample, int band) Creates aBufferedImage
whose underlying data array will be suitable for holding the raw decoded output of thedecodeRaw
method.void
decode()
Decodes the input bit stream (located in theImageInputStream
stream
, at offsetoffset
, and continuing forbyteCount
bytes) into the outputBufferedImage
image
.abstract void
decodeRaw
(byte[] b, int dstOffset, int bitsPerPixel, int scanlineStride) Decodes the source data into the providedbyte
arrayb
, starting at the offset given bydstOffset
.void
decodeRaw
(float[] f, int dstOffset, int bitsPerPixel, int scanlineStride) Decodes the source data into the providedfloat
arrayf
, starting at the offset given bydstOffset
.void
decodeRaw
(int[] i, int dstOffset, int bitsPerPixel, int scanlineStride) Decodes the source data into the providedint
arrayi
, starting at the offset given bydstOffset
.void
decodeRaw
(short[] s, int dstOffset, int bitsPerPixel, int scanlineStride) Decodes the source data into the providedshort
arrays
, starting at the offset given bydstOffset
.private static int
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 bydataType
which must be one of theDataBuffer
TYPE
s.Returns anImageTypeSpecifier
describing an image whose underlying data array has the same format as the raw source pixel data.static ImageTypeSpecifier
getRawImageTypeSpecifier
(int photometricInterpretation, int compression, int samplesPerPixel, int[] bitsPerSample, int[] sampleFormat, int[] extraSamples, char[] colorMap) A utility method that returns anImageTypeSpecifier
suitable for decoding an image with the given parameters.private static boolean
Determines whether theDataBuffer
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 stride, int w, int h, WritableRaster raster) Reformats bit-discontiguous data into theDataBuffer
of the suppliedWritableRaster
.void
setActiveSrcHeight
(int activeSrcHeight) Sets the value of theactiveSrcHeight
field.void
setActiveSrcMinX
(int activeSrcMinX) Sets the value of theactiveSrcMinX
field.void
setActiveSrcMinY
(int activeSrcMinY) Sets the value of theactiveSrcMinY
field.void
setActiveSrcWidth
(int activeSrcWidth) Sets the value of theactiveSrcWidth
field.void
setBitsPerSample
(int[] bitsPerSample) Sets the value of thebitsPerSample
field.void
setByteCount
(int byteCount) Sets the value of thebyteCount
field.void
setColorConverter
(TIFFColorConverter colorConverter) Sets theTIFFColorConverter
object describing the color space of the encoded data in the input stream.void
setColorMap
(char[] colorMap) Sets the value of thecolorMap
field.void
setCompression
(int compression) Sets the value of thecompression
field.void
setDestinationBands
(int[] destinationBands) Sets the value of thedestinationBands
field.void
setDstHeight
(int dstHeight) Sets the value of thedstHeight
field.void
setDstMinX
(int dstMinX) Sets the value of thedstMinX
field.void
setDstMinY
(int dstMinY) Sets the value of thedstMinY
field.void
setDstWidth
(int dstWidth) Sets the value of thedstWidth
field.void
setDstXOffset
(int dstXOffset) Sets the value of thedstXOffset
field.void
setDstYOffset
(int dstYOffset) Sets the value of thedstYOffset
field.void
setExtraSamples
(int[] extraSamples) Sets the value of theextraSamples
field.void
setImage
(BufferedImage image) Sets the value of theimage
field.void
setMetadata
(IIOMetadata metadata) Sets the value of themetadata
field.void
setOffset
(long offset) Sets the value of theoffset
field.void
setPhotometricInterpretation
(int photometricInterpretation) Sets the value of thephotometricInterpretation
field.void
setPlanar
(boolean planar) Sets the value of theplanar
field.void
setReader
(ImageReader reader) Sets the value of thereader
field.void
setSampleFormat
(int[] sampleFormat) Sets the value of thesampleFormat
field.void
setSamplesPerPixel
(int samplesPerPixel) Sets the value of thesamplesPerPixel
field.void
setSourceBands
(int[] sourceBands) Sets the value of thesourceBands
field.void
setSourceXOffset
(int sourceXOffset) Sets the value of thesourceXOffset
field.void
setSourceYOffset
(int sourceYOffset) Sets the value of thesourceYOffset
.void
setSrcHeight
(int srcHeight) Sets the value of thesrcHeight
field.void
setSrcMinX
(int srcMinX) Sets the value of thesrcMinX
field.void
setSrcMinY
(int srcMinY) Sets the value of thesrcMinY
field.void
setSrcWidth
(int srcWidth) Sets the value of thesrcWidth
field.void
setStream
(ImageInputStream stream) Sets the value of thestream
field.void
setSubsampleX
(int subsampleX) Sets the value of thesubsampleX
field.void
setSubsampleY
(int subsampleY) Sets the value of thesubsampleY
field.
-
Field Details
-
DEBUG
private static final boolean DEBUG- See Also:
-
reader
TheImageReader
calling thisTIFFDecompressor
. -
metadata
TheIIOMetadata
object containing metadata for the current image. -
photometricInterpretation
protected int photometricInterpretationThe value of thePhotometricInterpretation
tag. Legal values areBaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_WHITE_IS_ZERO
,BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_BLACK_IS_ZERO
,BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_RGB
,BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_PALETTE_COLOR
,BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_TRANSPARENCY_MASK
,BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_Y_CB_CR
,BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_CIELAB
,BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_ICCLAB
, or other value defined by a TIFF extension. -
compression
protected int compressionThe value of theCompression
tag. Legal values areBaselineTIFFTagSet.COMPRESSION_NONE
,BaselineTIFFTagSet.COMPRESSION_CCITT_RLE
,BaselineTIFFTagSet.COMPRESSION_CCITT_T_4
,BaselineTIFFTagSet.COMPRESSION_CCITT_T_6
,BaselineTIFFTagSet.COMPRESSION_LZW
,BaselineTIFFTagSet.COMPRESSION_OLD_JPEG
,BaselineTIFFTagSet.COMPRESSION_JPEG
,BaselineTIFFTagSet.COMPRESSION_ZLIB
,BaselineTIFFTagSet.COMPRESSION_PACKBITS
,BaselineTIFFTagSet.COMPRESSION_DEFLATE
, or other value defined by a TIFF extension. -
planar
protected boolean planartrue
if the image is encoded using separate planes. -
samplesPerPixel
protected int samplesPerPixelThe value of theSamplesPerPixel
tag. -
bitsPerSample
protected int[] bitsPerSampleThe value of theBitsPerSample
tag. -
sampleFormat
protected int[] sampleFormatThe value of theSampleFormat
tag. Legal values areBaselineTIFFTagSet.SAMPLE_FORMAT_UNSIGNED_INTEGER
,BaselineTIFFTagSet.SAMPLE_FORMAT_SIGNED_INTEGER
,BaselineTIFFTagSet.SAMPLE_FORMAT_FLOATING_POINT
,BaselineTIFFTagSet.SAMPLE_FORMAT_UNDEFINED
, or other value defined by a TIFF extension. -
extraSamples
protected int[] extraSamplesThe value of theExtraSamples
tag. Legal values areBaselineTIFFTagSet.EXTRA_SAMPLES_UNSPECIFIED
,BaselineTIFFTagSet.EXTRA_SAMPLES_ASSOCIATED_ALPHA
,BaselineTIFFTagSet.EXTRA_SAMPLES_UNASSOCIATED_ALPHA
, or other value defined by a TIFF extension. -
colorMap
protected char[] colorMapThe value of theColorMap
tag. -
stream
TheImageInputStream
containing the TIFF source data. -
offset
protected long offsetThe offset in the sourceImageInputStream
of the start of the data to be decompressed. -
byteCount
protected int byteCountThe number of bytes of data from the sourceImageInputStream
to be decompressed. -
srcMinX
protected int srcMinXThe X coordinate of the upper-left pixel of the source region being decoded from the source stream. This value is not affected by source subsampling. -
srcMinY
protected int srcMinYThe Y coordinate of the upper-left pixel of the source region being decoded from the source stream. This value is not affected by source subsampling. -
srcWidth
protected int srcWidthThe width of the source region being decoded from the source stream. This value is not affected by source subsampling. -
srcHeight
protected int srcHeightThe height of the source region being decoded from the source stream. This value is not affected by source subsampling. -
sourceXOffset
protected int sourceXOffsetThe source X offset used, along withdstXOffset
andsubsampleX
, to map between horizontal source and destination pixel coordinates. -
dstXOffset
protected int dstXOffsetThe horizontal destination offset used, along withsourceXOffset
andsubsampleX
, to map between horizontal source and destination pixel coordinates. See the comment for
for the mapping equations.sourceXOffset
-
sourceYOffset
protected int sourceYOffsetThe source Y offset used, along withdstYOffset
andsubsampleY
, to map between vertical source and destination pixel coordinates. -
dstYOffset
protected int dstYOffsetThe vertical destination offset used, along withsourceYOffset
andsubsampleY
, to map between horizontal source and destination pixel coordinates. See the comment for
for the mapping equations.sourceYOffset
-
subsampleX
protected int subsampleXThe horizontal subsampling factor. A factor of 1 means that every column is copied to the destination; a factor of 2 means that every second column is copied, etc. -
subsampleY
protected int subsampleYThe vertical subsampling factor. A factor of 1 means that every row is copied to the destination; a factor of 2 means that every second row is copied, etc. -
sourceBands
protected int[] sourceBandsThe sequence of source bands that are to be copied into the destination. -
destinationBands
protected int[] destinationBandsThe sequence of destination bands to receive the source data. -
rawImage
ABufferedImage
for thedecodeRaw
method to write into. -
image
The final destination image. -
dstMinX
protected int dstMinXThe X coordinate of the upper left pixel to be written in the destination image. -
dstMinY
protected int dstMinYThe Y coordinate of the upper left pixel to be written in the destination image. -
dstWidth
protected int dstWidthThe width of the region of the destination image to be written. -
dstHeight
protected int dstHeightThe height of the region of the destination image to be written. -
activeSrcMinX
protected int activeSrcMinXThe 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. That is, the pixel at (activeSrcMinX
,activeSrcMinY
) is to be copied into the destination pixel at (dstMinX
,dstMinY
).The pixels in the source region to be copied are those with X coordinates of the form
activeSrcMinX + k*subsampleX
, wherek
is an integer such that0 invalid input: '<'= k invalid input: '<' dstWidth
. -
activeSrcMinY
protected int activeSrcMinYThe 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.The pixels in the source region to be copied are those with Y coordinates of the form
activeSrcMinY + k*subsampleY
, wherek
is an integer such that0 invalid input: '<'= k invalid input: '<' dstHeight
. -
activeSrcWidth
protected int activeSrcWidthThe width of the source region that will actually be copied into the destination image, taking into account all susbampling, offsetting, and clipping.The active source width will always be equal to
(dstWidth - 1)*subsampleX + 1
. -
activeSrcHeight
protected int activeSrcHeightThe height of the source region that will actually be copied into the destination image, taking into account all susbampling, offsetting, and clipping.The active source height will always be equal to
(dstHeight - 1)*subsampleY + 1
. -
colorConverter
ATIFFColorConverter
object describing the color space of the encoded pixel data, ornull
. -
isBilevel
boolean isBilevel -
isContiguous
boolean isContiguous -
isImageSimple
boolean isImageSimple -
adjustBitDepths
boolean adjustBitDepths -
bitDepthScale
int[][] bitDepthScale -
isFirstBitDepthTable
private boolean isFirstBitDepthTable -
planarCache
private boolean planarCache -
destBitsPerSampleCache
private int[] destBitsPerSampleCache -
sourceBandsCache
private int[] sourceBandsCache -
bitsPerSampleCache
private int[] bitsPerSampleCache -
destinationBandsCache
private int[] destinationBandsCache
-
-
Constructor Details
-
TIFFDecompressor
public TIFFDecompressor()
-
-
Method Details
-
createInterleavedSM
Create aPixelInterleavedSampleModel
for use in creating anImageTypeSpecifier
. Its dimensions will be 1x1 and it will have ascending band offsets as {0, 1, 2, ..., numBands}.- Parameters:
dataType
- The data type (DataBuffer.TYPE_*).numBands
- The number of bands.- Returns:
- A
PixelInterleavedSampleModel
.
-
createComponentCM
static ColorModel createComponentCM(ColorSpace colorSpace, int numBands, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) Create aComponentColorModel
for use in creating anImageTypeSpecifier
. -
createMask
private static int createMask(int[] bitsPerSample, int band) -
getDataTypeFromNumBits
private static int getDataTypeFromNumBits(int numBits, boolean isSigned) -
areIntArraysEqual
private static boolean areIntArraysEqual(int[] a, int[] b) -
getDataTypeSize
Return the number of bits occupied bydataType
which must be one of theDataBuffer
TYPE
s.- Throws:
IIOException
-
getBitsPerPixel
Returns the number of bits per pixel. -
areSampleSizesEqual
Returns whether all samples have the same number of bits. -
isDataBufferBitContiguous
Determines whether theDataBuffer
is filled without any interspersed padding bits.- Throws:
IIOException
-
reformatData
private static void reformatData(byte[] buf, int bytesPerRow, int numRows, short[] shortData, int[] intData, int outOffset, int outStride) throws IIOException Reformats data read as bytes into a short or int buffer.- Throws:
IIOException
-
reformatDiscontiguousData
private static void reformatDiscontiguousData(byte[] buf, int stride, int w, int h, WritableRaster raster) throws IOException Reformats bit-discontiguous data into theDataBuffer
of the suppliedWritableRaster
.- Throws:
IOException
-
getRawImageTypeSpecifier
public static ImageTypeSpecifier getRawImageTypeSpecifier(int photometricInterpretation, int compression, int samplesPerPixel, int[] bitsPerSample, int[] sampleFormat, int[] extraSamples, char[] colorMap) A utility method that returns anImageTypeSpecifier
suitable for decoding an image with the given parameters.- Parameters:
photometricInterpretation
- the value of thePhotometricInterpretation
field.compression
- the value of theCompression
field.samplesPerPixel
- the value of theSamplesPerPixel
field.bitsPerSample
- the value of theBitsPerSample
field.sampleFormat
- the value of theSampleFormat
field.extraSamples
- the value of theExtraSamples
field.colorMap
- the value of theColorMap
field.- Returns:
- a suitable
ImageTypeSpecifier
, ornull
if it is not possible to create one.
-
setReader
Sets the value of thereader
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
reader
- the currentImageReader
.
-
setMetadata
Sets the value of themetadata
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
metadata
- theIIOMetadata
object for the image being read.
-
setPhotometricInterpretation
public void setPhotometricInterpretation(int photometricInterpretation) Sets the value of thephotometricInterpretation
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
photometricInterpretation
- the photometric interpretation value.
-
setCompression
public void setCompression(int compression) Sets the value of thecompression
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
compression
- the compression type.
-
setPlanar
public void setPlanar(boolean planar) Sets the value of theplanar
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
planar
-true
if the image to be decoded is stored in planar format.
-
setSamplesPerPixel
public void setSamplesPerPixel(int samplesPerPixel) Sets the value of thesamplesPerPixel
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
samplesPerPixel
- the number of samples in each source pixel.
-
setBitsPerSample
public void setBitsPerSample(int[] bitsPerSample) Sets the value of thebitsPerSample
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
bitsPerSample
- the number of bits for each source image sample.
-
setSampleFormat
public void setSampleFormat(int[] sampleFormat) Sets the value of thesampleFormat
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
sampleFormat
- the format of the source image data, for example unsigned integer or floating-point.
-
setExtraSamples
public void setExtraSamples(int[] extraSamples) Sets the value of theextraSamples
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
extraSamples
- the interpretation of any samples in the source file beyond those used for basic color or grayscale information.
-
setColorMap
public void setColorMap(char[] colorMap) Sets the value of thecolorMap
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
colorMap
- the color map to apply to the source data, as an array ofchar
s.
-
setStream
Sets the value of thestream
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
stream
- theImageInputStream
to be read.
-
setOffset
public void setOffset(long offset) Sets the value of theoffset
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
offset
- the offset of the beginning of the compressed data.
-
setByteCount
public void setByteCount(int byteCount) Sets the value of thebyteCount
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
byteCount
- the number of bytes of compressed data.
-
setSrcMinX
public void setSrcMinX(int srcMinX) Sets the value of thesrcMinX
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
srcMinX
- the minimum X coordinate of the source region being decoded, irrespective of how it will be copied into the destination.
-
setSrcMinY
public void setSrcMinY(int srcMinY) Sets the value of thesrcMinY
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
srcMinY
- the minimum Y coordinate of the source region being decoded, irrespective of how it will be copied into the destination.
-
setSrcWidth
public void setSrcWidth(int srcWidth) Sets the value of thesrcWidth
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
srcWidth
- the width of the source region being decoded, irrespective of how it will be copied into the destination.
-
setSrcHeight
public void setSrcHeight(int srcHeight) Sets the value of thesrcHeight
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
srcHeight
- the height of the source region being decoded, irrespective of how it will be copied into the destination.
-
setSourceXOffset
public void setSourceXOffset(int sourceXOffset) Sets the value of thesourceXOffset
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
sourceXOffset
- the horizontal source offset to be used when mapping between source and destination coordinates.
-
setDstXOffset
public void setDstXOffset(int dstXOffset) Sets the value of thedstXOffset
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
dstXOffset
- the horizontal destination offset to be used when mapping between source and destination coordinates.
-
setSourceYOffset
public void setSourceYOffset(int sourceYOffset) Sets the value of thesourceYOffset
.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
sourceYOffset
- the vertical source offset to be used when mapping between source and destination coordinates.
-
setDstYOffset
public void setDstYOffset(int dstYOffset) Sets the value of thedstYOffset
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
dstYOffset
- the vertical destination offset to be used when mapping between source and destination coordinates.
-
setSubsampleX
public void setSubsampleX(int subsampleX) Sets the value of thesubsampleX
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
subsampleX
- the horizontal subsampling factor.- Throws:
IllegalArgumentException
- ifsubsampleX
is less than or equal to 0.
-
setSubsampleY
public void setSubsampleY(int subsampleY) Sets the value of thesubsampleY
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
subsampleY
- the vertical subsampling factor.- Throws:
IllegalArgumentException
- ifsubsampleY
is less than or equal to 0.
-
setSourceBands
public void setSourceBands(int[] sourceBands) Sets the value of thesourceBands
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
sourceBands
- an array ofint
s specifying the source bands to be read.
-
setDestinationBands
public void setDestinationBands(int[] destinationBands) Sets the value of thedestinationBands
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
destinationBands
- an array ofint
s specifying the destination bands to be written.
-
setImage
Sets the value of theimage
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
image
- the destinationBufferedImage
.
-
setDstMinX
public void setDstMinX(int dstMinX) Sets the value of thedstMinX
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
dstMinX
- the minimum X coordinate of the destination region.
-
setDstMinY
public void setDstMinY(int dstMinY) Sets the value of thedstMinY
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
dstMinY
- the minimum Y coordinate of the destination region.
-
setDstWidth
public void setDstWidth(int dstWidth) Sets the value of thedstWidth
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
dstWidth
- the width of the destination region.
-
setDstHeight
public void setDstHeight(int dstHeight) Sets the value of thedstHeight
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
dstHeight
- the height of the destination region.
-
setActiveSrcMinX
public void setActiveSrcMinX(int activeSrcMinX) Sets the value of theactiveSrcMinX
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
activeSrcMinX
- the minimum X coordinate of the active source region.
-
setActiveSrcMinY
public void setActiveSrcMinY(int activeSrcMinY) Sets the value of theactiveSrcMinY
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
activeSrcMinY
- the minimum Y coordinate of the active source region.
-
setActiveSrcWidth
public void setActiveSrcWidth(int activeSrcWidth) Sets the value of theactiveSrcWidth
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
activeSrcWidth
- the width of the active source region.
-
setActiveSrcHeight
public void setActiveSrcHeight(int activeSrcHeight) Sets the value of theactiveSrcHeight
field.If this method is called, the
beginDecoding
method must be called prior to calling any of the decode methods.- Parameters:
activeSrcHeight
- the height of the active source region.
-
setColorConverter
Sets theTIFFColorConverter
object describing the color space of the encoded data in the input stream. If noTIFFColorConverter
is set, no conversion will be performed.- Parameters:
colorConverter
- aTIFFColorConverter
object, ornull
.
-
getRawImageType
Returns anImageTypeSpecifier
describing an image whose underlying data array has the same format as the raw source pixel data.- Returns:
- an
ImageTypeSpecifier
.
-
createRawImage
Creates aBufferedImage
whose underlying data array will be suitable for holding the raw decoded output of thedecodeRaw
method.The default implementation calls
getRawImageType
, and calls the resultingImageTypeSpecifier
'screateBufferedImage
method.- Returns:
- a
BufferedImage
whose underlying data array has the same format as the raw source pixel data, ornull
if it is not possible to create such an image.
-
decodeRaw
public abstract void decodeRaw(byte[] b, int dstOffset, int bitsPerPixel, int scanlineStride) throws IOException Decodes the source data into the providedbyte
arrayb
, starting at the offset given bydstOffset
. Each pixel occupiesbitsPerPixel
bits, with no padding between pixels. Scanlines are separated byscanlineStride
byte
s.- Parameters:
b
- abyte
array to be written.dstOffset
- the starting offset inb
to be written.bitsPerPixel
- the number of bits for each pixel.scanlineStride
- the number ofbyte
s to advance between that starting pixels of each scanline.- Throws:
IOException
- if an error occurs reading from the sourceImageInputStream
.
-
decodeRaw
public void decodeRaw(short[] s, int dstOffset, int bitsPerPixel, int scanlineStride) throws IOException Decodes the source data into the providedshort
arrays
, starting at the offset given bydstOffset
. Each pixel occupiesbitsPerPixel
bits, with no padding between pixels. Scanlines are separated byscanlineStride
short
sThe default implementation calls
decodeRaw(byte[] b, ...)
and copies the resulting data intos
.- Parameters:
s
- ashort
array to be written.dstOffset
- the starting offset ins
to be written.bitsPerPixel
- the number of bits for each pixel.scanlineStride
- the number ofshort
s to advance between that starting pixels of each scanline.- Throws:
IOException
- if an error occurs reading from the sourceImageInputStream
.
-
decodeRaw
public void decodeRaw(int[] i, int dstOffset, int bitsPerPixel, int scanlineStride) throws IOException Decodes the source data into the providedint
arrayi
, starting at the offset given bydstOffset
. Each pixel occupiesbitsPerPixel
bits, with no padding between pixels. Scanlines are separated byscanlineStride
int
s.The default implementation calls
decodeRaw(byte[] b, ...)
and copies the resulting data intoi
.- Parameters:
i
- anint
array to be written.dstOffset
- the starting offset ini
to be written.bitsPerPixel
- the number of bits for each pixel.scanlineStride
- the number ofint
s to advance between that starting pixels of each scanline.- Throws:
IOException
- if an error occurs reading from the sourceImageInputStream
.
-
decodeRaw
public void decodeRaw(float[] f, int dstOffset, int bitsPerPixel, int scanlineStride) throws IOException Decodes the source data into the providedfloat
arrayf
, starting at the offset given bydstOffset
. Each pixel occupiesbitsPerPixel
bits, with no padding between pixels. Scanlines are separated byscanlineStride
float
s.The default implementation calls
decodeRaw(byte[] b, ...)
and copies the resulting data intof
.- Parameters:
f
- afloat
array to be written.dstOffset
- the starting offset inf
to be written.bitsPerPixel
- the number of bits for each pixel.scanlineStride
- the number offloat
s to advance between that starting pixels of each scanline.- Throws:
IOException
- if an error occurs reading from the sourceImageInputStream
.
-
beginDecoding
public void beginDecoding()This routine is called prior to a sequence of calls to thedecode
method, in order to allow any necessary tables or other structures to be initialized based on metadata values. This routine is guaranteed to be called any time the metadata values have changed.The default implementation computes tables used by the
decode
method to rescale components to different bit depths. Thus, if this method is overridden, it is important for the subclass method to callsuper()
, unless it overridesdecode
as well. -
decode
Decodes the input bit stream (located in theImageInputStream
stream
, at offsetoffset
, and continuing forbyteCount
bytes) into the outputBufferedImage
image
.The default implementation analyzes the destination image to determine if it is suitable as the destination for the
decodeRaw
method. If not, a suitable image is created. Next,decodeRaw
is called to perform the actual decoding, and the results are copied into the destination image if necessary. Subsampling and offsetting are performed automatically.The precise responsibilities of this routine are as follows. The input bit stream is defined by the instance variables
stream
,offset
, andbyteCount
. These bits contain the data for the region of the source image defined bysrcMinX
,srcMinY
,srcWidth
, andsrcHeight
.The source data is required to be subsampling, starting at the
sourceXOffset
th column and including everysubsampleX
th pixel thereafter (and similarly forsourceYOffset
andsubsampleY
).Pixels are copied into the destination with an addition shift of (
dstXOffset
,dstYOffset
). The complete set of formulas relating the source and destination coordinate spaces are:dx = (sx - sourceXOffset)/subsampleX + dstXOffset; dy = (sy - sourceYOffset)/subsampleY + dstYOffset;
Only source pixels such that(sx - sourceXOffset) % subsampleX == 0
and(sy - sourceYOffset) % subsampleY == 0
are copied.The inverse mapping, from destination to source coordinates, is one-to-one:
sx = (dx - dstXOffset)*subsampleX + sourceXOffset; sy = (dy - dstYOffset)*subsampleY + sourceYOffset;
The region of the destination image to be updated is given by the instance variables
dstMinX
,dstMinY
,dstWidth
, anddstHeight
.It is possible that not all of the source data being read will contribute to the destination image. For example, the destination offsets could be set such that some of the source pixels land outside of the bounds of the image. As a convenience, the bounds of the active source region (that is, the region of the strip or tile being read that actually contributes to the destination image, taking clipping into account) are available as
activeSrcMinX
,activeSrcMinY
,activeSrcWidth
andactiveSrcHeight
. Thus, the source pixel at (activeSrcMinX
,activeSrcMinY
) will map to the destination pixel (dstMinX
,dstMinY
).The sequence of source bands given by
sourceBands
are to be copied into the sequence of bands in the destination given bydestinationBands
.Some standard tag information is provided the instance variables
photometricInterpretation
,compression
,samplesPerPixel
,bitsPerSample
,sampleFormat
,extraSamples
, andcolorMap
.In practice, unless there is a significant performance advantage to be gained by overriding this routine, most users will prefer to use the default implementation of this routine, and instead override the
decodeRaw
and/orgetRawImageType
methods.- Throws:
IOException
- if an error occurs indecodeRaw
.
-