org.libtiff.jai.codec
Class XTIFFDirectory

java.lang.Object
  extended by org.libtiff.jai.codec.XTIFFDirectory
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
GeoTIFFDirectory

public class XTIFFDirectory
extends java.lang.Object
implements java.io.Serializable

XTIFFDirectory is an extensible TIFF directory object. This class may be extended without changing the XTIFF codec by overriding the XTIFFFactory instance registered in this class. In addition, this class is the repository of all XTIFFTileCodec's which may be augmented with new codecs, again without overriding the ImageCodec. If the jai "tiff" codec has been overridden through the XTIFFDescriptor.register() method, each XTIFF image will possess a property called "tiff.directory" which will be an object of the type created by the factory. The class is declared as serializable to permit its transmission to remote images as a set of parameters to the codec, and to be able to survive as an instantiated property of the RenderedImage.

Author:
Niles Ritter
See Also:
XTIFFDescriptor, XTIFFField, XTIFFTileCodec, XTIFFFactory, Serialized Form

Field Summary
protected static XTIFFFactory factory
          default directory factory
protected  com.sun.media.jai.codec.SeekableStream stream
          The stream being read.
protected static java.util.Hashtable tileCodecs
           
 
Constructor Summary
  XTIFFDirectory()
          The default constructor.
protected XTIFFDirectory(com.sun.media.jai.codec.SeekableStream stream, int directory)
          Constructs a XTIFFDirectory from a SeekableStream.
protected XTIFFDirectory(com.sun.media.jai.codec.SeekableStream stream, long ifd_offset)
          Constructs a XTIFFDirectory by reading a SeekableStream.
 
Method Summary
 void addField(int tag, int type, int count, java.lang.Object obj)
          Create and add a TIFF field to this directory.
 void addField(XTIFFField field)
          Add an existing TIFF field to this directory.
static XTIFFDirectory create()
          Constructs an XTIFFDirectory from the currently.
static XTIFFDirectory create(com.sun.media.jai.codec.SeekableStream stream, int directory)
          Constructs a XTIFFDirectory from a SeekableStream.
static XTIFFDirectory create(com.sun.media.jai.codec.SeekableStream stream, long ifd_offset)
          Constructs a TIFFDirectory by reading a SeekableStream.
static XTIFFField createField(int tag, int type, int count, java.lang.Object obj)
          Create a TIFF field
 XTIFFTileCodec createTileCodec(XTIFFDecodeParam param)
          Constructs a tile codec for decoding data, using the compression defined in the current directory.
 XTIFFTileCodec createTileCodec(XTIFFEncodeParam param)
          Constructs a tile codec for encoding data, using the compression defined in the current directory.
 int getCompression()
          Return the type of compression indicated in the TIFF fields, or XTIFF.COMPRESSION_NON if not specified.
 XTIFFField getField(int tag)
          Returns the value of a given tag as a XTIFFField, or null if the tag is not present.
 byte getFieldAsByte(int tag)
          Returns the value of index 0 of a given tag as a byte.
 byte getFieldAsByte(int tag, int index)
          Returns the value of a particular index of a given tag as a byte.
 double getFieldAsDouble(int tag)
          Returns the value of index 0 of a given tag as a double.
 double getFieldAsDouble(int tag, int index)
          Returns the value of a particular index of a given tag as a double.
 float getFieldAsFloat(int tag)
          Returns the value of index 0 of a given tag as a float.
 float getFieldAsFloat(int tag, int index)
          Returns the value of a particular index of a given tag as a float.
 long getFieldAsLong(int tag)
          Returns the value of index 0 of a given tag as a long.
 long getFieldAsLong(int tag, int index)
          Returns the value of a particular index of a given tag as a long.
 XTIFFField[] getFields()
          Returns an array of XTIFFFields containing all the fields in this directory.
 int getImageType()
          Get the JAI Image decoded type.
static int getNumDirectories(com.sun.media.jai.codec.SeekableStream stream)
          Returns the number of image directories (subimages) stored in a given TIFF file, represented by a SeekableStream.
 int getNumEntries()
          Returns the number of directory entries.
 int[] getTags()
          Returns an ordered array of ints indicating the tag values.
static XTIFFTileCodec getTileCodec(int comp)
          Return the currently registered XTIFFTileCodec for this compression type.
protected  void initialize()
          Initialize the directory from a stream
 boolean isBigEndian()
          Returns a boolean indicating whether the byte order used in the the TIFF file is big-endian (i.e. whether the byte order is from the most significant to the least significant)
 boolean isTagPresent(int tag)
          Returns true if a tag appears in the directory.
 boolean isTiled()
          If true this image uses TIFF 6.0 tiling
protected  double readDouble(com.sun.media.jai.codec.SeekableStream stream)
           
 java.lang.Object readFieldValue(int tag, int type, int count)
          TIFF field-value reader.
protected  float readFloat(com.sun.media.jai.codec.SeekableStream stream)
           
protected  void readHeader()
          reads the TIFF header.
protected  int readInt(com.sun.media.jai.codec.SeekableStream stream)
           
protected  long readLong(com.sun.media.jai.codec.SeekableStream stream)
           
protected  short readShort(com.sun.media.jai.codec.SeekableStream stream)
           
protected  long readUnsignedInt(com.sun.media.jai.codec.SeekableStream stream)
           
protected  int readUnsignedShort(com.sun.media.jai.codec.SeekableStream stream)
           
static void registerTileCodec(int comp, XTIFFTileCodec codec)
          Register a new XTIFFTileCodec for encoding and decoding compressed TIFF image data.
 void setCompression(int compression)
          Specifies the type of compression to be used.
static void setFactory(XTIFFFactory fact)
          Set the XTIFFFactory, which is used to construct the XTIFFDirectory object assigned as a "tiff.directory" property in the resulting jai image.
 void setImageType(int image_type)
          Set the JAI Image decoded type.
 void setIsTiled(boolean isTiled)
          If set, the data will be written out in tiled format, instead of in strips.
 int sizeOfType(int type)
          Return the size of a data type.
static void unRegisterTileCodec(int comp)
          UnRegister the XTIFFTileCodec corresponding to the TIFF compression type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factory

protected static XTIFFFactory factory
default directory factory


tileCodecs

protected static java.util.Hashtable tileCodecs

stream

protected transient com.sun.media.jai.codec.SeekableStream stream
The stream being read. Not persisted

Constructor Detail

XTIFFDirectory

public XTIFFDirectory()
The default constructor. Publicized for Serializability


XTIFFDirectory

protected XTIFFDirectory(com.sun.media.jai.codec.SeekableStream stream,
                         int directory)
                  throws java.io.IOException
Constructs a XTIFFDirectory from a SeekableStream. The directory parameter specifies which directory to read from the linked list present in the stream; directory 0 is normally read but it is possible to store multiple images in a single TIFF file by maintaing multiple directories.

Parameters:
stream - a SeekableStream to read from.
directory - the index of the directory to read.
Throws:
java.io.IOException

XTIFFDirectory

protected XTIFFDirectory(com.sun.media.jai.codec.SeekableStream stream,
                         long ifd_offset)
                  throws java.io.IOException
Constructs a XTIFFDirectory by reading a SeekableStream. The ifd_offset parameter specifies the stream offset from which to begin reading; this mechanism is sometimes used to store private IFDs within a TIFF file that are not part of the normal sequence of IFDs.

Parameters:
stream - a SeekableStream to read from.
ifd_offset - the long byte offset of the directory.
Throws:
java.io.IOException
Method Detail

isTiled

public boolean isTiled()
If true this image uses TIFF 6.0 tiling


readHeader

protected void readHeader()
                   throws java.io.IOException
reads the TIFF header. Not likely to be overridden.

Throws:
java.io.IOException

sizeOfType

public int sizeOfType(int type)
               throws java.lang.ArrayIndexOutOfBoundsException
Return the size of a data type. Extend if you need to define new TIFF field types. Also override the createField() method of the XTIFFFactory, the XTIFFField class, and the readFieldValue() method here.

Parameters:
type - the XTIFFField type code
Throws:
java.lang.ArrayIndexOutOfBoundsException
See Also:
XTIFFField, XTIFFFactory

addField

public void addField(int tag,
                     int type,
                     int count,
                     java.lang.Object obj)
Create and add a TIFF field to this directory.

Parameters:
tag - the TIFF tag listed in XTIFF
type - the TIFF field type listed in XTIFFField
count - the number of values in array obj
obj - the array of values
See Also:
XTIFFField, XTIFF

createField

public static XTIFFField createField(int tag,
                                     int type,
                                     int count,
                                     java.lang.Object obj)
Create a TIFF field

Parameters:
tag - the TIFF tag listed in XTIFF
type - the TIFF field type listed in XTIFFField
count - the number of values in array obj
obj - the array of values
See Also:
XTIFFField, XTIFF

addField

public void addField(XTIFFField field)
Add an existing TIFF field to this directory.

Parameters:
type - the XTIFFField type code
See Also:
XTIFFField

initialize

protected void initialize()
                   throws java.io.IOException
Initialize the directory from a stream

Throws:
java.io.IOException

getNumEntries

public int getNumEntries()
Returns the number of directory entries.


getField

public XTIFFField getField(int tag)
Returns the value of a given tag as a XTIFFField, or null if the tag is not present.


isTagPresent

public boolean isTagPresent(int tag)
Returns true if a tag appears in the directory.


getTags

public int[] getTags()
Returns an ordered array of ints indicating the tag values.


getFields

public XTIFFField[] getFields()
Returns an array of XTIFFFields containing all the fields in this directory.


getFieldAsByte

public byte getFieldAsByte(int tag,
                           int index)
Returns the value of a particular index of a given tag as a byte. The caller is responsible for ensuring that the tag is present and has type XTIFFField.TIFF_SBYTE, TIFF_BYTE, or TIFF_UNDEFINED.


getFieldAsByte

public byte getFieldAsByte(int tag)
Returns the value of index 0 of a given tag as a byte. The caller is responsible for ensuring that the tag is present and has type XTIFFField.TIFF_SBYTE, TIFF_BYTE, or TIFF_UNDEFINED.


getFieldAsLong

public long getFieldAsLong(int tag,
                           int index)
Returns the value of a particular index of a given tag as a long. The caller is responsible for ensuring that the tag is present and has type TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SHORT, TIFF_SSHORT, TIFF_SLONG or TIFF_LONG.


getFieldAsLong

public long getFieldAsLong(int tag)
Returns the value of index 0 of a given tag as a long. The caller is responsible for ensuring that the tag is present and has type TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SHORT, TIFF_SSHORT, TIFF_SLONG or TIFF_LONG.


getFieldAsFloat

public float getFieldAsFloat(int tag,
                             int index)
Returns the value of a particular index of a given tag as a float. The caller is responsible for ensuring that the tag is present and has numeric type (all but TIFF_UNDEFINED and TIFF_ASCII).


getFieldAsFloat

public float getFieldAsFloat(int tag)
Returns the value of index 0 of a given tag as a float. The caller is responsible for ensuring that the tag is present and has numeric type (all but TIFF_UNDEFINED and TIFF_ASCII).


getFieldAsDouble

public double getFieldAsDouble(int tag,
                               int index)
Returns the value of a particular index of a given tag as a double. The caller is responsible for ensuring that the tag is present and has numeric type (all but TIFF_UNDEFINED and TIFF_ASCII).


getFieldAsDouble

public double getFieldAsDouble(int tag)
Returns the value of index 0 of a given tag as a double. The caller is responsible for ensuring that the tag is present and has numeric type (all but TIFF_UNDEFINED and TIFF_ASCII).


readFieldValue

public java.lang.Object readFieldValue(int tag,
                                       int type,
                                       int count)
                                throws java.io.IOException,
                                       java.lang.ArrayIndexOutOfBoundsException
TIFF field-value reader. Override if there are new field types. Also override sizeOfType() and, possibly the createField method of the factory, if the field needs new accessors.

Throws:
java.io.IOException
java.lang.ArrayIndexOutOfBoundsException

readShort

protected short readShort(com.sun.media.jai.codec.SeekableStream stream)
                   throws java.io.IOException
Throws:
java.io.IOException

readUnsignedShort

protected int readUnsignedShort(com.sun.media.jai.codec.SeekableStream stream)
                         throws java.io.IOException
Throws:
java.io.IOException

readInt

protected int readInt(com.sun.media.jai.codec.SeekableStream stream)
               throws java.io.IOException
Throws:
java.io.IOException

readUnsignedInt

protected long readUnsignedInt(com.sun.media.jai.codec.SeekableStream stream)
                        throws java.io.IOException
Throws:
java.io.IOException

readLong

protected long readLong(com.sun.media.jai.codec.SeekableStream stream)
                 throws java.io.IOException
Throws:
java.io.IOException

readFloat

protected float readFloat(com.sun.media.jai.codec.SeekableStream stream)
                   throws java.io.IOException
Throws:
java.io.IOException

readDouble

protected double readDouble(com.sun.media.jai.codec.SeekableStream stream)
                     throws java.io.IOException
Throws:
java.io.IOException

getNumDirectories

public static int getNumDirectories(com.sun.media.jai.codec.SeekableStream stream)
                             throws java.io.IOException
Returns the number of image directories (subimages) stored in a given TIFF file, represented by a SeekableStream.

Throws:
java.io.IOException

isBigEndian

public boolean isBigEndian()
Returns a boolean indicating whether the byte order used in the the TIFF file is big-endian (i.e. whether the byte order is from the most significant to the least significant)


setCompression

public void setCompression(int compression)
Specifies the type of compression to be used. The compression type specified will be honored only if it is compatible with the image being written out.

Parameters:
compression - The compression type.

getCompression

public int getCompression()
Return the type of compression indicated in the TIFF fields, or XTIFF.COMPRESSION_NON if not specified.


setIsTiled

public void setIsTiled(boolean isTiled)
If set, the data will be written out in tiled format, instead of in strips.

Parameters:
isTiled - Specifies whether the image data should be wriiten out in tiled format.

createTileCodec

public XTIFFTileCodec createTileCodec(XTIFFDecodeParam param)
                               throws java.io.IOException
Constructs a tile codec for decoding data, using the compression defined in the current directory.

Parameters:
param - the encoding param
Throws:
java.io.IOException
See Also:
XTIFFTileCodec

createTileCodec

public XTIFFTileCodec createTileCodec(XTIFFEncodeParam param)
                               throws java.io.IOException
Constructs a tile codec for encoding data, using the compression defined in the current directory.

Parameters:
param - the encoding param
Throws:
java.io.IOException
See Also:
XTIFFTileCodec

setFactory

public static void setFactory(XTIFFFactory fact)
Set the XTIFFFactory, which is used to construct the XTIFFDirectory object assigned as a "tiff.directory" property in the resulting jai image.

Parameters:
fact - the factory to register. The factory is guaranteed to always be non-null; if a null is passed in then the default XTIFFFactory is used. a null object is passed in
See Also:
XTIFFFactory

create

public static XTIFFDirectory create(com.sun.media.jai.codec.SeekableStream stream,
                                    int directory)
                             throws java.io.IOException
Constructs a XTIFFDirectory from a SeekableStream. The directory parameter specifies which directory to read from the linked list present in the stream; directory 0 is normally read but it is possible to store multiple images in a single TIFF file by maintaing multiple directories.

Parameters:
stream - a SeekableStream to read from.
directory - the index of the directory to read.
Throws:
java.io.IOException
See Also:
XTIFFFactory

create

public static XTIFFDirectory create(com.sun.media.jai.codec.SeekableStream stream,
                                    long ifd_offset)
                             throws java.io.IOException
Constructs a TIFFDirectory by reading a SeekableStream. The ifd_offset parameter specifies the stream offset from which to begin reading; this mechanism is sometimes used to store private IFDs within a TIFF file that are not part of the normal sequence of IFDs. Uses the XTIFFFactory to do this, so to extend the directory class, the factory method should be extended and registered instead of this one.

Parameters:
stream - a SeekableStream to read from.
ifd_offset - the long byte offset of the directory.
Throws:
java.io.IOException
See Also:
XTIFFFactory

create

public static XTIFFDirectory create()
Constructs an XTIFFDirectory from the currently. registered XTIFFDirectory factory.

See Also:
XTIFFFactory

getTileCodec

public static XTIFFTileCodec getTileCodec(int comp)
Return the currently registered XTIFFTileCodec for this compression type. Used by the XTIFFImage to decode the compression data.

See Also:
XTIFFTileCodec

unRegisterTileCodec

public static void unRegisterTileCodec(int comp)
UnRegister the XTIFFTileCodec corresponding to the TIFF compression type.

Parameters:
comp - The TIFF compression code indicated

registerTileCodec

public static void registerTileCodec(int comp,
                                     XTIFFTileCodec codec)
Register a new XTIFFTileCodec for encoding and decoding compressed TIFF image data. This overrides any existing codec previously registered.

Parameters:
comp - The TIFF compression code indicated by the
codec - The codec to register. XTIFF.TIFFTAG_COMPRESSION field.
See Also:
XTIFFTileCodec

getImageType

public int getImageType()
Get the JAI Image decoded type. This method is called by the XTIFFTileCodeImpl object during the decode() method to determine what type of colorspace and sample model to use.


setImageType

public void setImageType(int image_type)
Set the JAI Image decoded type. This method is called by the XTIFFImage constructor to indicate to the XTIFFTileCodec what type of colorspace and sample model to use. The types are enumerated in the XTIFF class.

See Also:
XTIFF, XTIFFImage, XTIFFTileCodec