edu.harvard.hul.ois.jhove.module.tiff
Class IFD

java.lang.Object
  extended by edu.harvard.hul.ois.jhove.module.tiff.IFD
Direct Known Subclasses:
ExifIFD, GlobalParametersIFD, GPSInfoIFD, InteroperabilityIFD, TiffIFD

public abstract class IFD
extends java.lang.Object

Encapsulation of a TIFF image file directory (IFD).


Field Summary
protected  boolean _bigEndian
          True if big-endian file.
protected  RepInfo _info
          Representation information.
protected  long _next
          Offset of next IFD.
protected  long _offset
          IFD offset.
protected  int _version
          TIFF version.
static int ASCII
          TIFF ASCII type.
static int BYTE
          TIFF BYTE (unsigned 8-bit) type.
static int DOUBLE
          TIFF DOUBLE (64-bit IEEE floating point) type.
static int EXIF
          Exif IFD.
static int FLOAT
          TIFF FLOAT (32-bit IEEE floating point) type.
static int GLOBALPARAMETERS
          Global parameters IFD.
static int GPSINFO
          GPSInfo IFD.
static int IFD
          TIFF IFD (LONG) type.
static int INTEROPERABILITY
          Exif Interoperability IFD.
static int LONG
          TIFF LONG (unsigned 32-bit) type.
static int NULL
          Undefined value for integer tags.
static int RATIONAL
          TIFF RATIONAL (two LONGs) type.
static int SBYTE
          TIFF SBYTE (signed 8-bit) type.
static int SHORT
          TIFF SHORT (unsigned 16-bit) type.
static int SLONG
          TIFF SLONG (signed 32-bit) type.
static int SRATIONAL
          TIFF SRATIONAL (two SLONGs) type.
static int SSHORT
          TIFF SSHORT (signed 16-bit) type.
static int TIFF
          Standard TIFF IFD.
static java.lang.String[] TYPE
          TIFF type labels.
static int UNDEFINED
          TIFF UNDEFINED (unsigned 8-bit) type.
 
Constructor Summary
IFD(long offset, RepInfo info, java.io.RandomAccessFile raf, boolean bigEndian)
          Instantiate an IFD object.
 
Method Summary
protected  Property addBitmaskProperty(java.lang.String name, long value, java.lang.String[] labels, boolean rawOutput)
          Returns a Property representing a bitmask.
protected  Property addIntegerArrayProperty(java.lang.String name, int[] value, java.lang.String[] labels, boolean rawOutput)
          Returns an ARRAY Property representing an integer array.
protected  Property addIntegerProperty(java.lang.String name, int value, java.lang.String[] labels, boolean rawOutput)
          Returns an Property representing an integer value.
protected  Property addIntegerProperty(java.lang.String name, int value, java.lang.String[] labels, int[] index, boolean rawOutput)
          Returns an Property representing an integer value.
protected  Property addRationalArrayProperty(java.lang.String name, Rational[] r, boolean rawOutput)
           
protected  Property addRationalProperty(java.lang.String name, Rational r, boolean rawOutput)
          Returns a property for a tag with a RATIONAL value.
protected static Rational average(Rational r1, Rational r2)
           
static long calcValueSize(int type, long count)
          Calculate how many bytes a given number of fields of a given type will require.
protected static void checkCount(int tag, long count, int minCount)
          Check the tag entry count.
protected static void checkType(int tag, int type, int expected)
          Check the tag entry type.
protected static void checkType(int tag, int type, int type1, int type2)
          Check the tag entry type.
 java.util.List<java.lang.String> getErrors()
          Get any errors discovered during parsing.
 long getNext()
          Get the offset of the next IFD.
 long getOffset()
          Get the IFD offset.
abstract  Property getProperty(boolean rawOutput)
          Get the IFD properties.
 int getVersion()
          Get the TIFF version.
 boolean isBigEndian()
          Returns true if file is big-endian, false if little-endian.
 boolean isFirst()
          Return true if this is the first IFD.
 boolean isThumbnail()
          Return true if this is the thumbnail IFD.
abstract  void lookupTag(int tag, int type, long count, long value)
          Lookup IFD tag.
 long parse()
          Parse the IFD.
 long parse(boolean byteOffsetIsValid)
          Parse the IFD.
 long parse(boolean byteOffsetIsValid, boolean suppressErrors)
          Parse the IFD.
protected  void postParseInitialization()
          Perform initializations that have to wait until after the IFD has been parsed.
protected  Property propertyHeader(java.lang.String type, java.util.List entries)
          Standard IFD property header.
protected  java.lang.String readASCII(long count, long value)
          Reads a string value from the TIFF file.
protected  java.lang.String[] readASCIIArray(long count, long value)
          Reads an array of strings from the TIFF file.
protected  int readByte(int type, long count, long value)
          Reads and returns a single unsigned 8-bit integer value.
protected  int[] readByteArray(int type, long count, long value)
          Reads an array of bytes and returns it as an int array.
protected  double[] readDoubleArray(long count, long value)
          Reads a TIFF array of DOUBLE 64-bit values and returns it as a double array.
protected  long readLong(int type, long count, long value)
          Reads and returns a single unsigned 32-bit integer value.
protected  long[] readLongArray(int type, long count, long value)
          Reads a TIFF array of signed 32-bit integer values and returns it as a long array.
protected  Rational readRational(long count, long value)
          Reads a RATIONAL value and returns it as a Rational.
protected  Rational[] readRationalArray(long count, long value)
          Reads an array of RATIONAL values and returns it as an array of Rational.
protected  int readShort(int type, long count, long value)
          Reads and returns a single unsigned 16-bit value.
protected  int[] readShortArray(int type, long count, long value)
          Reads a TIFF array of unsigned 16-bit values and returns it as an int array.
protected  Rational readSignedRational(long count, long value)
          Reads an SRATIONAL value and returns it as a Rational.
protected  Rational[] readSignedRationalArray(long count, long value)
          Reads an array of SRATIONAL values and returns it as an array of Rational.
protected  int[] readSShortArray(int type, long count, long value)
          Reads a TIFF array of signed 16-bit values and returns it as an int array.
protected  byte[] readTrueByteArray(int type, long count, long value)
          Reads an array of bytes and returns it as a byte array.
 long readUnsigned(int type)
          Reads an unsigned number of any type.
 void setFirst(boolean first)
          Sets flag indicating whether this is the first IFD.
 void setThumbnail(boolean thumbnail)
          Sets flag indicating whether this is the "thumbnail" IFD.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIFF

public static final int TIFF
Standard TIFF IFD.

See Also:
Constant Field Values

EXIF

public static final int EXIF
Exif IFD.

See Also:
Constant Field Values

INTEROPERABILITY

public static final int INTEROPERABILITY
Exif Interoperability IFD.

See Also:
Constant Field Values

GPSINFO

public static final int GPSINFO
GPSInfo IFD.

See Also:
Constant Field Values

GLOBALPARAMETERS

public static final int GLOBALPARAMETERS
Global parameters IFD.

See Also:
Constant Field Values

NULL

public static final int NULL
Undefined value for integer tags.

See Also:
Constant Field Values

BYTE

public static final int BYTE
TIFF BYTE (unsigned 8-bit) type.

See Also:
Constant Field Values

ASCII

public static final int ASCII
TIFF ASCII type.

See Also:
Constant Field Values

SHORT

public static final int SHORT
TIFF SHORT (unsigned 16-bit) type.

See Also:
Constant Field Values

LONG

public static final int LONG
TIFF LONG (unsigned 32-bit) type.

See Also:
Constant Field Values

RATIONAL

public static final int RATIONAL
TIFF RATIONAL (two LONGs) type.

See Also:
Constant Field Values

SBYTE

public static final int SBYTE
TIFF SBYTE (signed 8-bit) type.

See Also:
Constant Field Values

UNDEFINED

public static final int UNDEFINED
TIFF UNDEFINED (unsigned 8-bit) type.

See Also:
Constant Field Values

SSHORT

public static final int SSHORT
TIFF SSHORT (signed 16-bit) type.

See Also:
Constant Field Values

SLONG

public static final int SLONG
TIFF SLONG (signed 32-bit) type.

See Also:
Constant Field Values

SRATIONAL

public static final int SRATIONAL
TIFF SRATIONAL (two SLONGs) type.

See Also:
Constant Field Values

FLOAT

public static final int FLOAT
TIFF FLOAT (32-bit IEEE floating point) type.

See Also:
Constant Field Values

DOUBLE

public static final int DOUBLE
TIFF DOUBLE (64-bit IEEE floating point) type.

See Also:
Constant Field Values

IFD

public static final int IFD
TIFF IFD (LONG) type.

See Also:
Constant Field Values

TYPE

public static final java.lang.String[] TYPE
TIFF type labels.


_bigEndian

protected boolean _bigEndian
True if big-endian file.


_info

protected RepInfo _info
Representation information.


_next

protected long _next
Offset of next IFD.


_offset

protected long _offset
IFD offset.


_version

protected int _version
TIFF version.

Constructor Detail

IFD

public IFD(long offset,
           RepInfo info,
           java.io.RandomAccessFile raf,
           boolean bigEndian)
Instantiate an IFD object.

Parameters:
offset - IFD offset
info - Representation information
raf - TIFF file
bigEndian - True if big-endian file
Method Detail

getErrors

public java.util.List<java.lang.String> getErrors()
Get any errors discovered during parsing.


getNext

public long getNext()
Get the offset of the next IFD.


getOffset

public long getOffset()
Get the IFD offset.


getProperty

public abstract Property getProperty(boolean rawOutput)
                              throws TiffException
Get the IFD properties.

Throws:
TiffException

getVersion

public int getVersion()
Get the TIFF version.


isFirst

public boolean isFirst()
Return true if this is the first IFD.


isThumbnail

public boolean isThumbnail()
Return true if this is the thumbnail IFD.


lookupTag

public abstract void lookupTag(int tag,
                               int type,
                               long count,
                               long value)
                        throws TiffException
Lookup IFD tag.

Throws:
TiffException

parse

public long parse()
           throws TiffException
Parse the IFD. Errors are not suppressed, and odd byte offsets for tags not allowed.

Returns:
The offset of the next IFD
Throws:
TiffException

parse

public long parse(boolean byteOffsetIsValid,
                  boolean suppressErrors)
           throws TiffException
Parse the IFD.

Parameters:
byteOffsetIsValid - If true, allow offsets on odd byte boundaries
suppressErrors - If true, return IFD even with errors
Returns:
The offset of the next IFD
Throws:
TiffException

parse

public long parse(boolean byteOffsetIsValid)
           throws TiffException
Parse the IFD. Errors are not suppressed.

Parameters:
byteOffsetIsValid - If true, allow offsets on odd byte boundaries
Returns:
The offset of the next IFD
Throws:
TiffException

setFirst

public void setFirst(boolean first)
Sets flag indicating whether this is the first IFD.


setThumbnail

public void setThumbnail(boolean thumbnail)
Sets flag indicating whether this is the "thumbnail" IFD. The second IFD in the top-level chain is assumed to be the Thumbnail IFD.


addBitmaskProperty

protected Property addBitmaskProperty(java.lang.String name,
                                      long value,
                                      java.lang.String[] labels,
                                      boolean rawOutput)
Returns a Property representing a bitmask. If rawOutput is true, returns a LIST property whose elements are STRING properties. The string values of these STRING properties are the elements of labels whose indices correspond to 1 bits in the bitmask, counting the low-order bit as bit 0. if rawOutput is false, returns a LONG property whose numeric value is value.


addIntegerProperty

protected Property addIntegerProperty(java.lang.String name,
                                      int value,
                                      java.lang.String[] labels,
                                      boolean rawOutput)
Returns an Property representing an integer value. If rawOutput is true, returns an INTEGER property, and labels and index are unused. Otherwise, returns a STRING property, with the string being the element of labels whose index is value.


addIntegerProperty

protected Property addIntegerProperty(java.lang.String name,
                                      int value,
                                      java.lang.String[] labels,
                                      int[] index,
                                      boolean rawOutput)
Returns an Property representing an integer value. If rawOutput is true, returns an INTEGER property, and labels and index are unused. Otherwise, returns a STRING property, with the string being the element of labels whose index is the index of value in index.


addIntegerArrayProperty

protected Property addIntegerArrayProperty(java.lang.String name,
                                           int[] value,
                                           java.lang.String[] labels,
                                           boolean rawOutput)
Returns an ARRAY Property representing an integer array. If rawOutput is true, the elements of the property array are INTEGER properties, and labels is unused. Otherwise, the elements of the array are STRING properties, with the elements of value used as indices into labels.


addRationalProperty

protected Property addRationalProperty(java.lang.String name,
                                       Rational r,
                                       boolean rawOutput)
Returns a property for a tag with a RATIONAL value. If rawOutput is true, returns a property with type RATIONAL. Otherwise, returns a property with type STRING, and the text representation of the Rational value as a floating-point ratio.


addRationalArrayProperty

protected Property addRationalArrayProperty(java.lang.String name,
                                            Rational[] r,
                                            boolean rawOutput)

postParseInitialization

protected void postParseInitialization()
Perform initializations that have to wait until after the IFD has been parsed.


propertyHeader

protected Property propertyHeader(java.lang.String type,
                                  java.util.List entries)
Standard IFD property header.


readASCII

protected java.lang.String readASCII(long count,
                                     long value)
                              throws java.io.IOException
Reads a string value from the TIFF file. If there are non-ASCII characters, they're escaped as %XX

Parameters:
count - Length of string
value - Offset of string
Throws:
java.io.IOException

readASCIIArray

protected java.lang.String[] readASCIIArray(long count,
                                            long value)
                                     throws java.io.IOException
Reads an array of strings from the TIFF file.

Parameters:
count - Number of strings to read
value - Offset from which to read
Throws:
java.io.IOException

readByte

protected int readByte(int type,
                       long count,
                       long value)
                throws java.io.IOException
Reads and returns a single unsigned 8-bit integer value.

Parameters:
type - TIFF type to read; must be an 8-bit type
count - Unused
value - Offset from which to read
Throws:
java.io.IOException

readByteArray

protected int[] readByteArray(int type,
                              long count,
                              long value)
                       throws java.io.IOException
Reads an array of bytes and returns it as an int array.

Parameters:
type - TIFF type to read; must be an 8-bit type
count - Number of bytes to read
value - Offset from which to read
Throws:
java.io.IOException

readTrueByteArray

protected byte[] readTrueByteArray(int type,
                                   long count,
                                   long value)
                            throws java.io.IOException
Reads an array of bytes and returns it as a byte array.

Parameters:
type - Unused
count - Number of bytes to read
value - Offset from which to read
Throws:
java.io.IOException

readDoubleArray

protected double[] readDoubleArray(long count,
                                   long value)
                            throws java.io.IOException
Reads a TIFF array of DOUBLE 64-bit values and returns it as a double array.

Parameters:
count - Number of values to read
value - Offset from which to read
Throws:
java.io.IOException

readLong

protected long readLong(int type,
                        long count,
                        long value)
                 throws java.io.IOException
Reads and returns a single unsigned 32-bit integer value.

Parameters:
type - TIFF type to read; must be a 32-bit type
count - Unused
value - Offset from which to read
Throws:
java.io.IOException

readLongArray

protected long[] readLongArray(int type,
                               long count,
                               long value)
                        throws java.io.IOException
Reads a TIFF array of signed 32-bit integer values and returns it as a long array.

Parameters:
type - TIFF type to read; must be a 32-bit type
count - Number of values to read
value - Offset from which to read
Throws:
java.io.IOException

readUnsigned

public long readUnsigned(int type)
                  throws java.io.IOException
Reads an unsigned number of any type.

Parameters:
type - TIFF type to read
Throws:
java.io.IOException

readRational

protected Rational readRational(long count,
                                long value)
                         throws java.io.IOException
Reads a RATIONAL value and returns it as a Rational.

Throws:
java.io.IOException

readRationalArray

protected Rational[] readRationalArray(long count,
                                       long value)
                                throws java.io.IOException
Reads an array of RATIONAL values and returns it as an array of Rational.

Throws:
java.io.IOException

readSignedRational

protected Rational readSignedRational(long count,
                                      long value)
                               throws java.io.IOException
Reads an SRATIONAL value and returns it as a Rational.

Throws:
java.io.IOException

readSignedRationalArray

protected Rational[] readSignedRationalArray(long count,
                                             long value)
                                      throws java.io.IOException
Reads an array of SRATIONAL values and returns it as an array of Rational.

Throws:
java.io.IOException

readShort

protected int readShort(int type,
                        long count,
                        long value)
                 throws java.io.IOException
Reads and returns a single unsigned 16-bit value.

Throws:
java.io.IOException

readShortArray

protected int[] readShortArray(int type,
                               long count,
                               long value)
                        throws java.io.IOException
Reads a TIFF array of unsigned 16-bit values and returns it as an int array.

Throws:
java.io.IOException

readSShortArray

protected int[] readSShortArray(int type,
                                long count,
                                long value)
                         throws java.io.IOException
Reads a TIFF array of signed 16-bit values and returns it as an int array.

Throws:
java.io.IOException

calcValueSize

public static long calcValueSize(int type,
                                 long count)
Calculate how many bytes a given number of fields of a given type will require.

Parameters:
type - Field type
count - Field count

isBigEndian

public boolean isBigEndian()
Returns true if file is big-endian, false if little-endian.


checkCount

protected static void checkCount(int tag,
                                 long count,
                                 int minCount)
                          throws TiffException
Check the tag entry count.

Parameters:
tag - Tag entry value
count - Tag entry count
minCount - Tag count
Throws:
TiffException

checkType

protected static void checkType(int tag,
                                int type,
                                int expected)
                         throws TiffException
Check the tag entry type.

Parameters:
tag - Tag entry value
type - Tag entry type
expected - Tag type
Throws:
TiffException

checkType

protected static void checkType(int tag,
                                int type,
                                int type1,
                                int type2)
                         throws TiffException
Check the tag entry type.

Parameters:
tag - Tag entry value
type - Tag entry type
type1 - Tag type
type2 - Alternate tag type
Throws:
TiffException

average

protected static Rational average(Rational r1,
                                  Rational r2)