Class XTIFFTileCodecImpl
java.lang.Object
org.libtiff.jai.codec.XTIFFTileCodecImpl
- All Implemented Interfaces:
XTIFFTileCodec
- Direct Known Subclasses:
XTIFFFaxTileCodec, XTIFFLZWTileCodec, XTIFFPackTileCodec, XTIFFUncompTileCodec
Provides a base class for writing TIFF tile codecs, to
be registered with the XTIFFDirectory. This codec allows
for both decoding and (optionally) encoding of tiles, and
also handles the colorspace conversion in decoding.
At the minimum you will need to implement the two methods decodeTilePixels() for byte and short data, as well as the methods register() and create(). If your decoder requires additional parameters from the tags, set them up in initializeDecoding(), and initializeEncoding() for encoding.
To implement encoding, you must override the canEncode() method to return true, and implement encodeTilePixels().
- Author:
- Niles Ritter
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]protected short[]protected char[]protected byte[]protected DataBufferprotected char[]protected intprotected intprotected booleanprotected XTIFFDecodeParam/////////////////////////////////////////////////// / Decoding Section ///////////////////////////////////////////////////protected XTIFFDirectory/////////////////////////////////////////////////// / Common Section ///////////////////////////////////////////////////protected XTIFFEncodeParam/////////////////////////////////////////////////// / Encoding Section ///////////////////////////////////////////////////protected RenderedImageprotected intprotected booleanprotected intprotected intprotected intprotected intprotected SampleModelprotected int[]protected short[]protected intprotected intprotected intprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicate whether this codec can encode data.abstract XTIFFTileCodeccreate()Implement this to return the corresponding empty codec object.create(XTIFFDecodeParam param) The standard decoder creation methodcreate(XTIFFEncodeParam param) The method for creating an encoder from the XTIFFEncodeParam information.decode(RenderedImage img, Rectangle newRect, byte[] bpixels) Decode a rectangle of data stored in bpixels into a raster tile.protected voiddecodeColor(byte[] bpix, byte[] bdata, Rectangle newRect) Decode byte color dataprotected voiddecodeColor(byte[] bpix, short[] sdata, Rectangle newRect) Decode short pixel data, or interpret palette data as short from byte.protected voiddecodeColor(short[] spix, short[] sdata, Rectangle newRect) Decode short color data, or interpret palette data as short.protected voiddecodeColor(Rectangle newRect) Postprocess the uncompressed color data into the appropriate display color model.protected voiddecodeTilePixels(byte[] bpixels, Rectangle newRect) Decode a tile of data into either byte or short pixel buffers.abstract voiddecodeTilePixels(byte[] bpixels, Rectangle rect, byte[] pixels) decode bpixel byte array of data into pixels, packed for 1,2,4 8 bit pixels.abstract voiddecodeTilePixels(byte[] bpixels, Rectangle rect, short[] pixels) decode bpixel byte array of data into pixels, packed for 16 bit pixels.intencode(RenderedImage img, Rectangle rect, byte[] bpixels) Encode the data into buffer and return byte count Normally you will not need to override this method, but instead implement theencodeTilePixels()method.intencodeTilePixels(int[] pixels, Rectangle rect, byte[] bpixels) encode the tile in pixels into bpixels and return the byte size of the compressed data.intIf derived classes can make a better estimate for the maximum size of a compressed tile, they should override this, which assumes conservatively that it won't be worse than twice the original size.intReturns the TIFF compression typeprotected longgetLongField(int fld) A common utility method for accessing the XTIFFFields in the current image directory.protected voidgetTilePixels(Rectangle rect) Get the portion of tile fitting into buffer.voidThe method for initializing information common to both encoder and decoder.protected voidinitialize(XTIFFDecodeParam param) protected voidinitialize(XTIFFEncodeParam param) voidThe initialization method particular to decoding.voidThe initialization method particular to encoding.abstract voidregister()Registration method.voidregister(int comp) This method may be used by the implementations register() method to register itself with the XTIFFDirectory.protected WritableRastersetTilePixels(Rectangle rect) Take the values from the buffer and store them in a WritableRaster object.protected voidOne-time setup for encoding.protected voidOne-time setup for encodingprotected voidOne-time common image parameter setupprotected voidunpackShorts(byte[] byteArray, short[] output, int shortCount) A useful Method to interpret a byte array as shorts.
-
Field Details
-
directory
/////////////////////////////////////////////////// / Common Section /////////////////////////////////////////////////// -
image
-
minY
protected int minY -
minX
protected int minX -
width
protected int width -
length
protected int length -
numBands
protected int numBands -
tileLength
protected int tileLength -
tileWidth
protected int tileWidth -
compression
protected int compression -
sampleModel
-
sampleSize
protected int[] sampleSize -
bitsPerSample
protected char[] bitsPerSample -
colormap
protected char[] colormap -
encodeParam
/////////////////////////////////////////////////// / Encoding Section /////////////////////////////////////////////////// -
isTiled
protected boolean isTiled -
decodeParam
/////////////////////////////////////////////////// / Decoding Section /////////////////////////////////////////////////// -
decodePaletteAsShorts
protected boolean decodePaletteAsShorts -
unitsInThisTile
protected int unitsInThisTile -
_bdata
protected byte[] _bdata -
_sdata
protected short[] _sdata -
bpixvals
protected byte[] bpixvals -
spixvals
protected short[] spixvals -
buffer
-
dataType
protected int dataType -
image_type
protected int image_type
-
-
Constructor Details
-
XTIFFTileCodecImpl
public XTIFFTileCodecImpl()The empty constructor.
-
-
Method Details
-
register
public abstract void register()Registration method. Must be implemented by the extended class to register itself with the XTIFFDirectory for all compression codes it supports (e.g Fax codec supports 3 codes).- Specified by:
registerin interfaceXTIFFTileCodec- See Also:
-
create
Implement this to return the corresponding empty codec object. -
canEncode
public boolean canEncode()Indicate whether this codec can encode data. Override to return true only if your codec implments encoding. -
initializeDecoding
public void initializeDecoding()The initialization method particular to decoding. Extend for whatever compression-specific information or parameters is needed. The decoding parameter has already been assigned at this point, as well as the XTIFFDirectory parsed from the input stream, and so all XTIFFFields are available. -
initializeEncoding
public void initializeEncoding()The initialization method particular to encoding. Extend for whatever compression-specific information or parameters is needed. The decoding parameter has already been assigned at this point, as well as the XTIFFDirectory parsed from the input stream, and so all XTIFFFields are available. -
decodeTilePixels
decode bpixel byte array of data into pixels, packed for 1,2,4 8 bit pixels. Must implment this.- Parameters:
bpixels- the byte array of compressed input datarect- the rectangular shape of the target pixelspixels- the target decompressed pixels.
-
decodeTilePixels
decode bpixel byte array of data into pixels, packed for 16 bit pixels. Must implment this.- Parameters:
bpixels- the byte array of compressed input datarect- the rectangular shape of the target pixelspixels- the target decompressed pixels.
-
encodeTilePixels
encode the tile in pixels into bpixels and return the byte size of the compressed data. Override this method if canEncode() = true;- Parameters:
pixels- input pixelsrect- the array dimensions of samplesbpixels- the target array of compressed byte data
-
initialize
public void initialize()The method for initializing information common to both encoder and decoder. -
getLongField
protected long getLongField(int fld) A common utility method for accessing the XTIFFFields in the current image directory. -
register
public void register(int comp) This method may be used by the implementations register() method to register itself with the XTIFFDirectory.- See Also:
-
setupSourceImage
One-time common image parameter setup- Parameters:
img- the source image that will be encoded into a TIFF formatted stream, or the TIFF image from which Raster tiles will be decoded.
-
getCompression
public int getCompression()Returns the TIFF compression type- Specified by:
getCompressionin interfaceXTIFFTileCodec
-
create
The method for creating an encoder from the XTIFFEncodeParam information.- Specified by:
createin interfaceXTIFFTileCodec- Parameters:
param- the encoding parameter. It is the responsibility of the codec to initialize itself from this parameter.- Throws:
IOException
-
initialize
- Throws:
IOException
-
encode
Encode the data into buffer and return byte count Normally you will not need to override this method, but instead implement theencodeTilePixels()method.- Specified by:
encodein interfaceXTIFFTileCodec
-
setupBufferForEncoding
protected void setupBufferForEncoding()One-time setup for encoding -
getTilePixels
Get the portion of tile fitting into buffer. You probably won't need to override this.- Parameters:
rect- the region to extract from image.
-
getCompressedTileSize
If derived classes can make a better estimate for the maximum size of a compressed tile, they should override this, which assumes conservatively that it won't be worse than twice the original size.- Specified by:
getCompressedTileSizein interfaceXTIFFTileCodec- Parameters:
im- the rendered image containing the image data
-
create
The standard decoder creation method- Specified by:
createin interfaceXTIFFTileCodec- Parameters:
param- the decoding parameter. It is the responsibility of the codec to initialize itself from this parameter.- Throws:
IOException
-
initialize
- Throws:
IOException
-
setupBufferForDecoding
protected void setupBufferForDecoding()One-time setup for encoding. Some configurations require a temp array for unpacking 16-bit palette data. -
decode
Decode a rectangle of data stored in bpixels into a raster tile. Usually you will not need to override this, but instead implement the decodeTilePixels methods.- Specified by:
decodein interfaceXTIFFTileCodec
-
decodeColor
Postprocess the uncompressed color data into the appropriate display color model. This implementation Does a number of things:- For RGB color, reverse to BGR which apparently is faster for Java 2D display
- For one-bit WHITE_IS_ZERO data, flip the values so that they will look correct
- If the decodePaletteAsShorts flag is true then unpack the bits and apply the lookup table, as 16-bit lookup is not supported in JAI.
- See Also:
-
decodeTilePixels
Decode a tile of data into either byte or short pixel buffers. Override this if you have other buffer types (e.g. int) -
setTilePixels
Take the values from the buffer and store them in a WritableRaster object. -
unpackShorts
protected void unpackShorts(byte[] byteArray, short[] output, int shortCount) A useful Method to interpret a byte array as shorts. Method depends on whether the bytes are stored in a big endian or little endian format. -
decodeColor
Decode short pixel data, or interpret palette data as short from byte. -
decodeColor
Decode short color data, or interpret palette data as short. -
decodeColor
Decode byte color data
-