isle/LEGO1/legoutil.cpp

68 lines
1.1 KiB
C++
Raw Normal View History

2023-06-24 14:47:05 -04:00
#include "legoutil.h"
// OFFSET: LEGO1 0x1003eae0
2023-06-27 11:35:58 -04:00
void ConvertHSVToRGB(float h, float s, float v, float *r_out, float *b_out, float *g_out)
2023-06-24 14:47:05 -04:00
{
2023-06-27 11:35:58 -04:00
double calc;
double p;
long hue_index;
2023-06-26 06:50:40 -04:00
double v9;
double v12;
double v13;
2023-06-27 11:35:58 -04:00
if (s > 0.5f)
2023-06-28 11:15:42 -04:00
calc = (1.0f - v) * s + v;
2023-06-26 06:50:40 -04:00
else
calc = (v + 1.0) * s;
if (calc <= 0.0)
2023-06-26 06:24:11 -04:00
{
2023-06-27 11:35:58 -04:00
*g_out = 0.0f;
*b_out = 0.0f;
*r_out = 0.0f;
2023-06-26 06:24:11 -04:00
return;
}
2023-06-27 11:35:58 -04:00
p = s * 2.0 - calc;
2023-06-26 06:50:40 -04:00
hue_index = h * 6.0;
2023-06-27 11:35:58 -04:00
v9 = (h * 6.0 - (float)hue_index) * ((calc - p) / calc) * calc;
v12 = p + v9;
2023-06-26 06:50:40 -04:00
v13 = calc - v9;
2023-06-26 06:24:11 -04:00
switch (hue_index)
{
case 0:
*r_out = calc;
*b_out = v12;
2023-06-27 11:35:58 -04:00
*g_out = p;
2023-06-26 06:24:11 -04:00
break;
case 1:
*r_out = v13;
*b_out = calc;
2023-06-27 11:35:58 -04:00
*g_out = p;
2023-06-26 06:24:11 -04:00
break;
case 2:
2023-06-27 11:35:58 -04:00
*r_out = p;
2023-06-26 06:24:11 -04:00
*b_out = calc;
*g_out = v12;
break;
case 3:
2023-06-27 11:35:58 -04:00
*r_out = p;
2023-06-26 06:24:11 -04:00
*b_out = v13;
*g_out = calc;
break;
case 4:
*r_out = v12;
2023-06-27 11:35:58 -04:00
*b_out = p;
2023-06-26 06:24:11 -04:00
*g_out = calc;
break;
case 5:
*r_out = calc;
2023-06-27 11:35:58 -04:00
*b_out = p;
2023-06-26 06:24:11 -04:00
*g_out = v13;
break;
case 6:
*r_out = calc;
2023-06-27 11:35:58 -04:00
*b_out = p;
2023-06-26 06:24:11 -04:00
*g_out = v13;
break;
default:
return;
}
2023-06-24 14:47:05 -04:00
}