com.sun.media.jai.codec
Class JPEGEncodeParam

java.lang.Object
  |
  +--com.sun.media.jai.codec.JPEGEncodeParam
All Implemented Interfaces:
Cloneable, ImageDecodeParam, ImageEncodeParam, Serializable

public class JPEGEncodeParam
extends Object
implements ImageEncodeParam

A class which encapsulates the most common functionality required for the parameters to a Jpeg encode operation. It does not include all of the parameters of the com.sun.image.codec.jpeg classes. Users needing that additional functionality should use those classes directly, bearing in mind that they are part of an uncommitted non-core interface that may be modified or removed in the future. This class makes very simple assumptions about the image colorspaces. Images with a single band are assumed to be grayscale. Images with three bands are assumed to be RGB and are encoded to YCbCr.

This class is not a committed part of the JAI API. It may be removed or changed in future releases of JAI.

See Also:
Serialized Form

Constructor Summary
JPEGEncodeParam()
          Constructs a JAI JPEGEncodeParam object with default settings.
 
Method Summary
 Object clone()
          Returns a copy of this JPEGEncodeParam object.
 int getHorizontalSubsampling(int component)
          Get the horizontal subsampling factor for a band.
 int[] getQTable(int component)
          Retrieve the contents of the quantization table used for a component.
 int getQTableSlot(int component)
          Retrieve the quantization table slot used for a component.
 float getQuality()
          Retrieve the quality setting for this encoding.
 int getRestartInterval()
          Gets the restart interval in Minimum Coded Units (MCUs).
 int getVerticalSubsampling(int component)
          Get the vertical subsampling factor for a band.
 boolean getWriteImageOnly()
          Retrieve the setting of the writeImageOnly flag.
 boolean getWriteJFIFHeader()
          Retrieve the setting of the writeJFIF flag.
 boolean getWriteTablesOnly()
          Retrieve the setting of the writeTablesOnly flag.
 boolean isQTableSet(int component)
          Tests if a Quantization table has been set.
 boolean isQualitySet()
          Tests if the quality parameter has been set in this JPEGEncodeParam.
 void setChromaQTable(int[] qTable)
          Sets the quantization table to be used for chrominance data.
 void setHorizontalSubsampling(int component, int subsample)
          Sets the horizontal subsampling to be applied to an image band.
 void setLumaQTable(int[] qTable)
          Sets the quantization table to be used for luminance data.
 void setQTable(int component, int tableSlot, int[] qTable)
          Sets a quantization table to be used for a component.
 void setQuality(float quality)
          This creates new quantization tables that replace the currently installed quantization tables.
 void setRestartInterval(int restartInterval)
          Sets the restart interval in Minimum Coded Units (MCUs).
 void setVerticalSubsampling(int component, int subsample)
          Sets the vertical subsampling to be applied to an image band.
 void setWriteImageOnly(boolean imageOnly)
          Controls whether the encoder writes only the compressed image data to the output stream.
 void setWriteJFIFHeader(boolean writeJFIF)
          Controls whether the encoder writes a JFIF header using the APP0 marker.
 void setWriteTablesOnly(boolean tablesOnly)
          Instructs the encoder to write only the table data to the output stream.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JPEGEncodeParam

public JPEGEncodeParam()
Constructs a JAI JPEGEncodeParam object with default settings.
Method Detail

setHorizontalSubsampling

public void setHorizontalSubsampling(int component,
                                     int subsample)
Sets the horizontal subsampling to be applied to an image band. Defaults to 1 for grayscale and (1,2,2) for RGB.
Parameters:
component - The band for which to set horizontal subsampling.
subsample - The horizontal subsampling factor.

getHorizontalSubsampling

public int getHorizontalSubsampling(int component)
Get the horizontal subsampling factor for a band.
Parameters:
component - The band of the image for which to retrieve subsampling.
Returns:
The horizontal subsampling factor to be applied to this band

setVerticalSubsampling

public void setVerticalSubsampling(int component,
                                   int subsample)
Sets the vertical subsampling to be applied to an image band. Defaults to 1 for grayscale and (1,2,2) for RGB.
Parameters:
component - The band for which to set vertical subsampling.
subsample - The vertical subsampling factor.

getVerticalSubsampling

public int getVerticalSubsampling(int component)
Get the vertical subsampling factor for a band.
Parameters:
component - The band of the image for which to retrieve subsampling.
Returns:
The vertical subsampling factor to be applied to this band

setLumaQTable

public void setLumaQTable(int[] qTable)
Sets the quantization table to be used for luminance data. This is a convenience method which explicitly sets the contents of quantization table 0. The length of the table must be 64. This disables any quality setting.
Parameters:
qTable - Quantization table values in "zig-zag" order.

setChromaQTable

public void setChromaQTable(int[] qTable)
Sets the quantization table to be used for chrominance data. This is a convenience method which explicitly sets the contents of quantization table 1. The length of the table must be 64. This method assumes that all chroma components will use the same table. This disables any quality setting.
Parameters:
qTable - Quantization table values in "zig-zag" order.

setQTable

public void setQTable(int component,
                      int tableSlot,
                      int[] qTable)
Sets a quantization table to be used for a component. This method allows up to four independent tables to be specified. This disables any quality setting.
Parameters:
component - The band to which this table applies.
tableSlot - The table number that this table is assigned to (0 to 3).
qTable - Quantization table values in "zig-zag" order.

isQTableSet

public boolean isQTableSet(int component)
Tests if a Quantization table has been set.
Returns:
Returns true is the specified quantization table has been set.

getQTable

public int[] getQTable(int component)
Retrieve the contents of the quantization table used for a component.
Parameters:
component - The band to which this table applies.
Returns:
The contents of the quantization table as a reference.
Throws:
IllegalStateException - if table has not been previously set for this component.

getQTableSlot

public int getQTableSlot(int component)
Retrieve the quantization table slot used for a component.
Parameters:
component - The band to which this table slot applies.
Returns:
The table slot used for this band.
Throws:
IllegalStateException - if table has not been previously set for this component.

setRestartInterval

public void setRestartInterval(int restartInterval)
Sets the restart interval in Minimum Coded Units (MCUs). This can be useful in some environments to limit the effect of bitstream errors to a single restart interval. The default is zero (no restart interval markers).
Parameters:
restartInterval - Number of MCUs between restart markers.

getRestartInterval

public int getRestartInterval()
Gets the restart interval in Minimum Coded Units (MCUs).
Returns:
The restart interval in MCUs (0 if not set).

setQuality

public void setQuality(float quality)
This creates new quantization tables that replace the currently installed quantization tables. The created quantization table varies from very high compression, very low quality, (0.0) to low compression, very high quality (1.0) based on the quality parameter.

At a quality level of 1.0 the table will be all 1's which will lead to no loss of data due to quantization (however chrominace subsampling, if used, and roundoff error in the DCT will still degrade the image some what).

The default setting is 0.75 which provides high quality while insuring a good compression ratio.

Some guidelines: 0.75 high quality
                 0.5  medium quality
                 0.25 low quality
 
Parameters:
quality - 0.0-1.0 setting of desired quality level.

isQualitySet

public boolean isQualitySet()
Tests if the quality parameter has been set in this JPEGEncodeParam.
Returns:
True/false flag indicating if quality has been set.

getQuality

public float getQuality()
Retrieve the quality setting for this encoding. This is a number between 0.0 and 1.0.
Returns:
The specified quality setting (0.75 if not set).

setWriteTablesOnly

public void setWriteTablesOnly(boolean tablesOnly)
Instructs the encoder to write only the table data to the output stream. This is considered an abbreviated JPEG stream. Defaults to false -- normally both tables and encoded image data are written.
Parameters:
tablesOnly - If true, only the tables will be written.

getWriteTablesOnly

public boolean getWriteTablesOnly()
Retrieve the setting of the writeTablesOnly flag.
Returns:
The setting of the writeTablesOnly flag (false if not set).

setWriteImageOnly

public void setWriteImageOnly(boolean imageOnly)
Controls whether the encoder writes only the compressed image data to the output stream. This is considered an abbreviated JPEG stream. Defaults to false -- normally both tables and compressed image data are written.
Parameters:
imageOnly - If true, only the compressed image will be written.

getWriteImageOnly

public boolean getWriteImageOnly()
Retrieve the setting of the writeImageOnly flag.
Returns:
The setting of the writeImageOnly flag (false if not set).

setWriteJFIFHeader

public void setWriteJFIFHeader(boolean writeJFIF)
Controls whether the encoder writes a JFIF header using the APP0 marker. By default an APP0 marker is written to create a JFIF file.
Parameters:
writeJFIF - If true, writes a JFIF header.

getWriteJFIFHeader

public boolean getWriteJFIFHeader()
Retrieve the setting of the writeJFIF flag.
Returns:
The setting of the writeJFIF flag (true if not set).

clone

public Object clone()
Returns a copy of this JPEGEncodeParam object.
Overrides:
clone in class Object