raja
Class RGB

java.lang.Object
  |
  +--raja.RGB
All Implemented Interfaces:
Serializable, Writable

public class RGB
extends Object
implements Serializable, Writable

A class to encapsulate a high precision wavelength-dependent nonnegative value. The wavelength-dependent nonnegative value is defined by its samples at the Red, Green and Blue wavelengths. The samples can be any nonnegative double value; in particular, Double#POSITIVE_INFINITY is allowed. Note that for a color the samples should range from 0 to 1 (see getColor()).

See Also:
Color, Serialized Form

Field Summary
static RGB black
          The RGB wavelength-dependent value corresponding to the black color.
static RGB blue
          The RGB wavelength-dependent value corresponding to the blue color.
static RGB cyan
          The RGB wavelength-dependent value corresponding to the cyan color.
static RGB green
          The RGB wavelength-dependent value corresponding to the green color.
static RGB magenta
          The RGB wavelength-dependent value corresponding to the magenta color.
static RGB red
          The RGB wavelength-dependent value corresponding to the red color.
static RGB white
          The RGB wavelength-dependent value corresponding to the white color.
static RGB yellow
          The RGB wavelength-dependent value corresponding to the yellow color.
 
Constructor Summary
RGB(Color c)
          Creates an RGB wavelength-dependent value corresponding to the specified Color.
RGB(double c)
          Creates an RGB constant value initialized with the specified double value.
RGB(double r, double g, double b)
          Creates an RGB wavelength-dependent value initialized with the specified red, green, and blue samples.
 
Method Summary
static Object build(ObjectReader reader)
          Creates an RGB object from the specified ObjectReader.
 boolean equals(Object obj)
          Compares this object to the specified object.
 Color getColor()
          Returns the Color corresponding to this RGB wavelength-dependent value.
static RGB inverse(RGB rgb)
          Computes the componentwise inverse of the specified RGB wavelength-dependent value.
 boolean isSmaller(RGB rgb)
          Compares this RGB wavelength-dependent value with the specified RGB wavelength-dependent value.
static RGB max(RGB rgb1, RGB rgb2)
          Computes the componentwise max of the two specified RGB wavelength-dependent values.
static RGB product(RGB rgb, double f)
          Computes the product of the specified RGB wavelength-dependent value with the specified double factor.
static RGB product(RGB rgb1, RGB rgb2)
          Computes the componentwise product of the two specified RGB wavelength-dependent values.
static RGB sum(RGB rgb1, RGB rgb2)
          Computes the componentwise sum of the two specified RGB wavelength-dependent values.
 String toString()
          Returns a textual String representation of this RGB object.
 void write(ObjectWriter writer)
          Writes the contents of this RGB object to the specified ObjectWriter.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

black

public static final RGB black
The RGB wavelength-dependent value corresponding to the black color.

blue

public static final RGB blue
The RGB wavelength-dependent value corresponding to the blue color.

cyan

public static final RGB cyan
The RGB wavelength-dependent value corresponding to the cyan color.

green

public static final RGB green
The RGB wavelength-dependent value corresponding to the green color.

magenta

public static final RGB magenta
The RGB wavelength-dependent value corresponding to the magenta color.

red

public static final RGB red
The RGB wavelength-dependent value corresponding to the red color.

yellow

public static final RGB yellow
The RGB wavelength-dependent value corresponding to the yellow color.

white

public static final RGB white
The RGB wavelength-dependent value corresponding to the white color.
Constructor Detail

RGB

public RGB(double r,
           double g,
           double b)
Creates an RGB wavelength-dependent value initialized with the specified red, green, and blue samples.
Parameters:
r - a nonnegative double value corresponding to the red sample.
g - a nonnegative double value corresponding to the green sample.
b - a nonnegative double value corresponding to the blue sample.

RGB

public RGB(double c)
Creates an RGB constant value initialized with the specified double value.
Parameters:
c - a nonnegative double value.

RGB

public RGB(Color c)
Creates an RGB wavelength-dependent value corresponding to the specified Color.
Parameters:
c - the color to be represented by the RGB object.
See Also:
getColor()
Method Detail

build

public static Object build(ObjectReader reader)
                    throws IOException
Creates an RGB object from the specified ObjectReader.
Parameters:
reader - the ObjectReader to read the fields from.

equals

public boolean equals(Object obj)
Compares this object to the specified object. The result is true if and only if the argument is not null and is an RGB object that represents the same wavelength-dependent value as this object (i.e. their samples are the same).
Overrides:
equals in class Object
Parameters:
obj - the object to compare with.
Returns:
true if the objects are the same; false otherwise.

sum

public static RGB sum(RGB rgb1,
                      RGB rgb2)
Computes the componentwise sum of the two specified RGB wavelength-dependent values.
Parameters:
rgb1, rgb2 - the RGB wavelength-dependent values to sum.
Returns:
an instance of RGB that is the componentwise sum of the two specified RGB wavelength-dependent values.

product

public static RGB product(RGB rgb1,
                          RGB rgb2)
Computes the componentwise product of the two specified RGB wavelength-dependent values.
Parameters:
rgb1, rgb2 - the RGB wavelength-dependent values to product.
Returns:
an instance of RGB that is the componentwise product of the two specified RGB wavelength-dependent values.

product

public static RGB product(RGB rgb,
                          double f)
Computes the product of the specified RGB wavelength-dependent value with the specified double factor.
Parameters:
rgb - the RGB wavelength-dependent value to product with.
f - the double factor.
Returns:
an instance of RGB that is the product of the specified RGB wavelength-dependent value with the specified double factor.

max

public static RGB max(RGB rgb1,
                      RGB rgb2)
Computes the componentwise max of the two specified RGB wavelength-dependent values.
Parameters:
rgb1, rgb2 - the RGB values to compare.
Returns:
an instance of RGB that is the componentwise max of the two specified RGB wavelength-dependent values.

inverse

public static RGB inverse(RGB rgb)
Computes the componentwise inverse of the specified RGB wavelength-dependent value. The inverse of a zero sample is Double#POSITIVE_INFINITY.
Parameters:
rgb - the RGB value to inverse.
Returns:
an instance of RGB that is the componentwise inverse of the specified RGB wavelength-dependent value.

isSmaller

public boolean isSmaller(RGB rgb)
Compares this RGB wavelength-dependent value with the specified RGB wavelength-dependent value.
Parameters:
rgb - the RGB value to compare with.
Returns:
true if this RGB wavelength-dependent value is smaller than the specified RGB wavelength-dependent value; false otherwise.

getColor

public Color getColor()
Returns the Color corresponding to this RGB wavelength-dependent value. Each sample greater than 1 is truncated to 1 as this is the maximal value for a Color's component.
Returns:
a Color object corresponding to this RGB wavelength-dependent value.

toString

public String toString()
Returns a textual String representation of this RGB object.
Overrides:
toString in class Object

write

public void write(ObjectWriter writer)
           throws IOException
Writes the contents of this RGB object to the specified ObjectWriter.
Specified by:
write in interface Writable
Parameters:
writer - the ObjectWriter to write the fields to.