PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 satır
3.6KB

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