| 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::RGB64 Struct Reference

Color in R16/G16/B16/A16 format. More...

`#include <Color.h>`

## Public Member Functions
| RGB64 ()=default
| Default constructor. More...
constexpr | RGB64 (int r, int g, int b, int a=DEFAULT_A)
| Constructor from raw r,g,b,a value in [0,65535].
constexpr | RGB64 (iVec3 v)
| Constructor from a iVec3 with components (x=R, y=G, z=B) in [0,65535]. More...
constexpr | RGB64 (iVec4 v)
| Constructor from a iVec4 with components (x=R, y=G, z=B, w=A) in [0,65535].
| RGB64 (float r, float g, float b, float a=-1.0f)
| Constructor from float r,g,b,a in [0.0f, 1.0f]. More...
| RGB64 (fVec3 v)
| Constructor from a fVec3 with components (x=R, y=G, z=B) in [0.0f, 1.0f]. More...
| RGB64 (fVec4 v)
| Constructor from a fVec4 with components (x=R, y=G, z=B, w=A) in [0.0f, 1.0f].
constexpr | RGB64 (uint64_t c)
| Constructor from a uint64_t.
| RGB64 (uint16_t val)
| Constructor from a uint16_t (seen as RGB565).
| RGB64 (uint32_t val)
| Constructor from a uint32_t (seen as RGB32).
| RGB64 (const RGB64 &)=default
| Default Copy ctor.
| RGB64 (const RGB565 &c)
| Constructor from a RGB565 color. More...
| RGB64 (const RGB24 &c)
| Constructor from a RGB24 color. More...
| RGB64 (const RGB32 &c)
| Constructor from a RGB32 color.
| RGB64 (const RGBf &c)
| Constructor from a RGBf color. More...
| RGB64 (const HSV &c)
| Constructor from a HSV color. More...
| operator uint64_t & ()
| Cast into a uint64_t (non-const reference version)
| operator const uint64_t & () const
| Cast into a uint64_t (const reference version)
| operator iVec3 () const
| Cast into an iVec3 with components (x=R, y=G, z=B) in [0,65535]. More...
| operator fVec3 () const
| Cast into an fVec3 with components (x=R, y=G, z=B) in [0.0f, 1.0f]. More...
| operator iVec4 () const
| Cast into an iVec4 with components (x=R, y=G, z=B, w=A) in [0,65535].
| operator fVec4 () const
| Cast into an fVec4 with components (x=R, y=G, z=B, w=A) in [0.0f, 1.0f].
RGB64 & | operator= (const RGB64 &)=default
| Default assignement operator.
RGB64 & | operator= (const RGB565 &c)
| Assignement operator from a RGB24 color. More...
RGB64 & | operator= (const RGB24 &c)
| Assignement operator from a RGB24 color. More...
RGB64 & | operator= (const RGB32 &c)
| Assignement operator from a RGB32 color.
RGB64 & | operator= (const RGBf &c)
| Assignement operator from a RGBf color. More...
RGB64 & | operator= (const HSV &c)
| Assignement operator from a HSV color. More...
RGB64 & | operator= (iVec3 v)
| Assignement operator from a iVec3 with components (x=R, y=G, z=B) in [0,65535]. More...
RGB64 & | operator= (iVec4 v)
| Assignement operator from a iVec4 with components (x=R, y=G, z=B, w=A) in [0,65535].
RGB64 & | operator= (fVec3 v)
| Assignement operator from a fVec3 with components (x=R, y=G, z=B) in [0.0f,1.0f]. More...
RGB64 & | operator= (fVec4 v)
| Assignement operator from a fVec3 with components (x=R, y=G, z=B, w=A) in [0.0f,1.0f].
void | operator+= (const RGB64 &c)
| Add another color, component by component, including the alpha channel.
void | operator-= (const RGB64 &c)
| Substract another color, component by component, including the alpha channel.
void | operator+= (uint16_t v)
| Add the scalar value v to each component, including the alpha channel.
void | operator-= (uint16_t v)
| Substract the scalar value v to each component, including the alpha channel.
void | operator*= (uint16_t v)
| Multiply each component by the scalar value v, including the alpha channel.
void | operator*= (float v)
| Multiply each component by the scalar (floating point) value v, including the alpha channel.
void | operator/= (uint16_t v)
| Divide each component by the scalar value v, including the alpha channel.
void | operator/= (float v)
| Divide each component by the scalar (floating point value) v, including the alpha channel.
constexpr bool | operator== (const RGB64 &c) const
| Equality comparator.
constexpr bool | operator!= (const RGB64 &c) const
| Inequality comparator.
void | blend (const RGB64 &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 RGB64 &fg_col, uint32_t alpha)
| alpha-blend `fg_col` over this one with a given opacity in the integer range 0 (fully transparent) to 256 (fully opaque). More...
void | blend65536 (RGB64 fg_col, uint32_t alpha)
| alpha-blend `fg_col` over this one with a given opacity in the integer range 0 (fully transparent) to 65536 (fully opaque). More...
void | blend (const RGB64 &fg_col)
| alpha-blend `fg_col` over this one. More...
void | mult256 (int mr, int mg, int mb)
| Multiply each color component by a given factor m/256 with m in [0,256]. More...
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...
RGB64 | 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 {
uint64_t val
| color as uint64_t
struct {
uint16_t R
| Red channel (16 bits)
uint16_t G
| Green channel (16 bits)
uint16_t B
| Blue channel (16 bits)
uint16_t A
| Alpha channel (16 bits)
} |
}; |

## Static Public Attributes
static const uint16_t | DEFAULT_A = 65535
| fully opaque alpha value

## Detailed Description

Color in R16/G16/B16/A16 format.

Occupies 8 bytes in memory, aligned as uint64_t.

Can be converted from/to uint64_t.

the component A defaults to DEFAULT_A = 65535 (fully opaque) if not specified.

REMARK For all drawing/blending procedure, 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

## ◆ RGB64() [1/8]

tgx::RGB64::RGB64 | ( |  | ) |
| default

Default constructor.

Color is undefined

## ◆ RGB64() [2/8]

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

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

Component A is set to DEFAULT_A.

## ◆ RGB64() [3/8]

tgx::RGB64::RGB64 | ( | 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.

## ◆ RGB64() [4/8]

tgx::RGB64::RGB64 | ( | 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.

## ◆ RGB64() [5/8]

tgx::RGB64::RGB64 | ( | const RGB565 & | c | ) |
| inline

Constructor from a RGB565 color.

Component A is set to DEFAULT_A.

## ◆ RGB64() [6/8]

tgx::RGB64::RGB64 | ( | const RGB24 & | c | ) |
| inline

Constructor from a RGB24 color.

Component A is set to DEFAULT_A.

## ◆ RGB64() [7/8]

tgx::RGB64::RGB64 | ( | const RGBf & | c | ) |
| inline

Constructor from a RGBf color.

Component A is set to DEFAULT_A.

## ◆ RGB64() [8/8]

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

Constructor from a HSV color.

Component A is set to DEFAULT_A

## Member Function Documentation

## ◆ operator iVec3()

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

Cast into an iVec3 with components (x=R, y=G, z=B) in [0,65535].

Component A is ignored.

## ◆ operator fVec3()

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

Cast into an fVec3 with components (x=R, y=G, z=B) in [0.0f, 1.0f].

Component A is ignored.

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

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

Assignement operator from a RGB24 color.

Component A is set to DEFAULT_A.

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

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

Assignement operator from a RGB24 color.

Component A is set to DEFAULT_A.

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

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

Assignement operator from a RGBf color.

Component A is set to DEFAULT_A.

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

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

Assignement operator from a HSV color.

Component A is set to DEFAULT_A.

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

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

Assignement operator from a iVec3 with components (x=R, y=G, z=B) in [0,65535].

Component A is set to DEFAULT_A.

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

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

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

Component A is set to DEFAULT_A.

## ◆ blend() [1/2]

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

alpha-blend `fg_col` over this one with a given opacity in the integer range 0 (fully transparent) to 256 (fully opaque).

WARNING The color fg_col is assumed o have pre-multiplied alpha.

Parameters

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

## ◆ blend65536()

void tgx::RGB64::blend65536 | ( | RGB64 | fg_col,
|  | uint32_t | alpha
| ) |  |
| inline

alpha-blend `fg_col` over this one with a given opacity in the integer range 0 (fully transparent) to 65536 (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,65536].

## ◆ blend() [2/2]

void tgx::RGB64::blend | ( | const RGB64 & | fg_col | ) |
| inline

alpha-blend `fg_col` over this one.

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.

## ◆ mult256()

void tgx::RGB64::mult256 | ( | int | mr,
|  | int | mg,
|  | int | mb
| ) |  |
| inline

Multiply each color component by a given factor m/256 with m in [0,256].

Component A is left unchanged.

## ◆ premultiply()

void tgx::RGB64::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::RGB64::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 multOpacity() instead whenever possible because it is faster.

## ◆ multOpacity()

void tgx::RGB64::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()

RGB64 tgx::RGB64::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