JPEGEncodeParam encapsulates tables and options necessary to
control encoding of JPEG data streams. Parameters are either set
explicitly by the application for encoding, or read from another
JPEG header.
When working with BufferedImages, the codec will attempt to match
the encoded JPEG COLOR_ID with the ColorModel in the BufferedImage.
This is not always possible (the default mappings are listed
below). In cases where unsupported conversions are required (or
odd image colorspaces are in use) the user must either convert the
image data to a known ColorSpace or encode the data from a raster.
When encoding rasters no colorspace adjustments are made, so the
user must do any conversions required to get to the encoded
COLOR_ID.
The COLOR_ID for the encoded images is used to control the JPEG
codec's inital values for Huffman and Quantization Tables as well
as subsampling factors. It is also used to determine what color
conversion should be performed to obtain the best encoding.
Note: The color ids described herein are simply enumerated values
that influence data processing by the JPEG codec. JPEG compression
is, by definition, color blind. These values are used as hints when
compressing JPEG data. Through these values the JPEG codec can
perform some default rotation of data into spaces that will aid in
getting better compression ratios.
Example behaviour is described below. Since these mappings are
likely to change in the future it is strongly recommended that you
make use of the @see JPEGImageEncoder.getDefaultParamBlock calls
and check the encodedColorID for your particular BufferedImage.
In extreme cases is may be necessary for the user to convert the
image to the desired colorspace, and encode it from a Raster. In
this case the API programmer must specify the colorID of the data
in the Raster and no color conversion will take place.
ENCODING:
BufferedImage Type/Instance JPEG (Encoded) Color ID
======================== =======================
TYPE_GRAY COLOR_ID_GRAYSCALE
TYPE_RGB COLOR_ID_YCbCr
TYPE_YCbCr COLOR_ID_YCbCr
TYPE_YCbCr/CS_PYCC COLOR_ID_PYCC
TYPE_CMYK COLOR_ID_CMYK
TYPE_RGB (w/ alpha) COLOR_ID_YCbCrA
TYPE_YCbCr (w/ alpha) COLOR_ID_YCbCrA
TYPE_YCbCr/CS_PYCC (w/ alpha) COLOR_ID_PYCCA
Any Other ** COLOR_ID_UNKNOWN
When the user wants more control than the BufferedImage conversions
provide, the user must encode the data from a Raster. In this case
the data undergoes no color conversion at all. It is the user's
responsiblity to perform the desired conversions.
If you intend to write a JFIF image (by including the APP0_MARKER)
the encoded COLOR_ID must be one of: COLOR_ID_UNKNOWN,
COLOR_ID_GRAYSCALE, COLOR_ID_YCbCr, or COLOR_ID_CMYK. In all other
instances an ImageformatException will be thrown.
IMPORTANT: an Alpha RGB BufferedImage will not map to a
valid JFIF stream, you must strip off the alpha prior to encoding
if you want a JFIF file. If the APP0 marker is set and you do not
strip off the Alpha, an ImageFormatException will be thrown.
Note that the classes in the com.sun.image.codec.jpeg package are not
part of the core Java APIs. They are a part of Sun's JDK and JRE
distributions. Although other licensees may choose to distribute these
classes, developers cannot depend on their availability in non-Sun
implementations. We expect that equivalent functionality will eventually
be available in a core API or standard extension.
|