diff --git a/cogl-color.h b/cogl-color.h index 0cbc479a4..73de891de 100644 --- a/cogl-color.h +++ b/cogl-color.h @@ -228,6 +228,18 @@ float cogl_color_get_blue (const CoglColor *color); */ float cogl_color_get_alpha (const CoglColor *color); +/** + * cogl_color_premultiply: + * @color: the color to premultiply + * + * Converts a non-premultiplied color to a pre-multiplied color. For + * example, semi-transparent red is (1.0, 0, 0, 0.5) when non-premultiplied + * and (0.5, 0, 0, 0.5) when premultiplied. + * + * Since: 1.0 + */ +void cogl_color_premultiply (CoglColor *color); + G_END_DECLS #endif /* __COGL_COLOR_H__ */ diff --git a/common/cogl-color.c b/common/cogl-color.c index 306005f2f..df338fcc4 100644 --- a/common/cogl-color.c +++ b/common/cogl-color.c @@ -153,6 +153,14 @@ cogl_color_get_alpha (const CoglColor *color) return ((float) color->alpha / 255.0); } +void +cogl_color_premultiply (CoglColor *color) +{ + color->red = (color->red * color->alpha + 128) / 255; + color->green = (color->green * color->alpha + 128) / 255; + color->blue = (color->blue * color->alpha + 128) / 255; +} + void cogl_set_source_color4ub (guint8 red, guint8 green,