summaryrefslogtreecommitdiff
path: root/gdk/gdkpixbuf-render.c
diff options
context:
space:
mode:
authorJonathan Blandford <jrb@redhat.com>2000-01-14 20:59:18 +0000
committerJonathan Blandford <jrb@src.gnome.org>2000-01-14 20:59:18 +0000
commit1f48e45e54d4f2c529f6af91a082caefa5457b94 (patch)
treefef2b2037ca739db3e2fe060b1946817de2df3ff /gdk/gdkpixbuf-render.c
parent7bfdf70ae137731c64249f0aecc34023dff74cf8 (diff)
downloadgtk+-1f48e45e54d4f2c529f6af91a082caefa5457b94.tar.gz
new function to let you create a gdk_pixmap from a gdk_pixbuf.
2000-01-14 Jonathan Blandford <jrb@redhat.com> * gdk-pixbuf/gdk-pixbuf-render.c (gdk_pixbuf_render_pixmap): new function to let you create a gdk_pixmap from a gdk_pixbuf.
Diffstat (limited to 'gdk/gdkpixbuf-render.c')
-rw-r--r--gdk/gdkpixbuf-render.c67
1 files changed, 67 insertions, 0 deletions
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);
+}