[color] Add support for the "#rgba" color format

clutter_color_from_string() only supported the "#rrggbbaa" format with
alpha channel, this patch adds support for "#rgba".

Colors in "#rrggbb" format were parsed manually, this is now left to
the pango color parsing fallback, since that's handling it just fine.

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
This commit is contained in:
Robert Staudinger 2009-06-01 18:54:46 +02:00 committed by Emmanuele Bassi
parent ffd5fb172b
commit bd13a4ddc4

View File

@ -398,7 +398,7 @@ clutter_color_from_string (ClutterColor *color,
g_return_val_if_fail (str != NULL, FALSE);
/* if the string contains a color encoded using the hexadecimal
* notations (#rrggbbaa or #rrggbb) we attempt a rough pass at
* 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.
*/
@ -419,24 +419,22 @@ clutter_color_from_string (ClutterColor *color,
return TRUE;
}
else if (strlen (str) == 7)
else if (strlen (str) == 5)
{
/* #rrggbb */
color->red = (result >> 16) & 0xff;
color->green = (result >> 8) & 0xff;
color->blue = result & 0xff;
/* #rgba */
color->red = ((result >> 12) & 0xf);
color->green = ((result >> 8) & 0xf);
color->blue = ((result >> 4) & 0xf);
color->alpha = result & 0xf;
color->alpha = 0xff;
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;
}
}
/* XXX - should we return FALSE here? it's not like
* Pango is endowed with mystical parsing powers and
* will be able to do better than the code above.
* still, it doesn't hurt
*/
}
/* Fall back to pango for named colors */