mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user