artofillusion.math
Class RGBColor

java.lang.Object
  extended by artofillusion.math.RGBColor

public class RGBColor
extends java.lang.Object

The RGBColor class is used to represent a color. This class uses floating point numbers (usually between 0 and 1) to store the red, green, and blue components, in contrast to java.awt.Color which uses integers.


Field Summary
 float blue
           
static float[] ERGB_EXP_SCALE
           
 float green
           
 float red
           
 
Constructor Summary
RGBColor()
          Construct a new RGBColor object with components 0,0,0.
RGBColor(java.io.DataInputStream in)
          Reconstruct an RGBColor based on its serialized representation.
RGBColor(double r, double g, double b)
          Construct a new RGBColor object with components r,g,b.
RGBColor(float r, float g, float b)
          Construct a new RGBColor object with components r,g,b.
 
Method Summary
 void add(float r, float g, float b)
          Add the specified values to the components of this color.
 void add(RGBColor color)
          Add another color to this one.
 void clip()
          Clip the components of this color so they lie between 0 and 1.
 void copy(RGBColor color)
          Make this object identical to another one.
 RGBColor duplicate()
          Create an exact duplicate of this object.
 boolean equals(java.lang.Object c)
          Determine whether two colors are identical.
 int getARGB()
          Get a representation of this color in the default Java color model.
 float getBlue()
          Get the value of the blue component.
 float getBrightness()
          Get the perceptual brightness of this color.
 java.awt.Color getColor()
          Get a java.awt.Color object representing this color.
 int getERGB()
          Calculate the ERGB representation of this color.
 float getGreen()
          Get the value of the green component.
 float[] getHLS()
          Get a representation of this color in the HLS color model.
 float[] getHSV()
          Get a representation of this color in the HSV color model.
 float getMaxComponent()
          Get the maximum value which any of the color components has.
 float getRed()
          Get the value of the red component.
 Widget getSample(int width, int height)
          Get a Widget which displays this color.
 float[] getYCrCb()
          Get a representation of this color in the YCrCb color model.
 int hashCode()
           
 void multiply(float r, float g, float b)
          Multiply the components of this color by the specified values.
 void multiply(RGBColor color)
          Multiply this color by another one.
 void scale(double s)
          Scale each component of this color by the specified amount.
 void scale(float s)
          Scale each component of this color by the specified amount.
 void setARGB(int color)
          Set the color based on a 32 bit ARGB value (the default Java color model).
 void setERGB(byte r, byte g, byte b, byte e)
          Set this color based on its representation in Greg Ward's ERGB format.
 void setERGB(int ergb)
          Set this color based on its representation in Greg Ward's ERGB format.
 void setHLS(float h, float l, float s)
          Set this color based on values in the HLS color model.
 void setHSV(float h, float s, float v)
          Set this color based on values in the HSV color model.
 void setRGB(double r, double g, double b)
          Set the red, green, and blue components to the specified values.
 void setRGB(float r, float g, float b)
          Set the red, green, and blue components to the specified values.
 void setYCrCb(float Y, float Cr, float Cb)
          Set this color based on values in the YCrCb color model.
 void subtract(float r, float g, float b)
          Subtract the specified values from the components of this color.
 void subtract(RGBColor color)
          Subtract another color from this one.
 java.lang.String toString()
          Create a string describing the color.
 void writeToFile(java.io.DataOutputStream out)
          Serialize this object to an output stream.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

red

public float red

green

public float green

blue

public float blue

ERGB_EXP_SCALE

public static final float[] ERGB_EXP_SCALE
Constructor Detail

RGBColor

public RGBColor()
Construct a new RGBColor object with components 0,0,0.


RGBColor

public RGBColor(float r,
                float g,
                float b)
Construct a new RGBColor object with components r,g,b.


RGBColor

public RGBColor(double r,
                double g,
                double b)
Construct a new RGBColor object with components r,g,b.


RGBColor

public RGBColor(java.io.DataInputStream in)
         throws java.io.IOException
Reconstruct an RGBColor based on its serialized representation.

Throws:
java.io.IOException
Method Detail

setRGB

public final void setRGB(float r,
                         float g,
                         float b)
Set the red, green, and blue components to the specified values.


setRGB

public final void setRGB(double r,
                         double g,
                         double b)
Set the red, green, and blue components to the specified values.


getRed

public final float getRed()
Get the value of the red component.


getGreen

public final float getGreen()
Get the value of the green component.


getBlue

public final float getBlue()
Get the value of the blue component.


equals

public boolean equals(java.lang.Object c)
Determine whether two colors are identical.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

duplicate

public final RGBColor duplicate()
Create an exact duplicate of this object.


copy

public final void copy(RGBColor color)
Make this object identical to another one.


getColor

public final java.awt.Color getColor()
Get a java.awt.Color object representing this color.


getSample

public Widget getSample(int width,
                        int height)
Get a Widget which displays this color.


getARGB

public final int getARGB()
Get a representation of this color in the default Java color model.


setARGB

public final void setARGB(int color)
Set the color based on a 32 bit ARGB value (the default Java color model).


add

public final void add(RGBColor color)
Add another color to this one.


subtract

public final void subtract(RGBColor color)
Subtract another color from this one.


multiply

public final void multiply(RGBColor color)
Multiply this color by another one.


add

public final void add(float r,
                      float g,
                      float b)
Add the specified values to the components of this color.


subtract

public final void subtract(float r,
                           float g,
                           float b)
Subtract the specified values from the components of this color.


multiply

public final void multiply(float r,
                           float g,
                           float b)
Multiply the components of this color by the specified values.


scale

public final void scale(float s)
Scale each component of this color by the specified amount.


scale

public final void scale(double s)
Scale each component of this color by the specified amount.


clip

public final void clip()
Clip the components of this color so they lie between 0 and 1.


getBrightness

public final float getBrightness()
Get the perceptual brightness of this color.


getMaxComponent

public final float getMaxComponent()
Get the maximum value which any of the color components has.


setHSV

public final void setHSV(float h,
                         float s,
                         float v)
Set this color based on values in the HSV color model. This routine is based on sample code given in "Computer Graphics: Principles and Practice, 2nd Edition", by Foley, van Dam, Feiner and Hughes, 1997.


getHSV

public final float[] getHSV()
Get a representation of this color in the HSV color model. This routine is based on sample code given in "Computer Graphics: Principles and Practice, 2nd Edition", by Foley, van Dam, Feiner and Hughes, 1997.


setHLS

public final void setHLS(float h,
                         float l,
                         float s)
Set this color based on values in the HLS color model. This routine is based on sample code given in "Computer Graphics: Principles and Practice, 2nd Edition", by Foley, van Dam, Feiner and Hughes, 1997. (A bug in their HLS to RGB routine has been corrected.)


getHLS

public final float[] getHLS()
Get a representation of this color in the HLS color model. This routine is based on sample code given in "Computer Graphics: Principles and Practice, 2nd Edition", by Foley, van Dam, Feiner and Hughes, 1997.


getERGB

public final int getERGB()
Calculate the ERGB representation of this color.


setERGB

public final void setERGB(int ergb)
Set this color based on its representation in Greg Ward's ERGB format.


setERGB

public final void setERGB(byte r,
                          byte g,
                          byte b,
                          byte e)
Set this color based on its representation in Greg Ward's ERGB format.


getYCrCb

public final float[] getYCrCb()
Get a representation of this color in the YCrCb color model.


setYCrCb

public final void setYCrCb(float Y,
                           float Cr,
                           float Cb)
Set this color based on values in the YCrCb color model.


writeToFile

public void writeToFile(java.io.DataOutputStream out)
                 throws java.io.IOException
Serialize this object to an output stream.

Throws:
java.io.IOException

toString

public java.lang.String toString()
Create a string describing the color.

Overrides:
toString in class java.lang.Object


Copyright © 1999-2011 by Peter Eastman.