Revert changes from PR1902

This commit is contained in:
Henry Gabryjelski
2021-08-29 11:49:06 -07:00
parent 1d4487b6cd
commit 021c4ba68a
9 changed files with 9 additions and 111 deletions

View File

@@ -47,77 +47,6 @@ void relativeChangeWhite(int8_t amount, byte lowerBoundary)
col[3] = new_val;
}
void colorHSVtoRGB(float hue, float saturation, float value, byte& red, byte& green, byte& blue)
{
float r, g, b;
auto i = static_cast<int>(hue * 6);
auto f = hue * 6 - i;
auto p = value * (1 - saturation);
auto q = value * (1 - f * saturation);
auto t = value * (1 - (1 - f) * saturation);
switch (i % 6)
{
case 0: r = value, g = t, b = p;
break;
case 1: r = q, g = value, b = p;
break;
case 2: r = p, g = value, b = t;
break;
case 3: r = p, g = q, b = value;
break;
case 4: r = t, g = p, b = value;
break;
case 5: r = value, g = p, b = q;
break;
}
red = static_cast<uint8_t>(r * 255);
green = static_cast<uint8_t>(g * 255);
blue = static_cast<uint8_t>(b * 255);
}
void colorRGBtoHSV(byte red, byte green, byte blue, float& hue, float& saturation, float& value)
{
auto rd = static_cast<float>(red) / 255;
auto gd = static_cast<float>(green) / 255;
auto bd = static_cast<float>(blue) / 255;
auto max = std::max({ rd, gd, bd }), min = std::min({ rd, gd, bd });
value = max;
auto d = max - min;
saturation = max == 0 ? 0 : d / max;
hue = 0;
if (max != min)
{
if (max == rd) hue = (gd - bd) / d + (gd < bd ? 6 : 0);
else if (max == gd) hue = (bd - rd) / d + 2;
else if (max == bd) hue = (rd - gd) / d + 4;
hue /= 6;
}
}
#define SATURATION_THRESHOLD 0.1
#define MAX_HSV_VALUE 1
#define MAX_HSV_SATURATION 1
//corrects the realtime colors. 10 is the unchanged saturation/value
//this feature might cause slowdowns with large LED counts
void correctColors(byte r, byte g, byte b, byte* rgb) {
float hsv[3] = { 0,0,0 };
colorRGBtoHSV(r, g,b , hsv[0], hsv[1], hsv[2]);
float saturated = hsv[1] > SATURATION_THRESHOLD ?
hsv[1] * ((float)liveHSVSaturation / 10) : hsv[1];
float saturation = saturated < MAX_HSV_SATURATION ? saturated : MAX_HSV_SATURATION;
float valued = hsv[2] * ((float)liveHSVValue/10);
float value = valued < MAX_HSV_VALUE ? valued : MAX_HSV_VALUE;
colorHSVtoRGB(hsv[0], saturation, value, rgb[0], rgb[1], rgb[2]);
}
void colorHStoRGB(uint16_t hue, byte sat, byte* rgb) //hue, sat to rgb
{
float h = ((float)hue)/65535.0;