Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

java.awt.image
Class ColorModel  view ColorModel download ColorModel.java

java.lang.Object
  extended byjava.awt.image.ColorModel
All Implemented Interfaces:
java.awt.Transparency
Direct Known Subclasses:
ComponentColorModel, IndexColorModel, PackedColorModel

public abstract class ColorModel
extends java.lang.Object
implements java.awt.Transparency

A color model operates with colors in several formats:


Field Summary
(package private)  int[] bits
           
(package private)  java.awt.color.ColorSpace cspace
           
(package private)  boolean hasAlpha
           
(package private)  boolean isAlphaPremultiplied
           
protected  int pixel_bits
           
protected  int transferType
           
(package private)  int transparency
           
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
  ColorModel(int bits)
          Constructs the default color model.
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.
 
Method Summary
(package private)  ColorModel cloneColorModel(java.awt.color.ColorSpace cspace)
           
 ColorModel coerceData(WritableRaster raster, boolean isAlphaPremultiplied)
           
 SampleModel createCompatibleSampleModel(int w, int h)
           
 WritableRaster createCompatibleWritableRaster(int w, int h)
           
 boolean equals(java.lang.Object obj)
          Determine whether this Object is semantically equal to another Object.
 void finalize()
          Called on an object by the Virtual Machine at most once, at some point after the Object is determined unreachable but before it is destroyed.
abstract  int getAlpha(int pixel)
          Extract alpha int sample from pixel value, scaled to [0, 255].
 int getAlpha(java.lang.Object inData)
           
 WritableRaster getAlphaRaster(WritableRaster raster)
          Subclasses must override this method if it is possible for the color model to have an alpha channel.
abstract  int getBlue(int pixel)
          Converts pixel value to sRGB and extract blue int sample scaled to range [0, 255].
 int getBlue(java.lang.Object inData)
           
 java.awt.color.ColorSpace getColorSpace()
           
 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.
 int[] getComponentSize()
           
 int getComponentSize(int componentIdx)
           
 int getDataElement(float[] components, int offset)
          Converts the normalized component samples from an array to a pixel value.
 int getDataElement(int[] components, int offset)
          Converts the unnormalized component samples from an array to a pixel value.
 java.lang.Object getDataElements(float[] components, int offset, java.lang.Object obj)
          Converts the normalized component samples from an array to an array of TransferType values.
 java.lang.Object getDataElements(int[] components, int offset, java.lang.Object obj)
           
 java.lang.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.
abstract  int getGreen(int pixel)
          Converts pixel value to sRGB and extract green int sample scaled to range [0, 255].
 int getGreen(java.lang.Object inData)
           
 float[] getNormalizedComponents(int[] components, int offset, float[] normComponents, int normOffset)
          Convert unnormalized components to normalized components.
 float[] getNormalizedComponents(java.lang.Object pixel, float[] normComponents, int normOffset)
          Convert unnormalized components to normalized components.
 int getNumColorComponents()
           
 int getNumComponents()
           
(package private)  int getPixelFromArray(java.lang.Object inData)
          In this color model we know that the whole pixel value will always be contained within the first element of the pixel array.
 int getPixelSize()
          Get get number of bits wide used for the bit size of pixel values
abstract  int getRed(int pixel)
          Converts pixel value to sRGB and extract red int sample scaled to range [0, 255].
 int getRed(java.lang.Object inData)
          Converts pixel in the given array to sRGB and extract blue int sample scaled to range [0-255].
 int getRGB(int pixel)
          Converts a pixel int value of the color space of the color model to a sRGB pixel int value.
 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.
static ColorModel getRGBdefault()
          Returns the default color model which in Sun's case is an instance of DirectColorModel.
 int getTransferType()
           
 int getTransparency()
          Return the transparency type.
 int[] getUnnormalizedComponents(float[] normComponents, int normOffset, int[] components, int offset)
          Convert normalized components to unnormalized components.
 boolean hasAlpha()
           
 boolean isAlphaPremultiplied()
           
 boolean isCompatibleRaster(Raster raster)
          Checks if the given raster has a compatible data-layout (SampleModel).
 boolean isCompatibleSampleModel(SampleModel sm)
           
(package private) static byte[] nArray(byte value, int times)
           
(package private) static int[] nArray(int value, int times)
           
(package private)  java.lang.String stringParam()
           
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pixel_bits

protected int pixel_bits

transferType

protected int transferType

bits

int[] bits

cspace

java.awt.color.ColorSpace cspace

transparency

int transparency

hasAlpha

boolean hasAlpha

isAlphaPremultiplied

boolean isAlphaPremultiplied
Constructor Detail

ColorModel

public ColorModel(int bits)
Constructs the default color model. The default color model can be obtained by calling getRGBdefault of this class.


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.

Method Detail

nArray

static int[] nArray(int value,
                    int times)

nArray

static byte[] nArray(byte value,
                     int times)

cloneColorModel

ColorModel cloneColorModel(java.awt.color.ColorSpace cspace)

finalize

public void finalize()
Description copied from class: java.lang.Object
Called on an object by the Virtual Machine at most once, at some point after the Object is determined unreachable but before it is destroyed. You would think that this means it eventually is called on every Object, but this is not necessarily the case. If execution terminates abnormally, garbage collection does not always happen. Thus you cannot rely on this method to always work. For finer control over garbage collection, use references from the java.lang.ref package.

Virtual Machines are free to not call this method if they can determine that it does nothing important; for example, if your class extends Object and overrides finalize to do simply super.finalize().

finalize() will be called by a java.lang.Thread that has no locks on any Objects, and may be called concurrently. There are no guarantees on the order in which multiple objects are finalized. This means that finalize() is usually unsuited for performing actions that must be thread-safe, and that your implementation must be use defensive programming if it is to always work.

If an Exception is thrown from finalize() during garbage collection, it will be patently ignored and the Object will still be destroyed.

It is allowed, although not typical, for user code to call finalize() directly. User invocation does not affect whether automatic invocation will occur. It is also permitted, although not recommended, for a finalize() method to "revive" an object by making it reachable from normal code again.

Unlike constructors, finalize() does not get called for an object's superclass unless the implementation specifically calls super.finalize().

The default implementation does nothing.


getRGBdefault

public static ColorModel getRGBdefault()
Returns the default color model which in Sun's case is an instance of DirectColorModel.


hasAlpha

public final boolean hasAlpha()

isAlphaPremultiplied

public final boolean isAlphaPremultiplied()

getPixelSize

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


getComponentSize

public int getComponentSize(int componentIdx)

getComponentSize

public int[] getComponentSize()

getTransparency

public int getTransparency()
Description copied from interface: java.awt.Transparency
Return the transparency type.

Specified by:
getTransparency in interface java.awt.Transparency

getNumComponents

public int getNumComponents()

getNumColorComponents

public int getNumColorComponents()

getRed

public abstract int getRed(int pixel)
Converts pixel value to sRGB and extract red int sample scaled to range [0, 255].


getGreen

public abstract int getGreen(int pixel)
Converts pixel value to sRGB and extract green int sample scaled to range [0, 255].


getBlue

public abstract int getBlue(int pixel)
Converts pixel value to sRGB and extract blue int sample scaled to range [0, 255].


getAlpha

public abstract int getAlpha(int pixel)
Extract alpha int sample from pixel value, scaled to [0, 255].


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.


getPixelFromArray

final int getPixelFromArray(java.lang.Object inData)
In this color model we know that the whole pixel value will always be contained within the first element of the pixel array.


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.


getGreen

public int getGreen(java.lang.Object inData)

getBlue

public int getBlue(java.lang.Object inData)

getAlpha

public int getAlpha(java.lang.Object inData)

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))).


getDataElements

public java.lang.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


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.


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.


getUnnormalizedComponents

public int[] getUnnormalizedComponents(float[] normComponents,
                                       int normOffset,
                                       int[] components,
                                       int offset)
Convert normalized components to unnormalized components.


getNormalizedComponents

public float[] getNormalizedComponents(int[] components,
                                       int offset,
                                       float[] normComponents,
                                       int normOffset)
Convert unnormalized components to normalized components.


getNormalizedComponents

public float[] getNormalizedComponents(java.lang.Object pixel,
                                       float[] normComponents,
                                       int normOffset)
Convert unnormalized components to normalized components.

Since:
1.4

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 overriden in subclasses since this abstract class throws UnsupportedOperationException().


getDataElement

public int getDataElement(float[] components,
                          int offset)
Converts the normalized 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 is typically overriden in subclasses to provide a more efficient implementation. The method provided by this abstract class converts the components to unnormalized form and returns getDataElement(int[], int).

Since:
1.4

getDataElements

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

getDataElements

public java.lang.Object getDataElements(float[] components,
                                        int offset,
                                        java.lang.Object obj)
Converts the normalized component samples from an array to an array of TransferType values. I.e. composes the pixel from component samples, but does not perform any color conversion or scaling of the samples. If obj is null, a new array of TransferType is allocated and returned. Otherwise the results are stored in obj and obj is returned. If obj is not long enough, ArrayIndexOutOfBounds is thrown. If obj is not an array of primitives, ClassCastException is thrown. This method is typically overriden in subclasses to provide a more efficient implementation. The method provided by this abstract class converts the components to unnormalized form and returns getDataElement(int[], int, Object).

Since:
1.4

equals

public boolean equals(java.lang.Object obj)
Description copied from class: java.lang.Object
Determine whether this Object is semantically equal to another Object.

There are some fairly strict requirements on this method which subclasses must follow:

  • It must be transitive. If a.equals(b) and b.equals(c), then a.equals(c) must be true as well.
  • It must be symmetric. a.equals(b) and b.equals(a) must have the same value.
  • It must be reflexive. a.equals(a) must always be true.
  • It must be consistent. Whichever value a.equals(b) returns on the first invocation must be the value returned on all later invocations.
  • a.equals(null) must be false.
  • It must be consistent with hashCode(). That is, a.equals(b) must imply a.hashCode() == b.hashCode(). The reverse is not true; two objects that are not equal may have the same hashcode, but that has the potential to harm hashing performance.

This is typically overridden to throw a java.lang.ClassCastException if the argument is not comparable to the class performing the comparison, but that is not a requirement. It is legal for a.equals(b) to be true even though a.getClass() != b.getClass(). Also, it is typical to never cause a java.lang.NullPointerException.

In general, the Collections API (java.util) use the equals method rather than the == operator to compare objects. However, java.util.IdentityHashMap is an exception to this rule, for its own good reasons.

The default implementation returns this == o.


getColorSpace

public final java.awt.color.ColorSpace getColorSpace()

coerceData

public ColorModel coerceData(WritableRaster raster,
                             boolean isAlphaPremultiplied)

isCompatibleRaster

public boolean isCompatibleRaster(Raster raster)
Checks if the given raster has a compatible data-layout (SampleModel).


createCompatibleWritableRaster

public WritableRaster createCompatibleWritableRaster(int w,
                                                     int h)

createCompatibleSampleModel

public SampleModel createCompatibleSampleModel(int w,
                                               int h)

isCompatibleSampleModel

public boolean isCompatibleSampleModel(SampleModel sm)

getTransferType

public final int getTransferType()

getAlphaRaster

public WritableRaster getAlphaRaster(WritableRaster raster)
Subclasses must override this method if it is possible for the color model to have an alpha channel.


stringParam

java.lang.String stringParam()

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).