diff options
Diffstat (limited to 'src/gcompris/pixbuf_util.c')
-rw-r--r-- | src/gcompris/pixbuf_util.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/gcompris/pixbuf_util.c b/src/gcompris/pixbuf_util.c index 8b38a96..62cc6ca 100644 --- a/src/gcompris/pixbuf_util.c +++ b/src/gcompris/pixbuf_util.c @@ -83,3 +83,40 @@ GdkPixbuf *pixbuf_copy_mirror(GdkPixbuf *src, gint mirror, gint flip) return dest; } + + +/* Copyright 2006 Miguel DE IZARRA + * Base on function gdk_pixbuf_fill from gdk_pixbuf + */ +void pixbuf_add_transparent (GdkPixbuf *pixbuf,guint alpha) +{ + guchar *pixels; + guchar *p; + guint w, h; + + g_return_if_fail (GDK_IS_PIXBUF (pixbuf)); + g_return_if_fail(gdk_pixbuf_get_has_alpha(pixbuf)); + + if (gdk_pixbuf_get_width(pixbuf) == 0 || gdk_pixbuf_get_height(pixbuf) == 0) + return; + + pixels = gdk_pixbuf_get_pixels(pixbuf); + + h = gdk_pixbuf_get_height(pixbuf); + + while (h--) { + w = gdk_pixbuf_get_width(pixbuf); + p = pixels; + + while (w--) { + if(p[3] > alpha) + p[3] = p[3] - alpha; + else + p[3] = 0; + p += 4; + } + + pixels += gdk_pixbuf_get_rowstride(pixbuf); + } +} + |