Color

Fields

float

_r

float

_g

float

_b

float

_a

const Color

UNDEFINED

const Color

TRANSPARENCY

const Color

RED

const Color

GREEN

const Color

BLUE

const Color

CYAN

const Color

MAGENTA

const Color

YELLOW

const Color

DARK_RED

const Color

DARK_GREEN

const Color

DARK_BLUE

const Color

WHITE

const Color

GREY

const Color

DARK_GREY

const Color

LIGHT_GREY

const Color

BLACK

Functions

CID

GetClassID

Color

Random

Color

FromCharRGBA

Color

FromTemperature

Color

FromCIEXYZ

Color

FromCIExyY

void

DecodeRGBAAA

void

EncodeRGBAAA

void

GetRGBAAABackground

void

SetRGBAAABackground

void *

As

const void *

As

class T_As

As

class T_As

As

Color

Color

Color

Color

Color

Color

Color

Color

Color

void

SetRGBA

void

SetRGBA

~Color

void

ToCIEXYZ

void

ToCIExyY

bool

operator==

bool

operator!=

Color

operator+

Color

operator-

void

operator+=

void

operator-=

void

operator*=

void

operator*=

Color

operator*

Color

operator/

void

operator/=

bool

operator

float

GetIntensity

float

R

float

G

float

B

float

A

void

RGBClamp

bool

IsLower

float

GetMinComponent

float

GetMaxComponent

float

GetCIELuminance

void

Pack

const Color &

Unpack

void

ToHalfFloat

void

ToCharRGBA

Detailed Description

class Color : public RED::Object

RGBA color using 1 float per component.

By default in REDsdk, colors are stored as RGBA quadruplets in the linear sRGB color space. The colors are not clamped and can therefore be of any value (negative as well as positive).

Several colors operations are implemented in that class to simplify colors conversion, edition and comparison.

There are also a few hard-coded default values for most common colors:

RED::Color::TRANSPARENCY

0, 0, 0, 0

RED::Color::RED

1, 0, 0, 1

RED::Color::GREEN

0, 1, 0, 1

RED::Color::BLUE

0, 0, 1, 1

RED::Color::CYAN

0, 1, 1, 1

RED::Color::MAGENTA

1, 0, 1, 1

RED::Color::YELLOW

1, 1, 0, 1

RED::Color::DARK_RED

0.25, 0, 0, 1

RED::Color::DARK_GREEN

0, 0.25, 0, 1

RED::Color::DARK_BLUE

0, 0, 0.25, 1

RED::Color::WHITE

1, 1, 1, 1

RED::Color::GREY

0.5, 0.5, 0.5, 1

RED::Color::DARK_GREY

0.25, 0.25, 0.25, 1

RED::Color::LIGHT_GREY

0.75, 0.75, 0.75, 1

RED::Color::BLACK

0, 0, 0, 1

RED::Color::UNDEFINED

-1, -1, -1, -1

Public Functions

virtual void *As(const RED::CID &iCID)

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

virtual const void *As(const RED::CID &iCID) const

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

template<class T_As>
inline T_As *As()
template<class T_As>
inline const T_As *As() const
Color()

Default constructor.

The color is initialized to RED::Color::TRANSPARENCY.

Color(float iR, float iG, float iB, float iA = 1.0f)

Component-based color construction method using floats. Color space used is linear sRGB.

Parameters
  • iR – Red component of the color.

  • iG – Green component of the color.

  • iB – Blue component of the color.

  • iA – Alpha component of the color (default is opaque).

Color(double iR, double iG, double iB, double iA = 1.0)

Component-based color construction method using doubles. Color space used is linear sRGB.

Parameters
  • iR – Red component of the color.

  • iG – Green component of the color.

  • iB – Blue component of the color.

  • iA – Alpha component of the color (default is opaque).

Color(unsigned char iR, unsigned char iG, unsigned char iB, unsigned char iA = 255)

Component-based color construction method using unsigned chars. Color space used is linear sRGB.

Creates a color object from unsigned char RGBA values. The created color is normalized.

Parameters
  • iR – Red component of the color in [0,255].

  • iG – Green component of the color in [0,255].

  • iB – Blue component of the color in [0,255].

  • iA – Alpha component of the color in [0,255].

Color(unsigned short iR, unsigned short iG, unsigned short iB, unsigned short iA = (0x3c00))

Component-based color construction using half floats. Color space used is linear sRGB.

Creates a color object from unsigned short color components encoding half floating point values.

Parameters
  • iR – Red component of the color.

  • iG – Green component of the color.

  • iB – Blue component of the color.

  • iA – Alpha component of the color (default is opaque).

Color(float iIntensity)

Grey color constructor from color intensity.

Parameters

iIntensity – Intensity replicated on the 4 color components.

Color(double iIntensity)

Grey color constructor from color intensity.

Parameters

iIntensity – Intensity replicated on the 4 color components.

Color(const RED::Vector3 &iVector)

Conversion between RED::Vector3 and RED::Color.

Parameters

iVector – The source vector to build from. Alpha is set to 1.0f.

Color(const RED::Vector4 &iVector)

Conversion between RED::Vector4 and RED::Color.

Parameters

iVector – The source vector to build from.

inline void SetRGBA(float iRed, float iGreen, float iBlue, float iAlpha = 1.f)

Sets a color from the four RGBA components.

Parameters
  • iRed – red component.

  • iGreen – green component.

  • iBlue – blue component.

  • iAlpha – alpha component (default is 1.f).

inline void SetRGBA(const double iValues[4])

Sets a color from an array of four values.

Parameters

iValues – r, g, b and a values of the color.

virtual ~Color()

Destructor.

void ToCIEXYZ(float &oX, float &oY, float &oZ) const

Converts a linear sRGB color to CIE XYZ color space.

Parameters
  • oX – reference to the X component of the returned CIE XYZ color.

  • oY – reference to the Y component of the returned CIE XYZ color.

  • oZ – reference to the Z component of the returned CIE XYZ color.

void ToCIExyY(float &ox, float &oy, float &oY) const

Converts a linear sRGB color to CIE xyY color space.

Parameters
  • ox – reference to the x component of the returned CIE xyY color.

  • oy – reference to the y component of the returned CIE xyY color.

  • oY – reference to the Y component of the returned CIE xyY color.

inline bool operator==(const RED::Color &iOther) const

Equality test operator.

Parameters

iOtherRED::Color to test with.

inline bool operator!=(const RED::Color &iOther) const

Inequality test operator.

Parameters

iOtherRED::Color to test with.

inline RED::Color operator+(const RED::Color &iSource) const

Addition operation.

Builds a new color by the addition of two others.

Parameters

iSource – The color to add to ‘this’.

Returns

The sum of the two input colors.

inline RED::Color operator-(const RED::Color &iSource) const

Subtraction operation.

Builds a new color by the subtraction of two others.

Parameters

iSource – The color to subtract from ‘this’.

Returns

The subtraction of the two input colors.

inline void operator+=(const RED::Color &iSource)

Increment operation.

Adds the iSource color to ‘this’.

Parameters

iSource – The color to add to ‘this’.

inline void operator-=(const RED::Color &iSource)

Decrement operation.

Subtracts the iSource color to ‘this’.

Parameters

iSource – The color to subtract from ‘this’.

inline void operator*=(const RED::Color &iSource)

Color modulation operation.

Multiply each component of ‘this’ by those of iSource.

Parameters

iSourceColor to multiply by.

inline void operator*=(float iScalar)

Scalar product.

Multiply each component of ‘this’ by the given float.

Parameters

iScalar – The number to multiply ‘this’ components by.

inline RED::Color operator*(const RED::Color &iSource) const

Color modulation operation.

Multiply each component of ‘this’ by those of iSource.

Parameters

iSourceColor to multiply by.

Returns

The resulting color.

inline RED::Color operator/(float iScalar) const

Scalar division.

Divide each component of ‘this’ by the given float.

Parameters

iScalar – The number to divide ‘this’ components by.

Returns

The resulting color.

inline void operator/=(float iScalar)

In-place scalar division.

Divide each component of ‘this’ by the given float.

Parameters

iScalar – The number to divide ‘this’ components by.

inline bool operator<(const RED::Color &iColor) const

Color comparison operator.

Compares the two colors. The comparison occurs for each component of the compared colors. This operator is suitable for a RED::Map key lookup using colors.

Parameters

iColorColor to compare to.

Returns

true if this is < to iColor.

inline float GetIntensity() const

Gets the intensity of the color.

We define the color intensity by dot((RGB),(AAA))/3.0f.

Returns

the intensity of the color.

inline float R() const

Gets the red component of the color.

Returns

The red component of the color.

inline float G() const

Gets the green component of the color.

Returns

The green component of the color.

inline float B() const

Gets the blue component of the color.

Returns

The blue component of the color.

inline float A() const

Gets the alpha component of the color.

Returns

The alpha component of the color.

inline void RGBClamp(const RED::Color &iColor)

Clamps each channel between 0 and a given value.

The clamping follows those rules:

  1. ‘this’->_r/_g/_b = min( ‘this’->_r/_g/_b, iColor._r/_g/_b )

  2. ‘this’->_r/_g/_b = max( ‘this’->_r/_g/_b, 0.0 )

After the call, the callee will have its components in the [0, iColor._r], [0, iColor._g] and [0, iColor._b] ranges.

Parameters

iColor – The clamping value for each color channel.

inline bool IsLower(const RED::Color &iColor) const

Checks if all the components of ‘this’ are lower than (or equal to) those of a given color.

Parameters

iColor – The color to test with.

Returns

true if all the components of ‘this’ are lower than (or equal to) those of iColor, false otherwise.

inline float GetMinComponent() const

Gets the smallest component of the color.

Returns

The smallest component of the color.

inline float GetMaxComponent() const

Gets the biggest component of the color.

Returns

The biggest component of the color.

inline float GetCIELuminance() const

Gets the luminance value of the color as defined by the CIE.

The luminance is the Y component from the CIE XYZ or xyY color space as converted from the linear sRGB color space.

Returns

the luminance value of the color as defined by the CIE.

void Pack(unsigned char *iOutput) const

Packs the floating point color on 4 bytes.

The alpha term is discarded and not packed.

Parameters

iOutput – pointer to the packed color (must be allocated for at least 4 bytes).

const RED::Color &Unpack(const unsigned char *iInput)

Unpacks a floating point color from 4 packed bytes.

The alpha term of the returned color is set to 1.

Parameters

iInput – pointer to the input 4 bytes.

Returns

the unpacked color.

inline void ToHalfFloat(unsigned short oHalf[4]) const

Converts the color components to half float values.

Parameters

oHalf – An array of 4 half float values.

inline void ToCharRGBA(unsigned char oCharRGBA[4]) const

Converts the color components to unsigned char values.

Colors components are clamped to [0,1] and then converted to unsigned char.

Parameters

oCharRGBA – An array of 4 unsigned char values.

Public Members

float _r

Red component of the color.

float _g

Green component of the color.

float _b

Blue component of the color.

float _a

Alpha component of the color.

Public Static Functions

static inline RED::CID GetClassID()
static Color Random()
Returns

a random color.

static Color FromCharRGBA(unsigned char iR, unsigned char iG, unsigned char iB, unsigned char iA = 255)

Constructs a RED::Color instance based upon four (at least three) user defined values (between 0 and 255). Color space used is linear sRGB.

Parameters
  • iR – Red component of the color.

  • iG – Green component of the color.

  • iB – Blue component of the color.

  • iA – Alpha component of the color (default is opaque/255).

Returns

the corresponding color.

static Color FromTemperature(float iTemperature)

Constructs a RED::Color instance from a color temperature expressed in Kelvin.

../build/doxygen/RED/xml/API_Color_temperature.png

Note that contrary to one can expect, colors are getting more blue as the temperature increases.

The returned color has its alpha component set to 1.

Parameters

iTemperature – the color temperature in Kelvin.

Returns

the corresponding color.

static Color FromCIEXYZ(float iX, float iY, float iZ)

Constructs a RED::Color instance from a color in the CIE XYZ color space.

The resulting color is in the linear sRGB color space. The alpha component of the returned color is set to 1.

Parameters
  • iX – first stimulus value.

  • iY – second stimulus value.

  • iZ – third stimulus value.

Returns

the corresponding RGB color in linear sRGB color space.

static Color FromCIExyY(float ix, float iy, float iY)

Constructs a RED::Color instance from a color in the CIE xyY color space.

The resulting color is in the linear sRGB color space. The alpha component of the returned color is set to 1.

Parameters
  • ix – first stimulus value.

  • iy – second stimulus value.

  • iY – third stimulus value.

Returns

the corresponding RGB color in linear sRGB color space.

static void DecodeRGBAAA(float oColor[4], double iColor[4])

Decodes a pixel encoded in RED::FMT_FLOAT_RGBA_AA format to RED::FMT_FLOAT_RGBA.

Parameters
  • oColor – Decoded pixel color (4 floats).

  • iColor – Source pixel color (4 doubles).

static void EncodeRGBAAA(double oColor[4], float iColor[4])

Encodes a pixel color in the RED::FMT_FLOAT_RGBA_AA format.

Parameters
  • oColor – Encoded pixel color (4 doubles).

  • iColor – Source pixel color to encode (4 floats).

static void GetRGBAAABackground(float oBackColor[4], double iColor[4])

Extracts the background component encoded in a RED::FMT_FLOAT_RGBA_AA format.

This method retrieves the background color encoded in the source iColor.

Parameters
  • oBackColor – Retrieved background component (4 floats).

  • iColor – Source color (4 doubles, RGBA_AA format).

static void SetRGBAAABackground(double oColor[4], double iColor[4], float iBackColor[4])

Replaces the background component encoded in a RED::FMT_FLOAT_RGBA_AA format.

oColor and iColor may point to the same memory address.

Parameters
  • oColorColor after replacement (4 doubles, RGBA_AA format).

  • iColor – Source color before replacement (4 doubles, RGBA_AA format).

  • iBackColor – Background color to replace in the RGBA_AA (4 floats).

Public Static Attributes

static const RED::Color UNDEFINED

( -1.f, -1.f, -1.f, -1.f ).

static const RED::Color TRANSPARENCY

( 0.f, 0.f, 0.f, 0.f ).

static const RED::Color RED

( 1.f, 0.f, 0.f, 1.f ).

static const RED::Color GREEN

( 0.f, 1.f, 0.f, 1.f ).

static const RED::Color BLUE

( 0.f, 0.f, 1.f, 1.f ).

static const RED::Color CYAN

( 0.f, 1.f, 1.0f, 1.f ).

static const RED::Color MAGENTA

( 1.f, 0.f, 1.0f, 1.f ).

static const RED::Color YELLOW

( 1.f, 1.f, 0.0f, 1.f ).

static const RED::Color DARK_RED

( 0.25f, 0.f, 0.f, 1.f ).

static const RED::Color DARK_GREEN

( 0.f, 0.25f, 0.f, 1.f ).

static const RED::Color DARK_BLUE

( 0.f, 0.f, 0.25f, 1.f ).

static const RED::Color WHITE

( 1.f, 1.f, 1.f, 1.f ).

static const RED::Color GREY

( 0.5f, 0.5f, 0.5f, 1.f ).

static const RED::Color DARK_GREY

( 0.25f, 0.25f, 0.25f, 1.f ).

static const RED::Color LIGHT_GREY

( 0.75f, 0.75f, 0.75f, 1.f ).

static const RED::Color BLACK

( 0.f, 0.f, 0.f, 1.f ).