From 1f48e45e54d4f2c529f6af91a082caefa5457b94 Mon Sep 17 00:00:00 2001 From: Jonathan Blandford Date: Fri, 14 Jan 2000 20:59:18 +0000 Subject: [PATCH] new function to let you create a gdk_pixmap from a gdk_pixbuf. 2000-01-14 Jonathan Blandford * gdk-pixbuf/gdk-pixbuf-render.c (gdk_pixbuf_render_pixmap): new function to let you create a gdk_pixmap from a gdk_pixbuf. --- gdk-pixbuf/ChangeLog | 5 +++ gdk-pixbuf/gdk-pixbuf.h | 5 +++ gdk/gdkpixbuf-render.c | 67 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog index 05a687862c..fff8d86a9b 100644 --- a/gdk-pixbuf/ChangeLog +++ b/gdk-pixbuf/ChangeLog @@ -1,3 +1,8 @@ +2000-01-14 Jonathan Blandford + + * gdk-pixbuf/gdk-pixbuf-render.c (gdk_pixbuf_render_pixmap): new + function to let you create a gdk_pixmap from a gdk_pixbuf. + 2000-01-11 Jacob Berkman * gdk-pixbuf/pixops/Makefile.am (INCLUDES): added diff --git a/gdk-pixbuf/gdk-pixbuf.h b/gdk-pixbuf/gdk-pixbuf.h index 91898c1eec..9b5265bc49 100644 --- a/gdk-pixbuf/gdk-pixbuf.h +++ b/gdk-pixbuf/gdk-pixbuf.h @@ -147,6 +147,11 @@ void gdk_pixbuf_render_to_drawable (GdkPixbuf *pixbuf, GdkRgbDither dither, int x_dither, int y_dither); +void gdk_pixbuf_render_pixmap (GdkPixbuf *pixbuf, + GdkPixmap **pixmap, + GdkBitmap **mask, + gint alpha_threshold); + void gdk_pixbuf_render_to_drawable_alpha (GdkPixbuf *pixbuf, GdkDrawable *drawable, int src_x, int src_y, int dest_x, int dest_y, diff --git a/gdk/gdkpixbuf-render.c b/gdk/gdkpixbuf-render.c index d08f255477..5496aeb5dd 100644 --- a/gdk/gdkpixbuf-render.c +++ b/gdk/gdkpixbuf-render.c @@ -320,3 +320,70 @@ gdk_pixbuf_render_to_drawable_alpha (GdkPixbuf *pixbuf, GdkDrawable *drawable, gdk_gc_unref (gc); } +/** + * gdk_pixbuf_render_pixmap: + * @pixbuf: A pixbuf + * @pixmap: A pointer to a pixmap to fill in. + * @mask_retval: A pointer to the mask to be filled in. + * @alpha_threshold: Specifies the threshold value for opacity + * values if the pixbuf has opacity. + * + * Generates a #GdkPixmap from a #GdkPixbuf, along with an optional mask. The + * alpha threshold can be used to determine how the mask is created, if the + * pixbuf has an alpha channel. This function is mainly provided for + * compatibility reasons, as you will rarely want a #GdkPixmap. + * + **/ +void +gdk_pixbuf_render_pixmap (GdkPixbuf *pixbuf, + GdkPixmap **pixmap, + GdkBitmap **mask_retval, + gint alpha_threshold) +{ + GdkBitmap *mask = NULL; + + g_return_if_fail(pixbuf != NULL); + + /* generate mask */ + if (gdk_pixbuf_get_has_alpha(pixbuf)) { + mask = gdk_pixmap_new(NULL, + gdk_pixbuf_get_width(pixbuf), + gdk_pixbuf_get_height(pixbuf), + 1); + + gdk_pixbuf_render_threshold_alpha(pixbuf, mask, + 0, 0, 0, 0, + gdk_pixbuf_get_width(pixbuf), + gdk_pixbuf_get_height(pixbuf), + alpha_threshold); + } + + /* Draw to pixmap */ + if (pixmap != NULL) { + GdkGC* gc; + + *pixmap = gdk_pixmap_new(NULL, + gdk_pixbuf_get_width(pixbuf), + gdk_pixbuf_get_height(pixbuf), + gdk_rgb_get_visual()->depth); + + gc = gdk_gc_new(*pixmap); + + gdk_gc_set_clip_mask(gc, mask); + + gdk_pixbuf_render_to_drawable(pixbuf, *pixmap, + gc, + 0, 0, 0, 0, + gdk_pixbuf_get_width(pixbuf), + gdk_pixbuf_get_height(pixbuf), + GDK_RGB_DITHER_NORMAL, + 0, 0); + + gdk_gc_unref(gc); + } + + if (mask_retval) + *mask_retval = mask; + else + gdk_bitmap_unref(mask); +}