Copyright 2011-01-06 Werner Randelshofer

ch.randelshofer.media.tiff
Class TIFFInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by ch.randelshofer.media.tiff.TIFFInputStream
All Implemented Interfaces:
java.io.Closeable

public class TIFFInputStream
extends java.io.InputStream

Reads a TIFF file.

Source:

TIFF TM Revision 6.0. Final — June 3, 1992. Adobe Systems Inc. http://www.exif.org/specifications.html

Version:
1.0 2009-12-26 Created.
Author:
Werner Randelshofer

Constructor Summary
TIFFInputStream(javax.imageio.stream.ImageInputStream in)
           
TIFFInputStream(javax.imageio.stream.ImageInputStream in, java.nio.ByteOrder byteOrder, long firstIFDOffset)
          Creates a TIFFInputStream from a stream which does not have a header.
 
Method Summary
 java.nio.ByteOrder getByteOrder()
           
 long getFirstIFDOffset()
           
 int read()
           
 int read(byte[] b, int off, int len)
           
 int read(long offset, byte[] b, int off, int len)
           
 java.lang.String readASCII(long offset, long length)
          Reads an ASCII (8-bit byte that contains a 7-bit ASCII code; the last byte must be NUL (binary zero).
 IFD readIFD(long offset)
          Reads the IFD at the specified offset.
 IFD readIFD(long offset, boolean hasNextOffset, boolean isFirstIFD)
          Reads the IFD at the specified offset.
 long readLONG(long offset)
          Reads a LONG (32-bit (4-byte) unsigned integer).
 long[] readLONG(long offset, long count)
          Reads the specified number of LONGs (32-bit (4-byte) unsigned integer).
 Rational readRATIONAL(long offset)
          Reads a RATIONAL number at the specified offset.
 Rational[] readRATIONAL(long offset, long count)
          Reads the specified number of RATIONALs at the specified offset.
 int[] readSHORT(long offset, long count)
          Reads the specified number of SHORTs (16-bit (2-byte) unsigned integer).
 Rational readSRATIONAL(long offset)
          Reads a RATIONAL number at the specified offset.
 Rational[] readSRATIONAL(long offset, long count)
          Reads the specified number of RATIONALs at the specified offset.
 short[] readSSHORT(long offset, long count)
          Reads the specified number of SSHORTs (16-bit (2-byte) signed integer).
 void setByteOrder(java.nio.ByteOrder newValue)
           
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TIFFInputStream

public TIFFInputStream(javax.imageio.stream.ImageInputStream in)
                throws java.io.IOException
Throws:
java.io.IOException

TIFFInputStream

public TIFFInputStream(javax.imageio.stream.ImageInputStream in,
                       java.nio.ByteOrder byteOrder,
                       long firstIFDOffset)
Creates a TIFFInputStream from a stream which does not have a header.

Method Detail

getByteOrder

public java.nio.ByteOrder getByteOrder()

setByteOrder

public void setByteOrder(java.nio.ByteOrder newValue)

getFirstIFDOffset

public long getFirstIFDOffset()

readIFD

public IFD readIFD(long offset)
            throws java.io.IOException
Reads the IFD at the specified offset.

An IFD consists of a 2-byte count of the number of directory entries (i.e., the number of fields), followed by a sequence of 12-byte field entries, followed by a 4-byte offset of the next IFD (or 0 if none).

Each 12-byte IFD entry has the following format: Bytes 0-1 The Tag that identifies the field. Bytes 2-3 The field Type. Bytes 4-7 The number of values, Count of the indicated Type. Bytes 8-11 The Value Offset, the file offset (in bytes) of the Value for the field. The Value is expected to begin on a word boundary; the corresponding Value Offset will thus be an even number. This file offset may point anywhere in the file, even after the image data.

There must be at least 1 IFD in a TIFF file and each IFD must have at least one entry.

Throws:
java.io.IOException

readIFD

public IFD readIFD(long offset,
                   boolean hasNextOffset,
                   boolean isFirstIFD)
            throws java.io.IOException
Reads the IFD at the specified offset.

An IFD consists of a 2-byte count of the number of directory entries (i.e., the number of fields), followed by a sequence of 12-byte field entries, followed by a 4-byte offset of the next IFD (or 0 if none).

Each 12-byte IFD entry has the following format: Bytes 0-1 The Tag that identifies the field. Bytes 2-3 The field Type. Bytes 4-7 The number of values, Count of the indicated Type. Bytes 8-11 The Value Offset, the file offset (in bytes) of the Value for the field. The Value is expected to begin on a word boundary; the corresponding Value Offset will thus be an even number. This file offset may point anywhere in the file, even after the image data.

There must be at least 1 IFD in a TIFF file and each IFD must have at least one entry.

Throws:
java.io.IOException

readASCII

public java.lang.String readASCII(long offset,
                                  long length)
                           throws java.io.IOException
Reads an ASCII (8-bit byte that contains a 7-bit ASCII code; the last byte must be NUL (binary zero). value at the specified offset.

Throws:
java.io.IOException

readLONG

public long readLONG(long offset)
              throws java.io.IOException
Reads a LONG (32-bit (4-byte) unsigned integer). value at the specified offset.

Throws:
java.io.IOException

readLONG

public long[] readLONG(long offset,
                       long count)
                throws java.io.IOException
Reads the specified number of LONGs (32-bit (4-byte) unsigned integer). value at the specified offset.

Throws:
java.io.IOException

readSHORT

public int[] readSHORT(long offset,
                       long count)
                throws java.io.IOException
Reads the specified number of SHORTs (16-bit (2-byte) unsigned integer). value at the specified offset.

Throws:
java.io.IOException

readSSHORT

public short[] readSSHORT(long offset,
                          long count)
                   throws java.io.IOException
Reads the specified number of SSHORTs (16-bit (2-byte) signed integer). value at the specified offset.

Throws:
java.io.IOException

readRATIONAL

public Rational readRATIONAL(long offset)
                      throws java.io.IOException
Reads a RATIONAL number at the specified offset.

Throws:
java.io.IOException

readSRATIONAL

public Rational readSRATIONAL(long offset)
                       throws java.io.IOException
Reads a RATIONAL number at the specified offset.

Throws:
java.io.IOException

readRATIONAL

public Rational[] readRATIONAL(long offset,
                               long count)
                        throws java.io.IOException
Reads the specified number of RATIONALs at the specified offset.

Throws:
java.io.IOException

readSRATIONAL

public Rational[] readSRATIONAL(long offset,
                                long count)
                         throws java.io.IOException
Reads the specified number of RATIONALs at the specified offset.

Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(long offset,
                byte[] b,
                int off,
                int len)
         throws java.io.IOException
Throws:
java.io.IOException

Copyright 2011-01-06 Werner Randelshofer