Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'hsv2rgb.h')
-rw-r--r--hsv2rgb.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/hsv2rgb.h b/hsv2rgb.h
index 959c754a..6611298b 100644
--- a/hsv2rgb.h
+++ b/hsv2rgb.h
@@ -3,6 +3,7 @@
#include "pixeltypes.h"
+FASTLED_NAMESPACE_BEGIN
// hsv2rgb_rainbow - convert a hue, saturation, and value to RGB
// using a visually balanced rainbow (vs a straight
@@ -45,4 +46,44 @@ void hsv2rgb_raw(const struct CHSV& hsv, struct CRGB & rgb);
void hsv2rgb_raw(const struct CHSV* phsv, struct CRGB * prgb, int numLeds);
#define HUE_MAX 191
+
+// rgb2hsv_approximate - recover _approximate_ HSV values from RGB.
+//
+// NOTE 1: This function is a long-term work in process; expect
+// results to change slightly over time as this function is
+// refined and improved.
+//
+// NOTE 2: This function is most accurate when the input is an
+// RGB color that came from a fully-saturated HSV color to start
+// with. E.g. CHSV( hue, 255, 255) -> CRGB -> CHSV will give
+// best results.
+//
+// NOTE 3: This function is not nearly as fast as HSV-to-RGB.
+// It is provided for those situations when the need for this
+// function cannot be avoided, or when extremely high performance
+// is not needed.
+//
+// NOTE 4: Why is this 'only' an "approximation"?
+// Not all RGB colors have HSV equivalents! For example, there
+// is no HSV value that will ever convert to RGB(255,255,0) using
+// the code provided in this library. So if you try to
+// convert RGB(255,255,0) 'back' to HSV, you'll necessarily get
+// only an approximation. Emphasis has been placed on getting
+// the 'hue' as close as usefully possible, but even that's a bit
+// of a challenge. The 8-bit HSV and 8-bit RGB color spaces
+// are not a "bijection".
+//
+// Nevertheless, this function does a pretty good job, particularly
+// at recovering the 'hue' from fully saturated RGB colors that
+// originally came from HSV rainbow colors. So if you start
+// with CHSV(hue_in,255,255), and convert that to RGB, and then
+// convert it back to HSV using this function, the resulting output
+// hue will either exactly the same, or very close (+/-1).
+// The more desaturated the original RGB color is, the rougher the
+// approximation, and the less accurate the results.
+//
+CHSV rgb2hsv_approximate( const CRGB& rgb);
+
+FASTLED_NAMESPACE_END
+
#endif