FastLED 3.10.8
Loading...
Searching...
No Matches

◆ hsv2rgb_fullspectrum() [2/3]

void hsv2rgb_fullspectrum ( const CHSV & hsv,
CRGB & rgb )

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.

Parameters
hsvCHSV struct to convert to RGB
rgbCRGB struct to store the result of the conversion (will be modified)

Definition at line 504 of file hsv2rgb.cpp.hpp.

504 {
505 const auto f = [](const int n, const fl::u8 h) -> fl::u32 {
506 constexpr int kZero = 0 << 8;
507 constexpr int kOne = 1 << 8;
508 constexpr int kFour = 4 << 8;
509 constexpr int kSix = 6 << 8;
510
511 const int k = ((n << 8) + 6*h) % kSix;
512 const int k2 = kFour - k;
513 return fl::max(kZero, fl::min(kOne, fl::min(k, k2)));
514 };
515
516 const fl::u32 chroma = hsv.v * hsv.s / 255;
517 rgb.r = hsv.v - ((chroma * f(5, hsv.h)) >> 8);
518 rgb.g = hsv.v - ((chroma * f(3, hsv.h)) >> 8);
519 rgb.b = hsv.v - ((chroma * f(1, hsv.h)) >> 8);
520}
unsigned char u8
Definition stdint.h:131
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
Definition math.h:75
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
Definition math.h:71

References FL_NO_EXCEPT, fl::max(), and fl::min().

Referenced by hsv2rgb_dispatch(), hsv2rgb_dispatch(), hsv2rgb_fullspectrum(), hsv2rgb_fullspectrum(), and loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: