Class TIFFImageEncoder
- java.lang.Object
-
- org.apache.xmlgraphics.image.codec.util.ImageEncoderImpl
-
- org.apache.xmlgraphics.image.codec.tiff.TIFFImageEncoder
-
- All Implemented Interfaces:
ImageEncoder
public class TIFFImageEncoder extends ImageEncoderImpl
A baseline TIFF writer. The writer outputs TIFF images in either Bilevel, Greyscale, Palette color or Full Color modes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classTIFFImageEncoder.Context
-
Field Summary
Fields Modifier and Type Field Description private static int[]SIZE_OF_TYPEprivate static intTIFF_JPEG_TABLESprivate static intTIFF_REF_BLACK_WHITEprivate static intTIFF_YCBCR_POSITIONINGprivate static intTIFF_YCBCR_SUBSAMPLING-
Fields inherited from class org.apache.xmlgraphics.image.codec.util.ImageEncoderImpl
output, param
-
-
Constructor Summary
Constructors Constructor Description TIFFImageEncoder(java.io.OutputStream output, ImageEncodeParam param)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static intcompressPackBits(byte[] data, int numRows, long bytesPerRow, byte[] compData)Performs PackBits compression on a tile of data.private static intdeflate(java.util.zip.Deflater deflater, byte[] inflated, byte[] deflated)voidencode(java.awt.image.RenderedImage im)Encodes a RenderedImage and writes the output to the OutputStream associated with this ImageEncoder.private intencode(java.awt.image.RenderedImage im, TIFFEncodeParam encodeParam, int ifdOffset, boolean isLast)java.lang.ObjectencodeMultiple(java.lang.Object context, java.awt.image.RenderedImage img)Encodes a RenderedImage as part of a multi-page file and writes the output to the OutputStream associated with this ImageEncoder.voidfinishMultiple(java.lang.Object context)Signals the encoder that you've finished sending pages for a multi-page image files.private intgetDirectorySize(java.util.SortedSet fields)Calculates the size of the IFD.private static intgetValueSize(TIFFField field)Determine the number of bytes in the value portion of the field.private static intpackBits(byte[] input, int inOffset, int inCount, byte[] output, int outOffset)Performs PackBits compression for a single buffer of data.private voidvalidateImage(int dataTypeSize, int[] sampleSize, int numBands, int dataType, java.awt.image.ColorModel colorModel)private voidwriteDirectory(int thisIFDOffset, java.util.SortedSet fields, int nextIFDOffset)private voidwriteFileHeader()private voidwriteLong(long l)despite its name, this method writes only 4 bytes to output.private voidwriteUnsignedShort(int s)private voidwriteValues(TIFFField field)private voidwriteValuesAsFourBytes(TIFFField field)-
Methods inherited from class org.apache.xmlgraphics.image.codec.util.ImageEncoderImpl
encode, getOutputStream, getParam, setParam
-
-
-
-
Field Detail
-
TIFF_JPEG_TABLES
private static final int TIFF_JPEG_TABLES
- See Also:
- Constant Field Values
-
TIFF_YCBCR_SUBSAMPLING
private static final int TIFF_YCBCR_SUBSAMPLING
- See Also:
- Constant Field Values
-
TIFF_YCBCR_POSITIONING
private static final int TIFF_YCBCR_POSITIONING
- See Also:
- Constant Field Values
-
TIFF_REF_BLACK_WHITE
private static final int TIFF_REF_BLACK_WHITE
- See Also:
- Constant Field Values
-
SIZE_OF_TYPE
private static final int[] SIZE_OF_TYPE
-
-
Constructor Detail
-
TIFFImageEncoder
public TIFFImageEncoder(java.io.OutputStream output, ImageEncodeParam param)
-
-
Method Detail
-
encode
public void encode(java.awt.image.RenderedImage im) throws java.io.IOExceptionEncodes a RenderedImage and writes the output to the OutputStream associated with this ImageEncoder.- Specified by:
encodein interfaceImageEncoder- Specified by:
encodein classImageEncoderImpl- Throws:
java.io.IOException
-
encodeMultiple
public java.lang.Object encodeMultiple(java.lang.Object context, java.awt.image.RenderedImage img) throws java.io.IOExceptionEncodes 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:
java.io.IOException- In case of an I/O error
-
finishMultiple
public void finishMultiple(java.lang.Object context) throws java.io.IOExceptionSignals 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:
java.io.IOException- In case of an I/O error
-
encode
private int encode(java.awt.image.RenderedImage im, TIFFEncodeParam encodeParam, int ifdOffset, boolean isLast) throws java.io.IOException- Throws:
java.io.IOException
-
validateImage
private void validateImage(int dataTypeSize, int[] sampleSize, int numBands, int dataType, java.awt.image.ColorModel colorModel)
-
getDirectorySize
private int getDirectorySize(java.util.SortedSet fields)
Calculates the size of the IFD.
-
writeFileHeader
private void writeFileHeader() throws java.io.IOException- Throws:
java.io.IOException
-
writeDirectory
private void writeDirectory(int thisIFDOffset, java.util.SortedSet fields, int nextIFDOffset) throws java.io.IOException- Throws:
java.io.IOException
-
getValueSize
private static int getValueSize(TIFFField field) throws java.io.UnsupportedEncodingException
Determine the number of bytes in the value portion of the field.- Throws:
java.io.UnsupportedEncodingException
-
writeValuesAsFourBytes
private void writeValuesAsFourBytes(TIFFField field) throws java.io.IOException
- Throws:
java.io.IOException
-
writeValues
private void writeValues(TIFFField field) throws java.io.IOException
- Throws:
java.io.IOException
-
writeUnsignedShort
private void writeUnsignedShort(int s) throws java.io.IOException- Throws:
java.io.IOException
-
writeLong
private void writeLong(long l) throws java.io.IOExceptiondespite its name, this method writes only 4 bytes to output.- Parameters:
l- 32bits of this are written as 4 bytes- Throws:
java.io.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
private static int deflate(java.util.zip.Deflater deflater, byte[] inflated, byte[] deflated)
-
-