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

public Class IndexColorModel

extends ColorModel
Class Inheritance
Imports
java.awt.Transparency, java.awt.color.ColorSpace, java.math.BigInteger, java.util.Arrays

The IndexColorModel class is a ColorModel class that works with pixel values consisting of a single sample that is an index into a fixed colormap in the default sRGB color space. 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. Some constructors allow the caller to specify "holes" in the colormap by indicating which colormap entries are valid and which represent unusable colors via the bits set in a BigInteger object. This color model is similar to an X11 PseudoColor visual.

Some constructors provide a means to specify an alpha component for each pixel in the colormap, while others either provide no such means or, in some cases, a flag to indicate whether the colormap data contains alpha values. If no alpha is supplied to the constructor, an opaque alpha component (alpha = 1.0) is assumed for each entry. An optional transparent pixel value can be supplied that indicates a pixel to be made completely transparent, regardless of any alpha component supplied or assumed for that pixel value. Note that the color components in the colormap of an IndexColorModel objects are never pre-multiplied with the alpha components.

The transparency of an IndexColorModel object is determined by examining the alpha components of the colors in the colormap and choosing the most specific value after considering the optional alpha values and any transparent index specified. The transparency value is Transparency.OPAQUE only if all valid colors in the colormap are opaque and there is no valid transparent pixel. If all valid colors in the colormap are either completely opaque (alpha = 1.0) or completely transparent (alpha = 0.0), which typically occurs when a valid transparent pixel is specified, the value is Transparency.BITMASK. Otherwise, the value is Transparency.TRANSLUCENT, indicating that some valid color has an alpha component that is neither completely transparent nor completely opaque (0.0 < alpha < 1.0).

If an IndexColorModel object has a transparency value of Transparency.OPAQUE, then the hasAlpha and getNumComponents methods (both inherited from ColorModel) return false and 3, respectively. For any other transparency value, hasAlpha returns true and getNumComponents returns 4.

The values used to index into the colormap are taken from the least significant n bits of pixel representations where n is based on the pixel size specified in the constructor. For pixel sizes smaller than 8 bits, n is rounded up to a power of two (3 becomes 4 and 5,6,7 become 8). For pixel sizes between 8 and 16 bits, n is equal to the pixel size. Pixel sizes larger than 16 bits are not supported by this class. Higher order bits beyond n are ignored in pixel representations. Index values greater than or equal to the map size, but less than 2n, are undefined and return 0 for all color and alpha components.

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 reasons, but you cannot override or modify the behaviour of those methods.

See Also
ColorModel, ColorSpace, DataBuffer

Field Summary

Modifier and TypeField and Description
private boolean
private static int[]
private static final int
private BufImgSurfaceData.ICMColorData
private volatile int
private int[]
private int
private static int[]
private int
private int[]
private int
private BigInteger
Inherited from java.awt.image.ColorModel:
colorSpacecolorSpaceTypeg16Tos8Mapg8Tos8Mapis_sRGBisAlphaPremultipliedl16Tos8l8Tos8lg16Toog16Maplg16Toog8MapmaxBitsnBitsnumColorComponentsnumComponentspixel_bitss8Tol16s8Tol8supportsAlphatransferTypetransparency

Constructor Summary

AccessConstructor and Description
public
IndexColorModel(int
the number of bits each pixel occupies
bits
,
int
the size of the color component arrays
size
,
byte[]
the array of red color components
r
,
byte[]
the array of green color components
g
,
byte[]
the array of blue color components
b
)

Constructs an IndexColorModel from the specified arrays of red, green, and blue components.

public
IndexColorModel(int
the number of bits each pixel occupies
bits
,
int
the size of the color component arrays
size
,
byte[]
the array of red color components
r
,
byte[]
the array of green color components
g
,
byte[]
the array of blue color components
b
,
int
the index of the transparent pixel
trans
)

Constructs an IndexColorModel from the given arrays of red, green, and blue components.

public
IndexColorModel(int
the number of bits each pixel occupies
bits
,
int
the size of the color component arrays
size
,
byte[]
the array of red color components
r
,
byte[]
the array of green color components
g
,
byte[]
the array of blue color components
b
,
byte[]
the array of alpha value components
a
)

Constructs an IndexColorModel from the given arrays of red, green, blue and alpha components.

public
IndexColorModel(int
the number of bits each pixel occupies
bits
,
int
the size of the color component arrays
size
,
byte[]
the array of color components
cmap
,
int
the starting offset of the first color component
start
,
boolean
indicates whether alpha values are contained in the cmap array
hasalpha
)

Constructs an IndexColorModel from a single array of interleaved red, green, blue and optional alpha components.

public
IndexColorModel(int
the number of bits each pixel occupies
bits
,
int
the size of the color component arrays
size
,
byte[]
the array of color components
cmap
,
int
the starting offset of the first color component
start
,
boolean
indicates whether alpha values are contained in the cmap array
hasalpha
,
int
the index of the fully transparent pixel
trans
)

Constructs an IndexColorModel from a single array of interleaved red, green, blue and optional alpha components.

public
IndexColorModel(int
the number of bits each pixel occupies
bits
,
int
the size of the color component arrays
size
,
int[]
the array of color components
cmap
,
int
the starting offset of the first color component
start
,
boolean
indicates whether alpha values are contained in the cmap array
hasalpha
,
int
the index of the fully transparent pixel
trans
,
int
the data type of the array used to represent pixel values. The data type must be either DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT.
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.

public
IndexColorModel(int
the number of bits each pixel occupies
bits
,
int
the size of the color component array
size
,
int[]
the array of color components
cmap
,
int
the starting offset of the first color component
start
,
int
the specified data type
transferType
,
BigInteger
a BigInteger object. If a bit is set in the BigInteger, the pixel at that index is valid. If a bit is not set, the pixel at that index is considered invalid. If null, all pixels are valid. Only bits from 0 to the map size are considered.
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

Modifier and TypeMethod and Description
private int
calcRealMapSize(int bits, int size)

private void
calculatePixelMask()

This method is called from the constructors to set the pixel_mask value, which is based on the value of pixel_bits.

public BufferedImage

Returns:

a BufferedImage created with the specified Raster
convertToIntDiscrete
(Raster
the specified Raster
raster
,
boolean
if true, the returned BufferedImage is TYPE_INT_ARGB; otherwise it is TYPE_INT_RGB
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.

public SampleModel

Returns:

a SampleModel object with the specified width and height.
createCompatibleSampleModel
(int
the width to apply to the new SampleModel
w
,
int
the height to apply to the new SampleModel
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.

public 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 boolean

Returns:

true if the specified Object equals this IndexColorModel; 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 IndexColorModel and if it equals this IndexColorModel

private BigInteger
public final int

Returns:

the value of the alpha component for the specified pixel
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 final void
getAlphas(byte[]
the specified array into which the elements of the array of alpha components are copied
a
)

Copies the array of alpha transparency components into the specified array.

public final int

Returns:

the value of the blue color component for the specified pixel
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 final void
getBlues(byte[]
the specified array into which the elements of the array of blue color components are copied
b
)

Copies the array of blue color components into the specified array.

public 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 for a specified pixel in this ColorModel.

public 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[]
an array that receives the color and alpha components of the specified pixel
components
,
int
the index into the components array at which to begin storing the color and alpha components of the specified pixel
offset
)

Overrides java.awt.image.ColorModel.getComponents.

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

public int[]

Returns:

an array containing the number of bits of each color and alpha component of this IndexColorModel
getComponentSize
()

Overrides java.awt.image.ColorModel.getComponentSize.

Returns an array of the number of bits for each color/alpha component.

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 synchronized Object

Returns:

an array representation of the specified pixel in this IndexColorModel.
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
pixel
)

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.

public final int

Returns:

the value of the green color component for the specified pixel
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 final void
getGreens(byte[]
the specified array into which the elements of the array of green color components are copied
g
)

Copies the array of green color components into the specified array.

public final int

Returns:

the size of the color and alpha component arrays.
getMapSize
()

Returns the size of the color/alpha component arrays in this IndexColorModel.

public final int

Returns:

the value of the red color component for the specified pixel
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 final void
getReds(byte[]
the specified array into which the elements of the array of red color components are copied
r
)

Copies the array of red color components into the specified array.

public final int

Returns:

the color and 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 final void
getRGBs(int[]
the specified array into which the converted ARGB values from this array of color and alpha components are copied.
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.

public int

Returns:

the transparency of this IndexColorModel
getTransparency
()

Overrides java.awt.image.ColorModel.getTransparency.

Implements java.awt.Transparency.getTransparency.

Returns the transparency.

public final int

Returns:

the index of a transparent pixel in this IndexColorModel object, or -1 if there is no such pixel
getTransparentPixel
()

Returns the index of a transparent pixel in this IndexColorModel or -1 if there is no pixel with an alpha value of 0.

public BigInteger

Returns:

a BigInteger indicating the valid/invalid pixels.
getValidPixels
()

Returns a BigInteger that indicates the valid/invalid pixels in the colormap.

public int

Returns:

a hash code for IndexColorModel
hashCode
()

Overrides java.awt.image.ColorModel.hashCode.

Returns the hash code for IndexColorModel.

private static native void
private Object
installpixel(Object pixel, int pix)

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 or false if it is not compatible with this ColorModel.

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.

public boolean

Returns:

true if pixel is valid; false otherwise.
isValid
(int
the specified pixel value
pixel
)

Returns whether or not the pixel is valid.

public boolean

Returns:

true if all pixels are valid; false otherwise.
isValid
()

Returns whether or not all of the pixels are valid.

private void
setRGBs(int size, byte[] r, byte[] g, byte[] b, byte[] a)

private void
setRGBs(int size, int[] cmap, int start, boolean hasalpha)

private void
setTransparency(int transparency)

private void
public String

Returns:

a String representing the contents of this ColorModel object.
toString
()

Overrides java.awt.image.ColorModel.toString.

Returns the String representation of the contents of this ColorModel object.

Inherited from java.awt.image.ColorModel:
coerceDatagetAlphagetAlphaRastergetBluegetColorSpacegetComponentSizegetDataElementgetDataElementsgetDefaultTransferTypegetGray16TosRGB8LUTgetGray8TosRGB8LUTgetGreengetLinearGray16ToOtherGray16LUTgetLinearGray16ToOtherGray8LUTgetLinearRGB16TosRGB8LUTgetLinearRGB8TosRGB8LUTgetNormalizedComponentsgetNormalizedComponentsgetNumColorComponentsgetNumComponentsgetPixelSizegetRedgetRGBgetRGBdefaultgetsRGB8ToLinearRGB16LUTgetsRGB8ToLinearRGB8LUTgetTransferTypegetUnnormalizedComponentshasAlphaisAlphaPremultipliedisLinearGRAYspaceisLinearRGBspaceloadLibraries

Field Detail

allgrayopaqueback to summary
private boolean allgrayopaque
alphaBitsback to summary
private static int[] alphaBits
CACHESIZEback to summary
private static final int CACHESIZE
colorDataback to summary
private BufImgSurfaceData.ICMColorData colorData
hashCodeback to summary
private volatile int hashCode
lookupcacheback to summary
private int[] lookupcache
map_sizeback to summary
private int map_size
opaqueBitsback to summary
private static int[] opaqueBits
pixel_maskback to summary
private int pixel_mask
rgbback to summary
private int[] rgb
transparent_indexback to summary
private int transparent_index
validBitsback to summary
private BigInteger validBits

Constructor Detail

IndexColorModelback to summary
public IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b)

Constructs an IndexColorModel from the specified arrays of red, green, and blue components. Pixels described by this color model all have alpha components of 255 unnormalized (1.0 normalized), which means they are fully opaque. All of the arrays specifying the color components must have at least the specified number of entries. The ColorSpace is the default sRGB space. Since there is no alpha information in any of the arguments to this constructor, the transparency value is always Transparency.OPAQUE. The transfer type is the smallest of DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT that can hold a single pixel.

Parameters
bits:int

the number of bits each pixel occupies

size:int

the size of the color component arrays

r:byte[]

the array of red color components

g:byte[]

the array of green color components

b:byte[]

the array of blue color components

Exceptions
IllegalArgumentException:
  • if bits is less than 1 or greater than 16
  • if size is less than 1
IndexColorModelback to summary
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 all have alpha components of 255 unnormalized (1.0 normalized), which means they are fully opaque, except for the indicated pixel to be made transparent. All of the arrays specifying the color components must have at least the specified number of entries. The ColorSpace is the default sRGB space. The transparency value may be Transparency.OPAQUE or Transparency.BITMASK depending on the arguments, as specified in the class description above. The transfer type is the smallest of DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT that can hold a single pixel.

Parameters
bits:int

the number of bits each pixel occupies

size:int

the size of the color component arrays

r:byte[]

the array of red color components

g:byte[]

the array of green color components

b:byte[]

the array of blue color components

trans:int

the index of the transparent pixel

Exceptions
IllegalArgumentException:
  • if bits is less than 1 or greater than 16
  • if size is less than 1
IndexColorModelback to summary
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 is the default sRGB space. The transparency value may be any of Transparency.OPAQUE, Transparency.BITMASK, or Transparency.TRANSLUCENT depending on the arguments, as specified in the class description above. The transfer type is the smallest of DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT that can hold a single pixel.

Parameters
bits:int

the number of bits each pixel occupies

size:int

the size of the color component arrays

r:byte[]

the array of red color components

g:byte[]

the array of green color components

b:byte[]

the array of blue color components

a:byte[]

the array of alpha value components

Exceptions
IllegalArgumentException:
  • if bits is less than 1 or greater than 16
  • if size is less than 1
IndexColorModelback to summary
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 is the default sRGB space. The transparency value may be any of Transparency.OPAQUE, Transparency.BITMASK, or Transparency.TRANSLUCENT depending on the arguments, as specified in the class description above. The transfer type is the smallest of DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT that can hold a single pixel.

Parameters
bits:int

the number of bits each pixel occupies

size:int

the size of the color component arrays

cmap:byte[]

the array of color components

start:int

the starting offset of the first color component

hasalpha:boolean

indicates whether alpha values are contained in the cmap array

Exceptions
IllegalArgumentException:
  • if bits is less than 1 or greater than 16
  • if size is less than 1
IndexColorModelback to summary
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 is made 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 is the default sRGB space. The transparency value may be any of Transparency.OPAQUE, Transparency.BITMASK, or Transparency.TRANSLUCENT depending on the arguments, as specified in the class description above. The transfer type is the smallest of DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT that can hold a single pixel.

Parameters
bits:int

the number of bits each pixel occupies

size:int

the size of the color component arrays

cmap:byte[]

the array of color components

start:int

the starting offset of the first color component

hasalpha:boolean

indicates whether alpha values are contained in the cmap array

trans:int

the index of the fully transparent pixel

Exceptions
IllegalArgumentException:
  • if bits is less than 1 or greater than 16
  • if size is less than 1
IndexColorModelback to summary
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 is made 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 is the default sRGB space. The transparency value may be any of Transparency.OPAQUE, Transparency.BITMASK, or Transparency.TRANSLUCENT depending on the arguments, as specified in the class description above.

Parameters
bits:int

the number of bits each pixel occupies

size:int

the size of the color component arrays

cmap:int[]

the array of color components

start:int

the starting offset of the first color component

hasalpha:boolean

indicates whether alpha values are contained in the cmap array

trans:int

the index of the fully transparent pixel

transferType:int

the data type of the array used to represent pixel values. The data type must be either DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT.

Exceptions
IllegalArgumentException:
  • if bits is less than 1 or greater than 16
  • if size is less than 1
  • if transferType is not one of DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT
IndexColorModelback to summary
public 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. The array must have enough values in it to fill all of the needed component arrays of the specified size. The ColorSpace is the default sRGB space. The transparency value may be any of Transparency.OPAQUE, Transparency.BITMASK, or Transparency.TRANSLUCENT depending on the arguments, as specified in the class description above. The transfer type must be one of DataBuffer.TYPE_BYTE DataBuffer.TYPE_USHORT. The BigInteger object specifies the valid/invalid pixels in the cmap array. A pixel is valid if the BigInteger value at that index is set, and is invalid if the BigInteger bit at that index is not set.

Parameters
bits:int

the number of bits each pixel occupies

size:int

the size of the color component array

cmap:int[]

the array of color components

start:int

the starting offset of the first color component

transferType:int

the specified data type

validBits:BigInteger

a BigInteger object. If a bit is set in the BigInteger, the pixel at that index is valid. If a bit is not set, the pixel at that index is considered invalid. If null, all pixels are valid. Only bits from 0 to the map size are considered.

Exceptions
IllegalArgumentException:
  • if bits is less than 1 or greater than 16
  • if size is less than 1
  • if transferType is not one of DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT
Since
1.3

Method Detail

calcRealMapSizeback to summary
private int calcRealMapSize(int bits, int size)
calculatePixelMaskback to summary
private void calculatePixelMask()

This method is called from the constructors to set the pixel_mask value, which is based on the value of pixel_bits. The pixel_mask value is used to mask off the pixel parameters for methods such as getRed(), getGreen(), getBlue(), getAlpha(), and getRGB().

convertToIntDiscreteback to summary
public 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. Only the lower n bits of each index value in the source Raster, as specified in the class description above, are used to compute the color/alpha values in the returned image. If forceARGB is true, a TYPE_INT_ARGB image is returned regardless of whether or not this ColorModel has an alpha component array or a transparent pixel.

Parameters
raster:Raster

the specified Raster

forceARGB:boolean

if true, the returned BufferedImage is TYPE_INT_ARGB; otherwise it is TYPE_INT_RGB

Returns:BufferedImage

a BufferedImage created with the specified Raster

Exceptions
IllegalArgumentException:
if the raster argument is not compatible with this IndexColorModel
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 to apply to the new SampleModel

h:int

the height to apply to the new SampleModel

Returns:SampleModel

a SampleModel object with the specified width and height.

Exceptions
IllegalArgumentException:
if w or h is not greater than 0
See Also
SampleModel
createCompatibleWritableRasterback to summary
public 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. This method only works for color models with 16 or fewer bits per pixel.

Since IndexColorModel can be subclassed, any subclass that supports greater than 16 bits per pixel must override this method.

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
UnsupportedOperationException:
if the number of bits in a pixel is greater than 16
See Also
WritableRaster, SampleModel
equalsback to summary
public boolean equals(Object obj)

Overrides java.awt.image.ColorModel.equals.

Tests if the specified Object is an instance of IndexColorModel and if it equals this IndexColorModel

Parameters
obj:Object

the Object to test for equality

Returns:boolean

true if the specified Object equals this IndexColorModel; false otherwise.

Annotations
@Override
getAllValidback to summary
private BigInteger getAllValid()
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. Only the lower n bits of the pixel value, as specified in the class description above, are used to calculate the returned value.

Parameters
pixel:int

the specified pixel

Returns:int

the value of the alpha component for the specified pixel

getAlphasback to summary
public final void getAlphas(byte[] a)

Copies the array of alpha transparency components into the specified array. Only the initial entries of the array as specified by getMapSize are written.

Parameters
a:byte[]

the specified array into which the elements of the array of alpha components are copied

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. The pixel value is specified as an int. Only the lower n bits of the pixel value, as specified in the class description above, are used to calculate the returned value. The returned value is a non pre-multiplied value.

Parameters
pixel:int

the specified pixel

Returns:int

the value of the blue color component for the specified pixel

getBluesback to summary
public final void getBlues(byte[] b)

Copies the array of blue color components into the specified array. Only the initial entries of the array as specified by getMapSize are written.

Parameters
b:byte[]

the specified array into which the elements of the array of blue color components are copied

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

Overrides java.awt.image.ColorModel.getComponents.

Returns an array of unnormalized color/alpha components for a specified pixel in this ColorModel. The pixel value is specified as an int. If the components array is null, a new array is allocated that contains offset + getNumComponents() elements. The components array is returned, with the alpha component included only if hasAlpha returns true. 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.

See Also
ColorModel#hasAlpha, ColorModel#getNumComponents
getComponentsback to summary
public int[] getComponents(Object pixel, int[] components, int offset)

Overrides java.awt.image.ColorModel.getComponents.

Returns an array of unnormalized color/alpha components for a specified 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 that contains offset + getNumComponents() elements. The components array is returned, with the alpha component included only if hasAlpha returns true. Color/alpha components are stored in the components array starting at offset even if the array is allocated by this method. An ArrayIndexOutOfBoundsException is also 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 IndexColorModel 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[]

an array that receives the color and alpha components of the specified pixel

offset:int

the index into the components array at which to begin storing the color and alpha components of the specified pixel

Returns:int[]

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

Exceptions
ArrayIndexOutOfBoundsException:
if pixel is not large enough to hold a pixel value for this ColorModel or if the components array is not null and is not large enough to hold all the color and alpha components starting at offset
ClassCastException:
if pixel is not a primitive array of type transferType
UnsupportedOperationException:
if transferType is not one of the supported transfer types
See Also
ColorModel#hasAlpha, ColorModel#getNumComponents
getComponentSizeback to summary
public int[] getComponentSize()

Overrides java.awt.image.ColorModel.getComponentSize.

Returns an array of the number of bits for each color/alpha component. The array contains the color components in the order red, green, blue, followed by the alpha component, if present.

Returns:int[]

an array containing the number of bits of each color and alpha component of this IndexColorModel

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 of the color and alpha components starting at offset. 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
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
UnsupportedOperationException:
if transferType is invalid
getDataElementsback to summary
public synchronized 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 IndexColorModel 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 IndexColorModel.

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 transferType is invalid
See Also
WritableRaster#setDataElements, SampleModel#setDataElements
getDataElementsback to summary
public Object getDataElements(int[] components, int offset, Object pixel)

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 of the color and alpha components starting at offset. 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.

Since IndexColorModel 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

pixel: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 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 the components array is not large enough to hold all of the color and alpha components starting at offset
UnsupportedOperationException:
if transferType is not one of the supported transfer types
See Also
WritableRaster#setDataElements, SampleModel#setDataElements
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. The pixel value is specified as an int. Only the lower n bits of the pixel value, as specified in the class description above, are used to calculate the returned value. The returned value is a non pre-multiplied value.

Parameters
pixel:int

the specified pixel

Returns:int

the value of the green color component for the specified pixel

getGreensback to summary
public final void getGreens(byte[] g)

Copies the array of green color components into the specified array. Only the initial entries of the array as specified by getMapSize are written.

Parameters
g:byte[]

the specified array into which the elements of the array of green color components are copied

getMapSizeback to summary
public final int getMapSize()

Returns the size of the color/alpha component arrays in this IndexColorModel.

Returns:int

the size of the color and alpha component arrays.

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. The pixel value is specified as an int. Only the lower n bits of the pixel value, as specified in the class description above, are used to calculate the returned value. The returned value is a non pre-multiplied value.

Parameters
pixel:int

the specified pixel

Returns:int

the value of the red color component for the specified pixel

getRedsback to summary
public final void getReds(byte[] r)

Copies the array of red color components into the specified array. Only the initial entries of the array as specified by getMapSize are written.

Parameters
r:byte[]

the specified array into which the elements of the array of red color components are copied

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. The pixel value is specified as an int. Only the lower n bits of the pixel value, as specified in the class description above, are used to calculate the returned value. The returned value is in a non pre-multiplied format.

Parameters
pixel:int

the specified pixel

Returns:int

the color and alpha components of the specified pixel

See Also
ColorModel#getRGBdefault
getRGBsback to summary
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 specified array. Only the initial entries of the array as specified by getMapSize are written.

Parameters
rgb:int[]

the specified array into which the converted ARGB values from this array of color and alpha components are copied.

getTransparencyback to summary
public int getTransparency()

Overrides java.awt.image.ColorModel.getTransparency.

Implements java.awt.Transparency.getTransparency.

Returns the transparency. Returns either OPAQUE, BITMASK, or TRANSLUCENT

Returns:int

the transparency of this IndexColorModel

See Also
Transparency#OPAQUE, Transparency#BITMASK, Transparency#TRANSLUCENT
getTransparentPixelback to summary
public final int getTransparentPixel()

Returns the index of a transparent pixel in this IndexColorModel or -1 if there is no pixel with an alpha value of 0. If a transparent pixel was explicitly specified in one of the constructors by its index, then that index will be preferred, otherwise, the index of any pixel which happens to be fully transparent may be returned.

Returns:int

the index of a transparent pixel in this IndexColorModel object, or -1 if there is no such pixel

getValidPixelsback to summary
public BigInteger getValidPixels()

Returns a BigInteger that indicates the valid/invalid pixels in the colormap. A bit is valid if the BigInteger value at that index is set, and is invalid if the BigInteger value at that index is not set. The only valid ranges to query in the BigInteger are between 0 and the map size.

Returns:BigInteger

a BigInteger indicating the valid/invalid pixels.

Since
1.3
hashCodeback to summary
public int hashCode()

Overrides java.awt.image.ColorModel.hashCode.

Returns the hash code for IndexColorModel.

Returns:int

a hash code for IndexColorModel

Annotations
@Override
initIDsback to summary
private static native void initIDs()

Hides java.awt.image.ColorModel.initIDs.

installpixelback to summary
private Object installpixel(Object pixel, int pix)
isCompatibleRasterback to summary
public boolean isCompatibleRaster(Raster raster)

Overrides java.awt.image.ColorModel.isCompatibleRaster.

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

Parameters
raster:Raster

the Raster object to test for compatibility

Returns:boolean

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

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
isValidback to summary
public boolean isValid(int pixel)

Returns whether or not the pixel is valid.

Parameters
pixel:int

the specified pixel value

Returns:boolean

true if pixel is valid; false otherwise.

Since
1.3
isValidback to summary
public boolean isValid()

Returns whether or not all of the pixels are valid.

Returns:boolean

true if all pixels are valid; false otherwise.

Since
1.3
setRGBsback to summary
private void setRGBs(int size, byte[] r, byte[] g, byte[] b, byte[] a)
setRGBsback to summary
private void setRGBs(int size, int[] cmap, int start, boolean hasalpha)
setTransparencyback to summary
private void setTransparency(int transparency)
setTransparentPixelback to summary
private void setTransparentPixel(int trans)
toStringback to summary
public String toString()

Overrides java.awt.image.ColorModel.toString.

Returns the String representation of the contents of this ColorModel object.

Returns:String

a String representing the contents of this ColorModel object.