A color class. More...
#include "murl_color.h"
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... | |
Detailed Description
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:
- A 6-digit hex string representing an unsigned 24bit integer RGB color value (100% alpha)
- An 8-digit hex string representing an unsigned 32bit integer ARGB color value
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:
- 'f' to specify a floating point value that directly maps to the internal range
- 'i' to specify an integer value, which will be divided by 255
- 'h' to specify a hex string, which will be converted and divided by 255
String-to-color conversion in the described way can also be done from code, by using the Util::StringToColor() function.
Examples:
- "ffc080h": 100% alpha (implicitly), 100% red, 75% green and 50% blue (RGB)
- "40ffc080h": 25% alpha, 100% red, 75% green and 50% blue (ARGB)
- "1f,1f,1f,0.5f": 100% white with 50% alpha (RGBA)
- "128i,64i,192i": 50% red, 25% green, 75% blue and (implicitly) 100% alpha (RGB)
- "00h,00h,00h,ffh": black with 100% alpha (RGBA)
- "0.5f,128i,80h": 50% grey with (implicitly) 100% alpha (RGB)
Member Enumeration Documentation
◆ Components
◆ StringFormat
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. |
Constructor & Destructor Documentation
◆ Color() [1/2]
|
inline |
◆ Color() [2/2]
Member Function Documentation
◆ FromInt()
|
inlinestatic |
Named constructor to set all components to a set of given integer component values.
The integer values are divided by 255.
- Parameters
-
red The red integer component. green The green integer component. blue The blue integer component. alpha The alpha integer component.
- Returns
- The color object.
References Color().
◆ Set()
◆ SetInt()
Set all components of the color instance to a set of given integer component values.
The integer values are divided by 255.
- Parameters
-
red The red integer component. green The green integer component. blue The blue integer component. alpha The alpha integer component.
◆ GetRed()
|
inline |
◆ SetRed()
|
inline |
◆ GetRedInt()
|
inline |
Get the red integer component.
The component is multiplied by 255.
- Returns
- The red integer component.
References RED, and Murl::Math::Round().
◆ SetRedInt()
|
inline |
Set the red integer component.
The component is divided by 255.
- Parameters
-
red The red integer component.
References RED.
◆ GetGreen()
|
inline |
◆ SetGreen()
|
inline |
◆ GetGreenInt()
|
inline |
Get the green integer component.
The component is multiplied by 255.
- Returns
- The green integer component.
References GREEN, and Murl::Math::Round().
◆ SetGreenInt()
|
inline |
Set the green integer component.
The component is divided by 255.
- Parameters
-
green The green integer component.
References GREEN.
◆ GetBlue()
|
inline |
◆ SetBlue()
|
inline |
◆ GetBlueInt()
|
inline |
Get the blue integer component.
The component is multiplied by 255.
- Returns
- The blue integer component.
References BLUE, and Murl::Math::Round().
◆ SetBlueInt()
|
inline |
Set the blue integer component.
The component is divided by 255.
- Parameters
-
blue The blue integer component.
References BLUE.
◆ GetAlpha()
|
inline |
◆ SetAlpha()
|
inline |
◆ GetAlphaInt()
|
inline |
Get the alpha integer component.
The component is multiplied by 255.
- Returns
- The alpha integer component.
References ALPHA, and Murl::Math::Round().
◆ SetAlphaInt()
|
inline |
Set the alpha integer component.
The component is divided by 255.
- Parameters
-
alpha The alpha integer component.
References ALPHA.
◆ GetLuminance()
|
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.
- Returns
- The luminance (R * 0.2990 + G * 0.5864 + B * 0.1146).
References BLUE, GetLuminanceBlueWeight(), GetLuminanceGreenWeight(), GetLuminanceRedWeight(), GREEN, and RED.
Referenced by GetLuminanceInt().
◆ GetLuminanceInt()
|
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.
- Returns
- The integer luminance.
References GetLuminance(), and Murl::Math::Round().
◆ ToUInt32()
|
inline |
Get the 32 bit ABGR value of the color instance components.
- Returns
- The 32 bit ABGR value.
References ALPHA, BLUE, GREEN, RED, and Murl::Math::Round().
◆ ToUInt32Clamped()
|
inline |
Get the 32 bit ABGR value of the color instance components, clamped to the range [0..255].
- Returns
- The 32 bit ABGR value.
References ALPHA, BLUE, GREEN, RED, and Murl::Math::Round().
◆ FromUInt32()
|
inline |
◆ FromUInt32ARGB()
|
inline |
◆ BlendSelf()
|
inline |
◆ Blend()
Blend a given foreground color over this color using alpha blending and return the blended color.
- Parameters
-
foregroundColor The foreground color to blend.
- Returns
- The alpha blended color.
References BlendSelf().
◆ operator+=()
◆ operator-=()
◆ operator*=() [1/2]
◆ operator*=() [2/2]
◆ operator/=() [1/2]
◆ operator/=() [2/2]
◆ operator+()
Addition operator.
- Parameters
-
color The right hand side color.
- Returns
- The added color.
◆ operator-()
Subtraction operator.
- Parameters
-
color The right hand side color.
- Returns
- The subtracted color.
◆ operator*() [1/2]
Multiplication operator.
- Parameters
-
color The right hand side color.
- Returns
- The multiplied color.
◆ operator*() [2/2]
Multiplication operator.
- Parameters
-
value The right hand side value.
- Returns
- The multiplied color.
◆ operator/() [1/2]
Division operator.
- Parameters
-
color The right hand side color.
- Returns
- The divided color.
◆ operator/() [2/2]
Division operator.
- Parameters
-
value The right hand side value.
- Returns
- The divided color.
◆ IsEqual() [1/2]
Check if the color instance is equal to a given second color.
Compares all values within the default epsilon range Limits::Epsilon().
- Parameters
-
color The color to compare.
- Returns
- true if all components are equal.
◆ IsEqual() [2/2]
Check if the color instance is equal to a given second color.
Compares all values within a given epsilon range.
- Parameters
-
color The color to compare. epsilon The epsilon to compare.
- Returns
- true if all components are equal.
References Murl::Math::Abs(), ALPHA, BLUE, GREEN, and RED.
◆ GetRawComponents() [1/2]
|
inline |
Get a const pointer to the raw components data.
- Returns
- Const pointer to the raw data.
◆ GetRawComponents() [2/2]
|
inline |
Get a pointer to the raw components data.
- Returns
- Pointer to the raw data.
◆ ToString()
String Murl::Color::ToString | ( | ) | const |
Get the string representation of the object.
- Returns
- The string representation of the object.
◆ GetLuminanceRedWeight()
|
inlinestatic |
Get the red component's weight for luminance conversion, according to the ITU-R BT.601 standard.
- Returns
- The weight of the red component.
Referenced by GetLuminance().
◆ GetLuminanceGreenWeight()
|
inlinestatic |
Get the green component's weight for luminance conversion, according to the ITU-R BT.601 standard.
- Returns
- The weight of the green component.
Referenced by GetLuminance().
◆ GetLuminanceBlueWeight()
|
inlinestatic |
Get the blue component's weight for luminance conversion, according to the ITU-R BT.601 standard.
- Returns
- The weight of the blue component.
Referenced by GetLuminance().
Friends And Related Function Documentation
◆ operator==
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().
- Parameters
-
lhs The left hand side color to compare. rhs The right hand side color to compare.
- Returns
- true if all components are exactly the same.
◆ operator!=
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().
- Parameters
-
lhs The left hand side color to compare. rhs The right hand side color to compare.
- Returns
- true if all components are exactly the same.
The documentation for this class was generated from the following file:
- murl_color.h