Class TiffDirectory
- java.lang.Object
-
- org.apache.commons.imaging.formats.tiff.AbstractTiffElement
-
- org.apache.commons.imaging.formats.tiff.TiffDirectory
-
- All Implemented Interfaces:
java.lang.Iterable<TiffField>
public class TiffDirectory extends AbstractTiffElement implements java.lang.Iterable<TiffField>
Provides methods and elements for accessing an Image File Directory (IFD) from a TIFF file. In the TIFF specification, the IFD is the main container for individual images or sets of metadata. While not all Directories contain images, images are always stored in a Directory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTiffDirectory.ImageDataElement-
Nested classes/interfaces inherited from class org.apache.commons.imaging.formats.tiff.AbstractTiffElement
AbstractTiffElement.DataElement, AbstractTiffElement.Stub
-
-
Field Summary
Fields Modifier and Type Field Description private AbstractTiffImageDataabstractTiffImageDataprivate java.util.List<TiffField>entriesprivate java.nio.ByteOrderheaderByteOrderPreserves the byte order derived from the TIFF file header.private JpegImageDatajpegImageDataprivate longnextDirectoryOffsetinttype-
Fields inherited from class org.apache.commons.imaging.formats.tiff.AbstractTiffElement
COMPARATOR, length, offset
-
-
Constructor Summary
Constructors Constructor Description TiffDirectory(int type, java.util.List<TiffField> entries, long offset, long nextDirectoryOffset, java.nio.ByteOrder byteOrder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringdescription()static java.lang.Stringdescription(int type)voiddump()TiffFieldfindField(TagInfo tag)TiffFieldfindField(TagInfo tag, boolean failIfMissing)java.nio.ByteOrdergetByteOrder()Gets the byte order used by the source file for storing this directory and its content.java.util.List<TiffField>getDirectoryEntries()java.lang.StringgetElementDescription()java.lang.ObjectgetFieldValue(TagInfo tag)java.lang.String[]getFieldValue(TagInfoAscii tag, boolean mustExist)bytegetFieldValue(TagInfoByte tag)byte[]getFieldValue(TagInfoBytes tag, boolean mustExist)doublegetFieldValue(TagInfoDouble tag)double[]getFieldValue(TagInfoDoubles tag, boolean mustExist)floatgetFieldValue(TagInfoFloat tag)float[]getFieldValue(TagInfoFloats tag, boolean mustExist)java.lang.StringgetFieldValue(TagInfoGpsText tag, boolean mustExist)intgetFieldValue(TagInfoLong tag)int[]getFieldValue(TagInfoLongs tag, boolean mustExist)RationalNumbergetFieldValue(TagInfoRational tag)RationalNumber[]getFieldValue(TagInfoRationals tag, boolean mustExist)bytegetFieldValue(TagInfoSByte tag)byte[]getFieldValue(TagInfoSBytes tag, boolean mustExist)shortgetFieldValue(TagInfoShort tag)int[]getFieldValue(TagInfoShortOrLong tag, boolean mustExist)short[]getFieldValue(TagInfoShorts tag, boolean mustExist)intgetFieldValue(TagInfoSLong tag)int[]getFieldValue(TagInfoSLongs tag, boolean mustExist)RationalNumbergetFieldValue(TagInfoSRational tag)RationalNumber[]getFieldValue(TagInfoSRationals tag, boolean mustExist)shortgetFieldValue(TagInfoSShort tag)short[]getFieldValue(TagInfoSShorts tag, boolean mustExist)java.lang.StringgetFieldValue(TagInfoXpString tag, boolean mustExist)JpegImageDatagetJpegImageData()TiffDirectory.ImageDataElementgetJpegRawImageDataElement()longgetNextDirectoryOffset()AbstractTiffRasterDatagetRasterData(TiffImagingParameters params)Reads the numerical data stored in this TIFF directory, if available.private java.util.List<TiffDirectory.ImageDataElement>getRawImageDataElements(TiffField offsetsField, TiffField byteCountsField)java.lang.StringgetSingleFieldValue(TagInfoAscii tag)intgetSingleFieldValue(TagInfoShortOrLong tag)java.awt.image.BufferedImagegetTiffImage()Gets the image associated with the directory, if any.java.awt.image.BufferedImagegetTiffImage(java.nio.ByteOrder byteOrder)Gets the image associated with the directory, if any.java.awt.image.BufferedImagegetTiffImage(java.nio.ByteOrder byteOrder, TiffImagingParameters params)Gets the image associated with the directory, if any.java.awt.image.BufferedImagegetTiffImage(TiffImagingParameters params)Gets the image associated with the directory, if any.AbstractTiffImageDatagetTiffImageData()java.util.List<TiffDirectory.ImageDataElement>getTiffRawImageDataElements()booleanhasJpegImageData()booleanhasTiffFloatingPointRasterData()Indicates whether the directory definition specifies a float-point data format.booleanhasTiffImageData()booleanhasTiffRasterData()Indicates whether the content associated with the directory is given in a supported numerical-data format.booleanimageDataInStrips()java.util.Iterator<TiffField>iterator()voidsetJpegImageData(JpegImageData value)voidsetTiffImageData(AbstractTiffImageData rawImageData)intsize()
-
-
-
Field Detail
-
entries
private final java.util.List<TiffField> entries
-
headerByteOrder
private final java.nio.ByteOrder headerByteOrder
Preserves the byte order derived from the TIFF file header. Some of the legacy methods in this class require byte order as an argument, though that use could be phased out eventually.
-
jpegImageData
private JpegImageData jpegImageData
-
nextDirectoryOffset
private final long nextDirectoryOffset
-
abstractTiffImageData
private AbstractTiffImageData abstractTiffImageData
-
type
public final int type
-
-
Constructor Detail
-
TiffDirectory
public TiffDirectory(int type, java.util.List<TiffField> entries, long offset, long nextDirectoryOffset, java.nio.ByteOrder byteOrder)
-
-
Method Detail
-
description
public static java.lang.String description(int type)
-
description
public java.lang.String description()
-
dump
public void dump()
-
findField
public TiffField findField(TagInfo tag) throws ImagingException
- Throws:
ImagingException
-
findField
public TiffField findField(TagInfo tag, boolean failIfMissing) throws ImagingException
- Throws:
ImagingException
-
getByteOrder
public java.nio.ByteOrder getByteOrder()
Gets the byte order used by the source file for storing this directory and its content.- Returns:
- A valid byte order instance.
-
getDirectoryEntries
public java.util.List<TiffField> getDirectoryEntries()
-
getElementDescription
public java.lang.String getElementDescription()
- Specified by:
getElementDescriptionin classAbstractTiffElement
-
getFieldValue
public java.lang.Object getFieldValue(TagInfo tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public java.lang.String[] getFieldValue(TagInfoAscii tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public byte getFieldValue(TagInfoByte tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public byte[] getFieldValue(TagInfoBytes tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public double getFieldValue(TagInfoDouble tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public double[] getFieldValue(TagInfoDoubles tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public float getFieldValue(TagInfoFloat tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public float[] getFieldValue(TagInfoFloats tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public java.lang.String getFieldValue(TagInfoGpsText tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public int getFieldValue(TagInfoLong tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public int[] getFieldValue(TagInfoLongs tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public RationalNumber getFieldValue(TagInfoRational tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public RationalNumber[] getFieldValue(TagInfoRationals tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public byte getFieldValue(TagInfoSByte tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public byte[] getFieldValue(TagInfoSBytes tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public short getFieldValue(TagInfoShort tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public int[] getFieldValue(TagInfoShortOrLong tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public short[] getFieldValue(TagInfoShorts tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public int getFieldValue(TagInfoSLong tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public int[] getFieldValue(TagInfoSLongs tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public RationalNumber getFieldValue(TagInfoSRational tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public RationalNumber[] getFieldValue(TagInfoSRationals tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public short getFieldValue(TagInfoSShort tag) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public short[] getFieldValue(TagInfoSShorts tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getFieldValue
public java.lang.String getFieldValue(TagInfoXpString tag, boolean mustExist) throws ImagingException
- Throws:
ImagingException
-
getJpegImageData
public JpegImageData getJpegImageData()
-
getJpegRawImageDataElement
public TiffDirectory.ImageDataElement getJpegRawImageDataElement() throws ImagingException
- Throws:
ImagingException
-
getNextDirectoryOffset
public long getNextDirectoryOffset()
-
getRasterData
public AbstractTiffRasterData getRasterData(TiffImagingParameters params) throws ImagingException, java.io.IOException
Reads the numerical data stored in this TIFF directory, if available. Note that this method is defined only for TIFF directories that contain floating-point data or two-byte signed integer data.TIFF directories that provide numerical data do not directly specify images, though it is possible to interpret the data as an image using this library. TIFF files may contain multiple directories which are allowed to have different formats. Thus it is possible for a TIFF file to contain a mix of image and floating-point raster data.
If desired, sub-image data can be read from the file by using a Java Map instance to specify the subsection of the image that is required. The following code illustrates the approach:
int x; // coordinate (column) of corner of sub-image int y; // coordinate (row) of corner of sub-image int width; // width of sub-image int height; // height of sub-image Map<String, Object> params = new HashMap<>(); params.put(TiffConstants.PARAM_KEY_SUBIMAGE_X, x); params.put(TiffConstants.PARAM_KEY_SUBIMAGE_Y, y); params.put(TiffConstants.PARAM_KEY_SUBIMAGE_WIDTH, width); params.put(TiffConstants.PARAM_KEY_SUBIMAGE_HEIGHT, height); TiffRasterData raster = directory.readFloatingPointRasterData(params);
- Parameters:
params- an optional parameter map instance- Returns:
- a valid instance
- Throws:
ImagingException- in the event of incompatible or malformed datajava.io.IOException- in the event of an I/O error
-
getRawImageDataElements
private java.util.List<TiffDirectory.ImageDataElement> getRawImageDataElements(TiffField offsetsField, TiffField byteCountsField) throws ImagingException
- Throws:
ImagingException
-
getSingleFieldValue
public java.lang.String getSingleFieldValue(TagInfoAscii tag) throws ImagingException
- Throws:
ImagingException
-
getSingleFieldValue
public int getSingleFieldValue(TagInfoShortOrLong tag) throws ImagingException
- Throws:
ImagingException
-
getTiffImage
public java.awt.image.BufferedImage getTiffImage() throws ImagingException, java.io.IOExceptionGets the image associated with the directory, if any. Note that not all directories contain images.- Returns:
- if successful, a valid BufferedImage instance.
- Throws:
ImagingException- in the event of an invalid or incompatible data format.java.io.IOException- in the event of an I/O error.
-
getTiffImage
public java.awt.image.BufferedImage getTiffImage(java.nio.ByteOrder byteOrder) throws ImagingException, java.io.IOExceptionGets the image associated with the directory, if any. Note that not all directories contain images.This method comes from an older version of this class in which byte order was required from an external source. Developers are encouraged to use the simpler version of getTiffImage that does not require the byte-order argument.
- Parameters:
byteOrder- byte-order obtained from the containing TIFF file- Returns:
- if successful, a valid BufferedImage instance.
- Throws:
ImagingException- in the event of an invalid or incompatible data format.java.io.IOException- in the event of an I/O error.
-
getTiffImage
public java.awt.image.BufferedImage getTiffImage(java.nio.ByteOrder byteOrder, TiffImagingParameters params) throws ImagingException, java.io.IOExceptionGets the image associated with the directory, if any. Note that not all directories contain images.This method comes from an older version of this class in which byte order was required from an external source. Developers are encouraged to use the simpler version of getTiffImage that does not require the byte-order argument.
- Parameters:
byteOrder- byte-order obtained from the containing TIFF fileparams- an object containing optional parameters to be applied to the read operation.- Returns:
- if successful, a valid BufferedImage instance.
- Throws:
ImagingException- in the event of an invalid or incompatible data format.java.io.IOException- in the event of an I/O error.
-
getTiffImage
public java.awt.image.BufferedImage getTiffImage(TiffImagingParameters params) throws ImagingException, java.io.IOException
Gets the image associated with the directory, if any. Note that not all directories contain images.The optional parameters object can be used to specify image access or rendering options such as reading only a part of the overall image (i.e. reading a sub-image) or applying a custom photometric interpreter.
- Parameters:
params- an object containing optional parameters to be applied to the read operation.- Returns:
- if successful, a valid BufferedImage instance.
- Throws:
ImagingException- in the event of an invalid or incompatible data format.java.io.IOException- in the event of an I/O error.
-
getTiffImageData
public AbstractTiffImageData getTiffImageData()
-
getTiffRawImageDataElements
public java.util.List<TiffDirectory.ImageDataElement> getTiffRawImageDataElements() throws ImagingException
- Throws:
ImagingException
-
hasJpegImageData
public boolean hasJpegImageData() throws ImagingException- Throws:
ImagingException
-
hasTiffFloatingPointRasterData
public boolean hasTiffFloatingPointRasterData() throws ImagingExceptionIndicates whether the directory definition specifies a float-point data format.- Returns:
trueif the directory contains floating point data; otherwise,false- Throws:
ImagingException- in the event of an invalid or malformed specification.
-
hasTiffImageData
public boolean hasTiffImageData() throws ImagingException- Throws:
ImagingException
-
hasTiffRasterData
public boolean hasTiffRasterData() throws ImagingExceptionIndicates whether the content associated with the directory is given in a supported numerical-data format. If this method returnstrue, the Imaging API will be able to extract a TiffRasterData instance from the associated TIFF file using this directory.- Returns:
trueif the directory contains a supported raster data format; otherwise,false.- Throws:
ImagingException- in the event of an invalid or malformed specification.
-
imageDataInStrips
public boolean imageDataInStrips() throws ImagingException- Throws:
ImagingException
-
iterator
public java.util.Iterator<TiffField> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<TiffField>
-
setJpegImageData
public void setJpegImageData(JpegImageData value)
-
setTiffImageData
public void setTiffImageData(AbstractTiffImageData rawImageData)
-
size
public int size()
-
-