javax.media.jai
Class LookupTableJAI

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

public class LookupTableJAI
extends Object
implements Serializable

A lookup table object associated with the "Lookup" operation. The "Lookup" operation is described in javax.media.jai.operator.LookupDescriptor.

This object represents a single- or multi-banded table of any JAI supported data type. A single- or multi-banded source image of integral data types is passed through the table and transformed into a single- or multi-banded destination image of either integral and floating point data types.

The table data may cover only a subrange of the legal range of the input data type. The subrange is selected by means of an offset parameter which is to be subtracted from the input value before indexing into the table array. When only a subranged table is used with a source image, it is up to the user to make certain that the source image does not have pixel values outside of the table range. Otherwise, an ArrayIndexOutOfBoundsException can occur.

The table data is saved by reference only.

See Also:
LookupDescriptor, Serialized Form

Constructor Summary
LookupTableJAI(byte[] data)
          Constructs a single-banded byte lookup table.
LookupTableJAI(byte[][] data)
          Constructs a multi-banded byte lookup table.
LookupTableJAI(byte[][] data, int offset)
          Constructs a multi-banded byte lookup table where all bands have the same index offset.
LookupTableJAI(byte[][] data, int[] offsets)
          Constructs a multi-banded byte lookup table where each band has a different index offset.
LookupTableJAI(byte[] data, int offset)
          Constructs a single-banded byte lookup table with an index offset.
LookupTableJAI(double[] data)
          Constructs a single-banded double lookup table.
LookupTableJAI(double[][] data)
          Constructs a multi-banded double lookup table.
LookupTableJAI(double[][] data, int offset)
          Constructs a multi-banded double lookup table where all bands have the same index offset.
LookupTableJAI(double[][] data, int[] offsets)
          Constructs a multi-banded double lookup table where each band has a different index offset.
LookupTableJAI(double[] data, int offset)
          Constructs a single-banded double lookup table with an index offset.
LookupTableJAI(float[] data)
          Constructs a single-banded float lookup table.
LookupTableJAI(float[][] data)
          Constructs a multi-banded float lookup table.
LookupTableJAI(float[][] data, int offset)
          Constructs a multi-banded float lookup table where all bands have the same index offset.
LookupTableJAI(float[][] data, int[] offsets)
          Constructs a multi-banded float lookup table where each band has a different index offset.
LookupTableJAI(float[] data, int offset)
          Constructs a single-banded float lookup table with an index offset.
LookupTableJAI(int[] data)
          Constructs a single-banded int lookup table.
LookupTableJAI(int[][] data)
          Constructs a multi-banded int lookup table.
LookupTableJAI(int[][] data, int offset)
          Constructs a multi-banded int lookup table where all bands have the same index offset.
LookupTableJAI(int[][] data, int[] offsets)
          Constructs a multi-banded int lookup table where each band has a different index offset.
LookupTableJAI(int[] data, int offset)
          Constructs a single-banded int lookup table with an index offset.
LookupTableJAI(short[][] data, boolean isUShort)
          Constructs a multi-banded short or unsigned short lookup table.
LookupTableJAI(short[][] data, int[] offsets, boolean isUShort)
          Constructs a multi-banded short or unsigned short lookup table where each band has a different index offset.
LookupTableJAI(short[][] data, int offset, boolean isUShort)
          Constructs a multi-banded short or unsigned short lookup table where all bands have the same index offset.
LookupTableJAI(short[] data, boolean isUShort)
          Constructs a single-banded short or unsigned short lookup table.
LookupTableJAI(short[] data, int offset, boolean isUShort)
          Constructs a single-banded short or unsigned short lookup table with an index offset.
 
Method Summary
 int findNearestEntry(float[] pixel)
          Determine which entry in the LookupTableJAI is closest in Euclidean distance to the argument pixel.
 byte[][] getByteData()
          Returns the byte table data in array format, or null if the table's data type is not byte.
 byte[] getByteData(int band)
          Returns the byte table data of a specific band in array format, or null if the table's data type is not byte.
 DataBuffer getData()
          Returns the table data as a DataBuffer.
 int getDataType()
          Returns the data type of the table data.
 int getDestNumBands(int srcNumBands)
          Returns the number of bands of the destination image, based on the number of bands of the source image and lookup table.
 SampleModel getDestSampleModel(SampleModel srcSampleModel)
          Returns a SampleModel suitable for holding the output of a lookup operation on the source data described by a given SampleModel with this table.
 SampleModel getDestSampleModel(SampleModel srcSampleModel, int width, int height)
          Returns a SampleModel suitable for holding the output of a lookup operation on the source data described by a given SampleModel with this table.
 double[][] getDoubleData()
          Returns the double table data in array format, or null if the table's data type is not double.
 double[] getDoubleData(int band)
          Returns the double table data of a specific band in array format, or null if table's data type is not double.
 float[][] getFloatData()
          Returns the float table data in array format, or null if the table's data type is not float.
 float[] getFloatData(int band)
          Returns the float table data of a specific band in array format, or null if table's data type is not float.
 int[][] getIntData()
          Returns the integer table data in array format, or null if the table's data type is not int.
 int[] getIntData(int band)
          Returns the integer table data of a specific band in array format, or null if table's data type is not int.
 int getNumBands()
          Returns the number of bands of the table.
 int getNumEntries()
          Returns the number of entries per band of the table.
 int getOffset()
          Returns the index offset of entry 0 for the default band.
 int getOffset(int band)
          Returns the index offset of entry 0 for a specific band.
 int[] getOffsets()
          Returns the index offsets of entry 0 for all bands.
 short[][] getShortData()
          Returns the short table data in array format, or null if the table's data type is not short.
 short[] getShortData(int band)
          Returns the short table data of a specific band in array format, or null if the table's data type is not short.
 boolean isIntegralDataType(int dataType)
          Returns true if the specified data type is an integral data type, such as byte, ushort, short, or int.
 boolean isIntegralDataType(SampleModel sampleModel)
          Validates data type.
 int lookup(int band, int value)
          Performs lookup on a given value belonging to a given source band, and returns the result as an int.
 WritableRaster lookup(Raster src, WritableRaster dst, Rectangle rect)
          Performs table lookup on a source Raster, writing the result into a supplied WritableRaster.
 WritableRaster lookup(WritableRaster src)
          Performs table lookup in place on a given WritableRaster.
 double lookupDouble(int band, int value)
          Performs lookup on a given value belonging to a given source band, and returns the result as a double.
 float lookupFloat(int band, int value)
          Performs lookup on a given value belonging to a given source band, and returns the result as a float.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LookupTableJAI

public LookupTableJAI(byte[] data)
Constructs a single-banded byte lookup table. The index offset is 0.

Parameters:
data - The single-banded byte data.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(byte[] data,
                      int offset)
Constructs a single-banded byte lookup table with an index offset.

Parameters:
data - The single-banded byte data.
offset - The offset.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(byte[][] data)
Constructs a multi-banded byte lookup table. The index offset for each band is 0.

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

LookupTableJAI

public LookupTableJAI(byte[][] data,
                      int offset)
Constructs a multi-banded byte lookup table where all bands have the same index offset.

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

LookupTableJAI

public LookupTableJAI(byte[][] data,
                      int[] offsets)
Constructs a multi-banded byte lookup table where each band has a different index offset.

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

LookupTableJAI

public LookupTableJAI(short[] data,
                      boolean isUShort)
Constructs a single-banded short or unsigned short lookup table. The index offset is 0.

Parameters:
data - The single-banded short data.
isUShort - True if data type is DataBuffer.TYPE_USHORT; false if data type is DataBuffer.TYPE_SHORT.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(short[] data,
                      int offset,
                      boolean isUShort)
Constructs a single-banded short or unsigned short lookup table with an index offset.

Parameters:
data - The single-banded short data.
offset - The offset.
isUShort - True if data type is DataBuffer.TYPE_USHORT; false if data type is DataBuffer.TYPE_SHORT.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(short[][] data,
                      boolean isUShort)
Constructs a multi-banded short or unsigned short lookup table. The index offset for each band is 0.

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

LookupTableJAI

public LookupTableJAI(short[][] data,
                      int offset,
                      boolean isUShort)
Constructs a multi-banded short or unsigned short lookup table where all bands have the same index offset.

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.

LookupTableJAI

public LookupTableJAI(short[][] data,
                      int[] offsets,
                      boolean isUShort)
Constructs a multi-banded short or unsigned short lookup table where each band has a different index offset.

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

LookupTableJAI

public LookupTableJAI(int[] data)
Constructs a single-banded int lookup table. The index offset is 0.

Parameters:
data - The single-banded int data.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(int[] data,
                      int offset)
Constructs a single-banded int lookup table with an index offset.

Parameters:
data - The single-banded int data.
offset - The offset.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(int[][] data)
Constructs a multi-banded int lookup table. The index offset for each band is 0.

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

LookupTableJAI

public LookupTableJAI(int[][] data,
                      int offset)
Constructs a multi-banded int lookup table where all bands have the same index offset.

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

LookupTableJAI

public LookupTableJAI(int[][] data,
                      int[] offsets)
Constructs a multi-banded int lookup table where each band has a different index offset.

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

LookupTableJAI

public LookupTableJAI(float[] data)
Constructs a single-banded float lookup table. The index offset is 0.

Parameters:
data - The single-banded float data.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(float[] data,
                      int offset)
Constructs a single-banded float lookup table with an index offset.

Parameters:
data - The single-banded float data.
offset - The offset.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(float[][] data)
Constructs a multi-banded float lookup table. The index offset for each band is 0.

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

LookupTableJAI

public LookupTableJAI(float[][] data,
                      int offset)
Constructs a multi-banded float lookup table where all bands have the same index offset.

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

LookupTableJAI

public LookupTableJAI(float[][] data,
                      int[] offsets)
Constructs a multi-banded float lookup table where each band has a different index offset.

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

LookupTableJAI

public LookupTableJAI(double[] data)
Constructs a single-banded double lookup table. The index offset is 0.

Parameters:
data - The single-banded double data.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(double[] data,
                      int offset)
Constructs a single-banded double lookup table with an index offset.

Parameters:
data - The single-banded double data.
offset - The offset.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(double[][] data)
Constructs a multi-banded double lookup table. The index offset for each band is 0.

Parameters:
data - The multi-banded double data in [band][index] format.
Throws:
IllegalArgumentException - if data is null.

LookupTableJAI

public LookupTableJAI(double[][] data,
                      int offset)
Constructs a multi-banded double lookup table where all bands have the same index offset.

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

LookupTableJAI

public LookupTableJAI(double[][] data,
                      int[] offsets)
Constructs a multi-banded double lookup table where each band has a different index offset.

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

getData

public DataBuffer getData()
Returns the table data as a DataBuffer.


getByteData

public byte[][] getByteData()
Returns the byte table data in array format, or null if the table's data type is not byte.


getByteData

public byte[] getByteData(int band)
Returns the byte table data of a specific band in array format, or null if the table's data type is not byte.


getShortData

public short[][] getShortData()
Returns the short table data in array format, or null if the table's data type is not short. This includes both signed and unsigned short table data.


getShortData

public short[] getShortData(int band)
Returns the short table data of a specific band in array format, or null if the table's data type is not short.


getIntData

public int[][] getIntData()
Returns the integer table data in array format, or null if the table's data type is not int.


getIntData

public int[] getIntData(int band)
Returns the integer table data of a specific band in array format, or null if table's data type is not int.


getFloatData

public float[][] getFloatData()
Returns the float table data in array format, or null if the table's data type is not float.


getFloatData

public float[] getFloatData(int band)
Returns the float table data of a specific band in array format, or null if table's data type is not float.


getDoubleData

public double[][] getDoubleData()
Returns the double table data in array format, or null if the table's data type is not double.


getDoubleData

public double[] getDoubleData(int band)
Returns the double table data of a specific band in array format, or null if table's data type is not double.


getOffsets

public int[] getOffsets()
Returns the index offsets of entry 0 for all bands.


getOffset

public int getOffset()
Returns the index offset of entry 0 for the default band.


getOffset

public int getOffset(int band)
Returns the index offset of entry 0 for a specific band.


getNumBands

public int getNumBands()
Returns the number of bands of the table.


getNumEntries

public int getNumEntries()
Returns the number of entries per band of the table.


getDataType

public int getDataType()
Returns the data type of the table data.


getDestNumBands

public int getDestNumBands(int srcNumBands)
Returns the number of bands of the destination image, based on the number of bands of the source image and lookup table.

Parameters:
srcNumBands - The number of bands of the source image.
Returns:
the number of bands in destination image.

getDestSampleModel

public SampleModel getDestSampleModel(SampleModel srcSampleModel)
Returns a SampleModel suitable for holding the output of a lookup operation on the source data described by a given SampleModel with this table. The width and height of the destination SampleModel are the same as that of the source. This method will return null if the source SampleModel has a non-integral data type.

Parameters:
srcSampleModel - The SampleModel of the source image.
Returns:
sampleModel suitable for the destination image.
Throws:
IllegalArgumentException - if srcSampleModel is null.

getDestSampleModel

public SampleModel getDestSampleModel(SampleModel srcSampleModel,
                                      int width,
                                      int height)
Returns a SampleModel suitable for holding the output of a lookup operation on the source data described by a given SampleModel with this table. This method will return null if the source SampleModel has a non-integral data type.

Parameters:
srcSampleModel - The SampleModel of the source image.
width - The width of the destination SampleModel.
height - The height of the destination SampleModel.
Returns:
sampleModel suitable for the destination image.
Throws:
IllegalArgumentException - if srcSampleModel is null.

isIntegralDataType

public boolean isIntegralDataType(SampleModel sampleModel)
Validates data type. Returns true if it's one of the integral data types; false otherwise.

Throws:
IllegalArgumentException - if sampleModel is null.

isIntegralDataType

public boolean isIntegralDataType(int dataType)
Returns true if the specified data type is an integral data type, such as byte, ushort, short, or int.


lookup

public int lookup(int band,
                  int value)
Performs lookup on a given value belonging to a given source band, and returns the result as an int.

Parameters:
band - The source band the value is from.
value - The source value to be placed through the lookup table.

lookupFloat

public float lookupFloat(int band,
                         int value)
Performs lookup on a given value belonging to a given source band, and returns the result as a float.

Parameters:
band - The source band the value is from.
value - The source value to be placed through the lookup table.

lookupDouble

public double lookupDouble(int band,
                           int value)
Performs lookup on a given value belonging to a given source band, and returns the result as a double.

Parameters:
band - The source band the value is from.
value - The source value to be placed through the lookup table.

lookup

public WritableRaster lookup(WritableRaster src)
Performs table lookup in place on a given WritableRaster. The The lookup operation must preserve the data type and SampleModel of the source. A reference to the supplied WritableRaster will be returned.

Throws:
IllegalArgumentException - if the src is null.
IllegalArgumentException - if the source's SampleModel is not of integral type.
IllegalArgumentException - if the lookup operation would result in a change in the data type or number of bands of the Raster.

lookup

public WritableRaster lookup(Raster src,
                             WritableRaster dst,
                             Rectangle rect)
Performs table lookup on a source Raster, writing the result into a supplied WritableRaster. The destination must have a data type and SampleModel appropriate to the results of the lookup operation. The table lookup operation is performed within a specified rectangle.

The dst argument may be null, in which case a new WritableRaster is created using the appropriate SampleModel.

The rectangle of interest may be null, in which case the operation will be performed on the intersection of the source and destination bounding rectangles.

Parameters:
src - A Raster containing the source pixel data.
dst - The WritableRaster to be computed, or null. If supplied, its data type and number of bands must be suitable for the source and lookup table.
rect - The rectangle within the tile to be computed. If rect is null, the intersection of the source and destination bounds will be used. Otherwise, it will be clipped to the intersection of the source and destination bounds.
Returns:
A reference to the supplied WritableRaster, or to a new WritableRaster if the supplied one was null.
Throws:
IllegalArgumentException - if the source is null.
IllegalArgumentException - if the source's SampleModel is not of integral type.
IllegalArgumentException - if the destination's data type or number of bands differ from those returned by getDataType() and getDestNumBands().

findNearestEntry

public int findNearestEntry(float[] pixel)
Determine which entry in the LookupTableJAI is closest in Euclidean distance to the argument pixel.

Parameters:
pixel - The pixel the closest entry to which is to be found.
Returns:
the index of the closest entry. If the data array of the lookup table is in the format data[numBands][numEntries], then the value v for band b of the closest entry is
     v = data[b][index - lookup.getOffset()]
 
where index is the returned value of this method.
Throws:
IllegalArgumentException - if pixel is null.