java.awt.image
Class ColorModel
java.lang.Object
|
+--java.awt.image.ColorModel
All Implemented Interfaces:
Transparency
A color model operates with colors in several formats:
- normalized: component samples are in range [0.0, 1.0].
- color model pixel value: all the color component samples for a
sigle pixel packed/encoded in a way natural for the color
model.
- color model pixel int value: only makes sense if the natural
encoding of a single pixel can fit in a single int value.
- array of transferType containing a single pixel: the pixel is
encoded in the natural way of the color model, taking up as many
array elements as needed.
- sRGB pixel int value: a pixel in sRGB color space, encoded in
default 0xAARRGGBB format, assumed not alpha premultiplied.
- single [0, 255] scaled int samples from default sRGB color
space. These are always assumed to be alpha non-premultiplied.
- arrays of unnormalized component samples of single pixel: these
samples are scaled and multiplied according to the color model, but
is otherwise not packed or encoded. Each element of the array is one
separate component sample. The color model only operate on the
components from one pixel at a time, but using offsets, allows
manipulation of arrays that contain the components of more than one
pixel.
Authors:- Rolf W. Rasmussen <rolfwr@ii.uib.no>
- C. Brian Jones (cbj@gnu.org)
java.awt.image.ColorModel | coerceData(java.awt.image.WritableRaster raster, boolean isAlphaPremultiplied)
|
java.awt.image.SampleModel | createCompatibleSampleModel(int w, int h)
|
java.awt.image.WritableRaster | createCompatibleWritableRaster(int w, int h)
|
boolean | equals(java.lang.Object obj)
|
void | finalize()
|
int | getAlpha(int pixel)
|
int | getAlpha(java.lang.Object inData)
|
java.awt.image.WritableRaster | getAlphaRaster(java.awt.image.WritableRaster raster)
|
int | getBlue(int pixel)
|
int | getBlue(java.lang.Object inData)
|
java.awt.color.ColorSpace | getColorSpace()
|
int | getComponentSize(int componentIdx)
|
int[] | getComponentSize()
|
int[] | getComponents(int pixel, int[] components, int offset)
|
int[] | getComponents(java.lang.Object pixel, int[] components, int offset)
|
int | getDataElement(int[] components, int offset)
|
java.lang.Object | getDataElements(int rgb, java.lang.Object pixel)
|
java.lang.Object | getDataElements(int[] components, int offset, java.lang.Object obj)
|
int | getGreen(int pixel)
|
int | getGreen(java.lang.Object inData)
|
float[] | getNormalizedComponents(int[] components, int offset, float[] normComponents, int normOffset)
|
int | getNumColorComponents()
|
int | getNumComponents()
|
int | getPixelSize()
|
int | getRGB(int pixel)
|
int | getRGB(java.lang.Object inData)
|
static java.awt.image.ColorModel | getRGBdefault()
|
int | getRed(int pixel)
|
int | getRed(java.lang.Object inData)
|
int | getTransparency()
|
int[] | getUnnormalizedComponents(float[] normComponents, int normOffset, int[] components, int offset)
|
boolean | hasAlpha()
|
boolean | isAlphaPremultiplied()
|
boolean | isCompatibleRaster(java.awt.image.Raster raster)
|
boolean | isCompatibleSampleModel(java.awt.image.SampleModel sm)
|
java.lang.String | toString()
|
pixel_bits
protected int pixel_bits
A color model operates with colors in several formats:
- normalized: component samples are in range [0.0, 1.0].
- color model pixel value: all the color component samples for a
sigle pixel packed/encoded in a way natural for the color
model.
- color model pixel int value: only makes sense if the natural
encoding of a single pixel can fit in a single int value.
- array of transferType containing a single pixel: the pixel is
encoded in the natural way of the color model, taking up as many
array elements as needed.
- sRGB pixel int value: a pixel in sRGB color space, encoded in
default 0xAARRGGBB format, assumed not alpha premultiplied.
- single [0, 255] scaled int samples from default sRGB color
space. These are always assumed to be alpha non-premultiplied.
- arrays of unnormalized component samples of single pixel: these
samples are scaled and multiplied according to the color model, but
is otherwise not packed or encoded. Each element of the array is one
separate component sample. The color model only operate on the
components from one pixel at a time, but using offsets, allows
manipulation of arrays that contain the components of more than one
pixel.
Authors:- Rolf W. Rasmussen <rolfwr@ii.uib.no>
- C. Brian Jones (cbj@gnu.org)
transferType
protected int transferType
ColorModel
public ColorModel(int bits)
Constructs the default color model. The default color model
can be obtained by calling getRGBdefault
of this
class.
Parameters:
ColorModel
protected ColorModel(int pixel_bits, int[] bits, java.awt.color.ColorSpace cspace, boolean hasAlpha, boolean isAlphaPremultiplied, int transparency, int transferType)
Constructs a ColorModel that translates pixel values to
color/alpha components.
Parameters:
Throws:
IllegalArgumentException
- If the length of the bit array is less
than the number of color or alpha components in this ColorModel, or if the
transparency is not a valid value, or if the sum of the number of bits in
bits is less than 1 or if any of the elements in bits is less than 0.
coerceData
public ColorModel coerceData(java.awt.image.WritableRaster raster, boolean isAlphaPremultiplied)
Parameters:
createCompatibleSampleModel
public SampleModel createCompatibleSampleModel(int w, int h)
Parameters:
createCompatibleWritableRaster
public WritableRaster createCompatibleWritableRaster(int w, int h)
Parameters:
equals
public boolean equals(java.lang.Object obj)
Parameters:
finalize
public void finalize()
getAlpha
public int getAlpha(int pixel)
Extract alpha int sample from pixel value, scaled to [0, 255].
Parameters:
Returns:
- alpha sample, scaled to range [0, 255].
getAlpha
public int getAlpha(java.lang.Object inData)
Parameters:
See Also:
getAlphaRaster
public WritableRaster getAlphaRaster(java.awt.image.WritableRaster raster)
Subclasses must override this method if it is possible for the
color model to have an alpha channel.
Parameters:
Returns:
- null, as per JDK 1.3 doc. Subclasses will only return
null if no alpha raster exists.
getBlue
public int getBlue(int pixel)
Converts pixel value to sRGB and extract blue int sample
scaled to range [0, 255].
Parameters:
See Also:
getBlue
public int getBlue(java.lang.Object inData)
Parameters:
See Also:
getColorSpace
public final ColorSpace getColorSpace()
getComponentSize
public int[] getComponentSize()
getComponentSize
public int getComponentSize(int componentIdx)
Parameters:
getComponents
public int[] getComponents(int pixel, int[] components, int offset)
Fills an array with the unnormalized component samples from a
pixel value. I.e. decompose the pixel, but not perform any
color conversion.
This method is typically overriden in subclasses to provide a
more efficient implementation.
Parameters:
Returns:
- arrays of unnormalized component samples of single
pixel. The scale and multiplication state of the samples are
according to the color model. Each component sample is stored
as a separate element in the array.
getComponents
public int[] getComponents(java.lang.Object pixel, int[] components, int offset)
Fills an array with the unnormalized component samples from an
array of transferType containing a single pixel. I.e. decompose
the pixel, but not perform any color conversion.
This method is typically overriden in subclasses to provide a
more efficient implementation.
Parameters:
Returns:
- arrays of unnormalized component samples of single
pixel. The scale and multiplication state of the samples are
according to the color model. Each component sample is stored
as a separate element in the array.
getDataElement
public int getDataElement(int[] components, int offset)
Converts the unnormalized component samples from an array to a
pixel value. I.e. composes the pixel from component samples, but
does not perform any color conversion or scaling of the samples.
This method performs the inverse function of
getComponents(int pixel, int[] components,
int offset)
. I.e.
(pixel == cm.getDataElement(cm.getComponents(pixel, null,
0), 0))
.
This method is typically overriden in subclasses to provide a
more efficient implementation.
Parameters:
Returns:
- pixel value encoded according to the color model.
getDataElements
public Object getDataElements(int[] components, int offset, java.lang.Object obj)
Parameters:
getDataElements
public Object getDataElements(int rgb, java.lang.Object pixel)
Converts an sRGB pixel int value to an array containing a
single pixel of the color space of the color model.
This method performs the inverse function of
getRGB(Object inData)
.
Outline of conversion process:
- Convert rgb to normalized [0.0, 1.0] sRGB values.
- Convert to color space components using fromRGB in
ColorSpace.
- If color model has alpha and should be premultiplied,
multiply color space components with alpha value
- Scale the components to the correct number of bits.
- Arrange the components in the output array
Parameters:
Returns:
- An array of transferType values representing the color,
in the color model format. The color model defines whether the
See Also:
getGreen
public int getGreen(int pixel)
Converts pixel value to sRGB and extract green int sample
scaled to range [0, 255].
Parameters:
See Also:
getGreen
public int getGreen(java.lang.Object inData)
Parameters:
See Also:
getNormalizedComponents
public float[] getNormalizedComponents(int[] components, int offset, float[] normComponents, int normOffset)
Convert unnormalized components to normalized components.
Parameters:
getNumColorComponents
public int getNumColorComponents()
getNumComponents
public int getNumComponents()
getPixelSize
public int getPixelSize()
Get get number of bits wide used for the bit size of pixel values
getRGB
public int getRGB(int pixel)
Converts a pixel int value of the color space of the color
model to a sRGB pixel int value.
This method is typically overriden in subclasses to provide a
more efficient implementation.
Parameters:
Returns:
- a pixel in sRGB color space, encoded in default
0xAARRGGBB format.
getRGB
public int getRGB(java.lang.Object inData)
Converts a pixel in the given array of the color space of the
color model to an sRGB pixel int value.
This method performs the inverse function of
getDataElements(int rgb, Object pixel)
.
I.e. (rgb == cm.getRGB(cm.getDataElements(rgb,
null)))
.
Parameters:
Returns:
- a pixel in sRGB color space, encoded in default
0xAARRGGBB format.
See Also:
getRGBdefault
public static ColorModel getRGBdefault()
Returns the default color model which in Sun's case is an instance
of DirectColorModel
.
getRed
public int getRed(int pixel)
Converts pixel value to sRGB and extract red int sample scaled
to range [0, 255].
Parameters:
Returns:
- red sample scaled to range [0, 255], from default color
space sRGB, alpha non-premultiplied.
getRed
public int getRed(java.lang.Object inData)
Converts pixel in the given array to sRGB and extract blue int
sample scaled to range [0-255].
This method is typically overriden in subclasses to provide a
more efficient implementation.
Parameters:
getTransparency
public int getTransparency()
getUnnormalizedComponents
public int[] getUnnormalizedComponents(float[] normComponents, int normOffset, int[] components, int offset)
Convert normalized components to unnormalized components.
Parameters:
hasAlpha
public final boolean hasAlpha()
isAlphaPremultiplied
public final boolean isAlphaPremultiplied()
isCompatibleRaster
public boolean isCompatibleRaster(java.awt.image.Raster raster)
Parameters:
isCompatibleSampleModel
public boolean isCompatibleSampleModel(java.awt.image.SampleModel sm)
Parameters:
toString
public String toString()