public final class Color
extends java.lang.Object
Color class is used to encapsulate colors in the default sRGB color space.
This class is immutable and therefore suitable for concurrent use without external synchronization.
| Modifier and Type | Field and Description |
|---|---|
float |
a
The value of the alpha component (A).
|
float |
b
The value of the blue component (B).
|
static Color |
BLACK
A
Color denoting the color black. |
static Color |
BLUE
A
Color denoting the color blue. |
static Color |
CYAN
A
Color denoting the color cyan. |
static float |
DEFAULT_GAMMA
The default gamma used in gamma correction.
|
float |
g
The value of the green component (G).
|
static Color |
GRAY
A
Color denoting the color gray. |
static Color |
GREEN
A
Color denoting the color green. |
static Color |
MAGENTA
A
Color denoting the color magenta. |
static Color |
ORANGE
A
Color denoting the color orange. |
float |
r
The value of the red component (R).
|
static Color |
RED
A
Color denoting the color red. |
static Color |
TRANSPARENT
A
Color denoting total transparency. |
static Color |
WHITE
A
Color denoting the color white. |
static Color |
YELLOW
A
Color denoting the color yellow. |
| Constructor and Description |
|---|
Color()
Constructs a new
Color instance denoting the color black. |
Color(float r,
float g,
float b)
Constructs a new
Color instance given the specified components. |
Color(float r,
float g,
float b,
float a)
Constructs a new
Color instance given the specified components. |
Color(int rGB)
Constructs a new
Color instance given the specified RGB-value. |
Color(int r,
int g,
int b)
Constructs a new
Color instance given the specified RGB-values. |
Color(int r,
int g,
int b,
int a)
Constructs a new
Color instance given the specified RGBA-values. |
| Modifier and Type | Method and Description |
|---|---|
Color |
add(Color color)
Adds
color to this Color instance. |
Color |
add(float s)
Adds
s to the R-, G- and B-component values of this Color instance. |
Color |
add(float r,
float g,
float b)
Adds
r, g and b to the R-, G- and B-component values of this Color instance, respectively. |
Color |
add(float r,
float g,
float b,
float a)
Adds
r, g, b and a to the R-, G-, B- and A-component values of this Color instance, respectively. |
Color |
applyGammaCorrection()
Applies Gamma Correction to this
Color instance. |
Color |
applyGammaCorrection(float gamma)
Applies Gamma Correction to this
Color instance. |
Color |
applyToneMapping()
Applies Tone Mapping to this
Color instance. |
Color |
applyToneMapping(ToneMapper toneMapper)
Applies Tone Mapping to this
Color instance. |
float |
average()
Returns the average value of the RGB-component values of this
Color instance. |
Color |
constrain()
Constrains this
Color instance to be representable. |
Color |
divide(Color color)
Divides this
Color instance with color. |
Color |
divide(float s)
Divides the R-, G- and B-component values of this
Color instance with s. |
Color |
divide(float r,
float g,
float b)
Divides the R-, G- and B-component values of this
Color instance with r, g and b, respectively. |
Color |
divide(float r,
float g,
float b,
float a)
Divides the R-, G-, B- and A-component values of this
Color instance with r, g, b and a, respectively. |
boolean |
equals(java.lang.Object object)
Compares
object to this Color instance for equality. |
Color |
exp()
Returns a new
Color instance with Euler's number e raised to the power of each RGB-component value. |
float |
getA()
Returns the value of the A component.
|
float |
getB()
Returns the value of the B component.
|
float |
getG()
Returns the value of the G component.
|
float |
getR()
Returns the value of the R component.
|
int |
hashCode()
Returns a hash code for this
Color instance. |
boolean |
isBlack()
Returns
true if, and only if, this Color denotes the color black, false otherwise. |
float |
luminance()
Returns the luminance of this
Color instance. |
Color |
makeDisplayCompatible()
Makes this
Color instance display compatible. |
Color |
makeDisplayCompatible(float gamma)
Makes this
Color instance display compatible. |
Color |
makeDisplayCompatible(float gamma,
ToneMapper toneMapper)
Makes this
Color instance display compatible. |
Color |
makeDisplayCompatible(ToneMapper toneMapper)
Makes this
Color instance display compatible. |
float |
max()
Returns the maximum RGB-component value of this
Color instance. |
float |
min()
Returns the minimum RGB-component value of this
Color instance. |
Color |
multiply(Color color)
Multiplies this
Color instance with color. |
Color |
multiply(float s)
Multiplies the R-, G- and B-component values of this
Color instance with s. |
Color |
multiply(float r,
float g,
float b)
Multiplies the R-, G- and B-component values of this
Color instance with r, g and b, respectively. |
Color |
multiply(float r,
float g,
float b,
float a)
Multiplies the R-, G-, B- and A-component values of this
Color instance with r, g, b and a, respectively. |
Color |
negate()
Returns a new
Color instance with each RGB-component value negated. |
Color |
pow(Color color)
Returns a new
Color instance with the R-, G- and B-component values of this Color instance raised to the power of the R-, G- and B-component values of color, respectively. |
Color |
pow(float exponent)
Returns a new
Color instance with the R-, G- and B-component values of this Color instance raised to the power of exponent. |
Color |
pow(float r,
float g,
float b)
Returns a new
Color instance with the R-, G- and B-component values of this Color instance raised to the power of r, g and b, respectively. |
Color |
pow(float r,
float g,
float b,
float a)
Returns a new
Color instance with the R-, G-, B- and A-component values of this Color instance raised to the power of r, g, b and a, respectively. |
Color |
redoGammaCorrection(ColorSpace colorSpace)
Call this method to redo Gamma Correction using the specified
ColorSpace. |
Color |
saturate(float min,
float max)
Saturates this
Color instance, such that each component value will lie in the range [min, max]. |
Color |
sqrt()
Returns a new
Color instance with the square root performed on each RGB-component value. |
Color |
subtract(Color color)
Subtracts this
Color instance with color. |
Color |
subtract(float s)
Subtracts
s from the R-, G- and B-component values of this Color instance. |
Color |
subtract(float r,
float g,
float b)
Subtracts the R-, G- and B-component values of this
Color instance with r, g and b, respectively. |
Color |
subtract(float r,
float g,
float b,
float a)
Subtracts the R-, G-, B- and A-component values of this
Color instance with r, g, b and a, respectively. |
static int |
toA(int aRGB)
Returns the A component value of
aRGB. |
int |
toARGB()
Returns an
int representation of the ARGB-component values of this Color instance. |
static int |
toB(int rGB)
Returns the B component value of
rGB. |
static int |
toG(int rGB)
Returns the G component value of
rGB. |
static int |
toR(int rGB)
Returns the R component value of
rGB. |
int |
toRGB()
Returns an
int representation of the RGB-component values of this Color instance. |
static int |
toRGB(int r,
int g,
int b)
Returns an
int with the R-, G- and B-component values. |
java.lang.String |
toString()
Returns a
String representation of this Color instance. |
Color |
undoGammaCorrection(ColorSpace colorSpace)
Call this method to undo Gamma Correction using the specified
ColorSpace. |
public static final Color BLACK
Color denoting the color black.public static final Color BLUE
Color denoting the color blue.public static final Color CYAN
Color denoting the color cyan.public static final Color GRAY
Color denoting the color gray.public static final Color GREEN
Color denoting the color green.public static final Color MAGENTA
Color denoting the color magenta.public static final Color ORANGE
Color denoting the color orange.public static final Color RED
Color denoting the color red.public static final Color TRANSPARENT
Color denoting total transparency.public static final Color WHITE
Color denoting the color white.public static final Color YELLOW
Color denoting the color yellow.public static final float DEFAULT_GAMMA
public final float a
public final float b
public final float g
public final float r
public Color()
Color instance denoting the color black.public Color(float r,
float g,
float b)
Color instance given the specified components.
Calling this constructor is equivalent to calling new Color(r, g, b, 1.0F).
r - the value of the red component (R)g - the value of the green component (G)b - the value of the blue component (B)public Color(float r,
float g,
float b,
float a)
Color instance given the specified components.r - the value of the red component (R)g - the value of the green component (G)b - the value of the blue component (B)a - the value of the alpha component (A)public Color(int rGB)
Color instance given the specified RGB-value.rGB - the RGB-valuepublic Color(int r,
int g,
int b)
Color instance given the specified RGB-values.
Calling this constructor is equivalent to calling new Color(r, g, b, 255).
r - the value of the red component (R)g - the value of the green component (G)b - the value of the blue component (B)public Color(int r,
int g,
int b,
int a)
Color instance given the specified RGBA-values.r - the value of the red component (R)g - the value of the green component (G)b - the value of the blue component (B)a - the value of the alpha component (A)public Color add(Color color)
color to this Color instance.
Returns a new Color instance with the result of the addition.
If color is null, a NullPointerException will be thrown.
color - the Color to add to this Color instanceColor instance with the result of the additionjava.lang.NullPointerException - thrown if, and only if, color is nullpublic Color add(float s)
s to the R-, G- and B-component values of this Color instance.
Returns a new Color instance with the result of the addition.
s - the value to addColor instance with the result of the additionpublic Color add(float r, float g, float b)
r, g and b to the R-, G- and B-component values of this Color instance, respectively.
Returns a new Color instance with the result of the addition.
r - the value to add to the R componentg - the value to add to the G componentb - the value to add to the B componentColor instance with the result of the additionpublic Color add(float r, float g, float b, float a)
r, g, b and a to the R-, G-, B- and A-component values of this Color instance, respectively.
Returns a new Color instance with the result of the addition.
r - the value to add to the R componentg - the value to add to the G componentb - the value to add to the B componenta - the value to add to the A componentColor instance with the result of the additionpublic Color applyGammaCorrection()
Color instance.
Returns a new Color instance with Gamma Correction applied.
Calling this method is equivalent to color.applyGammaCorrection(Color.DEFAULT_GAMMA).
Color instance with Gamma Correction appliedpublic Color applyGammaCorrection(float gamma)
Color instance.
Returns a new Color instance with Gamma Correction applied.
gamma - the gamma value to useColor instance with Gamma Correction appliedpublic Color applyToneMapping()
Color instance.
Returns a new Color instance with Tone Mapping applied.
Calling this method is equivalent to color.applyToneMapping(ToneMapper.linear()).
Color instance with Tone Mapping appliedpublic Color applyToneMapping(ToneMapper toneMapper)
Color instance.
Returns a new Color instance with Tone Mapping applied.
If toneMapper is null, a NullPointerException will be thrown.
toneMapper - the ToneMapper to useColor instance with Tone Mapping appliedjava.lang.NullPointerException - thrown if, and only if, toneMapper is nullpublic Color constrain()
Color instance to be representable.
Returns a constrained version of this Color instance.
Color instancepublic Color divide(Color color)
Color instance with color.
Returns a new Color instance with the result of the division.
If color is null, a NullPointerException will be thrown.
color - the Color to divide this Color instance withColor instance with the result of the divisionjava.lang.NullPointerException - thrown if, and only if, color is nullpublic Color divide(float s)
Color instance with s.
Returns a new Color instance with the result of the division.
s - the value to divide withColor instance with the result of the divisionpublic Color divide(float r, float g, float b)
Color instance with r, g and b, respectively.
Returns a new Color instance with the result of the division.
r - the value to divide the R component withg - the value to divide the G component withb - the value to divide the B component withColor instance with the result of the divisionpublic Color divide(float r, float g, float b, float a)
Color instance with r, g, b and a, respectively.
Returns a new Color instance with the result of the division.
r - the value to divide the R component withg - the value to divide the G component withb - the value to divide the B component witha - the value to divide the A component withColor instance with the result of the divisionpublic Color exp()
Color instance with Euler's number e raised to the power of each RGB-component value.Color instance with Euler's number e raised to the power of each RGB-component valuepublic Color makeDisplayCompatible()
Color instance display compatible.
Returns a new Color instance.
Calling this method is equivalent to color.makeDisplayCompatible(Color.DEFAULT_GAMMA).
Color instancepublic Color makeDisplayCompatible(float gamma)
Color instance display compatible.
Returns a new Color instance.
Calling this method is equivalent to color.makeDisplayCompatible(gamma, ToneMapper.linear()).
gamma - the gamma value to useColor instancepublic Color makeDisplayCompatible(float gamma, ToneMapper toneMapper)
Color instance display compatible.
Returns a new Color instance.
Calling this method is equivalent to the following:
color.applyToneMapping(toneMapper).applyGammaCorrection(gamma).saturate(0.0F, 1.0F).multiply(255.0F)
If toneMapper is null, a NullPointerException will be thrown.gamma - the gamma value to usetoneMapper - the ToneMapper to useColor instancejava.lang.NullPointerException - thrown if, and only if, toneMapper is nullpublic Color makeDisplayCompatible(ToneMapper toneMapper)
Color instance display compatible.
Returns a new Color instance.
Calling this method is equivalent to the following:
color.applyToneMapping(toneMapper).saturate(0.0F, 1.0F).multiply(255.0F)
If toneMapper is null, a NullPointerException will be thrown.
Note that this method should preferably only be used if toneMapper takes care of Gamma Correction.
toneMapper - the ToneMapper to useColor instancejava.lang.NullPointerException - thrown if, and only if, toneMapper is nullpublic Color multiply(Color color)
Color instance with color.
Returns a new Color instance with the result of the multiplication.
If color is null, a NullPointerException will be thrown.
color - the Color to multiply this Color instance withColor instance with the result of the multiplicationjava.lang.NullPointerException - thrown if, and only if, color is nullpublic Color multiply(float s)
Color instance with s.
Returns a new Color instance with the result of the multiplication.
s - the value to multiply withColor instance with the result of the multiplicationpublic Color multiply(float r, float g, float b)
Color instance with r, g and b, respectively.
Returns a new Color instance with the result of the multiplication.
r - the value to multiply with the R componentg - the value to multiply with the G componentb - the value to multiply with the B componentColor instance with the result of the multiplicationpublic Color multiply(float r, float g, float b, float a)
Color instance with r, g, b and a, respectively.
Returns a new Color instance with the result of the multiplication.
r - the value to multiply with the R componentg - the value to multiply with the G componentb - the value to multiply with the B componenta - the value to multiply with the A componentColor instance with the result of the multiplicationpublic Color negate()
Color instance with each RGB-component value negated.Color instance with each RGB-component value negatedpublic Color pow(Color color)
Color instance with the R-, G- and B-component values of this Color instance raised to the power of the R-, G- and B-component values of color, respectively.
If color is null, a NullPointerException will be thrown.
color - a Color instance with R-, G- and B-component values that are used as exponentsColor instance with the R-, G- and B-component values of this Color instance raised to the power of the R-, G- and B-component values of color, respectivelyjava.lang.NullPointerException - thrown if, and only if, color is nullpublic Color pow(float exponent)
Color instance with the R-, G- and B-component values of this Color instance raised to the power of exponent.exponent - the exponent to useColor instance with the R-, G- and B-component values of this Color instance raised to the power of exponentpublic Color pow(float r, float g, float b)
Color instance with the R-, G- and B-component values of this Color instance raised to the power of r, g and b, respectively.r - the exponent of the R-component valueg - the exponent of the G-component valueb - the exponent of the B-component valueColor instance with the R-, G- and B-component values of this Color instance raised to the power of r, g and b, respectivelypublic Color pow(float r, float g, float b, float a)
Color instance with the R-, G-, B- and A-component values of this Color instance raised to the power of r, g, b and a, respectively.r - the exponent of the R-component valueg - the exponent of the G-component valueb - the exponent of the B-component valuea - the exponent of the A-component valueColor instance with the R-, G-, B- and A-component values of this Color instance raised to the power of r, g, b and a, respectivelypublic Color redoGammaCorrection(ColorSpace colorSpace)
ColorSpace.
Returns a new Color instance.
If colorSpace is null, a NullPointerException will be thrown.
colorSpace - the ColorSpace to useColor instancejava.lang.NullPointerException - thrown if, and only if, colorSpace is nullpublic Color saturate(float min, float max)
Color instance, such that each component value will lie in the range [min, max].
Returns a new Color instance with the result of the saturation.
min - the minimum valuemax - the maximum valueColor instance with the result of the saturationpublic Color sqrt()
Color instance with the square root performed on each RGB-component value.Color instance with the square root performed on each RGB-component valuepublic Color subtract(Color color)
Color instance with color.
Returns a new Color instance with the result of the subtraction.
If color is null, a NullPointerException will be thrown.
color - the Color to subtract from this Color instanceColor instance with the result of the subtractionjava.lang.NullPointerException - thrown if, and only if, color is nullpublic Color subtract(float s)
s from the R-, G- and B-component values of this Color instance.
Returns a new Color instance with the result of the subtraction.
s - the value to subtractColor instance with the result of the subtractionpublic Color subtract(float r, float g, float b)
Color instance with r, g and b, respectively.
Returns a new Color instance with the result of the subtraction.
r - the value to subtract from the R componentg - the value to subtract from the G componentb - the value to subtract from the B componentColor instance with the result of the subtractionpublic Color subtract(float r, float g, float b, float a)
Color instance with r, g, b and a, respectively.
Returns a new Color instance with the result of the subtraction.
r - the value to subtract from the R componentg - the value to subtract from the G componentb - the value to subtract from the B componenta - the value to subtract from the A componentColor instance with the result of the subtractionpublic Color undoGammaCorrection(ColorSpace colorSpace)
ColorSpace.
Returns a new Color instance.
If colorSpace is null, a NullPointerException will be thrown.
colorSpace - the ColorSpace to useColor instancejava.lang.NullPointerException - thrown if, and only if, colorSpace is nullpublic java.lang.String toString()
String representation of this Color instance.toString in class java.lang.ObjectString representation of this Color instancepublic boolean equals(java.lang.Object object)
object to this Color instance for equality.
Returns true if, and only if, object is an instance of Color, and their respective values are equal, false otherwise.
equals in class java.lang.Objectobject - the Object to compare to this Color instance for equalitytrue if, and only if, object is an instance of Color, and their respective values are equal, false otherwisepublic boolean isBlack()
true if, and only if, this Color denotes the color black, false otherwise.true if, and only if, this Color denotes the color black, false otherwisepublic float average()
Color instance.Color instancepublic float getA()
public float getB()
public float getG()
public float getR()
public float luminance()
Color instance.Color instancepublic float max()
Color instance.Color instancepublic float min()
Color instance.Color instancepublic int hashCode()
Color instance.hashCode in class java.lang.ObjectColor instancepublic int toARGB()
int representation of the ARGB-component values of this Color instance.int representation of the ARGB-component values of this Color instancepublic int toRGB()
int representation of the RGB-component values of this Color instance.int representation of the RGB-component values of this Color instancepublic static int toA(int aRGB)
aRGB.aRGB - an int with the ARGB-component valuesaRGBpublic static int toB(int rGB)
rGB.rGB - an int with the RGB-component valuesrGBpublic static int toG(int rGB)
rGB.rGB - an int with the RGB-component valuesrGBpublic static int toR(int rGB)
rGB.rGB - an int with the RGB-component valuesrGBpublic static int toRGB(int r,
int g,
int b)
int with the R-, G- and B-component values.r - the R-component valueg - the G-component valueb - the B-component valueint with the R-, G- and B-component values