Class java.awt.image.ColorModel
java.lang.Object
|
+----java.awt.image.ColorModel
- Subclasses:
- ComponentColorModel, IndexColorModel, PackedColorModel
- public abstract class ColorModel
- extends Object
- implements Transparency
An abstract class that encapsulates the methods for translating from pixel
values to color components (e.g. red, green, blue) for an image.
Pixels may be represented as 32-bit ints or as arrays of 32-bit ints.
- See Also:
- IndexColorModel, ComponentColorModel, PackedColorModel, DirectColorModel
Constructor Summary
|
ColorModel(int bits)
Constructs a ColorModel which describes a pixel of the specified
number of bits.
|
ColorModel(int bits,
ColorSpace cspace,
boolean hasAlpha,
boolean isAlphaPremultiplied,
int transparency)
Constructs a ColorModel which describes a pixel of the specified
number of bits in the color space of the specified ColorSpace.
|
ColorModel(int[] bits,
ColorSpace cspace,
boolean hasAlpha,
boolean isAlphaPremultiplied,
int transparency)
Constructs a ColorModel which describes a pixel
in the color space of the specified ColorSpace.
|
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.
|
WritableRaster
|
createCompatibleWritableRaster(int w,
int h)
Creates a WritableRaster with the specified width and height, that
has a channel layout compatible with this ColorModel.
|
boolean
|
equals(Object obj)
|
void
|
finalize()
|
int
|
getAlpha(int pixel)
Returns the alpha
component for the specified pixel, scaled from 0 to 255
in the default RGB ColorSpace, sRGB.
|
int
|
getAlpha(Object inData)
Returns the alpha
color component for the specified pixel, scaled from 0 to 255 in
the default RGB ColorSpace, sRGB.
|
int
|
getBlue(int pixel)
Returns the blue
color component for the specified pixel, scaled from 0 to 255
in the default RGB ColorSpace, sRGB.
|
int
|
getBlue(Object inData)
Returns the blue
color component for the specified pixel, scaled from 0 to 255 in
the default RGB ColorSpace, sRGB.
|
ColorSpace
|
getColorSpace()
Returns the ColorSpace associated with this ColorModel
|
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 obj,
int[] components,
int offset)
Returns an array of all of the components given a pixel array
in the current color model.
|
int[]
|
getComponents(float[] normComponents,
int normOffset,
int[] components,
int offset)
Returns an array of all of the components given a normalized
component array.
|
int
|
getComponentSize(int componentIdx)
Returns the number of bits for the given component.
|
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, scaled from 0 to 255
in the default RGB ColorSpace, sRGB.
|
int
|
getGreen(Object inData)
Returns the green
color component for the specified pixel, scaled from 0 to 255 in
the default RGB ColorSpace, sRGB.
|
int
|
getMaxComponentSize()
Returns the maximum number of bits for all components.
|
float[]
|
getNormalizedComponents(int[] components,
int offset,
float[] normComponents,
int normOffset)
Returns an array of normalized components given an array of all
components.
|
int
|
getNumColorComponents()
Returns the number of color components in this color model.
|
int
|
getNumComponents()
Returns the number of components (including alpha) in this color model.
|
Object
|
getPixelData(int rgb,
Object pixel)
Returns a pixel array given a pixel in the default RGB color model.
|
int
|
getPixelSize()
Returns the number of bits per pixel described by this ColorModel.
|
int
|
getRed(int pixel)
Returns the red
color component for the specified pixel, scaled from 0 to 255
in the default RGB ColorSpace, sRGB.
|
int
|
getRed(Object inData)
Returns the red
color component for the specified pixel, scaled from 0 to 255 in
the default RGB ColorSpace, sRGB.
|
int
|
getRGB(int pixel)
Returns the color of the pixel in the default RGB color model.
|
int
|
getRGB(Object inData)
Returns a pixel in the default RGB color model given a pixel array
in the current color model.
|
static ColorModel
|
getRGBdefault()
Return a DirectColorModel that describes the default format for
integer RGB values used in many of the methods in the
AWT image interfaces for the convenience of the programmer.
|
int
|
getTransparency()
Returns the transparency.
|
boolean
|
hasAlpha()
Returns whether or not alpha is supported in this ColorModel.
|
boolean
|
isAlphaPremultiplied()
Returns whether or not the alpha has been premultiplied in the
Raster associated with this ColorModel.
|
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)
This method will pack the components into a pixel given an
array of discrete components in this color model.
|
Object
|
setComponents(int[] components,
int offset,
Object obj)
Returns a pixel, given a discrete components (unpacked color/alpha
values) in this color model.
|
String
|
toString()
Prints the contents of this object
|
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
pixel_bits
protected int pixel_bits
transferType
protected int transferType
ColorModel
public ColorModel(int bits)
- Constructs a ColorModel which describes a pixel of the specified
number of bits. The color space is the default RGB ColorSpace,
which is sRGB.
ColorModel
protected ColorModel(int bits,
ColorSpace cspace,
boolean hasAlpha,
boolean isAlphaPremultiplied,
int transparency)
- Constructs a ColorModel which describes a pixel of the specified
number of bits in the color space of the specified ColorSpace.
The boolean, isAlphaPremultiplied, specifies how to interpret color
data that are passed to this ColorModel. If the boolean is true, the
color data have been multiplied with alpha. The transparency
specifies what alpha values can be represented by this color model.
Any ColorModel object that uses this constructor should override
the getComponentSize() method to return the actual bits per
component array. This constructor is here to support legacy
code.
- See Also:
- Transparency
ColorModel
protected ColorModel(int[] bits,
ColorSpace cspace,
boolean hasAlpha,
boolean isAlphaPremultiplied,
int transparency)
- Constructs a ColorModel which describes a pixel
in the color space of the specified ColorSpace. The bits array
specifies the number of significant bits per component in the
color model (color components and alpha).
The boolean, isAlphaPremultiplied, specifies how to
interpret color data that
are passed to this ColorModel. If the boolean is true, the
color data have been multiplied with alpha. The transparency
specifies what alpha values can be represented by this color model.
- See Also:
- Transparency
getRGBdefault
public static ColorModel getRGBdefault()
- Return a DirectColorModel that describes the default format for
integer RGB values used in many of the methods in the
AWT image interfaces for the convenience of the programmer.
The color space is the default ColorSpace, sRGB.
The format for the RGB values is an integer with 8 bits
each of alpha, red, green, and blue color components ordered
correspondingly from the most significant byte to the least
significant byte, as in: 0xAARRGGBB. Color components are
not premultiplied by the alpha component. This format does not
necessarily represent the native or the most efficient
ColorModel for a particular device or for all images. It is
merely used as a common color model format.
hasAlpha
public final boolean hasAlpha()
- Returns whether or not alpha is supported in this ColorModel.
isAlphaPremultiplied
public final boolean isAlphaPremultiplied()
- Returns whether or not the alpha has been premultiplied in the
Raster associated with this ColorModel.
getPixelSize
public int getPixelSize()
- Returns the number of bits per pixel described by this ColorModel.
getComponentSize
public int getComponentSize(int componentIdx)
- Returns the number of bits for the given component.
getComponentSize
public int[] getComponentSize()
- Returns an array of the number of bits per component.
getMaxComponentSize
public final int getMaxComponentSize()
- Returns the maximum number of bits for all components.
getTransparency
public int getTransparency()
- Returns the transparency. Returns either OPAQUE, BITMASK,
or TRANSLUCENT
- Implements:
- getTransparency in interface Transparency
- See Also:
- OPAQUE, BITMASK, TRANSLUCENT
getNumComponents
public int getNumComponents()
- Returns the number of components (including alpha) in this color model.
This is equal to the number of color components, optionally plus
one, if there is an alpha component.
getNumColorComponents
public int getNumColorComponents()
- Returns the number of color components in this color model.
This is the number of components returned by
ColorSpace.getNumComponents().
- See Also:
- getNumComponents
getRed
public abstract int getRed(int pixel)
- Returns the red
color component for the specified pixel, scaled from 0 to 255
in the default RGB ColorSpace, sRGB.
An IllegalArgumentException will be thrown if there is more than
one component in this ColorModel. 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.
getGreen
public abstract int getGreen(int pixel)
- Returns the green
color component for the specified pixel, scaled from 0 to 255
in the default RGB ColorSpace, sRGB.
An IllegalArgumentException will be thrown if there is more than
one component in this ColorModel. 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.
getBlue
public abstract int getBlue(int pixel)
- Returns the blue
color component for the specified pixel, scaled from 0 to 255
in the default RGB ColorSpace, sRGB.
An IllegalArgumentException will be thrown if there is more than
one component in this ColorModel. 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.
getAlpha
public abstract int getAlpha(int pixel)
- Returns the alpha
component for the specified pixel, scaled from 0 to 255
in the default RGB ColorSpace, sRGB.
An IllegalArgumentException will be thrown if there is more than
one component in this ColorModel.
getRGB
public int getRGB(int pixel)
- Returns the color of the pixel in the default RGB color model.
An IllegalArgumentException will be thrown if there is more than
one component in this ColorModel. 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.
- See Also:
- getRGBdefault
getRed
public int getRed(Object inData)
- Returns the red
color component for the specified pixel, scaled from 0 to 255 in
the default RGB ColorSpace, sRGB. The pixel is
described by a discrete array of data elements of type
transferType passed in as an object reference.
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.
getGreen
public int getGreen(Object inData)
- Returns the green
color component for the specified pixel, scaled from 0 to 255 in
the default RGB ColorSpace, sRGB. The pixel is
described by a discrete array of
channel elements, one per channel. 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.
getBlue
public int getBlue(Object inData)
- Returns the blue
color component for the specified pixel, scaled from 0 to 255 in
the default RGB ColorSpace, sRGB. The pixel is
described by a discrete array of
channel elements, one per channel. 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.
getAlpha
public int getAlpha(Object inData)
- Returns the alpha
color component for the specified pixel, scaled from 0 to 255 in
the default RGB ColorSpace, sRGB. The pixel is
described by a discrete array of
channel elements, one per channel.
getRGB
public int getRGB(Object inData)
- Returns a pixel in the default RGB color model given a pixel array
in the current color model.
The pixel is described by a discrete array of
channel elements, one per channel. 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.
- See Also:
- getRGBdefault
getPixelData
public Object getPixelData(int rgb,
Object pixel)
- Returns a pixel array given a pixel in the default RGB color model.
This pixel array can then be passed to the putPixelData method of
a Raster object. If the pixel variable is null, a new array will
be allocated. The pixel array will be returned.
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. If the color model is not
an IndexColorModel or DirectColorModel, an IllegalArgumentException
will be thrown. 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.
getComponents
public int[] getComponents(Object obj,
int[] components,
int offset)
- Returns an array of all of the components given a pixel array
in the current color model. 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.
getComponents
public int[] getComponents(float[] normComponents,
int normOffset,
int[] components,
int offset)
- Returns an array of all of the components given a normalized
component array.
getNormalizedComponents
public float[] getNormalizedComponents(int[] components,
int offset,
float[] normComponents,
int normOffset)
- Returns an array of normalized components given an array of all
components.
setComponents
public int setComponents(int[] components,
int offset)
- This method will pack the components into a pixel given an
array of discrete components in this color model. This method
will throw an IllegalArgumentException if the components cannot
fit in a single integer pixel.
setComponents
public Object setComponents(int[] components,
int offset,
Object obj)
- Returns a pixel, given a discrete components (unpacked color/alpha
values) in this color model.
equals
public boolean equals(Object obj)
- Overrides:
- equals in class Object
getColorSpace
public final ColorSpace getColorSpace()
- Returns the ColorSpace associated with this ColorModel
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.
isCompatibleRaster
public boolean isCompatibleRaster(Raster raster)
- Returns true if raster is compatible with this ColorModel and
false if it is not.
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.
- See Also:
- WritableRaster
finalize
public void finalize()
- Overrides:
- finalize in class Object
toString
public String toString()
- Prints the contents of this object
- Overrides:
- toString in class Object
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.