[wpilib] Tweak Color HSV formula and use in AddressableLED (#4724)

The Color algorithm was tweaked to:
a) not produce incorrect values if the user happens to input a hue outside the [0, 180) range, and
b) more accurately convert the hue remainder from range 0-30 to 0-255. The current conversion vastly overshoots the multiplier (converts 0-30 to 0-270) and relies on clamping the value when constructing the Color object to produce a slightly incorrect result.
This commit is contained in:
Colin Wong
2022-11-28 16:42:22 -06:00
committed by GitHub
parent ec124bb662
commit e82cd5147b
4 changed files with 42 additions and 25 deletions

View File

@@ -784,10 +784,10 @@ class Color {
int chroma = (s * v) >> 8;
// Beacuse hue is 0-180 rather than 0-360 use 30 not 60
int region = h / 30;
int region = (h / 30) % 6;
// Remainder converted from 0-30 to roughly 0-255
int remainder = (h - (region * 30)) * 9;
// Remainder converted from 0-30 to 0-255
int remainder = static_cast<int>((h % 30) * (255 / 30.0));
// Value of the lowest rgb component
int m = v - chroma;