Class TIFFDirectory
- java.lang.Object
-
- com.github.jaiimageio.plugins.tiff.TIFFDirectory
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
TIFFIFD
public class TIFFDirectory extends java.lang.Object implements java.lang.CloneableA convenience class for simplifying interaction with TIFF native image metadata. A TIFF image metadata tree represents an Image File Directory (IFD) from a TIFF 6.0 stream. An IFD consists of a number of IFD Entries each of which associates an identifying tag number with a compatible value. ATIFFDirectoryinstance corresponds to an IFD and contains a set ofTIFFFields each of which corresponds to an IFD Entry in the IFD.When reading, a
TIFFDirectorymay be created by passing the value returned byImageReader.getImageMetadata()tocreateFromMetadata(). TheTIFFFields in the directory may then be obtained using the accessor methods provided in this class.When writing, an
IIOMetadataobject for use by one of thewrite() methods of ImageWritermay be created from aTIFFDirectorybygetAsMetadata(). TheTIFFDirectoryitself may be created by construction or from theIIOMetadataobject returned byImageWriter.getDefaultImageMetadata(). TheTIFFFields in the directory may be set using the mutator methods provided in this class.A
TIFFDirectoryis aware of the tag numbers in the group ofTIFFTagSets associated with it. When aTIFFDirectoryis created from a native image metadata object, these tag sets are derived from the tagSets attribute of the TIFFIFD node.A
TIFFDirectorymight also have a parentTIFFTag. This will occur if the directory represents an IFD other than the root IFD of the image. The parent tag is the tag of the IFD Entry which is a pointer to the IFD represented by thisTIFFDirectory. TheTIFFTag.isIFDPointer()method of this parentTIFFTagmust returntrue. When aTIFFDirectoryis created from a native image metadata object, the parent tag set is set from the parentTagName attribute of the corresponding TIFFIFD node. Note that aTIFFDirectoryinstance which has a non-nullparent tag will be contained in the data field of aTIFFFieldinstance which has a tag field equal to the contained directory's parent tag.As an example consider an EXIF image. The
TIFFDirectoryinstance corresponding to the EXIF IFD in the EXIF stream would have parent tagTAG_EXIF_IFD_POINTERand would includeEXIFTIFFTagSetin its group of known tag sets. TheTIFFDirectorycorresponding to this EXIF IFD will be contained in the data field of aTIFFFieldwhich will in turn be contained in theTIFFDirectorycorresponding to the primary IFD of the EXIF image which will itself have anull-valued parent tag.Note that this implementation is not synchronized. If multiple threads use a
TIFFDirectoryinstance concurrently, and at least one of the threads modifies the directory, for example, by adding or removingTIFFFields orTIFFTagSets, it must be synchronized externally.- Since:
- 1.1-beta
- See Also:
IIOMetadata,TIFFField,TIFFTag,TIFFTagSet
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.MaphighFieldsA mapping ofIntegertag numbers toTIFFFields for fields which are not low tag numbered.private TIFFField[]lowFieldsThe fields in this directory which have a low tag number.private static intMAX_LOW_FIELD_TAG_NUMThe largest low-valued tag number in the TIFF 6.0 specification.private intnumLowFieldsThe number of low tag numbered fields in the directory.private TIFFTagparentTagThe parentTIFFTagof this directory.private java.util.ListtagSetsTheTIFFTagSetsassociated with this directory.
-
Constructor Summary
Constructors Constructor Description TIFFDirectory(TIFFTagSet[] tagSets, TIFFTag parentTag)Constructs aTIFFDirectorywhich is aware of a given group ofTIFFTagSets.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTagSet(TIFFTagSet tagSet)Adds an element to the group ofTIFFTagSets of which this directory is aware.voidaddTIFFField(TIFFField f)Adds a TIFF field to the directory.java.lang.Objectclone()Clones the directory and all the fields contained therein.booleancontainsTIFFField(int tagNumber)Determines whether a TIFF field with the given tag number is contained in this directory.static TIFFDirectorycreateFromMetadata(javax.imageio.metadata.IIOMetadata tiffImageMetadata)Creates aTIFFDirectoryinstance from the contents of an image metadata object.javax.imageio.metadata.IIOMetadatagetAsMetadata()Converts the directory to a metadata object.private static TIFFIFDgetDirectoryAsIFD(TIFFDirectory dir)Converts aTIFFDirectoryto aTIFFIFD.intgetNumTIFFFields()Returns the number ofTIFFFields in this directory.TIFFTaggetParentTag()Returns the parentTIFFTagof this directory if one has been defined ornullotherwise.TIFFTaggetTag(int tagNumber)Returns theTIFFTagwhich has tag number equal totagNumberornullif no such tag exists in theTIFFTagSets associated with this directory.TIFFTagSet[]getTagSets()Returns theTIFFTagSets of which this directory is aware.TIFFFieldgetTIFFField(int tagNumber)Retrieves a TIFF field from the directory.TIFFField[]getTIFFFields()Retrieves all TIFF fields from the directory.voidremoveTagSet(TIFFTagSet tagSet)Removes an element from the group ofTIFFTagSets of which this directory is aware.voidremoveTIFFField(int tagNumber)Removes a TIFF field from the directory.voidremoveTIFFFields()Removes all TIFF fields from the directory.
-
-
-
Field Detail
-
MAX_LOW_FIELD_TAG_NUM
private static final int MAX_LOW_FIELD_TAG_NUM
The largest low-valued tag number in the TIFF 6.0 specification.- See Also:
- Constant Field Values
-
tagSets
private java.util.List tagSets
TheTIFFTagSetsassociated with this directory.
-
parentTag
private TIFFTag parentTag
The parentTIFFTagof this directory.
-
lowFields
private TIFFField[] lowFields
The fields in this directory which have a low tag number. These are managed as an array for efficiency as they are the most common fields.
-
numLowFields
private int numLowFields
The number of low tag numbered fields in the directory.
-
highFields
private java.util.Map highFields
A mapping ofIntegertag numbers toTIFFFields for fields which are not low tag numbered.
-
-
Constructor Detail
-
TIFFDirectory
public TIFFDirectory(TIFFTagSet[] tagSets, TIFFTag parentTag)
Constructs aTIFFDirectorywhich is aware of a given group ofTIFFTagSets. An optional parentTIFFTagmay also be specified.- Parameters:
tagSets- TheTIFFTagSetsassociated with this directory.parentTag- The parentTIFFTagof this directory; may benull.- Throws:
java.lang.IllegalArgumentException- iftagSetsisnull.
-
-
Method Detail
-
createFromMetadata
public static TIFFDirectory createFromMetadata(javax.imageio.metadata.IIOMetadata tiffImageMetadata) throws javax.imageio.metadata.IIOInvalidTreeException
Creates aTIFFDirectoryinstance from the contents of an image metadata object. The supplied object must support an image metadata format supported by the TIFFImageWriterplug-in. This will usually be either the TIFF native image metadata format com_sun_media_imageio_plugins_tiff_1.0 or the Java Image I/O standard metadata format javax_imageio_1.0.- Parameters:
tiffImageMetadata- A metadata object which supports a compatible image metadata format.- Returns:
- A
TIFFDirectorypopulated from the contents of the supplied metadata object. - Throws:
java.lang.IllegalArgumentException- iftiffImageMetadataisnull.java.lang.IllegalArgumentException- iftiffImageMetadatadoes not support a compatible image metadata format.javax.imageio.metadata.IIOInvalidTreeException- if the supplied metadata object cannot be parsed.
-
getDirectoryAsIFD
private static TIFFIFD getDirectoryAsIFD(TIFFDirectory dir)
Converts aTIFFDirectoryto aTIFFIFD.
-
getTagSets
public TIFFTagSet[] getTagSets()
Returns theTIFFTagSets of which this directory is aware.- Returns:
- The
TIFFTagSets associated with thisTIFFDirectory.
-
addTagSet
public void addTagSet(TIFFTagSet tagSet)
Adds an element to the group ofTIFFTagSets of which this directory is aware.- Parameters:
tagSet- TheTIFFTagSetto add.- Throws:
java.lang.IllegalArgumentException- iftagSetisnull.
-
removeTagSet
public void removeTagSet(TIFFTagSet tagSet)
Removes an element from the group ofTIFFTagSets of which this directory is aware.- Parameters:
tagSet- TheTIFFTagSetto remove.- Throws:
java.lang.IllegalArgumentException- iftagSetisnull.
-
getParentTag
public TIFFTag getParentTag()
Returns the parentTIFFTagof this directory if one has been defined ornullotherwise.- Returns:
- The parent
TIFFTagof thisTIFFDiectoryornull.
-
getTag
public TIFFTag getTag(int tagNumber)
Returns theTIFFTagwhich has tag number equal totagNumberornullif no such tag exists in theTIFFTagSets associated with this directory.- Parameters:
tagNumber- The tag number of interest.- Returns:
- The corresponding
TIFFTagornull.
-
getNumTIFFFields
public int getNumTIFFFields()
Returns the number ofTIFFFields in this directory.- Returns:
- The number of
TIFFFields in thisTIFFDirectory.
-
containsTIFFField
public boolean containsTIFFField(int tagNumber)
Determines whether a TIFF field with the given tag number is contained in this directory.- Returns:
- Whether a
TIFFTagwith tag number equal totagNumberis present in thisTIFFDirectory.
-
addTIFFField
public void addTIFFField(TIFFField f)
Adds a TIFF field to the directory.- Parameters:
f- The field to add.- Throws:
java.lang.IllegalArgumentException- iffisnull.
-
getTIFFField
public TIFFField getTIFFField(int tagNumber)
Retrieves a TIFF field from the directory.- Parameters:
tagNumber- The tag number of the tag associated with the field.- Returns:
- A
TIFFFieldwith the requested tag number ofnullif no such field is present.
-
removeTIFFField
public void removeTIFFField(int tagNumber)
Removes a TIFF field from the directory.- Parameters:
tagNumber- The tag number of the tag associated with the field.
-
getTIFFFields
public TIFFField[] getTIFFFields()
Retrieves all TIFF fields from the directory.- Returns:
- An array of all TIFF fields in order of numerically increasing tag number.
-
removeTIFFFields
public void removeTIFFFields()
Removes all TIFF fields from the directory.
-
getAsMetadata
public javax.imageio.metadata.IIOMetadata getAsMetadata()
Converts the directory to a metadata object.- Returns:
- A metadata instance initialized from the contents of this
TIFFDirectory.
-
clone
public java.lang.Object clone()
Clones the directory and all the fields contained therein.- Overrides:
clonein classjava.lang.Object- Returns:
- A clone of this
TIFFDirectory.
-
-