Class TIFFField
- All Implemented Interfaces:
Comparable
A field in a TIFF Image File Directory (IFD) is defined as a
tag number accompanied by a sequence of values of identical data type.
TIFF 6.0 defines 12 data types; a 13th type IFD
is
defined in TIFF Tech Note 1 of TIFF Specification Supplement 1. These
TIFF data types are referred to by Java constants and mapped internally
onto Java language data types and type names as follows:
TIFF Data Type | Java Constant | Java Data Type | Java Type Name |
---|---|---|---|
BYTE |
TIFFTag.TIFF_BYTE
|
byte
|
"Byte"
|
ASCII |
TIFFTag.TIFF_ASCII
|
String
|
"Ascii"
|
SHORT |
TIFFTag.TIFF_SHORT
|
char
|
"Short"
|
LONG |
TIFFTag.TIFF_LONG
|
long
|
"Long"
|
RATIONAL |
TIFFTag.TIFF_RATIONAL
|
long[2] {numerator, denominator}
|
"Rational"
|
SBYTE |
TIFFTag.TIFF_SBYTE
|
byte
|
"SByte"
|
UNDEFINED |
TIFFTag.TIFF_UNDEFINED
|
byte
|
"Undefined"
|
SSHORT |
TIFFTag.TIFF_SSHORT
|
short
|
"SShort"
|
SLONG |
TIFFTag.TIFF_SLONG
|
int
|
"SLong"
|
SRATIONAL |
TIFFTag.TIFF_SRATIONAL
|
int[2] {numerator, denominator}
|
"SRational"
|
FLOAT |
TIFFTag.TIFF_FLOAT
|
float
|
"Float"
|
DOUBLE |
TIFFTag.TIFF_DOUBLE
|
double
|
"Double"
|
IFD |
TIFFTag.TIFF_IFD_POINTER
|
long
|
"IFDPointer"
|
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
The default constructor.Constructs aTIFFField
with a single integral value.Constructs a data array using
and invokescreateArrayForType()
TIFFField(TIFFTag,int,int,Object)
with the supplied parameters and the created array.Constructs aTIFFField
with arbitrary data. -
Method Summary
Modifier and TypeMethodDescriptionint
Compares thisTIFFField
with anotherTIFFField
by comparing the tags.static Object
createArrayForType
(int dataType, int count) Creates an array appropriate for the indicated data type.static TIFFField
createFromMetadataNode
(TIFFTagSet tagSet, Node node) Creates aTIFFField
from a TIFF native image metadata node.byte[]
Returns the data as an uninterpreted array ofbyte
s.char[]
ReturnsTIFFTag.TIFF_SHORT
data as an array ofchar
s (unsigned 16-bit integers).double
getAsDouble
(int index) Returns data in any format as adouble
.double[]
ReturnsTIFFTag.TIFF_DOUBLE
data as an array ofdouble
s (64-bit floating-point values).float
getAsFloat
(int index) Returns data in any format as afloat
.float[]
ReturnsTIFFTag.TIFF_FLOAT
data as an array offloat
s (32-bit floating-point values).int
getAsInt
(int index) Returns data in any format as anint
.int[]
ReturnsTIFFTag.TIFF_SLONG
data as an array ofint
s (signed 32-bit integers).long
getAsLong
(int index) Returns data in any format as along
.long[]
ReturnsTIFFTag.TIFF_LONG
orTIFF_IFD_POINTER
data as an array oflong
s (signed 64-bit integers).Returns theTIFFField
as a node named either "TIFFField" or "TIFFIFD" as described in the TIFF native image metadata specification.long[]
getAsRational
(int index) Returns a TIFFTag.TIFF_RATIONAL data item as a two-element array of ints.long[][]
ReturnsTIFFTag.TIFF_RATIONAL
data as an array of 2-element arrays oflong
s.short[]
ReturnsTIFFTag.TIFF_SSHORT
data as an array ofshort
s (signed 16-bit integers).int[]
getAsSRational
(int index) Returns aTIFFTag.TIFF_SRATIONAL
data item as a two-element array ofint
s.int[][]
ReturnsTIFFTag.TIFF_SRATIONAL
data as an array of 2-element arrays ofint
s.getAsString
(int index) Returns aTIFFTag.TIFF_ASCII
value as aString
.private static String
getAttribute
(Node node, String attrName) int
getCount()
Returns the number of data items present in the field.getData()
Returns a reference to the data object associated with the field.getTag()
Retrieves the tag associated with this field.int
Retrieves the tag number in the range[0, 65535]
.int
getType()
Returns the type of the data stored in the field.static int
getTypeByName
(String typeName) Returns the data type constant corresponding to the supplied data type name.static String
getTypeName
(int dataType) Returns the name of the supplied data type constant.getValueAsString
(int index) Returns aString
containing a human-readable version of the data item.private static void
boolean
Indicates whether the value associated with the field is of integral data type.
-
Field Details
-
typeNames
-
isIntegral
private static final boolean[] isIntegral -
tag
The tag. -
tagNumber
private int tagNumberThe tag number. -
type
private int typeThe tag type. -
count
private int countThe number of data items present in the field. -
data
The field data.
-
-
Constructor Details
-
TIFFField
private TIFFField()The default constructor. -
TIFFField
Constructs aTIFFField
with arbitrary data. Thetype
parameter must be a value for which
returnstag.isDataTypeOK()
true
. Thedata
parameter must be an array of a Java type appropriate for the type of the TIFF field unless
returnstag.isIFDPointer()
true
in which case it must be aTIFFDirectory
instance.Neither the legality of
type
with respect totag
nor that ordata
with respect totype
is verified by this constructor. The methods
andTIFFTag.isDataTypeOK()
should be used programmatically to ensure that subsequent errors such ascreateArrayForType()
ClassCastException
s do not occur as a result of providing inconsitent parameters to this constructor.Note that the value (data) of the
TIFFField
will always be the actual field value regardless of the number of bytes required for that value. This is the case despite the fact that the TIFF IFD Entry corresponding to the field may actually contain the offset to the field's value rather than the value itself (the latter occurring if and only if the value fits into 4 bytes). In other words, the value of the field will already have been read from the TIFF stream. This subsumes the case wheretag.isIFDPointer()
returnstrue
and the value will be aTIFFDirectory
rather than an array.- Parameters:
tag
- The tag to associated with this field.type
- One of theTIFFTag.TIFF_*
constants indicating the data type of the field as written to the TIFF stream.count
- The number of data values.data
- The actual data content of the field.- Throws:
IllegalArgumentException
- iftag == null
.IllegalArgumentException
- ifdataType
is not one of theTIFFTag.TIFF_*
data type constants.IllegalArgumentException
- ifcount < 0
.
-
TIFFField
Constructs a data array using
and invokescreateArrayForType()
TIFFField(TIFFTag,int,int,Object)
with the supplied parameters and the created array.- See Also:
-
TIFFField
Constructs aTIFFField
with a single integral value. The field will have type
ifTIFF_SHORT
val < 65536
and type
otherwise. It is not verified whether the resulting type is legal forTIFF_LONG
tag
.- Parameters:
tag
- The tag to associate with this field.value
- The value to associate with this field.- Throws:
IllegalArgumentException
- iftag == null
.IllegalArgumentException
- ifvalue < 0
.
-
-
Method Details
-
getAttribute
-
initData
-
createFromMetadataNode
Creates aTIFFField
from a TIFF native image metadata node. If the value of the "tagNumber" attribute of the node is not found intagSet
then a newTIFFTag
with name"unknown"
will be created and assigned to the field.- Parameters:
tagSet
- TheTIFFTagSet
to which theTIFFTag
of the field belongs.node
- A native TIFF image metadataTIFFField
node.- Throws:
IllegalArgumentException
- ifnode
isnull
.IllegalArgumentException
- if the name of the node is not"TIFFField"
.
-
getTag
Retrieves the tag associated with this field.- Returns:
- The associated
TIFFTag
.
-
getTagNumber
public int getTagNumber()Retrieves the tag number in the range[0, 65535]
.- Returns:
- The tag number.
-
getType
public int getType()Returns the type of the data stored in the field. For a TIFF 6.0 stream, the value will equal one of theTIFFTag.TIFF_*
constants. For future revisions of TIFF, higher values are possible.- Returns:
- The data type of the field value.
-
getTypeName
Returns the name of the supplied data type constant.- Parameters:
dataType
- One of theTIFFTag.TIFF_*
constants indicating the data type of the field as written to the TIFF stream.- Returns:
- The type name corresponding to the supplied type constant.
- Throws:
IllegalArgumentException
- ifdataType
is not one of theTIFFTag.TIFF_*
data type constants.
-
getTypeByName
Returns the data type constant corresponding to the supplied data type name. If the name is unknown-1
will be returned.- Returns:
- One of the
TIFFTag.TIFF_*
constants or-1
if the name is not recognized.
-
createArrayForType
Creates an array appropriate for the indicated data type.- Parameters:
dataType
- One of theTIFFTag.TIFF_*
data type constants.count
- The number of values in the array.- Throws:
IllegalArgumentException
- ifdataType
is not one of theTIFFTag.TIFF_*
data type constants.IllegalArgumentException
- ifcount < 0
.
-
getAsNativeNode
Returns theTIFFField
as a node named either "TIFFField" or "TIFFIFD" as described in the TIFF native image metadata specification. The node will be named "TIFFIFD" if and only if the field's data object is an instance ofTIFFDirectory
or equivalentlygetTag.isIFDPointer()
returnstrue
.- Returns:
- a
Node
named "TIFFField" or "TIFFIFD".
-
isIntegral
public boolean isIntegral()Indicates whether the value associated with the field is of integral data type.- Returns:
- Whether the field type is integral.
-
getCount
public int getCount()Returns the number of data items present in the field. ForTIFFTag.TIFF_ASCII
fields, the value returned is the number ofString
s, not the total length of the data as in the file representation. -
getData
Returns a reference to the data object associated with the field.- Returns:
- The data object of the field.
-
getAsBytes
public byte[] getAsBytes()Returns the data as an uninterpreted array ofbyte
s. The type of the field must be one ofTIFFTag.TIFF_BYTE
,TIFF_SBYTE
, orTIFF_UNDEFINED
.For data in
TIFFTag.TIFF_BYTE
format, the application must take care when promoting the data to longer integral types to avoid sign extension.- Throws:
ClassCastException
- if the field is not of typeTIFF_BYTE
,TIFF_SBYTE
, orTIFF_UNDEFINED
.
-
getAsChars
public char[] getAsChars()ReturnsTIFFTag.TIFF_SHORT
data as an array ofchar
s (unsigned 16-bit integers).- Throws:
ClassCastException
- if the field is not of typeTIFF_SHORT
.
-
getAsShorts
public short[] getAsShorts()ReturnsTIFFTag.TIFF_SSHORT
data as an array ofshort
s (signed 16-bit integers).- Throws:
ClassCastException
- if the field is not of typeTIFF_SSHORT
.
-
getAsInts
public int[] getAsInts()ReturnsTIFFTag.TIFF_SLONG
data as an array ofint
s (signed 32-bit integers).- Throws:
ClassCastException
- if the field is not of typeTIFF_SHORT
,TIFF_SSHORT
, orTIFF_SLONG
.
-
getAsLongs
public long[] getAsLongs()ReturnsTIFFTag.TIFF_LONG
orTIFF_IFD_POINTER
data as an array oflong
s (signed 64-bit integers).- Throws:
ClassCastException
- if the field is not of typeTIFF_LONG
orTIFF_IFD_POINTER
.
-
getAsFloats
public float[] getAsFloats()ReturnsTIFFTag.TIFF_FLOAT
data as an array offloat
s (32-bit floating-point values).- Throws:
ClassCastException
- if the field is not of typeTIFF_FLOAT
.
-
getAsDoubles
public double[] getAsDoubles()ReturnsTIFFTag.TIFF_DOUBLE
data as an array ofdouble
s (64-bit floating-point values).- Throws:
ClassCastException
- if the field is not of typeTIFF_DOUBLE
.
-
getAsSRationals
public int[][] getAsSRationals()ReturnsTIFFTag.TIFF_SRATIONAL
data as an array of 2-element arrays ofint
s.- Throws:
ClassCastException
- if the field is not of typeTIFF_SRATIONAL
.
-
getAsRationals
public long[][] getAsRationals()ReturnsTIFFTag.TIFF_RATIONAL
data as an array of 2-element arrays oflong
s.- Throws:
ClassCastException
- if the field is not of typeTIFF_RATIONAL
.
-
getAsInt
public int getAsInt(int index) Returns data in any format as anint
.TIFFTag.TIFF_BYTE
values are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255].TIFF_SBYTE
data will be returned in the range [-128, 127].A
TIFF_UNDEFINED
value is treated as though it were aTIFF_BYTE
.Data in
TIFF_SLONG
,TIFF_LONG
,TIFF_FLOAT
,TIFF_DOUBLE
orTIFF_IFD_POINTER
format are simply cast toint
and may suffer from truncation.Data in
TIFF_SRATIONAL
orTIFF_RATIONAL
format are evaluated by dividing the numerator into the denominator using double-precision arithmetic and then casting toint
. Loss of precision and truncation may occur.Data in
TIFF_ASCII
format will be parsed as by theDouble.parseDouble
method, with the result case toint
. -
getAsLong
public long getAsLong(int index) Returns data in any format as along
.TIFFTag.TIFF_BYTE
andTIFF_UNDEFINED
data are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255].TIFF_SBYTE
data will be returned in the range [-128, 127].Data in
TIFF_ASCII
format will be parsed as by theDouble.parseDouble
method, with the result cast tolong
. -
getAsFloat
public float getAsFloat(int index) Returns data in any format as afloat
.TIFFTag.TIFF_BYTE
andTIFF_UNDEFINED
data are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255].TIFF_SBYTE
data will be returned in the range [-128, 127].Data in
TIFF_SLONG
,TIFF_LONG
,TIFF_DOUBLE
, orTIFF_IFD_POINTER
format are simply cast tofloat
and may suffer from truncation.Data in
TIFF_SRATIONAL
orTIFF_RATIONAL
format are evaluated by dividing the numerator into the denominator using double-precision arithmetic and then casting tofloat
.Data in
TIFF_ASCII
format will be parsed as by theDouble.parseDouble
method, with the result cast tofloat
. -
getAsDouble
public double getAsDouble(int index) Returns data in any format as adouble
.TIFFTag.TIFF_BYTE
andTIFF_UNDEFINED
data are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255].TIFF_SBYTE
data will be returned in the range [-128, 127].Data in
TIFF_SRATIONAL
orTIFF_RATIONAL
format are evaluated by dividing the numerator into the denominator using double-precision arithmetic.Data in
TIFF_ASCII
format will be parsed as by theDouble.parseDouble
method. -
getAsString
Returns aTIFFTag.TIFF_ASCII
value as aString
.- Throws:
ClassCastException
- if the field is not of typeTIFF_ASCII
.
-
getAsSRational
public int[] getAsSRational(int index) Returns aTIFFTag.TIFF_SRATIONAL
data item as a two-element array ofint
s.- Throws:
ClassCastException
- if the field is not of typeTIFF_SRATIONAL
.
-
getAsRational
public long[] getAsRational(int index) Returns a TIFFTag.TIFF_RATIONAL data item as a two-element array of ints.- Throws:
ClassCastException
- if the field is not of typeTIFF_RATIONAL
.
-
getValueAsString
Returns aString
containing a human-readable version of the data item. Data of typeTIFFTag.TIFF_RATIONAL
orTIFF_SRATIONAL
are represented as a pair of integers separated by a'/'
character.- Throws:
ClassCastException
- if the field is not of one of the legal field types.
-
compareTo
Compares thisTIFFField
with anotherTIFFField
by comparing the tags.Note: this class has a natural ordering that is inconsistent with
equals()
.- Specified by:
compareTo
in interfaceComparable
- Throws:
IllegalArgumentException
- if the parameter isnull
.ClassCastException
- if the parameter is not aTIFFField
.
-