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.
This commit is contained in:
Emmanuele Bassi 2009-10-26 16:29:31 +00:00
parent 5a14db5089
commit c387513a5f

View File

@ -39,6 +39,8 @@
#include "config.h"
#endif
#include <math.h>
#include <pango/pango-attributes.h>
#include <gobject/gvaluecollector.h>
@ -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);
}
/**