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 ( ) |
float | A ( ) 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 ( ) |
float | B ( ) const |
float | G ( ) const |
float | GetCIELuminance ( ) const |
float | GetIntensity ( ) const |
float | GetMaxComponent ( ) const |
float | GetMinComponent ( ) const |
bool | IsLower ( const RED::Color & iColor ) const |
bool | operator!= ( const RED::Color & iOther ) const |
RED::Color | operator* ( const RED::Color & iSource ) const |
void | operator*= ( const RED::Color & iSource ) |
void | operator*= ( float iScalar ) |
RED::Color | operator+ ( const RED::Color & iSource ) const |
void | operator+= ( const RED::Color & iSource ) |
RED::Color | operator- ( const RED::Color & iSource ) const |
void | operator-= ( const RED::Color & iSource ) |
RED::Color | operator/ ( float iScalar ) const |
void | operator/= ( float iScalar ) |
bool | operator< ( const RED::Color & iColor ) const |
bool | operator== ( const RED::Color & iOther ) const |
void | Pack ( unsigned char * iOutput ) const |
float | R ( ) const |
void | RGBClamp ( const RED::Color & iColor ) |
void | SetRGBA ( const double iValues[4] ) |
void | SetRGBA ( float iRed, float iGreen, float iBlue, float iAlpha = 1.f ) |
void | ToCharRGBA ( unsigned char oCharRGBA[4] ) const |
void | ToCIExyY ( float & ox, float & oy, float & oY ) const |
void | ToCIEXYZ ( float & oX, float & oY, float & oZ ) const |
void | ToHalfFloat ( unsigned short oHalf[4] ) const |
const RED::Color & | Unpack ( const unsigned char * iInput ) |
Public static functions:
static void | DecodeRGBAAA ( float oColor[4], double iColor[4] ) |
static void | EncodeRGBAAA ( double oColor[4], float iColor[4] ) |
static Color | FromCharRGBA ( unsigned char iR, unsigned char iG, unsigned char iB, unsigned char iA = 255 ) |
static Color | FromCIExyY ( float ix, float iy, float iY ) |
static Color | FromCIEXYZ ( float iX, float iY, float iZ ) |
static Color | FromTemperature ( float iTemperature ) |
static RED::CID | GetClassID ( ) |
static void | GetRGBAAABackground ( float oBackColor[4], double iColor[4] ) |
static Color | Random ( ) |
static void | SetRGBAAABackground ( 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::Color | BLACK |
static const RED::Color | BLUE |
static const RED::Color | CYAN |
static const RED::Color | DARK_BLUE |
static const RED::Color | DARK_GREEN |
static const RED::Color | DARK_GREY |
static const RED::Color | DARK_RED |
static const RED::Color | GREEN |
static const RED::Color | GREY |
static const RED::Color | LIGHT_GREY |
static const RED::Color | MAGENTA |
static const RED::Color | RED |
static const RED::Color | TRANSPARENCY |
static const RED::Color | UNDEFINED |
static const RED::Color | WHITE |
static const RED::Color | YELLOW |
Private static variables:
static const double | CIE_cmx [] |
static const double | CIE_cmy [] |
static const double | CIE_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::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 |
Functions documentation
public RED::Color::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]. |
public RED::Color::Color | ( | unsigned short | iR, |
unsigned short | iG, | ||
unsigned short | iB, | ||
unsigned short | iA = 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). |
public RED::Color::Color | ( | ) |
Default constructor.
The color is initialized to RED::Color::TRANSPARENCY.
public RED::Color::Color | ( | float | iIntensity | ) |
Grey color constructor from color intensity.
Parameters:
iIntensity | Intensity replicated on the 4 color components. |
public RED::Color::Color | ( | double | iIntensity | ) |
Grey color constructor from color intensity.
Parameters:
iIntensity | Intensity replicated on the 4 color components. |
public RED::Color::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). |
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 | ) |
public RED::Color::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). |
public virtual RED::Color::~Color | ( | ) |
Destructor.
public static void RED::Color::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). |
public static void RED::Color::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). |
public static Color RED::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:
public static Color RED::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:
public static Color RED::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:
public static Color RED::Color::FromTemperature | ( | float | iTemperature | ) |
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:
public static RED::CID RED::Color::GetClassID | ( | ) |
Reimplements: RED::Object::GetClassID.
public static void RED::Color::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). |
public static Color RED::Color::Random | ( | ) |
Returns:
public static void RED::Color::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:
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:
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:
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:
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:
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:
Reimplements: RED::Object::As.
public float RED::Color::B | ( | ) const |
Gets the blue component of the color.
Returns:
public float RED::Color::G | ( | ) const |
Gets the green component of the color.
Returns:
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:
public float RED::Color::GetIntensity | ( | ) const |
Gets the intensity of the color.
We define the color intensity by dot((RGB),(AAA))/3.0f.
Returns:
public float RED::Color::GetMaxComponent | ( | ) const |
Gets the biggest component of the color.
Returns:
public float RED::Color::GetMinComponent | ( | ) const |
Gets the smallest component of the color.
Returns:
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:
iColor | The color to test with. |
Returns:
public bool RED::Color::operator!= | ( | const RED::Color & | iOther | ) const |
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:
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*= | ( | float | iScalar | ) |
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:
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:
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/ | ( | float | iScalar | ) const |
Scalar division.
Divide each component of this by the given float.
Parameters:
iScalar: | The number to divide this components by. |
Returns:
public void RED::Color::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. |
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:
public bool RED::Color::operator== | ( | const RED::Color & | iOther | ) const |
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:
public void RED::Color::RGBClamp | ( | const RED::Color & | iColor | ) |
Clamps each channel between 0 and a given value.
The clamping follows those rules:
- this->_r/_g/_b = min( this->_r/_g/_b, iColor._r/_g/_b )
- 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 double | iValues[4] | ) |
Sets a color from an array of four values.
Parameters:
iValues | r, g, b and a values of the color. |
public void RED::Color::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). |
public void RED::Color::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 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 short | oHalf[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:
Variables documentation
Alpha component of the color.
Blue component of the color.
Green component of the color.
Red component of the color.
( 0.f, 0.f, 0.f, 1.f ).
( 0.f, 0.f, 1.f, 1.f ).
( 0.f, 1.f, 1.0f, 1.f ).
( 0.f, 0.f, 0.25f, 1.f ).
( 0.f, 0.25f, 0.f, 1.f ).
( 0.25f, 0.25f, 0.25f, 1.f ).
( 0.25f, 0.f, 0.f, 1.f ).
( 0.f, 1.f, 0.f, 1.f ).
( 0.5f, 0.5f, 0.5f, 1.f ).
( 0.75f, 0.75f, 0.75f, 1.f ).
( 1.f, 0.f, 1.0f, 1.f ).
( 1.f, 0.f, 0.f, 1.f ).
( 0.f, 0.f, 0.f, 0.f ).
( -1.f, -1.f, -1.f, -1.f ).
( 1.f, 1.f, 1.f, 1.f ).
( 1.f, 1.f, 0.0f, 1.f ).
1964 CIE color matching table for X component.
1964 CIE color matching table for Y component.
1964 CIE color matching table for Z component.