From c387513a5fd5293cb8cf60e9c1334ceeff905852 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 26 Oct 2009 16:29:31 +0000 Subject: [PATCH] color: Fix HLS-to-RGB conversion Apparently, on 64bit systems the floating point noise is enough to screw up the float-to-int truncation. The solution is to round up by 0.5 and then use floorf(). This gives predictable and correct results on both 32bit and 64bit systems. --- clutter/clutter-color.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/clutter/clutter-color.c b/clutter/clutter-color.c index e0b4614ea..b9d14f0d8 100644 --- a/clutter/clutter-color.c +++ b/clutter/clutter-color.c @@ -39,6 +39,8 @@ #include "config.h" #endif +#include + #include #include @@ -282,9 +284,9 @@ clutter_color_from_hls (ClutterColor *color, clr[i] = tmp1; } - color->red = clr[0] * 255.0; - color->green = clr[1] * 255.0; - color->blue = clr[2] * 255.0; + color->red = floorf (clr[0] * 255.0 + 0.5); + color->green = floorf (clr[1] * 255.0 + 0.5); + color->blue = floorf (clr[2] * 255.0 + 0.5); } /**