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

Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
Color.h File Reference

Color classes [RGB565, RGB24, RGB32, RGB64, RGBf, HSV]. More...

`#include "Misc.h"`
`#include <stdint.h>`
`#include <math.h>`
`#include <type_traits>`
`#include "Vec3.h"`
`#include "Vec4.h"`
`#include "Color.inl"`

Go to the source code of this file.

## Classes
struct | tgx::RGB565
| Color in R5/G6/B5 format. More...
struct | tgx::RGB24
| Color in R8/G8/B8 format. More...
struct | tgx::RGB32
| Color in R8/G8/B8/A8 format. More...
struct | tgx::RGB64
| Color in R16/G16/B16/A16 format. More...
struct | tgx::RGBf
| Color in R,G,B float format. More...
struct | tgx::HSV
| Color in H/S/V format [experimental]. More...

## Macros
#define | TGX_RGB565_ORDER_BGR 1
| color ordering for RGB565 (default B,G,R for compatibility with adafruit and most SPI display)
#define | TGX_RGB24_ORDER_BGR 0
| color ordering for RGB24 (default R,G,B)
#define | TGX_RGB32_ORDER_BGR 1
| color ordering for RGB565 (default B,G,R for compatibility with the mtools library)
#define | TGX_RGB64_ORDER_BGR 0
| color ordering for RGB64 (default R,G,B)
#define | TGX_RGBf_ORDER_BGR 0
| color ordering for RGBf (default R,G,B)

## Functions
RGB565 | tgx::interpolateColorsTriangle (const RGB565 &col1, int32_t C1, const RGB565 &col2, int32_t C2, const RGB565 &col3, const int32_t totC)
| Interpolate between 3 colors. More...
RGB565 | tgx::interpolateColorsBilinear (const RGB565 &C00, const RGB565 &C10, const RGB565 &C01, const RGB565 &C11, const float ax, const float ay)
| Bilinear interpolation between 4 colors. More...
RGB565 | tgx::meanColor (RGB565 colA, RGB565 colB)
| Return the average color between colA and colB. More...
RGB565 | tgx::meanColor (RGB565 colA, RGB565 colB, RGB565 colC, RGB565 colD)
| Return the average color between 4 colors. More...
RGB24 | tgx::interpolateColorsTriangle (const RGB24 &col1, int32_t C1, const RGB24 &col2, int32_t C2, const RGB24 &col3, const int32_t totC)
| Interpolate between 3 colors. More...
RGB24 | tgx::interpolateColorsBilinear (const RGB24 &C00, const RGB24 &C10, const RGB24 &C01, const RGB24 &C11, const float ax, const float ay)
| Bilinear interpolation between 4 colors. More...
RGB24 | tgx::meanColor (const RGB24 &colA, const RGB24 &colB)
| Return the average color between colA and colB.
RGB24 | tgx::meanColor (const RGB24 &colA, const RGB24 &colB, const RGB24 &colC, const RGB24 &colD)
| Return the average color between 4 colors.
RGB32 | tgx::interpolateColorsTriangle (const RGB32 &col1, int32_t C1, const RGB32 &col2, int32_t C2, const RGB32 &col3, const int32_t totC)
| Interpolate between 3 colors. More...
RGB32 | tgx::interpolateColorsBilinear (const RGB32 &C00, const RGB32 &C10, const RGB32 &C01, const RGB32 &C11, const float ax, const float ay)
| Bilinear interpolation between 4 colors. More...
RGB32 | tgx::meanColor (RGB32 colA, RGB32 colB)
| Return the average color between colA and colB.
RGB32 | tgx::meanColor (RGB32 colA, RGB32 colB, RGB32 colC, RGB32 colD)
| Return the average color between 4 colors.
RGB64 | tgx::interpolateColorsTriangle (const RGB64 &col1, int32_t C1, const RGB64 &col2, int32_t C2, const RGB64 &col3, const int32_t totC)
| Interpolate between 3 colors. More...
RGB64 | tgx::interpolateColorsBilinear (const RGB64 &C00, const RGB64 &C10, const RGB64 &C01, const RGB64 &C11, const float ax, const float ay)
| Bilinear interpolation between 4 colors. More...
RGB64 | tgx::meanColor (const RGB64 &colA, const RGB64 &colB)
| Return the average color between colA and colB.
RGB64 | tgx::meanColor (const RGB64 &colA, const RGB64 &colB, const RGB64 &colC, const RGB64 &colD)
| Return the average color between 4 colors.
RGBf | tgx::interpolate (const RGBf &col1, const RGBf &col2, float alpha)
| Interpolate between 2 colors. More...
RGBf | tgx::interpolateColorsTriangle (const RGBf &col1, int32_t C1, const RGBf &col2, int32_t C2, const RGBf &col3, int32_t totC)
| Interpolate between 3 colors. More...
RGBf | tgx::interpolateColorsBilinear (const RGBf &C00, const RGBf &C10, const RGBf &C01, const RGBf &C11, const float ax, const float ay)
| Bilinear interpolation between 4 colors. More...
RGBf | tgx::meanColor (const RGBf &colA, const RGBf &colB)
| Return the average color between colA and colB.
RGBf | tgx::meanColor (const RGBf &colA, const RGBf &colB, const RGBf &colC, const RGBf &colD)
| Return the average color between 4 colors.
HSV | tgx::interpolateColorsTriangle (HSV col1, int32_t C1, HSV col2, int32_t C2, HSV col3, int32_t totC)
| Interpolate between 3 colors. More...
HSV | tgx::interpolateColorsBilinear (const HSV &C00, const HSV &C10, const HSV &C01, const HSV &C11, const float ax, const float ay)
| Bilinear interpolation between 4 colors. More...
HSV | tgx::meanColor (const HSV &colA, const HSV &colB)
| Return the average color between colA and colB.
HSV | tgx::meanColor (const HSV &colA, const HSV &colB, const HSV &colC, const HSV &colD)
| Return the average color between 4 colors.

## Variables
const RGB32 | tgx::RGB32_Black
| Color black in RGB32 format.
const RGB32 | tgx::RGB32_White
| Color white in RGB32 format.
const RGB32 | tgx::RGB32_Red
| Color red in RGB32 format.
const RGB32 | tgx::RGB32_Blue
| Color blue in RGB32 format.
const RGB32 | tgx::RGB32_Green
| Color green in RGB32 format.
const RGB32 | tgx::RGB32_Purple
| Color purple in RGB32 format.
const RGB32 | tgx::RGB32_Orange
| Color orange in RGB32 format.
const RGB32 | tgx::RGB32_Cyan
| Color cyan in RGB32 format.
const RGB32 | tgx::RGB32_Lime
| Color lime in RGB32 format.
const RGB32 | tgx::RGB32_Salmon
| Color salmon in RGB32 format.
const RGB32 | tgx::RGB32_Maroon
| Color maroon in RGB32 format.
const RGB32 | tgx::RGB32_Yellow
| Color yellow in RGB32 format.
const RGB32 | tgx::RGB32_Magenta
| Color majenta in RGB32 format.
const RGB32 | tgx::RGB32_Olive
| Color olive in RGB32 format.
const RGB32 | tgx::RGB32_Teal
| Color teal in RGB32 format.
const RGB32 | tgx::RGB32_Gray
| Color gray in RGB32 format.
const RGB32 | tgx::RGB32_Silver
| Color silver in RGB32 format.
const RGB32 | tgx::RGB32_Navy
| Color navy in RGB32 format.
const RGB32 | tgx::RGB32_Transparent
| premultiplied transparent black (0,0,0,0)
const RGB565 | tgx::RGB565_Black
| Color black in RGB565 format.
const RGB565 | tgx::RGB565_White
| Color white in RGB565 format.
const RGB565 | tgx::RGB565_Red
| Color red in RGB565 format.
const RGB565 | tgx::RGB565_Blue
| Color blue in RGB565 format.
const RGB565 | tgx::RGB565_Green
| Color green in RGB565 format.
const RGB565 | tgx::RGB565_Purple
| Color purple in RGB565 format.
const RGB565 | tgx::RGB565_Orange
| Color orange in RGB565 format.
const RGB565 | tgx::RGB565_Cyan
| Color cyan in RGB565 format.
const RGB565 | tgx::RGB565_Lime
| Color lime in RGB565 format.
const RGB565 | tgx::RGB565_Salmon
| Color salmon in RGB565 format.
const RGB565 | tgx::RGB565_Maroon
| Color maroon in RGB565 format.
const RGB565 | tgx::RGB565_Yellow
| Color yellow in RGB565 format.
const RGB565 | tgx::RGB565_Magenta
| Color majenta in RGB565 format.
const RGB565 | tgx::RGB565_Olive
| Color olive in RGB565 format.
const RGB565 | tgx::RGB565_Teal
| Color teal in RGB565 format.
const RGB565 | tgx::RGB565_Gray
| Color gray in RGB565 format.
const RGB565 | tgx::RGB565_Silver
| Color silver in RGB565 format.
const RGB565 | tgx::RGB565_Navy
| Color navy in RGB565 format.

## Detailed Description

Color classes [RGB565, RGB24, RGB32, RGB64, RGBf, HSV].

## Function Documentation

## ◆ interpolateColorsTriangle() [1/6]

RGB565 tgx::interpolateColorsTriangle | ( | const RGB565 & | col1,
|  | int32_t | C1,
|  | const RGB565 & | col2,
|  | int32_t | C2,
|  | const RGB565 & | col3,
|  | const int32_t | totC
| ) |  |
| inline

Interpolate between 3 colors.

Return the color (C1*col1 + C2*col2 + (totC-C1-C2)*col3) / totC.

## ◆ interpolateColorsBilinear() [1/6]

RGB565 tgx::interpolateColorsBilinear | ( | const RGB565 & | C00,
|  | const RGB565 & | C10,
|  | const RGB565 & | C01,
|  | const RGB565 & | C11,
|  | const float | ax,
|  | const float | ay
| ) |  |
| inline

Bilinear interpolation between 4 colors.

Return the bilinear interpolation of four neighouring pixels in an image with respect to position X where ax and ay are in [0.0f,1.0f] and represent the distance to the mininum coord. in direction x and y, as illustrated in the drawing below:

C01 C11
--ax--X
|
ay
C00 | C10

## ◆ meanColor() [1/2]

RGB565 tgx::meanColor | ( | RGB565 | colA,
|  | RGB565 | colB
| ) |  |
| inline

Return the average color between colA and colB.

TODO : make it faster

## ◆ meanColor() [2/2]

RGB565 tgx::meanColor | ( | RGB565 | colA,
|  | RGB565 | colB,
|  | RGB565 | colC,
|  | RGB565 | colD
| ) |  |
| inline

Return the average color between 4 colors.

TODO : make it faster

## ◆ interpolateColorsTriangle() [2/6]

RGB24 tgx::interpolateColorsTriangle | ( | const RGB24 & | col1,
|  | int32_t | C1,
|  | const RGB24 & | col2,
|  | int32_t | C2,
|  | const RGB24 & | col3,
|  | const int32_t | totC
| ) |  |
| inline

Interpolate between 3 colors.

Return the color (C1*col1 + C2*col2 + (totC-C1-C2)*col3) / totC.

## ◆ interpolateColorsBilinear() [2/6]

RGB24 tgx::interpolateColorsBilinear | ( | const RGB24 & | C00,
|  | const RGB24 & | C10,
|  | const RGB24 & | C01,
|  | const RGB24 & | C11,
|  | const float | ax,
|  | const float | ay
| ) |  |
| inline

Bilinear interpolation between 4 colors.

Return the bilinear interpolation of four neighouring pixels in an image with respect to position X where ax and ay are in [0.0f,1.0f] and represent the distance to the mininum coord. in direction x and y, as illustrated in the drawing below:

C01 C11
--ax--X
|
ay
C00 | C10

## ◆ interpolateColorsTriangle() [3/6]

RGB32 tgx::interpolateColorsTriangle | ( | const RGB32 & | col1,
|  | int32_t | C1,
|  | const RGB32 & | col2,
|  | int32_t | C2,
|  | const RGB32 & | col3,
|  | const int32_t | totC
| ) |  |
| inline

Interpolate between 3 colors.

Return the color (C1*col1 + C2*col2 + (totC-C1-C2)*col3) / totC.

## ◆ interpolateColorsBilinear() [3/6]

RGB32 tgx::interpolateColorsBilinear | ( | const RGB32 & | C00,
|  | const RGB32 & | C10,
|  | const RGB32 & | C01,
|  | const RGB32 & | C11,
|  | const float | ax,
|  | const float | ay
| ) |  |
| inline

Bilinear interpolation between 4 colors.

Return the bilinear interpolation of four neighouring pixels in an image with respect to position X where ax and ay are in [0.0f,1.0f] and represent the distance to the mininum coord. in direction x and y, as illustrated in the drawing below:

C01 C11
--ax--X
|
ay
C00 | C10

## ◆ interpolateColorsTriangle() [4/6]

RGB64 tgx::interpolateColorsTriangle | ( | const RGB64 & | col1,
|  | int32_t | C1,
|  | const RGB64 & | col2,
|  | int32_t | C2,
|  | const RGB64 & | col3,
|  | const int32_t | totC
| ) |  |
| inline

Interpolate between 3 colors.

Return the color (C1*col1 + C2*col2 + (totC-C1-C2)*col3) / totC.

## ◆ interpolateColorsBilinear() [4/6]

RGB64 tgx::interpolateColorsBilinear | ( | const RGB64 & | C00,
|  | const RGB64 & | C10,
|  | const RGB64 & | C01,
|  | const RGB64 & | C11,
|  | const float | ax,
|  | const float | ay
| ) |  |
| inline

Bilinear interpolation between 4 colors.

Return the bilinear interpolation of four neighouring pixels in an image with respect to position X where ax and ay are in [0.0f,1.0f] and represent the distance to the mininum coord. in direction x and y, as illustrated in the drawing below:

C01 C11
--ax--X
|
ay
C00 | C10

## ◆ interpolate()

RGBf tgx::interpolate | ( | const RGBf & | col1,
|  | const RGBf & | col2,
|  | float | alpha
| ) |  |
| inline

Interpolate between 2 colors.

Return the color col1 + alpha*(col2 - col1)

## ◆ interpolateColorsTriangle() [5/6]

RGBf tgx::interpolateColorsTriangle | ( | const RGBf & | col1,
|  | int32_t | C1,
|  | const RGBf & | col2,
|  | int32_t | C2,
|  | const RGBf & | col3,
|  | int32_t | totC
| ) |  |
| inline

Interpolate between 3 colors.

Return the color (C1*col1 + C2*col2 + (totC-C1-C2)*col3) / totC.

## ◆ interpolateColorsBilinear() [5/6]

RGBf tgx::interpolateColorsBilinear | ( | const RGBf & | C00,
|  | const RGBf & | C10,
|  | const RGBf & | C01,
|  | const RGBf & | C11,
|  | const float | ax,
|  | const float | ay
| ) |  |
| inline

Bilinear interpolation between 4 colors.

Return the bilinear interpolation of four neighouring pixels in an image with respect to position X where ax and ay are in [0.0f,1.0f] and represent the distance to the mininum coord. in direction x and y, as illustrated in the drawing below:

C01 C11
--ax--X
|
ay
C00 | C10

## ◆ interpolateColorsTriangle() [6/6]

HSV tgx::interpolateColorsTriangle | ( | HSV | col1,
|  | int32_t | C1,
|  | HSV | col2,
|  | int32_t | C2,
|  | HSV | col3,
|  | int32_t | totC
| ) |  |
| inline

Interpolate between 3 colors.

Return the color (C1*col1 + C2*col2 + (totC-C1-C2)*col3) / totC.

## ◆ interpolateColorsBilinear() [6/6]

HSV tgx::interpolateColorsBilinear | ( | const HSV & | C00,
|  | const HSV & | C10,
|  | const HSV & | C01,
|  | const HSV & | C11,
|  | const float | ax,
|  | const float | ay
| ) |  |
| inline

Bilinear interpolation between 4 colors.

Return the bilinear interpolation of four neighouring pixels in an image with respect to position X where ax and ay are in [0.0f,1.0f] and represent the distance to the mininum coord. in direction x and y, as illustrated in the drawing below:

C01 C11
--ax--X
|
ay
C00 | C10