added clutter_color_to/from_hlsx(); clobbered hue to 0..255 in clutter_colour_to/from_hls()

This commit is contained in:
Tomas Frydrych 2007-05-10 11:37:45 +00:00
parent eb42f82f23
commit c5fee48847
3 changed files with 104 additions and 39 deletions

View File

@ -1,3 +1,11 @@
2007-05-10 Tomas Frydrych <tf@openedhand.com>
* clutter/clutter-color.h:
* clutter/clutter-color.c:
Added clutter_color_to/from_hlsx()
(clutter_color_to/from_hls):
Clobber hue to 0 .. 250
2007-05-10 Matthew Allum <mallum@openedhand.com> 2007-05-10 Matthew Allum <mallum@openedhand.com>
* clutter/clutter-backend.c: * clutter/clutter-backend.c:

View File

@ -128,7 +128,7 @@ clutter_color_darken (const ClutterColor *src,
} }
/** /**
* clutter_color_to_hls: * clutter_color_to_hlsx:
* @src: a #ClutterColor * @src: a #ClutterColor
* @hue: return location for the hue value or %NULL * @hue: return location for the hue value or %NULL
* @luminance: return location for the luminance value or %NULL * @luminance: return location for the luminance value or %NULL
@ -137,10 +137,10 @@ clutter_color_darken (const ClutterColor *src,
* Converts @src to the HLS format. * Converts @src to the HLS format.
*/ */
void void
clutter_color_to_hls (const ClutterColor *src, clutter_color_to_hlsx (const ClutterColor *src,
guint8 *hue, ClutterFixed *hue,
guint8 *luminance, ClutterFixed *luminance,
guint8 *saturation) ClutterFixed *saturation)
{ {
ClutterFixed red, green, blue; ClutterFixed red, green, blue;
ClutterFixed min, max, delta; ClutterFixed min, max, delta;
@ -202,17 +202,17 @@ clutter_color_to_hls (const ClutterColor *src,
} }
if (hue) if (hue)
*hue = (guint8) CFX_INT (h * 255); *hue = h;
if (luminance) if (luminance)
*luminance = (guint8) CFX_INT (l * 255); *luminance = l;
if (saturation) if (saturation)
*saturation = (guint8) CFX_INT (s * 255); *saturation = s;
} }
/** /**
* clutter_color_from_hls: * clutter_color_from_hlsx:
* @dest: return location for a #ClutterColor * @dest: return location for a #ClutterColor
* @hue: hue value (0 .. 255) * @hue: hue value (0 .. 255)
* @luminance: luminance value (0 .. 255) * @luminance: luminance value (0 .. 255)
@ -223,21 +223,21 @@ clutter_color_to_hls (const ClutterColor *src,
*/ */
void void
clutter_color_from_hls (ClutterColor *dest, clutter_color_from_hlsx (ClutterColor *dest,
guint8 hue, ClutterFixed hue,
guint8 luminance, ClutterFixed luminance,
guint8 saturation) ClutterFixed saturation)
{ {
ClutterFixed h, l, s; ClutterFixed h, l, s;
ClutterFixed m1, m2; ClutterFixed m1, m2;
g_return_if_fail (dest != NULL); g_return_if_fail (dest != NULL);
l = CLUTTER_INT_TO_FIXED (luminance) / 255; l = luminance;
s = CLUTTER_INT_TO_FIXED (saturation) / 255; s = saturation;
if (l <= CFX_ONE/2) if (l <= CFX_ONE/2)
m2 = CFX_MUL (l, (CFX_ONE - s)); m2 = CFX_MUL (l, (CFX_ONE + s));
else else
m2 = l + s - CFX_MUL (l,s); m2 = l + s - CFX_MUL (l,s);
@ -251,7 +251,7 @@ clutter_color_from_hls (ClutterColor *dest,
} }
else else
{ {
h = (CLUTTER_INT_TO_FIXED (hue)/ 255) + CFX_120; h = hue + CFX_120;
while (h > CFX_360) while (h > CFX_360)
h -= CFX_360; h -= CFX_360;
while (h < 0) while (h < 0)
@ -266,7 +266,7 @@ clutter_color_from_hls (ClutterColor *dest,
else else
dest->red = (guint8) CFX_INT (m1 * 255); dest->red = (guint8) CFX_INT (m1 * 255);
h = CLUTTER_INT_TO_FIXED (hue) / 255; h = hue;
while (h > CFX_360) while (h > CFX_360)
h -= CFX_360; h -= CFX_360;
while (h < 0) while (h < 0)
@ -282,7 +282,7 @@ clutter_color_from_hls (ClutterColor *dest,
else else
dest->green = (guint8) CFX_INT (m1 * 255); dest->green = (guint8) CFX_INT (m1 * 255);
h = (CLUTTER_INT_TO_FIXED (hue) / 255) - CFX_120; h = hue - CFX_120;
while (h > CFX_360) while (h > CFX_360)
h -= CFX_360; h -= CFX_360;
while (h < 0) while (h < 0)
@ -299,6 +299,61 @@ clutter_color_from_hls (ClutterColor *dest,
} }
} }
/**
* clutter_color_to_hls:
* @src: a #ClutterColor
* @hue: return location for the hue value or %NULL
* @luminance: return location for the luminance value or %NULL
* @saturation: return location for the saturation value or %NULL
*
* Converts @src to the HLS format.
*/
void
clutter_color_to_hls (const ClutterColor *src,
guint8 *hue,
guint8 *luminance,
guint8 *saturation)
{
ClutterFixed h, l, s;
clutter_color_to_hlsx (src, &h, &l, &s);
if (hue)
*hue = (guint8) CFX_INT (h * 255) / 360;
if (luminance)
*luminance = (guint8) CFX_INT (l * 255);
if (saturation)
*saturation = (guint8) CFX_INT (s * 255);
}
/**
* clutter_color_from_hls:
* @dest: return location for a #ClutterColor
* @hue: hue value (0 .. 360)
* @luminance: luminance value (0 .. 255)
* @saturation: saturation value (0 .. 255)
*
* Converts a color expressed in HLS (hue, luminance and saturation)
* values into a #ClutterColor.
*/
void
clutter_color_from_hls (ClutterColor *dest,
guint8 hue,
guint8 luminance,
guint8 saturation)
{
ClutterFixed h, l, s;
h = CLUTTER_INT_TO_FIXED (hue * 360) / 255;
l = CLUTTER_INT_TO_FIXED (luminance) / 255;
s = CLUTTER_INT_TO_FIXED (saturation) / 255;
clutter_color_from_hlsx (dest, h, l, s);
}
/** /**
* clutter_color_shade: * clutter_color_shade:
* @src: a #ClutterColor * @src: a #ClutterColor
@ -334,33 +389,26 @@ clutter_color_shadex (const ClutterColor *src,
ClutterColor *dest, ClutterColor *dest,
ClutterFixed shade) ClutterFixed shade)
{ {
guint8 h, l, s; ClutterFixed h, l, s;
ClutterFixed l1, s1;
g_return_if_fail (src != NULL); g_return_if_fail (src != NULL);
g_return_if_fail (dest != NULL); g_return_if_fail (dest != NULL);
clutter_color_to_hls (src, &h, &l, &s); clutter_color_to_hlsx (src, &h, &l, &s);
l1 = CLUTTER_INT_TO_FIXED (l) / 255; l = CFX_MUL (l, shade);
s1 = CLUTTER_INT_TO_FIXED (s) / 255; if (l > CFX_ONE)
l = CFX_ONE;
else if (l < 0)
l = 0;
l1 = CFX_MUL (l1, shade); s = CFX_MUL (s, shade);
if (l1 > CFX_ONE) if (s > CFX_ONE)
l1 = CFX_ONE; s = CFX_ONE;
else if (l1 < 0) else if (s < 0)
l1 = 0; s = 0;
s1 = CFX_MUL (s1, shade); clutter_color_from_hlsx (dest, h, l, s);
if (s1 > CFX_ONE)
s1 = CFX_ONE;
else if (s1 < 0)
s1 = 0;
l = (guint8) CFX_INT (l1 * 255);
s = (guint8) CFX_INT (s1 * 255);
clutter_color_from_hls (dest, h, l, s);
} }
/** /**

View File

@ -72,6 +72,15 @@ void clutter_color_shadex (const ClutterColor *src,
ClutterColor *dest, ClutterColor *dest,
ClutterFixed shade); ClutterFixed shade);
void clutter_color_to_hlsx (const ClutterColor *src,
ClutterFixed *hue,
ClutterFixed *luminance,
ClutterFixed *saturation);
void clutter_color_from_hlsx (ClutterColor *dest,
ClutterFixed hue,
ClutterFixed luminance,
ClutterFixed saturation);
void clutter_color_to_hls (const ClutterColor *src, void clutter_color_to_hls (const ClutterColor *src,
guint8 *hue, guint8 *hue,
guint8 *luminance, guint8 *luminance,