Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
color_utils.c File Reference

Functions

uint32_t EHSVtoHEXhelper (uint8_t hue, uint8_t sat, uint8_t val, bool applyGamma)
 This converts a hue, saturation, and value (HSV) into 32 bit RGB (0xBBGGRR)
 
led_t LedEHSVtoHEXhelper (uint8_t hue, uint8_t sat, uint8_t val, bool applyGamma)
 This converts a hue, saturation, and value (HSV) into led_t color.
 
paletteColor_t paletteHsvToHex (uint8_t hue, uint8_t sat, uint8_t val)
 This converts a hue, saturation, and value (HSV) into paletteColor_t color.
 
paletteColor_t RGBtoPalette (uint32_t rgb)
 Find the palette color closest to the given 32 bit RGB color.
 
uint32_t paletteToRGB (paletteColor_t pal)
 Find the 32 bit RGB color for the given palette color.
 

Variables

const uint32_t gamma_correction_table [256]
 A table that can be used for gamma correction.
 

Function Documentation

◆ EHSVtoHEXhelper()

uint32_t EHSVtoHEXhelper ( uint8_t hue,
uint8_t sat,
uint8_t val,
bool applyGamma )

This converts a hue, saturation, and value (HSV) into 32 bit RGB (0xBBGGRR)

Parameters
hueHue, the color, 0..255
satSaturation, how intense the color is, 0..255
valValue, how bright the color is, 0..255
applyGammaWhether or not to apply gamma to the output
Returns
An RGB color (0xBBGGRR)

◆ LedEHSVtoHEXhelper()

led_t LedEHSVtoHEXhelper ( uint8_t hue,
uint8_t sat,
uint8_t val,
bool applyGamma )

This converts a hue, saturation, and value (HSV) into led_t color.

Parameters
hueHue, the color, 0..255
satSaturation, how intense the color is, 0..255
valValue, how bright the color is, 0..255
applyGammaWhether or not to apply gamma to the output
Returns
An led_t set to the RGB color

◆ paletteHsvToHex()

paletteColor_t paletteHsvToHex ( uint8_t hue,
uint8_t sat,
uint8_t val )

This converts a hue, saturation, and value (HSV) into paletteColor_t color.

Parameters
hueHue, the color, 0..255
satSaturation, how intense the color is, 0..255
valValue, how bright the color is, 0..255
Returns
The paletteColor_t closest to the HSV color

◆ RGBtoPalette()

paletteColor_t RGBtoPalette ( uint32_t rgb)

Find the palette color closest to the given 32 bit RGB color.

Parameters
rgbA 32 bit RGB color (0xBBGGRR)
Returns
The closest palette color to the given RGB color

◆ paletteToRGB()

uint32_t paletteToRGB ( paletteColor_t pal)

Find the 32 bit RGB color for the given palette color.

Parameters
palA palette color
Returns
The 32 bit RGB representation of the palette color (0xBBGGRR)

Variable Documentation

◆ gamma_correction_table

const uint32_t gamma_correction_table[256]
Initial value:
= {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6,
6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14,
14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 23, 23, 24, 24, 25,
26, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 36, 37, 38, 39, 40, 40,
41, 42, 43, 44, 44, 45, 46, 47, 48, 49, 50, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84,
85, 86, 88, 89, 90, 91, 92, 94, 95, 96, 98, 99, 100, 101, 103, 104, 106, 107, 108, 110, 111, 112,
114, 115, 117, 118, 120, 121, 122, 124, 125, 127, 128, 130, 131, 133, 134, 136, 138, 139, 141, 142, 144, 146,
147, 149, 150, 152, 154, 155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 174, 176, 178, 180, 182, 183,
185, 187, 189, 191, 193, 195, 197, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226,
228, 230, 232, 235, 237, 239, 241, 243, 245, 247, 249, 252, 254, 255}

A table that can be used for gamma correction.

A LUT which maps perceived brightness to LED brightness.

Maps a uint8_t value to a gamma-corrected uint8_t.