org.libtiff.jai.codec
Class XTIFFTileCodecImpl

java.lang.Object
  extended by org.libtiff.jai.codec.XTIFFTileCodecImpl
All Implemented Interfaces:
XTIFFTileCodec
Direct Known Subclasses:
XTIFFFaxTileCodec, XTIFFLZWTileCodec, XTIFFPackTileCodec, XTIFFUncompTileCodec

public abstract class XTIFFTileCodecImpl
extends java.lang.Object
implements XTIFFTileCodec

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:
XTIFFTileCodec

Constructor Summary
XTIFFTileCodecImpl()
          The empty constructor.
 
Method Summary
 boolean canEncode()
          Indicate whether this codec can encode data.
abstract  XTIFFTileCodec create()
          Implement this to return the corresponding empty codec object.
 XTIFFTileCodec create(XTIFFDecodeParam param)
          The standard decoder creation method
 XTIFFTileCodec create(XTIFFEncodeParam param)
          The method for creating an encoder from the XTIFFEncodeParam information.
 java.awt.image.WritableRaster decode(java.awt.image.RenderedImage img, java.awt.Rectangle newRect, byte[] bpixels)
          Decode a rectangle of data stored in bpixels into a raster tile.
abstract  void decodeTilePixels(byte[] bpixels, java.awt.Rectangle rect, byte[] pixels)
          decode bpixel byte array of data into pixels, packed for 1,2,4 8 bit pixels.
abstract  void decodeTilePixels(byte[] bpixels, java.awt.Rectangle rect, short[] pixels)
          decode bpixel byte array of data into pixels, packed for 16 bit pixels.
 int encode(java.awt.image.RenderedImage img, java.awt.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 the encodeTilePixels() method.
 int encodeTilePixels(int[] pixels, java.awt.Rectangle rect, byte[] bpixels)
          encode the tile in pixels into bpixels and return the byte size of the compressed data.
 int getCompressedTileSize(java.awt.image.RenderedImage im)
          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.
 int getCompression()
          Returns the TIFF compression type
 void initialize()
          The method for initializing information common to both encoder and decoder.
 void initializeDecoding()
          The initialization method particular to decoding.
 void initializeEncoding()
          The initialization method particular to encoding.
abstract  void register()
          Registration method.
 void register(int comp)
          This method may be used by the implementations register() method to register itself with the XTIFFDirectory.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XTIFFTileCodecImpl

public XTIFFTileCodecImpl()
The empty constructor.

Method Detail

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:
register in interface XTIFFTileCodec
See Also:
XTIFFDirectory

create

public abstract XTIFFTileCodec 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

public abstract void decodeTilePixels(byte[] bpixels,
                                      java.awt.Rectangle rect,
                                      byte[] pixels)
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 data
rect - the rectangular shape of the target pixels
pixels - the target decompressed pixels.

decodeTilePixels

public abstract void decodeTilePixels(byte[] bpixels,
                                      java.awt.Rectangle rect,
                                      short[] pixels)
decode bpixel byte array of data into pixels, packed for 16 bit pixels. Must implment this.

Parameters:
bpixels - the byte array of compressed input data
rect - the rectangular shape of the target pixels
pixels - the target decompressed pixels.

encodeTilePixels

public int encodeTilePixels(int[] pixels,
                            java.awt.Rectangle rect,
                            byte[] bpixels)
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 pixels
rect - the array dimensions of samples
bpixels - the target array of compressed byte data

initialize

public void initialize()
The method for initializing information common to both encoder and decoder.


register

public void register(int comp)
This method may be used by the implementations register() method to register itself with the XTIFFDirectory.

See Also:
XTIFFDirectory

getCompression

public int getCompression()
Returns the TIFF compression type

Specified by:
getCompression in interface XTIFFTileCodec

create

public XTIFFTileCodec create(XTIFFEncodeParam param)
                      throws java.io.IOException
The method for creating an encoder from the XTIFFEncodeParam information.

Specified by:
create in interface XTIFFTileCodec
Parameters:
param - the encoding parameter. It is the responsibility of the codec to initialize itself from this parameter.
Throws:
java.io.IOException

encode

public int encode(java.awt.image.RenderedImage img,
                  java.awt.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 the encodeTilePixels() method.

Specified by:
encode in interface XTIFFTileCodec

getCompressedTileSize

public int getCompressedTileSize(java.awt.image.RenderedImage im)
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:
getCompressedTileSize in interface XTIFFTileCodec
Parameters:
im - the rendered image containing the image data

create

public XTIFFTileCodec create(XTIFFDecodeParam param)
                      throws java.io.IOException
The standard decoder creation method

Specified by:
create in interface XTIFFTileCodec
Parameters:
param - the decoding parameter. It is the responsibility of the codec to initialize itself from this parameter.
Throws:
java.io.IOException

decode

public java.awt.image.WritableRaster decode(java.awt.image.RenderedImage img,
                                            java.awt.Rectangle newRect,
                                            byte[] bpixels)
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:
decode in interface XTIFFTileCodec