APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.image

public abstract Class PackedColorModel

extends ColorModel
Class Inheritance
Known Direct Subclasses
java.awt.image.DirectColorModel
Imports
java.awt.Transparency, java.awt.color.ColorSpace, java.util.Arrays

The PackedColorModel class is an abstract ColorModel class that works with pixel values which represent color and alpha information as separate samples and which pack all samples for a single pixel into a single int, short, or byte quantity. This class can be used with an arbitrary ColorSpace. The number of color samples in the pixel values must be the same as the number of color components in the ColorSpace. There can be a single alpha sample. The array length is always 1 for those methods that use a primitive array pixel representation of type transferType. 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 PackedColorModel is typically used with image data that uses masks to define packed samples. For example, a PackedColorModel 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 is 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 that use this representation do not throw an IllegalArgumentException due to an invalid pixel value.

A subclass of PackedColorModel is DirectColorModel, which is similar to an X11 TrueColor visual.

See Also
DirectColorModel, SinglePixelPackedSampleModel, BufferedImage

Field Summary

Modifier and TypeField and Description
private volatile int
pack-priv int[]
pack-priv int[]
pack-priv float[]
Inherited from java.awt.image.ColorModel:
colorSpacecolorSpaceTypeg16Tos8Mapg8Tos8Mapis_sRGBisAlphaPremultipliedl16Tos8l8Tos8lg16Toog16Maplg16Toog8MapmaxBitsnBitsnumColorComponentsnumComponentspixel_bitss8Tol16s8Tol8supportsAlphatransferTypetransparency

Constructor Summary

AccessConstructor and Description
public
PackedColorModel(ColorSpace
the specified ColorSpace
space
,
int
the number of bits in the pixel values
bits
,
int[]
array that specifies the masks representing the bits of the pixel values that represent the color components
colorMaskArray
,
int
specifies the mask representing the bits of the pixel values that represent the alpha component
alphaMask
,
boolean
true if color samples are premultiplied by the alpha sample; false otherwise
isAlphaPremultiplied
,
int
specifies the alpha value that can be represented by this color model
trans
,
int
the type of array used to represent pixel values
transferType
)

Constructs a PackedColorModel from a color mask array, which specifies which bits in an int pixel representation contain each of the color samples, and an alpha mask.

public
PackedColorModel(ColorSpace
the specified ColorSpace
space
,
int
the number of bits in the pixel values
bits
,
int
specifies the mask representing the bits of the pixel values that represent the red color component
rmask
,
int
specifies the mask representing the bits of the pixel values that represent the green color component
gmask
,
int
specifies the mask representing the bits of the pixel values that represent the blue color component
bmask
,
int
specifies the mask representing the bits of the pixel values that represent the alpha component
amask
,
boolean
true if color samples are premultiplied by the alpha sample; false otherwise
isAlphaPremultiplied
,
int
specifies the alpha value that can be represented by this color model
trans
,
int
the type of array used to represent pixel values
transferType
)

Constructs a PackedColorModel from the specified masks which indicate which bits in an int pixel representation contain the alpha, red, green and blue color samples.

Method Summary

Modifier and TypeMethod and Description
private static final int
countBits(int mask)

private static final int[]
createBitsArray(int[] colorMaskArray, int alphaMask)

private static final int[]
createBitsArray(int rmask, int gmask, int bmask, int amask)

public SampleModel

Returns:

the newly created SampleModel.
createCompatibleSampleModel
(int
the width (in pixels) of the region of the image data described
w
,
int
the height (in pixels) of the region of the image data described
h
)

Overrides java.awt.image.ColorModel.createCompatibleSampleModel.

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

private void
DecomposeMask(int mask, int idx, String componentName)

public boolean

Returns:

true if the specified Object is an instance of PackedColorModel and equals this PackedColorModel; false otherwise.
equals
(Object
the Object to test for equality
obj
)

Overrides java.awt.image.ColorModel.equals.

Tests if the specified Object is an instance of PackedColorModel and equals this PackedColorModel.

public WritableRaster

Returns:

a WritableRaster that represents the alpha channel of the image contained in raster.
getAlphaRaster
(WritableRaster
a WritableRaster containing an image
raster
)

Overrides java.awt.image.ColorModel.getAlphaRaster.

Returns a WritableRaster representing the alpha channel of an image, extracted from the input WritableRaster.

public final int

Returns:

the mask, which indicates which bits of the int pixel representation contain the color or alpha sample specified by index.
getMask
(int
the specified color or alpha sample
index
)

Returns the mask indicating which bits in a pixel contain the specified color/alpha sample.

public final int[]

Returns:

the mask array , which indicates which bits of the int pixel representation contain the color or alpha samples.
getMasks
()

Returns a mask array indicating which bits in a pixel contain the color and alpha samples.

public int

Returns:

a hash code for this PackedColorModel.
hashCode
()

Overrides java.awt.image.ColorModel.hashCode.

Returns the hash code for this PackedColorModel.

public boolean

Returns:

true if the specified SampleModel is compatible with this ColorModel; false otherwise.
isCompatibleSampleModel
(SampleModel
the specified SampleModel, or null
sm
)

Overrides java.awt.image.ColorModel.isCompatibleSampleModel.

Checks if the specified SampleModel is compatible with this ColorModel.

Inherited from java.awt.image.ColorModel:
coerceDatacreateCompatibleWritableRastergetAlphagetAlphagetBluegetBluegetColorSpacegetComponentsgetComponentsgetComponentSizegetComponentSizegetDataElementgetDataElementgetDataElementsgetDataElementsgetDataElementsgetDefaultTransferTypegetGray16TosRGB8LUTgetGray8TosRGB8LUTgetGreengetGreengetLinearGray16ToOtherGray16LUTgetLinearGray16ToOtherGray8LUTgetLinearRGB16TosRGB8LUTgetLinearRGB8TosRGB8LUTgetNormalizedComponentsgetNormalizedComponentsgetNumColorComponentsgetNumComponentsgetPixelSizegetRedgetRedgetRGBgetRGBgetRGBdefaultgetsRGB8ToLinearRGB16LUTgetsRGB8ToLinearRGB8LUTgetTransferTypegetTransparencygetUnnormalizedComponentshasAlphaisAlphaPremultipliedisCompatibleRasterisLinearGRAYspaceisLinearRGBspaceloadLibrariestoString

Field Detail

hashCodeback to summary
private volatile int hashCode
maskArrayback to summary
pack-priv int[] maskArray
maskOffsetsback to summary
pack-priv int[] maskOffsets
scaleFactorsback to summary
pack-priv float[] scaleFactors

Constructor Detail

PackedColorModelback to summary
public PackedColorModel(ColorSpace space, int bits, int[] colorMaskArray, int alphaMask, boolean isAlphaPremultiplied, int trans, int transferType)

Constructs a PackedColorModel from a color mask array, which specifies which bits in an int pixel representation contain each of the color samples, and an alpha mask. Color components are in the specified ColorSpace. The length of colorMaskArray should be the number of components in the ColorSpace. 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 the alphaMask is 0, there is no alpha. 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, trans, specifies what alpha values can be represented by this color model. The transfer type is the type of primitive array used to represent pixel values.

Parameters
space:ColorSpace

the specified ColorSpace

bits:int

the number of bits in the pixel values

colorMaskArray:int[]

array that specifies the masks representing the bits of the pixel values that represent the color components

alphaMask:int

specifies the mask representing the bits of the pixel values that represent the alpha component

isAlphaPremultiplied:boolean

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

trans:int

specifies the alpha value that can be represented by this color model

transferType:int

the type of array used to represent pixel values

Exceptions
IllegalArgumentException:
if bits is less than 1 or greater than 32
PackedColorModelback to summary
public PackedColorModel(ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean isAlphaPremultiplied, int trans, int transferType)

Constructs a PackedColorModel from the specified masks which indicate which bits in an int pixel representation contain the alpha, red, green and blue color samples. Color components are in the specified ColorSpace, which must be of type ColorSpace.TYPE_RGB. 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 amask is 0, there is no alpha. 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, trans, specifies what alpha values can be represented by this color model. The transfer type is the type of primitive array used to represent pixel values.

Parameters
space:ColorSpace

the specified ColorSpace

bits:int

the number of bits in the pixel values

rmask:int

specifies the mask representing the bits of the pixel values that represent the red color component

gmask:int

specifies the mask representing the bits of the pixel values that represent the green color component

bmask:int

specifies the mask representing the bits of the pixel values that represent the blue color component

amask:int

specifies the mask representing the bits of the pixel values that represent the alpha component

isAlphaPremultiplied:boolean

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

trans:int

specifies the alpha value that can be represented by this color model

transferType:int

the type of array used to represent pixel values

Exceptions
IllegalArgumentException:
if space is not a TYPE_RGB space
See Also
ColorSpace

Method Detail

countBitsback to summary
private static final int countBits(int mask)
createBitsArrayback to summary
private static final int[] createBitsArray(int[] colorMaskArray, int alphaMask)
createBitsArrayback to summary
private static final int[] createBitsArray(int rmask, int gmask, int bmask, int amask)
createCompatibleSampleModelback to summary
public SampleModel createCompatibleSampleModel(int w, int h)

Overrides java.awt.image.ColorModel.createCompatibleSampleModel.

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

Parameters
w:int

the width (in pixels) of the region of the image data described

h:int

the height (in pixels) of the region of the image data described

Returns:SampleModel

the newly created SampleModel.

Exceptions
IllegalArgumentException:
if w or h is not greater than 0
See Also
SampleModel
DecomposeMaskback to summary
private void DecomposeMask(int mask, int idx, String componentName)
equalsback to summary
public boolean equals(Object obj)

Overrides java.awt.image.ColorModel.equals.

Tests if the specified Object is an instance of PackedColorModel and equals this PackedColorModel.

Parameters
obj:Object

the Object to test for equality

Returns:boolean

true if the specified Object is an instance of PackedColorModel and equals this PackedColorModel; false otherwise.

Annotations
@Override
getAlphaRasterback to summary
public WritableRaster getAlphaRaster(WritableRaster raster)

Overrides java.awt.image.ColorModel.getAlphaRaster.

Returns a WritableRaster representing the alpha channel of an image, extracted from the input WritableRaster. This method assumes that WritableRaster objects associated with this ColorModel store the alpha band, if present, as the last band of image data. Returns null if there is no separate spatial alpha channel associated with this ColorModel. This method creates a new WritableRaster, but shares the data array.

Parameters
raster:WritableRaster

a WritableRaster containing an image

Returns:WritableRaster

a WritableRaster that represents the alpha channel of the image contained in raster.

getMaskback to summary
public final int getMask(int index)

Returns the mask indicating which bits in a pixel contain the specified color/alpha sample. For color samples, index corresponds to the placement of color sample names in the color space. Thus, an index equal to 0 for a CMYK ColorSpace would correspond to Cyan and an index equal to 1 would correspond to Magenta. If there is alpha, the alpha index would be:

     alphaIndex = numComponents() - 1;
Parameters
index:int

the specified color or alpha sample

Returns:int

the mask, which indicates which bits of the int pixel representation contain the color or alpha sample specified by index.

Exceptions
ArrayIndexOutOfBoundsException:
if index is greater than the number of components minus 1 in this PackedColorModel or if index is less than zero
getMasksback to summary
public final int[] getMasks()

Returns a mask array indicating which bits in a pixel contain the color and alpha samples.

Returns:int[]

the mask array , which indicates which bits of the int pixel representation contain the color or alpha samples.

hashCodeback to summary
public int hashCode()

Overrides java.awt.image.ColorModel.hashCode.

Returns the hash code for this PackedColorModel.

Returns:int

a hash code for this PackedColorModel.

Annotations
@Override
isCompatibleSampleModelback to summary
public boolean isCompatibleSampleModel(SampleModel sm)

Overrides java.awt.image.ColorModel.isCompatibleSampleModel.

Checks if the specified SampleModel is compatible with this ColorModel. If sm is null, this method returns false.

Parameters
sm:SampleModel

the specified SampleModel, or null

Returns:boolean

true if the specified SampleModel is compatible with this ColorModel; false otherwise.

See Also
SampleModel