The "Format" operation performs reformatting on an image. It
is capable of casting the pixel values of an image to a given data
type, replacing the SampleModel and ColorModel of an image, and
restructuring the image's tile grid layout. The pixel values of
the destination image are defined by the pseudocode:

dst[x][y][b] = cast(src[x][y][b], dataType)

where "dataType" is one of the constants TYPE_BYTE, TYPE_SHORT,
TYPE_USHORT, TYPE_INT, TYPE_FLOAT, or TYPE_DOUBLE from
java.awt.image.DataBuffer.

The output SampleModel, ColorModel and tile grid layout are
specified by passing an ImageLayout object as a RenderingHint named
"ImageLayout". The output image will have a SampleModel compatible
with the one specified in the layout hint wherever possible;
however, for output data types of float and
double a ComponentSampleModel will be used
regardless of the value of the hint parameter.

One of the common uses of the format operator is to cast the
pixel values of an image to a given data type. In such a case, if
the source image provided has an IndexColorModel, a
RenderingHints object for
JAI.KEY_REPLACE_INDEX_COLOR_MODEL with the value of
Boolean.TRUE will automatically be added to the
configuration Map for the operation. This addition
will only take place if a value for the
JAI.KEY_REPLACE_INDEX_COLOR_MODEL has not already been
provided by the user. Note that the configuration Map
is cloned before the new hint is added to it. Due to the addition
of this new RenderingHint, using the "format" operation
with source(s) that have an IndexColorModel will cause
the destination to have an expanded non-IndexColorModelColorModel. This expansion ensures that the conversion
to a different data type, ColorModel or
SampleModel happens correctly such that the indices
into the color map (for IndexColorModel images) are
not treated as pixel data. If the format operator is not being used
to cast the pixel values of an image to a given data type, the
expansion will not take place, the resultant image will still have
an IndexColorModel.

The ImageLayout may also specify a tile grid origin and size
which will be respected.

The typecasting performed by the Format function
is defined by the following set of expressions, dependent on the
data types of the source and destination. Casting an image to its
current data type is a no-op. See The
Java Language Specification for the definition of type
conversions between primitive types.

In most cases, it is not necessary to explictly perform widening
typecasts since they will be performed automatically by image
operators when handed source images having different datatypes.