mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 08:00:42 -05:00
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:
parent
2ba6ab6dbc
commit
896dd975d1
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -384,6 +384,7 @@ cogl_color_get_alpha_float
|
||||
|
||||
<SUBSECTION>
|
||||
cogl_color_premultiply
|
||||
cogl_color_unpremultiply
|
||||
cogl_color_equal
|
||||
</SECTION>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user