cellGem: fix cellGemHSVtoRGB

This commit is contained in:
Megamouse
2026-10-01 22:35:46 +02:00
parent 53d9522073
commit 1dd70e036e
+12 -5
View File
@@ -3593,12 +3593,19 @@ error_code cellGemHSVtoRGB(f32 h, f32 s, f32 v, vm::ptr<f32> r, vm::ptr<f32> g,
{
cellGem.warning("cellGemHSVtoRGB(h=%f, s=%f, v=%f, r=*0x%x, g=*0x%x, b=*0x%x)", h, s, v, r, g, b);
if (s < 0.0f || s > 1.0f || v < 0.0f || v > 1.0f || !r || !g || !b)
if (!r || !g || !b)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
h = std::clamp(h, 0.0f, 360.0f);
h = std::fmod(h, 360.0f);
s = std::clamp(s, 0.0f, 1.0f);
v = std::clamp(v, 0.0f, 1.0f);
if (h < 0.0)
{
h += 360.0f;
}
const f32 c = v * s;
const f32 x = c * (1.0f - fabs(fmod(h / 60.0f, 2.0f) - 1.0f));
@@ -3639,9 +3646,9 @@ error_code cellGemHSVtoRGB(f32 h, f32 s, f32 v, vm::ptr<f32> r, vm::ptr<f32> g,
b_tmp = x;
}
*r = (r_tmp + m) * 255.0f;
*g = (g_tmp + m) * 255.0f;
*b = (b_tmp + m) * 255.0f;
*r = std::clamp(r_tmp + m, 0.0f, 1.0f);
*g = std::clamp(g_tmp + m, 0.0f, 1.0f);
*b = std::clamp(b_tmp + m, 0.0f, 1.0f);
return CELL_OK;
}