FastLED 3.9.15
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 495 of file hsv2rgb.cpp.hpp.

495 {
496 const auto f = [](const int n, const fl::u8 h) -> fl::u32 {
497 constexpr int kZero = 0 << 8;
498 constexpr int kOne = 1 << 8;
499 constexpr int kFour = 4 << 8;
500 constexpr int kSix = 6 << 8;
501
502 const int k = ((n << 8) + 6*h) % kSix;
503 const int k2 = kFour - k;
504 return fl::max(kZero, fl::min(kOne, fl::min(k, k2)));
505 };
506
507 const fl::u32 chroma = hsv.v * hsv.s / 255;
508 rgb.r = hsv.v - ((chroma * f(5, hsv.h)) >> 8);
509 rgb.g = hsv.v - ((chroma * f(3, hsv.h)) >> 8);
510 rgb.b = hsv.v - ((chroma * f(1, hsv.h)) >> 8);
511}
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
unsigned char u8
Definition stdint.h:131
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75

References 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: