From ad7dcc989648791e8fec1bb45711c9f71671dfe0 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 27 Jul 2009 12:04:40 +0100 Subject: [PATCH] [color] Fix HLS to RGB colorspace conversion The HLS to RGB conversion in case the S value is zero is: R = G = B = luminance ClutterColor uses a byte (0 to 255) for the R, G and B channels encoding, while luminance is expressed using a floating point value in the closed interval [0, 1]; thus the case above becomes: R = G = B = (luminance * 255) The clutter_color_from_hls() code is missing the final step of de-normalizing the luminance value, and so it breaks the roundtrip colorspace conversion between RGB and HLS. Fixes bug: http://bugzilla.openedhand.com/show_bug.cgi?id=1695 --- clutter/clutter-color.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/clutter/clutter-color.c b/clutter/clutter-color.c index 0ff170e..a190690 100644 --- a/clutter/clutter-color.c +++ b/clutter/clutter-color.c @@ -244,15 +244,10 @@ clutter_color_from_hls (ClutterColor *color, hue /= 360.0; - if (luminance == 0) - { - color->red = color->green = color->blue = 0; - return; - } - if (saturation == 0) { - color->red = color->green = color->blue = luminance; + color->red = color->green = color->blue = (luminance * 255); + return; } @@ -271,6 +266,7 @@ clutter_color_from_hls (ClutterColor *color, { if (tmp3[i] < 0) tmp3[i] += 1.0; + if (tmp3[i] > 1) tmp3[i] -= 1.0; @@ -284,9 +280,9 @@ clutter_color_from_hls (ClutterColor *color, clr[i] = tmp1; } - color->red = clr[0] * 255.0; + color->red = clr[0] * 255.0; color->green = clr[1] * 255.0; - color->blue = clr[2] * 255.0; + color->blue = clr[2] * 255.0; } /** -- 2.7.4