diff --git a/cogl/cogl-color.c b/cogl/cogl-color.c index a89534e49..544d874fc 100644 --- a/cogl/cogl-color.c +++ b/cogl/cogl-color.c @@ -163,6 +163,17 @@ cogl_color_premultiply (CoglColor *color) color->blue = (color->blue * color->alpha + 128) / 255; } +void +cogl_color_unpremultiply (CoglColor *color) +{ + if (color->alpha != 0) + { + color->red = (color->red * 255) / color->alpha; + color->green = (color->green * 255) / color->alpha; + color->blue = (color->blue * 255) / color->alpha; + } +} + gboolean cogl_color_equal (gconstpointer v1, gconstpointer v2) { diff --git a/cogl/cogl-color.h b/cogl/cogl-color.h index 8f3458bbf..1e1a14da7 100644 --- a/cogl/cogl-color.h +++ b/cogl/cogl-color.h @@ -299,6 +299,19 @@ cogl_color_get_alpha (const CoglColor *color); void cogl_color_premultiply (CoglColor *color); +/** + * cogl_color_unpremultiply: + * @color: the color to unpremultiply + * + * Converts a pre-multiplied color to a non-premultiplied color. For + * example, semi-transparent red is (0.5, 0, 0, 0.5) when premultiplied + * and (1.0, 0, 0, 0.5) when non-premultiplied. + * + * Since: 1.4 + */ +void +cogl_color_unpremultiply (CoglColor *color); + /** * cogl_color_equal: * @v1: a #CoglColor diff --git a/doc/reference/cogl/cogl-sections.txt b/doc/reference/cogl/cogl-sections.txt index af4685d2d..f23a7b1ea 100644 --- a/doc/reference/cogl/cogl-sections.txt +++ b/doc/reference/cogl/cogl-sections.txt @@ -384,6 +384,7 @@ cogl_color_get_alpha_float cogl_color_premultiply +cogl_color_unpremultiply cogl_color_equal