TGX 1.0.0
A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.
Loading...
Searching...
No Matches
tgx::RGB565 Struct Reference

Color in R5/G6/B5 format. More...

#include <Color.h>

Public Member Functions

 RGB565 ()=default
 Default constructor. More...
 
constexpr RGB565 (int r, int g, int b)
 Constructor from R,G,B values. More...
 
constexpr RGB565 (iVec3 v)
 Constructor from a iVec3 vector (x=R, y=G, z=B). More...
 
constexpr RGB565 (iVec4 v)
 Constructor from an iVec4 vector (x=R, y=G, z=B, w=ignored). More...
 
 RGB565 (float r, float g, float b)
 Constructor from float r,g,b in [0.0f, 1.0f].
 
 RGB565 (fVec3 v)
 Constructor from a fVec3 vector with components (x=R, y=G, z=B) in [0.0f, 1.0f].
 
 RGB565 (fVec4 v)
 Constructor from a fVec4 vector with components (x=R, y=G, z=B, w=ignored) in [0.0f, 1.0f].
 
constexpr RGB565 (uint16_t c)
 Constructor from a uint16_t.
 
constexpr RGB565 (uint32_t val)
 Constructor from a uint32_t (seen as RGB32).
 
constexpr RGB565 (uint64_t val)
 Constructor from a uint64_t (seen as RGB64).
 
constexpr RGB565 (const RGB565 &)=default
 Default Copy constructor.
 
constexpr RGB565 (const RGB24 &c)
 Constructor from a RGB24 color.
 
constexpr RGB565 (const RGB32 &c)
 Constructor from a RGB32 color. More...
 
constexpr RGB565 (const RGB64 &c)
 Constructor from a RGB64 color. More...
 
constexpr RGB565 (const RGBf &c)
 Constructor from a RGBf color.
 
 RGB565 (const HSV &c)
 Constructor from a HSV color.
 
 operator uint16_t & ()
 Cast into a uint16_t (non-const reference version)
 
 operator const uint16_t & () const
 Cast into a uint16_t (const reference version)
 
 operator iVec3 () const
 Cast into an iVec3 vector. More...
 
 operator fVec3 () const
 Cast into an fVec3 vector. More...
 
RGB565operator= (const RGB565 &)=default
 Default assignement operator.
 
RGB565operator= (const RGB24 &c)
 Assignement operator from a RGB24 color.
 
RGB565operator= (const RGB32 &c)
 Assignement operator from a RGB32 color. More...
 
RGB565operator= (const RGB64 &c)
 Assignement operator from a RGB64 color. More...
 
RGB565operator= (const RGBf &c)
 Assignement operator from a RGBf color.
 
RGB565operator= (const HSV &c)
 Assignement operator from a HSV color.
 
RGB565operator= (iVec3 v)
 Assignement operator from an iVec3 vector. More...
 
RGB565operator= (iVec4 v)
 Assignement operator from a iVec4. More...
 
RGB565operator= (fVec3 v)
 Assignement operator from a fVec3. More...
 
RGB565operator= (fVec4 v)
 Assignement operator from a fVec4. More...
 
void operator+= (const RGB565 &c)
 Add another color, component by component.
 
void operator-= (const RGB565 &c)
 Substract another color, component by component.
 
constexpr bool operator== (const RGB565 &c) const
 Equality comparator.
 
constexpr bool operator!= (const RGB565 &c) const
 Inequality comparator.
 
void blend (RGB565 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 RGB565 &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 mult256 (int mr, int mg, int mb)
 Multiply each color component by a given factor m/256 with m in [0,256].
 
void mult256 (int mr, int mg, int mb, int ma)
 Multiply each color component by a given factor x/256 with x in [0,256]. More...
 
void premultiply ()
 Dummy function for compatibility with color types having an alpha channel. More...
 
float opacity () const
 Dummy function for compatibility with color types having an alpha channel. More...
 
void setOpacity (float op)
 Dummy function for compatibility with color types having an alpha channel. More...
 

Public Attributes

union {
   uint16_t   val
 color as uint16_t
 
   struct {
      uint16_t   B: 5
 Blue channel (5 bits)
 
      uint16_t   G: 6
 Green channel (6 bits)
 
      uint16_t   R: 5
 Red channel (5 bits)
 
   } 
 
}; 
 

Detailed Description

Color in R5/G6/B5 format.

The object occupies 2 bytes in memory (aligned as uint16_t)

Can be converted from/to uint16_t.

This type is used mostly with MCU / embedded systems.

Constructor & Destructor Documentation

◆ RGB565() [1/6]

tgx::RGB565::RGB565 ( )
default

Default constructor.

** color is undefined ***

◆ RGB565() [2/6]

constexpr tgx::RGB565::RGB565 ( int  r,
int  g,
int  b 
)
inlineconstexpr

Constructor from R,G,B values.

Parameters
rin [0,31]
gin [0,63]
bin [0,31]

◆ RGB565() [3/6]

constexpr tgx::RGB565::RGB565 ( iVec3  v)
inlineconstexpr

Constructor from a iVec3 vector (x=R, y=G, z=B).

  • red componenent v.x in [0,31]
  • green componenent v.y in [0,63]
  • blue componenent v.z in [0,31]

◆ RGB565() [4/6]

constexpr tgx::RGB565::RGB565 ( iVec4  v)
inlineconstexpr

Constructor from an iVec4 vector (x=R, y=G, z=B, w=ignored).

  • red componenent v.x in [0,31]
  • green componenent v.y in [0,63]
  • blue componenent v.z in [0,31]
  • v.w is ignored

◆ RGB565() [5/6]

constexpr tgx::RGB565::RGB565 ( const RGB32 c)
inlineconstexpr

Constructor from a RGB32 color.

The component A is ignored

◆ RGB565() [6/6]

constexpr tgx::RGB565::RGB565 ( const RGB64 c)
inlineconstexpr

Constructor from a RGB64 color.

The component A is ignored

Member Function Documentation

◆ operator iVec3()

tgx::RGB565::operator iVec3 ( ) const
inlineexplicit

Cast into an iVec3 vector.

raw values.

◆ operator fVec3()

tgx::RGB565::operator fVec3 ( ) const
inlineexplicit

Cast into an fVec3 vector.

Values in [0.0f, 1.0f].

◆ operator=() [1/6]

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

Assignement operator from a RGB32 color.

The component A is ignored

◆ operator=() [2/6]

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

Assignement operator from a RGB64 color.

The component A is ignored

◆ operator=() [3/6]

RGB565 & tgx::RGB565::operator= ( iVec3  v)
inline

Assignement operator from an iVec3 vector.

Raw values (no conversion).

◆ operator=() [4/6]

RGB565 & tgx::RGB565::operator= ( iVec4  v)
inline

Assignement operator from a iVec4.

The w component is ignored. Raw values (no conversion).

◆ operator=() [5/6]

RGB565 & tgx::RGB565::operator= ( fVec3  v)
inline

Assignement operator from a fVec3.

All values in [0.0f, 1.0f].

◆ operator=() [6/6]

RGB565 & tgx::RGB565::operator= ( fVec4  v)
inline

Assignement operator from a fVec4.

the w component is ignored. All values in [0.0f, 1.0f].

◆ blend()

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

Parameters
fg_colThe foreground color.
alphaThe opacity/alpha multiplier in [0.0f,1.0f].

◆ blend256()

void tgx::RGB565::blend256 ( const RGB565 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).

Parameters
fg_colThe foreground color.
alphaThe opacity/alpha multiplier in [0,256].

◆ mult256()

void tgx::RGB565::mult256 ( int  mr,
int  mg,
int  mb,
int  ma 
)
inline

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

Parameter ma is ignored since there is not alpha channel.

◆ premultiply()

void tgx::RGB565::premultiply ( )
inline

Dummy function for compatibility with color types having an alpha channel.

Does nothing since the color is always fully opaque.

◆ opacity()

float tgx::RGB565::opacity ( ) const
inline

Dummy function for compatibility with color types having an alpha channel.

Return 1.0f (fully opaque)

◆ setOpacity()

void tgx::RGB565::setOpacity ( float  op)
inline

Dummy function for compatibility with color types having an alpha channel.

Does nothing since the color is always fully opaque.


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