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

Quick Search    Search Deep

java.awt.image
Class IndexColorModel  view IndexColorModel download IndexColorModel.java

java.lang.Object
  extended byjava.awt.image.ColorModel
      extended byjava.awt.image.IndexColorModel
All Implemented Interfaces:
java.awt.Transparency

public class IndexColorModel
extends ColorModel

Color model similar to pseudo visual in X11.

This color model maps linear pixel values to actual RGB and alpha colors. Thus, pixel values are indexes into the color map. Each color component is an 8-bit unsigned value.

The IndexColorModel supports a map of valid pixels, allowing the representation of holes in the the color map. The valid map is represented as a java.math.BigInteger where each bit indicates the validity of the map entry with the same index.

Colors can have alpha components for transparency support. If alpha component values aren't given, color values are opaque. The model also supports a reserved pixel value to represent completely transparent colors, no matter what the actual color component values are.

IndexColorModel supports anywhere from 1 to 16 bit index values. The allowed transfer types are DataBuffer.TYPE_BYTE 55 and DataBuffer.TYPE_USHORT 55 .


Field Summary
private  int map_size
           
private  boolean opaque
           
private  int[] rgb
           
private  int trans
           
private  java.math.BigInteger validBits
           
 
Fields inherited from class java.awt.image.ColorModel
bits, cspace, hasAlpha, isAlphaPremultiplied, pixel_bits, transferType, transparency
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
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, java.math.BigInteger validBits)
          Construct an IndexColorModel using a colormap with holes.
 
Method Summary
 BufferedImage convertToIntDiscrete(Raster raster, boolean forceARGB)
          Construct a BufferedImage with rgb pixel values from a Raster.
 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.
 java.math.BigInteger getValidPixels()
          Returns a binary value (java.math.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.
 
Methods inherited from class java.awt.image.ColorModel
cloneColorModel, coerceData, createCompatibleSampleModel, createCompatibleWritableRaster, equals, finalize, getAlpha, getAlphaRaster, getBlue, getColorSpace, getComponents, getComponents, getComponentSize, getComponentSize, getDataElement, getDataElement, getDataElements, getDataElements, getDataElements, getGreen, getNormalizedComponents, getNormalizedComponents, getNumColorComponents, getNumComponents, getPixelFromArray, getPixelSize, getRed, getRGB, getRGBdefault, getTransferType, getTransparency, getUnnormalizedComponents, hasAlpha, isAlphaPremultiplied, isCompatibleRaster, isCompatibleSampleModel, nArray, nArray, stringParam, toString
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

map_size

private int map_size

opaque

private boolean opaque

trans

private int trans

rgb

private int[] rgb

validBits

private java.math.BigInteger validBits
Constructor Detail

IndexColorModel

public 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. 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].


IndexColorModel

public IndexColorModel(int bits,
                       int size,
                       byte[] reds,
                       byte[] greens,
                       byte[] blues,
                       int trans)
Creates a new indexed color model for 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.


IndexColorModel

public 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. 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].


IndexColorModel

public IndexColorModel(int bits,
                       int size,
                       byte[] cmap,
                       int start,
                       boolean hasAlpha)
Creates a new indexed color model using the color components in cmap. If hasAlpha is true then cmap contains an alpha component after each of the red, green and blue components.


IndexColorModel

public 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. The component values are interleaved as RGB(A).


IndexColorModel

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


IndexColorModel

public IndexColorModel(int bits,
                       int size,
                       int[] cmap,
                       int start,
                       int transferType,
                       java.math.BigInteger validBits)
Construct an IndexColorModel using a colormap with holes.

The IndexColorModel is built from the array of ints defining the colormap. Each element contains red, green, blue, and alpha components. The ColorSpace is sRGB. The transparency value is automatically determined.

This constructor permits indicating which colormap entries are valid, using the validBits argument. Each entry in cmap is valid if the corresponding bit in validBits is set.

Method Detail

getMapSize

public final int getMapSize()
Returns the size of the color lookup table.


getTransparentPixel

public final int getTransparentPixel()
Get the index of the transparent color in this color model.


getReds

public final void getReds(byte[] r)
Fills the supplied array with the red component of each color in the lookup table.


getGreens

public final void getGreens(byte[] g)
Fills the supplied array with the green component of each color in the lookup table.


getBlues

public final void getBlues(byte[] b)
Fills the supplied array with the blue component of each color in the lookup table.


getAlphas

public final void getAlphas(byte[] a)
Fills the supplied array with the alpha component of each color in the lookup table. If the model has a transparent pixel specified, the alpha for that pixel will be 0.


getRed

public final int getRed(int pixel)
Returns the red component of the color in the lookup table for the given pixel value.

Specified by:
getRed in class ColorModel

getGreen

public final int getGreen(int pixel)
Returns the green component of the color in the lookup table for the given pixel value.

Specified by:
getGreen in class ColorModel

getBlue

public final int getBlue(int pixel)
Returns the blue component of the color in the lookup table for the given pixel value.

Specified by:
getBlue in class ColorModel

getAlpha

public final int getAlpha(int pixel)
Returns the alpha component of the color in the lookup table for the given pixel value. If no alpha channel was specified when the color model was created, then 255 is returned for all pixels except the transparent pixel (if one is defined - see getTransparentPixel() 55 ) which returns an alpha of 0.

Specified by:
getAlpha in class ColorModel

getRGB

public final int getRGB(int pixel)
Get the RGB color value of the given pixel using the default RGB color model.

Overrides:
getRGB in class ColorModel

getRGBs

public final void getRGBs(int[] rgb)
Get the RGB color values of all pixels in the map using the default RGB color model.


isValid

public boolean isValid(int pixel)
Return true if the lookup table contains valid data for pixel, and false otherwise.


isValid

public boolean isValid()
Return true if all pixels are valid, false otherwise.


getValidPixels

public java.math.BigInteger getValidPixels()
Returns a binary value (java.math.BigInteger) where each bit represents an entry in the color lookup table. If the bit is on, the entry is valid.


convertToIntDiscrete

public BufferedImage convertToIntDiscrete(Raster raster,
                                          boolean forceARGB)
Construct a 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.