Add cogl_color_premultiply()
Add a convenience function to convert an ARGB color from non-premultiplied to premultiplied form. http://bugzilla.openedhand.com/show_bug.cgi?id=1406 Signed-off-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
parent
fd9d87bc3a
commit
dcc4f14169
2 changed files with 20 additions and 0 deletions
12
cogl-color.h
12
cogl-color.h
|
@ -228,6 +228,18 @@ float cogl_color_get_blue (const CoglColor *color);
|
||||||
*/
|
*/
|
||||||
float cogl_color_get_alpha (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
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __COGL_COLOR_H__ */
|
#endif /* __COGL_COLOR_H__ */
|
||||||
|
|
|
@ -153,6 +153,14 @@ cogl_color_get_alpha (const CoglColor *color)
|
||||||
return ((float) color->alpha / 255.0);
|
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
|
void
|
||||||
cogl_set_source_color4ub (guint8 red,
|
cogl_set_source_color4ub (guint8 red,
|
||||||
guint8 green,
|
guint8 green,
|
||||||
|
|
Loading…
Reference in a new issue