java.awt.image
Class IndexColorModel

java.lang.Object
  |
  +--java.awt.image.ColorModel
        |
        +--java.awt.image.IndexColorModel
All Implemented Interfaces:
Transparency
public class IndexColorModel
extends ColorModel

The IndexColorModel class is a ColorModel class that works with pixel values consisting of a single sample which is an index into a fixed colormap in the default sRGB ColorSpace. The colormap specifies red, green, blue, and optional alpha components corresponding to each index. All components are represented in the colormap as 8-bit unsigned integral values. If alpha is not present, an opaque alpha component (alpha = 1.0) is assumed for each entry. An optional transparent pixel value can be supplied that indicates a completely transparent pixel, regardless of any alpha component recorded for that pixel value. Note that alpha values in IndexColorModel objects are never premultiplied. This color model is similar to an X11 PseudoColor visual.

The index represented by a pixel value is stored in the least significant n bits of the pixel representations passed to the methods of this class, where n is the pixel size specified to the constructor for a particular IndexColorModel object and n must be between 1 and 16. Higher order bits in pixel representations are assumed to be zero. 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 and DataBuffer.TYPE_USHORT. 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.

Many of the methods in this class are final. The reason for this is that 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 reaons, but you cannot override or modify the behaviour of those methods.

See Also:
ColorModel, ColorSpace, DataBuffer

 

Field Summary

 
Fields inherited from class java.awt.image.ColorModel
pixel_bits, transferType
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 

 

Constructor Summary

IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b)
    Constructs an IndexColorModel from the specified arrays of red, green, and blue components.
IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b, byte[] a)
    Constructs an IndexColorModel from the given arrays of red, green, blue and alpha components.
IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b, int trans)
    Constructs an IndexColorModel from the given arrays of red, green, and blue components.
IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasalpha)
    Constructs an IndexColorModel from a single array of interleaved red, green, blue and optional alpha components.
IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasalpha, int trans)
    Constructs an IndexColorModel from a single array of interleaved red, green, blue and optional alpha components.
IndexColorModel(int bits, int size, int[] cmap, int start, boolean hasalpha, int trans, int transferType)
    Constructs an IndexColorModel from an array of ints where each int is comprised of red, green, blue, and optional alpha components in the default RGB color model format.
IndexColorModel(int bits, int size, int[] cmap, int start, int transferType, BigInteger validBits)
    Constructs an IndexColorModel from an int array where each int is comprised of red, green, blue, and alpha components in the default RGB color model format.
 

 

Method Summary

 BufferedImage convertToIntDiscrete(Raster raster, boolean forceARGB)
    Returns a new BufferedImage of TYPE_INT_ARGB or TYPE_INT_RGB that has a Raster with pixel data computed by expanding the indices in the source Raster using the color/alpha component arrays of this ColorModel.
 SampleModel createCompatibleSampleModel(int w, int h)
    Creates a SampleModel with the specified width and height that has a data layout compatible with this ColorModel.
 WritableRaster createCompatibleWritableRaster(int w, int h)
    Creates a WritableRaster with the specified width and height that has a data layout (SampleModel) compatible with this ColorModel.
 void finalize()
    Disposes of system resources associated with this ColorModel once this ColorModel is no longer referenced.
 int getAlpha(int pixel)
    Returns the alpha component for the specified pixel, scaled from 0 to 255.
 void getAlphas(byte[] a)
    Copies the array of alpha transparency components into the specified array.
 int getBlue(int pixel)
    Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.
 void getBlues(byte[] b)
    Copies the array of blue color components into the specified array.
 int[] getComponents(int pixel, int[] components, int offset)
    Returns an array of unnormalized color/alpha components for a specified pixel in this ColorModel.
 int[] getComponents(Object pixel, int[] components, int offset)
    Returns an array of unnormalized color/alpha components for a specified pixel in this ColorModel.
 int[] getComponentSize()
    Returns an array of the number of bits for each color/alpha component.
 int getDataElement(int[] components, int offset)
    Returns a pixel value represented as an int in this ColorModel given an array of unnormalized color/alpha components.
 Object getDataElements(int[] components, int offset, Object pixel)
    Returns a data element array representation of a pixel in this ColorModel given an array of unnormalized color/alpha components.
 Object getDataElements(int rgb, Object pixel)
    Returns a data element array representation of a pixel in this ColorModel, given an integer pixel representation in the default RGB color model.
 int getGreen(int pixel)
    Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.
 void getGreens(byte[] g)
    Copies the array of green color components into the specified array.
 int getMapSize()
    Returns the size of the color/alpha component arrays in this IndexColorModel.
 int getRed(int pixel)
    Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.
 void getReds(byte[] r)
    Copies the array of red color components into the specified array.
 int getRGB(int pixel)
    Returns the color/alpha components of the pixel in the default RGB color model format.
 void getRGBs(int[] rgb)
    Converts data for each index from the color and alpha component arrays to an int in the default RGB ColorModel format and copies the resulting 32-bit ARGB values into the specified array.
 int getTransparency()
    Returns the transparency.
 int getTransparentPixel()
    Returns the index of the transparent pixel in this IndexColorModel or -1 if there is no transparent pixel.
 BigInteger getValidPixels()
    Returns a BigInteger that indicates the valid/invalid pixels in the colormap.
 boolean isCompatibleRaster(Raster raster)
    Returns true if raster is compatible with this ColorModel or false if it is not compatible with this ColorModel.
 boolean isCompatibleSampleModel(SampleModel sm)
    Checks if the specified SampleModel is compatible with this ColorModel.
 boolean isValid()
    Returns whether or not all of the pixels are valid.