|
PDAP Public Review Draft | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.image.ColorModel
The ColorModel
abstract class encapsulates the
methods for translating a pixel value to color components
(for example, red, green, and blue) and an alpha component.
In order to render an image to the screen, a printer, or another
image, pixel values must be converted to color and alpha components.
As arguments to or return values from methods of this class,
pixels are represented as 32-bit ints or as arrays of primitive types.
A ColorModel
used with pixel data that does not include
alpha information treats all pixels as opaque, which is an alpha
value of 1.0.
This ColorModel
class supports two representations of
pixel values. A pixel value can be a single 32-bit int or an
array of primitive types. The Java(tm) Platform 1.0 and 1.1 APIs
represented pixels as single byte
or single
int
values. For purposes of the ColorModel
class, pixel value arguments were passed as ints.
ColorModel
objects used with images for which pixel values
are not conveniently representable as a single int throw an
IllegalArgumentException
when methods taking a single int pixel
argument are called. Subclasses of ColorModel
must
specify the conditions under which this occurs. This does not
occur with DirectColorModel
or IndexColorModel
objects.
The algorithm used to convert from pixel values to color and alpha components varies by subclass. Even when there is such a correspondence, the number of bits in a sample is not necessarily the same as the number of bits in the corresponding color/alpha component. Each subclass must specify how the translation from pixel values to color/alpha components is done.
Methods in the ColorModel
class use two different
representations of color and alpha components. In the unnormalized
form, each component is an unsigned integral value between 0 and
2n - 1, where n is the number of significant bits for a
particular component. If pixel values for a particular
ColorModel
represent color samples premultiplied by
the alpha sample, unnormalized color component values are
also premultiplied. In the normalized form, each component is a
float
value between 0.0 and 1.0. Normalized color
component values are not premultiplied.
IndexColorModel
,
DirectColorModel
,
Image
Field Summary | |
protected int |
pixel_bits
The total number of bits in the pixel. |
Constructor Summary | |
ColorModel(int bits)
Constructs a ColorModel that translates pixels of the
specified number of bits to color/alpha components. |
Method Summary | |
boolean |
equals(java.lang.Object obj)
Tests if the specified Object is an instance of
ColorModel and if it equals this
ColorModel . |
void |
finalize()
Disposes of system resources associated with this ColorModel once this ColorModel is no
longer referenced. |
abstract int |
getAlpha(int pixel)
Returns the alpha component for the specified pixel, scaled from 0 to 255. |
abstract int |
getBlue(int pixel)
Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB. |
abstract int |
getGreen(int pixel)
Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB. |
int |
getPixelSize()
Returns the number of bits per pixel described by this ColorModel . |
abstract int |
getRed(int pixel)
Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB. |
int |
getRGB(int pixel)
Returns the color/alpha components of the pixel in the default RGB color model format. |
static ColorModel |
getRGBdefault()
Returns a DirectColorModel that describes the default
format for integer RGB values used in many of the methods in the
AWT image interfaces for the convenience of the programmer. |
boolean |
hasAlpha()
Returns whether or not alpha is supported in this ColorModel . |
int |
hashCode()
Returns the hash code for this ColorModel. |
boolean |
isAlphaPremultiplied()
Returns whether or not the alpha has been premultiplied in the pixel values to be translated by this ColorModel . |
java.lang.String |
toString()
Returns the String representation of the contents of
this ColorModel object. |
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
protected int pixel_bits
Constructor Detail |
public ColorModel(int bits)
ColorModel
that translates pixels of the
specified number of bits to color/alpha components.
Pixel values are assumed to include alpha information. If color
and alpha information are represented in the pixel value as
separate spatial bands, the color bands are assumed not to be
premultiplied with the alpha value. The transfer type will be the
smallest of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
or DataBuffer.TYPE_INT that can hold a single pixel
(or DataBuffer.TYPE_UNDEFINED if bits is greater
than 32). Since this constructor has no information about the
number of bits per color and alpha component, any subclass calling
this constructor should override any method that requires this
information.bits
- the number of bits of a pixeljava.lang.IllegalArgumentException
- if the number
of bits in bits
is less than 1Method Detail |
public static ColorModel getRGBdefault()
DirectColorModel
that describes the default
format for integer RGB values used in many of the methods in the
AWT image interfaces for the convenience of the programmer.
The format for the RGB values is an integer with 8 bits
each of alpha, red, green, and blue color components ordered
correspondingly from the most significant byte to the least
significant byte, as in: 0xAARRGGBB. Color components are
not premultiplied by the alpha component. This format does not
necessarily represent the native or the most efficient
ColorModel
for a particular device or for all images.
It is merely used as a common color model format.DirectColorModel
object describing default
RGB values.public final boolean hasAlpha()
ColorModel
.true
if alpha is supported in this
ColorModel
; false
otherwise.public final boolean isAlphaPremultiplied()
ColorModel
.
If the boolean is true
, this ColorModel
is to be used to interpret pixel values in which color and alpha
information are represented as separate spatial bands, and color
samples are assumed to have been multiplied by the
alpha sample.true
if the alpha values are premultiplied
in the pixel values to be translated by this
ColorModel
; false
otherwise.public int getPixelSize()
ColorModel
.public abstract int getRed(int pixel)
IllegalArgumentException
is thrown if pixel
values for this ColorModel
are not conveniently
representable as a single int. The returned value is not a
pre-multiplied value. For example, if the
alpha is premultiplied, this method divides it out before returning
the value. If the alpha value is 0, the red value is 0.pixel
- a specified pixelpublic abstract int getGreen(int pixel)
IllegalArgumentException
is thrown if pixel
values for this ColorModel
are not conveniently
representable as a single int. The returned value is a non
pre-multiplied value. For example, if the alpha is premultiplied,
this method divides it out before returning
the value. If the alpha value is 0, the green value is 0.pixel
- the specified pixelpublic abstract int getBlue(int pixel)
IllegalArgumentException
is thrown if pixel values
for this ColorModel
are not conveniently representable
as a single int. The returned value is a non pre-multiplied
value, for example, if the alpha is premultiplied, this method
divides it out before returning the value. If the alpha value is
0, the blue value is 0.pixel
- the specified pixelpublic abstract int getAlpha(int pixel)
IllegalArgumentException
is thrown if pixel
values for this ColorModel
are not conveniently
representable as a single int.pixel
- the specified pixelpublic int getRGB(int pixel)
IllegalArgumentException
thrown if pixel values
for this ColorModel
are not conveniently representable
as a single int. The returned value is in a non
pre-multiplied format. For example, if the alpha is premultiplied,
this method divides it out of the color components. If the alpha
value is 0, the color values are 0.pixel
- the specified pixelgetRGBdefault()
public boolean equals(java.lang.Object obj)
Object
is an instance of
ColorModel
and if it equals this
ColorModel
.equals
in class java.lang.Object
obj
- the Object
to test for equalitytrue
if the specified Object
is an instance of ColorModel
and equals this
ColorModel
; false
otherwise.public int hashCode()
hashCode
in class java.lang.Object
public void finalize()
ColorModel
once this ColorModel
is no
longer referenced.public java.lang.String toString()
String
representation of the contents of
this ColorModel
object.toString
in class java.lang.Object
String
representing the contents of this
ColorModel
object.
|
PDAP 1.0 Spec, Rev. 0.16 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |