psychWithJava
Class CLUT

java.lang.Object
  extended by psychWithJava.CLUT

public class CLUT
extends java.lang.Object

Provides methods to perform (inverse) color lookup operations.

Author:
Huseyin Boyaci

Constructor Summary
CLUT(double[] table)
          Constructs a CLUT object for an 8 bit video display system.
CLUT(double[] table, int bits)
          Constructs a CLUT object for a system with an arbitrary number of bits.
CLUT(java.lang.String filename)
          Constructs a CLUT object for an 8 bit video display system.
CLUT(java.lang.String filename, int bits)
          Constructs a CLUT object for a system with an arbitrary number of bits.
 
Method Summary
 double getMaxLum()
          returns the maximum available luminance
 int lum2Pix(double lum)
          Returns the pixel whose luminance is CLOSEST to the required luminance.
 int lum2Pix(int lum)
          Returns the pixel whose luminance is CLOSEST to the required luminance.
 double pix2Lum(int pixel)
          Returns the RELATIVE luminance of the given pixel.
 void setClut(double[] table)
          Sets a new color look-up table (CLUT).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CLUT

public CLUT(java.lang.String filename)
Constructs a CLUT object for an 8 bit video display system. A file with name "filename" contains the 28=256 luminance values, one for each pixel from 255 to 0 in descending order. The file may contain the absolute luminance values, but by default CLUT stores and works with relative values between 0.0 and 255.0.

Parameters:
filename - the name of the file containing luminance values for all pixels from 255 to 0 in descending order.
Throws:
java.lang.IllegalArgumentException - if the file has different number of elements than 256

CLUT

public CLUT(double[] table)
Constructs a CLUT object for an 8 bit video display system. A double array "table" contains the 28=256 luminance values, one for each pixel from 255 to 0 in descending order. The table may contain the absolute luminance values, but by default CLUT stores and works with relative values between 0.0 and 255.0.

Parameters:
table - the double array containing luminance values for all pixels from 255 to 0 in descending order.
Throws:
java.lang.IllegalArgumentException - if the file has different number of elements than 256

CLUT

public CLUT(java.lang.String filename,
            int bits)
     throws java.lang.IllegalArgumentException
Constructs a CLUT object for a system with an arbitrary number of bits. File with name "filename" contains the 2bits lines of luminance values for each pixel from 2bits-1 to 0 in descending order. The file may contain the absolute luminance values, but by default CLUT stores and works with relative values between 0.0 and 2bits-1.

Parameters:
filename - the name of the file containing luminance values for all pixels from 2bits-1 to 0 in descending order.
bits - number of bits of the system.
Throws:
java.lang.IllegalArgumentException

CLUT

public CLUT(double[] table,
            int bits)
     throws java.lang.IllegalArgumentException
Constructs a CLUT object for a system with an arbitrary number of bits. Double array table contains the 2bits luminance values for each pixel from 2bits-1 to 0 in descending order. The table may contain the absolute luminance values, but by default CLUT stores and works with relative values between 0.0 and 2bits-1.

Parameters:
table - the double array containing luminance values for all pixels from 2bits-1 to 0 in descending order.
bits - number of bits of the system.
Throws:
java.lang.IllegalArgumentException
Method Detail

setClut

public void setClut(double[] table)
Sets a new color look-up table (CLUT).

Parameters:
table - new look-up table

getMaxLum

public double getMaxLum()
returns the maximum available luminance

Returns:
maximum luminance

lum2Pix

public int lum2Pix(double lum)
Returns the pixel whose luminance is CLOSEST to the required luminance. This is a slower but more precise lookup for real (non-whole) values between 0 and 2bits-1

Parameters:
lum - required Luminance (real number, i.e. double)
Returns:
pixel whose luminance is the closest to required Luminance

lum2Pix

public int lum2Pix(int lum)
Returns the pixel whose luminance is CLOSEST to the required luminance. This is a faster lookup for whole numbers between 0 and 2bits-1.

Parameters:
lum - required Luminance (whole number, integer)
Returns:
pixel whose luminance is the closest to required Luminance

pix2Lum

public double pix2Lum(int pixel)
Returns the RELATIVE luminance of the given pixel. The relative value is between 0 and 2bits-1 (not 0 and 1)

Parameters:
pixel - whose luminance is sought
Returns:
Luminance8 of the pixel