public abstract class TIFFDecompressor extends Object
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.
Modifier and Type | Field 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.
|
(package private) boolean |
adjustBitDepths |
(package private) int[][] |
bitDepthScale |
protected int[] |
bitsPerSample
The value of the
BitsPerSample tag. |
private int[] |
bitsPerSampleCache |
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 static boolean |
DEBUG |
private int[] |
destBitsPerSampleCache |
protected int[] |
destinationBands
The sequence of destination bands to receive the source data.
|
private int[] |
destinationBandsCache |
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.
|
(package private) boolean |
isBilevel |
(package private) boolean |
isContiguous |
private boolean |
isFirstBitDepthTable |
(package private) boolean |
isImageSimple |
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. |
private boolean |
planarCache |
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[] |
sourceBandsCache |
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 and Description |
---|
TIFFDecompressor() |
Modifier and Type | Method 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.
|
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. |
(package private) static ColorModel |
createComponentCM(ColorSpace colorSpace,
int numBands,
int dataType,
boolean hasAlpha,
boolean isAlphaPremultiplied)
Create a
ComponentColorModel for use in creating
an ImageTypeSpecifier . |
(package private) static SampleModel |
createInterleavedSM(int dataType,
int numBands)
Create a
PixelInterleavedSampleModel for use in creating
an ImageTypeSpecifier . |
private static int |
createMask(int[] bitsPerSample,
int band) |
BufferedImage |
createRawImage()
Creates a
BufferedImage whose underlying data
array will be suitable for holding the raw decoded output of
the decodeRaw method. |
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 . |
abstract void |
decodeRaw(byte[] b,
int dstOffset,
int bitsPerPixel,
int scanlineStride)
Decodes the source data into the provided
byte
array b , starting at the offset given by
dstOffset . |
void |
decodeRaw(float[] f,
int dstOffset,
int bitsPerPixel,
int scanlineStride)
Decodes the source data into the provided
float
array f , starting at the offset given by
dstOffset . |
void |
decodeRaw(int[] i,
int dstOffset,
int bitsPerPixel,
int scanlineStride)
Decodes the source data into the provided
int
array i , starting at the offset given by
dstOffset . |
void |
decodeRaw(short[] s,
int dstOffset,
int bitsPerPixel,
int scanlineStride)
Decodes the source data into the provided
short
array s , 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 TYPE s. |
ImageTypeSpecifier |
getRawImageType()
Returns an
ImageTypeSpecifier 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 an
ImageTypeSpecifier suitable for decoding an image
with the given parameters. |
private static boolean |
isDataBufferBitContiguous(SampleModel sm)
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 stride,
int w,
int h,
WritableRaster raster)
Reformats bit-discontiguous data into the
DataBuffer
of the supplied WritableRaster . |
void |
setActiveSrcHeight(int activeSrcHeight)
Sets the value of the
activeSrcHeight field. |
void |
setActiveSrcMinX(int activeSrcMinX)
Sets the value of the
activeSrcMinX field. |
void |
setActiveSrcMinY(int activeSrcMinY)
Sets the value of the
activeSrcMinY field. |
void |
setActiveSrcWidth(int activeSrcWidth)
Sets the value of the
activeSrcWidth field. |
void |
setBitsPerSample(int[] bitsPerSample)
Sets the value of the
bitsPerSample field. |
void |
setByteCount(int byteCount)
Sets the value of the
byteCount field. |
void |
setColorConverter(TIFFColorConverter colorConverter)
Sets the
TIFFColorConverter object describing the color
space of the encoded data in the input stream. |
void |
setColorMap(char[] colorMap)
Sets the value of the
colorMap field. |
void |
setCompression(int compression)
Sets the value of the
compression field. |
void |
setDestinationBands(int[] destinationBands)
Sets the value of the
destinationBands field. |
void |
setDstHeight(int dstHeight)
Sets the value of the
dstHeight field. |
void |
setDstMinX(int dstMinX)
Sets the value of the
dstMinX field. |
void |
setDstMinY(int dstMinY)
Sets the value of the
dstMinY field. |
void |
setDstWidth(int dstWidth)
Sets the value of the
dstWidth field. |
void |
setDstXOffset(int dstXOffset)
Sets the value of the
dstXOffset field. |
void |
setDstYOffset(int dstYOffset)
Sets the value of the
dstYOffset field. |
void |
setExtraSamples(int[] extraSamples)
Sets the value of the
extraSamples field. |
void |
setImage(BufferedImage image)
Sets the value of the
image field. |
void |
setMetadata(IIOMetadata metadata)
Sets the value of the
metadata field. |
void |
setOffset(long offset)
Sets the value of the
offset field. |
void |
setPhotometricInterpretation(int photometricInterpretation)
Sets the value of the
photometricInterpretation
field. |
void |
setPlanar(boolean planar)
Sets the value of the
planar field. |
void |
setReader(ImageReader reader)
Sets the value of the
reader field. |
void |
setSampleFormat(int[] sampleFormat)
Sets the value of the
sampleFormat field. |
void |
setSamplesPerPixel(int samplesPerPixel)
Sets the value of the
samplesPerPixel field. |
void |
setSourceBands(int[] sourceBands)
Sets the value of the
sourceBands field. |
void |
setSourceXOffset(int sourceXOffset)
Sets the value of the
sourceXOffset field. |
void |
setSourceYOffset(int sourceYOffset)
Sets the value of the
sourceYOffset . |
void |
setSrcHeight(int srcHeight)
Sets the value of the
srcHeight field. |
void |
setSrcMinX(int srcMinX)
Sets the value of the
srcMinX field. |
void |
setSrcMinY(int srcMinY)
Sets the value of the
srcMinY field. |
void |
setSrcWidth(int srcWidth)
Sets the value of the
srcWidth field. |
void |
setStream(ImageInputStream stream)
Sets the value of the
stream field. |
void |
setSubsampleX(int subsampleX)
Sets the value of the
subsampleX field. |
void |
setSubsampleY(int subsampleY)
Sets the value of the
subsampleY field. |
private static final boolean DEBUG
protected ImageReader reader
ImageReader
calling this
TIFFDecompressor
.protected IIOMetadata metadata
IIOMetadata
object containing metadata for the
current image.protected int photometricInterpretation
PhotometricInterpretation
tag.
Legal values are BaselineTIFFTagSet.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.protected int compression
Compression
tag. Legal values are
BaselineTIFFTagSet.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.protected boolean planar
true
if the image is encoded using separate planes.protected int samplesPerPixel
SamplesPerPixel
tag.protected int[] bitsPerSample
BitsPerSample
tag.protected int[] sampleFormat
SampleFormat
tag. Legal values
are BaselineTIFFTagSet.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.protected int[] extraSamples
ExtraSamples
tag. Legal values
are BaselineTIFFTagSet.EXTRA_SAMPLES_UNSPECIFIED
,
BaselineTIFFTagSet.EXTRA_SAMPLES_ASSOCIATED_ALPHA
,
BaselineTIFFTagSet.EXTRA_SAMPLES_UNASSOCIATED_ALPHA
,
or other value defined by a TIFF extension.protected char[] colorMap
ColorMap
tag.protected ImageInputStream stream
ImageInputStream
containing the TIFF source
data.protected long offset
ImageInputStream
of the
start of the data to be decompressed.protected int byteCount
ImageInputStream
to be decompressed.protected int srcMinX
protected int srcMinY
protected int srcWidth
protected int srcHeight
protected int sourceXOffset
dstXOffset
and subsampleX
, to map between horizontal source
and destination pixel coordinates.protected int dstXOffset
sourceXOffset
and subsampleX
, to map
between horizontal source and destination pixel coordinates.
See the comment for sourceXOffset
for the mapping equations.protected int sourceYOffset
dstYOffset
and subsampleY
, to map between vertical source and
destination pixel coordinates.protected int dstYOffset
sourceYOffset
and subsampleY
, to map
between horizontal source and destination pixel coordinates.
See the comment for sourceYOffset
for the mapping equations.protected int subsampleX
protected int subsampleY
protected int[] sourceBands
protected int[] destinationBands
protected BufferedImage rawImage
BufferedImage
for the decodeRaw
method to write into.protected BufferedImage image
protected int dstMinX
protected int dstMinY
protected int dstWidth
protected int dstHeight
protected int activeSrcMinX
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
, where k
is an integer such
that 0 <= k < dstWidth
.
protected int activeSrcMinY
The pixels in the source region to be copied are
those with Y coordinates of the form activeSrcMinY +
k*subsampleY
, where k
is an integer such
that 0 <= k < dstHeight
.
protected int activeSrcWidth
The active source width will always be equal to
(dstWidth - 1)*subsampleX + 1
.
protected int activeSrcHeight
The active source height will always be equal to
(dstHeight - 1)*subsampleY + 1
.
protected TIFFColorConverter colorConverter
TIFFColorConverter
object describing the color space of
the encoded pixel data, or null
.boolean isBilevel
boolean isContiguous
boolean isImageSimple
boolean adjustBitDepths
int[][] bitDepthScale
private boolean isFirstBitDepthTable
private boolean planarCache
private int[] destBitsPerSampleCache
private int[] sourceBandsCache
private int[] bitsPerSampleCache
private int[] destinationBandsCache
static SampleModel createInterleavedSM(int dataType, int numBands)
PixelInterleavedSampleModel
for use in creating
an ImageTypeSpecifier
. Its dimensions will be 1x1 and
it will have ascending band offsets as {0, 1, 2, ..., numBands}.dataType
- The data type (DataBuffer.TYPE_*).numBands
- The number of bands.PixelInterleavedSampleModel
.static ColorModel createComponentCM(ColorSpace colorSpace, int numBands, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied)
ComponentColorModel
for use in creating
an ImageTypeSpecifier
.private static int createMask(int[] bitsPerSample, int band)
private static int getDataTypeFromNumBits(int numBits, boolean isSigned)
private static boolean areIntArraysEqual(int[] a, int[] b)
private static int getDataTypeSize(int dataType) throws IIOException
dataType
which must be one of the DataBuffer
TYPE
s.IIOException
private static int getBitsPerPixel(SampleModel sm)
private static boolean areSampleSizesEqual(SampleModel sm)
private static boolean isDataBufferBitContiguous(SampleModel sm) throws IIOException
DataBuffer
is filled without
any interspersed padding bits.IIOException
private static void reformatData(byte[] buf, int bytesPerRow, int numRows, short[] shortData, int[] intData, int outOffset, int outStride) throws IIOException
IIOException
private static void reformatDiscontiguousData(byte[] buf, int stride, int w, int h, WritableRaster raster) throws IOException
DataBuffer
of the supplied WritableRaster
.IOException
public static ImageTypeSpecifier getRawImageTypeSpecifier(int photometricInterpretation, int compression, int samplesPerPixel, int[] bitsPerSample, int[] sampleFormat, int[] extraSamples, char[] colorMap)
ImageTypeSpecifier
suitable for decoding an image
with the given parameters.photometricInterpretation
- the value of the
PhotometricInterpretation
field.compression
- the value of the Compression
field.samplesPerPixel
- the value of the
SamplesPerPixel
field.bitsPerSample
- the value of the BitsPerSample
field.sampleFormat
- the value of the SampleFormat
field.extraSamples
- the value of the ExtraSamples
field.colorMap
- the value of the ColorMap
field.ImageTypeSpecifier
, or
null
if it is not possible to create one.public void setReader(ImageReader reader)
reader
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
reader
- the current ImageReader
.public void setMetadata(IIOMetadata metadata)
metadata
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
metadata
- the IIOMetadata
object for the
image being read.public void setPhotometricInterpretation(int photometricInterpretation)
photometricInterpretation
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
photometricInterpretation
- the photometric interpretation
value.public void setCompression(int compression)
compression
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
compression
- the compression type.public void setPlanar(boolean planar)
planar
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
planar
- true
if the image to be decoded is
stored in planar format.public void setSamplesPerPixel(int samplesPerPixel)
samplesPerPixel
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
samplesPerPixel
- the number of samples in each source
pixel.public void setBitsPerSample(int[] bitsPerSample)
bitsPerSample
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
bitsPerSample
- the number of bits for each source image
sample.public void setSampleFormat(int[] sampleFormat)
sampleFormat
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
sampleFormat
- the format of the source image data,
for example unsigned integer or floating-point.public void setExtraSamples(int[] extraSamples)
extraSamples
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
extraSamples
- the interpretation of any samples in the
source file beyond those used for basic color or grayscale
information.public void setColorMap(char[] colorMap)
colorMap
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
colorMap
- the color map to apply to the source data,
as an array of char
s.public void setStream(ImageInputStream stream)
stream
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
stream
- the ImageInputStream
to be read.public void setOffset(long offset)
offset
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
offset
- the offset of the beginning of the compressed
data.public void setByteCount(int byteCount)
byteCount
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
byteCount
- the number of bytes of compressed data.public void setSrcMinX(int srcMinX)
srcMinX
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
srcMinX
- the minimum X coordinate of the source region
being decoded, irrespective of how it will be copied into the
destination.public void setSrcMinY(int srcMinY)
srcMinY
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
srcMinY
- the minimum Y coordinate of the source region
being decoded, irrespective of how it will be copied into the
destination.public void setSrcWidth(int srcWidth)
srcWidth
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
srcWidth
- the width of the source region being decoded,
irrespective of how it will be copied into the destination.public void setSrcHeight(int srcHeight)
srcHeight
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
srcHeight
- the height of the source region being decoded,
irrespective of how it will be copied into the destination.public void setSourceXOffset(int sourceXOffset)
sourceXOffset
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
sourceXOffset
- the horizontal source offset to be used when
mapping between source and destination coordinates.public void setDstXOffset(int dstXOffset)
dstXOffset
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
dstXOffset
- the horizontal destination offset to be
used when mapping between source and destination coordinates.public void setSourceYOffset(int sourceYOffset)
sourceYOffset
.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
sourceYOffset
- the vertical source offset to be used when
mapping between source and destination coordinates.public void setDstYOffset(int dstYOffset)
dstYOffset
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
dstYOffset
- the vertical destination offset to be
used when mapping between source and destination coordinates.public void setSubsampleX(int subsampleX)
subsampleX
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
subsampleX
- the horizontal subsampling factor.IllegalArgumentException
- if subsampleX
is
less than or equal to 0.public void setSubsampleY(int subsampleY)
subsampleY
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
subsampleY
- the vertical subsampling factor.IllegalArgumentException
- if subsampleY
is
less than or equal to 0.public void setSourceBands(int[] sourceBands)
sourceBands
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
sourceBands
- an array of int
s
specifying the source bands to be read.public void setDestinationBands(int[] destinationBands)
destinationBands
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
destinationBands
- an array of int
s
specifying the destination bands to be written.public void setImage(BufferedImage image)
image
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
image
- the destination BufferedImage
.public void setDstMinX(int dstMinX)
dstMinX
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
dstMinX
- the minimum X coordinate of the destination
region.public void setDstMinY(int dstMinY)
dstMinY
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
dstMinY
- the minimum Y coordinate of the destination
region.public void setDstWidth(int dstWidth)
dstWidth
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
dstWidth
- the width of the destination region.public void setDstHeight(int dstHeight)
dstHeight
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
dstHeight
- the height of the destination region.public void setActiveSrcMinX(int activeSrcMinX)
activeSrcMinX
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
activeSrcMinX
- the minimum X coordinate of the active
source region.public void setActiveSrcMinY(int activeSrcMinY)
activeSrcMinY
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
activeSrcMinY
- the minimum Y coordinate of the active
source region.public void setActiveSrcWidth(int activeSrcWidth)
activeSrcWidth
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
activeSrcWidth
- the width of the active source region.public void setActiveSrcHeight(int activeSrcHeight)
activeSrcHeight
field.
If this method is called, the beginDecoding
method must be called prior to calling any of the decode
methods.
activeSrcHeight
- the height of the active source region.public void setColorConverter(TIFFColorConverter colorConverter)
TIFFColorConverter
object describing the color
space of the encoded data in the input stream. If no
TIFFColorConverter
is set, no conversion will be performed.colorConverter
- a TIFFColorConverter
object, or
null
.public ImageTypeSpecifier getRawImageType()
ImageTypeSpecifier
describing an image
whose underlying data array has the same format as the raw
source pixel data.ImageTypeSpecifier
.public BufferedImage createRawImage()
BufferedImage
whose underlying data
array will be suitable for holding the raw decoded output of
the decodeRaw
method.
The default implementation calls
getRawImageType
, and calls the resulting
ImageTypeSpecifier
's
createBufferedImage
method.
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.public abstract void decodeRaw(byte[] b, int dstOffset, int bitsPerPixel, int scanlineStride) throws IOException
byte
array b
, starting at the offset given by
dstOffset
. Each pixel occupies
bitsPerPixel
bits, with no padding between pixels.
Scanlines are separated by scanlineStride
byte
s.b
- a byte
array to be written.dstOffset
- the starting offset in b
to be
written.bitsPerPixel
- the number of bits for each pixel.scanlineStride
- the number of byte
s to
advance between that starting pixels of each scanline.IOException
- if an error occurs reading from the source
ImageInputStream
.public void decodeRaw(short[] s, int dstOffset, int bitsPerPixel, int scanlineStride) throws IOException
short
array s
, starting at the offset given by
dstOffset
. Each pixel occupies
bitsPerPixel
bits, with no padding between pixels.
Scanlines are separated by scanlineStride
short
s
The default implementation calls decodeRaw(byte[] b,
...)
and copies the resulting data into s
.
s
- a short
array to be written.dstOffset
- the starting offset in s
to be
written.bitsPerPixel
- the number of bits for each pixel.scanlineStride
- the number of short
s to
advance between that starting pixels of each scanline.IOException
- if an error occurs reading from the source
ImageInputStream
.public void decodeRaw(int[] i, int dstOffset, int bitsPerPixel, int scanlineStride) throws IOException
int
array i
, starting at the offset given by
dstOffset
. Each pixel occupies
bitsPerPixel
bits, with no padding between pixels.
Scanlines are separated by scanlineStride
int
s.
The default implementation calls decodeRaw(byte[] b,
...)
and copies the resulting data into i
.
i
- an int
array to be written.dstOffset
- the starting offset in i
to be
written.bitsPerPixel
- the number of bits for each pixel.scanlineStride
- the number of int
s to
advance between that starting pixels of each scanline.IOException
- if an error occurs reading from the source
ImageInputStream
.public void decodeRaw(float[] f, int dstOffset, int bitsPerPixel, int scanlineStride) throws IOException
float
array f
, starting at the offset given by
dstOffset
. Each pixel occupies
bitsPerPixel
bits, with no padding between pixels.
Scanlines are separated by scanlineStride
float
s.
The default implementation calls decodeRaw(byte[] b,
...)
and copies the resulting data into f
.
f
- a float
array to be written.dstOffset
- the starting offset in f
to be
written.bitsPerPixel
- the number of bits for each pixel.scanlineStride
- the number of float
s to
advance between that starting pixels of each scanline.IOException
- if an error occurs reading from the source
ImageInputStream
.public void beginDecoding()
decode
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 call super()
,
unless it overrides decode
as well.
public void decode() throws IOException
ImageInputStream
stream
, at offset
offset
, and continuing for byteCount
bytes) into the output BufferedImage
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
, and
byteCount
. These bits contain the data for the
region of the source image defined by srcMinX
,
srcMinY
, srcWidth
, and
srcHeight
.
The source data is required to be subsampling, starting at
the sourceXOffset
th column and including
every subsampleX
th pixel thereafter (and similarly
for sourceYOffset
and
subsampleY
).
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
, and
dstHeight
.
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
and
activeSrcHeight
. 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 by
destinationBands
.
Some standard tag information is provided the instance
variables photometricInterpretation
,
compression
, samplesPerPixel
,
bitsPerSample
, sampleFormat
,
extraSamples
, and colorMap
.
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/or
getRawImageType
methods.
IOException
- if an error occurs in
decodeRaw
.Copyright © 2016 Open Microscopy Environment