Release Clutter 1.11.4 (snapshot)
[profile/ivi/clutter.git] / clutter / clutter-color.c
index 45191f3..723349a 100644 (file)
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /**
  * SECTION:clutter-color
  * @short_description: Color management and manipulation.
  *
- * #ClutterColor is a simple type for representing colors.
+ * #ClutterColor is a simple type for representing colors in Clutter.
+ *
+ * A #ClutterColor is expressed as a 4-tuple of values ranging from
+ * zero to 255, one for each color channel plus one for the alpha.
+ *
+ * The alpha channel is fully opaque at 255 and fully transparent at 0.
  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include <math.h>
+
 #include <pango/pango-attributes.h>
-#include <gobject/gvaluecollector.h>
 
+#include "clutter-interval.h"
 #include "clutter-main.h"
 #include "clutter-color.h"
 #include "clutter-private.h"
 #include "clutter-debug.h"
 
+/* XXX - keep in sync with the ClutterStaticColor enumeration order */
+static const ClutterColor const static_colors[] = {
+  /* CGA/EGA color palette */
+  { 0xff, 0xff, 0xff, 0xff },   /* white */
+  { 0x00, 0x00, 0x00, 0xff },   /* black */
+  { 0xff, 0x00, 0x00, 0xff },   /* red */
+  { 0x80, 0x00, 0x00, 0xff },   /* dark red */
+  { 0x00, 0xff, 0x00, 0xff },   /* green */
+  { 0x00, 0x80, 0x00, 0xff },   /* dark green */
+  { 0x00, 0x00, 0xff, 0xff },   /* blue */
+  { 0x00, 0x00, 0x80, 0xff },   /* dark blue */
+  { 0x00, 0xff, 0xff, 0xff },   /* cyan */
+  { 0x00, 0x80, 0x80, 0xff },   /* dark cyan */
+  { 0xff, 0x00, 0xff, 0xff },   /* magenta */
+  { 0x80, 0x00, 0x80, 0xff },   /* dark magenta */
+  { 0xff, 0xff, 0x00, 0xff },   /* yellow */
+  { 0x80, 0x80, 0x00, 0xff },   /* dark yellow */
+  { 0xa0, 0xa0, 0xa4, 0xff },   /* gray */
+  { 0x80, 0x80, 0x80, 0xff },   /* dark gray */
+  { 0xc0, 0xc0, 0xc0, 0xff },   /* light gray */
+
+  /* Tango Icon color palette */
+  { 0xed, 0xd4, 0x00, 0xff },   /* butter */
+  { 0xfc, 0xe9, 0x4f, 0xff },   /* butter light */
+  { 0xc4, 0xa0, 0x00, 0xff },   /* butter dark */
+  { 0xf5, 0x79, 0x00, 0xff },   /* orange */
+  { 0xfc, 0xaf, 0x3e, 0xff },   /* orange light */
+  { 0xce, 0x5c, 0x00, 0xff },   /* orange dark */
+  { 0xc1, 0x7d, 0x11, 0xff },   /* chocolate */
+  { 0xe9, 0xb9, 0x6e, 0xff },   /* chocolate light */
+  { 0x8f, 0x59, 0x02, 0xff },   /* chocolate dark */
+  { 0x73, 0xd2, 0x16, 0xff },   /* chameleon */
+  { 0x8a, 0xe2, 0x34, 0xff },   /* chameleon light */
+  { 0x4e, 0x9a, 0x06, 0xff },   /* chameleon dark */
+  { 0x34, 0x65, 0xa4, 0xff },   /* sky blue */
+  { 0x72, 0x9f, 0xcf, 0xff },   /* sky blue light */
+  { 0x20, 0x4a, 0x87, 0xff },   /* sky blue dark */
+  { 0x75, 0x50, 0x7b, 0xff },   /* plum */
+  { 0xad, 0x7f, 0xa8, 0xff },   /* plum light */
+  { 0x5c, 0x35, 0x66, 0xff },   /* plum dark */
+  { 0xcc, 0x00, 0x00, 0xff },   /* scarlet red */
+  { 0xef, 0x29, 0x29, 0xff },   /* scarlet red light */
+  { 0xa4, 0x00, 0x00, 0xff },   /* scarlet red dark */
+  { 0xee, 0xee, 0xec, 0xff },   /* aluminium 1 */
+  { 0xd3, 0xd7, 0xcf, 0xff },   /* aluminium 2 */
+  { 0xba, 0xbd, 0xb6, 0xff },   /* aluminium 3 */
+  { 0x88, 0x8a, 0x85, 0xff },   /* aluminium 4 */
+  { 0x55, 0x57, 0x53, 0xff },   /* aluminium 5 */
+  { 0x2e, 0x34, 0x36, 0xff },   /* aluminium 6 */
+
+  /* last color */
+  { 0x00, 0x00, 0x00, 0x00 }    /* transparent */
+};
+
+/**
+ * clutter_color_get_static:
+ * @color: the named global color
+ *
+ * Retrieves a static color for the given @color name
+ *
+ * Static colors are created by Clutter and are guaranteed to always be
+ * available and valid
+ *
+ * Return value: a pointer to a static color; the returned pointer
+ *   is owned by Clutter and it should never be modified or freed
+ *
+ * Since: 1.6
+ */
+const ClutterColor *
+clutter_color_get_static (ClutterStaticColor color)
+{
+  g_return_val_if_fail (color >= CLUTTER_COLOR_WHITE &&
+                        color <= CLUTTER_COLOR_TRANSPARENT, NULL);
+
+  return &static_colors[color];
+}
+
 /**
  * clutter_color_add:
- * @src1: a #ClutterColor
- * @src2: a #ClutterColor
- * @dest: return location for the result
+ * @a: a #ClutterColor
+ * @b: a #ClutterColor
+ * @result: (out caller-allocates): return location for the result
  *
- * Adds @src2 to @src1 and saves the resulting color
- * inside @dest.
+ * Adds @a to @b and saves the resulting color inside @result.
  *
- * The alpha channel of @dest is as the maximum value
- * between the alpha channels of @src1 and @src2.
+ * The alpha channel of @result is set as as the maximum value
+ * between the alpha channels of @a and @b.
  */
 void
-clutter_color_add (const ClutterColor *src1,
-                  const ClutterColor *src2,
-                  ClutterColor       *dest)
+clutter_color_add (const ClutterColor *a,
+                  const ClutterColor *b,
+                  ClutterColor       *result)
 {
-  g_return_if_fail (src1 != NULL);
-  g_return_if_fail (src2 != NULL);
-  g_return_if_fail (dest != NULL);
+  g_return_if_fail (a != NULL);
+  g_return_if_fail (b != NULL);
+  g_return_if_fail (result != NULL);
 
-  dest->red   = CLAMP (src1->red   + src2->red,   0, 255);
-  dest->green = CLAMP (src1->green + src2->green, 0, 255);
-  dest->blue  = CLAMP (src1->blue  + src2->blue,  0, 255);
+  result->red   = CLAMP (a->red   + b->red,   0, 255);
+  result->green = CLAMP (a->green + b->green, 0, 255);
+  result->blue  = CLAMP (a->blue  + b->blue,  0, 255);
 
-  dest->alpha = MAX (src1->alpha, src2->alpha);
+  result->alpha = MAX (a->alpha, b->alpha);
 }
 
 /**
  * clutter_color_subtract:
- * @src1: a #ClutterColor
- * @src2: a #ClutterColor
- * @dest: return location for the result
+ * @a: a #ClutterColor
+ * @b: a #ClutterColor
+ * @result: (out caller-allocates): return location for the result
  *
- * Subtracts @src2 from @src1 and saves the resulting
- * color inside @dest. This function assumes that the components
- * of @src1 are greater than the components of @src2; the result is,
- * otherwise, undefined.
+ * Subtracts @b from @a and saves the resulting color inside @result.
  *
- * The alpha channel of @dest is set as the minimum value
- * between the alpha channels of @src1 and @src2.
+ * This function assumes that the components of @a are greater than the
+ * components of @b; the result is, otherwise, undefined.
+ *
+ * The alpha channel of @result is set as the minimum value
+ * between the alpha channels of @a and @b.
  */
 void
-clutter_color_subtract (const ClutterColor *src1,
-                       const ClutterColor *src2,
-                       ClutterColor       *dest)
+clutter_color_subtract (const ClutterColor *a,
+                       const ClutterColor *b,
+                       ClutterColor       *result)
 {
-  g_return_if_fail (src1 != NULL);
-  g_return_if_fail (src2 != NULL);
-  g_return_if_fail (dest != NULL);
+  g_return_if_fail (a != NULL);
+  g_return_if_fail (b != NULL);
+  g_return_if_fail (result != NULL);
 
-  dest->red   = CLAMP (src1->red   - src2->red,   0, 255);
-  dest->green = CLAMP (src1->green - src2->green, 0, 255);
-  dest->blue  = CLAMP (src1->blue  - src2->blue,  0, 255);
+  result->red   = CLAMP (a->red   - b->red,   0, 255);
+  result->green = CLAMP (a->green - b->green, 0, 255);
+  result->blue  = CLAMP (a->blue  - b->blue,  0, 255);
 
-  dest->alpha = MIN (src1->alpha, src2->alpha);
+  result->alpha = MIN (a->alpha, b->alpha);
 }
 
 /**
  * clutter_color_lighten:
- * @src: a #ClutterColor
- * @dest: return location for the lighter color
+ * @color: a #ClutterColor
+ * @result: (out caller-allocates): return location for the lighter color
  *
- * Lightens @src by a fixed amount, and saves the changed
- * color in @dest.
+ * Lightens @color by a fixed amount, and saves the changed color
+ * in @result.
  */
 void
-clutter_color_lighten (const ClutterColor *src,
-                      ClutterColor       *dest)
+clutter_color_lighten (const ClutterColor *color,
+                      ClutterColor       *result)
 {
-  /* 0x14ccd is ClutterFixed for 1.3 */
-  clutter_color_shadex (src, dest, 0x14ccd);
+  clutter_color_shade (color, 1.3, result);
 }
 
 /**
  * clutter_color_darken:
- * @src: a #ClutterColor
- * @dest: return location for the darker color
+ * @color: a #ClutterColor
+ * @result: (out caller-allocates): return location for the darker color
  *
- * Darkens @src by a fixed amount, and saves the changed color
- * in @dest.
+ * Darkens @color by a fixed amount, and saves the changed color
+ * in @result.
  */
 void
-clutter_color_darken (const ClutterColor *src,
-                     ClutterColor       *dest)
+clutter_color_darken (const ClutterColor *color,
+                     ClutterColor       *result)
 {
-  /* 0xb333 is ClutterFixed for 0.7 */
-  clutter_color_shadex (src, dest, 0xb333);
+  clutter_color_shade (color, 0.7, result);
 }
 
 /**
- * clutter_color_to_hlsx:
- * @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. Returned hue is in degrees (0 .. 360),
- * luminance and saturation from interval <0 .. 1>.
+ * clutter_color_to_hls:
+ * @color: a #ClutterColor
+ * @hue: (out): return location for the hue value or %NULL
+ * @luminance: (out): return location for the luminance value or %NULL
+ * @saturation: (out): return location for the saturation value or %NULL
+ *
+ * Converts @color to the HLS format.
+ *
+ * The @hue value is in the 0 .. 360 range. The @luminance and
+ * @saturation values are in the 0 .. 1 range.
  */
 void
-clutter_color_to_hlsx (const ClutterColor *src,
-                      ClutterFixed       *hue,
-                      ClutterFixed       *luminance,
-                      ClutterFixed       *saturation)
-{
-  ClutterFixed red, green, blue;
-  ClutterFixed min, max, delta;
-  ClutterFixed h, l, s;
+clutter_color_to_hls (const ClutterColor *color,
+                     float              *hue,
+                     float              *luminance,
+                     float              *saturation)
+{
+  float red, green, blue;
+  float min, max, delta;
+  float h, l, s;
   
-  g_return_if_fail (src != NULL);
+  g_return_if_fail (color != NULL);
 
-  red   = CLUTTER_INT_TO_FIXED (src->red)   / 255;
-  green = CLUTTER_INT_TO_FIXED (src->green) / 255;
-  blue  = CLUTTER_INT_TO_FIXED (src->blue)  / 255;
+  red   = color->red / 255.0;
+  green = color->green / 255.0;
+  blue  = color->blue / 255.0;
 
   if (red > green)
     {
@@ -189,22 +270,24 @@ clutter_color_to_hlsx (const ClutterColor *src,
 
   if (max != min)
     {
-      if (l <= CFX_ONE/2)
-       s = CFX_DIV ((max - min), (max + min));
+      if (l <= 0.5)
+       s = (max - min) / (max + min);
       else
-       s = CFX_DIV ((max - min), (CLUTTER_INT_TO_FIXED (2) - max - min));
+       s = (max - min) / (2.0 - max - min);
 
       delta = max - min;
+
       if (red == max)
-       h = CFX_DIV ((green - blue), delta);
+       h = (green - blue) / delta;
       else if (green == max)
-       h = CLUTTER_INT_TO_FIXED (2) + CFX_DIV ((blue - red), delta);
+       h = 2.0 + (blue - red) / delta;
       else if (blue == max)
-       h = CLUTTER_INT_TO_FIXED (4) + CFX_DIV ((red - green), delta);
+       h = 4.0 + (red - green) / delta;
 
       h *= 60;
+
       if (h < 0)
-       h += CLUTTER_INT_TO_FIXED (360);
+       h += 360.0;
     }
 
   if (hue)
@@ -218,309 +301,498 @@ clutter_color_to_hlsx (const ClutterColor *src,
 }
 
 /**
- * clutter_color_from_hlsx:
- * @dest: return location for a #ClutterColor
- * @hue: hue value (0 .. 360)
- * @luminance: luminance value (0 .. 1)
- * @saturation: saturation value (0 .. 1)
+ * clutter_color_from_hls:
+ * @color: (out): return location for a #ClutterColor
+ * @hue: hue value, in the 0 .. 360 range
+ * @luminance: luminance value, in the 0 .. 1 range
+ * @saturation: saturation value, in the 0 .. 1 range
  *
  * Converts a color expressed in HLS (hue, luminance and saturation)
  * values into a #ClutterColor.
  */
-
 void
-clutter_color_from_hlsx (ClutterColor *dest,
-                        ClutterFixed   hue,
-                        ClutterFixed   luminance,
-                        ClutterFixed   saturation)
+clutter_color_from_hls (ClutterColor *color,
+                       float         hue,
+                       float         luminance,
+                       float         saturation)
 {
-  ClutterFixed h, l, s;
-  ClutterFixed m1, m2;
-  
-  g_return_if_fail (dest != NULL);
+  float tmp1, tmp2;
+  float tmp3[3];
+  float clr[3];
+  int   i;
 
-  l = luminance;
-  s = saturation;
+  hue /= 360.0;
 
-  if (l <= CFX_ONE/2)
-    m2 = CFX_MUL (l, (CFX_ONE + s));
-  else
-    m2 = l + s - CFX_MUL (l,s);
-
-  m1 = 2 * l - m2;
-
-  if (s == 0)
+  if (saturation == 0)
     {
-      dest->red   = (guint8) CFX_INT (l * 255);
-      dest->green = (guint8) CFX_INT (l * 255);
-      dest->blue  = (guint8) CFX_INT (l * 255);
-    }
-  else
-    {
-      h = hue + CFX_120;
-      while (h > CFX_360)
-       h -= CFX_360;
-      while (h < 0)
-       h += CFX_360;
-
-      if (h < CFX_60)
-       dest->red = (guint8) CFX_INT((m1 + CFX_MUL((m2-m1), h) / 60) * 255);
-      else if (h < CFX_180)
-       dest->red = (guint8) CFX_INT (m2 * 255);
-      else if (h < CFX_240)
-       dest->red = (guint8)CFX_INT((m1+CFX_MUL((m2-m1),(CFX_240-h))/60)*255);
-      else
-       dest->red = (guint8) CFX_INT (m1 * 255);
-
-      h = hue;
-      while (h > CFX_360)
-       h -= CFX_360;
-      while (h < 0)
-       h += CFX_360;
-
-      if (h < CFX_60)
-       dest->green = (guint8)CFX_INT((m1 + CFX_MUL((m2 - m1), h) / 60) * 255);
-      else if (h < CFX_180)
-        dest->green = (guint8) CFX_INT (m2 * 255);
-      else if (h < CFX_240)
-       dest->green =
-           (guint8) CFX_INT((m1 + CFX_MUL ((m2-m1), (CFX_240-h)) / 60) * 255);
-      else
-       dest->green = (guint8) CFX_INT (m1 * 255);
-
-      h = hue - CFX_120;
-      while (h > CFX_360)
-       h -= CFX_360;
-      while (h < 0)
-       h += CFX_360;
-
-      if (h < CFX_60)
-       dest->blue = (guint8) CFX_INT ((m1 + CFX_MUL ((m2-m1), h) / 60) * 255);
-      else if (h < CFX_180)
-       dest->blue = (guint8) CFX_INT (m2 * 255);
-      else if (h < CFX_240)
-       dest->blue = (guint8)CFX_INT((m1+CFX_MUL((m2-m1),(CFX_240-h))/60)*255);
-      else
-       dest->blue = (guint8) CFX_INT(m1 * 255);
-    }
-}
-
-/**
- * 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. Returned HLS values are from interval
- * 0 .. 255.
- */
-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;
+      color->red = color->green = color->blue = (luminance * 255);
 
-  if (luminance)
-    *luminance = (guint8) CFX_INT (l * 255);
+      return;
+    }
 
-  if (saturation)
-    *saturation = (guint8) CFX_INT (s * 255);
-}
+  if (luminance <= 0.5)
+    tmp2 = luminance * (1.0 + saturation);
+  else
+    tmp2 = luminance + saturation - (luminance * saturation);
 
-/**
- * clutter_color_from_hls:
- * @dest: return location for a #ClutterColor
- * @hue: hue value (0 .. 255)
- * @luminance: luminance value (0 .. 255)
- * @saturation: saturation value (0 .. 255)
- *
- * Converts a color expressed in HLS (hue, luminance and saturation)
- * values into a #ClutterColor.
- */
+  tmp1 = 2.0 * luminance - tmp2;
 
-void
-clutter_color_from_hls (ClutterColor *dest,
-                       guint8        hue,
-                       guint8        luminance,
-                       guint8        saturation)
-{
-  ClutterFixed h, l, s;
+  tmp3[0] = hue + 1.0 / 3.0;
+  tmp3[1] = hue;
+  tmp3[2] = hue - 1.0 / 3.0;
 
-  h = CLUTTER_INT_TO_FIXED (hue * 360) / 255;
-  l = CLUTTER_INT_TO_FIXED (luminance)  / 255;
-  s = CLUTTER_INT_TO_FIXED (saturation) / 255;
+  for (i = 0; i < 3; i++)
+    {
+      if (tmp3[i] < 0)
+        tmp3[i] += 1.0;
+
+      if (tmp3[i] > 1)
+        tmp3[i] -= 1.0;
+
+      if (6.0 * tmp3[i] < 1.0)
+        clr[i] = tmp1 + (tmp2 - tmp1) * tmp3[i] * 6.0;
+      else if (2.0 * tmp3[i] < 1.0)
+        clr[i] = tmp2;
+      else if (3.0 * tmp3[i] < 2.0)
+        clr[i] = (tmp1 + (tmp2 - tmp1) * ((2.0 / 3.0) - tmp3[i]) * 6.0);
+      else
+        clr[i] = tmp1;
+    }
 
-  clutter_color_from_hlsx (dest, h, l, s);
+  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);
 }
 
 /**
  * clutter_color_shade:
- * @src: a #ClutterColor
- * @dest: return location for the shaded color
- * @shade: the shade factor to apply
- * 
- * Shades @src by the factor of @shade and saves the modified
- * color into @dest.
- */
-void
-clutter_color_shade (const ClutterColor *src,
-                    ClutterColor       *dest,
-                    gdouble             shade)
-{
-  clutter_color_shadex (src, dest, CLUTTER_FLOAT_TO_FIXED (shade));
-}
-
-/**
- * clutter_color_shadex:
- * @src: a #ClutterColor
- * @dest: return location for the shaded color
- * @shade: #ClutterFixed the shade factor to apply
- * 
- * Fixed point version of clutter_color_shade().
- *
- * Shades @src by the factor of @shade and saves the modified
- * color into @dest.
+ * @color: a #ClutterColor
+ * @factor: the shade factor to apply
+ * @result: (out caller-allocates): return location for the shaded color
  *
- * Since: 0.2
+ * Shades @color by @factor and saves the modified color into @result.
  */
 void
-clutter_color_shadex (const ClutterColor *src,
-                     ClutterColor       *dest,
-                     ClutterFixed        shade)
+clutter_color_shade (const ClutterColor *color,
+                     gdouble             factor,
+                     ClutterColor       *result)
 {
-  ClutterFixed h, l, s;
+  float h, l, s;
 
-  g_return_if_fail (src != NULL);
-  g_return_if_fail (dest != NULL);
+  g_return_if_fail (color != NULL);
+  g_return_if_fail (result != NULL);
   
-  clutter_color_to_hlsx (src, &h, &l, &s);
+  clutter_color_to_hls (color, &h, &l, &s);
 
-  l = CFX_MUL (l, shade);
-  if (l > CFX_ONE)
-    l = CFX_ONE;
+  l *= factor;
+  if (l > 1.0)
+    l = 1.0;
   else if (l < 0)
     l = 0;
 
-  s = CFX_MUL (s, shade);
-  if (s > CFX_ONE)
-    s = CFX_ONE;
+  s *= factor;
+  if (s > 1.0)
+    s = 1.0;
   else if (s < 0)
     s = 0;
   
-  clutter_color_from_hlsx (dest, h, l, s);
-  dest->alpha = src->alpha;
+  clutter_color_from_hls (result, h, l, s);
+
+  result->alpha = color->alpha;
 }
 
 /**
  * clutter_color_to_pixel:
- * @src: a #ClutterColor
+ * @color: a #ClutterColor
  *
- * Converts @src into a packed 32 bit integer, containing
+ * Converts @color into a packed 32 bit integer, containing
  * all the four 8 bit channels used by #ClutterColor.
  *
  * Return value: a packed color
  */
 guint32
-clutter_color_to_pixel (const ClutterColor *src)
+clutter_color_to_pixel (const ClutterColor *color)
 {
-  g_return_val_if_fail (src != NULL, 0);
+  g_return_val_if_fail (color != NULL, 0);
   
-  return (src->alpha | src->blue << 8 | src->green << 16  | src->red << 24);
+  return (color->alpha       |
+          color->blue  << 8  |
+          color->green << 16 |
+          color->red   << 24);
 }
 
 /**
  * clutter_color_from_pixel:
- * @dest: return location for a #ClutterColor
+ * @color: (out caller-allocates): return location for a #ClutterColor
  * @pixel: a 32 bit packed integer containing a color
  *
  * Converts @pixel from the packed representation of a four 8 bit channel
  * color to a #ClutterColor.
  */
 void
-clutter_color_from_pixel (ClutterColor *dest,
+clutter_color_from_pixel (ClutterColor *color,
                          guint32       pixel)
 {
-  g_return_if_fail (dest != NULL);
+  g_return_if_fail (color != NULL);
 
-  dest->red = pixel >> 24;
-  dest->green = (pixel >> 16) & 0xff;
-  dest->blue = (pixel >> 8) & 0xff;
-  dest->alpha = pixel & 0xff;
+  color->red   =  pixel >> 24;
+  color->green = (pixel >> 16) & 0xff;
+  color->blue  = (pixel >> 8)  & 0xff;
+  color->alpha =  pixel        & 0xff;
+}
+
+static inline void
+skip_whitespace (gchar **str)
+{
+  while (g_ascii_isspace (**str))
+    *str += 1;
+}
+
+static inline void
+parse_rgb_value (gchar   *str,
+                 guint8  *color,
+                 gchar  **endp)
+{
+  gdouble number;
+  gchar *p;
+
+  skip_whitespace (&str);
+
+  number = g_ascii_strtod (str, endp);
+
+  p = *endp;
+
+  skip_whitespace (&p);
+
+  if (*p == '%')
+    {
+      *endp = (gchar *) (p + 1);
+
+      *color = CLAMP (number / 100.0, 0.0, 1.0) * 255;
+    }
+  else
+    *color = CLAMP (number, 0, 255);
+}
+
+static gboolean
+parse_rgba (ClutterColor *color,
+            gchar        *str,
+            gboolean      has_alpha)
+{
+  skip_whitespace (&str);
+
+  if (*str != '(')
+    return FALSE;
+
+  str += 1;
+
+  /* red */
+  parse_rgb_value (str, &color->red, &str);
+  skip_whitespace (&str);
+  if (*str != ',')
+    return FALSE;
+
+  str += 1;
+
+  /* green */
+  parse_rgb_value (str, &color->green, &str);
+  skip_whitespace (&str);
+  if (*str != ',')
+    return FALSE;
+
+  str += 1;
+
+  /* blue */
+  parse_rgb_value (str, &color->blue, &str);
+  skip_whitespace (&str);
+
+  /* alpha (optional); since the alpha channel value can only
+   * be between 0 and 1 we don't use the parse_rgb_value()
+   * function
+   */
+  if (has_alpha)
+    {
+      gdouble number;
+
+      if (*str != ',')
+        return FALSE;
+
+      str += 1;
+
+      skip_whitespace (&str);
+      number = g_ascii_strtod (str, &str);
+
+      color->alpha = CLAMP (number * 255.0, 0, 255);
+    }
+  else
+    color->alpha = 255;
+
+  skip_whitespace (&str);
+  if (*str != ')')
+    return FALSE;
+
+  return TRUE;
+}
+
+static gboolean
+parse_hsla (ClutterColor *color,
+            gchar        *str,
+            gboolean      has_alpha)
+{
+  gdouble number;
+  gdouble h, l, s;
+
+  skip_whitespace (&str);
+
+  if (*str != '(')
+    return FALSE;
+
+  str += 1;
+
+  /* hue */
+  skip_whitespace (&str);
+  /* we don't do any angle normalization here because
+   * clutter_color_from_hls() will do it for us
+   */
+  number = g_ascii_strtod (str, &str);
+  skip_whitespace (&str);
+  if (*str != ',')
+    return FALSE;
+
+  h = number;
+
+  str += 1;
+
+  /* saturation */
+  skip_whitespace (&str);
+  number = g_ascii_strtod (str, &str);
+  skip_whitespace (&str);
+  if (*str != '%')
+    return FALSE;
+
+  str += 1;
+
+  s = CLAMP (number / 100.0, 0.0, 1.0);
+  skip_whitespace (&str);
+  if (*str != ',')
+    return FALSE;
+
+  str += 1;
+
+  /* luminance */
+  skip_whitespace (&str);
+  number = g_ascii_strtod (str, &str);
+  skip_whitespace (&str);
+  if (*str != '%')
+    return FALSE;
+
+  str += 1;
+
+  l = CLAMP (number / 100.0, 0.0, 1.0);
+  skip_whitespace (&str);
+
+  /* alpha (optional); since the alpha channel value can only
+   * be between 0 and 1 we don't use the parse_rgb_value()
+   * function
+   */
+  if (has_alpha)
+    {
+      if (*str != ',')
+        return FALSE;
+
+      str += 1;
+
+      skip_whitespace (&str);
+      number = g_ascii_strtod (str, &str);
+
+      color->alpha = CLAMP (number * 255.0, 0, 255);
+    }
+  else
+    color->alpha = 255;
+
+  skip_whitespace (&str);
+  if (*str != ')')
+    return FALSE;
+
+  clutter_color_from_hls (color, h, l, s);
+
+  return TRUE;
 }
 
 /**
- * clutter_color_parse:
- * @color: a string specifiying a color (named color or #RRGGBBAA)
- * @dest: return location for a #ClutterColor
+ * clutter_color_from_string:
+ * @color: (out caller-allocates): return location for a #ClutterColor
+ * @str: a string specifiying a color
  *
  * Parses a string definition of a color, filling the
  * <structfield>red</structfield>, <structfield>green</structfield>, 
  * <structfield>blue</structfield> and <structfield>alpha</structfield> 
- * channels of @dest. If alpha is not specified it will be set full opaque.
- * The color in @dest is not allocated.
+ * channels of @color.
  *
- * The color may be defined by any of the formats understood by
- * <function>pango_color_parse</function>; these include literal color
- * names, like <literal>Red</literal> or <literal>DarkSlateGray</literal>,
- * or hexadecimal specifications like <literal>&num;3050b2</literal> or
- * <literal>&num;333</literal>.
+ * The @color is not allocated.
  *
- * Return value: %TRUE if parsing succeeded.
+ * The format of @str can be either one of:
  *
- * Since: 0.2
+ * <itemizedlist>
+ * <listitem>
+ *   <para>a standard name (as taken from the X11 rgb.txt file)</para>
+ * </listitem>
+ * <listitem>
+ *   <para>an hexadecimal value in the form: <literal>&num;rgb</literal>,
+ *   <literal>&num;rrggbb</literal>, <literal>&num;rgba</literal> or
+ *   <literal>&num;rrggbbaa</literal></para>
+ * </listitem>
+ * <listitem>
+ *   <para>a RGB color in the form: <literal>rgb(r, g, b)</literal></para>
+ * </listitem>
+ * <listitem>
+ *   <para>a RGB color in the form: <literal>rgba(r, g, b, a)</literal></para>
+ * </listitem>
+ * <listitem>
+ *   <para>a HSL color in the form: <literal>hsl(h, s, l)</literal></para>
+ * </listitem>
+ * <listitem>
+ *   <para>a HSL color in the form: <literal>hsla(h, s, l, a)</literal></para>
+ * </listitem>
+ * </itemizedlist>
+ *
+ * where 'r', 'g', 'b' and 'a' are (respectively) the red, green, blue color
+ * intensities and the opacity. The 'h', 's' and 'l' are (respectively) the
+ * hue, saturation and luminance values.
+ *
+ * In the rgb() and rgba() formats, the 'r', 'g', and 'b' values are either
+ * integers between 0 and 255, or percentage values in the range between 0%
+ * and 100%; the percentages require the '%' character. The 'a' value, if
+ * specified, can only be a floating point value between 0.0 and 1.0.
+ *
+ * In the hls() and hlsa() formats, the 'h' value (hue) it's an angle between
+ * 0 and 360.0 degrees; the 'l' and 's' values (luminance and saturation) are
+ * a floating point value between 0.0 and 1.0. The 'a' value, if specified,
+ * can only be a floating point value between 0.0 and 1.0.
+ *
+ * Whitespace inside the definitions is ignored; no leading whitespace
+ * is allowed.
+ *
+ * If the alpha component is not specified then it is assumed to be set to
+ * be fully opaque.
+ *
+ * Return value: %TRUE if parsing succeeded, and %FALSE otherwise
+ *
+ * Since: 1.0
  */
 gboolean
-clutter_color_parse (const gchar  *color,
-                     ClutterColor *dest)
+clutter_color_from_string (ClutterColor *color,
+                           const gchar  *str)
 {
-  PangoColor pango_color;
+  PangoColor pango_color = { 0, };
 
   g_return_val_if_fail (color != NULL, FALSE);
-  g_return_val_if_fail (dest != NULL, FALSE);
+  g_return_val_if_fail (str != NULL, FALSE);
+
+  if (strncmp (str, "rgb", 3) == 0)
+    {
+      gchar *s = (gchar *) str;
+      gboolean res;
+
+      if (strncmp (str, "rgba", 4) == 0)
+        res = parse_rgba (color, s + 4, TRUE);
+      else
+        res = parse_rgba (color, s + 3, FALSE);
+
+      return res;
+    }
 
-  /* parse ourselves to get alpha */
-  if (color[0] == '#')
+  if (strncmp (str, "hsl", 3) == 0)
     {
+      gchar *s = (gchar *) str;
+      gboolean res;
+
+      if (strncmp (str, "hsla", 4) == 0)
+        res = parse_hsla (color, s + 4, TRUE);
+      else
+        res = parse_hsla (color, s + 3, FALSE);
+
+      return res;
+    }
+
+  /* if the string contains a color encoded using the hexadecimal
+   * notations (#rrggbbaa or #rgba) we attempt a rough pass at
+   * parsing the color ourselves, as we need the alpha channel that
+   * Pango can't retrieve.
+   */
+  if (str[0] == '#' && str[1] != '\0')
+    {
+      gsize length = strlen (str + 1);
       gint32 result;
 
-      if (sscanf (color + 1, "%x", &result))
-       {
-         if (strlen (color) == 9)
-           {
-             dest->red   = (result >> 24) & 0xff;
-             dest->green = (result >> 16) & 0xff;
-             dest->blue  = (result >>  8) & 0xff;
-             dest->alpha = result & 0xff;
-
-             return TRUE;
-           }
-         else if (strlen (color) == 7)
-           {
-             dest->red   = (result >> 16) & 0xff;
-             dest->green = (result >>  8) & 0xff;
-             dest->blue  = result & 0xff;
-             dest->alpha = 0xff;
-
-             return TRUE;
-           }
-       }
+      if (sscanf (str + 1, "%x", &result) == 1)
+        {
+          switch (length)
+            {
+            case 8: /* rrggbbaa */
+              color->red   = (result >> 24) & 0xff;
+              color->green = (result >> 16) & 0xff;
+              color->blue  = (result >>  8) & 0xff;
+
+              color->alpha = result & 0xff;
+
+              return TRUE;
+
+            case 6: /* #rrggbb */
+              color->red   = (result >> 16) & 0xff;
+              color->green = (result >>  8) & 0xff;
+              color->blue  = result & 0xff;
+
+              color->alpha = 0xff;
+
+              return TRUE;
+
+            case 4: /* #rgba */
+              color->red   = ((result >> 12) & 0xf);
+              color->green = ((result >>  8) & 0xf);
+              color->blue  = ((result >>  4) & 0xf);
+              color->alpha = result & 0xf;
+
+              color->red   = (color->red   << 4) | color->red;
+              color->green = (color->green << 4) | color->green;
+              color->blue  = (color->blue  << 4) | color->blue;
+              color->alpha = (color->alpha << 4) | color->alpha;
+
+              return TRUE;
+
+            case 3: /* #rgb */
+              color->red   = ((result >>  8) & 0xf);
+              color->green = ((result >>  4) & 0xf);
+              color->blue  = result & 0xf;
+
+              color->red   = (color->red   << 4) | color->red;
+              color->green = (color->green << 4) | color->green;
+              color->blue  = (color->blue  << 4) | color->blue;
+
+              color->alpha = 0xff;
+
+              return TRUE;
+
+            default:
+              return FALSE;
+            }
+        }
     }
-  
-  /* Fall back to pango for named colors - note pango does not handle alpha */
-  if (pango_color_parse (&pango_color, color))
+
+  /* fall back to pango for X11-style named colors; see:
+   *
+   *   http://en.wikipedia.org/wiki/X11_color_names
+   *
+   * for a list. at some point we might even ship with our own list generated
+   * from X11/rgb.txt, like we generate the key symbols.
+   */
+  if (pango_color_parse (&pango_color, str))
     {
-      dest->red   = pango_color.red;
-      dest->green = pango_color.green;
-      dest->blue  = pango_color.blue;
-      dest->alpha = 0xff;
+      color->red   = pango_color.red;
+      color->green = pango_color.green;
+      color->blue  = pango_color.blue;
+
+      color->alpha = 0xff;
 
       return TRUE;
     }
@@ -535,10 +807,10 @@ clutter_color_parse (const gchar  *color,
  * Returns a textual specification of @color in the hexadecimal form
  * <literal>&num;rrggbbaa</literal>, where <literal>r</literal>,
  * <literal>g</literal>, <literal>b</literal> and <literal>a</literal> are
- * hex digits representing the red, green, blue and alpha components
+ * hexadecimal digits representing the red, green, blue and alpha components
  * respectively.
  *
- * Return value: a newly-allocated text string
+ * Return value: (transfer full): a newly-allocated text string
  *
  * Since: 0.2
  */
@@ -556,53 +828,120 @@ clutter_color_to_string (const ClutterColor *color)
 
 /**
  * clutter_color_equal:
- * @a: a #ClutterColor
- * @b: a #ClutterColor
+ * @v1: a #ClutterColor
+ * @v2: a #ClutterColor
  *
  * Compares two #ClutterColor<!-- -->s and checks if they are the same.
  *
+ * This function can be passed to g_hash_table_new() as the @key_equal_func
+ * parameter, when using #ClutterColor<!-- -->s as keys in a #GHashTable.
+ *
  * Return value: %TRUE if the two colors are the same.
  *
  * Since: 0.2
  */
 gboolean
-clutter_color_equal (const ClutterColor *a,
-                     const ClutterColor *b)
+clutter_color_equal (gconstpointer v1,
+                     gconstpointer v2)
 {
-  g_return_val_if_fail (a != NULL, FALSE);
-  g_return_val_if_fail (b != NULL, FALSE);
+  const ClutterColor *a, *b;
 
-  if (a == b)
+  g_return_val_if_fail (v1 != NULL, FALSE);
+  g_return_val_if_fail (v2 != NULL, FALSE);
+
+  if (v1 == v2)
     return TRUE;
 
-  return (a->red == b->red &&
+  a = v1;
+  b = v2;
+
+  return (a->red   == b->red   &&
           a->green == b->green &&
-          a->blue == b->blue &&
+          a->blue  == b->blue  &&
           a->alpha == b->alpha);
 }
 
 /**
+ * clutter_color_hash:
+ * @v: a #ClutterColor
+ *
+ * Converts a #ClutterColor to a hash value.
+ *
+ * This function can be passed to g_hash_table_new() as the @hash_func
+ * parameter, when using #ClutterColor<!-- -->s as keys in a #GHashTable.
+ *
+ * Return value: a hash value corresponding to the color
+ *
+ * Since: 1.0
+ */
+guint
+clutter_color_hash (gconstpointer v)
+{
+  return clutter_color_to_pixel ((const ClutterColor *) v);
+}
+
+/**
+ * clutter_color_interpolate:
+ * @initial: the initial #ClutterColor
+ * @final: the final #ClutterColor
+ * @progress: the interpolation progress
+ * @result: (out): return location for the interpolation
+ *
+ * Interpolates between @initial and @final #ClutterColor<!-- -->s
+ * using @progress
+ *
+ * Since: 1.6
+ */
+void
+clutter_color_interpolate (const ClutterColor *initial,
+                           const ClutterColor *final,
+                           gdouble             progress,
+                           ClutterColor       *result)
+{
+  g_return_if_fail (initial != NULL);
+  g_return_if_fail (final != NULL);
+  g_return_if_fail (result != NULL);
+
+  result->red   = initial->red   + (final->red   - initial->red)   * progress;
+  result->green = initial->green + (final->green - initial->green) * progress;
+  result->blue  = initial->blue  + (final->blue  - initial->blue)  * progress;
+  result->alpha = initial->alpha + (final->alpha - initial->alpha) * progress;
+}
+
+static gboolean
+clutter_color_progress (const GValue *a,
+                        const GValue *b,
+                        gdouble       progress,
+                        GValue       *retval)
+{
+  const ClutterColor *a_color = clutter_value_get_color (a);
+  const ClutterColor *b_color = clutter_value_get_color (b);
+  ClutterColor res = { 0, };
+
+  clutter_color_interpolate (a_color, b_color, progress, &res);
+  clutter_value_set_color (retval, &res);
+
+  return TRUE;
+}
+
+/**
  * clutter_color_copy:
  * @color: a #ClutterColor
  *
  * Makes a copy of the color structure.  The result must be
  * freed using clutter_color_free().
  *
- * Return value: an allocated copy of @color.
+ * Return value: (transfer full): an allocated copy of @color.
  *
  * Since: 0.2
  */
 ClutterColor *
 clutter_color_copy (const ClutterColor *color)
 {
-  ClutterColor *result;
-  
-  g_return_val_if_fail (color != NULL, NULL);
+  if (G_LIKELY (color != NULL))
+    return g_slice_dup (ClutterColor, color);
 
-  result = g_slice_new (ClutterColor);
-  *result = *color;
-
-  return result;
+  return NULL;
 }
 
 /**
@@ -616,7 +955,7 @@ clutter_color_copy (const ClutterColor *color)
 void
 clutter_color_free (ClutterColor *color)
 {
-  if (G_LIKELY (color))
+  if (G_LIKELY (color != NULL))
     g_slice_free (ClutterColor, color);
 }
 
@@ -629,10 +968,16 @@ clutter_color_free (ClutterColor *color)
  *
  * Creates a new #ClutterColor with the given values.
  *
- * Return value: the newly allocated color. Use clutter_color_free()
- *   when done
+ * This function is the equivalent of:
  *
- * Since: 1.0
+ * |[
+ *   clutter_color_init (clutter_color_alloc (), red, green, blue, alpha);
+ * ]|
+ *
+ * Return value: (transfer full): the newly allocated color.
+ *   Use clutter_color_free() when done
+ *
+ * Since: 0.8.4
  */
 ClutterColor *
 clutter_color_new (guint8 red,
@@ -640,14 +985,56 @@ clutter_color_new (guint8 red,
                    guint8 blue,
                    guint8 alpha)
 {
-  ClutterColor *color;
+  return clutter_color_init (clutter_color_alloc (),
+                             red,
+                             green,
+                             blue,
+                             alpha);
+}
+
+/**
+ * clutter_color_alloc:
+ *
+ * Allocates a new, transparent black #ClutterColor.
+ *
+ * Return value: (transfer full): the newly allocated #ClutterColor; use
+ *   clutter_color_free() to free its resources
+ *
+ * Since: 1.12
+ */
+ClutterColor *
+clutter_color_alloc (void)
+{
+  return g_slice_new0 (ClutterColor);
+}
 
-  color = g_slice_new (ClutterColor);
+/**
+ * clutter_color_init:
+ * @color: a #ClutterColor
+ * @red: red component of the color, between 0 and 255
+ * @green: green component of the color, between 0 and 255
+ * @blue: blue component of the color, between 0 and 255
+ * @alpha: alpha component of the color, between 0 and 255
+ *
+ * Initializes @color with the given values.
+ *
+ * Return value: (transfer none): the initialized #ClutterColor
+ *
+ * Since: 1.12
+ */
+ClutterColor *
+clutter_color_init (ClutterColor *color,
+                    guint8        red,
+                    guint8        green,
+                    guint8        blue,
+                    guint8        alpha)
+{
+  g_return_val_if_fail (color != NULL, NULL);
 
-  color->red   = CLAMP (red,   0, 255);
-  color->green = CLAMP (green, 0, 255);
-  color->blue  = CLAMP (blue,  0, 255);
-  color->alpha = CLAMP (alpha, 0, 255);
+  color->red = red;
+  color->green = green;
+  color->blue = blue;
+  color->alpha = alpha;
 
   return color;
 }
@@ -656,119 +1043,43 @@ static void
 clutter_value_transform_color_string (const GValue *src,
                                       GValue       *dest)
 {
-  gchar *string = clutter_color_to_string (src->data[0].v_pointer);
+  const ClutterColor *color = g_value_get_boxed (src);
 
-  g_value_take_string (dest, string);
+  if (color)
+    {
+      gchar *string = clutter_color_to_string (color);
+
+      g_value_take_string (dest, string);
+    }
+  else
+    g_value_set_string (dest, NULL);
 }
 
 static void
 clutter_value_transform_string_color (const GValue *src,
                                       GValue       *dest)
 {
-  ClutterColor color = { 0, };
-
-  clutter_color_parse (g_value_get_string (src), &color);
+  const char *str = g_value_get_string (src);
 
-  clutter_value_set_color (dest, &color);
-}
-
-GType
-clutter_color_get_type (void)
-{
-  static GType _clutter_color_type = 0;
-  
-  if (G_UNLIKELY (_clutter_color_type == 0))
+  if (str)
     {
-       _clutter_color_type =
-         g_boxed_type_register_static (I_("ClutterColor"),
-                                       (GBoxedCopyFunc) clutter_color_copy,
-                                       (GBoxedFreeFunc) clutter_color_free);
-
-       g_value_register_transform_func (_clutter_color_type, G_TYPE_STRING,
-                                        clutter_value_transform_color_string);
-       g_value_register_transform_func (G_TYPE_STRING, _clutter_color_type,
-                                        clutter_value_transform_string_color);
-    }
+      ClutterColor color = { 0, };
 
-  return _clutter_color_type;
-}
+      clutter_color_from_string (&color, str);
 
-static void
-clutter_value_init_color (GValue *value)
-{
-  value->data[0].v_pointer = NULL;
-}
-
-static void
-clutter_value_free_color (GValue *value)
-{
-  if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
-    clutter_color_free (value->data[0].v_pointer);
-}
-
-static void
-clutter_value_copy_color (const GValue *src,
-                          GValue       *dest)
-{
-  dest->data[0].v_pointer = clutter_color_copy (src->data[0].v_pointer);
-}
-
-static gpointer
-clutter_value_peek_color (const GValue *value)
-{
-  return value->data[0].v_pointer;
-}
-
-static gchar *
-clutter_value_collect_color (GValue      *value,
-                             guint        n_collect_values,
-                             GTypeCValue *collect_values,
-                             guint        collect_flags)
-{
-  if (!collect_values[0].v_pointer)
-      value->data[0].v_pointer = NULL;
-  else
-    {
-      if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
-        {
-          value->data[0].v_pointer = collect_values[0].v_pointer;
-          value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
-        }
-      else
-        {
-          value->data[0].v_pointer =
-            clutter_color_copy (collect_values[0].v_pointer);
-        }
+      clutter_value_set_color (dest, &color);
     }
-
-  return NULL;
-}
-
-static gchar *
-clutter_value_lcopy_color (const GValue *value,
-                           guint         n_collect_values,
-                           GTypeCValue  *collect_values,
-                           guint         collect_flags)
-{
-  ClutterColor **color_p = collect_values[0].v_pointer;
-
-  if (!color_p)
-    return g_strdup_printf ("value location for `%s' passed as NULL",
-                            G_VALUE_TYPE_NAME (value));
-
-  if (!value->data[0].v_pointer)
-    *color_p = NULL;
   else
-    {
-      if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
-        *color_p = value->data[0].v_pointer;
-      else
-        *color_p = clutter_color_copy (value->data[0].v_pointer);
-    }
-
-  return NULL;
+    clutter_value_set_color (dest, NULL);
 }
 
+G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterColor, clutter_color,
+                               clutter_color_copy,
+                               clutter_color_free,
+                               CLUTTER_REGISTER_VALUE_TRANSFORM_TO (G_TYPE_STRING, clutter_value_transform_color_string)
+                               CLUTTER_REGISTER_VALUE_TRANSFORM_FROM (G_TYPE_STRING, clutter_value_transform_string_color)
+                               CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_color_progress));
+
 /**
  * clutter_value_set_color:
  * @value: a #GValue initialized to #CLUTTER_TYPE_COLOR
@@ -776,7 +1087,7 @@ clutter_value_lcopy_color (const GValue *value,
  *
  * Sets @value to @color.
  *
- * Since: 1.0
+ * Since: 0.8.4
  */
 void
 clutter_value_set_color (GValue             *value,
@@ -784,7 +1095,7 @@ clutter_value_set_color (GValue             *value,
 {
   g_return_if_fail (CLUTTER_VALUE_HOLDS_COLOR (value));
 
-  value->data[0].v_pointer = clutter_color_copy (color);
+  g_value_set_boxed (value, color);
 }
 
 /**
@@ -793,16 +1104,16 @@ clutter_value_set_color (GValue             *value,
  *
  * Gets the #ClutterColor contained in @value.
  *
- * Return value: the colors inside the passed #GValue
+ * Return value: (transfer none): the color inside the passed #GValue
  *
- * Since: 1.0
+ * Since: 0.8.4
  */
-G_CONST_RETURN ClutterColor *
+const ClutterColor *
 clutter_value_get_color (const GValue *value)
 {
   g_return_val_if_fail (CLUTTER_VALUE_HOLDS_COLOR (value), NULL);
 
-  return value->data[0].v_pointer;
+  return g_value_get_boxed (value);
 }
 
 static void
@@ -823,9 +1134,11 @@ param_color_finalize (GParamSpec *pspec)
 
 static void
 param_color_set_default (GParamSpec *pspec,
-                        GValue     *value)
+                         GValue     *value)
 {
-  value->data[0].v_pointer = CLUTTER_PARAM_SPEC_COLOR (pspec)->default_value;
+  const ClutterColor *default_value =
+    CLUTTER_PARAM_SPEC_COLOR (pspec)->default_value;
+  clutter_value_set_color (value, default_value);
 }
 
 static gint
@@ -833,30 +1146,24 @@ param_color_values_cmp (GParamSpec   *pspec,
                         const GValue *value1,
                         const GValue *value2)
 {
-  guint32 color1, color2;
+  const ClutterColor *color1 = g_value_get_boxed (value1);
+  const ClutterColor *color2 = g_value_get_boxed (value2);
+  int pixel1, pixel2;
 
-  color1 = clutter_color_to_pixel (value1->data[0].v_pointer);
-  color2 = clutter_color_to_pixel (value2->data[0].v_pointer);
+  if (color1 == NULL)
+    return color2 == NULL ? 0 : -1;
 
-  if (color1 < color2)
+  pixel1 = clutter_color_to_pixel (color1);
+  pixel2 = clutter_color_to_pixel (color2);
+
+  if (pixel1 < pixel2)
     return -1;
-  else if (color1 == color2)
+  else if (pixel1 == pixel2)
     return 0;
   else
     return 1;
 }
 
-static const GTypeValueTable _clutter_color_value_table = {
-  clutter_value_init_color,
-  clutter_value_free_color,
-  clutter_value_copy_color,
-  clutter_value_peek_color,
-  "p",
-  clutter_value_collect_color,
-  "p",
-  clutter_value_lcopy_color
-};
-
 GType
 clutter_param_color_get_type (void)
 {
@@ -883,7 +1190,7 @@ clutter_param_color_get_type (void)
 }
 
 /**
- * clutter_param_spec_color:
+ * clutter_param_spec_color: (skip)
  * @name: name of the property
  * @nick: short name
  * @blurb: description (can be translatable)
@@ -894,7 +1201,7 @@ clutter_param_color_get_type (void)
  *
  * Return value: the newly created #GParamSpec
  *
- * Since: 1.0
+ * Since: 0.8.4
  */
 GParamSpec *
 clutter_param_spec_color (const gchar        *name,