PDAP Public Review Draft

java.awt.image
Class ColorModel

java.lang.Object
  |
  +--java.awt.image.ColorModel
Direct Known Subclasses:
DirectColorModel, IndexColorModel

public abstract class ColorModel
extends java.lang.Object

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.

See Also:
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 ColorModelobject.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

pixel_bits

protected int pixel_bits
The total number of bits in the pixel.
Constructor Detail

ColorModel

public ColorModel(int bits)
Constructs a 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.
Parameters:
bits - the number of bits of a pixel
Throws:
java.lang.IllegalArgumentException - if the number of bits in bits is less than 1
Method Detail

getRGBdefault

public 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. 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.
Returns:
a DirectColorModelobject describing default RGB values.

hasAlpha

public final boolean hasAlpha()
Returns whether or not alpha is supported in this ColorModel.
Returns:
true if alpha is supported in this ColorModel; false otherwise.

isAlphaPremultiplied

public final boolean isAlphaPremultiplied()
Returns whether or not the alpha has been premultiplied in the pixel values to be translated by this 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.
Returns:
true if the alpha values are premultiplied in the pixel values to be translated by this ColorModel; false otherwise.

getPixelSize

public int getPixelSize()
Returns the number of bits per pixel described by this ColorModel.
Returns:
the number of bits per pixel.

getRed

public abstract int getRed(int pixel)
Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB. A color conversion is done if necessary. The pixel value is specified as an int. An 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.
Parameters:
pixel - a specified pixel
Returns:
the value of the red component of the specified pixel.

getGreen

public abstract int getGreen(int pixel)
Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB. A color conversion is done if necessary. The pixel value is specified as an int. An 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.
Parameters:
pixel - the specified pixel
Returns:
the value of the green component of the specified pixel.

getBlue

public abstract int getBlue(int pixel)
Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB. A color conversion is done if necessary. The pixel value is specified as an int. An 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.
Parameters:
pixel - the specified pixel
Returns:
the value of the blue component of the specified pixel.

getAlpha

public abstract int getAlpha(int pixel)
Returns the alpha component for the specified pixel, scaled from 0 to 255. The pixel value is specified as an int. An IllegalArgumentException is thrown if pixel values for this ColorModel are not conveniently representable as a single int.
Parameters:
pixel - the specified pixel
Returns:
the value of alpha component of the specified pixel.

getRGB

public int getRGB(int pixel)
Returns the color/alpha components of the pixel in the default RGB color model format. A color conversion is done if necessary. The pixel value is specified as an int. An 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.
Parameters:
pixel - the specified pixel
Returns:
the RGB value of the color/alpha components of the specified pixel.
See Also:
getRGBdefault()

equals

public boolean equals(java.lang.Object obj)
Tests if the specified Object is an instance of ColorModel and if it equals this ColorModel.
Overrides:
equals in class java.lang.Object
Parameters:
obj - the Object to test for equality
Returns:
true if the specified Object is an instance of ColorModel and equals this ColorModel; false otherwise.

hashCode

public int hashCode()
Returns the hash code for this ColorModel.
Overrides:
hashCode in class java.lang.Object
Returns:
a hash code for this ColorModel.

finalize

public void finalize()
Disposes of system resources associated with this ColorModel once this ColorModel is no longer referenced.

toString

public java.lang.String toString()
Returns the String representation of the contents of this ColorModelobject.
Overrides:
toString in class java.lang.Object
Returns:
a String representing the contents of this ColorModel object.

PDAP 1.0 Spec, Rev. 0.16