PDAP Public Review Draft

java.awt.image
Class DirectColorModel

java.lang.Object
  |
  +--java.awt.image.ColorModel
        |
        +--java.awt.image.DirectColorModel

public class DirectColorModel
extends ColorModel

The DirectColorModel class is a ColorModel class that works with pixel values that represent RGB color and alpha information as separate samples and that pack all samples for a single pixel into a single int, short, or byte quantity. There must be three color samples in the pixel values and there can be a single alpha sample. For those methods that use a primitive array pixel representation of type transferType, the array length is always one. The transfer types supported are DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, and DataBuffer.TYPE_INT. Color and alpha samples are stored in the single element of the array in bits indicated by bit masks. Each bit mask must be contiguous and masks must not overlap. The same masks apply to the single int pixel representation used by other methods. The correspondence of masks and color/alpha samples is as follows:

The translation from pixel values to color/alpha components for display or processing purposes is a one-to-one correspondence of samples to components.

A single int pixel representation is valid for all objects of this class, since it is always possible to represent pixel values used with this class in a single int. Therefore, methods which use this representation will not throw an IllegalArgumentException due to an invalid pixel value.

This color model is similar to an X11 TrueColor visual. The default RGB ColorModel specified by the getRGBdefault method is a DirectColorModel with the following parameters:

 Number of bits:        32
 Red mask:              0x00ff0000
 Green mask:            0x0000ff00
 Blue mask:             0x000000ff
 Alpha mask:            0xff000000
 Color space:           sRGB
 isAlphaPremultiplied:  False
 Transparency:          Transparency.TRANSLUCENT
 transferType:          DataBuffer.TYPE_INT
 

Many of the methods in this class are final. This is because the underlying native graphics code makes assumptions about the layout and operation of this class and those assumptions are reflected in the implementations of the methods here that are marked final. You can subclass this class for other reasons, but you cannot override or modify the behavior of those methods.

See Also:
ColorModel, ColorModel.getRGBdefault()

Fields inherited from class java.awt.image.ColorModel
pixel_bits
 
Constructor Summary
DirectColorModel(int bits, int rmask, int gmask, int bmask)
          Constructs a DirectColorModel from the specified masks that indicate which bits in an int pixel representation contain the red, green and blue color samples.
DirectColorModel(int bits, int rmask, int gmask, int bmask, int amask)
          Constructs a DirectColorModel from the specified masks that indicate which bits in an int pixel representation contain the red, green and blue color samples and the alpha sample, if present.
 
Method Summary
 int getAlpha(int pixel)
          Returns the alpha component for the specified pixel, scaled from 0 to 255.
 int getAlphaMask()
          Returns the mask indicating which bits in an int pixel representation contain the alpha component.
 int getBlue(int pixel)
          Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB.
 int getBlueMask()
          Returns the mask indicating which bits in an int pixel representation contain the blue color component.
 int getGreen(int pixel)
          Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB.
 int getGreenMask()
          Returns the mask indicating which bits in an int pixel representation contain the green color component.
 int getRed(int pixel)
          Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB.
 int getRedMask()
          Returns the mask indicating which bits in an int pixel representation contain the red color component.
 int getRGB(int pixel)
          Returns the color/alpha components of the pixel in the default RGB color model format.
 java.lang.String toString()
          Returns a String that represents this DirectColorModel.
 
Methods inherited from class java.awt.image.ColorModel
equals, finalize, getPixelSize, getRGBdefault, hasAlpha, hashCode, isAlphaPremultiplied
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DirectColorModel

public DirectColorModel(int bits,
                        int rmask,
                        int gmask,
                        int bmask)
Constructs a DirectColorModel from the specified masks that indicate which bits in an int pixel representation contain the red, green and blue color samples. As pixel values do not contain alpha information, all pixels are treated as opaque, which means that alpha = 1.0. All of the bits in each mask must be contiguous and fit in the specified number of least significant bits of an int pixel representation. The transfer type is the smallest of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT that can hold a single pixel.
Parameters:
bits - the number of bits in the pixel values; for example, the sum of the number of bits in the masks.
rmask - specifies a mask indicating which bits in an integer pixel contain the red component
gmask - specifies a mask indicating which bits in an integer pixel contain the green component
bmask - specifies a mask indicating which bits in an integer pixel contain the blue component

DirectColorModel

public DirectColorModel(int bits,
                        int rmask,
                        int gmask,
                        int bmask,
                        int amask)
Constructs a DirectColorModel from the specified masks that indicate which bits in an int pixel representation contain the red, green and blue color samples and the alpha sample, if present. If amask is 0, pixel values do not contain alpha information and all pixels are treated as opaque, which means that alpha = 1.0. All of the bits in each mask must be contiguous and fit in the specified number of least significant bits of an int pixel representation. Alpha, if present, is not premultiplied. The transfer type is the smallest of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT that can hold a single pixel.
Parameters:
bits - the number of bits in the pixel values; for example, the sum of the number of bits in the masks.
rmask - specifies a mask indicating which bits in an integer pixel contain the red component
gmask - specifies a mask indicating which bits in an integer pixel contain the green component
bmask - specifies a mask indicating which bits in an integer pixel contain the blue component
amask - specifies a mask indicating which bits in an integer pixel contain the alpha component
Method Detail

getRedMask

public final int getRedMask()
Returns the mask indicating which bits in an int pixel representation contain the red color component.
Returns:
the mask, which indicates which bits of the int pixel representation contain the red color sample.

getGreenMask

public final int getGreenMask()
Returns the mask indicating which bits in an int pixel representation contain the green color component.
Returns:
the mask, which indicates which bits of the int pixel representation contain the green color sample.

getBlueMask

public final int getBlueMask()
Returns the mask indicating which bits in an int pixel representation contain the blue color component.
Returns:
the mask, which indicates which bits of the int pixel representation contain the blue color sample.

getAlphaMask

public final int getAlphaMask()
Returns the mask indicating which bits in an int pixel representation contain the alpha component.
Returns:
the mask, which indicates which bits of the int pixel representation contain the alpha sample.

getRed

public final 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. The returned value is a non pre-multiplied value. Thus, if the alpha is premultiplied, this method divides it out before returning the value. If the alpha value is 0, for example, the red value is 0.
Overrides:
getRed in class ColorModel
Parameters:
pixel - the specified pixel
Returns:
the red color component for the specified pixel, from 0 to 255 in the sRGB.

getGreen

public final 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. The returned value is a non pre-multiplied value. Thus, if the alpha is premultiplied, this method divides it out before returning the value. If the alpha value is 0, for example, the green value is 0.
Overrides:
getGreen in class ColorModel
Parameters:
pixel - the specified pixel
Returns:
the green color component for the specified pixel, from 0 to 255 in the sRGB.

getBlue

public final 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. The returned value is a non pre-multiplied value. Thus, if the alpha is premultiplied, this method divides it out before returning the value. If the alpha value is 0, for example, the blue value is 0.
Overrides:
getBlue in class ColorModel
Parameters:
pixel - the specified pixel
Returns:
the blue color component for the specified pixel, from 0 to 255 in the sRGB.

getAlpha

public final 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.
Overrides:
getAlpha in class ColorModel
Parameters:
pixel - the specified pixel
Returns:
the value of the alpha component of pixel from 0 to 255.

getRGB

public final 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. The returned value is in a non pre-multiplied format. Thus, if the alpha is premultiplied, this method divides it out of the color components. If the alpha value is 0, for example, the color values are each 0.
Overrides:
getRGB in class ColorModel
Parameters:
pixel - the specified pixel
Returns:
the RGB value of the color/alpha components of the specified pixel.
See Also:
ColorModel.getRGBdefault()

toString

public java.lang.String toString()
Returns a String that represents this DirectColorModel.
Overrides:
toString in class ColorModel
Returns:
a String representing this DirectColorModel.

PDAP 1.0 Spec, Rev. 0.16