| TGX 1.0.8 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
tgx::RGB32 Struct Reference

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

## Detailed Description

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

## Constructor & Destructor Documentation

## ◆ RGB32() [1/10]

tgx::RGB32::RGB32 | ( |  | ) |
| default

Default constructor.

Color is undefined.

## ◆ RGB32() [2/10]

constexpr tgx::RGB32::RGB32 | ( | int | r,
|  | int | g,
|  | int | b,
|  | int | a = `DEFAULT_A`
| ) |  |
| inline constexpr

Constructor from raw r,g,b,a values.

All values in [0,255].

## ◆ RGB32() [3/10]

constexpr tgx::RGB32::RGB32 | ( | iVec3 | v | ) |
| inline constexpr

Constructor from a fVec3 with components (x=R, y=G, z=B) in [0,255].

Component A is set to DEFAULT_A (opaque).

## ◆ RGB32() [4/10]

tgx::RGB32::RGB32 | ( | float | r,
|  | float | g,
|  | float | b,
|  | float | a = `-1.0f`
| ) |  |
| inline

Constructor from float r,g,b,a in [0.0f, 1.0f].

If unspecified, component A is set to DEFAULT_A.

## ◆ RGB32() [5/10]

tgx::RGB32::RGB32 | ( | fVec3 | v | ) |
| 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).

## ◆ RGB32() [6/10]

constexpr tgx::RGB32::RGB32 | ( | uint16_t | val | ) |
| inline constexpr

Constructor from a uint16_t (seen as RGB565).

Component A is set to DEFAULT_A.

## ◆ RGB32() [7/10]

constexpr tgx::RGB32::RGB32 | ( | const RGB565 & | c | ) |
| inline constexpr

Constructor from a RGB565 color.

Component A is set to DEFAULT_A.

## ◆ RGB32() [8/10]

constexpr tgx::RGB32::RGB32 | ( | const RGB24 & | c | ) |
| inline constexpr

Constructor from a RGB24 color.

Component A is set to DEFAULT_A.

## ◆ RGB32() [9/10]

constexpr tgx::RGB32::RGB32 | ( | const RGBf & | c | ) |
| inline constexpr

Constructor from a RGBf color.

Component A is set to DEFAULT_A.

## ◆ RGB32() [10/10]

tgx::RGB32::RGB32 | ( | const HSV & | c | ) |

Constructor from a HSV color.

Component A is set to DEFAULT_A.

## Member Function Documentation

## ◆ operator iVec3()

tgx::RGB32::operator iVec3 | ( |  | ) | const
| inline explicit

Cast into an iVec3.

Raw values (component A is ignored).

## ◆ operator fVec3()

tgx::RGB32::operator fVec3 | ( |  | ) | const
| inline explicit

Cast into an fVec3.

Values in [0.0f, 1.0f] (component A is ignored).

## ◆ operator iVec4()

tgx::RGB32::operator iVec4 | ( |  | ) | const
| inline explicit

Cast into an iVec4.

Raw values.

## ◆ operator fVec4()

tgx::RGB32::operator fVec4 | ( |  | ) | const
| inline explicit

Cast into an fVec4.

Values in [0.0f, 1.0f].

## ◆ operator=() [1/7]

RGB32 & tgx::RGB32::operator= | ( | const RGB565 & | c | ) |
| inline

Assignement operator from a RGB565 color.

Component A is set to DEFAULT_A.

## ◆ operator=() [2/7]

RGB32 & tgx::RGB32::operator= | ( | const RGB24 & | c | ) |
| inline

Assignement operator from a RGB24 color.

Component A is set to DEFAULT_A.

## ◆ operator=() [3/7]

RGB32 & tgx::RGB32::operator= | ( | const RGBf & | c | ) |
| inline

Assignement operator from a RGBf color.

Component A is set to DEFAULT_A.

## ◆ operator=() [4/7]

RGB32 & tgx::RGB32::operator= | ( | const HSV & | c | ) |

Assignement operator from a HSV color.

Component A is set to DEFAULT_A.

## ◆ operator=() [5/7]

RGB32 & tgx::RGB32::operator= | ( | iVec3 | v | ) |
| inline

Assignement operator from a vector (x=R, y=G, z=B).

Raw values. Component A is set to DEFAULT_A.

## ◆ operator=() [6/7]

RGB32 & tgx::RGB32::operator= | ( | iVec4 | v | ) |
| inline

Assignement operator from a vector (x=R, y=G, z=B, w=A).

Raw values.

## ◆ operator=() [7/7]

RGB32 & tgx::RGB32::operator= | ( | fVec3 | v | ) |
| inline

Assignement operator from a vector (x=R, y=G, z=B) in [0.0f, 1.0f].

Component A is set to DEFAULT_A.

## ◆ blend() [1/2]

void tgx::RGB32::blend | ( | const RGB32 & | fg_col,
|  | float | alpha
| ) |  |
| 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.

Parameters

  fg_col | The foreground color.
  alpha | Additional opacity/alpha multiplier in [0.0f,1.0f].

## ◆ blend256()

void tgx::RGB32::blend256 | ( | const RGB32 & | fg_col,
|  | uint32_t | alpha
| ) |  |
| 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.

Parameters

  fg_col | The foreground color.
  alpha | The opacity/alpha multiplier in [0,256].

## ◆ blend() [2/2]

void tgx::RGB32::blend | ( | RGB32 | fg_col | ) |
| 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.

Parameters

  fg_col | The foreground color. The alpha channel of the color is used for blending.

## ◆ premultiply()

void tgx::RGB32::premultiply | ( |  | ) |
| 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.

## ◆ setOpacity()

void tgx::RGB32::setOpacity | ( | float | op | ) |
| 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.

## ◆ multOpacity()

void tgx::RGB32::multOpacity | ( | float | op | ) |
| 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.

## ◆ getMultOpacity()

RGB32 tgx::RGB32::getMultOpacity | ( | float | op | ) | const
| 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.

The documentation for this struct was generated from the following file:

- src/Color.h