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 represents pixel values which are
indices into a fixed colormap in the ColorModel's color space.
An optional transparent
pixel value can be supplied which indicates a completely transparent
pixel, regardless of any alpha value recorded for that pixel value.
This color model is similar to an X11 PseudoColor visual. Note
that alpha values in IndexColorModels are never premultiplied.
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
Constructor Summary
|
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[] 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,
byte[] a)
Constructs an IndexColorModel from the given arrays of red,
green, blue and alpha components.
|
IndexColorModel(int bits,
int size,
byte[] cmap,
int start,
boolean hasalpha)
Constructs an IndexColorModel from a single array of packed
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 packed
red, green, blue and optional alpha components.
|
IndexColorModel(int bits,
int size,
int[] cmap,
int start,
boolean hasalpha,
int trans,
boolean isAlphaPremultiplied)
Constructs an IndexColorModel from an array of integers
where each integer is comprised of
red, green, blue, and optional alpha components in the default
RGB color model packing.
|
Method Summary
|
ColorModel
|
coerceData(WritableRaster raster,
boolean isAlphaPremultiplied)
Forces the Raster data to match the state specified in the
isAlphaPremultiplied variable, assuming the data is currently
correctly described by this ColorModel.
|
BufferedImage
|
convertToIntDiscrete(Raster raster,
boolean forceARGB)
Returns a new BufferedImage of TYPE_INT_ARGB or TYPE_INT_RGB that
matches the lookup tables.
|
WritableRaster
|
createCompatibleWritableRaster(int w,
int h)
Creates a WritableRaster with the specified width and height, that
has a channel layout compatible with this ColorModel.
|
int
|
getAlpha(int pixel)
Return the alpha transparency value for the specified pixel in the
range 0-255.
|
void
|
getAlphas(byte[] a)
Copies the array of alpha transparency values into the given array.
|
int
|
getBlue(int pixel)
Returns the blue color component for the specified pixel in the
range 0-255 in the default RGB ColorSpace, sRGB.
|
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 all of the components given a pixel
in the current color model.
|
int[]
|
getComponents(Object inPixel,
int[] components,
int offset)
Returns an array of all of the components given a pixel array
in the current color model.
|
int[]
|
getComponentSize()
Returns an array of the number of bits per component.
|
int
|
getGreen(int pixel)
Returns the green color component for the specified pixel in the
range 0-255 in the default RGB ColorSpace, sRGB.
|
void
|
getGreens(byte[] g)
Copies the array of green color components into the given array.
|
int
|
getMapSize()
Returns the size of the color component arrays in this
IndexColorModel.
|
Object
|
getPixelData(int rgb,
Object pixel)
Returns a pixel array given a pixel in the default RGB color model.
|
int
|
getRed(int pixel)
Returns the red color component for the specified pixel in the
range 0-255 in the default RGB ColorSpace, sRGB.
|
void
|
getReds(byte[] r)
Copies the array of red color components into the given array.
|
int
|
getRGB(int pixel)
Returns the color of the pixel in the default RGB color model.
|
void
|
getRGBs(int[] rgb)
Converts the arrays color and alpha components to the default
RGB ColorModel (if necessary) and copies the resulting array
of 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.
|
int
|
setComponents(int[] components,
int offset)
Returns a pixel, given a discrete components (unpacked color/alpha
values) in this color model.
|
Object
|
setComponents(int[] components,
int offset,
Object pixel)
Returns a pixel array, given a discrete components (unpacked
color/alpha values) in this color model.
|
Methods inherited from class java.awt.image.ColorModel
|
coerceData, createCompatibleWritableRaster, equals, finalize, getAlpha, getAlpha, getBlue, getBlue, getColorSpace, getComponents, getComponents, getComponents, getComponentSize, getComponentSize, getGreen, getGreen, getMaxComponentSize, getNormalizedComponents, getNumColorComponents, getNumComponents, getPixelData, getPixelSize, getRed, getRed, getRGB, getRGB, getRGBdefault, getTransparency, hasAlpha, isAlphaPremultiplied, isCompatibleRaster, setComponents, setComponents, toString |
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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 (fully opaque).
All of the arrays specifying the color components must have
at least the specified number of entries. Uses the default
sRGB ColorSpace.
- 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 (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. Uses the default sRGB ColorSpace.
- 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 color components must have at least the specified number
of entries. Uses the default sRGB ColorSpace.
- 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 packed
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. Uses the default
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 packed
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.
Uses the default 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.
trans
- The index of the fully transparent pixel.
IndexColorModel
public IndexColorModel(int bits,
int size,
int[] cmap,
int start,
boolean hasalpha,
int trans,
boolean isAlphaPremultiplied)
- Constructs an IndexColorModel from an array of integers
where each integer is comprised of
red, green, blue, and optional alpha components in the default
RGB color model packing.
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.
Uses the default 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.
trans
- The index of the fully transparent pixel.
isAlphaPremultiplied
- Specifies how to interpret the color
data that are passed to this ColorModel. If true, the data will
have been multiplied with alpha.
getTransparency
public int getTransparency()
- Returns the transparency. Returns either OPAQUE, BITMASK,
or TRANSLUCENT
- Overrides:
- getTransparency in class ColorModel
- See Also:
- OPAQUE, BITMASK, TRANSLUCENT
getComponentSize
public int[] getComponentSize()
- Returns an array of the number of bits per component.
- Overrides:
- getComponentSize in class ColorModel
getMapSize
public final int getMapSize()
- Returns the size of the color 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. If the color space is not sRGB, then the entries are
converted to sRGB and the red components are extracted.
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. If the color space is not sRGB, then the entries are
converted to sRGB and the green components are extracted.
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. If the color space is not sRGB, then the entries are
converted to sRGB and the green components are extracted.
getAlphas
public final void getAlphas(byte[] a)
- Copies the array of alpha transparency values 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 the arrays color and alpha components to the default
RGB ColorModel (if necessary) and copies the resulting array
of 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 in the
range 0-255 in the default RGB ColorSpace, sRGB.
The returned value will be a
non pre-multiplied color (i.e. if the alpha is premultiplied,
this method will divide it out before it is returned). If the
alpha value is 0, the color will be 0.
- Overrides:
- getRed in class ColorModel
getGreen
public final int getGreen(int pixel)
- Returns the green color component for the specified pixel in the
range 0-255 in the default RGB ColorSpace, sRGB. The
returned value will be a
non pre-multiplied color (i.e. if the alpha is premultiplied,
this method will divide it out before it is returned). If the
alpha value is 0, the color will be 0.
- Overrides:
- getGreen in class ColorModel
getBlue
public final int getBlue(int pixel)
- Returns the blue color component for the specified pixel in the
range 0-255 in the default RGB ColorSpace, sRGB. The
returned value will be a
non pre-multiplied color (i.e. if the alpha is premultiplied,
this method will divide it out before it is returned). If the
alpha value is 0, the color will be 0.
- Overrides:
- getBlue in class ColorModel
getAlpha
public final int getAlpha(int pixel)
- Return the alpha transparency value for the specified pixel in the
range 0-255.
- Overrides:
- getAlpha in class ColorModel
getRGB
public final int getRGB(int pixel)
- Returns the color of the pixel in the default RGB color model.
If the ColorSpace is not sRGB, it will be converted to sRGB.
- Overrides:
- getRGB in class ColorModel
- See Also:
- getRGBdefault
getPixelData
public Object getPixelData(int rgb,
Object pixel)
- Returns a pixel array given a pixel in the default RGB color model.
The pixel is
described by a discrete array of data elements of type
transferType passed in as an object reference.
This pixel array can then be passed to the setPixelData method of
a WritableRaster object. If the pixel variable is null, a new
array will be allocated. The pixel array will be returned.
- Overrides:
- getPixelData in class ColorModel
getComponents
public int[] getComponents(int pixel,
int[] components,
int offset)
- Returns an array of all of the components given a pixel
in the current color model.
This can be used to retrieve the
components for a specific pixel. If the
components array is null, a new array will be allocated. The
components array will be returned.
- Overrides:
- getComponents in class ColorModel
getComponents
public int[] getComponents(Object inPixel,
int[] components,
int offset)
- Returns an array of all of the components given a pixel array
in the current color model. The pixel is
described by a discrete array of data elements of type
transferType passed in as an object reference.
This can be used to retrieve the
components for a specific pixel in a PackedColorModel. If the
components array is null, a new array will be allocated. The
components array will be returned.
- Overrides:
- getComponents in class ColorModel
setComponents
public int setComponents(int[] components,
int offset)
- Returns a pixel, given a discrete components (unpacked color/alpha
values) in this color model.
- Overrides:
- setComponents in class ColorModel
setComponents
public Object setComponents(int[] components,
int offset,
Object pixel)
- Returns a pixel array, given a discrete components (unpacked
color/alpha values) in this color model. The pixel is
described by a discrete array of data elements of type
transferType passed in as an object reference.
This array can be passed to the setPixelData methods of Raster.
objects.
- Overrides:
- setComponents in class ColorModel
createCompatibleWritableRaster
public WritableRaster createCompatibleWritableRaster(int w,
int h)
- Creates a WritableRaster with the specified width and height, that
has a channel layout compatible with this ColorModel.
- Overrides:
- createCompatibleWritableRaster in class ColorModel
- See Also:
- WritableRaster
coerceData
public ColorModel coerceData(WritableRaster raster,
boolean isAlphaPremultiplied)
- Forces the Raster data to match the state specified in the
isAlphaPremultiplied variable, assuming the data is currently
correctly described by this ColorModel. It may multiply or divide
the color Raster data by alpha, or do nothing if the data is
in the correct state. If the data needs to be coerced, this
method will also return an instance of this ColorModel with
the isAlphaPremultiplied flag set appropriately.
- Overrides:
- coerceData in class ColorModel
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
convertToIntDiscrete
public BufferedImage convertToIntDiscrete(Raster raster,
boolean forceARGB)
- Returns a new BufferedImage of TYPE_INT_ARGB or TYPE_INT_RGB that
matches the lookup tables.
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.