Class TIFFBaseJPEGCompressor
- java.lang.Object
-
- com.github.jaiimageio.plugins.tiff.TIFFCompressor
-
- com.github.jaiimageio.impl.plugins.tiff.TIFFBaseJPEGCompressor
-
- Direct Known Subclasses:
TIFFEXIFJPEGCompressor
,TIFFJPEGCompressor
public abstract class TIFFBaseJPEGCompressor extends TIFFCompressor
Base class for all possible forms of JPEG compression in TIFF.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TIFFBaseJPEGCompressor.IIOByteArrayOutputStream
AByteArrayOutputStream
which allows writing to anImageOutputStream
.
-
Field Summary
Fields Modifier and Type Field Description private TIFFBaseJPEGCompressor.IIOByteArrayOutputStream
baos
private static boolean
DEBUG
protected static java.lang.String
IMAGE_METADATA_NAME
private javax.imageio.metadata.IIOMetadata
JPEGImageMetadata
protected javax.imageio.plugins.jpeg.JPEGImageWriteParam
JPEGParam
ImageWriteParam for JPEG writer.protected javax.imageio.metadata.IIOMetadata
JPEGStreamMetadata
Stream metadata equivalent to a tables-only stream such as in theJPEGTables
.protected javax.imageio.ImageWriter
JPEGWriter
The JPEG writer.private javax.imageio.ImageWriteParam
param
protected static java.lang.String
STREAM_METADATA_NAME
private boolean
usingCodecLib
protected boolean
writeAbbreviatedStream
Whether to write abbreviated JPEG streams (default == false).-
Fields inherited from class com.github.jaiimageio.plugins.tiff.TIFFCompressor
compressionTagValue, compressionType, isCompressionLossless, metadata, stream, writer
-
-
Constructor Summary
Constructors Constructor Description TIFFBaseJPEGCompressor(java.lang.String compressionType, int compressionTagValue, boolean isCompressionLossless, javax.imageio.ImageWriteParam param)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
encode(byte[] b, int off, int width, int height, int[] bitsPerSample, int scanlineStride)
Encodes the supplied image data, writing to the currently setImageOutputStream
.protected void
finalize()
private static java.util.List
getAllNodes(javax.imageio.metadata.IIOMetadataNode root, java.util.List nodes)
private javax.imageio.metadata.IIOMetadata
getImageMetadata(boolean pruneTables)
Retrieves image metadata with non-core nodes removed.protected void
initJPEGWriter(boolean supportsStreamMetadata, boolean supportsImageMetadata)
Initializes the JPEGWriter and JPEGParam instance variables.private static void
pruneNodes(org.w3c.dom.Node tree, boolean pruneTables)
Removes nonessential nodes from a JPEG native image metadata tree.-
Methods inherited from class com.github.jaiimageio.plugins.tiff.TIFFCompressor
dispose, getCompressionTagValue, getCompressionType, getMetadata, getStream, getWriter, isCompressionLossless, setMetadata, setStream, setWriter
-
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
-
STREAM_METADATA_NAME
protected static final java.lang.String STREAM_METADATA_NAME
- See Also:
- Constant Field Values
-
IMAGE_METADATA_NAME
protected static final java.lang.String IMAGE_METADATA_NAME
- See Also:
- Constant Field Values
-
param
private javax.imageio.ImageWriteParam param
-
JPEGParam
protected javax.imageio.plugins.jpeg.JPEGImageWriteParam JPEGParam
ImageWriteParam for JPEG writer. May be initialized byinitJPEGWriter(boolean, boolean)
.
-
JPEGWriter
protected javax.imageio.ImageWriter JPEGWriter
The JPEG writer. May be initialized byinitJPEGWriter(boolean, boolean)
.
-
writeAbbreviatedStream
protected boolean writeAbbreviatedStream
Whether to write abbreviated JPEG streams (default == false). A subclass which sets this totrue
should also initializedJPEGStreamMetadata
.
-
JPEGStreamMetadata
protected javax.imageio.metadata.IIOMetadata JPEGStreamMetadata
Stream metadata equivalent to a tables-only stream such as in theJPEGTables
. Default value isnull
. This should be set by any subclass which setswriteAbbreviatedStream
totrue
.
-
JPEGImageMetadata
private javax.imageio.metadata.IIOMetadata JPEGImageMetadata
-
usingCodecLib
private boolean usingCodecLib
-
baos
private TIFFBaseJPEGCompressor.IIOByteArrayOutputStream baos
-
-
Method Detail
-
pruneNodes
private static void pruneNodes(org.w3c.dom.Node tree, boolean pruneTables)
Removes nonessential nodes from a JPEG native image metadata tree. All nodes derived from JPEG marker segments other than DHT, DQT, SOF, SOS segments are removed unlesspruneTables
istrue
in which case the nodes derived from the DHT and DQT marker segments are also removed.- Parameters:
tree
- A javax_imageio_jpeg_image_1.0 tree.pruneTables
- Whether to prune Huffman and quantization tables.- Throws:
java.lang.IllegalArgumentException
- iftree
isnull
or is not the root of a JPEG native image metadata tree.
-
getAllNodes
private static java.util.List getAllNodes(javax.imageio.metadata.IIOMetadataNode root, java.util.List nodes)
-
initJPEGWriter
protected void initJPEGWriter(boolean supportsStreamMetadata, boolean supportsImageMetadata)
Initializes the JPEGWriter and JPEGParam instance variables. This method must be called before encode() is invoked.- Parameters:
supportsStreamMetadata
- Whether the JPEG writer must support JPEG native stream metadata, i.e., be capable of writing abbreviated streams.supportsImageMetadata
- Whether the JPEG writer must support JPEG native image metadata.
-
getImageMetadata
private javax.imageio.metadata.IIOMetadata getImageMetadata(boolean pruneTables) throws javax.imageio.IIOException
Retrieves image metadata with non-core nodes removed.- Throws:
javax.imageio.IIOException
-
encode
public final int encode(byte[] b, int off, int width, int height, int[] bitsPerSample, int scanlineStride) throws java.io.IOException
Description copied from class:TIFFCompressor
Encodes the supplied image data, writing to the currently setImageOutputStream
.- Specified by:
encode
in classTIFFCompressor
- Parameters:
b
- an array ofbyte
s containing the packed but uncompressed image data.off
- the starting offset of the data to be written in the arrayb
.width
- the width of the rectangle of pixels to be written.height
- the height of the rectangle of pixels to be written.bitsPerSample
- an array ofint
s indicting the number of bits used to represent each image sample within a pixel.scanlineStride
- the number of bytes separating each row of the input data.- Returns:
- the number of bytes written.
- Throws:
java.io.IOException
- if the supplied data cannot be encoded by thisTIFFCompressor
, or if any I/O error occurs during writing.
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
-