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...
 

Public Member Functions

 Color ()=default
 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...
 
 Color (const float *values)
 Constructor to set all color components to a given value. 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 over saturated 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 post-fixed 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.

Constructor & Destructor Documentation

◆ Color() [1/3]

Murl::Color::Color ( Float  value)
explicit

Constructor to set all color components to a given value.

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

◆ Color() [2/3]

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

Constructor to initialize a color with given component values.

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

◆ Color() [3/3]

Murl::Color::Color ( const float *  values)
explicit

Constructor to set all color components to a given value.

Parameters
valuesThe values for the red, green, blue and alpha component.

Member Function Documentation

◆ FromInt()

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

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.

◆ Set()

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

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.

◆ SetInt()

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

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.

◆ GetRed()

Float Murl::Color::GetRed ( ) const

Get the red component.

Returns
The red component.

◆ SetRed()

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

Set the red component.

Parameters
redThe red component.

◆ GetRedInt()

SInt32 Murl::Color::GetRedInt ( ) const

Get the red integer component.

The component is multiplied by 255.

Returns
The red integer component.

◆ SetRedInt()

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

Set the red integer component.

The component is divided by 255.

Parameters
redThe red integer component.

◆ GetGreen()

Float Murl::Color::GetGreen ( ) const

Get the green component.

Returns
The green component.

◆ SetGreen()

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

Set the green component.

Parameters
greenThe green component.

◆ GetGreenInt()

SInt32 Murl::Color::GetGreenInt ( ) const

Get the green integer component.

The component is multiplied by 255.

Returns
The green integer component.

◆ SetGreenInt()

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

Set the green integer component.

The component is divided by 255.

Parameters
greenThe green integer component.

◆ GetBlue()

Float Murl::Color::GetBlue ( ) const

Get the blue component.

Returns
The blue component.

◆ SetBlue()

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

Set the blue component.

Parameters
blueThe blue component.

◆ GetBlueInt()

SInt32 Murl::Color::GetBlueInt ( ) const

Get the blue integer component.

The component is multiplied by 255.

Returns
The blue integer component.

◆ SetBlueInt()

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

Set the blue integer component.

The component is divided by 255.

Parameters
blueThe blue integer component.

◆ GetAlpha()

Float Murl::Color::GetAlpha ( ) const

Get the alpha component.

Returns
The alpha component.

◆ SetAlpha()

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

Set the alpha component.

Parameters
alphaThe alpha component.

◆ GetAlphaInt()

SInt32 Murl::Color::GetAlphaInt ( ) const

Get the alpha integer component.

The component is multiplied by 255.

Returns
The alpha integer component.

◆ SetAlphaInt()

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

Set the alpha integer component.

The component is divided by 255.

Parameters
alphaThe alpha integer component.

◆ GetLuminance()

Float Murl::Color::GetLuminance ( ) const

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).

◆ GetLuminanceInt()

SInt32 Murl::Color::GetLuminanceInt ( ) const

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.

◆ ToUInt32()

UInt32 Murl::Color::ToUInt32 ( ) const

Get the 32 bit ABGR value of the color instance components.

Returns
The 32 bit ABGR value.

◆ ToUInt32Clamped()

UInt32 Murl::Color::ToUInt32Clamped ( ) const

Get the 32 bit ABGR value of the color instance components, clamped to the range [0..255].

Returns
The 32 bit ABGR value.

◆ FromUInt32()

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

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

Parameters
colorThe 32 bit ABGR value.

◆ FromUInt32ARGB()

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

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

Parameters
colorThe 32 bit ARBG value.

◆ BlendSelf()

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

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

Parameters
foregroundColorThe foreground color to blend.

◆ Blend()

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

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.

◆ operator+=()

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

In-place addition operator.

Parameters
colorThe color to add.
Returns
The object itself.

◆ operator-=()

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

In-place subtraction operator.

Parameters
colorThe color to subtract.
Returns
The object itself.

◆ operator*=() [1/2]

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

In-place multiplication operator.

Parameters
colorThe color to multiply.
Returns
The object itself.

◆ operator*=() [2/2]

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

In-place multiplication operator.

Parameters
valueThe value to multiply.
Returns
The object itself.

◆ operator/=() [1/2]

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

In-place division operator.

Parameters
colorThe color to divide.
Returns
The object itself.

◆ operator/=() [2/2]

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

In-place division operator.

Parameters
valueThe value to divide.
Returns
The object itself.

◆ operator+()

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

Addition operator.

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

◆ operator-()

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

Subtraction operator.

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

◆ operator*() [1/2]

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

Multiplication operator.

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

◆ operator*() [2/2]

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

Multiplication operator.

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

◆ operator/() [1/2]

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

Division operator.

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

◆ operator/() [2/2]

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

Division operator.

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

◆ IsEqual() [1/2]

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

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

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.

◆ GetRawComponents() [1/2]

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

Get a const pointer to the raw components data.

Returns
Const pointer to the raw data.

◆ GetRawComponents() [2/2]

Float* Murl::Color::GetRawComponents ( )

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 ( )
static

Get the red component's weight for luminance conversion, according to the ITU-R BT.601 standard.

Returns
The weight of the red component.

◆ GetLuminanceGreenWeight()

static Float Murl::Color::GetLuminanceGreenWeight ( )
static

Get the green component's weight for luminance conversion, according to the ITU-R BT.601 standard.

Returns
The weight of the green component.

◆ GetLuminanceBlueWeight()

static Float Murl::Color::GetLuminanceBlueWeight ( )
static

Get the blue component's weight for luminance conversion, according to the ITU-R BT.601 standard.

Returns
The weight of the blue component.

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-2024 Spraylight GmbH.