JIU 0.14.3

net.sourceforge.jiu.codecs.tiff
Class TIFFCodec

java.lang.Object
  extended by net.sourceforge.jiu.ops.Operation
      extended by net.sourceforge.jiu.codecs.ImageCodec
          extended by net.sourceforge.jiu.codecs.tiff.TIFFCodec
All Implemented Interfaces:
TIFFConstants

public class TIFFCodec
extends ImageCodec
implements TIFFConstants

A codec to read Tagged Image File Format (TIFF) image files.

Usage example

Load an image from a TIFF file.
 TIFFCodec codec = new TIFFCodec();
 codec.setFile("image.tif", CodecMode.LOAD);
 codec.process();
 PixelImage loadedImage = codec.getImage();
 
Saving images is not supported by this codec.

Compression types

Reading

The TIFF package supports the following compression types when reading:

Note that you can write your own decoder (extending TIFFDecoder) for any compression type you want.

Image types

Reading

The TIFF package supports the following image / color types when reading:

Note that you can write your own decoder (extending TIFFDecoder) for any compression type you want.

Writing

Writing TIFFs is not supported. I don't know if or when it will be supported.

Strips and tiles

The early versions of TIFF considered an image to be a sequence of strips. Each strip was a rectangular part of the image, as wide as the complete image, and with a certain height defined by the rows per strip tag. So with a number of rows per strip of 10, and an image height of 200, you would have to store 20 strips. It was recommended that a strip should not be larger than 8 KB (RAM was tighter in those days). The rule of thumb to define the number of rows per strip was to see how many rows would fit into 8 KB.

Later, the concept of tiles was added to the TIFF specs. Tiled TIFFs are separated into rectangles that not only had a defineable height but also a defineable width (tile width and tile height are also stored in corresponding tags).

Obviously, strips are just a special case of tiles, with the tile width being equal to image width. That is why JIU internally only deals with tiles. The only difference: No row padding takes place for strips. In a tiled image with a tile height of 10 and an image height of 14, the image is two tiles high.

Number of images

TIFF allows for multiple images in a single file. This codec regards the image index, queries ImageCodec.getImageIndex() and skips to the correct image.

Bounds

The bounds concept of JIU is supported by this codec. So you can specify bounds of a rectangular part of an image that you want to load instead of loading the complete image.

Color spaces

The following color spaces are understood when reading truecolor TIFF files.

Physical resolution

DPI information can be stored in TIFF files. If that information is available, this codec retrieves it so that it can be queried using ImageCodec.getDpiX() and ImageCodec.getDpiY().

Background information on TIFF

TIFF is an important image file format for DTP (desktop publishing). The advantages of TIFF include its flexibility, availability of libraries to read and write TIFF files and its good support in existing software. The major disadvantage of TIFF is its complexity, which makes it hard for software to support all possible valid TIFF files.

TIFF was created by Aldus and now belongs to Adobe, who offer a specification document: TIFF (Tagged Image File Format) 6.0 Specification (updated on Web September, 20 1995, document dated June, 3 1992) (PDF: 385 KB / 121 pages).

Other good references include the homepage of libtiff, a free C library to read and write TIFF files and The Unofficial TIFF homepage by Niles Ritter. Also see the TIFF section of the Open Directory.

TIFF is used for various specialized tasks. As an example, see GeoTIFF (geographical data) or EXIF (digital camera metadata; this is actually a TIFF directory embedded in a JPEG header).

Here's a list of features that make TIFF quite complex:

Author:
Marco Schmidt

Field Summary
static int BYTE_ORDER_INTEL
           
static int BYTE_ORDER_MOTOROLA
           
 
Fields inherited from interface net.sourceforge.jiu.codecs.tiff.TIFFConstants
COMPRESSION_CCITT_GROUP3_1D_MODIFIED_HUFFMAN, COMPRESSION_CCITT_T4, COMPRESSION_CCITT_T6, COMPRESSION_DEFLATED_INOFFICIAL, COMPRESSION_DEFLATED_OFFICIAL, COMPRESSION_JBIG, COMPRESSION_JBIG2, COMPRESSION_JPEG_6_0, COMPRESSION_JPEG_POST_6_0, COMPRESSION_LZW, COMPRESSION_NEXT, COMPRESSION_NONE, COMPRESSION_NONE_WORD_ALIGNED, COMPRESSION_PACKBITS, COMPRESSION_SGI_LOG_24_PACKED, COMPRESSION_SGI_LOG_RLE, COMPRESSION_THUNDERSCAN, PHOTOMETRIC_BLACK_IS_ZERO, PHOTOMETRIC_LOGL, PHOTOMETRIC_PALETTED, PHOTOMETRIC_TRUECOLOR_CMYK, PHOTOMETRIC_TRUECOLOR_LOGLUV, PHOTOMETRIC_TRUECOLOR_RGB, PHOTOMETRIC_WHITE_IS_ZERO, PLANAR_CONFIGURATION_CHUNKY, PLANAR_CONFIGURATION_PLANAR, TAG_ARTIST, TAG_BAD_FAX_LINES, TAG_BITS_PER_SAMPLE, TAG_CELL_LENGTH, TAG_CELL_WIDTH, TAG_CLEAN_FAX_DATA, TAG_COLOR_MAP, TAG_COMPRESSION, TAG_CONSECUTIVE_BAD_FAX_LINES, TAG_COPYRIGHT, TAG_DATE_TIME, TAG_DOCUMENT_NAME, TAG_EXTRA_SAMPLES, TAG_FILL_ORDER, TAG_FREE_BYTE_COUNTS, TAG_FREE_OFFSETS, TAG_GRAY_RESPONSE_CURVE, TAG_GRAY_RESPONSE_UNIT, TAG_HOST_COMPUTER, TAG_IMAGE_DESCRIPTION, TAG_IMAGE_LENGTH, TAG_IMAGE_WIDTH, TAG_LENGTH, TAG_MAKE, TAG_MAX_SAMPLE_VALUE, TAG_MIN_SAMPLE_VALUE, TAG_MODEL, TAG_NEW_SUBFILE_TYPE, TAG_ORIENTATION, TAG_PHOTOMETRIC_INTERPRETATION, TAG_PHOTOSHOP_IMAGE_RESOURCES, TAG_PLANAR_CONFIGURATION, TAG_PREDICTOR, TAG_RESOLUTION_UNIT, TAG_RESOLUTION_X, TAG_RESOLUTION_Y, TAG_ROWS_PER_STRIP, TAG_SAMPLES_PER_PIXEL, TAG_SOFTWARE, TAG_STRIP_BYTE_COUNTS, TAG_STRIP_OFFSETS, TAG_T4_OPTIONS, TAG_T6_OPTIONS, TAG_TILE_BYTE_COUNTS, TAG_TILE_HEIGHT, TAG_TILE_OFFSETS, TAG_TILE_WIDTH, TAG_TYPE_ASCII, TAG_TYPE_BYTE, TAG_TYPE_DOUBLE, TAG_TYPE_FLOAT, TAG_TYPE_LONG, TAG_TYPE_RATIONAL, TAG_TYPE_SBYTE, TAG_TYPE_SHORT, TAG_TYPE_SLONG, TAG_TYPE_SRATIONAL, TAG_TYPE_SSHORT, TAG_TYPE_UNDEFINED
 
Constructor Summary
TIFFCodec()
           
 
Method Summary
 int getByteOrder()
          Returns the current byte order, either BYTE_ORDER_INTEL or BYTE_ORDER_MOTOROLA.
 String getFormatName()
          Returns the name of the file format supported by this codec.
 String[] getMimeTypes()
          Return the MIME (Multipurpose Internet Mail Extensions) type strings for this format, or null if none are available.
static String getTagName(int id)
          Returns the name of a tag in English.
 boolean isLoadingSupported()
          Returns if this codec is able to load images in the file format supported by this codec.
 boolean isSavingSupported()
          Returns if this codec is able to save images in the file format supported by this codec.
 void process()
          This method does the actual work of the operation.
static void registerDecoder(Class decoderClass)
          Register a TIFFDecoder class.
 void setFile(String fileName, CodecMode codecMode)
          Gives a file name and codec mode to the codec which will then try to create the corresponding I/O object.
 
Methods inherited from class net.sourceforge.jiu.codecs.ImageCodec
appendComment, checkBounds, checkImageResolution, close, getBoundsHeight, getBoundsWidth, getBoundsX1, getBoundsX2, getBoundsY1, getBoundsY2, getComment, getDataInput, getDataOutput, getDpiX, getDpiY, getFileExtensions, getImage, getImageIndex, getInputAsDataInput, getInputStream, getMode, getNumComments, getOutputAsDataOutput, getOutputStream, getRandomAccessFile, hasBounds, initModeFromIOObjects, isRowRequired, isTileRequired, removeAllComments, removeBounds, setBounds, setBoundsIfNecessary, setDataInput, setDataOutput, setDpi, setFile, setImage, setImageIndex, setInputStream, setOutputStream, setRandomAccessFile, suggestFileExtension
 
Methods inherited from class net.sourceforge.jiu.ops.Operation
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_ORDER_MOTOROLA

public static final int BYTE_ORDER_MOTOROLA
See Also:
Constant Field Values

BYTE_ORDER_INTEL

public static final int BYTE_ORDER_INTEL
See Also:
Constant Field Values
Constructor Detail

TIFFCodec

public TIFFCodec()
Method Detail

getByteOrder

public int getByteOrder()
Returns the current byte order, either BYTE_ORDER_INTEL or BYTE_ORDER_MOTOROLA.

Returns:
current byte order

getFormatName

public String getFormatName()
Description copied from class: ImageCodec
Returns the name of the file format supported by this codec. All classes extending ImageCodec must override this method. When overriding, leave out any words in a particular language so that this format name can be understood by everyone. Usually it is enough to return the format creator plus a typical abbreviation, e.g. Microsoft BMP or Portable Anymap (PNM).

Specified by:
getFormatName in class ImageCodec
Returns:
name of the file format supported by this codec

getMimeTypes

public String[] getMimeTypes()
Description copied from class: ImageCodec
Return the MIME (Multipurpose Internet Mail Extensions) type strings for this format, or null if none are available.

Specified by:
getMimeTypes in class ImageCodec
Returns:
MIME type strings or null

getTagName

public static String getTagName(int id)
Returns the name of a tag in English.

Parameters:
id - of the tag for which a name is to be returned
Returns:
tag name as String or a question mark ?

isLoadingSupported

public boolean isLoadingSupported()
Description copied from class: ImageCodec
Returns if this codec is able to load images in the file format supported by this codec. If true is returned this does not necessarily mean that all files in this format can be read, but at least some.

Specified by:
isLoadingSupported in class ImageCodec
Returns:
if loading is supported

isSavingSupported

public boolean isSavingSupported()
Description copied from class: ImageCodec
Returns if this codec is able to save images in the file format supported by this codec. If true is returned this does not necessarily mean that all types files in this format can be written, but at least some.

Specified by:
isSavingSupported in class ImageCodec
Returns:
if saving is supported

process

public void process()
             throws MissingParameterException,
                    OperationFailedException
Description copied from class: Operation
This method does the actual work of the operation. It must be called after all parameters have been given to the operation object.

Overrides:
process in class Operation
Throws:
MissingParameterException - if any mandatory parameter was not given to the operation
WrongParameterException - if at least one of the input parameters was not initialized appropriately (values out of the valid interval, etc.)
OperationFailedException

registerDecoder

public static void registerDecoder(Class decoderClass)
Register a TIFFDecoder class. TIFF knows many compression types, and JIU only supports some of them. To register an external TIFFDecoder class with TIFFCodec, call this method with the class field of your decoder. As an example, for your TIFFDecoderMyCompression class, call TIFFCodec.registerDecoder(TIFFDecoderMyCompression.class). It will be checked if decoderClass.newInstance() instanceof TIFFDecoder is true and, if so, the class will be added to an internal list. Whenever a TIFF file is to be decoded, the correct decoder is determined (each decoder knows about the compression types it supports via the getCompressionTypes method) and for each tile or strip such a decoder object will be created.


setFile

public void setFile(String fileName,
                    CodecMode codecMode)
             throws IOException,
                    UnsupportedCodecModeException
Description copied from class: ImageCodec
Gives a file name and codec mode to the codec which will then try to create the corresponding I/O object. The default implementation in ImageCodec creates a DataInputStream object wrapped around a BufferedInputStream wrapped around a FileInputStream for CodecMode.LOAD. Similar for CodecMode.SAVE: a DataOutputStream around a BufferedOutputStream object around a FileOutputStream object. Codecs that need different I/O objects must override this method (some codecs may need random access and thus require a RandomAccessFile object).

Overrides:
setFile in class ImageCodec
Parameters:
fileName - name of the file to be used for loading or saving
codecMode - defines whether file is to be used for loading or saving
Throws:
IOException
UnsupportedCodecModeException

JIU 0.14.3

Copyright © 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Marco Schmidt