![]() |
Murl Engine API
Version 2018.3
|
A color class. More...
#include <murl_color.h>
A color class.
This class holds four individual 32bit floating point values representing an RGBA color, each of them with a "regular" range of 0.0 (black) to 1.0 (full color). Actual values may lie beyond that range (in both directions), to define oversaturated colors or even "negative" ones.
When specified as an attribute value in an XML file, there exist a number of different notations. For specifying multiple components in one value, the following ones can be used:
For these, a trailing 'h' character defines the hex notation. For specifying individual values, either 3 (RGB) or 4 (RGBA) values must be given as a comma-separated string. Each of these values must be postfixed by one of the following characters:
String-to-color conversion in the described way can also be done from code, by using the Util::StringToColor() function.
Examples:
Public Types | |
enum | Components { RED, GREEN, BLUE, ALPHA, NUM_COMPONENTS } |
Enumeration of the components raw data. More... | |
enum | StringFormat { STRING_FORMAT_UNKNOWN, STRING_FORMAT_FLOAT, STRING_FORMAT_INT, STRING_FORMAT_HEX, STRING_FORMAT_MIXED, STRING_FORMAT_INCOMPLETE, NUM_STRING_FORMATS } |
String formats. More... | |
Public Member Functions | |
Color () | |
The default constructor. | |
Color (Float value) | |
Constructor to set all color components to a given value. More... | |
Color (Float red, Float green, Float blue, Float alpha) | |
Constructor to initialize a color with given component values. More... | |
void | Set (Float red, Float green, Float blue, Float alpha) |
Set all components of the color instance to a set of given component values. More... | |
void | SetInt (SInt32 red, SInt32 green, SInt32 blue, SInt32 alpha) |
Set all components of the color instance to a set of given integer component values. More... | |
Float | GetRed () const |
Get the red component. More... | |
void | SetRed (Float red) |
Set the red component. More... | |
SInt32 | GetRedInt () const |
Get the red integer component. More... | |
void | SetRedInt (SInt32 red) |
Set the red integer component. More... | |
Float | GetGreen () const |
Get the green component. More... | |
void | SetGreen (Float green) |
Set the green component. More... | |
SInt32 | GetGreenInt () const |
Get the green integer component. More... | |
void | SetGreenInt (SInt32 green) |
Set the green integer component. More... | |
Float | GetBlue () const |
Get the blue component. More... | |
void | SetBlue (Float blue) |
Set the blue component. More... | |
SInt32 | GetBlueInt () const |
Get the blue integer component. More... | |
void | SetBlueInt (SInt32 blue) |
Set the blue integer component. More... | |
Float | GetAlpha () const |
Get the alpha component. More... | |
void | SetAlpha (Float alpha) |
Set the alpha component. More... | |
SInt32 | GetAlphaInt () const |
Get the alpha integer component. More... | |
void | SetAlphaInt (SInt32 alpha) |
Set the alpha integer component. More... | |
Float | GetLuminance () const |
Get the luminance (gray scale) value calculated from R, G and B. More... | |
SInt32 | GetLuminanceInt () const |
Get the luminance (gray scale) integer value calculated from R, G and B. More... | |
UInt32 | ToUInt32 () const |
Get the 32 bit ABGR value of the color instance components. More... | |
UInt32 | ToUInt32Clamped () const |
Get the 32 bit ABGR value of the color instance components, clamped to the range [0..255]. More... | |
void | FromUInt32 (UInt32 color) |
Set the color instance components from a 32 bit ABGR value. More... | |
void | FromUInt32ARGB (UInt32 color) |
Set the color instance components from a 32 bit ARGB value. More... | |
void | BlendSelf (const Color &foregroundColor) |
Blend a given foreground color over this color using alpha blending in place. More... | |
Color | Blend (const Color &foregroundColor) const |
Blend a given foreground color over this color using alpha blending and return the blended color. More... | |
Color & | operator+= (const Color &color) |
In-place addition operator. More... | |
Color & | operator-= (const Color &color) |
In-place subtraction operator. More... | |
Color & | operator*= (const Color &color) |
In-place multiplication operator. More... | |
Color & | operator*= (Float value) |
In-place multiplication operator. More... | |
Color & | operator/= (const Color &color) |
In-place division operator. More... | |
Color & | operator/= (Float value) |
In-place division operator. More... | |
Color | operator+ (const Color &color) const |
Addition operator. More... | |
Color | operator- (const Color &color) const |
Subtraction operator. More... | |
Color | operator* (const Color &color) const |
Multiplication operator. More... | |
Color | operator* (Float value) const |
Multiplication operator. More... | |
Color | operator/ (const Color &color) const |
Division operator. More... | |
Color | operator/ (Float value) const |
Division operator. More... | |
Bool | IsEqual (const Color &color) const |
Check if the color instance is equal to a given second color. More... | |
Bool | IsEqual (const Color &color, Float epsilon) const |
Check if the color instance is equal to a given second color. More... | |
const Float * | GetRawComponents () const |
Get a const pointer to the raw components data. More... | |
Float * | GetRawComponents () |
Get a pointer to the raw components data. More... | |
String | ToString () const |
Get the string representation of the object. More... | |
Static Public Member Functions | |
static Color | FromInt (SInt32 red, SInt32 green, SInt32 blue, SInt32 alpha) |
Named constructor to set all components to a set of given integer component values. More... | |
static Float | GetLuminanceRedWeight () |
Get the red component's weight for luminance conversion, according to the ITU-R BT.601 standard. More... | |
static Float | GetLuminanceGreenWeight () |
Get the green component's weight for luminance conversion, according to the ITU-R BT.601 standard. More... | |
static Float | GetLuminanceBlueWeight () |
Get the blue component's weight for luminance conversion, according to the ITU-R BT.601 standard. More... | |
Friends | |
bool | operator== (const Color &lhs, const Color &rhs) |
Equal to comparison operator. More... | |
bool | operator!= (const Color &lhs, const Color &rhs) |
Not equal to comparison operator. More... | |
String formats.
Enumerator | |
---|---|
STRING_FORMAT_UNKNOWN | Unknown format. |
STRING_FORMAT_FLOAT | Float format, e.g. "0.75f,0.5f,0.25f,1f" (RGBA) |
STRING_FORMAT_INT | Integer format, e.g. "192i,128i,64i,255i" (RGBA) |
STRING_FORMAT_HEX | Hex format, e.g. "ffc08040h" (ARGB) |
STRING_FORMAT_MIXED | String contains different format identifiers. |
STRING_FORMAT_INCOMPLETE | String does not contain a format identifier for all components. |
NUM_STRING_FORMATS | Number of formats. |
|
inline |
Constructor to set all color components to a given value.
value | The value for the red, green, blue and alpha component. |
Constructor to initialize a color with given component values.
red | The red component. |
green | The green component. |
blue | The blue component. |
alpha | The alpha component. |
|
inlinestatic |
Named constructor to set all components to a set of given integer component values.
The integer values are divided by 255.
red | The red integer component. |
green | The green integer component. |
blue | The blue integer component. |
alpha | The alpha integer component. |
Set all components of the color instance to a set of given component values.
red | The red component. |
green | The green component. |
blue | The blue component. |
alpha | The alpha component. |
Set all components of the color instance to a set of given integer component values.
The integer values are divided by 255.
red | The red integer component. |
green | The green integer component. |
blue | The blue integer component. |
alpha | The alpha integer component. |
|
inline |
Get the red component.
|
inline |
Set the red component.
red | The red component. |
|
inline |
Get the red integer component.
The component is multiplied by 255.
|
inline |
Set the red integer component.
The component is divided by 255.
red | The red integer component. |
|
inline |
Get the green component.
|
inline |
Set the green component.
green | The green component. |
|
inline |
Get the green integer component.
The component is multiplied by 255.
|
inline |
Set the green integer component.
The component is divided by 255.
green | The green integer component. |
|
inline |
Get the blue component.
|
inline |
Set the blue component.
blue | The blue component. |
|
inline |
Get the blue integer component.
The component is multiplied by 255.
|
inline |
Set the blue integer component.
The component is divided by 255.
blue | The blue integer component. |
|
inline |
Get the alpha component.
|
inline |
Set the alpha component.
alpha | The alpha component. |
|
inline |
Get the alpha integer component.
The component is multiplied by 255.
|
inline |
Set the alpha integer component.
The component is divided by 255.
alpha | The alpha integer component. |
|
inline |
Get the luminance (gray scale) value calculated from R, G and B.
Luminance calculation uses the standard conversion factors defined by the Rec 601 standard which can be found in PAL and NTSC color models.
|
inline |
Get the luminance (gray scale) integer value calculated from R, G and B.
Luminance calculation uses the standard conversion factors defined by the Rec 601 standard which can be found in PAL and NTSC color models, multiplied by 255.
|
inline |
Get the 32 bit ABGR value of the color instance components.
|
inline |
Get the 32 bit ABGR value of the color instance components, clamped to the range [0..255].
|
inline |
Set the color instance components from a 32 bit ABGR value.
color | The 32 bit ABGR value. |
|
inline |
Set the color instance components from a 32 bit ARGB value.
color | The 32 bit ARBG value. |
|
inline |
Blend a given foreground color over this color using alpha blending in place.
foregroundColor | The foreground color to blend. |
Blend a given foreground color over this color using alpha blending and return the blended color.
foregroundColor | The foreground color to blend. |
In-place addition operator.
color | The color to add. |
In-place subtraction operator.
color | The color to subtract. |
In-place multiplication operator.
color | The color to multiply. |
In-place multiplication operator.
value | The value to multiply. |
In-place division operator.
color | The color to divide. |
In-place division operator.
value | The value to divide. |
Addition operator.
color | The right hand side color. |
Subtraction operator.
color | The right hand side color. |
Multiplication operator.
color | The right hand side color. |
Multiplication operator.
value | The right hand side value. |
Division operator.
color | The right hand side color. |
Division operator.
value | The right hand side value. |
Check if the color instance is equal to a given second color.
Compares all values within the default epsilon range Limits::Epsilon().
color | The color to compare. |
Check if the color instance is equal to a given second color.
Compares all values within a given epsilon range.
color | The color to compare. |
epsilon | The epsilon to compare. |
|
inline |
Get a const pointer to the raw components data.
|
inline |
Get a pointer to the raw components data.
String Murl::Color::ToString | ( | ) | const |
Get the string representation of the object.
|
inlinestatic |
Get the red component's weight for luminance conversion, according to the ITU-R BT.601 standard.
|
inlinestatic |
Get the green component's weight for luminance conversion, according to the ITU-R BT.601 standard.
|
inlinestatic |
Get the blue component's weight for luminance conversion, according to the ITU-R BT.601 standard.
Equal to comparison operator.
Performs a test without an epsilon range, which can be used for detecting changes i.e. DoubleBuffer<Color> class. To compare within an epsilon range use Color::IsEqual().
lhs | The left hand side color to compare. |
rhs | The right hand side color to compare. |
Not equal to comparison operator.
Performs a test without an epsilon range, which can be used for detecting changes i.e. DoubleBuffer<Color> class. To compare within an epsilon range use Color::IsEqual().
lhs | The left hand side color to compare. |
rhs | The right hand side color to compare. |