summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/gdk-pixbuf.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@pobox.com>2000-11-01 07:07:46 +0000
committerHavoc Pennington <hp@src.gnome.org>2000-11-01 07:07:46 +0000
commitfe9f9d03f41936fc9ace154db4904e32f2ec3304 (patch)
treeb7948e3ad25559ae7b231f8e209a86687bbd927e /gdk-pixbuf/gdk-pixbuf.c
parentda5fdc1360a6002b06b0196e33e294527069a90c (diff)
downloadgtk+-fe9f9d03f41936fc9ace154db4904e32f2ec3304.tar.gz
New function to create a pixbuf pointing to a subregion of another pixbuf.
2000-11-01 Havoc Pennington <hp@pobox.com> * gdk-pixbuf.c (gdk_pixbuf_new_subpixbuf): New function to create a pixbuf pointing to a subregion of another pixbuf. 2000-11-01 Havoc Pennington <hp@pobox.com> * gtk/gtklabel.c (gtk_label_set_attributes): Set a PangoAttrList on a label (gtk_label_finalize): unref the attr list if any. * gtk/testgtk.c (create_get_image): close test on second click (make_message_dialog): close dialog if it exists * gdk/gdkpango.c (gdk_draw_layout): Handle rise attribute * gdk-2.0.pc.in (Requires): Make it require gdk-pixbuf-2.0 not gdk-pixbuf * gtk/gtklabel.c (gtk_label_set_markup): new function to set label from Pango markup format (gtk_label_set_markup_with_accel): ditto but with accelerator parsing * gtk/gtkimage.c (gtk_image_expose): reformatting. * gdk/gdkpixbuf-drawable.c (gdk_pixbuf_get_from_drawable): Hack to reflect current state of GDK - use gdk_drawable_get_colormap, etc. Check GDK_IS_WINDOW() not !GDK_IS_PIXMAP() to decide whether to call gdk_window_get_origin(). * gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable_alpha): implement GDK_PIXBUF_ALPHA_FULL
Diffstat (limited to 'gdk-pixbuf/gdk-pixbuf.c')
-rw-r--r--gdk-pixbuf/gdk-pixbuf.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c
index 84e086e725..b2e3f53969 100644
--- a/gdk-pixbuf/gdk-pixbuf.c
+++ b/gdk-pixbuf/gdk-pixbuf.c
@@ -203,6 +203,60 @@ gdk_pixbuf_copy (const GdkPixbuf *pixbuf)
NULL);
}
+/**
+ * gdk_pixbuf_new_subpixbuf:
+ * @src_pixbuf: a #GdkPixbuf
+ * @src_x: X coord in @src_pixbuf
+ * @src_y: Y coord in @src_pixbuf
+ * @width: width of region in @src_pixbuf
+ * @height: height of region in @src_pixbuf
+ *
+ * Creates a new pixbuf which represents a sub-region of
+ * @src_pixbuf. The new pixbuf shares its pixels with the
+ * original pixbuf, so writing to one affects both.
+ * The new pixbuf holds a reference to @src_pixbuf, so
+ * @src_pixbuf will not be finalized until the new pixbuf
+ * is finalized.
+ *
+ * Return value: a new pixbuf
+ **/
+GdkPixbuf*
+gdk_pixbuf_new_subpixbuf (GdkPixbuf *src_pixbuf,
+ int src_x,
+ int src_y,
+ int width,
+ int height)
+{
+ guchar *pixels;
+ GdkPixbuf *sub;
+
+ g_return_val_if_fail (GDK_IS_PIXBUF (src_pixbuf), NULL);
+ g_return_val_if_fail (src_x >= 0 && src_x + width <= src_pixbuf->width, NULL);
+ g_return_val_if_fail (src_y >= 0 && src_y + height <= src_pixbuf->height, NULL);
+
+ pixels = (gdk_pixbuf_get_pixels (src_pixbuf)
+ + src_y * src_pixbuf->rowstride
+ + src_x * src_pixbuf->n_channels);
+
+ sub = gdk_pixbuf_new_from_data (pixels,
+ src_pixbuf->colorspace,
+ src_pixbuf->has_alpha,
+ src_pixbuf->bits_per_sample,
+ width, height,
+ src_pixbuf->rowstride,
+ NULL, NULL);
+
+ /* Keep a reference to src_pixbuf */
+ g_object_ref (G_OBJECT (src_pixbuf));
+
+ g_object_set_qdata_full (G_OBJECT (sub),
+ g_quark_from_static_string ("gdk-pixbuf-subpixbuf-src"),
+ src_pixbuf,
+ (GDestroyNotify) g_object_unref);
+
+ return sub;
+}
+
/* Accessors */