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

Color conversions and types. More...

Modules

 Color Internals
 
 Named Colors
 

Data Structures

struct  color_rgb_t
 Color represented in red-green-blue color space. More...
 
struct  color_hsv_t
 Color represented in hue-saturation-value color space. More...
 
struct  color_hsl_t
 Color represented in hue-saturation-lightness color space. More...
 
union  color_kind_t
 Union for the three color space representations. More...
 
struct  color_t
 Represents a color in a defined color space. More...
 

Macros

#define RGB_MAX   (255U)
 Maximum value of an RGB color component.
 
#define RGB_MAX_F32   (255.0f)
 Maximum value of an RGB color component as a float-32.
 
#define RGB_RANGE   (256U)
 Total range of RGB values.
 
#define RGB_RANGE_F32   (256.0f)
 Total range of RGB values as a float-32.
 
#define HUE_MAX   (359U)
 Maximum value of hue.
 
#define HUE_MAX_F32   (359.0f)
 Maximum value of hue as a float-32.
 
#define HUE_RANGE   (360U)
 Total range of hue values.
 
#define HUE_RANGE_F32   (360.0f)
 Total range of hue values as a float-32.
 
#define HUE_FP_BITS   (6U)
 Number of fixed-point fractional bits in the internal hue representation.
 
#define HUE(x)   ((uint16_t)((x) << HUE_FP_BITS))
 Converts an integer hue to the fixed-point representation.
 
#define HUE_F32(x)   ((uint16_t)((x) * (float)(1 << HUE_FP_BITS)))
 Converts a float hue to the fixed-point representation.
 
#define HUE_FP_TO_F32(x)   ((float)(x) / (float)(1 << HUE_FP_BITS))
 Converts a fixed-point value to a float.
 
#define SATURATION_MAX   (100U)
 Maximum value of saturation.
 
#define SATURATION_MAX_F32   (100.0f)
 Maximum value of saturation as a float-32.
 
#define VALUE_MAX   (100U)
 Maximum value of the value component of HSV.
 
#define VALUE_MAX_F32   (100.0f)
 Maximum value of the value component of HSV as a float-32.
 
#define LIGHTNESS_MAX   (100U)
 Maximum value of lightness.
 
#define LIGHTNESS_MAX_F32   (100.0f)
 Maximum value of lightness as a float-32.
 

Enumerations

enum  color_space_t { COLOR_SPACE_RGB , COLOR_SPACE_HSV , COLOR_SPACE_HSL }
 Supported color spaces. More...
 

Functions

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...
 

Detailed Description

Color conversions and types.

Enumeration Type Documentation

◆ color_space_t

Supported color spaces.

Enumerator
COLOR_SPACE_RGB 

Red-green-blue color space.

COLOR_SPACE_HSV 

Hue-saturation-value color space.

COLOR_SPACE_HSL 

Hue-saturation-lightness color space.

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_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.