Color

The color sys module supports handling RGB and HSV color. More...

Detailed Description

The color sys module supports handling RGB and HSV color.

Files

file  color.h
 Headers for the color handling module.
 

Data Structures

struct  color_rgb_t
 Data-structure describing a RGB color. More...
 
struct  color_rgba_t
 RGBA color value. More...
 
struct  color_hsv_t
 Data-structure for holding HSV colors. More...
 

Functions

void color_rgb2hsv (color_rgb_t *rgb, color_hsv_t *hsv)
 Convert RGB color to HSV color. More...
 
void color_hsv2rgb (color_hsv_t *hsv, color_rgb_t *rgb)
 Convert HSV color to RGB color. More...
 
void color_hex2rgb (const uint32_t hex, color_rgb_t *rgb)
 Convert a hex value of the form 0x00RRGGBB to an RGB color struct. More...
 
void color_rgb2hex (const color_rgb_t *rgb, uint32_t *hex)
 Convert a rgb struct to a hex value of the form 0x00RRGGBB. More...
 
void color_str2rgb (const char *str, color_rgb_t *color)
 Convert a hex color string of the form 'RRGGBB' to a color_rgb_t struct. More...
 
void color_rgb2str (const color_rgb_t *rgb, char *str)
 Convert a color_rgb_t struct to a hex color string of the form 'RRGGBB'. More...
 
static void color_rgb_invert (const color_rgb_t *rgb, color_rgb_t *inv_rgb)
 Invert a given rgb color. More...
 
void color_rgb_complementary (const color_rgb_t *rgb, color_rgb_t *comp_rgb)
 Calculate the complementary color of a given rgb color. More...
 

Function Documentation

◆ color_hex2rgb()

void color_hex2rgb ( const uint32_t  hex,
color_rgb_t rgb 
)

Convert a hex value of the form 0x00RRGGBB to an RGB color struct.

Note
the two most significant bytes of hex will be ignored
Parameters
[in]hexInput color encoded in hex
[out]rgbOutput color encoded in RGB space

◆ color_hsv2rgb()

void color_hsv2rgb ( color_hsv_t hsv,
color_rgb_t rgb 
)

Convert HSV color to RGB color.

Parameters
[in]hsvInput color encoded in HSV space
[out]rgbOutput color encoded in RGB space

◆ color_rgb2hex()

void color_rgb2hex ( const color_rgb_t rgb,
uint32_t *  hex 
)

Convert a rgb struct to a hex value of the form 0x00RRGGBB.

Note
the two most significant bytes of hex will be 0
Parameters
[in]rgbInput color encoded in RGB space
[out]hexOutput color encoded in hex

◆ color_rgb2hsv()

void color_rgb2hsv ( color_rgb_t rgb,
color_hsv_t hsv 
)

Convert RGB color to HSV color.

Parameters
[in]rgbInput color encoded in RGB space
[out]hsvOutput color encoded in HSV space

◆ color_rgb2str()

void color_rgb2str ( const color_rgb_t rgb,
char *  str 
)

Convert a color_rgb_t struct to a hex color string of the form 'RRGGBB'.

Note
str MUST be big enough to hold 6 characters
Parameters
[in]rgbInput color encoded in RGB space
[out]strOutput color encoded as string of the form 'RRGGBB'

◆ color_rgb_complementary()

void color_rgb_complementary ( const color_rgb_t rgb,
color_rgb_t comp_rgb 
)

Calculate the complementary color of a given rgb color.

Note
Complementary color calculation according to adobe illustator calculations. See https://helpx.adobe.com/illustrator/using/adjusting-colors.html
Precondition
((rgb != NULL) && (comp_rgb != NULL))
Parameters
[in]rgbInput rgb color. Must be NOT NULL
[out]comp_rgbOutput rgb color, result of the complementary color calculation. Must be NOT NULL

◆ color_rgb_invert()

static void color_rgb_invert ( const color_rgb_t rgb,
color_rgb_t inv_rgb 
)
inlinestatic

Invert a given rgb color.

Precondition
((rgb != NULL) && (inv_rgb != NULL))
Parameters
[in]rgbInput rgb color, that should be converted. Must be NOT NULL
[out]inv_rgbOutput rgb color, result of the conversion. Must be NOT NULL

Definition at line 123 of file color.h.

◆ color_str2rgb()

void color_str2rgb ( const char *  str,
color_rgb_t color 
)

Convert a hex color string of the form 'RRGGBB' to a color_rgb_t struct.

Note
str MUST contain only hexadecimal digits. Expect unexpected behaviour, otherwise.
Parameters
[in]strInput color encoded as string of the form 'RRGGBB'
[out]colorOutput color encoded in RGB space