- java.lang.Object
-
- javax.imageio.IIOParam
-
- javax.imageio.ImageWriteParam
-
- javax.imageio.plugins.jpeg.JPEGImageWriteParam
-
public class JPEGImageWriteParam extends ImageWriteParam
This class adds the ability to set JPEG quantization and Huffman tables when using the built-in JPEG writer plug-in, and to request that optimized Huffman tables be computed for an image. An instance of this class will be returned from thegetDefaultImageWriteParam
methods of the built-in JPEGImageWriter
.The principal purpose of these additions is to allow the specification of tables to use in encoding abbreviated streams. The built-in JPEG writer will also accept an ordinary
ImageWriteParam
, in which case the writer will construct the necessary tables internally.In either case, the quality setting in an
ImageWriteParam
has the same meaning as for the underlying library: 1.00 means a quantization table of all 1's, 0.75 means the "standard", visually lossless quantization table, and 0.00 means aquantization table of all 255's.While tables for abbreviated streams are often specified by first writing an abbreviated stream containing only the tables, in some applications the tables are fixed ahead of time. This class allows the tables to be specified directly from client code.
Normally, the tables are specified in the
IIOMetadata
objects passed in to the writer, and any tables included in these objects are written to the stream. If no tables are specified in the metadata, then an abbreviated stream is written. If no tables are included in the metadata and no tables are specified in aJPEGImageWriteParam
, then an abbreviated stream is encoded using the "standard" visually lossless tables. This class is necessary for specifying tables when an abbreviated stream must be written without writing any tables to a stream first. In order to use this class, the metadata object passed into the writer must contain no tables, and no stream metadata must be provided. See
andJPEGQTable
for more information on the default tables.JPEGHuffmanTable
The default
JPEGImageWriteParam
returned by thegetDefaultWriteParam
method of the writer contains no tables. Default tables are included in the defaultIIOMetadata
objects returned by the writer.If the metadata does contain tables, the tables given in a
JPEGImageWriteParam
are ignored. Furthermore, once a set of tables has been written, only tables in the metadata can override them for subsequent writes, whether to the same stream or a different one. In order to specify new tables using this class, the
method of the writer must be called.reset
For more information about the operation of the built-in JPEG plug-ins, see the JPEG metadata format specification and usage notes.
-
-
Field Summary
-
Fields inherited from class javax.imageio.ImageWriteParam
canOffsetTiles, canWriteCompressed, canWriteProgressive, canWriteTiles, compressionMode, compressionQuality, compressionType, compressionTypes, locale, MODE_COPY_FROM_METADATA, MODE_DEFAULT, MODE_DISABLED, MODE_EXPLICIT, preferredTileSizes, progressiveMode, tileGridXOffset, tileGridYOffset, tileHeight, tileWidth, tilingMode, tilingSet
-
Fields inherited from class javax.imageio.IIOParam
controller, defaultController, destinationOffset, destinationType, sourceBands, sourceRegion, sourceXSubsampling, sourceYSubsampling, subsamplingXOffset, subsamplingYOffset
-
-
Constructor Summary
Constructors Constructor and Description JPEGImageWriteParam(Locale locale)
Constructs aJPEGImageWriteParam
.
-
Method Summary
Methods Modifier and Type Method and Description boolean
areTablesSet()
Returnstrue
if tables are currently set.JPEGHuffmanTable[]
getACHuffmanTables()
Returns a copy of the array of AC Huffman tables set on the most recent call tosetEncodeTables
, ornull
if tables are not currently set.String[]
getCompressionQualityDescriptions()
Returns an array ofString
s that may be used along withgetCompressionQualityValues
as part of a user interface for setting or displaying the compression quality level.float[]
getCompressionQualityValues()
Returns an array offloat
s that may be used along withgetCompressionQualityDescriptions
as part of a user interface for setting or displaying the compression quality level.JPEGHuffmanTable[]
getDCHuffmanTables()
Returns a copy of the array of DC Huffman tables set on the most recent call tosetEncodeTables
, ornull
if tables are not currently set.boolean
getOptimizeHuffmanTables()
Returns the value passed into the most recent call tosetOptimizeHuffmanTables
, orfalse
ifsetOptimizeHuffmanTables
has never been called.JPEGQTable[]
getQTables()
Returns a copy of the array of quantization tables set on the most recent call tosetEncodeTables
, ornull
if tables are not currently set.boolean
isCompressionLossless()
Returnsfalse
since the JPEG plug-in only supports lossy compression.void
setEncodeTables(JPEGQTable[] qTables, JPEGHuffmanTable[] DCHuffmanTables, JPEGHuffmanTable[] ACHuffmanTables)
Sets the quantization and Huffman tables to use in encoding abbreviated streams.void
setOptimizeHuffmanTables(boolean optimize)
Tells the writer to generate optimized Huffman tables for the image as part of the writing process.void
unsetCompression()
Removes any previous compression quality setting.void
unsetEncodeTables()
Removes any quantization and Huffman tables that are currently set.-
Methods inherited from class javax.imageio.ImageWriteParam
canOffsetTiles, canWriteCompressed, canWriteProgressive, canWriteTiles, getBitRate, getCompressionMode, getCompressionQuality, getCompressionType, getCompressionTypes, getLocale, getLocalizedCompressionTypeName, getPreferredTileSizes, getProgressiveMode, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getTilingMode, setCompressionMode, setCompressionQuality, setCompressionType, setProgressiveMode, setTiling, setTilingMode, unsetTiling
-
Methods inherited from class javax.imageio.IIOParam
activateController, getController, getDefaultController, getDestinationOffset, getDestinationType, getSourceBands, getSourceRegion, getSourceXSubsampling, getSourceYSubsampling, getSubsamplingXOffset, getSubsamplingYOffset, hasController, setController, setDestinationOffset, setDestinationType, setSourceBands, setSourceRegion, setSourceSubsampling
-
-
-
-
Constructor Detail
-
JPEGImageWriteParam
public JPEGImageWriteParam(Locale locale)
Constructs aJPEGImageWriteParam
. Tiling is not supported. Progressive encoding is supported. The default progressive mode is MODE_DISABLED. A single form of compression, named "JPEG", is supported. The default compression quality is 0.75.- Parameters:
locale
- aLocale
to be used by the superclass to localize compression type names and quality descriptions, ornull
.
-
-
Method Detail
-
unsetCompression
public void unsetCompression()
Removes any previous compression quality setting.The default implementation resets the compression quality to
0.75F
.- Overrides:
unsetCompression
in classImageWriteParam
- Throws:
IllegalStateException
- if the compression mode is notMODE_EXPLICIT
.- See Also:
ImageWriteParam.setCompressionType(java.lang.String)
,ImageWriteParam.setCompressionQuality(float)
-
isCompressionLossless
public boolean isCompressionLossless()
Returnsfalse
since the JPEG plug-in only supports lossy compression.- Overrides:
isCompressionLossless
in classImageWriteParam
- Returns:
false
.- Throws:
IllegalStateException
- if the compression mode is notMODE_EXPLICIT
.
-
getCompressionQualityDescriptions
public String[] getCompressionQualityDescriptions()
Description copied from class:ImageWriteParam
Returns an array ofString
s that may be used along withgetCompressionQualityValues
as part of a user interface for setting or displaying the compression quality level. TheString
with indexi
provides a description of the range of quality levels betweengetCompressionQualityValues[i]
andgetCompressionQualityValues[i + 1]
. Note that the length of the array returned fromgetCompressionQualityValues
will always be one greater than that returned fromgetCompressionQualityDescriptions
.As an example, the strings "Good", "Better", and "Best" could be associated with the ranges
[0, .33)
,[.33, .66)
, and[.66, 1.0]
. In this case,getCompressionQualityDescriptions
would return{ "Good", "Better", "Best" }
andgetCompressionQualityValues
would return{ 0.0F, .33F, .66F, 1.0F }
.If no descriptions are available,
null
is returned. Ifnull
is returned fromgetCompressionQualityValues
, this method must also returnnull
.The descriptions should be localized for the
Locale
returned bygetLocale
, if it is non-null
.If there are multiple compression types but none has been set, an
IllegalStateException
is thrown.The default implementation checks that compression is supported and that the compression mode is
MODE_EXPLICIT
. If so, ifgetCompressionTypes()
isnull
orgetCompressionType()
is non-null
, it returnsnull
.- Overrides:
getCompressionQualityDescriptions
in classImageWriteParam
- Returns:
- an array of
String
s containing localized descriptions of the compression quality levels. - See Also:
ImageWriteParam.getCompressionQualityValues()
-
getCompressionQualityValues
public float[] getCompressionQualityValues()
Description copied from class:ImageWriteParam
Returns an array offloat
s that may be used along withgetCompressionQualityDescriptions
as part of a user interface for setting or displaying the compression quality level. See
for more information.getCompressionQualityDescriptions
If no descriptions are available,
null
is returned. Ifnull
is returned fromgetCompressionQualityDescriptions
, this method must also returnnull
.If there are multiple compression types but none has been set, an
IllegalStateException
is thrown.The default implementation checks that compression is supported and that the compression mode is
MODE_EXPLICIT
. If so, ifgetCompressionTypes()
isnull
orgetCompressionType()
is non-null
, it returnsnull
.- Overrides:
getCompressionQualityValues
in classImageWriteParam
- Returns:
- an array of
float
s indicating the boundaries between the compression quality levels as described by theString
s fromgetCompressionQualityDescriptions
. - See Also:
ImageWriteParam.getCompressionQualityDescriptions()
-
areTablesSet
public boolean areTablesSet()
Returnstrue
if tables are currently set.- Returns:
true
if tables are present.
-
setEncodeTables
public void setEncodeTables(JPEGQTable[] qTables, JPEGHuffmanTable[] DCHuffmanTables, JPEGHuffmanTable[] ACHuffmanTables)
Sets the quantization and Huffman tables to use in encoding abbreviated streams. There may be a maximum of 4 tables of each type. These tables are ignored if tables are specified in the metadata. All arguments must be non-null
. The two arrays of Huffman tables must have the same number of elements. The table specifiers in the frame and scan headers in the metadata are assumed to be equivalent to indices into these arrays. The argument arrays are copied by this method.- Parameters:
qTables
- An array of quantization table objects.DCHuffmanTables
- An array of Huffman table objects.ACHuffmanTables
- An array of Huffman table objects.- Throws:
IllegalArgumentException
- if any of the arguments isnull
or has more than 4 elements, or if the numbers of DC and AC tables differ.- See Also:
unsetEncodeTables()
-
unsetEncodeTables
public void unsetEncodeTables()
Removes any quantization and Huffman tables that are currently set.
-
getQTables
public JPEGQTable[] getQTables()
Returns a copy of the array of quantization tables set on the most recent call tosetEncodeTables
, ornull
if tables are not currently set.- Returns:
- an array of
JPEGQTable
objects, ornull
. - See Also:
setEncodeTables(javax.imageio.plugins.jpeg.JPEGQTable[], javax.imageio.plugins.jpeg.JPEGHuffmanTable[], javax.imageio.plugins.jpeg.JPEGHuffmanTable[])
-
getDCHuffmanTables
public JPEGHuffmanTable[] getDCHuffmanTables()
Returns a copy of the array of DC Huffman tables set on the most recent call tosetEncodeTables
, ornull
if tables are not currently set.- Returns:
- an array of
JPEGHuffmanTable
objects, ornull
. - See Also:
setEncodeTables(javax.imageio.plugins.jpeg.JPEGQTable[], javax.imageio.plugins.jpeg.JPEGHuffmanTable[], javax.imageio.plugins.jpeg.JPEGHuffmanTable[])
-
getACHuffmanTables
public JPEGHuffmanTable[] getACHuffmanTables()
Returns a copy of the array of AC Huffman tables set on the most recent call tosetEncodeTables
, ornull
if tables are not currently set.- Returns:
- an array of
JPEGHuffmanTable
objects, ornull
. - See Also:
setEncodeTables(javax.imageio.plugins.jpeg.JPEGQTable[], javax.imageio.plugins.jpeg.JPEGHuffmanTable[], javax.imageio.plugins.jpeg.JPEGHuffmanTable[])
-
setOptimizeHuffmanTables
public void setOptimizeHuffmanTables(boolean optimize)
Tells the writer to generate optimized Huffman tables for the image as part of the writing process. The default isfalse
. If this flag is set totrue
, it overrides any tables specified in the metadata. Note that this means that any image written with this flag set totrue
will always contain Huffman tables.- Parameters:
optimize
- A boolean indicating whether to generate optimized Huffman tables when writing.- See Also:
getOptimizeHuffmanTables()
-
getOptimizeHuffmanTables
public boolean getOptimizeHuffmanTables()
Returns the value passed into the most recent call tosetOptimizeHuffmanTables
, orfalse
ifsetOptimizeHuffmanTables
has never been called.- Returns:
true
if the writer will generate optimized Huffman tables.- See Also:
setOptimizeHuffmanTables(boolean)
-
-
Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-javax/imageio/plugins/jpeg/jpegimagewriteparam.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.