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...
 
Coloroperator+= (const Color &color)
 In-place addition operator. More...
 
Coloroperator-= (const Color &color)
 In-place subtraction operator. More...
 
Coloroperator*= (const Color &color)
 In-place multiplication operator. More...
 
Coloroperator*= (Float value)
 In-place multiplication operator. More...
 
Coloroperator/= (const Color &color)
 In-place division operator. More...
 
Coloroperator/= (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 FloatGetRawComponents () const
 Get a const pointer to the raw components data. More...
 
FloatGetRawComponents ()
 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

Enumeration of the components raw data.

Enumerator
RED 

Index to the red component.

GREEN 

Index to the green component.

BLUE 

Index to the blue component.

ALPHA 

Index to the alpha component.

NUM_COMPONENTS 

Number of 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]

Murl::Color::Color ( Float  value)
inline

Constructor to set all color components to a given value.

Parameters
valueThe value for the red, green, blue and alpha component.

References ALPHA, BLUE, GREEN, and RED.

◆ Color() [2/2]

Murl::Color::Color ( Float  red,
Float  green,
Float  blue,
Float  alpha 
)
inline

Constructor to initialize a color with given component values.

Parameters
redThe red component.
greenThe green component.
blueThe blue component.
alphaThe alpha component.

References ALPHA, BLUE, GREEN, and RED.

Member Function Documentation

◆ FromInt()

static Color Murl::Color::FromInt ( SInt32  red,
SInt32  green,
SInt32  blue,
SInt32  alpha 
)
inlinestatic

Named constructor to set all components to a set of given integer component values.

The integer values are divided by 255.

Parameters
redThe red integer component.
greenThe green integer component.
blueThe blue integer component.
alphaThe alpha integer component.
Returns
The color object.

References Color().

◆ Set()

void Murl::Color::Set ( Float  red,
Float  green,
Float  blue,
Float  alpha 
)
inline

Set all components of the color instance to a set of given component values.

Parameters
redThe red component.
greenThe green component.
blueThe blue component.
alphaThe alpha component.

References ALPHA, BLUE, GREEN, and RED.

◆ SetInt()

void Murl::Color::SetInt ( SInt32  red,
SInt32  green,
SInt32  blue,
SInt32  alpha 
)
inline

Set all components of the color instance to a set of given integer component values.

The integer values are divided by 255.

Parameters
redThe red integer component.
greenThe green integer component.
blueThe blue integer component.
alphaThe alpha integer component.

References ALPHA, BLUE, GREEN, and RED.

◆ GetRed()

Float Murl::Color::GetRed ( ) const
inline

Get the red component.

Returns
The red component.

References RED.

◆ SetRed()

void Murl::Color::SetRed ( Float  red)
inline

Set the red component.

Parameters
redThe red component.

References RED.

◆ GetRedInt()

SInt32 Murl::Color::GetRedInt ( ) const
inline

Get the red integer component.

The component is multiplied by 255.

Returns
The red integer component.

References RED, and Murl::Math::Round().

◆ SetRedInt()

void Murl::Color::SetRedInt ( SInt32  red)
inline

Set the red integer component.

The component is divided by 255.

Parameters
redThe red integer component.

References RED.

◆ GetGreen()

Float Murl::Color::GetGreen ( ) const
inline

Get the green component.

Returns
The green component.

References GREEN.

◆ SetGreen()

void Murl::Color::SetGreen ( Float  green)
inline

Set the green component.

Parameters
greenThe green component.

References GREEN.

◆ GetGreenInt()

SInt32 Murl::Color::GetGreenInt ( ) const
inline

Get the green integer component.

The component is multiplied by 255.

Returns
The green integer component.

References GREEN, and Murl::Math::Round().

◆ SetGreenInt()

void Murl::Color::SetGreenInt ( SInt32  green)
inline

Set the green integer component.

The component is divided by 255.

Parameters
greenThe green integer component.

References GREEN.

◆ GetBlue()

Float Murl::Color::GetBlue ( ) const
inline

Get the blue component.

Returns
The blue component.

References BLUE.

◆ SetBlue()

void Murl::Color::SetBlue ( Float  blue)
inline

Set the blue component.

Parameters
blueThe blue component.

References BLUE.

◆ GetBlueInt()

SInt32 Murl::Color::GetBlueInt ( ) const
inline

Get the blue integer component.

The component is multiplied by 255.

Returns
The blue integer component.

References BLUE, and Murl::Math::Round().

◆ SetBlueInt()

void Murl::Color::SetBlueInt ( SInt32  blue)
inline

Set the blue integer component.

The component is divided by 255.

Parameters
blueThe blue integer component.

References BLUE.

◆ GetAlpha()

Float Murl::Color::GetAlpha ( ) const
inline

Get the alpha component.

Returns
The alpha component.

References ALPHA.

◆ SetAlpha()

void Murl::Color::SetAlpha ( Float  alpha)
inline

Set the alpha component.

Parameters
alphaThe alpha component.

References ALPHA.

◆ GetAlphaInt()

SInt32 Murl::Color::GetAlphaInt ( ) const
inline

Get the alpha integer component.

The component is multiplied by 255.

Returns
The alpha integer component.

References ALPHA, and Murl::Math::Round().

◆ SetAlphaInt()

void Murl::Color::SetAlphaInt ( SInt32  alpha)
inline

Set the alpha integer component.

The component is divided by 255.

Parameters
alphaThe alpha integer component.

References ALPHA.

◆ GetLuminance()

Float Murl::Color::GetLuminance ( ) const
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()

SInt32 Murl::Color::GetLuminanceInt ( ) const
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()

UInt32 Murl::Color::ToUInt32 ( ) const
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()

UInt32 Murl::Color::ToUInt32Clamped ( ) const
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()

void Murl::Color::FromUInt32 ( UInt32  color)
inline

Set the color instance components from a 32 bit ABGR value.

Parameters
colorThe 32 bit ABGR value.

References ALPHA, BLUE, GREEN, and RED.

◆ FromUInt32ARGB()

void Murl::Color::FromUInt32ARGB ( UInt32  color)
inline

Set the color instance components from a 32 bit ARGB value.

Parameters
colorThe 32 bit ARBG value.

References ALPHA, BLUE, GREEN, and RED.

◆ BlendSelf()

void Murl::Color::BlendSelf ( const Color foregroundColor)
inline

Blend a given foreground color over this color using alpha blending in place.

Parameters
foregroundColorThe foreground color to blend.

References ALPHA, BLUE, GREEN, and RED.

Referenced by Blend().

◆ Blend()

Color Murl::Color::Blend ( const Color foregroundColor) const
inline

Blend a given foreground color over this color using alpha blending and return the blended color.

Parameters
foregroundColorThe foreground color to blend.
Returns
The alpha blended color.

References BlendSelf().

◆ operator+=()

Color& Murl::Color::operator+= ( const Color color)
inline

In-place addition operator.

Parameters
colorThe color to add.
Returns
The object itself.

References ALPHA, BLUE, GREEN, and RED.

◆ operator-=()

Color& Murl::Color::operator-= ( const Color color)
inline

In-place subtraction operator.

Parameters
colorThe color to subtract.
Returns
The object itself.

References ALPHA, BLUE, GREEN, and RED.

◆ operator*=() [1/2]

Color& Murl::Color::operator*= ( const Color color)
inline

In-place multiplication operator.

Parameters
colorThe color to multiply.
Returns
The object itself.

References ALPHA, BLUE, GREEN, and RED.

◆ operator*=() [2/2]

Color& Murl::Color::operator*= ( Float  value)
inline

In-place multiplication operator.

Parameters
valueThe value to multiply.
Returns
The object itself.

References ALPHA, BLUE, GREEN, and RED.

◆ operator/=() [1/2]

Color& Murl::Color::operator/= ( const Color color)
inline

In-place division operator.

Parameters
colorThe color to divide.
Returns
The object itself.

References ALPHA, BLUE, GREEN, and RED.

◆ operator/=() [2/2]

Color& Murl::Color::operator/= ( Float  value)
inline

In-place division operator.

Parameters
valueThe value to divide.
Returns
The object itself.

References ALPHA, BLUE, GREEN, and RED.

◆ operator+()

Color Murl::Color::operator+ ( const Color color) const
inline

Addition operator.

Parameters
colorThe right hand side color.
Returns
The added color.

◆ operator-()

Color Murl::Color::operator- ( const Color color) const
inline

Subtraction operator.

Parameters
colorThe right hand side color.
Returns
The subtracted color.

◆ operator*() [1/2]

Color Murl::Color::operator* ( const Color color) const
inline

Multiplication operator.

Parameters
colorThe right hand side color.
Returns
The multiplied color.

◆ operator*() [2/2]

Color Murl::Color::operator* ( Float  value) const
inline

Multiplication operator.

Parameters
valueThe right hand side value.
Returns
The multiplied color.

◆ operator/() [1/2]

Color Murl::Color::operator/ ( const Color color) const
inline

Division operator.

Parameters
colorThe right hand side color.
Returns
The divided color.

◆ operator/() [2/2]

Color Murl::Color::operator/ ( Float  value) const
inline

Division operator.

Parameters
valueThe right hand side value.
Returns
The divided color.

◆ IsEqual() [1/2]

Bool Murl::Color::IsEqual ( const Color color) const
inline

Check if the color instance is equal to a given second color.

Compares all values within the default epsilon range Limits::Epsilon().

Parameters
colorThe color to compare.
Returns
true if all components are equal.

◆ IsEqual() [2/2]

Bool Murl::Color::IsEqual ( const Color color,
Float  epsilon 
) const
inline

Check if the color instance is equal to a given second color.

Compares all values within a given epsilon range.

Parameters
colorThe color to compare.
epsilonThe epsilon to compare.
Returns
true if all components are equal.

References Murl::Math::Abs(), ALPHA, BLUE, GREEN, and RED.

◆ GetRawComponents() [1/2]

const Float* Murl::Color::GetRawComponents ( ) const
inline

Get a const pointer to the raw components data.

Returns
Const pointer to the raw data.

◆ GetRawComponents() [2/2]

Float* Murl::Color::GetRawComponents ( )
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()

static Float Murl::Color::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()

static Float Murl::Color::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()

static Float Murl::Color::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==

bool operator== ( const Color lhs,
const Color rhs 
)
friend

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
lhsThe left hand side color to compare.
rhsThe right hand side color to compare.
Returns
true if all components are exactly the same.

◆ operator!=

bool operator!= ( const Color lhs,
const Color rhs 
)
friend

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
lhsThe left hand side color to compare.
rhsThe 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


Copyright © 2011-2018 Spraylight GmbH.