Class TIFFImageEncoder
java.lang.Object
org.apache.xmlgraphics.image.codec.util.ImageEncoderImpl
org.apache.xmlgraphics.image.codec.tiff.TIFFImageEncoder
- All Implemented Interfaces:
ImageEncoder
A baseline TIFF writer. The writer outputs TIFF images in either Bilevel,
Greyscale, Palette color or Full Color modes.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]
private static final int
private static final int
private static final int
private static final int
Fields inherited from class org.apache.xmlgraphics.image.codec.util.ImageEncoderImpl
output, param
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
compressPackBits
(byte[] data, int numRows, long bytesPerRow, byte[] compData) Performs PackBits compression on a tile of data.private static int
void
encode
(RenderedImage im) Encodes a RenderedImage and writes the output to the OutputStream associated with this ImageEncoder.private int
encode
(RenderedImage im, TIFFEncodeParam encodeParam, int ifdOffset, boolean isLast) encodeMultiple
(Object context, RenderedImage img) Encodes a RenderedImage as part of a multi-page file and writes the output to the OutputStream associated with this ImageEncoder.void
finishMultiple
(Object context) Signals the encoder that you've finished sending pages for a multi-page image files.private int
getDirectorySize
(SortedSet fields) Calculates the size of the IFD.private static int
getValueSize
(TIFFField field) Determine the number of bytes in the value portion of the field.private static int
packBits
(byte[] input, int inOffset, int inCount, byte[] output, int outOffset) Performs PackBits compression for a single buffer of data.private void
validateImage
(int dataTypeSize, int[] sampleSize, int numBands, int dataType, ColorModel colorModel) private void
writeDirectory
(int thisIFDOffset, SortedSet fields, int nextIFDOffset) private void
private void
writeLong
(long l) despite its name, this method writes only 4 bytes to output.private void
writeUnsignedShort
(int s) private void
writeValues
(TIFFField field) private void
writeValuesAsFourBytes
(TIFFField field) Methods inherited from class org.apache.xmlgraphics.image.codec.util.ImageEncoderImpl
encode, getOutputStream, getParam, setParam
-
Field Details
-
TIFF_JPEG_TABLES
private static final int TIFF_JPEG_TABLES- See Also:
-
TIFF_YCBCR_SUBSAMPLING
private static final int TIFF_YCBCR_SUBSAMPLING- See Also:
-
TIFF_YCBCR_POSITIONING
private static final int TIFF_YCBCR_POSITIONING- See Also:
-
TIFF_REF_BLACK_WHITE
private static final int TIFF_REF_BLACK_WHITE- See Also:
-
SIZE_OF_TYPE
private static final int[] SIZE_OF_TYPE
-
-
Constructor Details
-
TIFFImageEncoder
-
-
Method Details
-
encode
Encodes a RenderedImage and writes the output to the OutputStream associated with this ImageEncoder.- Specified by:
encode
in interfaceImageEncoder
- Specified by:
encode
in classImageEncoderImpl
- Throws:
IOException
-
encodeMultiple
Encodes a RenderedImage as part of a multi-page file and writes the output to the OutputStream associated with this ImageEncoder.When you sent all pages, make sure you call finishMultiple() in the end. Otherwise, the generated file will be corrupted.
- Parameters:
context
- the context object you receive as return value to a previous call to encodeMultiple(). Set null for the first image.img
- the image- Returns:
- a context object needed for writing multiple pages for a single image file
- Throws:
IOException
- In case of an I/O error
-
finishMultiple
Signals the encoder that you've finished sending pages for a multi-page image files.- Parameters:
context
- the context object you receive as return value to a previous call to encodeMultiple()- Throws:
IOException
- In case of an I/O error
-
encode
private int encode(RenderedImage im, TIFFEncodeParam encodeParam, int ifdOffset, boolean isLast) throws IOException - Throws:
IOException
-
validateImage
private void validateImage(int dataTypeSize, int[] sampleSize, int numBands, int dataType, ColorModel colorModel) -
getDirectorySize
Calculates the size of the IFD. -
writeFileHeader
- Throws:
IOException
-
writeDirectory
private void writeDirectory(int thisIFDOffset, SortedSet fields, int nextIFDOffset) throws IOException - Throws:
IOException
-
getValueSize
Determine the number of bytes in the value portion of the field.- Throws:
UnsupportedEncodingException
-
writeValuesAsFourBytes
- Throws:
IOException
-
writeValues
- Throws:
IOException
-
writeUnsignedShort
- Throws:
IOException
-
writeLong
despite its name, this method writes only 4 bytes to output.- Parameters:
l
- 32bits of this are written as 4 bytes- Throws:
IOException
-
compressPackBits
private static int compressPackBits(byte[] data, int numRows, long bytesPerRow, byte[] compData) Performs PackBits compression on a tile of data. -
packBits
private static int packBits(byte[] input, int inOffset, int inCount, byte[] output, int outOffset) Performs PackBits compression for a single buffer of data. This should be called for each row of each tile. The returned value is the offset into the output buffer after compression. -
deflate
-