improve accuracy

This commit is contained in:
Misha
2023-06-26 13:50:40 +03:00
parent 7dd3469ca3
commit 4c2e1ca95c

View File

@@ -4,22 +4,27 @@
void ConvertColor(float h, float s, float v, float *r_out, float *b_out, float *g_out) void ConvertColor(float h, float s, float v, float *r_out, float *b_out, float *g_out)
{ {
double calc; // st7 double calc; // st7
if (s <= 0.5) double v11;
calc = (v + 1.0) * s; int hue_index;
else double v9;
double v12;
double v13;
if (s >= 0.5)
calc = (1.0 - v) * s + v; calc = (1.0 - v) * s + v;
if (calc < 0.0) else
calc = (v + 1.0) * s;
if (calc <= 0.0)
{ {
*g_out = 0.0; *g_out = 0.0;
*b_out = 0.0; *b_out = 0.0;
*r_out = 0.0; *r_out = 0.0;
return; return;
} }
double v11 = s * 2.0 - calc; v11 = s * 2.0 - calc;
int hue_index = h * 6.0; hue_index = h * 6.0;
double v9 = (calc - v11) / calc * (hue_index - hue_index) * calc; v9 = (h * 6.0 - (float)hue_index) * ((calc - v11) / calc) * calc;
double v12 = v11 + v9; v12 = v11 + v9;
double v13 = calc - v9; v13 = calc - v9;
switch (hue_index) switch (hue_index)
{ {
case 0: case 0: