Package net.sourceforge.jiu.codecs.tiff
Class TIFFDecoder
java.lang.Object
net.sourceforge.jiu.codecs.tiff.TIFFDecoder
- Direct Known Subclasses:
TIFFDecoderDeflated
,TIFFDecoderLogLuv
,TIFFDecoderModifiedHuffman
,TIFFDecoderPackbits
,TIFFDecoderUncompressed
The abstract base class for a TIFF decoder, a class that decompresses one tile or
strip of image data and understands one or more compression types.
Each child class implements the decoding of a particular TIFF compression type
in its
decode()
method.
This class does all the work of storing decompressed data (given as a byte array) in the image object. Given the many variants (sample order, color depth, color space etc.) this is a larger portion of code.
- Since:
- 0.7.0
- Author:
- Marco Schmidt
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private int
private TIFFCodec
private int
private TIFFImageFileDirectory
private int
private int
private int
private byte[]
private int
private int
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
decode()
Decode data from input and write the decompressed pixel data to the image associated with this decoder.int
Returns the number of bytes per row for the strip or tile that this decoder deals with.getCodec()
Returns the codec from which this decoder is used.abstract Integer[]
Returns an array with Integer values of all compression types supported by this decoder (see the COMPRESSION_xyz constants inTIFFConstants
.Returns the IFD for the image this decoder is supposed to uncompress (partially).getInput()
Returns the input stream from which this decoder is supposed to read data.int
Returns the zero-based index of the tile or strip this decoder is supposed to be decompressing.int
getX1()
Returns the leftmost column of the image strip / tile to be read by this decoder.int
getX2()
Returns the rightmost column of the image strip / tile to be read by this decoder.int
getY1()
Returns the top row of the image strip / tile to be read by this decoder.int
getY2()
Returns the bottom row of the image strip / tile to be read by this decoder.void
Check if all necessary parameters have been given to this decoder and initialize several internal fields from them.void
putBytes
(byte[] data, int offset, int number) Adds a number of bytes to the internal row buffer.void
Specify the codec to be used with this decoder.void
Specify the IFD to be used with this decoder.void
setTileIndex
(int index) Specify the zero-based tile index for the tile or strip to be decompressed by this decoder.private void
storeRow
(byte[] data, int offset)
-
Field Details
-
codec
-
ifd
-
currentRow
private int currentRow -
leftColumn
private int leftColumn -
rightColumn
private int rightColumn -
topRow
private int topRow -
bottomRow
private int bottomRow -
rowBuffer
private byte[] rowBuffer -
bufferIndex
private int bufferIndex -
tileIndex
private int tileIndex -
processedTileRows
private int processedTileRows -
totalTileRows
private int totalTileRows
-
-
Constructor Details
-
TIFFDecoder
public TIFFDecoder()
-
-
Method Details
-
decode
Decode data from input and write the decompressed pixel data to the image associated with this decoder. Child classes must override this method to implement the decoding for a particular compression type. -
getBytesPerRow
public int getBytesPerRow()Returns the number of bytes per row for the strip or tile that this decoder deals with. So with a tiled TIFF and an image width of 500 and a tile width of 100, for an eight bit grayscale image this would return 100 (not 500).- Returns:
- number of bytes per row
-
getCodec
Returns the codec from which this decoder is used.- Returns:
- TIFFCodec object using this decoder
-
getCompressionTypes
Returns an array with Integer values of all compression types supported by this decoder (see the COMPRESSION_xyz constants inTIFFConstants
. Normally, this is only one value, but some compression types got assigned more than one constant (e.g. deflated). Also, a decoder could be capable of dealing with more than one type of compression if the compression types are similar enough to justify that. However, typically a decoder can only deal with one type of compression.- Returns:
- array with Integer objects of all TIFF compression constants supported by this decoder
-
getImageFileDirectory
Returns the IFD for the image this decoder is supposed to uncompress (partially).- Returns:
- IFD object
-
getInput
Returns the input stream from which this decoder is supposed to read data. -
getTileIndex
public int getTileIndex()Returns the zero-based index of the tile or strip this decoder is supposed to be decompressing.- Returns:
- tile index
-
getX1
public int getX1()Returns the leftmost column of the image strip / tile to be read by this decoder. -
getX2
public int getX2()Returns the rightmost column of the image strip / tile to be read by this decoder. -
getY1
public int getY1()Returns the top row of the image strip / tile to be read by this decoder. -
getY2
public int getY2()Returns the bottom row of the image strip / tile to be read by this decoder. -
initialize
Check if all necessary parameters have been given to this decoder and initialize several internal fields from them. Required parameters are a TIFFCodec object, a TIFFImageFileDirectory object and a tile index.- Throws:
IOException
MissingParameterException
-
putBytes
public void putBytes(byte[] data, int offset, int number) Adds a number of bytes to the internal row buffer. If the row buffer gets full (a complete line is available) that data will be copied to the image. Note that more than one line, exactly one line or only part of a line can be stored in thenumber
bytes indata
.- Parameters:
data
- byte array with image data that has been decodedoffset
- int index into data where the first byte to be stored is situatednumber
- int number of bytes to be stored
-
setCodec
Specify the codec to be used with this decoder. This is a mandatory parameter - without it,initialize()
will throw an exception.- Parameters:
tiffCodec
- TIFFCodec object to be used by this decoder- See Also:
-
setImageFileDirectory
Specify the IFD to be used with this decoder. This is a mandatory parameter - without it,initialize()
will throw an exception.- Parameters:
tiffIfd
- object to be used by this decoder- See Also:
-
setTileIndex
public void setTileIndex(int index) Specify the zero-based tile index for the tile or strip to be decompressed by this decoder. This is a mandatory parameter - without it,initialize()
will throw an exception.- Parameters:
index
- zero-based tile / strip index- See Also:
-
storeRow
private void storeRow(byte[] data, int offset)
-