PixelKey
NeoPixel USB Key
Loading...
Searching...
No Matches
color.c File Reference
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <string.h>
#include "color.h"

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.