Color
Fields
float |
|
float |
|
float |
|
float |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
const Color |
|
Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
void |
|
|
|
void |
|
void |
|
bool |
|
bool |
|
|
|
|
|
void |
|
void |
|
void |
|
void |
|
|
|
|
|
void |
|
bool |
|
float |
|
float |
|
float |
|
float |
|
float |
|
void |
|
bool |
|
float |
|
float |
|
float |
|
void |
|
const Color & |
|
void |
|
void |
|
|
|
|
|
|
|
|
|
|
|
void |
|
void |
|
void |
|
void |
|
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:
0, 0, 0, 0
1, 0, 0, 1
0, 1, 0, 1
0, 0, 1, 1
0, 1, 1, 1
1, 0, 1, 1
1, 1, 0, 1
0.25, 0, 0, 1
0, 0.25, 0, 1
0, 0, 0.25, 1
1, 1, 1, 1
0.5, 0.5, 0.5, 1
0.25, 0.25, 0.25, 1
0.75, 0.75, 0.75, 1
0, 0, 0, 1
-1, -1, -1, -1
Public Functions
- SET_CID (CID_class_REDColor) IMPLEMENT_AS()
-
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 = 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).
-
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
iOther – RED::Color to test with.
-
inline bool operator!=(const RED::Color &iOther) const
Inequality test operator.
- Parameters
iOther – RED::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
iSource – Color 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
iSource – Color 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
iColor – Color 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:
‘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.
-
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 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.
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
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 Static Attributes