From bd6510ec45cb266ab132035c41b4afaba10221b9 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 1 Feb 2013 01:28:08 +0000 Subject: [PATCH] color: fix a logic error in RGBToHSL. --- src/lol/image/color.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lol/image/color.h b/src/lol/image/color.h index 81c96706..bc1ee49f 100644 --- a/src/lol/image/color.h +++ b/src/lol/image/color.h @@ -122,8 +122,10 @@ public: float chroma = src.r - min(src.g, src.b); float luma = src.r + min(src.g, src.b); + /* XXX: we use min() here because numerical stability is not + * guaranteed with -ffast-math, I’ve seen it fail on i386. */ float h = min(abs(K + (src.g - src.b) / (6.f * chroma)), 1.f); - float s = min(abs(chroma / (min(luma, 2.f - luma))), 1.f); + float s = clamp(chroma / (min(luma, 2.f - luma)), 0.f, 1.f); return vec3(h, s, 0.5f * luma); }