Spec-Zone.ru › OpenJDK 27

Class JPEGImageWriteParam

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 the getDefaultImageWriteParam methods of the built-in JPEG ImageWriter.

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 a JPEGImageWriteParam, 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 JPEGQTable and JPEGHuffmanTable for more information on the default tables.

The default JPEGImageWriteParam returned by the getDefaultWriteParam method of the writer contains no tables. Default tables are included in the default IIOMetadata 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 reset method of the writer must be called.

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 declared in class 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
Modifier and Type Field Description
protected boolean canOffsetTiles
A boolean that is true if this ImageWriteParam allows tiling grid offset parameters to be set.
protected boolean canWriteCompressed
A boolean that is true if this writer can write images using compression.
protected boolean canWriteProgressive
A boolean that is true if this ImageWriteParam allows images to be written as a progressive sequence of increasing quality passes.
protected boolean canWriteTiles
A boolean that is true if this ImageWriteParam allows tile width and tile height parameters to be set.
protected int compressionMode
The mode controlling compression settings, which must be set to one of the four MODE_* values.
protected float compressionQuality
A float containing the current compression quality setting.
protected String compressionType
A String containing the name of the current compression type, or null if none is set.
protected String[] compressionTypes
An array of Strings containing the names of the available compression types.
protected Locale locale
A Locale to be used to localize compression type names and quality descriptions, or null to use a default Locale.
static final int MODE_COPY_FROM_METADATA
A constant value that may be passed into methods such as setTilingMode, setProgressiveMode, or setCompressionMode to enable that feature for future writes.
static final int MODE_DEFAULT
A constant value that may be passed into methods such as setTilingMode, setProgressiveMode, and setCompressionMode to enable that feature for future writes.
static final int MODE_DISABLED
A constant value that may be passed into methods such as setTilingMode, setProgressiveMode, and setCompressionMode to disable a feature for future writes.
static final int MODE_EXPLICIT
A constant value that may be passed into methods such as setTilingMode or setCompressionMode to enable a feature for future writes.
protected Dimension[] preferredTileSizes
An array of preferred tile size range pairs.
protected int progressiveMode
The mode controlling progressive encoding, which must be set to one of the four MODE_* values, except MODE_EXPLICIT.
protected int tileGridXOffset
The amount by which the tile grid origin should be offset horizontally from the image origin if tiling has been set, or 0 otherwise.
protected int tileGridYOffset
The amount by which the tile grid origin should be offset vertically from the image origin if tiling has been set, or 0 otherwise.
protected int tileHeight
The height of each tile if tiling has been set, or 0 otherwise.
protected int tileWidth
The width of each tile if tiling has been set, or 0 otherwise.
protected int tilingMode
The mode controlling tiling settings, which Must be set to one of the four MODE_* values.
protected boolean tilingSet
A boolean that is true if tiling parameters have been specified.

Fields declared in class IIOParam

controller, defaultController, destinationOffset, destinationType, sourceBands, sourceRegion, sourceXSubsampling, sourceYSubsampling, subsamplingXOffset, subsamplingYOffset
Modifier and Type Field Description
protected IIOParamController controller
The IIOParamController that will be used to provide settings for this IIOParam object when the activateController method is called.
protected IIOParamController defaultController
The default IIOParamController that will be used to provide settings for this IIOParam object when the activateController method is called.
protected Point destinationOffset
The offset in the destination where the upper-left decoded pixel should be placed.
protected ImageTypeSpecifier destinationType
An ImageTypeSpecifier to be used to generate a destination image when reading, or to set the output color type when writing.
protected int[] sourceBands
An array of ints indicating which source bands will be used, or null.
protected Rectangle sourceRegion
The source region, on null if none is set.
protected int sourceXSubsampling
The decimation subsampling to be applied in the horizontal direction.
protected int sourceYSubsampling
The decimation subsampling to be applied in the vertical direction.
protected int subsamplingXOffset
A horizontal offset to be applied to the subsampling grid before subsampling.
protected int subsamplingYOffset
A vertical offset to be applied to the subsampling grid before subsampling.

Constructor Summary

Constructor Description
JPEGImageWriteParam(Locale locale)
Constructs a JPEGImageWriteParam.

Method Summary

Modifier and Type Method Description
boolean areTablesSet()
Returns true if tables are currently set.
JPEGHuffmanTable[] getACHuffmanTables()
Returns a copy of the array of AC Huffman tables set on the most recent call to setEncodeTables, or null if tables are not currently set.
JPEGHuffmanTable[] getDCHuffmanTables()
Returns a copy of the array of DC Huffman tables set on the most recent call to setEncodeTables, or null if tables are not currently set.
boolean getOptimizeHuffmanTables()
Returns the value passed into the most recent call to setOptimizeHuffmanTables, or false if setOptimizeHuffmanTables has never been called.
JPEGQTable[] getQTables()
Returns a copy of the array of quantization tables set on the most recent call to setEncodeTables, or null if tables are not currently set.
boolean isCompressionLossless()
Returns false 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 declared in class ImageWriteParam

canOffsetTiles, canWriteCompressed, canWriteProgressive, canWriteTiles, getBitRate, getCompressionMode, getCompressionQuality, getCompressionQualityDescriptions, getCompressionQualityValues, getCompressionType, getCompressionTypes, getLocale, getLocalizedCompressionTypeName, getPreferredTileSizes, getProgressiveMode, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getTilingMode, setCompressionMode, setCompressionQuality, setCompressionType, setProgressiveMode, setTiling, setTilingMode, unsetTiling
Modifier and Type Method Description
boolean canOffsetTiles()
Returns true if the writer can perform tiling with non-zero grid offsets while writing.
boolean canWriteCompressed()
Returns true if this writer supports compression.
boolean canWriteProgressive()
Returns true if the writer can write out images as a series of passes of progressively increasing quality.
boolean canWriteTiles()
Returns true if the writer can perform tiling while writing.
float getBitRate(float quality)
Returns a float indicating an estimate of the number of bits of output data for each bit of input image data at the given quality level.
int getCompressionMode()
Returns the current compression mode, if compression is supported.
float getCompressionQuality()
Returns the current compression quality setting.
String[] getCompressionQualityDescriptions()
Returns an array of Strings that may be used along with getCompressionQualityValues as part of a user interface for setting or displaying the compression quality level.
float[] getCompressionQualityValues()
Returns an array of floats that may be used along with getCompressionQualityDescriptions as part of a user interface for setting or displaying the compression quality level.
String getCompressionType()
Returns the currently set compression type, or null if none has been set.
String[] getCompressionTypes()
Returns a list of available compression types, as an array or Strings, or null if a compression type may not be chosen using these interfaces.
Locale getLocale()
Returns the currently set Locale, or null if only a default Locale is supported.
String getLocalizedCompressionTypeName()
Returns a localized version of the name of the current compression type, using the Locale returned by getLocale.
Dimension[] getPreferredTileSizes()
Returns an array of Dimensions indicating the legal size ranges for tiles as they will be encoded in the output file or stream.
int getProgressiveMode()
Returns the current mode for writing the stream in a progressive manner.
int getTileGridXOffset()
Returns the horizontal tile grid offset of an image as it will be written to the output stream.
int getTileGridYOffset()
Returns the vertical tile grid offset of an image as it will be written to the output stream.
int getTileHeight()
Returns the height of each tile in an image as it will be written to the output stream.
int getTileWidth()
Returns the width of each tile in an image as it will be written to the output stream.
int getTilingMode()
Returns the current tiling mode, if tiling is supported.
void setCompressionMode(int mode)
Specifies whether compression is to be performed, and if so how compression parameters are to be determined.
void setCompressionQuality(float quality)
Sets the compression quality to a value between 0 and 1.
void setCompressionType(String compressionType)
Sets the compression type to one of the values indicated by getCompressionTypes.
void setProgressiveMode(int mode)
Specifies that the writer is to write the image out in a progressive mode such that the stream will contain a series of scans of increasing quality.
void setTiling(int tileWidth, int tileHeight, int tileGridXOffset, int tileGridYOffset)
Specifies that the image should be tiled in the output stream.
void setTilingMode(int mode)
Determines whether the image will be tiled in the output stream and, if it will, how the tiling parameters will be determined.
void unsetTiling()
Removes any previous tile grid parameters specified by calls to setTiling.

Methods declared in class IIOParam

activateController, getController, getDefaultController, getDestinationOffset, getDestinationType, getSourceBands, getSourceRegion, getSourceXSubsampling, getSourceYSubsampling, getSubsamplingXOffset, getSubsamplingYOffset, hasController, setController, setDestinationOffset, setDestinationType, setSourceBands, setSourceRegion, setSourceSubsampling
Modifier and Type Method Description
boolean activateController()
Activates the installed IIOParamController for this IIOParam object and returns the resulting value.
IIOParamController getController()
Returns whatever IIOParamController is currently installed.
IIOParamController getDefaultController()
Returns the default IIOParamController, if there is one, regardless of the currently installed controller.
Point getDestinationOffset()
Returns the offset in the destination image at which pixels are to be placed.
ImageTypeSpecifier getDestinationType()
Returns the type of image to be returned by the read, if one was set by a call to setDestination(ImageTypeSpecifier), as an ImageTypeSpecifier.
int[] getSourceBands()
Returns the set of source bands to be used.
Rectangle getSourceRegion()
Returns the source region to be used.
int getSourceXSubsampling()
Returns the number of source columns to advance for each pixel.
int getSourceYSubsampling()
Returns the number of rows to advance for each pixel.
int getSubsamplingXOffset()
Returns the horizontal offset of the subsampling grid.
int getSubsamplingYOffset()
Returns the vertical offset of the subsampling grid.
boolean hasController()
Returns true if there is a controller installed for this IIOParam object.
void setController(IIOParamController controller)
Sets the IIOParamController to be used to provide settings for this IIOParam object when the activateController method is called, overriding any default controller.
void setDestinationOffset(Point destinationOffset)
Specifies the offset in the destination image at which future decoded pixels are to be placed, when reading, or where a region will be written, when writing.
void setDestinationType(ImageTypeSpecifier destinationType)
Sets the desired image type for the destination image, using an ImageTypeSpecifier.
void setSourceBands(int[] sourceBands)
Sets the indices of the source bands to be used.
void setSourceRegion(Rectangle sourceRegion)
Sets the source region of interest.
void setSourceSubsampling(int sourceXSubsampling, int sourceYSubsampling, int subsamplingXOffset, int subsamplingYOffset)
Specifies a decimation subsampling to apply on I/O.

Methods declared in class Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Modifier and Type Method Description
protected Object clone()
Creates and returns a copy of this object.
boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.
protected void finalize()
Deprecated, for removal: This API element is subject to removal in a future version.
Finalization is deprecated and subject to removal in a future release.
final Class<?> getClass()
Returns the runtime class of this Object.
int hashCode()
Returns a hash code value for this object.
final void notify()
Wakes up a single thread that is waiting on this object's monitor.
final void notifyAll()
Wakes up all threads that are waiting on this object's monitor.
String toString()
Returns a string representation of the object.
final void wait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
final void wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
final void wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

Constructor Details

JPEGImageWriteParam

public JPEGImageWriteParam(Locale locale)
Constructs a JPEGImageWriteParam. 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 - a Locale to be used by the superclass to localize compression type names and quality descriptions, or null.

Method Details

unsetCompression

public void unsetCompression()
Removes any previous compression quality setting.

The default implementation resets the compression quality to 0.75F.

Overrides:
unsetCompression in class ImageWriteParam
Throws:
IllegalStateException - if the compression mode is not MODE_EXPLICIT.
See Also:
  • ImageWriteParam.setCompressionType(String)
  • ImageWriteParam.setCompressionQuality(float)

isCompressionLossless

public boolean isCompressionLossless()
Returns false since the JPEG plug-in only supports lossy compression.
Overrides:
isCompressionLossless in class ImageWriteParam
Returns:
false.
Throws:
IllegalStateException - if the compression mode is not MODE_EXPLICIT.

areTablesSet

public boolean areTablesSet()
Returns true 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 is null 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.
See Also:
  • setEncodeTables(JPEGQTable[], JPEGHuffmanTable[], JPEGHuffmanTable[])

getQTables

public JPEGQTable[] getQTables()
Returns a copy of the array of quantization tables set on the most recent call to setEncodeTables, or null if tables are not currently set.
Returns:
an array of JPEGQTable objects, or null.
See Also:
  • setEncodeTables(JPEGQTable[], JPEGHuffmanTable[], JPEGHuffmanTable[])

getDCHuffmanTables

public JPEGHuffmanTable[] getDCHuffmanTables()
Returns a copy of the array of DC Huffman tables set on the most recent call to setEncodeTables, or null if tables are not currently set.
Returns:
an array of JPEGHuffmanTable objects, or null.
See Also:
  • setEncodeTables(JPEGQTable[], JPEGHuffmanTable[], JPEGHuffmanTable[])

getACHuffmanTables

public JPEGHuffmanTable[] getACHuffmanTables()
Returns a copy of the array of AC Huffman tables set on the most recent call to setEncodeTables, or null if tables are not currently set.
Returns:
an array of JPEGHuffmanTable objects, or null.
See Also:
  • setEncodeTables(JPEGQTable[], JPEGHuffmanTable[], 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 is false. If this flag is set to true, it overrides any tables specified in the metadata. Note that this means that any image written with this flag set to true 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 to setOptimizeHuffmanTables, or false if setOptimizeHuffmanTables has never been called.
Returns:
true if the writer will generate optimized Huffman tables.
See Also:
  • setOptimizeHuffmanTables(boolean)

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2026, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API