Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.awt.image

Class ColorModel

java.lang.Object
|
+--java.awt.image.ColorModel

All Implemented Interfaces:

Transparency


public abstract class ColorModel

extends Object

implements Transparency

A color model operates with colors in several formats:

Authors:

Field Summary

intpixel_bits

A color model operates with colors in several formats:
  • normalized: component samples are in range [0.0, 1.0].
  • color model pixel value: all the color component samples for a sigle pixel packed/encoded in a way natural for the color model.
  • color model pixel int value: only makes sense if the natural encoding of a single pixel can fit in a single int value.
  • array of transferType containing a single pixel: the pixel is encoded in the natural way of the color model, taking up as many array elements as needed.
  • sRGB pixel int value: a pixel in sRGB color space, encoded in default 0xAARRGGBB format, assumed not alpha premultiplied.
  • single [0, 255] scaled int samples from default sRGB color space.
inttransferType

Constructor Summary

ColorModel(int bits)

Constructs the default color model.
ColorModel(int pixel_bits, int[] bits, java.awt.color.ColorSpace cspace, boolean hasAlpha, boolean isAlphaPremultiplied, int transparency, int transferType)

Constructs a ColorModel that translates pixel values to color/alpha components.

Method Summary

java.awt.image.ColorModelcoerceData(java.awt.image.WritableRaster raster, boolean isAlphaPremultiplied)

java.awt.image.SampleModelcreateCompatibleSampleModel(int w, int h)

java.awt.image.WritableRastercreateCompatibleWritableRaster(int w, int h)

booleanequals(java.lang.Object obj)

voidfinalize()

intgetAlpha(int pixel)

Extract alpha int sample from pixel value, scaled to [0, 255].
intgetAlpha(java.lang.Object inData)

java.awt.image.WritableRastergetAlphaRaster(java.awt.image.WritableRaster raster)

Subclasses must override this method if it is possible for the color model to have an alpha channel.
intgetBlue(int pixel)

Converts pixel value to sRGB and extract blue int sample scaled to range [0, 255].
intgetBlue(java.lang.Object inData)

java.awt.color.ColorSpacegetColorSpace()

intgetComponentSize(int componentIdx)

int[]getComponentSize()

int[]getComponents(int pixel, int[] components, int offset)

Fills an array with the unnormalized component samples from a pixel value.
int[]getComponents(java.lang.Object pixel, int[] components, int offset)

Fills an array with the unnormalized component samples from an array of transferType containing a single pixel.
intgetDataElement(int[] components, int offset)

Converts the unnormalized component samples from an array to a pixel value.
java.lang.ObjectgetDataElements(int rgb, java.lang.Object pixel)

Converts an sRGB pixel int value to an array containing a single pixel of the color space of the color model.
java.lang.ObjectgetDataElements(int[] components, int offset, java.lang.Object obj)

intgetGreen(int pixel)

Converts pixel value to sRGB and extract green int sample scaled to range [0, 255].
intgetGreen(java.lang.Object inData)

float[]getNormalizedComponents(int[] components, int offset, float[] normComponents, int normOffset)

Convert unnormalized components to normalized components.
intgetNumColorComponents()

intgetNumComponents()

intgetPixelSize()

Get get number of bits wide used for the bit size of pixel values
intgetRGB(int pixel)

Converts a pixel int value of the color space of the color model to a sRGB pixel int value.
intgetRGB(java.lang.Object inData)

Converts a pixel in the given array of the color space of the color model to an sRGB pixel int value.
static java.awt.image.ColorModelgetRGBdefault()

Returns the default color model which in Sun's case is an instance of DirectColorModel.
intgetRed(int pixel)

Converts pixel value to sRGB and extract red int sample scaled to range [0, 255].
intgetRed(java.lang.Object inData)

Converts pixel in the given array to sRGB and extract blue int sample scaled to range [0-255].
intgetTransparency()

int[]getUnnormalizedComponents(float[] normComponents, int normOffset, int[] components, int offset)

Convert normalized components to unnormalized components.
booleanhasAlpha()

booleanisAlphaPremultiplied()

booleanisCompatibleRaster(java.awt.image.Raster raster)

booleanisCompatibleSampleModel(java.awt.image.SampleModel sm)

java.lang.StringtoString()

Field Details

pixel_bits

protected int pixel_bits

A color model operates with colors in several formats:

Authors:

transferType

protected int transferType


Constructor Details

ColorModel

public ColorModel(int bits)

Constructs the default color model. The default color model can be obtained by calling getRGBdefault of this class.

Parameters:


ColorModel

protected ColorModel(int pixel_bits, int[] bits, java.awt.color.ColorSpace cspace, boolean hasAlpha, boolean isAlphaPremultiplied, int transparency, int transferType)

Constructs a ColorModel that translates pixel values to color/alpha components.

Parameters:

Throws:


Method Details

coerceData

public ColorModel coerceData(java.awt.image.WritableRaster raster, boolean isAlphaPremultiplied)

Parameters:


createCompatibleSampleModel

public SampleModel createCompatibleSampleModel(int w, int h)

Parameters:


createCompatibleWritableRaster

public WritableRaster createCompatibleWritableRaster(int w, int h)

Parameters:


equals

public boolean equals(java.lang.Object obj)

Parameters:


finalize

public void finalize()


getAlpha

public int getAlpha(int pixel)

Extract alpha int sample from pixel value, scaled to [0, 255].

Parameters:

Returns:


getAlpha

public int getAlpha(java.lang.Object inData)

Parameters:

See Also:


getAlphaRaster

public WritableRaster getAlphaRaster(java.awt.image.WritableRaster raster)

Subclasses must override this method if it is possible for the color model to have an alpha channel.

Parameters:

Returns:


getBlue

public int getBlue(int pixel)

Converts pixel value to sRGB and extract blue int sample scaled to range [0, 255].

Parameters:

See Also:


getBlue

public int getBlue(java.lang.Object inData)

Parameters:

See Also:


getColorSpace

public final ColorSpace getColorSpace()


getComponentSize

public int[] getComponentSize()


getComponentSize

public int getComponentSize(int componentIdx)

Parameters:


getComponents

public int[] getComponents(int pixel, int[] components, int offset)

Fills an array with the unnormalized component samples from a pixel value. I.e. decompose the pixel, but not perform any color conversion. This method is typically overriden in subclasses to provide a more efficient implementation.

Parameters:

Returns:


getComponents

public int[] getComponents(java.lang.Object pixel, int[] components, int offset)

Fills an array with the unnormalized component samples from an array of transferType containing a single pixel. I.e. decompose the pixel, but not perform any color conversion. This method is typically overriden in subclasses to provide a more efficient implementation.

Parameters:

Returns:


getDataElement

public int getDataElement(int[] components, int offset)

Converts the unnormalized component samples from an array to a pixel value. I.e. composes the pixel from component samples, but does not perform any color conversion or scaling of the samples. This method performs the inverse function of getComponents(int pixel, int[] components, int offset). I.e. (pixel == cm.getDataElement(cm.getComponents(pixel, null, 0), 0)). This method is typically overriden in subclasses to provide a more efficient implementation.

Parameters:

Returns:


getDataElements

public Object getDataElements(int[] components, int offset, java.lang.Object obj)

Parameters:


getDataElements

public Object getDataElements(int rgb, java.lang.Object pixel)

Converts an sRGB pixel int value to an array containing a single pixel of the color space of the color model.

This method performs the inverse function of getRGB(Object inData). Outline of conversion process:

  1. Convert rgb to normalized [0.0, 1.0] sRGB values.
  2. Convert to color space components using fromRGB in ColorSpace.
  3. If color model has alpha and should be premultiplied, multiply color space components with alpha value
  4. Scale the components to the correct number of bits.
  5. Arrange the components in the output array

Parameters:

Returns:

See Also:


getGreen

public int getGreen(int pixel)

Converts pixel value to sRGB and extract green int sample scaled to range [0, 255].

Parameters:

See Also:


getGreen

public int getGreen(java.lang.Object inData)

Parameters:

See Also:


getNormalizedComponents

public float[] getNormalizedComponents(int[] components, int offset, float[] normComponents, int normOffset)

Convert unnormalized components to normalized components.

Parameters:


getNumColorComponents

public int getNumColorComponents()


getNumComponents

public int getNumComponents()


getPixelSize

public int getPixelSize()

Get get number of bits wide used for the bit size of pixel values


getRGB

public int getRGB(int pixel)

Converts a pixel int value of the color space of the color model to a sRGB pixel int value. This method is typically overriden in subclasses to provide a more efficient implementation.

Parameters:

Returns:


getRGB

public int getRGB(java.lang.Object inData)

Converts a pixel in the given array of the color space of the color model to an sRGB pixel int value.

This method performs the inverse function of getDataElements(int rgb, Object pixel). I.e. (rgb == cm.getRGB(cm.getDataElements(rgb, null))).

Parameters:

Returns:

See Also:


getRGBdefault

public static ColorModel getRGBdefault()

Returns the default color model which in Sun's case is an instance of DirectColorModel.


getRed

public int getRed(int pixel)

Converts pixel value to sRGB and extract red int sample scaled to range [0, 255].

Parameters:

Returns:


getRed

public int getRed(java.lang.Object inData)

Converts pixel in the given array to sRGB and extract blue int sample scaled to range [0-255]. This method is typically overriden in subclasses to provide a more efficient implementation.

Parameters:


getTransparency

public int getTransparency()


getUnnormalizedComponents

public int[] getUnnormalizedComponents(float[] normComponents, int normOffset, int[] components, int offset)

Convert normalized components to unnormalized components.

Parameters:


hasAlpha

public final boolean hasAlpha()


isAlphaPremultiplied

public final boolean isAlphaPremultiplied()


isCompatibleRaster

public boolean isCompatibleRaster(java.awt.image.Raster raster)

Parameters:


isCompatibleSampleModel

public boolean isCompatibleSampleModel(java.awt.image.SampleModel sm)

Parameters:


toString

public String toString()