Top Description Fields Constructors Methods
java.awt.image

public Class DirectColorModel

extends PackedColorModel
Class Inheritance
Imports
java.awt.color.ColorSpace, java.awt.Transparency

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. This class can be used only with ColorSpaces of type ColorSpace.TYPE_RGB. In addition, for each component of the ColorSpace, the minimum normalized component value obtained via the getMinValue() method of ColorSpace must be 0.0, and the maximum value obtained via the getMaxValue() method must be 1.0 (these min/max values are typical for RGB spaces). 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 DirectColorModel is typically used with image data which uses masks to define packed samples. For example, a DirectColorModel can be used in conjunction with a SinglePixelPackedSampleModel to construct a BufferedImage. Normally the masks used by the SampleModel and the ColorModel would be the same. However, if they are different, the color interpretation of pixel data will be done according to the masks of the ColorModel.

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, ColorSpace, SinglePixelPackedSampleModel, BufferedImage, ColorModel#getRGBdefault

Field Summary

Modifier and TypeField and Description
private int
private int
private int
private int
private int
private int
private short[]
private byte[]
private int
private int
private int
private boolean
private int
private int
private int
private int
private byte[]
Inherited from java.awt.image.PackedColorModel:
maskArraymaskOffsetsscaleFactors

Constructor Summary

AccessConstructor and Description
public
DirectColorModel(int
the number of bits in the pixel values; for example, the sum of the number of bits in the masks.
bits
,
int
specifies a mask indicating which bits in an integer pixel contain the red component
rmask
,
int
specifies a mask indicating which bits in an integer pixel contain the green component
gmask
,
int
specifies a mask indicating which bits in an integer pixel contain the blue component
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.

public
DirectColorModel(int
the number of bits in the pixel values; for example, the sum of the number of bits in the masks.
bits
,
int
specifies a mask indicating which bits in an integer pixel contain the red component
rmask
,
int
specifies a mask indicating which bits in an integer pixel contain the green component
gmask
,
int
specifies a mask indicating which bits in an integer pixel contain the blue component
bmask
,
int
specifies a mask indicating which bits in an integer pixel contain the alpha component
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.

public
DirectColorModel(ColorSpace
the specified ColorSpace
space
,
int
the number of bits in the pixel values; for example, the sum of the number of bits in the masks.
bits
,
int
specifies a mask indicating which bits in an integer pixel contain the red component
rmask
,
int
specifies a mask indicating which bits in an integer pixel contain the green component
gmask
,
int
specifies a mask indicating which bits in an integer pixel contain the blue component
bmask
,
int
specifies a mask indicating which bits in an integer pixel contain the alpha component
amask
,
boolean
true if color samples are premultiplied by the alpha sample; false otherwise
isAlphaPremultiplied
,
int
the type of array used to represent pixel values
transferType
)

Constructs a DirectColorModel from the specified parameters.

Method Summary

Modifier and TypeMethod and Description
public final ColorModel

Returns:

a ColorModel object that represents the coerced data.
coerceData
(WritableRaster
the WritableRaster data
raster
,
boolean
true if the alpha is premultiplied; false otherwise
isAlphaPremultiplied
)

Overrides java.awt.image.ColorModel.coerceData.

Forces the raster data to match the state specified in the isAlphaPremultiplied variable, assuming the data is currently correctly described by this ColorModel.

public final WritableRaster

Returns:

a WritableRaster object with the specified width and height.
createCompatibleWritableRaster
(int
the width to apply to the new WritableRaster
w
,
int
the height to apply to the new WritableRaster
h
)

Overrides java.awt.image.ColorModel.createCompatibleWritableRaster.

Creates a WritableRaster with the specified width and height that has a data layout (SampleModel) compatible with this ColorModel.

public final int

Returns:

the value of the alpha component of pixel from 0 to 255.
getAlpha
(int
the specified pixel
pixel
)

Implements abstract java.awt.image.ColorModel.getAlpha.

Returns the alpha component for the specified pixel, scaled from 0 to 255.

public int

Returns:

the alpha component of the specified pixel, scaled from 0 to 255.
getAlpha
(Object
the specified pixel
inData
)

Overrides java.awt.image.ColorModel.getAlpha.

Returns the alpha component for the specified pixel, scaled from 0 to 255.

public final int

Returns:

the mask, which indicates which bits of the int pixel representation contain the alpha sample.
getAlphaMask
()

Returns the mask indicating which bits in an int pixel representation contain the alpha component.

public final int

Returns:

the blue color component for the specified pixel, from 0 to 255 in the sRGB ColorSpace.
getBlue
(int
the specified pixel
pixel
)

Implements abstract java.awt.image.ColorModel.getBlue.

Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.

public int

Returns:

the value of the blue component of the specified pixel.
getBlue
(Object
the array containing the pixel value
inData
)

Overrides java.awt.image.ColorModel.getBlue.

Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.

public final int

Returns:

the mask, which indicates which bits of the int pixel representation contain the blue color sample.
getBlueMask
()

Returns the mask indicating which bits in an int pixel representation contain the blue color component.

public final int[]

Returns:

an array containing the color and alpha components of the specified pixel starting at the specified offset.
getComponents
(int
the specified pixel
pixel
,
int[]
the array to receive the color and alpha components of the specified pixel
components
,
int
the offset into the components array at which to start storing the color and alpha components
offset
)

Overrides java.awt.image.ColorModel.getComponents.

Returns an array of unnormalized color/alpha components given a pixel in this ColorModel.

public final int[]

Returns:

an array containing the color and alpha components of the specified pixel starting at the specified offset.
getComponents
(Object
the specified pixel
pixel
,
int[]
the array to receive the color and alpha components of the specified pixel
components
,
int
the offset into the components array at which to start storing the color and alpha components
offset
)

Overrides java.awt.image.ColorModel.getComponents.

Returns an array of unnormalized color/alpha components given a pixel in this ColorModel.

public int

Returns:

an int pixel value in this ColorModel corresponding to the specified components.
getDataElement
(int[]
an array of unnormalized color and alpha components
components
,
int
the index into components at which to begin retrieving the color and alpha components
offset
)

Overrides java.awt.image.ColorModel.getDataElement.

Returns a pixel value represented as an int in this ColorModel, given an array of unnormalized color/alpha components.

public Object

Returns:

an array representation of the specified pixel in this ColorModel
getDataElements
(int
the integer pixel representation in the default RGB color model
rgb
,
Object
the specified pixel
pixel
)

Overrides java.awt.image.ColorModel.getDataElements.

Returns a data element array representation of a pixel in this ColorModel, given an integer pixel representation in the default RGB color model.

public Object

Returns:

an Object representing an array of color and alpha components.
getDataElements
(int[]
an array of unnormalized color and alpha components
components
,
int
the index into components at which to begin retrieving color and alpha components
offset
,
Object
the Object representing an array of color and alpha components
obj
)

Overrides java.awt.image.ColorModel.getDataElements.

Returns a data element array representation of a pixel in this ColorModel, given an array of unnormalized color/alpha components.

private float[]
public final int

Returns:

the green color component for the specified pixel, from 0 to 255 in the sRGB ColorSpace.
getGreen
(int
the specified pixel
pixel
)

Implements abstract java.awt.image.ColorModel.getGreen.

Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.

public int

Returns:

the value of the green component of the specified pixel.
getGreen
(Object
the array containing the pixel value
inData
)

Overrides java.awt.image.ColorModel.getGreen.

Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.

public final int

Returns:

the mask, which indicates which bits of the int pixel representation contain the green color sample.
getGreenMask
()

Returns the mask indicating which bits in an int pixel representation contain the green color component.

public final int

Returns:

the red color component for the specified pixel, from 0 to 255 in the sRGB ColorSpace.
getRed
(int
the specified pixel
pixel
)

Implements abstract java.awt.image.ColorModel.getRed.

Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.

public int

Returns:

the value of the red component of the specified pixel.
getRed
(Object
the array containing the pixel value
inData
)

Overrides java.awt.image.ColorModel.getRed.

Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.

public final int

Returns:

the mask, which indicates which bits of the int pixel representation contain the red color sample.
getRedMask
()

Returns the mask indicating which bits in an int pixel representation contain the red color component.

public final int

Returns:

the RGB value of the color/alpha components of the specified pixel.
getRGB
(int
the specified pixel
pixel
)

Overrides java.awt.image.ColorModel.getRGB.

Returns the color/alpha components of the pixel in the default RGB color model format.

public int

Returns:

the color and alpha components of the specified pixel.
getRGB
(Object
the specified pixel
inData
)

Overrides java.awt.image.ColorModel.getRGB.

Returns the color/alpha components for the specified pixel in the default RGB color model format.

private int
getsRGBComponentFromLinearRGB(int pixel, int idx)

private int
getsRGBComponentFromsRGB(int pixel, int idx)

public boolean

Returns:

true if raster is compatible with this ColorModel; false otherwise.
isCompatibleRaster
(Raster
the Raster object to test for compatibility
raster
)

Overrides java.awt.image.ColorModel.isCompatibleRaster.

Returns true if raster is compatible with this ColorModel and false if it is not.

private void
public String

Returns:

a String representing this DirectColorModel.
toString
()

Overrides java.awt.image.ColorModel.toString.

Returns a String that represents this DirectColorModel.

Inherited from java.awt.image.PackedColorModel:
createCompatibleSampleModelequalsgetAlphaRastergetMaskgetMaskshashCodeisCompatibleSampleModel

Field Detail

alpha_maskback to summary
private int alpha_mask
alpha_offsetback to summary
private int alpha_offset
alpha_scaleback to summary
private int alpha_scale
blue_maskback to summary
private int blue_mask
blue_offsetback to summary
private int blue_offset
blue_scaleback to summary
private int blue_scale
fromsRGB8LUT16back to summary
private short[] fromsRGB8LUT16
fromsRGB8LUT8back to summary
private byte[] fromsRGB8LUT8
green_maskback to summary
private int green_mask
green_offsetback to summary
private int green_offset
green_scaleback to summary
private int green_scale
is_LinearRGBback to summary
private boolean is_LinearRGB
lRGBprecisionback to summary
private int lRGBprecision
red_maskback to summary
private int red_mask
red_offsetback to summary
private int red_offset
red_scaleback to summary
private int red_scale
tosRGB8LUTback to summary
private byte[] tosRGB8LUT

Constructor Detail

DirectColorModelback to summary
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 ColorSpace is the default sRGB space. The transparency value is Transparency.OPAQUE. 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:int

the number of bits in the pixel values; for example, the sum of the number of bits in the masks.

rmask:int

specifies a mask indicating which bits in an integer pixel contain the red component

gmask:int

specifies a mask indicating which bits in an integer pixel contain the green component

bmask:int

specifies a mask indicating which bits in an integer pixel contain the blue component

DirectColorModelback to summary
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 ColorSpace is the default sRGB space. The transparency value is Transparency.OPAQUE if no alpha is present, or Transparency.TRANSLUCENT otherwise. 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:int

the number of bits in the pixel values; for example, the sum of the number of bits in the masks.

rmask:int

specifies a mask indicating which bits in an integer pixel contain the red component

gmask:int

specifies a mask indicating which bits in an integer pixel contain the green component

bmask:int

specifies a mask indicating which bits in an integer pixel contain the blue component

amask:int

specifies a mask indicating which bits in an integer pixel contain the alpha component

DirectColorModelback to summary
public DirectColorModel(ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean isAlphaPremultiplied, int transferType)

Constructs a DirectColorModel from the specified parameters. Color components are in the specified ColorSpace, which must be of type ColorSpace.TYPE_RGB and have minimum normalized component values which are all 0.0 and maximum values which are all 1.0. The masks specify 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. If there is alpha, the boolean isAlphaPremultiplied specifies how to interpret color and alpha samples in pixel values. If the boolean is true, color samples are assumed to have been multiplied by the alpha sample. The transparency value is Transparency.OPAQUE, if no alpha is present, or Transparency.TRANSLUCENT otherwise. The transfer type is the type of primitive array used to represent pixel values and must be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT.

Parameters
space:ColorSpace

the specified ColorSpace

bits:int

the number of bits in the pixel values; for example, the sum of the number of bits in the masks.

rmask:int

specifies a mask indicating which bits in an integer pixel contain the red component

gmask:int

specifies a mask indicating which bits in an integer pixel contain the green component

bmask:int

specifies a mask indicating which bits in an integer pixel contain the blue component

amask:int

specifies a mask indicating which bits in an integer pixel contain the alpha component

isAlphaPremultiplied:boolean

true if color samples are premultiplied by the alpha sample; false otherwise

transferType:int

the type of array used to represent pixel values

Exceptions
IllegalArgumentException:
if space is not a TYPE_RGB space or if the min/max normalized component values are not 0.0/1.0.

Method Detail

coerceDataback to summary
public final ColorModel coerceData(WritableRaster raster, boolean isAlphaPremultiplied)

Overrides java.awt.image.ColorModel.coerceData.

Forces the raster data to match the state specified in the isAlphaPremultiplied variable, assuming the data is currently correctly described by this ColorModel. It may multiply or divide the color raster data by alpha, or do nothing if the data is in the correct state. If the data needs to be coerced, this method will also return an instance of this ColorModel with the isAlphaPremultiplied flag set appropriately. This method will throw a UnsupportedOperationException if this transferType is not supported by this ColorModel. Since ColorModel can be subclassed, subclasses inherit the implementation of this method and if they don't override it then they throw an exception if they use an unsupported transferType.

Parameters
raster:WritableRaster

the WritableRaster data

isAlphaPremultiplied:boolean

true if the alpha is premultiplied; false otherwise

Returns:ColorModel

a ColorModel object that represents the coerced data.

Exceptions
UnsupportedOperationException:
if this transferType is not supported by this color model
createCompatibleWritableRasterback to summary
public final WritableRaster createCompatibleWritableRaster(int w, int h)

Overrides java.awt.image.ColorModel.createCompatibleWritableRaster.

Creates a WritableRaster with the specified width and height that has a data layout (SampleModel) compatible with this ColorModel.

Parameters
w:int

the width to apply to the new WritableRaster

h:int

the height to apply to the new WritableRaster

Returns:WritableRaster

a WritableRaster object with the specified width and height.

Exceptions
IllegalArgumentException:
if w or h is less than or equal to zero
See Also
WritableRaster, SampleModel
getAlphaback to summary
public final int getAlpha(int pixel)

Implements abstract java.awt.image.ColorModel.getAlpha.

Returns the alpha component for the specified pixel, scaled from 0 to 255. The pixel value is specified as an int.

Parameters
pixel:int

the specified pixel

Returns:int

the value of the alpha component of pixel from 0 to 255.

getAlphaback to summary
public int getAlpha(Object inData)

Overrides java.awt.image.ColorModel.getAlpha.

Returns the alpha component for the specified pixel, scaled from 0 to 255. The pixel value is specified by an array of data elements of type transferType passed in as an object reference. If inData is not a primitive array of type transferType, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException is thrown if inData is not large enough to hold a pixel value for this ColorModel. Since DirectColorModel can be subclassed, subclasses inherit the implementation of this method and if they don't override it then they throw an exception if they use an unsupported transferType. If this transferType is not supported, an UnsupportedOperationException is thrown.

Parameters
inData:Object

the specified pixel

Returns:int

the alpha component of the specified pixel, scaled from 0 to 255.

Exceptions
ClassCastException:
if inData is not a primitive array of type transferType
ArrayIndexOutOfBoundsException:
if inData is not large enough to hold a pixel value for this ColorModel
UnsupportedOperationException:
if this tranferType is not supported by this ColorModel
getAlphaMaskback to summary
public final int getAlphaMask()

Returns the mask indicating which bits in an int pixel representation contain the alpha component.

Returns:int

the mask, which indicates which bits of the int pixel representation contain the alpha sample.

getBlueback to summary
public final int getBlue(int pixel)

Implements abstract java.awt.image.ColorModel.getBlue.

Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB. 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.

Parameters
pixel:int

the specified pixel

Returns:int

the blue color component for the specified pixel, from 0 to 255 in the sRGB ColorSpace.

getBlueback to summary
public int getBlue(Object inData)

Overrides java.awt.image.ColorModel.getBlue.

Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB. A color conversion is done if necessary. The pixel value is specified by an array of data elements of type transferType passed in as an object reference. 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. If inData is not a primitive array of type transferType, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException is thrown if inData is not large enough to hold a pixel value for this ColorModel. Since DirectColorModel can be subclassed, subclasses inherit the implementation of this method and if they don't override it then they throw an exception if they use an unsupported transferType. An UnsupportedOperationException is thrown if this transferType is not supported by this ColorModel.

Parameters
inData:Object

the array containing the pixel value

Returns:int

the value of the blue component of the specified pixel.

Exceptions
ArrayIndexOutOfBoundsException:
if inData is not large enough to hold a pixel value for this color model
ClassCastException:
if inData is not a primitive array of type transferType
UnsupportedOperationException:
if this transferType is not supported by this color model
getBlueMaskback to summary
public final int getBlueMask()

Returns the mask indicating which bits in an int pixel representation contain the blue color component.

Returns:int

the mask, which indicates which bits of the int pixel representation contain the blue color sample.

getComponentsback to summary
public final int[] getComponents(int pixel, int[] components, int offset)

Overrides java.awt.image.ColorModel.getComponents.

Returns an array of unnormalized color/alpha components given a pixel in this ColorModel. The pixel value is specified as an int. If the components array is null, a new array is allocated. The components array is returned. Color/alpha components are stored in the components array starting at offset, even if the array is allocated by this method. An ArrayIndexOutOfBoundsException is thrown if the components array is not null and is not large enough to hold all the color and alpha components, starting at offset.

Parameters
pixel:int

the specified pixel

components:int[]

the array to receive the color and alpha components of the specified pixel

offset:int

the offset into the components array at which to start storing the color and alpha components

Returns:int[]

an array containing the color and alpha components of the specified pixel starting at the specified offset.

getComponentsback to summary
public final int[] getComponents(Object pixel, int[] components, int offset)

Overrides java.awt.image.ColorModel.getComponents.

Returns an array of unnormalized color/alpha components given a pixel in this ColorModel. The pixel value is specified by an array of data elements of type transferType passed in as an object reference. If pixel is not a primitive array of type transferType, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException is thrown if pixel is not large enough to hold a pixel value for this ColorModel. If the components array is null, a new array is allocated. The components array is returned. Color/alpha components are stored in the components array starting at offset, even if the array is allocated by this method. An ArrayIndexOutOfBoundsException is thrown if the components array is not null and is not large enough to hold all the color and alpha components, starting at offset. Since DirectColorModel can be subclassed, subclasses inherit the implementation of this method and if they don't override it then they throw an exception if they use an unsupported transferType.

Parameters
pixel:Object

the specified pixel

components:int[]

the array to receive the color and alpha components of the specified pixel

offset:int

the offset into the components array at which to start storing the color and alpha components

Returns:int[]

an array containing the color and alpha components of the specified pixel starting at the specified offset.

Exceptions
ClassCastException:
if pixel is not a primitive array of type transferType
ArrayIndexOutOfBoundsException:
if pixel is not large enough to hold a pixel value for this ColorModel, or if components is not null and is not large enough to hold all the color and alpha components, starting at offset
UnsupportedOperationException:
if this transferType is not supported by this color model
getDataElementback to summary
public int getDataElement(int[] components, int offset)

Overrides java.awt.image.ColorModel.getDataElement.

Returns a pixel value represented as an int in this ColorModel, given an array of unnormalized color/alpha components. An ArrayIndexOutOfBoundsException is thrown if the components array is not large enough to hold all the color and alpha components, starting at offset.

Parameters
components:int[]

an array of unnormalized color and alpha components

offset:int

the index into components at which to begin retrieving the color and alpha components

Returns:int

an int pixel value in this ColorModel corresponding to the specified components.

Exceptions
ArrayIndexOutOfBoundsException:
if the components array is not large enough to hold all of the color and alpha components starting at offset
getDataElementsback to summary
public Object getDataElements(int rgb, Object pixel)

Overrides java.awt.image.ColorModel.getDataElements.

Returns a data element array representation of a pixel in this ColorModel, given an integer pixel representation in the default RGB color model. This array can then be passed to the setDataElements method of a WritableRaster object. If the pixel variable is null, a new array is allocated. If pixel is not null, it must be a primitive array of type transferType; otherwise, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException is thrown if pixel is not large enough to hold a pixel value for this ColorModel. The pixel array is returned. Since DirectColorModel can be subclassed, subclasses inherit the implementation of this method and if they don't override it then they throw an exception if they use an unsupported transferType.

Parameters
rgb:int

the integer pixel representation in the default RGB color model

pixel:Object

the specified pixel

Returns:Object

an array representation of the specified pixel in this ColorModel

Exceptions
ClassCastException:
if pixel is not a primitive array of type transferType
ArrayIndexOutOfBoundsException:
if pixel is not large enough to hold a pixel value for this ColorModel
UnsupportedOperationException:
if this transferType is not supported by this ColorModel
See Also
WritableRaster#setDataElements, SampleModel#setDataElements
getDataElementsback to summary
public Object getDataElements(int[] components, int offset, Object obj)

Overrides java.awt.image.ColorModel.getDataElements.

Returns a data element array representation of a pixel in this ColorModel, given an array of unnormalized color/alpha components. This array can then be passed to the setDataElements method of a WritableRaster object. An ArrayIndexOutOfBoundsException is thrown if the components array is not large enough to hold all the color and alpha components, starting at offset. If the obj variable is null, a new array is allocated. If obj is not null, it must be a primitive array of type transferType; otherwise, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException is thrown if obj is not large enough to hold a pixel value for this ColorModel. Since DirectColorModel can be subclassed, subclasses inherit the implementation of this method and if they don't override it then they throw an exception if they use an unsupported transferType.

Parameters
components:int[]

an array of unnormalized color and alpha components

offset:int

the index into components at which to begin retrieving color and alpha components

obj:Object

the Object representing an array of color and alpha components

Returns:Object

an Object representing an array of color and alpha components.

Exceptions
ClassCastException:
if obj is not a primitive array of type transferType
ArrayIndexOutOfBoundsException:
if obj is not large enough to hold a pixel value for this ColorModel or the components array is not large enough to hold all of the color and alpha components starting at offset
UnsupportedOperationException:
if this transferType is not supported by this color model
See Also
WritableRaster#setDataElements, SampleModel#setDataElements
getDefaultRGBComponentsback to summary
private float[] getDefaultRGBComponents(int pixel)
getGreenback to summary
public final int getGreen(int pixel)

Implements abstract java.awt.image.ColorModel.getGreen.

Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB. 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.

Parameters
pixel:int

the specified pixel

Returns:int

the green color component for the specified pixel, from 0 to 255 in the sRGB ColorSpace.

getGreenback to summary
public int getGreen(Object inData)

Overrides java.awt.image.ColorModel.getGreen.

Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB. A color conversion is done if necessary. The pixel value is specified by an array of data elements of type transferType passed in as an object reference. 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. If inData is not a primitive array of type transferType, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException is thrown if inData is not large enough to hold a pixel value for this ColorModel. Since DirectColorModel can be subclassed, subclasses inherit the implementation of this method and if they don't override it then they throw an exception if they use an unsupported transferType. An UnsupportedOperationException is thrown if this transferType is not supported by this ColorModel.

Parameters
inData:Object

the array containing the pixel value

Returns:int

the value of the green component of the specified pixel.

Exceptions
ArrayIndexOutOfBoundsException:
if inData is not large enough to hold a pixel value for this color model
ClassCastException:
if inData is not a primitive array of type transferType
UnsupportedOperationException:
if this transferType is not supported by this color model
getGreenMaskback to summary
public final int getGreenMask()

Returns the mask indicating which bits in an int pixel representation contain the green color component.

Returns:int

the mask, which indicates which bits of the int pixel representation contain the green color sample.

getRedback to summary
public final int getRed(int pixel)

Implements abstract java.awt.image.ColorModel.getRed.

Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB. 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.

Parameters
pixel:int

the specified pixel

Returns:int

the red color component for the specified pixel, from 0 to 255 in the sRGB ColorSpace.

getRedback to summary
public int getRed(Object inData)

Overrides java.awt.image.ColorModel.getRed.

Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB. A color conversion is done if necessary. The pixel value is specified by an array of data elements of type transferType passed in as an object reference. 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. If inData is not a primitive array of type transferType, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException is thrown if inData is not large enough to hold a pixel value for this ColorModel. Since DirectColorModel can be subclassed, subclasses inherit the implementation of this method and if they don't override it then they throw an exception if they use an unsupported transferType. An UnsupportedOperationException is thrown if this transferType is not supported by this ColorModel.

Parameters
inData:Object

the array containing the pixel value

Returns:int

the value of the red component of the specified pixel.

Exceptions
ArrayIndexOutOfBoundsException:
if inData is not large enough to hold a pixel value for this color model
ClassCastException:
if inData is not a primitive array of type transferType
UnsupportedOperationException:
if this transferType is not supported by this color model
getRedMaskback to summary
public final int getRedMask()

Returns the mask indicating which bits in an int pixel representation contain the red color component.

Returns:int

the mask, which indicates which bits of the int pixel representation contain the red color sample.

getRGBback to summary
public final int getRGB(int pixel)

Overrides java.awt.image.ColorModel.getRGB.

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.

Parameters
pixel:int

the specified pixel

Returns:int

the RGB value of the color/alpha components of the specified pixel.

See Also
ColorModel#getRGBdefault
getRGBback to summary
public int getRGB(Object inData)

Overrides java.awt.image.ColorModel.getRGB.

Returns the color/alpha components for the specified pixel in the default RGB color model format. A color conversion is done if necessary. The pixel value is specified by an array of data elements of type transferType passed in as an object reference. If inData is not a primitive array of type transferType, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException is thrown if inData is not large enough to hold a pixel value for this ColorModel. 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 is 0. Since DirectColorModel can be subclassed, subclasses inherit the implementation of this method and if they don't override it then they throw an exception if they use an unsupported transferType.

Parameters
inData:Object

the specified pixel

Returns:int

the color and alpha components of the specified pixel.

Exceptions
UnsupportedOperationException:
if this transferType is not supported by this ColorModel
See Also
ColorModel#getRGBdefault
getsRGBComponentFromLinearRGBback to summary
private int getsRGBComponentFromLinearRGB(int pixel, int idx)
getsRGBComponentFromsRGBback to summary
private int getsRGBComponentFromsRGB(int pixel, int idx)
isCompatibleRasterback to summary
public boolean isCompatibleRaster(Raster raster)

Overrides java.awt.image.ColorModel.isCompatibleRaster.

Returns true if raster is compatible with this ColorModel and false if it is not.

Parameters
raster:Raster

the Raster object to test for compatibility

Returns:boolean

true if raster is compatible with this ColorModel; false otherwise.

setFieldsback to summary
private void setFields()
toStringback to summary
public String toString()

Overrides java.awt.image.ColorModel.toString.

Returns a String that represents this DirectColorModel.

Returns:String

a String representing this DirectColorModel.