public class IndexColorModel extends ColorModel
IndexColorModel
supports a map of valid pixels, allowing
the representation of holes in the the color map. The valid map is
represented as a BigInteger
where each bit indicates the validity
of the map entry with the same index.
IndexColorModel
supports anywhere from 1 to 16 bit index
values. The allowed transfer types are DataBuffer.TYPE_BYTE
and
DataBuffer.TYPE_USHORT
.pixel_bits, transferType
BITMASK, OPAQUE, TRANSLUCENT
Constructor and Description |
---|
IndexColorModel(int bits,
int size,
byte[] reds,
byte[] greens,
byte[] blues)
Creates a new indexed color model for
size color elements
with no alpha component. |
IndexColorModel(int bits,
int size,
byte[] reds,
byte[] greens,
byte[] blues,
byte[] alphas)
Creates a new indexed color model for
size color elements
including alpha. |
IndexColorModel(int bits,
int size,
byte[] reds,
byte[] greens,
byte[] blues,
int trans)
Creates a new indexed color model for
size color elements. |
IndexColorModel(int bits,
int size,
byte[] cmap,
int start,
boolean hasAlpha)
Creates a new indexed color model using the color components in
cmap . |
IndexColorModel(int bits,
int size,
byte[] cmap,
int start,
boolean hasAlpha,
int trans)
Construct an IndexColorModel from an array of red, green, blue, and
optional alpha components.
|
IndexColorModel(int bits,
int size,
int[] cmap,
int start,
boolean hasAlpha,
int trans,
int transferType)
Construct an IndexColorModel from an array of
size packed
colors. |
IndexColorModel(int bits,
int size,
int[] cmap,
int start,
int transferType,
BigInteger validBits)
Construct an IndexColorModel using a colormap with holes.
|
Modifier and Type | Method and Description |
---|---|
BufferedImage |
convertToIntDiscrete(Raster raster,
boolean forceARGB)
Construct a
BufferedImage with rgb pixel values from a
Raster . |
SampleModel |
createCompatibleSampleModel(int w,
int h)
Creates a
SampleModel that is compatible to this color model. |
int |
getAlpha(int pixel)
Returns the alpha component of the color in the lookup table for the
given pixel value.
|
void |
getAlphas(byte[] a)
Fills the supplied array with the alpha component of each color in the
lookup table.
|
int |
getBlue(int pixel)
Returns the blue component of the color in the lookup table for the
given pixel value.
|
void |
getBlues(byte[] b)
Fills the supplied array with the blue component of each color in the
lookup table.
|
int |
getGreen(int pixel)
Returns the green component of the color in the lookup table for the
given pixel value.
|
void |
getGreens(byte[] g)
Fills the supplied array with the green component of each color in the
lookup table.
|
int |
getMapSize()
Returns the size of the color lookup table.
|
int |
getRed(int pixel)
Returns the red component of the color in the lookup table for the
given pixel value.
|
void |
getReds(byte[] r)
Fills the supplied array with the red component of each color in the
lookup table.
|
int |
getRGB(int pixel)
Get the RGB color value of the given pixel using the default
RGB color model.
|
void |
getRGBs(int[] rgb)
Get the RGB color values of all pixels in the map using the default
RGB color model.
|
int |
getTransparentPixel()
Get the index of the transparent color in this color model.
|
BigInteger |
getValidPixels()
Returns a binary value (
BigInteger ) where each bit represents an
entry in the color lookup table. |
boolean |
isValid()
Return
true if all pixels are valid, false
otherwise. |
boolean |
isValid(int pixel)
Return
true if the lookup table contains valid data for
pixel , and false otherwise. |
coerceData, createCompatibleWritableRaster, equals, finalize, getAlpha, getAlphaRaster, getBlue, getColorSpace, getComponents, getComponents, getComponentSize, getComponentSize, getDataElement, getDataElement, getDataElements, getDataElements, getDataElements, getGreen, getNormalizedComponents, getNormalizedComponents, getNumColorComponents, getNumComponents, getPixelSize, getRed, getRGB, getRGBdefault, getTransferType, getTransparency, getUnnormalizedComponents, hasAlpha, isAlphaPremultiplied, isCompatibleRaster, isCompatibleSampleModel, toString
public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, byte[] blues)
size
color elements
with no alpha component. Each array must contain at least
size
elements. For each array, the i-th color is described
by reds[i], greens[i] and blues[i].bits
- the number of bits needed to represent size
colors.size
- the number of colors in the color map.reds
- the red component of all colors.greens
- the green component of all colors.blues
- the blue component of all colors.IllegalArgumentException
- if bits
< 1 or
bits
> 16.NullPointerException
- if any of the arrays is null
.ArrayIndexOutOfBoundsException
- if size
is greater
than the length of the component arrays.public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, byte[] blues, int trans)
size
color elements.
Each array must contain at least size
elements. For each
array, the i-th color is described by reds[i], greens[i] and blues[i].
All the colors are opaque except for the transparent color.bits
- the number of bits needed to represent size
colorssize
- the number of colors in the color mapreds
- the red component of all colorsgreens
- the green component of all colorsblues
- the blue component of all colorstrans
- the index of the transparent color (use -1 for no
transparent color).IllegalArgumentException
- if bits
< 1 or
bits
> 16.NullPointerException
- if any of the arrays is null
.ArrayIndexOutOfBoundsException
- if size
is greater
than the length of the component arrays.public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, byte[] blues, byte[] alphas)
size
color elements
including alpha. Each array must contain at least size
elements. For each array, the i-th color is described
by reds[i], greens[i], blues[i] and alphas[i].bits
- the number of bits needed to represent size
colors.size
- the number of colors in the color map.reds
- the red component of all colors.greens
- the green component of all colors.blues
- the blue component of all colors.alphas
- the alpha component of all colors (null
permitted).IllegalArgumentException
- if bits
< 1 or
bits
> 16.NullPointerException
- if reds
, greens
or
blues
is null
.ArrayIndexOutOfBoundsException
- if size
is greater
than the length of the component arrays.public IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasAlpha)
cmap
. If hasAlpha
is true
then
cmap
contains an alpha component after each of the red, green
and blue components.bits
- the number of bits needed to represent size
colorssize
- the number of colors in the color mapcmap
- packed color componentsstart
- the offset of the first color component in cmap
hasAlpha
- cmap
has alpha valuesIllegalArgumentException
- if bits < 1, bits > 16, or size
< 1.NullPointerException
- if cmap
is null
.public IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasAlpha, int trans)
bits
- the number of bits needed to represent size
colorssize
- the number of colors in the color mapcmap
- interleaved color componentsstart
- the offset of the first color component in cmap
hasAlpha
- cmap
has alpha valuestrans
- the index of the transparent colorIllegalArgumentException
- if bits < 1, bits > 16, or size
< 1.NullPointerException
- if cmap
is null
.public IndexColorModel(int bits, int size, int[] cmap, int start, boolean hasAlpha, int trans, int transferType)
size
packed
colors. Each int element contains 8-bit red, green, blue, and optional
alpha values packed in order. If hasAlpha is false, then all the colors
are opaque except for the transparent color.bits
- the number of bits needed to represent size
colorssize
- the number of colors in the color mapcmap
- packed color componentsstart
- the offset of the first color component in cmap
hasAlpha
- cmap
has alpha valuestrans
- the index of the transparent colortransferType
- DataBuffer.TYPE_BYTE
or
DataBuffer.TYPE_USHORT
.IllegalArgumentException
- if bits < 1, bits > 16, or size
< 1.IllegalArgumentException
- if transferType
is something
other than DataBuffer.TYPE_BYTE
or
DataBuffer.TYPE_USHORT
.public IndexColorModel(int bits, int size, int[] cmap, int start, int transferType, BigInteger validBits)
bits
- the number of bits needed to represent size
colors.size
- the number of colors in the color map.cmap
- packed color components.start
- the offset of the first color component in cmap
.transferType
- DataBuffer.TYPE_BYTE
or
DataBuffer.TYPE_USHORT
.validBits
- a map of the valid entries in cmap
.IllegalArgumentException
- if bits < 1, bits > 16, or size
< 1.IllegalArgumentException
- if transferType is something other than
DataBuffer.TYPE_BYTE
or DataBuffer.TYPE_USHORT
.public final int getMapSize()
public final int getTransparentPixel()
public final void getReds(byte[] r)
r
- an array that is at least as large as getMapSize()
.NullPointerException
- if r
is null
.ArrayIndexOutOfBoundsException
- if r
has less
than getMapSize()
elements.public final void getGreens(byte[] g)
g
- an array that is at least as large as getMapSize()
.NullPointerException
- if g
is null
.ArrayIndexOutOfBoundsException
- if g
has less
than getMapSize()
elements.public final void getBlues(byte[] b)
b
- an array that is at least as large as getMapSize()
.NullPointerException
- if b
is null
.ArrayIndexOutOfBoundsException
- if b
has less
than getMapSize()
elements.public final void getAlphas(byte[] a)
a
- an array that is at least as large as getMapSize()
.NullPointerException
- if a
is null
.ArrayIndexOutOfBoundsException
- if a
has less
than getMapSize()
elements.public final int getRed(int pixel)
getRed
in class ColorModel
pixel
- the pixel lookup value.ArrayIndexOutOfBoundsException
- if pixel
is negative.public final int getGreen(int pixel)
getGreen
in class ColorModel
pixel
- the pixel lookup value.ArrayIndexOutOfBoundsException
- if pixel
is negative.ColorModel.getRed(int)
public final int getBlue(int pixel)
getBlue
in class ColorModel
pixel
- the pixel lookup value.ArrayIndexOutOfBoundsException
- if pixel
is negative.ColorModel.getRed(int)
public final int getAlpha(int pixel)
getTransparentPixel()
) which
returns an alpha of 0.getAlpha
in class ColorModel
pixel
- the pixel lookup value.ArrayIndexOutOfBoundsException
- if pixel
is negative.public final int getRGB(int pixel)
getRGB
in class ColorModel
pixel
- the pixel lookup value.ArrayIndexOutOfBoundsException
- if pixel
is negative.public final void getRGBs(int[] rgb)
rgb
- The destination array.public boolean isValid(int pixel)
true
if the lookup table contains valid data for
pixel
, and false
otherwise.pixel
- the pixel value used to index the color lookup table.true
if pixel
is valid,
false
otherwise.public boolean isValid()
true
if all pixels are valid, false
otherwise.true
if all pixels are valid, false
otherwise.public BigInteger getValidPixels()
BigInteger
) where each bit represents an
entry in the color lookup table. If the bit is on, the entry is valid.public BufferedImage convertToIntDiscrete(Raster raster, boolean forceARGB)
BufferedImage
with rgb pixel values from a
Raster
.
Constructs a new BufferedImage in which each pixel is an RGBA int from
a Raster with index-valued pixels. If this model has no alpha component
or transparent pixel, the type of the new BufferedImage is TYPE_INT_RGB.
Otherwise the type is TYPE_INT_ARGB. If forceARGB is true, the type is
forced to be TYPE_INT_ARGB no matter what.raster
- The source of pixel values.forceARGB
- True if type must be TYPE_INT_ARGB.public SampleModel createCompatibleSampleModel(int w, int h)
SampleModel
that is compatible to this color model.
This will be a MultiPixelPackedSampleModel
for bits/pixel of
1, 2 or 4, or a ComponentColorModel
for the other cases.createCompatibleSampleModel
in class ColorModel
w
- the width of the sample model to createh
- the height of the sample model to create