Java Platform 1.2

java.awt.image
Class PackedColorModel

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

public abstract class PackedColorModel
extends ColorModel

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 same as the number of color components in the ColorSpace. There may be a single alpha sample. For those methods which use a primitive array pixel representation of type transferType, the array length is always one. 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. Masks are identified by indices running from 0 through getNumComponents() - 1. The first getNumColorComponents() indices refer to color samples. If an alpha sample is present, it corresponds the last index. The order of the color indices is specified by the ColorSpace. Typically, this reflects the name of the color space type, e.g. for TYPE_RGB, index 0 corresponds to red, index 1 to green, and index 2 to blue. The transfer types supported are DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, and DataBuffer.TYPE_INT.

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 which 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 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.

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

See Also:
DirectColorModel, SinglePixelPackedSampleModel, BufferedImage

Fields inherited from class java.awt.image.ColorModel
pixel_bits, transferType
 
Constructor Summary
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.
PackedColorModel(ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean isAlphaPremultiplied, int trans, int transferType)
          Constructs a PackedColorModel from the given masks specifying which bits in an int pixel representation contain the alpha, red, green and blue color samples.
 
Method Summary
 SampleModel createCompatibleSampleModel(int w, int h)
          Creates a SampleModel with the specified width and height that has a data layout compatible with this ColorModel.
 boolean equals(Object obj)
          Tests if the specified Object is an instance of PackedColorModel and equals this PackedColorModel.
 WritableRaster getAlphaRaster(WritableRaster raster)
          Returns a Raster representing the alpha channel of an image, extracted from the input Raster.
 int getMask(int index)
          Returns the mask indicating which bits in an int pixel representation contain the specified color/alpha sample.
 int[] getMasks()
          Returns a mask array indicating which bits in an int pixel representation contain the color and alpha samples.
 boolean isCompatibleSampleModel(SampleModel sm)
          Checks if the SampleModel is compatible with this ColorModel.
 
Methods inherited from class java.awt.image.ColorModel
coerceData, createCompatibleWritableRaster, finalize, getAlpha, getAlpha, getBlue, getBlue, getColorSpace, getComponents, getComponents, getComponentSize, getComponentSize, getDataElement, getDataElements, getDataElements, getGreen, getGreen, getNormalizedComponents, getNumColorComponents, getNumComponents, getPixelSize, getRed, getRed, getRGB, getRGB, getRGBdefault, getTransparency, getUnnormalizedComponents, hasAlpha, isAlphaPremultiplied, isCompatibleRaster, toString
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PackedColorModel

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 will be 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 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.

PackedColorModel

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 given masks specifying which bits in an int pixel representation contain the alpha, red, green and blue color samples. Color components will be 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 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.
See Also:
ColorSpace
Method Detail

getMask

public final int getMask(int index)
Returns the mask indicating which bits in an int pixel representation contain the specified color/alpha sample. For color samples, the index corresponds to the placement of color sample names in the color space. Thus, index 0 for a CMYK ColorSpace would correspond to Cyan and index 1 would correspond to Magenta. If there is alpha, the alpha index would be:
      alphaIndex = numComponents() - 1;
 

getMasks

public final int[] getMasks()
Returns a mask array indicating which bits in an int pixel representation contain the color and alpha samples.

createCompatibleSampleModel

public SampleModel createCompatibleSampleModel(int w,
                                               int h)
Creates a SampleModel with the specified width and height that has a data layout compatible with this ColorModel.
Overrides:
createCompatibleSampleModel in class ColorModel
See Also:
SampleModel

isCompatibleSampleModel

public boolean isCompatibleSampleModel(SampleModel sm)
Checks if the SampleModel is compatible with this ColorModel.
Overrides:
isCompatibleSampleModel in class ColorModel
See Also:
SampleModel

getAlphaRaster

public WritableRaster getAlphaRaster(WritableRaster raster)
Returns a Raster representing the alpha channel of an image, extracted from the input Raster. This method assumes that Rasters 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 will create a new Raster (but will share the data array).
Overrides:
getAlphaRaster in class ColorModel

equals

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

Java Platform 1.2

Submit a bug or feature Version 1.2 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.