javax.media.jai
Class ColorCube

java.lang.Object
  extended byjavax.media.jai.LookupTableJAI
      extended byjavax.media.jai.ColorCube
All Implemented Interfaces:
Serializable

public class ColorCube
extends LookupTableJAI

A subclass of LookupTableJAI which represents a lookup table which is a color cube. A color cube provides a fixed, invertible mapping between table indices and sample values. This allows the findNearestEntry method to be implemented more efficiently than in the general case.

All constructors are protected. The correct way to create a ColorCube is to use one of the static create methods defined in this class.

See Also:
LookupTableJAI, Serialized Form

Field Summary
static ColorCube BYTE_496
          A ColorCube for dithering RGB byte data into 216 colors.
static ColorCube BYTE_855
          A ColorCube for dithering YCC byte data into 200 colors.
 
Constructor Summary
protected ColorCube(byte[][] data, int offset)
          Returns a multi-banded byte ColorCube with an index offset common to all bands.
protected ColorCube(double[][] data, int offset)
          Returns a multi-banded double ColorCube with an index offset common to all bands.
protected ColorCube(float[][] data, int offset)
          Returns a multi-banded float ColorCube with an index offset common to all bands.
protected ColorCube(int[][] data, int offset)
          Returns a multi-banded int ColorCube with an index offset common to all bands.
protected ColorCube(short[][] data, int offset, boolean isUShort)
          Returns a multi-banded short or unsigned short ColorCube with an index offset common to all bands.
 
Method Summary
static ColorCube createColorCube(int dataType, int[] dimension)
          Returns a multi-banded ColorCube of a specified data type with zero offset for all bands.
static ColorCube createColorCube(int dataType, int offset, int[] dimension)
          Returns a multi-banded ColorCube of a specified data type.
 int findNearestEntry(float[] pixel)
          Finds the index of the nearest color in the color map to the pixel value argument.
 int getAdjustedOffset()
          Returns the adjusted offset into the lookup table, accounting for negative dimensions.
 int[] getDimension()
          Returns the array of signed dimensions used to construct the ColorCube.
 int[] getDimsLessOne()
          Returns an array containing the signed dimensions, less one.
 int[] getMultipliers()
          Returns the multipliers as an array.
 
Methods inherited from class javax.media.jai.LookupTableJAI
getByteData, getByteData, getData, getDataType, getDestNumBands, getDestSampleModel, getDestSampleModel, getDoubleData, getDoubleData, getFloatData, getFloatData, getIntData, getIntData, getNumBands, getNumEntries, getOffset, getOffset, getOffsets, getShortData, getShortData, isIntegralDataType, isIntegralDataType, lookup, lookup, lookup, lookupDouble, lookupFloat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_496

public static final ColorCube BYTE_496
A ColorCube for dithering RGB byte data into 216 colors. The offset of this ColorCube is 38.


BYTE_855

public static final ColorCube BYTE_855
A ColorCube for dithering YCC byte data into 200 colors. The offset of this ColorCube is 54.

Constructor Detail

ColorCube

protected ColorCube(byte[][] data,
                    int offset)
Returns a multi-banded byte ColorCube with an index offset common to all bands.

Parameters:
data - The multi-banded byte data in [band][index] format.
offset - The common offset for all bands.
Throws:
IllegalArgumentException - if data is null.

ColorCube

protected ColorCube(short[][] data,
                    int offset,
                    boolean isUShort)
Returns a multi-banded short or unsigned short ColorCube with an index offset common to all bands.

Parameters:
data - The multi-banded short data in [band][index] format.
offset - The common offset for all bands.
isUShort - True if data type is DataBuffer.TYPE_USHORT; false if data type is DataBuffer.TYPE_SHORT.
Throws:
IllegalArgumentException - if data is null.

ColorCube

protected ColorCube(int[][] data,
                    int offset)
Returns a multi-banded int ColorCube with an index offset common to all bands.

Parameters:
data - The multi-banded int data in [band][index] format.
offset - The common offset for all bands.
Throws:
IllegalArgumentException - if data is null.

ColorCube

protected ColorCube(float[][] data,
                    int offset)
Returns a multi-banded float ColorCube with an index offset common to all bands.

Parameters:
data - The multi-banded float data in [band][index] format.
offset - The common offset for all bands.
Throws:
IllegalArgumentException - if data is null.

ColorCube

protected ColorCube(double[][] data,
                    int offset)
Returns a multi-banded double ColorCube with an index offset common to all bands.

Parameters:
data - The multi-banded double data in [band][index] format.
offset - The common offset for all bands.
Throws:
IllegalArgumentException - if data is null.
Method Detail

createColorCube

public static ColorCube createColorCube(int dataType,
                                        int offset,
                                        int[] dimension)
Returns a multi-banded ColorCube of a specified data type.

Parameters:
dataType - The data type of the ColorCube, one of DataBuffer.TYPE_BYTE, TYPE_SHORT, TYPE_USHORT, TYPE_INT, TYPE_FLOAT, or TYPE_DOUBLE.
offset - The common offset for all bands.
dimension - The signed dimension of each band.
Returns:
An appropriate ColorCube.
Throws:
RuntimeExceptions - for unsupported data types

createColorCube

public static ColorCube createColorCube(int dataType,
                                        int[] dimension)
Returns a multi-banded ColorCube of a specified data type with zero offset for all bands.

Parameters:
dataType - The data type of the ColorCube.
dimension - The signed dimension of each band.
Returns:
An appropriate ColorCube.
Throws:
IllegalArgumentException - if dimension is null.

getDimension

public int[] getDimension()
Returns the array of signed dimensions used to construct the ColorCube.


getDimsLessOne

public int[] getDimsLessOne()
Returns an array containing the signed dimensions, less one.


getMultipliers

public int[] getMultipliers()
Returns the multipliers as an array.


getAdjustedOffset

public int getAdjustedOffset()
Returns the adjusted offset into the lookup table, accounting for negative dimensions.


findNearestEntry

public int findNearestEntry(float[] pixel)
Finds the index of the nearest color in the color map to the pixel value argument.

Overrides:
findNearestEntry in class LookupTableJAI
Parameters:
pixel - a float array of all samples of a pixel.
Returns:
the index of the nearest color.
Throws:
RuntimeException - for dataTypes other than DataBuffer.TYPE_BYTE DataBuffer.TYPE_USHORT DataBuffer.TYPE_SHORT DataBuffer.TYPE_INT DataBuffer.TYPE_FLOAT DataBuffer.TYPE_DOUBLE