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

Detailed Description

Design Philosophy

These are a collection of functions to convert from red, green, blue (RGB) to hue, saturation, value (HSV) color spaces.

Functions can also convert between the paletteColor_t enum and the RGB color space.

Usage

Call the functions as necessary.

Example

// HSV to RGB, three different output formats
uint8_t hue = 0xFF;
uint8_t sat = 0xFF;
uint8_t val = 0xFF;
uint32_t rgb = EHSVtoHEXhelper(hue, sat, val, true);
led_t ledVal = LedEHSVtoHEXhelper(hue, sat, val, true);
paletteColor_t pCol = paletteHsvToHex(hue, sat, val);
// Palette to RGB and back
paletteColor_t pCol = RGBtoPalette(0x123456);
uint32_t rgbCol = paletteToRGB(c345);
paletteColor_t RGBtoPalette(uint32_t rgb)
Find the palette color closest to the given 32 bit RGB color.
Definition color_utils.c:158
paletteColor_t paletteHsvToHex(uint8_t hue, uint8_t sat, uint8_t val)
This converts a hue, saturation, and value (HSV) into paletteColor_t color.
Definition color_utils.c:147
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.
Definition color_utils.c:129
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)
Definition color_utils.c:43
uint32_t paletteToRGB(paletteColor_t pal)
Find the 32 bit RGB color for the given palette color.
Definition color_utils.c:175
LED colors, with red, green, and blue components.
Definition hdw-led.h:63
paletteColor_t
All 216 possible colors, named like cRGB.
Definition palette.h:23
@ c345
r = 3, g = 4, b = 5
Definition palette.h:161

Go to the source code of this file.

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 LUT which maps perceived brightness to LED brightness.
 

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]
extern

A LUT which maps perceived brightness to LED brightness.

A LUT which maps perceived brightness to LED brightness.

Maps a uint8_t value to a gamma-corrected uint8_t.