| java.lang.Object javax.media.jai.PixelAccessor
PixelAccessor | final public class PixelAccessor (Code) | | This is a utility class that may be used to access the pixel data
stored in a RenderedImage 's Raster s, as
well as performing pixel-to-color data translation based on the
image's SampleModel and ColorModel . It
also provides several static methods to determine information about
the image data.
This class is intended to help classes that need to access the
pixel and/or color data of a RenderedImage , such as an
OpImage , in an optimized fashion. Most of the variables
defined in this class are public so that other classes may use them
directly. However, the variables are also declared final
so that other classes can not modify their values.
In general, the pixel data of a RenderedImage may
be obtained by calling the getPixels() method. By
definition, the pixel data of an image are the data described
by the image's SampleModel and stored in the image's
Raster s. No consideration of any kind is given to the
image's ColorModel . If no error is found, the pixel
data are returned in the primitive arrays of the type specified by
the caller in an unpacked format, along with access information.
Therefore, the specified data type must be one of the valid types
defined in DataBuffer and large enough (in bit depth)
to hold the pixel data of the image.
The pixel data of a binary image may be obtained in a packed
format by calling the getPackedPixels() method. It
returns the data in a packed byte array, with 8 pixels
packed into 1 byte. The format of the data in the array is
similar to the format described by the
MultiPixelPackedSampleModel , where the end of each
scanline is padded to the end of the byte if necessary. Note that this
method returns a valid result only if and only if the image is a
single-band bit image, that is, each pixel has only 1 sample with a
sample size of 1 bit.
Two corresponding "set" methods are also provided for setting the
computed pixel data back into the Raster 's
DataBuffer : setPixels() for unpacked data,
and setPackedPixels() for packed data. It is very
important that the caller uses the correct "set" method that matches
the "get" method used to obtain the data, or errors will occur.
The color/alpha data of the RenderedImage may be
obtained by calling the getComponents() method which
returns the unnormalized data in the ColorSpace specified
in the ColorModel , or the getComponentsRGB()
method which returns the data scaled from 0 to 255 in the default sRGB
ColorSpace . These methods retrieve the pixel data from
the Raster , and perform the pixel-to-color translation.
Therefore, in order for these two methods to return a valid result, the
image must have a valid ColorModel .
Similarly, two "set" methods may be used to perform the
color-to-pixel translation, and set the pixel data back to the
Raster 's DataBuffer . Again, it is important
that the "get" and "set" methods are matched up correctly.
In addition, several static methods are included in this class
for the convenience of OpImage developers, who may use them to
help determine the appropriate destination SampleModel
type.
since: JAI 1.1 |
Field Summary | |
final public static int | TYPE_BIT Tag for single-bit data type. | final public int | bufferType The type of the DataBuffer 's data array used to store the
pixel data by the image's SampleModel . | final public ColorModel | colorModel The image's ColorModel . | final public int[] | componentSize The size, in number of bits, of all the color/alpha components. | final public int | componentType The type of the color/alpha components, determined based on the
component size. | final public boolean | hasCompatibleCM Set to true if the image has a non-null
ColorModel which is compatible with the image's
SampleModel ; false otherwise. | final public boolean | isComponentCM Set to true if the image has a
ComponentColorModel ;
false otherwise. | final public boolean | isComponentSM true if the image has a
ComponentSampleModel ;
false otherwise. | final public boolean | isIndexCM Set to true if the image has an
IndexColorModel ;
false otherwise. | final public boolean | isMultiPixelPackedSM true if the image has a
MultiPixelPackedSampleModel ;
false otherwise. | final public boolean | isPacked Set to true if the pixel data of this image may be
packed into a byte array. | final public boolean | isPackedCM Set to true if the image has a
PackedColorModel ;
false otherwise. | final public boolean | isSinglePixelPackedSM true if the image has a
SinglePixelPackedSampleModel ;
false otherwise. | final public int | numBands The number of bands (samples) per pixel. | final public int | numComponents The total number of color/alpha components in the image's
ColorModel . | final public SampleModel | sampleModel The image's SampleModel . | final public int[] | sampleSize The size, in number of bits, of all the pixel samples. | final public int | sampleType The data type of the pixel samples, determined based on the sample size. | final public int | transferType The type of the primitive array used to transfer the pixel data by
the image's SampleModel . |
Constructor Summary | |
public | PixelAccessor(RenderedImage image) Constructs a PixelAccessor from a
RenderedImage . | public | PixelAccessor(SampleModel sm, ColorModel cm) Constructs a PixelAccessor given a valid
SampleModel and a (possibly null )
ColorModel . |
Method Summary | |
public UnpackedImageData | getComponents(Raster raster, Rectangle rect, int type) Returns an array of unnormalized color/alpha components in the
ColorSpace defined in the image's
ColorModel . | public UnpackedImageData | getComponentsRGB(Raster raster, Rectangle rect) Returns an array of color/alpha components scaled from 0 to 255
in the default sRGB ColorSpace . | public static int | getDestNumBands(Vector sources) Returns the smallest number of bands of all the sources.
This method may be used to determine the number of bands a
destination should have in the default situation. | public static int | getDestPixelType(Vector sources) Returns the largest data type of all the sources. | public PackedImageData | getPackedPixels(Raster raster, Rectangle rect, boolean isDest, boolean coerceZeroOffset) Returns a region of the pixel data within a Raster
in a packed byte array. | public static int | getPixelType(SampleModel sm) Determines the pixel type based on the SampleModel .
The pixel type signifies the data type for a PixelAccessor .
For ComponentSampleModel , the pixel type is the same
as the type of the DataBuffer used to store the pixel
data. | public UnpackedImageData | getPixels(Raster raster, Rectangle rect, int type, boolean isDest) Returns a region of the pixel data within a Raster
in an unpacked primitive array. | public static boolean | isPackedOperation(PixelAccessor[] srcs, PixelAccessor dst) Returns true if the destination and/or all the
sources are single-bit, single-band images, and their pixel
data may be packed into a byte array.
If so, then the operations may be done in the packed format.
Parameters: srcs - The array of source PixelAccesor s. Parameters: dst - The destination PixelAccesor . | public static boolean | isPackedOperation(PixelAccessor src, PixelAccessor dst) Returns true if the destination and the source
are both single-bit, single-band images, and their pixel
data may be packed into a byte array.
If so, then the operations may be done in the packed format.
Parameters: srcs - The source PixelAccesor . Parameters: dst - The destination PixelAccesor . | public static boolean | isPackedOperation(PixelAccessor src1, PixelAccessor src2, PixelAccessor dst) Returns true if the destination and both sources
are all single-bit, single-band images, and their pixel
data may be packed into a byte array.
If so, then the operations may be done in the packed format.
Parameters: src1 - The first source PixelAccesor . Parameters: src2 - The second source PixelAccesor . Parameters: dst - The destination PixelAccesor . | public void | setComponents(UnpackedImageData uid) Given an array of unnormalized color/alpha components, this
method performs color-to-pixel translation, and sets the
translated pixel data back to the Raster within
a specific region. | public void | setComponentsRGB(UnpackedImageData uid) Given an array of normalized (between 0 and 255) alpha/RGB color
components, this method performs color-to-pixel translation, and
sets the translated pixel data back to the Raster
within a specific region. | public void | setPackedPixels(PackedImageData pid) Sets a region of the pixel data within a Raster
using a primitive array. | public void | setPixels(UnpackedImageData uid) Sets a region of the pixel data within a Raster
using a primitive array. | public void | setPixels(UnpackedImageData uid, boolean clamp) Sets a region of the pixel data within a Raster
using a primitive array. |
TYPE_BIT | final public static int TYPE_BIT(Code) | | Tag for single-bit data type.
|
bufferType | final public int bufferType(Code) | | The type of the DataBuffer 's data array used to store the
pixel data by the image's SampleModel . This is the same
value as that returned by SampleModel.getDataType() .
|
componentSize | final public int[] componentSize(Code) | | The size, in number of bits, of all the color/alpha components.
This is the same array as that returned by
ColorModel.getComponentSize() .
|
componentType | final public int componentType(Code) | | The type of the color/alpha components, determined based on the
component size.
|
hasCompatibleCM | final public boolean hasCompatibleCM(Code) | | Set to true if the image has a non-null
ColorModel which is compatible with the image's
SampleModel ; false otherwise.
|
isComponentCM | final public boolean isComponentCM(Code) | | Set to true if the image has a
ComponentColorModel ;
false otherwise.
|
isComponentSM | final public boolean isComponentSM(Code) | | true if the image has a
ComponentSampleModel ;
false otherwise.
|
isIndexCM | final public boolean isIndexCM(Code) | | Set to true if the image has an
IndexColorModel ;
false otherwise.
|
isMultiPixelPackedSM | final public boolean isMultiPixelPackedSM(Code) | | true if the image has a
MultiPixelPackedSampleModel ;
false otherwise.
|
isPacked | final public boolean isPacked(Code) | | Set to true if the pixel data of this image may be
packed into a byte array. That is, each pixel has
1 sample (1 band) with a sample size of 1 bit. If this variable
is true , getPackedPixels() should return
a valid result, with 8 pixels packed into 1 byte.
|
isPackedCM | final public boolean isPackedCM(Code) | | Set to true if the image has a
PackedColorModel ;
false otherwise.
|
isSinglePixelPackedSM | final public boolean isSinglePixelPackedSM(Code) | | true if the image has a
SinglePixelPackedSampleModel ;
false otherwise.
|
numBands | final public int numBands(Code) | | The number of bands (samples) per pixel. This is the same value
as that returned by SampleModel.getNumBands() .
|
numComponents | final public int numComponents(Code) | | The total number of color/alpha components in the image's
ColorModel . This is the same value as that
returned by ColorModel.getNumComponents() .
|
sampleModel | final public SampleModel sampleModel(Code) | | The image's SampleModel .
|
sampleSize | final public int[] sampleSize(Code) | | The size, in number of bits, of all the pixel samples. This is
the same array as that returned by
SampleModel.getSampleSize() .
|
sampleType | final public int sampleType(Code) | | The data type of the pixel samples, determined based on the sample size.
|
transferType | final public int transferType(Code) | | The type of the primitive array used to transfer the pixel data by
the image's SampleModel . This is the same value as
that returned by SampleModel.getTransferType() .
|
PixelAccessor | public PixelAccessor(RenderedImage image)(Code) | | Constructs a PixelAccessor from a
RenderedImage .
The RenderedImage must have a valid
SampleModel , but may or may not have a valid
ColorModel .
Parameters: image - The image whose data are to be accessed. throws: IllegalArgumentException - If image isnull , or if the image does not have a validSampleModel . |
PixelAccessor | public PixelAccessor(SampleModel sm, ColorModel cm)(Code) | | Constructs a PixelAccessor given a valid
SampleModel and a (possibly null )
ColorModel .
Parameters: sm - The SampleModel for the image to be accessed.Must be valid. Parameters: cm - The ColorModel for the image to be accessed.May be null. throws: IllegalArgumentException - If sm is null . |
getComponents | public UnpackedImageData getComponents(Raster raster, Rectangle rect, int type)(Code) | | Returns an array of unnormalized color/alpha components in the
ColorSpace defined in the image's
ColorModel . This method retrieves the pixel data
within the specified rectangular region from the
Raster , performs the pixel-to-color translation based
on the image's ColorModel , and returns the components
in the order specified by the ColorSpace .
In order for this method to return a valid result, the
image must have a valid ColorModel that is compatible
with the image's SampleModel . Further, the
SampleModel and ColorModel must have
the same transferType .
The component data are stored in a primitive array of the
type specified by the type argument. It must be one
of the valid data types defined in DataBuffer and
large (in bit depth) enough to hold the color/alpha components,
or an exception is thrown. This means type should
be greater than or equal to componentType . To avoid
extra array copy, it is best to use
DataBuffer.TYPE_INT for this argument.
The Rectangle specifies the region of interest
within which the pixel data are to be retrieved. It must be
completely inside the Raster 's boundary, or else
this method throws an exception.
Parameters: raster - The Raster that contains the pixel data. Parameters: rect - The region of interest within the Raster where the pixels are accessed. Parameters: type - The type of the primitive array used to return thecolor/alpha components with. The UnpackedImageData with its data filled in. throws: IllegalArgumentException - If the image does not have a validColorModel that is compatible with itsSampleModel . throws: IllegalArgumentException - If type is not avalid data type defined in DataBuffer , oris not large enough to hold the translated color/alphacomponents. throws: IllegalArgumentException - If rect is notcontained by the bounds of the specified Raster . |
getComponentsRGB | public UnpackedImageData getComponentsRGB(Raster raster, Rectangle rect)(Code) | | Returns an array of color/alpha components scaled from 0 to 255
in the default sRGB ColorSpace . This method
retrieves the pixel data within the specified rectangular region
from the Raster , performs the pixel-to-color translation
based on the image's ColorModel , and returns the
components in the order specified by the ColorSpace .
In order for this method to return a valid result, the
image must have a valid ColorModel that is compatible
with the image's SampleModel . Further, the
SampleModel and ColorModel must have
the same transferType .
The component data are stored in a two-dimensional,
band-interleaved, byte array, because the components
are always scaled from 0 to 255. Red is band 0, green is band 1,
blue is band 2, and alpha is band 3.
The Rectangle specifies the region of interest
within which the pixel data are to be retrieved. It must be
completely inside the Raster 's boundary, or
this method will throw an exception.
Parameters: raster - The Raster that contains the pixel data. Parameters: rect - The region of interest within the Raster where the pixels are accessed. The UnpackedImageData with its data filled in. throws: IllegalArgumentException - If the image does not have a validColorModel that is compatible with itsSampleModel . throws: IllegalArgumentException - If rect is notcontained by the bounds of the specified Raster . |
getDestNumBands | public static int getDestNumBands(Vector sources)(Code) | | Returns the smallest number of bands of all the sources.
This method may be used to determine the number of bands a
destination should have in the default situation. It guarantees
that every destination band has a corresponding source band.
In general, if an operation has multiple sources, and some
sources have 1 band and others have multiple bands, the single
band may be applied to the multiple bands one at a time. (An
example of this would be the MultiplyOpImage ). Therefore,
in such a case, this method returns the smallest band count among the
multi-band sources.
If there is no object in the source Vector , this
method returns 0. All the objects in the source Vector
must be RenderedImage s.
When determining the result, only information from each image's
SampleModel are used. No consideration is given to the
image's ColorModel .
Parameters: sources - A Vector of RenderedImage sources. The minimum number of destination bands. throws: IllegalArgumentException - If sources isnull . throws: ClassCastException - If any object in sources is not a RenderedImage . |
getDestPixelType | public static int getDestPixelType(Vector sources)(Code) | | Returns the largest data type of all the sources. This method
may be used to determine the pixel sample type of a destination
in the default situation. It guarantees that the destination can
store the resulting pixel values without losing any precision.
The pixel type signifies the data type for a PixelAccessor .
If all the sources are single-bit images, this method returns
TYPE_BIT (defined in this class) so that the
destination does not use unnecessary memory for some operations.
This includes all images whose SampleModel is
single-banded and whose sample size is 1, regardless of the type
of ColorModel the image may have.
If an operation does not wish to deal with packed data, it
should use TYPE_BYTE for pixel computation.
If there is no object in the source Vector , this
method returns TYPE_UNDEFINED . All the objects in
the source Vector must be RenderedImage s.
When determining the result, only information from each image's
SampleModel is used. No consideration is given to the
image's ColorModel .
Parameters: sources - A Vector of RenderedImage sources. The largest data type which can accomodate all sources. throws: IllegalArgumentException - If sources isnull . throws: ClassCastException - If any object in sources is not a RenderedImage . |
getPackedPixels | public PackedImageData getPackedPixels(Raster raster, Rectangle rect, boolean isDest, boolean coerceZeroOffset)(Code) | | Returns a region of the pixel data within a Raster
in a packed byte array. The returned data are
retrieved from the Raster 's DataBuffer ;
no pixel-to-color translation is performed.
This method only returns a valid result when the pixels are
single-band and single-bit. All other types of data result in
an exception. The data are packed in such a format that eight
pixels are packed into one byte, and the end of each scanline is
padded with zeros to the end of the byte.
In general, this method is called when operations are to be
performed on the bit data in a packed format directly, to save
memory usage. The static method isPackedOperation
should be used to determine whether the destination and/or its sources
are suitable for performing operations to a packed array.
The Rectangle specifies the region of interest
within which the pixel data are to be retrieved. It must be
completely inside the Raster 's boundary, or
this method will throw an exception.
Parameters: raster - The Raster that contains the pixel data. Parameters: rect - The region of interest within the Raster where the pixels are accessed. Parameters: isDest - Indicates whether this Raster is adestination Raster . That is, its pixels havenot been computed. Parameters: coerceZeroOffset - If true the returnedPackedImageData will be forced to have abitOffset and offset of zeroand a lineStride of (rect.width+7)/8 .The coercedZeroOffset field of the returnedPackedImageData will be set to true . The PackedImageData with its data filled in. throws: IllegalArgumentException - If data described by theRaster 's SampleModel are notsingle-band and single-bit. throws: IllegalArgumentException - If rect is notwithin the bounds of the specified Raster . |
getPixelType | public static int getPixelType(SampleModel sm)(Code) | | Determines the pixel type based on the SampleModel .
The pixel type signifies the data type for a PixelAccessor .
For ComponentSampleModel , the pixel type is the same
as the type of the DataBuffer used to store the pixel
data. For all other types of SampleModel , the pixel
type is determined based on the sample sizes.
Parameters: sm - The SampleModel of the image. The pixel type for this sample model. |
getPixels | public UnpackedImageData getPixels(Raster raster, Rectangle rect, int type, boolean isDest)(Code) | | Returns a region of the pixel data within a Raster
in an unpacked primitive array. The returned data are
retrieved from the Raster 's DataBuffer ;
no pixel-to-color translation is performed.
The primitive array is of the type specified by the
type argument. It must be one of the valid data
types defined in DataBuffer and large (in bit depth)
enough to hold the pixel samples, or an exception will be thrown.
This means type should be greater than or equal to
sampleType .
The Rectangle specifies the region of interest
within which the pixel data are to be retrieved. It must be
completely inside the Raster 's boundary, or else
this method throws an exception.
This method tries to avoid copying data as much as possible.
If it is unable to reformat the pixel data in the way requested,
or if the pixels do not have enough data to satisfy the request,
this method throws an exception.
Parameters: raster - The Raster that contains the pixel data. Parameters: rect - The region of interest within the Raster where the pixels are accessed. Parameters: type - The type of the primitive array used to return thepixel samples. Parameters: isDest - Indicates whether this Raster is adestination Raster . That is, its pixels havenot been computed. The pixel data in an UnpackedImageData object. throws: IllegalArgumentException - If type is not avalid data type defined in DataBuffer , oris not large enough to hold the pixel samples from thespecified Raster . throws: IllegalArgumentException - If rect is notcontained by the bounds of the specified Raster . |
isPackedOperation | public static boolean isPackedOperation(PixelAccessor[] srcs, PixelAccessor dst)(Code) | | Returns true if the destination and/or all the
sources are single-bit, single-band images, and their pixel
data may be packed into a byte array.
If so, then the operations may be done in the packed format.
Parameters: srcs - The array of source PixelAccesor s. Parameters: dst - The destination PixelAccesor . true if a packed operation is possible. |
isPackedOperation | public static boolean isPackedOperation(PixelAccessor src, PixelAccessor dst)(Code) | | Returns true if the destination and the source
are both single-bit, single-band images, and their pixel
data may be packed into a byte array.
If so, then the operations may be done in the packed format.
Parameters: srcs - The source PixelAccesor . Parameters: dst - The destination PixelAccesor . true if a packed operation is possible. |
isPackedOperation | public static boolean isPackedOperation(PixelAccessor src1, PixelAccessor src2, PixelAccessor dst)(Code) | | Returns true if the destination and both sources
are all single-bit, single-band images, and their pixel
data may be packed into a byte array.
If so, then the operations may be done in the packed format.
Parameters: src1 - The first source PixelAccesor . Parameters: src2 - The second source PixelAccesor . Parameters: dst - The destination PixelAccesor . true if a packed operation is possible. |
setComponents | public void setComponents(UnpackedImageData uid)(Code) | | Given an array of unnormalized color/alpha components, this
method performs color-to-pixel translation, and sets the
translated pixel data back to the Raster within
a specific region. It is very important that the components
array along with access information are obtained by calling
the getComponents() method, or errors
will occur.
In order for this method to return a valid result, the
image must have a valid ColorModel that is compatible
with the image's SampleModel . Further, the
SampleModel and ColorModel must have
the same transferType .
This method sets data only if the set flag in
UnpackedImageData is true .
Parameters: uid - The UnpackedImageData whose data is to be set. throws: IllegalArgumentException - If the uid isnull . |
setComponentsRGB | public void setComponentsRGB(UnpackedImageData uid)(Code) | | Given an array of normalized (between 0 and 255) alpha/RGB color
components, this method performs color-to-pixel translation, and
sets the translated pixel data back to the Raster
within a specific region. It is very important that the components
array along with access information are obtained by calling
the getComponentsRGB() method, or errors
will occur.
In order for this method to return a valid result, the
image must have a valid ColorModel that is compatible
with the image's SampleModel . Furthermore, the
SampleModel and ColorModel must have
the same transferType .
This method sets data only if the set flag in
UnpackedImageData is true .
Parameters: uid - The UnpackedImageData to set. throws: IllegalArgumentException - If the uid isnull . |
setPackedPixels | public void setPackedPixels(PackedImageData pid)(Code) | | Sets a region of the pixel data within a Raster
using a primitive array. This method copies data only if
the set flag in PackedImageData is
true .
The PackedImageData should be obtained by
calling the getPackedPixels() method.
Parameters: pid - The PackedImageData object whose pixelsare to be written. throws: IllegalArgumentException - If the pid isnull . |
setPixels | public void setPixels(UnpackedImageData uid)(Code) | | Sets a region of the pixel data within a Raster
using a primitive array. This method copies data only if
the set flag in UnpackedImageData is
true . Performs clamping by default.
The UnpackedImageData should be obtained by
calling the getPixels() method.
Parameters: uid - The UnpackedImageData object to set. throws: IllegalArgumentException - If the uid isnull . |
setPixels | public void setPixels(UnpackedImageData uid, boolean clamp)(Code) | | Sets a region of the pixel data within a Raster
using a primitive array. This method only copies data only if
the set flag in UnpackedImageData is
true .
The UnpackedImageData should be obtained by
calling the getPixels() method.
Parameters: uid - The UnpackedImageData object to set. Parameters: clamp - A boolean set to true if clampingis to be performed. throws: IllegalArgumentException - If the uid isnull . |
|
|