LightHub
4.6.0
Open-source smart home controller firmware
Toggle main menu visibility
Loading...
Searching...
No Matches
hsv2rgb.h
Go to the documentation of this file.
1
#ifndef __INC_HSV2RGB_H
2
#define __INC_HSV2RGB_H
3
4
#include "FastLED.h"
5
6
#include "pixeltypes.h"
7
8
FASTLED_NAMESPACE_BEGIN
9
10
// hsv2rgb_rainbow - convert a hue, saturation, and value to RGB
11
// using a visually balanced rainbow (vs a straight
12
// mathematical spectrum).
13
// This 'rainbow' yields better yellow and orange
14
// than a straight 'spectrum'.
15
//
16
// NOTE: here hue is 0-255, not just 0-191
17
18
void
hsv2rgb_rainbow
(
const
struct
CHSV& hsv,
struct
CRGB& rgb);
19
void
hsv2rgb_rainbow
(
const
struct
CHSV* phsv,
struct
CRGB * prgb,
int
numLeds);
20
#define HUE_MAX_RAINBOW 255
21
22
23
// hsv2rgb_spectrum - convert a hue, saturation, and value to RGB
24
// using a mathematically straight spectrum (vs
25
// a visually balanced rainbow).
26
// This 'spectrum' will have more green & blue
27
// than a 'rainbow', and less yellow and orange.
28
//
29
// NOTE: here hue is 0-255, not just 0-191
30
31
void
hsv2rgb_spectrum
(
const
struct
CHSV& hsv,
struct
CRGB& rgb);
32
void
hsv2rgb_spectrum
(
const
struct
CHSV* phsv,
struct
CRGB * prgb,
int
numLeds);
33
#define HUE_MAX_SPECTRUM 255
34
35
36
// hsv2rgb_raw - convert hue, saturation, and value to RGB.
37
// This 'spectrum' conversion will be more green & blue
38
// than a real 'rainbow', and the hue is specified just
39
// in the range 0-191. Together, these result in a
40
// slightly faster conversion speed, at the expense of
41
// color balance.
42
//
43
// NOTE: Hue is 0-191 only!
44
// Saturation & value are 0-255 each.
45
//
46
47
void
hsv2rgb_raw
(
const
struct
CHSV& hsv,
struct
CRGB & rgb);
48
void
hsv2rgb_raw
(
const
struct
CHSV* phsv,
struct
CRGB * prgb,
int
numLeds);
49
#define HUE_MAX 191
50
51
52
// rgb2hsv_approximate - recover _approximate_ HSV values from RGB.
53
//
54
// NOTE 1: This function is a long-term work in process; expect
55
// results to change slightly over time as this function is
56
// refined and improved.
57
//
58
// NOTE 2: This function is most accurate when the input is an
59
// RGB color that came from a fully-saturated HSV color to start
60
// with. E.g. CHSV( hue, 255, 255) -> CRGB -> CHSV will give
61
// best results.
62
//
63
// NOTE 3: This function is not nearly as fast as HSV-to-RGB.
64
// It is provided for those situations when the need for this
65
// function cannot be avoided, or when extremely high performance
66
// is not needed.
67
//
68
// NOTE 4: Why is this 'only' an "approximation"?
69
// Not all RGB colors have HSV equivalents! For example, there
70
// is no HSV value that will ever convert to RGB(255,255,0) using
71
// the code provided in this library. So if you try to
72
// convert RGB(255,255,0) 'back' to HSV, you'll necessarily get
73
// only an approximation. Emphasis has been placed on getting
74
// the 'hue' as close as usefully possible, but even that's a bit
75
// of a challenge. The 8-bit HSV and 8-bit RGB color spaces
76
// are not a "bijection".
77
//
78
// Nevertheless, this function does a pretty good job, particularly
79
// at recovering the 'hue' from fully saturated RGB colors that
80
// originally came from HSV rainbow colors. So if you start
81
// with CHSV(hue_in,255,255), and convert that to RGB, and then
82
// convert it back to HSV using this function, the resulting output
83
// hue will either exactly the same, or very close (+/-1).
84
// The more desaturated the original RGB color is, the rougher the
85
// approximation, and the less accurate the results.
86
//
87
CHSV
rgb2hsv_approximate
(
const
CRGB& rgb);
88
89
FASTLED_NAMESPACE_END
90
91
#endif
hsv2rgb_rainbow
void hsv2rgb_rainbow(const CHSV &hsv, CRGB &rgb)
Definition
hsv2rgb.cpp:278
hsv2rgb_spectrum
void hsv2rgb_spectrum(const CHSV &hsv, CRGB &rgb)
Definition
hsv2rgb.cpp:256
hsv2rgb_raw
void hsv2rgb_raw(const struct CHSV &hsv, struct CRGB &rgb)
Definition
hsv2rgb.cpp:59
rgb2hsv_approximate
CHSV rgb2hsv_approximate(const CRGB &rgb)
Definition
hsv2rgb.cpp:523
lib
hsv2rgb
hsv2rgb.h
Generated by
1.18.0