cogl-color: Add cogl_color_unpremultiply()

For some operations on pre-multiplied colors (say, replace the alpha
value), you need to unpremultiply the color.

This patch provides the counterpart to cogl_color_premultiply().
This commit is contained in:
Damien Lespiau 2010-06-06 22:57:02 +01:00 committed by Robert Bragg
parent 2ba6ab6dbc
commit 896dd975d1
3 changed files with 25 additions and 0 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -384,6 +384,7 @@ cogl_color_get_alpha_float
<SUBSECTION>
cogl_color_premultiply
cogl_color_unpremultiply
cogl_color_equal
</SECTION>