Java Platform 1.2
Beta 4

Class java.awt.image.IndexColorModel

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

public class IndexColorModel
extends ColorModel
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) will be assumed for each entry. An optional transparent pixel value can be supplied which indicates a completely transparent pixel, regardless of any alpha component recorded for that pixel value. Note that alpha values in IndexColorModels 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. Higher order bits in pixel representations are assumed to be zero. For those methods which 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. 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.

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

Fields inherited from class java.awt.image.ColorModel
pixel_bits , transferType
 
Constructor Summary
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[] r, byte[] g, byte[] b)
          Constructs an IndexColorModel from the given arrays of red, green, and blue 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, 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, 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.
 
Method Summary
 BufferedImage convertToIntDiscrete(Raster raster, boolean forceARGB)
          Returns a new BufferedImage of TYPE_INT_ARGB or TYPE_INT_RGB which 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.
 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.
 void getAlphas(byte[] a)
          Copies the array of alpha transparency components into the given 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. The pixel value is specified as an int.
 void getBlues(byte[] b)
          Copies the array of blue color components into the given array.
 int[] getComponents(int pixel, int[] components, int offset)
          Returns an array of unnormalized color/alpha components given a pixel in this ColorModel.
 int[] getComponents(Object pixel, int[] components, int offset)
          Returns an array of unnormalized color/alpha components given a pixel in this ColorModel.
 int[] getComponentSize()
          Returns an array of the number of bits per color/alpha component.
 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. The pixel value is specified as an int.
 void getGreens(byte[] g)
          Copies the array of green color components into the given 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. The pixel value is specified as an int.
 void getReds(byte[] r)
          Copies the array of red color components into the given 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 given 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.
 boolean isCompatibleRaster(Raster raster)
          Returns true if raster is compatible with this ColorModel and false if it is not.
 boolean isCompatibleSampleModel(SampleModel sm)
          Checks if the SampleModel is compatible with this ColorModel.
 int setDataElement(int[] components, int offset)
          Returns a pixel value represented as an int in this ColorModel, given an array of unnormalized color/alpha components.
 Object setDataElements(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.
 String toString()
          Prints the contents of this object
 
Methods inherited from class java.awt.image.ColorModel
coerceData , equals , finalize , getAlpha , getAlphaRaster , getBlue , getColorSpace , getComponentSize , getDataElement , getGreen , getNormalizedComponents , getNumColorComponents , getNumComponents , getPixelSize , getRed , getRGB , getRGBdefault , getUnnormalizedComponents , hasAlpha , isAlphaPremultiplied
 
Methods inherited from class java.lang.Object
clone , getClass , hashCode , notify , notifyAll , wait , wait , wait
 

Constructor Detail

IndexColorModel

public IndexColorModel(int bits,
                       int size,
                       byte[] r,
                       byte[] g,
                       byte[] b)
Constructs an IndexColorModel from the given arrays of red, green, and blue components. Pixels described by this color model will all have alpha components of 255 unnormalized (1.0 normalized), i.e. fully opaque. All of the arrays specifying the color components must have at least the specified number of entries. The ColorSpace will be the default sRGB space. The transparency value will be Transparency.OPAQUE. The transfer type will be 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 each pixel occupies.
size - The size of the color component arrays.
r - The array of red color components.
g - The array of green color components.
b - The array of blue color components.

IndexColorModel

public 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. Pixels described by this color model will all have alpha components of 255 unnormalized (1.0 normalized), i.e. fully opaque, except for the indicated transparent pixel. All of the arrays specifying the color components must have at least the specified number of entries. The ColorSpace will be the default sRGB space. The transparency value will be Transparency.BITMASK. The transfer type will be 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 each pixel occupies.
size - The size of the color component arrays.
r - The array of red color components.
g - The array of green color components.
b - The array of blue color components.
trans - The index of the transparent pixel.

IndexColorModel

public 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. All of the arrays specifying the components must have at least the specified number of entries. The ColorSpace will be the default sRGB space. The transparency value will be Transparency.TRANSLUCENT. The transfer type will be 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 each pixel occupies.
size - The size of the color component arrays.
r - The array of red color components.
g - The array of green color components.
b - The array of blue color components.
a - The array of alpha value components.

IndexColorModel

public 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. The array must have enough values in it to fill all of the needed component arrays of the specified size. The ColorSpace will be the default sRGB space. The transparency value will be Transparency.TRANSLUCENT if hasAlpha is true, Transparency.OPAQUE otherwise. The transfer type will be the smallest of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT that can hold a single pixel. sRGB ColorSpace.
Parameters:
bits - The number of bits each pixel occupies.
size - The size of the color component arrays.
cmap - The array of color components.
start - The starting offset of the first color component.
hasalpha - Indicates whether alpha values are contained in the cmap array.

IndexColorModel

public 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. The specified transparent index represents a pixel that will be considered entirely transparent regardless of any alpha value specified for it. The array must have enough values in it to fill all of the needed component arrays of the specified size. The ColorSpace will be the default sRGB space. The transparency value will be Transparency.TRANSLUCENT if hasAlpha is true; otherwise it will be Transparency.BITMASK if trans is a valid index into the colormap (between 0 and size - 1) or Transparency.OPAQUE if trans is not a valid index. The transfer type will be 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 each pixel occupies.
size - The size of the color component arrays.
cmap - The array of color components.
start - The starting offset of the first color component.
hasalpha - Indicates whether alpha values are contained in the cmap array.
trans - The index of the fully transparent pixel.

IndexColorModel

public 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. The specified transparent index represents a pixel that will be considered entirely transparent regardless of any alpha value specified for it. The array must have enough values in it to fill all of the needed component arrays of the specified size. The ColorSpace will be the default sRGB space. The transparency value will be Transparency.TRANSLUCENT if hasAlpha is true; otherwise it will be Transparency.BITMASK if trans is a valid index into the colormap (between 0 and size - 1) or Transparency.OPAQUE if trans is not a valid index. The transfer type will be 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 each pixel occupies.
size - The size of the color component arrays.
cmap - The array of color components.
start - The starting offset of the first color component.
hasalpha - Indicates whether alpha values are contained in the cmap array.
trans - The index of the fully transparent pixel.
Method Detail

getTransparency

public int getTransparency()
Returns the transparency. Returns either OPAQUE, BITMASK, or TRANSLUCENT
Overrides:
getTransparency in class ColorModel
See Also:
Transparency.OPAQUE, Transparency.BITMASK, Transparency.TRANSLUCENT

getComponentSize

public int[] getComponentSize()
Returns an array of the number of bits per color/alpha component. The array contains the color components in the order red, green, blue, followed by the alpha component, if present.
Overrides:
getComponentSize in class ColorModel

getMapSize

public final int getMapSize()
Returns the size of the color/alpha component arrays in this IndexColorModel.

getTransparentPixel

public final int getTransparentPixel()
Returns the index of the transparent pixel in this IndexColorModel or -1 if there is no transparent pixel.

getReds

public final void getReds(byte[] r)
Copies the array of red color components into the given array. Only the initial entries of the array as specified by getMapSize() are written.

getGreens

public final void getGreens(byte[] g)
Copies the array of green color components into the given array. Only the initial entries of the array as specified by getMapSize() are written.

getBlues

public final void getBlues(byte[] b)
Copies the array of blue color components into the given array. Only the initial entries of the array as specified by getMapSize() will be written.

getAlphas

public final void getAlphas(byte[] a)
Copies the array of alpha transparency components into the given array. Only the initial entries of the array as specified by getMapSize() will be written.

getRGBs

public final 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 given array. Only the initial entries of the array as specified by getMapSize() will be written.

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 ColorSpace, sRGB. The pixel value is specified as an int. The returned value will be a non pre-multiplied value.
Overrides:
getRed in class ColorModel

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 ColorSpace, sRGB. The pixel value is specified as an int. The returned value will be a non pre-multiplied value.
Overrides:
getGreen in class ColorModel

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 ColorSpace, sRGB. The pixel value is specified as an int. The returned value will be a non pre-multiplied value.
Overrides:
getBlue in class ColorModel

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

getRGB

public final int getRGB(int pixel)
Returns the color/alpha components of the pixel in the default RGB color model format. The pixel value is specified as an int. The returned value will be in a non pre-multiplied format.
Overrides:
getRGB in class ColorModel
See Also:
ColorModel.getRGBdefault()

getDataElements

public 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. This array can then be passed to the setDataElements method of a WritableRaster object. If the pixel variable is null, a new array will be 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 will be returned.
Overrides:
getDataElements in class ColorModel
See Also:
WritableRaster.setDataElements(int, int, java.lang.Object), SampleModel.setDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)

getComponents

public int[] getComponents(int pixel,
                           int[] components,
                           int offset)
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 will be allocated. The components array will be 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).
Overrides:
getComponents in class ColorModel

getComponents

public int[] getComponents(Object pixel,
                           int[] components,
                           int offset)
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 will be allocated. The components array will be 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).
Overrides:
getComponents in class ColorModel

setDataElement

public int setDataElement(int[] components,
                          int offset)
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).

setDataElements

public Object setDataElements(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. 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 pixel variable is null, a new array will be 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.
Overrides:
setDataElements in class ColorModel
See Also:
WritableRaster.setDataElements(int, int, java.lang.Object), SampleModel.setDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)

createCompatibleWritableRaster

public 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.
Overrides:
createCompatibleWritableRaster in class ColorModel
See Also:
WritableRaster, SampleModel

isCompatibleRaster

public boolean isCompatibleRaster(Raster raster)
Returns true if raster is compatible with this ColorModel and false if it is not.
Overrides:
isCompatibleRaster in class ColorModel

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

convertToIntDiscrete

public BufferedImage convertToIntDiscrete(Raster raster,
                                          boolean forceARGB)
Returns a new BufferedImage of TYPE_INT_ARGB or TYPE_INT_RGB which has a Raster with pixel data computed by expanding the indices in the source Raster using the color/alpha component arrays of this ColorModel. If forceARGB is true, a TYPE_INT_ARGB image is returned regardless of whether this ColorModel has an alpha component array or a transparent pixel.

toString

public String toString()
Prints the contents of this object
Overrides:
toString in class ColorModel

Java Platform 1.2
Beta 4

Submit a bug or feature
Submit comments/suggestions about new javadoc look
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.
This documentation was generated with a post-Beta4 version of Javadoc.