![]() |
TGX 1.0.3
A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.
|
Color in R8/G8/B8/A8 format. More...
#include <Color.h>
Public Member Functions | |
RGB32 ()=default | |
Default constructor. More... | |
constexpr | RGB32 (int r, int g, int b, int a=DEFAULT_A) |
Constructor from raw r,g,b,a values. More... | |
constexpr | RGB32 (iVec3 v) |
Constructor from a fVec3 with components (x=R, y=G, z=B) in [0,255]. More... | |
constexpr | RGB32 (iVec4 v) |
Constructor from a fVec4 with components (x=R, y=G, z=B, w=A) in [0,255]. | |
RGB32 (float r, float g, float b, float a=-1.0f) | |
Constructor from float r,g,b,a in [0.0f, 1.0f]. More... | |
RGB32 (fVec3 v) | |
Constructor from a fVec3 with components (x=R, y=G, z=B) in [0.0f, 1.0f]. More... | |
RGB32 (fVec4 v) | |
Constructor from a fVec4 with components (x=R, y=G, z=B, w=A) in [0.0f, 1.0f]. | |
constexpr | RGB32 (uint32_t c) |
Constructor from a uint32_t. | |
constexpr | RGB32 (uint16_t val) |
Constructor from a uint16_t (seen as RGB565). More... | |
constexpr | RGB32 (uint64_t val) |
Constructor from a uint64_t (seen as RGB64). | |
RGB32 (const RGB32 &)=default | |
Default Copy constructor. | |
constexpr | RGB32 (const RGB565 &c) |
Constructor from a RGB565 color. More... | |
constexpr | RGB32 (const RGB24 &c) |
Constructor from a RGB24 color. More... | |
constexpr | RGB32 (const RGB64 &c) |
Constructor from a RGB64 color. | |
constexpr | RGB32 (const RGBf &c) |
Constructor from a RGBf color. More... | |
RGB32 (const HSV &c) | |
Constructor from a HSV color. More... | |
operator uint32_t & () | |
Cast into a uint32_t (non-const reference version) | |
operator const uint32_t & () const | |
Cast into a uint32_t (const reference version) | |
operator iVec3 () const | |
Cast into an iVec3. More... | |
operator fVec3 () const | |
Cast into an fVec3. More... | |
operator iVec4 () const | |
Cast into an iVec4. More... | |
operator fVec4 () const | |
Cast into an fVec4. More... | |
RGB32 & | operator= (const RGB32 &)=default |
Default assignement operator. | |
RGB32 & | operator= (const RGB565 &c) |
Assignement operator from a RGB565 color. More... | |
RGB32 & | operator= (const RGB24 &c) |
Assignement operator from a RGB24 color. More... | |
RGB32 & | operator= (const RGB64 &c) |
Assignement operator from a RGB64 color. | |
RGB32 & | operator= (const RGBf &c) |
Assignement operator from a RGBf color. More... | |
RGB32 & | operator= (const HSV &c) |
Assignement operator from a HSV color. More... | |
RGB32 & | operator= (iVec3 v) |
Assignement operator from a vector (x=R, y=G, z=B). More... | |
RGB32 & | operator= (iVec4 v) |
Assignement operator from a vector (x=R, y=G, z=B, w=A). More... | |
RGB32 & | operator= (fVec3 v) |
Assignement operator from a vector (x=R, y=G, z=B) in [0.0f, 1.0f]. More... | |
RGB32 & | operator= (fVec4 v) |
Assignement operator from a vector (x=R, y=G, z=B, w=A) in [0.0f, 1.0f]. | |
void | operator+= (const RGB32 &c) |
Add another color, component by component (including alpha channel). | |
void | operator-= (const RGB32 &c) |
Substract another color, component by component (including alpha channel). | |
void | operator+= (uint8_t v) |
Add the scalar value v to each component (including alpha channel). | |
void | operator-= (uint8_t v) |
Substract the scalar value v to each component (including alpha channel). | |
void | operator*= (uint8_t v) |
Multiply each component by the scalar value v (including alpha channel). | |
void | operator*= (float v) |
Multiply each component by the scalar (floating point) value v (including alpha channel). | |
void | operator/= (uint8_t v) |
Divide each component by the scalar value v (including alpha channel). | |
void | operator/= (float v) |
Divide each component by the scalar (floating point value) v, including the alpha channel. | |
constexpr bool | operator== (const RGB32 &c) const |
Equality comparator. | |
constexpr bool | operator!= (const RGB32 &c) const |
Inequality comparator. | |
void | blend (const RGB32 &fg_col, float alpha) |
alpha-blend fg_col over this one with a given opacity in the range 0.0f (fully transparent) to 1.0f (fully opaque). More... | |
void | blend256 (const RGB32 &fg_col, uint32_t alpha) |
alpha-blend fg_col over this one with a given opacity in the range 0.0f (fully transparent) to 1.0f (fully opaque). More... | |
void | blend (RGB32 fg_col) |
alpha-blend fg_col over this one with a given opacity in the range 0.0f (fully transparent) to 1.0f (fully opaque). More... | |
void | mult256 (int mr, int mg, int mb) |
Multiply each color component by a given factor m/256 with m in [0,256] except the A component. | |
void | mult256 (int mr, int mg, int mb, int ma) |
Multiply each color component by a given factor m/256 with m in [0,256]. | |
void | premultiply () |
Convert the color from plain alpha to pre-multiplied alpha. More... | |
float | opacity () const |
Return the opacity (alpha channel value) of this color in the range [0,1] (0=fully transparent, 1=fully opaque). | |
void | setOpacity (float op) |
Change the opacity of the color to a given value in [0.0f, 1.0f]. More... | |
void | multOpacity (float op) |
Multiply the opacity of the color by a given factor in [0.0f, 1.0f]. More... | |
RGB32 | getMultOpacity (float op) const |
Return a copy of this color with opacity multiplied by a given factor in [0.0f, 1.0f]. More... | |
void | setOpaque () |
Set the alpha channel of the color to fully opaque. | |
void | setTransparent () |
Set the alpha channel of the color to fully transparent. | |
Public Attributes | |
union { | |
uint32_t val | |
color as uint32_t | |
struct { | |
uint8_t B | |
Blue channel (8bits) | |
uint8_t G | |
Green channel (8bits) | |
uint8_t R | |
Red channel (8bits) | |
uint8_t A | |
Alpha channel (8bits) | |
} | |
}; | |
Static Public Attributes | |
static const uint8_t | DEFAULT_A = 255 |
fully opaque alpha value | |
Color in R8/G8/B8/A8 format.
Occupies 4 bytes in memory, aligned as uint32_t.
Can be converted from/to uint32_t.
the component A defaults to DEFAULT_A = 255 (fully opaque) if not specified.
Remark For all drawing/blending operations, the color is assume to have pre-multiplied alpha. Use the premultiply() method to convert a plain alpha color to its pre-multiplied version (https://developer.nvidia.com/content/alpha-blending-pre-or-not-pre).
|
default |
Default constructor.
Color is undefined.
|
inlineconstexpr |
Constructor from raw r,g,b,a values.
All values in [0,255].
|
inlineconstexpr |
Constructor from a fVec3 with components (x=R, y=G, z=B) in [0,255].
Component A is set to DEFAULT_A (opaque).
|
inline |
Constructor from float r,g,b,a in [0.0f, 1.0f].
If unspecified, component A is set to DEFAULT_A.
|
inline |
Constructor from a fVec3 with components (x=R, y=G, z=B) in [0.0f, 1.0f].
Component A is set to DEFAULT_A (opaque).
|
inlineconstexpr |
Constructor from a uint16_t (seen as RGB565).
Component A is set to DEFAULT_A.
|
inlineconstexpr |
Constructor from a RGB565 color.
Component A is set to DEFAULT_A.
|
inlineconstexpr |
Constructor from a RGB24 color.
Component A is set to DEFAULT_A.
|
inlineconstexpr |
Constructor from a RGBf color.
Component A is set to DEFAULT_A.
|
inlineexplicit |
Cast into an iVec3.
Raw values (component A is ignored).
|
inlineexplicit |
Cast into an fVec3.
Values in [0.0f, 1.0f] (component A is ignored).
Assignement operator from a RGB565 color.
Component A is set to DEFAULT_A.
Assignement operator from a RGB24 color.
Component A is set to DEFAULT_A.
Assignement operator from a RGBf color.
Component A is set to DEFAULT_A.
Assignement operator from a HSV color.
Component A is set to DEFAULT_A.
Assignement operator from a vector (x=R, y=G, z=B).
Raw values. Component A is set to DEFAULT_A.
Assignement operator from a vector (x=R, y=G, z=B, w=A).
Raw values.
Assignement operator from a vector (x=R, y=G, z=B) in [0.0f, 1.0f].
Component A is set to DEFAULT_A.
|
inline |
alpha-blend fg_col
over this one with a given opacity in the range 0.0f (fully transparent) to 1.0f (fully opaque).
WARNING The color fg_col is assumed to have pre-multiplied alpha.
fg_col | The foreground color. |
alpha | Additional opacity/alpha multiplier in [0.0f,1.0f]. |
|
inline |
alpha-blend fg_col
over this one with a given opacity in the range 0.0f (fully transparent) to 1.0f (fully opaque).
WARNING The color fg_col is assumed to have pre-multiplied alpha.
fg_col | The foreground color. |
alpha | The opacity/alpha multiplier in [0,256]. |
|
inline |
alpha-blend fg_col
over this one with a given opacity in the range 0.0f (fully transparent) to 1.0f (fully opaque).
WARNING The color fg_col is assumed to have pre-multiplied alpha.
fg_col | The foreground color. The alpha channel of the color is used for blending. |
|
inline |
Convert the color from plain alpha to pre-multiplied alpha.
Remark All colors type in TGX should have pre-multiplied alpha. This method should only be used when loading a color from external data (a png image for example) where the colors are not initially pre-multiplied.
|
inline |
Change the opacity of the color to a given value in [0.0f, 1.0f].
This method assumes (and returns) a color with pre-multiplied alpha.
Remark Use method multOpacity() instead whenever possible because it is faster.
|
inline |
Multiply the opacity of the color by a given factor in [0.0f, 1.0f].
This method assumes (and returns) a color with pre-multiplied alpha.
|
inline |
Return a copy of this color with opacity multiplied by a given factor in [0.0f, 1.0f].
This method assumes (and returns) a color with pre-multiplied alpha.