com.tensegrity.graphics.color
Class ColorUtilities

java.lang.Object
  extended bycom.tensegrity.graphics.color.ColorUtilities

public class ColorUtilities
extends java.lang.Object

The ColorUtilities class provides the generic functionalities needed to work with colors.

Version:
$Id: ColorUtilities.java,v 1.13 2005/08/31 09:58:19 BurkhardWick Exp $
Author:
MichaelKegel

Field Summary
static java.awt.Color[] awtColors
          An Array of all AWT based colors.
static int BLACK
          enumeration that defines standard color
static int BLUE
          enumeration that defines standard color
static java.awt.Color[] colorCacheDefault
          An Array of 64 basic colors.
static int CYAN
          enumeration that defines standard color
static int DARKGRAY
          enumeration that defines standard color
static int GRAY
          enumeration that defines standard color
static int GREEN
          enumeration that defines standard color
static int INDEX_ALPHA
          constant that tells about a component of a color within an array
static int INDEX_BLUE
          constant that tells about a component of a color within an array
static int INDEX_BRIGHTNESS
          constant that tells about a component of a color within an array
static int INDEX_GREEN
          constant that tells about a component of a color within an array
static int INDEX_HUE
          constant that tells about a component of a color within an array
static int INDEX_RED
          constant that tells about a component of a color within an array
static int INDEX_SATURATION
          constant that tells about a component of a color within an array
static int LIGHTGRAY
          enumeration that defines standard color
static int MAGENTA
          enumeration that defines standard color
static int ORANGE
          enumeration that defines standard color
static int PINK
          enumeration that defines standard color
static int RED
          enumeration that defines standard color
static int[] webColorsLookup
          A webcolor-lookup-table.
static int WHITE
          enumeration that defines standard color
static int YELLOW
          enumeration that defines standard color
 
Method Summary
static int blend(int color1, int color2, int opacity)
          This method will blend two colors with the given factor.
static java.awt.Color brighter(java.awt.Color c)
          Similar to Color.brighter(), but with a different FACTOR.
static int getHue(int color)
          Returns the hue value of a given color instance as int.
static int getLuminance(int color)
          Returns the luminance value of a color.
static int getRGBbyHue(int color, int hue)
          Returns a Color based on rgb scheme with the given hue.
static int getRGBbyLuminance(int color, int luminance)
          Returns a Color based on rgb scheme with the given luminance.
static int getRGBbyLuminanceWeb(int color, int luminance)
          Takes a color value, changes its luminance value and then returns the webcompliant color instance of it.
static int getRGBColor(int[] components)
          returns the color value for the given color components. the indice are defined by INDEX_ALPHA, INDEX_RED, INDEX_GREEN and INDEX_BLUE.
static int getRGBColor(int r, int g, int b)
          returns the color value for the given color components.
static int getRGBColor(int r, int g, int b, int alpha)
          returns the color value for the given color components.
static int[] getRGBComponents(int color)
          returns the itemized components of the given color. the indices of the components in the array are defined by INDEX_ALPHA, INDEX_RED, INDEX_GREEN and INDEX_BLUE.
static int HSBtoRGB(float hue, float saturation, float brightness)
          Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the RGB model.
static void HSBtoRGB(float hue, float saturation, float brightness, int[] rgb)
           
static int HSBtoRGBOptimized(float h, float f, float saturation, float brightness)
          Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the RGB model.
static int HSBtoRGBWeb(float hue, float saturation, float brightness)
          Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the RGB model.
static boolean isLight(int color)
          Returns true if the luminance value is greater then 128.
static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals)
          Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.
static int RGBtoWeb(int r, int g, int b)
          Returns the web color representation of the given rgb color.
static int setHue(int color, int hue)
          Sets the hue value of the given color to the specified int.
static int setLuminance(int color, int lum)
          Creates a new color with the given luminance level and returns a rgb int to reflect the change.
static java.lang.String toString(int color)
          Method toString returns a formatted string representing the given color index in human readable form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLACK

public static final int BLACK
enumeration that defines standard color

See Also:
Constant Field Values

WHITE

public static final int WHITE
enumeration that defines standard color

See Also:
Constant Field Values

LIGHTGRAY

public static final int LIGHTGRAY
enumeration that defines standard color

See Also:
Constant Field Values

GRAY

public static final int GRAY
enumeration that defines standard color

See Also:
Constant Field Values

DARKGRAY

public static final int DARKGRAY
enumeration that defines standard color

See Also:
Constant Field Values

RED

public static final int RED
enumeration that defines standard color

See Also:
Constant Field Values

GREEN

public static final int GREEN
enumeration that defines standard color

See Also:
Constant Field Values

BLUE

public static final int BLUE
enumeration that defines standard color

See Also:
Constant Field Values

YELLOW

public static final int YELLOW
enumeration that defines standard color

See Also:
Constant Field Values

MAGENTA

public static final int MAGENTA
enumeration that defines standard color

See Also:
Constant Field Values

CYAN

public static final int CYAN
enumeration that defines standard color

See Also:
Constant Field Values

PINK

public static final int PINK
enumeration that defines standard color

See Also:
Constant Field Values

ORANGE

public static final int ORANGE
enumeration that defines standard color

See Also:
Constant Field Values

INDEX_ALPHA

public static final int INDEX_ALPHA
constant that tells about a component of a color within an array

See Also:
Constant Field Values

INDEX_RED

public static final int INDEX_RED
constant that tells about a component of a color within an array

See Also:
Constant Field Values

INDEX_GREEN

public static final int INDEX_GREEN
constant that tells about a component of a color within an array

See Also:
Constant Field Values

INDEX_BLUE

public static final int INDEX_BLUE
constant that tells about a component of a color within an array

See Also:
Constant Field Values

INDEX_HUE

public static final int INDEX_HUE
constant that tells about a component of a color within an array

See Also:
Constant Field Values

INDEX_SATURATION

public static final int INDEX_SATURATION
constant that tells about a component of a color within an array

See Also:
Constant Field Values

INDEX_BRIGHTNESS

public static final int INDEX_BRIGHTNESS
constant that tells about a component of a color within an array

See Also:
Constant Field Values

awtColors

public static final java.awt.Color[] awtColors
An Array of all AWT based colors.


colorCacheDefault

public static final java.awt.Color[] colorCacheDefault
An Array of 64 basic colors.


webColorsLookup

public static int[] webColorsLookup
A webcolor-lookup-table. Matches a value between 0 and 255 to its corresponding webcolor-value.

Method Detail

getRGBComponents

public static final int[] getRGBComponents(int color)
returns the itemized components of the given color. the indices of the components in the array are defined by INDEX_ALPHA, INDEX_RED, INDEX_GREEN and INDEX_BLUE.

Parameters:
color - the color to extract the components from
Returns:
int[] the itemized components of the color

getRGBColor

public static final int getRGBColor(int[] components)
returns the color value for the given color components. the indice are defined by INDEX_ALPHA, INDEX_RED, INDEX_GREEN and INDEX_BLUE.

Parameters:
components - the components of the color
Returns:
int the color value

getRGBColor

public static int getRGBColor(int r,
                              int g,
                              int b)
returns the color value for the given color components.

Parameters:
r - The red component of the color
g - The green component of the color
b - The blue component of the color
Returns:
int the color value

getRGBColor

public static int getRGBColor(int r,
                              int g,
                              int b,
                              int alpha)
returns the color value for the given color components.

Parameters:
r - The red component of the color
g - The green component of the color
b - The blue component of the color
alpha - The alpha component of the color
Returns:
int the color value

getRGBbyHue

public static final int getRGBbyHue(int color,
                                    int hue)
Returns a Color based on rgb scheme with the given hue.


getRGBbyLuminance

public static final int getRGBbyLuminance(int color,
                                          int luminance)
Returns a Color based on rgb scheme with the given luminance.


getRGBbyLuminanceWeb

public static final int getRGBbyLuminanceWeb(int color,
                                             int luminance)
Takes a color value, changes its luminance value and then returns the webcompliant color instance of it.


isLight

public static final boolean isLight(int color)
Returns true if the luminance value is greater then 128.

Returns:
boolean true, if color's luminance exceeds 128.

getHue

public static final int getHue(int color)
Returns the hue value of a given color instance as int.


setHue

public static final int setHue(int color,
                               int hue)
Sets the hue value of the given color to the specified int. Implicitly converts the int to float and returns a rgb int representing the new color.


getLuminance

public static final int getLuminance(int color)
Returns the luminance value of a color.


setLuminance

public static final int setLuminance(int color,
                                     int lum)
Creates a new color with the given luminance level and returns a rgb int to reflect the change.


HSBtoRGB

public static final int HSBtoRGB(float hue,
                                 float saturation,
                                 float brightness)
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the RGB model.

The saturation and brightness components should be floating-point values between zero and one (numbers in the range 0.0-1.0). The hue component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.

The integer that is returned by HSBtoRGB encodes the value of a color in bits 0-23 of an integer value.

Parameters:
hue - the hue component of the color
saturation - the saturation of the color
brightness - the brightness of the color
Returns:
the RGB value of the color with the indicated hue, saturation, and brightness.

HSBtoRGB

public static final void HSBtoRGB(float hue,
                                  float saturation,
                                  float brightness,
                                  int[] rgb)

RGBtoHSB

public static final float[] RGBtoHSB(int r,
                                     int g,
                                     int b,
                                     float[] hsbvals)
Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.

If the hsbvals argument is null, then a new array is allocated to return the result. Otherwise, the method returns the array hsbvals, with the values put into that array.

the indices of the components in the array are defined by INDEX_HUE, INDEX_SATURATION and INDEX_BRIGHTNESS.

Parameters:
r - the red component of the color
g - the green component of the color
b - the blue component of the color
hsbvals - the array used to return the three HSB values, or null
Returns:
an array of three elements containing the hue, saturation, and brightness (in that order), of the color with the indicated red, green, and blue components.

HSBtoRGBOptimized

public static final int HSBtoRGBOptimized(float h,
                                          float f,
                                          float saturation,
                                          float brightness)
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the RGB model.

The saturation and brightness components should be floating-point values between zero and one (numbers in the range 0.0-1.0). The hue component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.

The integer that is returned by HSBtoRGB encodes the value of a color in bits 0-23 of an integer value.

Parameters:
saturation - the saturation of the color
brightness - the brightness of the color
Returns:
the RGB value of the color with the indicated hue, saturation, and brightness.

HSBtoRGBWeb

public static final int HSBtoRGBWeb(float hue,
                                    float saturation,
                                    float brightness)
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the RGB model.

The saturation and brightness components should be floating-point values between zero and one (numbers in the range 0.0-1.0). The hue component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.

The integer that is returned by HSBtoRGB encodes the value of a color in bits 0-23 of an integer value.

Parameters:
hue - the hue component of the color
saturation - the saturation of the color
brightness - the brightness of the color
Returns:
the RGB value of the color with the indicated hue, saturation, and brightness.
See Also:
Color.getRGB(), Color.Color(int), ColorModel.getRGBdefault()

RGBtoWeb

public static final int RGBtoWeb(int r,
                                 int g,
                                 int b)
Returns the web color representation of the given rgb color.

Parameters:
r - The red component
g - The green component
b - The blue component
Returns:
the web color representation of the given rgb color.

blend

public static final int blend(int color1,
                              int color2,
                              int opacity)
This method will blend two colors with the given factor. The factor must be in the interval [0,255].

Parameters:
color1 - the input color 1.
color2 - the input color 2.
opacity - the blending between 0 and 255 inclusive.
Returns:
the slightly darker color.

brighter

public static java.awt.Color brighter(java.awt.Color c)
Similar to Color.brighter(), but with a different FACTOR.


toString

public static final java.lang.String toString(int color)
Method toString returns a formatted string representing the given color index in human readable form.

Parameters:
color - the color defined by an int.
Returns:
String the formatted string with (r,g,b,a)


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.