public class IndexColorModel extends ColorModel
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.
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.
ColorModel
,
ColorSpace
,
DataBuffer
pixel_bits, transferType
Constructor and Description |
---|
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. |
Modifier and Type | Method and Description |
---|---|
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[] |
getComponentSize()
Returns an array of the number of bits for each color/alpha component.
|
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 a transparent pixel in this
IndexColorModel or -1 if there is no pixel
with an alpha value of 0. |
String |
toString()
Returns the
String representation of the contents of
this ColorModel object. |
equals, getColorSpace, getComponentSize, getNumColorComponents, getNumComponents, getPixelSize, getRGBdefault, getTransferType, hasAlpha, hashCode, isAlphaPremultiplied
public IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b)
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.bits
- the number of bits each pixel occupiessize
- the size of the color component arraysr
- the array of red color componentsg
- the array of green color componentsb
- the array of blue color componentsIllegalArgumentException
- if bits
is less
than 1 or greater than 16IllegalArgumentException
- if size
is less
than 1public IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b, int trans)
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.bits
- the number of bits each pixel occupiessize
- the size of the color component arraysr
- the array of red color componentsg
- the array of green color componentsb
- the array of blue color componentstrans
- the index of the transparent pixelIllegalArgumentException
- if bits
is less than
1 or greater than 16IllegalArgumentException
- if size
is less than
1public IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b, byte[] a)
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.bits
- the number of bits each pixel occupiessize
- the size of the color component arraysr
- the array of red color componentsg
- the array of green color componentsb
- the array of blue color componentsa
- the array of alpha value componentsIllegalArgumentException
- if bits
is less
than 1 or greater than 16IllegalArgumentException
- if size
is less
than 1public IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasalpha)
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.bits
- the number of bits each pixel occupiessize
- the size of the color component arrayscmap
- the array of color componentsstart
- the starting offset of the first color componenthasalpha
- indicates whether alpha values are contained in
the cmap
arrayIllegalArgumentException
- if bits
is less
than 1 or greater than 16IllegalArgumentException
- if size
is less
than 1public IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasalpha, int trans)
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.bits
- the number of bits each pixel occupiessize
- the size of the color component arrayscmap
- the array of color componentsstart
- the starting offset of the first color componenthasalpha
- indicates whether alpha values are contained in
the cmap
arraytrans
- the index of the fully transparent pixelIllegalArgumentException
- if bits
is less than
1 or greater than 16IllegalArgumentException
- if size
is less than
1public IndexColorModel(int bits, int size, int[] cmap, int start, boolean hasalpha, int trans, int transferType)
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.bits
- the number of bits each pixel occupiessize
- the size of the color component arrayscmap
- the array of color componentsstart
- the starting offset of the first color componenthasalpha
- indicates whether alpha values are contained in
the cmap
arraytrans
- the index of the fully transparent pixeltransferType
- the data type of the array used to represent
pixel values. The data type must be either
DataBuffer.TYPE_BYTE
or
DataBuffer.TYPE_USHORT
.IllegalArgumentException
- if bits
is less
than 1 or greater than 16IllegalArgumentException
- if size
is less
than 1IllegalArgumentException
- if transferType
is not
one of DataBuffer.TYPE_BYTE
or
DataBuffer.TYPE_USHORT
public IndexColorModel(int bits, int size, int[] cmap, int start, int transferType, BigInteger validBits)
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.bits
- the number of bits each pixel occupiessize
- the size of the color component arraycmap
- the array of color componentsstart
- the starting offset of the first color componenttransferType
- the specified data typevalidBits
- 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.IllegalArgumentException
- if bits
is less
than 1 or greater than 16IllegalArgumentException
- if size
is less
than 1IllegalArgumentException
- if transferType
is not
one of DataBuffer.TYPE_BYTE
or
DataBuffer.TYPE_USHORT
public int getTransparency()
getTransparency
in interface java.awt.Transparency
getTransparency
in class ColorModel
IndexColorModel
Transparency.OPAQUE
,
Transparency.BITMASK
,
Transparency.TRANSLUCENT
public int[] getComponentSize()
getComponentSize
in class ColorModel
IndexColorModel
public final int getMapSize()
IndexColorModel
.public final int getTransparentPixel()
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.IndexColorModel
object, or -1 if there
is no such pixelpublic final void getReds(byte[] r)
getMapSize
are written.r
- the specified array into which the elements of the
array of red color components are copiedpublic final void getGreens(byte[] g)
getMapSize
are written.g
- the specified array into which the elements of the
array of green color components are copiedpublic final void getBlues(byte[] b)
getMapSize
are written.b
- the specified array into which the elements of the
array of blue color components are copiedpublic final void getAlphas(byte[] a)
getMapSize
are written.a
- the specified array into which the elements of the
array of alpha components are copiedpublic final void getRGBs(int[] rgb)
getMapSize
are
written.rgb
- the specified array into which the converted ARGB
values from this array of color and alpha components
are copied.public final int getRed(int pixel)
getRed
in class ColorModel
pixel
- the specified pixelpublic final int getGreen(int pixel)
getGreen
in class ColorModel
pixel
- the specified pixelpublic final int getBlue(int pixel)
getBlue
in class ColorModel
pixel
- the specified pixelpublic final int getAlpha(int pixel)
getAlpha
in class ColorModel
pixel
- the specified pixelpublic final int getRGB(int pixel)
getRGB
in class ColorModel
pixel
- the specified pixelColorModel.getRGBdefault()
public void finalize()
ColorModel
once this ColorModel
is no
longer referenced.finalize
in class ColorModel
WeakReference
,
PhantomReference
public String toString()
String
representation of the contents of
this ColorModel
object.toString
in class ColorModel
String
representing the contents of this
ColorModel
object.