PixelKey
NeoPixel USB Key
Loading...
Searching...
No Matches
Color Internals

Data Structures

struct  named_color
 

Macros

#define HUE_SECTOR_SIZE   (60U)
 Number of degrees in each sector of the hue component.
 
#define HUE_SECTOR_SIZE_F32   (60.0f)
 Number of degrees in each sector of the hue component as a float-32.
 
#define max(a, b)   ((a) >= (b) ? (a) : (b))
 Maximum of two values.
 
#define min(a, b)   ((a) < (b) ? (a) : (b))
 Minimum of two values.
 
#define COLOR_RGB_HEX_STR_LENGTH   (7U)
 Maximum expected length of a hexadecimal color.
 

Functions

static int parse_next_hex_byte (char **p_str)
 Parses the next hexadecimal byte from p_str and increments p_str. More...
 
static int parse_next_uint (char *p_str, int min, int max)
 Parses the next integer in a list separated by commas. More...
 
static float parse_next_f32 (char *p_str, float min, float max)
 Parses the next float in a list separated by commas. More...
 
static void color_convert_rgb (color_space_t from, color_kind_t const *p_in, color_rgb_t *p_out)
 Converts a color to the RGB color space. More...
 
static void color_convert_hsv (color_space_t from, color_kind_t const *p_in, color_hsv_t *p_out)
 Converts a color to the HSV color space. More...
 
static void color_convert_hsl (color_space_t from, color_kind_t const *p_in, color_hsl_t *p_out)
 Converts a color to the HSL color space. More...
 
void color_convert (color_space_t to, color_t const *p_in, color_t *p_out)
 Convert a color to a different color space. More...
 
void color_convert2 (color_space_t from, color_space_t to, color_kind_t const *p_in, color_kind_t *p_out)
 Convert a color to a different color space. More...
 
bool color_parse (char *p_str, color_t *p_color_out)
 Parses a color from a string; must be NULL-terminated. More...
 
void color_gamma_correct (color_rgb_t *p_in, color_rgb_t *p_out)
 Applies gamma correction to an RGB color. More...
 
void color_gamma_build (float gamma)
 Updates the gamma table with the provided correction factor. More...
 

Variables

const color_t color_red = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 0 ) << (6U) )), 100, 100 } }
 Red: #FF0000.
 
const color_t color_orange = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 30 ) << (6U) )), 100, 100 } }
 Orange: #FF8000.
 
const color_t color_yellow = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 60 ) << (6U) )), 100, 100 } }
 Yellow: #FFFF00.
 
const color_t color_neon = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 90 ) << (6U) )), 100, 100 } }
 Neon: #80FF00.
 
const color_t color_green = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 120 ) << (6U) )), 100, 100 } }
 Green: #00FF00.
 
const color_t color_seafoam = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 150 ) << (6U) )), 100, 100 } }
 Seafoam: #00FF80.
 
const color_t color_cyan = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 180 ) << (6U) )), 100, 100 } }
 Cyan: #00FFFF.
 
const color_t color_lightblue = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 210 ) << (6U) )), 100, 100 } }
 Light Blue: #0080FF.
 
const color_t color_blue = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 240 ) << (6U) )), 100, 100 } }
 Blue: #0000FF.
 
const color_t color_purple = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 270 ) << (6U) )), 100, 100 } }
 Purple: #8000FF.
 
const color_t color_magenta = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 300 ) << (6U) )), 100, 100 } }
 Magenta: #FF00FF.
 
const color_t color_pink = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 330 ) << (6U) )), 100, 100 } }
 Pink: #FF0080.
 
const color_t color_white = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 0 ) << (6U) )), 0, 100 } }
 White: #FFFFFF.
 
const color_t color_black = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 0 ) << (6U) )), 0, 0 } }
 Black: #000000.
 
const color_t color_off = { .color_space = COLOR_SPACE_HSV, .hsv = { ((uint16_t)(( 0 ) << (6U) )), 0, 0 } }
 Off: #000000.
 
static const struct named_color named_colors []
 List of named colors. More...
 
static uint8_t gamma_table [(255U)+1] = {0}
 Lookup table for gamma correction values.
 

Detailed Description

Function Documentation

◆ color_convert()

void color_convert ( color_space_t  to,
color_t const *  p_in,
color_t p_out 
)

Convert a color to a different color space.

Parameters
toDesired color space to convert to.
[in]p_inPointer to the color in the original color space.
[out]p_outPointer to the color for the desired color space.

◆ color_convert2()

void color_convert2 ( color_space_t  from,
color_space_t  to,
color_kind_t const *  p_in,
color_kind_t p_out 
)

Convert a color to a different color space.

Parameters
fromColor space to convert from.
toDesired color space to convert to.
[in]p_inPointer to the color in the original color space.
[out]p_outPointer to the color for the desired color space.

◆ color_convert_hsl()

static void color_convert_hsl ( color_space_t  from,
color_kind_t const *  p_in,
color_hsl_t p_out 
)
static

Converts a color to the HSL color space.

Parameters
[in]fromColor space to convert from.
[in]p_inPointer to the color to convert from.
[out]p_outPointer to the color converted to HSL.

◆ color_convert_hsv()

static void color_convert_hsv ( color_space_t  from,
color_kind_t const *  p_in,
color_hsv_t p_out 
)
static

Converts a color to the HSV color space.

Parameters
[in]fromColor space to convert from.
[in]p_inPointer to the color to convert from.
[out]p_outPointer to the color converted to HSV.

◆ color_convert_rgb()

static void color_convert_rgb ( color_space_t  from,
color_kind_t const *  p_in,
color_rgb_t p_out 
)
static

Converts a color to the RGB color space.

Parameters
[in]fromColor space to convert from.
[in]p_inPointer to the color to convert from.
[out]p_outPointer to the color converted to RGB.

◆ color_gamma_build()

void color_gamma_build ( float  gamma)

Updates the gamma table with the provided correction factor.

Parameters
gammaThe gamma correction factor to use.

Builds the gamma table using the equation

\[ C_\gamma = 255 * \left( \frac{C}{255} \right)^\gamma + \frac{1}{2} \]

◆ color_gamma_correct()

void color_gamma_correct ( color_rgb_t p_in,
color_rgb_t p_out 
)

Applies gamma correction to an RGB color.

Parameters
[in,out]p_inThe color to correct.
[out]p_outPointer to write the corrected color, if NULL p_in is edited in place.

◆ color_parse()

bool color_parse ( char *  p_str,
color_t p_color_out 
)

Parses a color from a string; must be NULL-terminated.

Parameters
[in]p_strPointer to the color string to parse; may be modified.
[out]p_color_outPointer to store the parsed color.
Returns
true on success, false on failure.

◆ parse_next_f32()

static float parse_next_f32 ( char *  p_str,
float  min,
float  max 
)
static

Parses the next float in a list separated by commas.

Parameters
[in,out]p_strPointer to the string to parse, or NULL to continue from the last string.
minMinimum accepted value (inclusive).
maxMaximum accepted value (exclusive).
Returns
the parsed float or NaN on error or out of range.

◆ parse_next_hex_byte()

static int parse_next_hex_byte ( char **  p_str)
static

Parses the next hexadecimal byte from p_str and increments p_str.

Parameters
[in,out]p_strPointer to a string pointer to parse.
Returns
The next hexadecimal value parsed from p_str.

◆ parse_next_uint()

static int parse_next_uint ( char *  p_str,
int  min,
int  max 
)
static

Parses the next integer in a list separated by commas.

Parameters
[in,out]p_strPointer to the string to parse, or NULL to continue from the last string.
minMinumum accepted value (inclusive).
maxMaximum accepted value (exclusive).
Returns
the parsed integer or -1 on error or out of range.

Variable Documentation

◆ named_colors

const struct named_color named_colors[]
static
Initial value:
=
{
{ "red", &color_red },
{ "orange", &color_orange },
{ "yellow", &color_yellow },
{ "neon", &color_neon },
{ "green", &color_green },
{ "seafoam", &color_seafoam },
{ "cyan", &color_cyan },
{ "lightblue", &color_lightblue },
{ "blue", &color_blue },
{ "purple", &color_purple },
{ "magenta", &color_magenta },
{ "pink", &color_pink },
{ "white", &color_white },
{ "black", &color_black },
{ "off", &color_off },
{ NULL, NULL }
}
const color_t color_green
Green: #00FF00.
Definition: color.c:46
const color_t color_cyan
Cyan: #00FFFF.
Definition: color.c:52
const color_t color_black
Black: #000000.
Definition: color.c:73
const color_t color_lightblue
Light Blue: #0080FF.
Definition: color.c:55
const color_t color_pink
Pink: #FF0080.
Definition: color.c:67
const color_t color_seafoam
Seafoam: #00FF80.
Definition: color.c:49
const color_t color_red
Red: #FF0000.
Definition: color.c:34
const color_t color_orange
Orange: #FF8000.
Definition: color.c:37
const color_t color_blue
Blue: #0000FF.
Definition: color.c:58
const color_t color_off
Off: #000000.
Definition: color.c:76
const color_t color_magenta
Magenta: #FF00FF.
Definition: color.c:64
const color_t color_neon
Neon: #80FF00.
Definition: color.c:43
const color_t color_purple
Purple: #8000FF.
Definition: color.c:61
const color_t color_white
White: #FFFFFF.
Definition: color.c:70
const color_t color_yellow
Yellow: #FFFF00.
Definition: color.c:40

List of named colors.

Pointers are NULL terminated at end of the list.