class RED::Color

RGBA color using 1 float per component. More...

#include <REDColor.h>

Inherits: Object.

Public functions:

Color ( unsigned char iR, unsigned char iG, unsigned char iB, unsigned char iA = 255 )
Color ( unsigned short iR, unsigned short iG, unsigned short iB, unsigned short iA = RED_HALF_ONE )
Color ( )
Color ( float iIntensity )
Color ( double iIntensity )
Color ( float iR, float iG, float iB, float iA = 1.0f )
Color ( const RED::Vector3 & iVector )
Color ( const RED::Vector4 & iVector )
Color ( double iR, double iG, double iB, double iA = 1.0 )
virtual ~Color ( )
floatA ( ) const
virtual void *As ( const RED::CID & iCID )
virtual const void *As ( const RED::CID & iCID ) const
template< class T_As > const T_As *As ( ) const
template< class T_As > T_As *As ( )
floatB ( ) const
floatG ( ) const
floatGetCIELuminance ( ) const
floatGetIntensity ( ) const
floatGetMaxComponent ( ) const
floatGetMinComponent ( ) const
boolIsLower ( const RED::Color & iColor ) const
booloperator!= ( const RED::Color & iOther ) const
RED::Coloroperator* ( const RED::Color & iSource ) const
voidoperator*= ( const RED::Color & iSource )
voidoperator*= ( float iScalar )
RED::Coloroperator+ ( const RED::Color & iSource ) const
voidoperator+= ( const RED::Color & iSource )
RED::Coloroperator- ( const RED::Color & iSource ) const
voidoperator-= ( const RED::Color & iSource )
RED::Coloroperator/ ( float iScalar ) const
voidoperator/= ( float iScalar )
booloperator< ( const RED::Color & iColor ) const
booloperator== ( const RED::Color & iOther ) const
voidPack ( unsigned char * iOutput ) const
floatR ( ) const
voidRGBClamp ( const RED::Color & iColor )
voidSetRGBA ( const double iValues[4] )
voidSetRGBA ( float iRed, float iGreen, float iBlue, float iAlpha = 1.f )
voidToCharRGBA ( unsigned char oCharRGBA[4] ) const
voidToCIExyY ( float & ox, float & oy, float & oY ) const
voidToCIEXYZ ( float & oX, float & oY, float & oZ ) const
voidToHalfFloat ( unsigned short oHalf[4] ) const
const RED::Color &Unpack ( const unsigned char * iInput )

Public static functions:

static voidDecodeRGBAAA ( float oColor[4], double iColor[4] )
static voidEncodeRGBAAA ( double oColor[4], float iColor[4] )
static ColorFromCharRGBA ( unsigned char iR, unsigned char iG, unsigned char iB, unsigned char iA = 255 )
static ColorFromCIExyY ( float ix, float iy, float iY )
static ColorFromCIEXYZ ( float iX, float iY, float iZ )
static ColorFromTemperature ( float iTemperature )
static RED::CIDGetClassID ( )
static voidGetRGBAAABackground ( float oBackColor[4], double iColor[4] )
static ColorRandom ( )
static voidSetRGBAAABackground ( double oColor[4], double iColor[4], float iBackColor[4] )

Public variables:

float_a
float_b
float_g
float_r

Public static variables:

static const RED::ColorBLACK
static const RED::ColorBLUE
static const RED::ColorCYAN
static const RED::ColorDARK_BLUE
static const RED::ColorDARK_GREEN
static const RED::ColorDARK_GREY
static const RED::ColorDARK_RED
static const RED::ColorGREEN
static const RED::ColorGREY
static const RED::ColorLIGHT_GREY
static const RED::ColorMAGENTA
static const RED::ColorRED
static const RED::ColorTRANSPARENCY
static const RED::ColorUNDEFINED
static const RED::ColorWHITE
static const RED::ColorYELLOW

Private static variables:

static const doubleCIE_cmx []
static const doubleCIE_cmy []
static const doubleCIE_cmz []

Detailed description:

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::TRANSPARENCY0, 0, 0, 0
RED::Color::RED1, 0, 0, 1
RED::Color::GREEN0, 1, 0, 1
RED::Color::BLUE0, 0, 1, 1
RED::Color::CYAN0, 1, 1, 1
RED::Color::MAGENTA1, 0, 1, 1
RED::Color::YELLOW1, 1, 0, 1
RED::Color::DARK_RED0.25, 0, 0, 1
RED::Color::DARK_GREEN0, 0.25, 0, 1
RED::Color::DARK_BLUE0, 0, 0.25, 1
RED::Color::WHITE1, 1, 1, 1
RED::Color::GREY0.5, 0.5, 0.5, 1
RED::Color::DARK_GREY0.25, 0.25, 0.25, 1
RED::Color::LIGHT_GREY0.75, 0.75, 0.75, 1
RED::Color::BLACK0, 0, 0, 1
RED::Color::UNDEFINED-1, -1, -1, -1

Functions documentation

public RED::Color::Color(unsigned chariR,
unsigned chariG,
unsigned chariB,
unsigned chariA = 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].
public RED::Color::Color(unsigned shortiR,
unsigned shortiG,
unsigned shortiB,
unsigned shortiA = RED_HALF_ONE
)

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

Default constructor.

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

public RED::Color::Color(floatiIntensity)

Grey color constructor from color intensity.

Parameters:

iIntensityIntensity replicated on the 4 color components.
public RED::Color::Color(doubleiIntensity)

Grey color constructor from color intensity.

Parameters:

iIntensityIntensity replicated on the 4 color components.
public RED::Color::Color(floatiR,
floatiG,
floatiB,
floatiA = 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).
public RED::Color::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.
public RED::Color::Color(const RED::Vector4 &iVector)

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

Parameters:

iVector:The source vector to build from.
public RED::Color::Color(doubleiR,
doubleiG,
doubleiB,
doubleiA = 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).
public virtual RED::Color::~Color()

Destructor.

public static void RED::Color::DecodeRGBAAA(floatoColor[4],
doubleiColor[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).
public static void RED::Color::EncodeRGBAAA(doubleoColor[4],
floatiColor[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).
public static Color RED::Color::FromCharRGBA(unsigned chariR,
unsigned chariG,
unsigned chariB,
unsigned chariA = 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.
public static Color RED::Color::FromCIExyY(floatix,
floatiy,
floatiY
)

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.
public static Color RED::Color::FromCIEXYZ(floatiX,
floatiY,
floatiZ
)

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.
public static Color RED::Color::FromTemperature(floatiTemperature)

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

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.
public static void RED::Color::GetRGBAAABackground(floatoBackColor[4],
doubleiColor[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).
public static Color RED::Color::Random()

Returns:

a random color.
public static void RED::Color::SetRGBAAABackground(doubleoColor[4],
doubleiColor[4],
floatiBackColor[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:

oColor:Color 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 float RED::Color::A() const

Gets the alpha component of the color.

Returns:

The alpha component of the color.
public virtual void * RED::Color::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.

Reimplements: RED::Object::As.

public virtual const void * RED::Color::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.

Reimplements: RED::Object::As.

template< class T_As > public const T_As * RED::Color::As() const

Template version of the as const method.

Simply set T to be the class you want to retrieve an interface to.

Returns:

A pointer to a const instance of class T on success, NULL otherwise.

Reimplements: RED::Object::As.

template< class T_As > public T_As * RED::Color::As()

Template version of the as method.

Simply set T to be the class you want to retrieve an interface to.

Returns:

A pointer to an instance of class T on success, NULL otherwise.

Reimplements: RED::Object::As.

public float RED::Color::B() const

Gets the blue component of the color.

Returns:

The blue component of the color.
public float RED::Color::G() const

Gets the green component of the color.

Returns:

The green component of the color.
public float RED::Color::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.
public float RED::Color::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.
public float RED::Color::GetMaxComponent() const

Gets the biggest component of the color.

Returns:

The biggest component of the color.
public float RED::Color::GetMinComponent() const

Gets the smallest component of the color.

Returns:

The smallest component of the color.
public bool RED::Color::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:

iColorThe color to test with.

Returns:

true if all the components of this are lower than (or equal to) those of iColor, false otherwise.
public bool RED::Color::operator!=(const RED::Color &iOther) const

Inequality test operator.

Parameters:

iOther:RED::Color to test with.
public RED::Color RED::Color::operator*(const RED::Color &iSource) const

Color modulation operation.

Multiply each component of this by those of iSource.

Parameters:

iSource:Color to multiply by.

Returns:

The resulting color.
public void RED::Color::operator*=(const RED::Color &iSource)

Color modulation operation.

Multiply each component of this by those of iSource.

Parameters:

iSource:Color to multiply by.
public void RED::Color::operator*=(floatiScalar)

Scalar product.

Multiply each component of this by the given float.

Parameters:

iScalar:The number to multiply this components by.
public RED::Color 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.
public void RED::Color::operator+=(const RED::Color &iSource)

Increment operation.

Adds the iSource color to this.

Parameters:

iSource:The color to add to this.
public RED::Color 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.
public void RED::Color::operator-=(const RED::Color &iSource)

Decrement operation.

Subtracts the iSource color to this.

Parameters:

iSource:The color to subtract from this.
public RED::Color RED::Color::operator/(floatiScalar) 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.
public void RED::Color::operator/=(floatiScalar)

In-place scalar division.

Divide each component of this by the given float.

Parameters:

iScalar:The number to divide this components by.
public bool RED::Color::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:

iColor:Color to compare to.

Returns:

true if this is < to iColor.
public bool RED::Color::operator==(const RED::Color &iOther) const

Equality test operator.

Parameters:

iOther:RED::Color to test with.
public void RED::Color::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).
public float RED::Color::R() const

Gets the red component of the color.

Returns:

The red component of the color.
public void RED::Color::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.
public void RED::Color::SetRGBA(const doubleiValues[4])

Sets a color from an array of four values.

Parameters:

iValuesr, g, b and a values of the color.
public void RED::Color::SetRGBA(floatiRed,
floatiGreen,
floatiBlue,
floatiAlpha = 1.f
)

Sets a color from the four RGBA components.

Parameters:

iRedred component.
iGreengreen component.
iBlueblue component.
iAlphaalpha component (default is 1.f).
public void RED::Color::ToCharRGBA(unsigned charoCharRGBA[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 void RED::Color::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.
public void RED::Color::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.
public void RED::Color::ToHalfFloat(unsigned shortoHalf[4]) const

Converts the color components to half float values.

Parameters:

oHalf:An array of 4 half float values.
public const RED::Color & 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.

Variables documentation

public float RED::Color::_a

Alpha component of the color.

public float RED::Color::_b

Blue component of the color.

public float RED::Color::_g

Green component of the color.

public float RED::Color::_r

Red component of the color.

public static const RED::Color RED::Color::BLACK

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

public static const RED::Color RED::Color::BLUE

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

public static const RED::Color RED::Color::CYAN

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

public static const RED::Color RED::Color::DARK_BLUE

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

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

public static const RED::Color RED::Color::DARK_GREY

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

public static const RED::Color RED::Color::DARK_RED

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

public static const RED::Color RED::Color::GREEN

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

public static const RED::Color RED::Color::GREY

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

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

public static const RED::Color RED::Color::MAGENTA

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

public static const RED::Color RED::Color::RED

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

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

public static const RED::Color RED::Color::UNDEFINED

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

public static const RED::Color RED::Color::WHITE

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

public static const RED::Color RED::Color::YELLOW

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

private static const double RED::Color::CIE_cmx[]

1964 CIE color matching table for X component.

private static const double RED::Color::CIE_cmy[]

1964 CIE color matching table for Y component.

private static const double RED::Color::CIE_cmz[]

1964 CIE color matching table for Z component.