summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demos/testpixbuf-drawable.c6
-rw-r--r--gdk-pixbuf/gdk-pixbuf-util.c61
-rw-r--r--gdk-pixbuf/gdk-pixbuf.h7
3 files changed, 69 insertions, 5 deletions
diff --git a/demos/testpixbuf-drawable.c b/demos/testpixbuf-drawable.c
index 0ac321e237..3d43244ca5 100644
--- a/demos/testpixbuf-drawable.c
+++ b/demos/testpixbuf-drawable.c
@@ -12,7 +12,6 @@ void expose_cb(GtkWidget *drawing_area, GdkEventExpose *evt, gpointer
data)
{
GdkPixbuf *pixbuf;
- gint x1, y1, x2, y2;
pixbuf = (GdkPixbuf *) gtk_object_get_data(GTK_OBJECT(drawing_area),
"pixbuf");
@@ -44,10 +43,11 @@ data)
pixbuf->art_pixbuf->rowstride);
}
}
+
void configure_cb(GtkWidget *drawing_area, GdkEventConfigure *evt,
gpointer data)
{
- GdkPixbuf *pixbuf, spb;
+ GdkPixbuf *pixbuf;
pixbuf = (GdkPixbuf *) gtk_object_get_data(GTK_OBJECT(drawing_area),
"pixbuf");
@@ -67,8 +67,6 @@ int main(int argc, char **argv)
GtkWidget *vbox;
GtkWidget *drawing_area;
GdkPixbuf *pixbuf;
- gint width, height;
- gint x, y;
gtk_init(&argc, &argv);
gdk_rgb_set_verbose(TRUE);
diff --git a/gdk-pixbuf/gdk-pixbuf-util.c b/gdk-pixbuf/gdk-pixbuf-util.c
index b507d25070..2bc7e98b06 100644
--- a/gdk-pixbuf/gdk-pixbuf-util.c
+++ b/gdk-pixbuf/gdk-pixbuf-util.c
@@ -2,7 +2,8 @@
*
* Copyright (C) 1999 The Free Software Foundation
*
- * Author: Federico Mena-Quintero <federico@gimp.org>
+ * Authors: Federico Mena-Quintero <federico@gimp.org>
+ * Cody Russell <bratsche@dfw.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -93,3 +94,61 @@ gdk_pixbuf_add_alpha (GdkPixbuf *pixbuf, gboolean substitute_color, guchar r, gu
return new_pixbuf;
}
+
+/**
+ * gdk_pixbuf_copy_area:
+ * @src_pixbuf: The pixbuf to be copied.
+ * @src_x: The X coordinate of the upper left corner of the area to copy.
+ * @src_y: The Y coordinate of the upper left corner of the area to copy.
+ * @width: The width of the area to copy.
+ * @height: The height of the area to copy.
+ * @dest_pixbuf: The pixbuf to store the copy in.
+ * @dest_x: X coordinate for the upper left corner of the rectangle to draw to in @dest_pixbuf.
+ * @dest_y: Y coordinate for the upper left corner of the rectangle to draw to in @dest_pixbuf.
+ *
+ * Takes a rectangle area beginning at (@src_x, @src_y) @width pixels wide
+ * and @height pixels high from @src_pixbuf and copy it into @dest_pixbuf
+ * at (@dest_x, @dest_y). @dest_pixbuf must already be created and must be
+ * large enough to hold the requested area.
+ *
+ * Return value: void
+ **/
+void gdk_pixbuf_copy_area(GdkPixbuf *src_pixbuf,
+ gint src_x, gint src_y,
+ gint width, gint height,
+ GdkPixbuf *dest_pixbuf,
+ gint dest_x, gint dest_y)
+{
+ gint src_width, src_height, dest_width, dest_height;
+
+ /* Ensure that we have a source pixbuf, and that the requested
+ * area is not larger than that pixbuf.
+ */
+ g_return_if_fail(src_pixbuf != NULL);
+
+ src_width = gdk_pixbuf_get_width(src_pixbuf);
+ src_height = gdk_pixbuf_get_height(src_pixbuf);
+
+ g_return_if_fail(src_x >= 0 && width <= src_width);
+ g_return_if_fail(src_y >= 0 && height <= src_height);
+
+ /* Ensure that we have a destination pixbuf, and that the
+ * requested area is not larger than that pixbuf.
+ */
+ g_return_if_fail(dest_pixbuf != NULL);
+
+ dest_width = gdk_pixbuf_get_width(dest_pixbuf);
+ dest_height = gdk_pixbuf_get_height(dest_pixbuf);
+
+ g_return_if_fail(dest_x >= 0 && width <= dest_width);
+ g_return_if_fail(dest_y >= 0 && height <= dest_height);
+
+ /* Scale 1:1 the source pixbuf into the destination pixbuf. */
+ gdk_pixbuf_scale(src_pixbuf,
+ dest_pixbuf,
+ dest_x, dest_y,
+ width, height,
+ (double)(dest_x - src_x),
+ (double)(dest_y - src_y),
+ 1., 1., ART_FILTER_NEAREST);
+}
diff --git a/gdk-pixbuf/gdk-pixbuf.h b/gdk-pixbuf/gdk-pixbuf.h
index 82784c3023..91898c1eec 100644
--- a/gdk-pixbuf/gdk-pixbuf.h
+++ b/gdk-pixbuf/gdk-pixbuf.h
@@ -163,6 +163,13 @@ GdkPixbuf *gdk_pixbuf_get_from_drawable (GdkPixbuf *dest,
int dest_x, int dest_y,
int width, int height);
+/* Copy an area of a pixbuf into another one */
+void gdk_pixbuf_copy_area (GdkPixbuf *src_pixbuf,
+ gint src_x, gint src_y,
+ gint width, gint height,
+ GdkPixbuf *dest_pixbuf,
+ gint dest_x, gint dest_y);
+
/* Scaling */
void gdk_pixbuf_scale (GdkPixbuf *src,