FastLED 3.10.8
Loading...
Searching...
No Matches
HSV to RGB Conversion Functions

Detailed Description

Functions to convert from the HSV colorspace to the RGB colorspace.

These basically fall into two groups: spectra, and rainbows. pectra and rainbows are not the same thing. Wikipedia has a good llustration that shows a "spectrum" and a "rainbow" side by side: Spectra and Rainbow comparison

Source: http://en.wikipedia.org/wiki/Rainbow#Number_of_colours_in_spectrum_or_rainbow

Among other differences, you'll see that a "rainbow" has much more yellow than a plain spectrum. "Classic" LED color washes are spectrum based, and usually show very little yellow.

Take a look Wikipedia's page on HSV color space, with pseudocode for conversion to RGB color space: http://en.wikipedia.org/wiki/HSL_and_HSV

Note that their conversion algorithm, which is (naturally) very popular is in the "maximum brightness at any given hue" style, vs. the "uniform brightness for all hues" style.

You can't have both; either purple is the same brightness as red, e.g:

red = 0xFF0000
purple = 0x800080

Where you have the same "total light" output. OR purple is "as bright as it can be", e.g.:

red = 0xFF0000
purple = 0xFF00FF

Where purple is much brighter than red.

The colorspace conversions here try to keep the apparent brightness constant even as the hue varies.

Note
CHSV::val is part of this 8-bit colorspace conversion. Very low values necessarily quantize individual RGB channels and can make a mixed hue appear closer to a primary color. For sensor-controlled output brightness, keep the color at full value and use FastLED.setBrightness() so the output pipeline can preserve the channel ratios with temporal dithering.

Adafruit's "Wheel" function, discussed here is also of the "constant apparent brightness" variety.

Todo
Provide the "maximum brightness no matter what" variation.
See also
Some good, clear Arduino C code from Kasper Kamperman, which in turn was based on Windows C code from "nico80"

Macros

#define HUE_MAX   191
 Max hue accepted for the hsv2rgb_raw() function.
 
#define HUE_MAX_RAINBOW   255
 Max hue accepted for the hsv2rgb_rainbow() function.
 
#define HUE_MAX_SPECTRUM   255
 Max hue accepted for the hsv2rgb_spectrum() function.
 

Typedefs

using CHSV = fl::hsv8
 
using CRGB = fl::CRGB
 

Functions

CRGB hsv2rgb_fullspectrum (const CHSV &hsv) FL_NO_EXCEPT
 version of hsv2rgb_fullspectrum which returns a CRGB object.
 
void hsv2rgb_fullspectrum (const CHSV &hsv, CRGB &rgb) FL_NO_EXCEPT
 Converts an HSV value to RGB using the algorithm from here: https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative By Shawn Silverman.
 
void hsv2rgb_fullspectrum (const CHSV *phsv, CRGB *prgb, int numLeds) FL_NO_EXCEPT
 Converts an HSV value to RGB using the algorithm from here: https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative By Shawn Silverman.
 
CRGB hsv2rgb_rainbow (const CHSV &hsv) FL_NO_EXCEPT
 
void hsv2rgb_rainbow (const CHSV &hsv, CRGB &rgb) FL_NO_EXCEPT
 
void hsv2rgb_rainbow (const CHSV *phsv, CRGB *prgb, int numLeds) FL_NO_EXCEPT
 
void hsv2rgb_raw (const CHSV &hsv, CRGB &rgb) FL_NO_EXCEPT
 Convert an HSV value to RGB using a mathematically straight spectrum.
 
void hsv2rgb_raw (const CHSV *phsv, CRGB *prgb, int numLeds) FL_NO_EXCEPT
 Convert an HSV value to RGB using a mathematically straight spectrum.
 
CRGB hsv2rgb_spectrum (const CHSV &hsv) FL_NO_EXCEPT
 Inline version of hsv2rgb_spectrum which returns a CRGB object.
 
void hsv2rgb_spectrum (const CHSV &hsv, CRGB &rgb) FL_NO_EXCEPT
 Convert an HSV value to RGB using a mathematically straight spectrum.
 
void hsv2rgb_spectrum (const CHSV *phsv, CRGB *prgb, int numLeds) FL_NO_EXCEPT
 Convert an HSV value to RGB using a mathematically straight spectrum.
 
CHSV rgb2hsv_approximate (const CRGB &rgb) FL_NO_EXCEPT
 Recover approximate HSV values from RGB.