Class TIFFCompressor
- java.lang.Object
-
- com.github.jaiimageio.plugins.tiff.TIFFCompressor
-
- Direct Known Subclasses:
TIFFBaseJPEGCompressor
,TIFFDeflater
,TIFFFaxCompressor
,TIFFLSBCompressor
,TIFFLZWCompressor
,TIFFNullCompressor
,TIFFPackBitsCompressor
public abstract class TIFFCompressor extends java.lang.Object
An abstract superclass for pluggable TIFF compressors.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
compressionTagValue
The value to be assigned to the TIFF Compression tag in the TIFF image metadata.protected java.lang.String
compressionType
The name of the compression type supported by this compressor.protected boolean
isCompressionLossless
Whether the compression is lossless.protected javax.imageio.metadata.IIOMetadata
metadata
TheIIOMetadata
object containing metadata for the current image.protected javax.imageio.stream.ImageOutputStream
stream
TheImageOutputStream
to be written.protected javax.imageio.ImageWriter
writer
TheImageWriter
calling thisTIFFCompressor
.
-
Constructor Summary
Constructors Constructor Description TIFFCompressor(java.lang.String compressionType, int compressionTagValue, boolean isCompressionLossless)
Creates a compressor object for use in compressing TIFF data.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
dispose()
Allows any resources held by this object to be released.abstract int
encode(byte[] b, int off, int width, int height, int[] bitsPerSample, int scanlineStride)
Encodes the supplied image data, writing to the currently setImageOutputStream
.int
getCompressionTagValue()
Retrieve the value to be assigned to the TIFF Compression tag in the TIFF image metadata.java.lang.String
getCompressionType()
Retrieve the name of the compression type supported by this compressor.javax.imageio.metadata.IIOMetadata
getMetadata()
Returns the currentIIOMetadata
object.javax.imageio.stream.ImageOutputStream
getStream()
Returns theImageOutputStream
that will be written.javax.imageio.ImageWriter
getWriter()
Returns the currentImageWriter
.boolean
isCompressionLossless()
Retrieves a value indicating whether the compression is lossless.void
setMetadata(javax.imageio.metadata.IIOMetadata metadata)
Sets the value of themetadata
field.void
setStream(javax.imageio.stream.ImageOutputStream stream)
Sets theImageOutputStream
to be written.void
setWriter(javax.imageio.ImageWriter writer)
Sets the value of thewriter
field.
-
-
-
Field Detail
-
writer
protected javax.imageio.ImageWriter writer
TheImageWriter
calling thisTIFFCompressor
.
-
metadata
protected javax.imageio.metadata.IIOMetadata metadata
TheIIOMetadata
object containing metadata for the current image.
-
compressionType
protected java.lang.String compressionType
The name of the compression type supported by this compressor.
-
compressionTagValue
protected int compressionTagValue
The value to be assigned to the TIFF Compression tag in the TIFF image metadata.
-
isCompressionLossless
protected boolean isCompressionLossless
Whether the compression is lossless.
-
stream
protected javax.imageio.stream.ImageOutputStream stream
TheImageOutputStream
to be written.
-
-
Constructor Detail
-
TIFFCompressor
public TIFFCompressor(java.lang.String compressionType, int compressionTagValue, boolean isCompressionLossless)
Creates a compressor object for use in compressing TIFF data. This object may be passed to theTIFFImageWriteParam.setTIFFCompressor(TIFFCompressor)
method to override the compressor of a supported compression type or to provide the implementation of the compression algorithm of an unsupported compression type.The parameters
compressionTagValue
andisCompressionLossless
are provided to accomodate compression types which are unknown. A compression type is "known" if it is either among those already supported by the TIFF writer (seeTIFFImageWriteParam
), or is listed in the TIFF 6.0 specification but not supported. If the compression type is unknown, thecompressionTagValue
andisCompressionLossless
parameters are ignored.- Parameters:
compressionType
- The name of the compression type.compressionTagValue
- The value to be assigned to the TIFF Compression tag in the TIFF image metadata; ignored ifcompressionType
is a known type.isCompressionLossless
- Whether the compression is lossless; ignored ifcompressionType
is a known type.- Throws:
java.lang.IllegalArgumentException
- ifcompressionType
isnull
orcompressionTagValue
is less than1
.
-
-
Method Detail
-
getCompressionType
public java.lang.String getCompressionType()
Retrieve the name of the compression type supported by this compressor.- Returns:
- The compression type name.
-
getCompressionTagValue
public int getCompressionTagValue()
Retrieve the value to be assigned to the TIFF Compression tag in the TIFF image metadata.- Returns:
- The Compression tag value.
-
isCompressionLossless
public boolean isCompressionLossless()
Retrieves a value indicating whether the compression is lossless.- Returns:
- Whether the compression is lossless.
-
setStream
public void setStream(javax.imageio.stream.ImageOutputStream stream)
Sets theImageOutputStream
to be written.- Parameters:
stream
- anImageOutputStream
to be written.- See Also:
getStream()
-
getStream
public javax.imageio.stream.ImageOutputStream getStream()
Returns theImageOutputStream
that will be written.- Returns:
- an
ImageOutputStream
. - See Also:
setStream(ImageOutputStream)
-
setWriter
public void setWriter(javax.imageio.ImageWriter writer)
Sets the value of thewriter
field.- Parameters:
writer
- the currentImageWriter
.- See Also:
getWriter()
-
getWriter
public javax.imageio.ImageWriter getWriter()
Returns the currentImageWriter
.- Returns:
- an
ImageWriter
. - See Also:
setWriter(ImageWriter)
-
setMetadata
public void setMetadata(javax.imageio.metadata.IIOMetadata metadata)
Sets the value of themetadata
field.- Parameters:
metadata
- theIIOMetadata
object for the image being written.- See Also:
getMetadata()
-
getMetadata
public javax.imageio.metadata.IIOMetadata getMetadata()
Returns the currentIIOMetadata
object.- Returns:
- the
IIOMetadata
object for the image being written. - See Also:
setMetadata(IIOMetadata)
-
encode
public abstract int encode(byte[] b, int off, int width, int height, int[] bitsPerSample, int scanlineStride) throws java.io.IOException
Encodes the supplied image data, writing to the currently setImageOutputStream
.- 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.
-
dispose
public void dispose()
Allows any resources held by this object to be released. The result of calling any other method (other thanfinalize
) subsequent to a call to this method is undefined.It is important for applications to call this method when they know they will no longer be using this
TIFFCompressor
. Otherwise, the writer may continue to hold on to resources indefinitely.The default implementation of this method in the superclass does nothing. Subclass implementations should ensure that all resources, especially native resources, are released.
-
-