[gdk-pixbuf] gdk-pixbuf: Add new gdk_pixbuf_get_pixels_with_length method for gi users



commit deaf15acf911dd892cf72483ba4c704f20b51ee2
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Oct 6 16:58:17 2011 -0400

    gdk-pixbuf: Add new gdk_pixbuf_get_pixels_with_length method for gi users
    
    Binary data needs an explicit length to be useful. Add a new API for
    getting length of binary data, and allow gi users to use "get_pixels"
    in a useful manner instead of just grabbing the first pixel.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=662009

 gdk-pixbuf/gdk-pixbuf-core.h |    5 ++++
 gdk-pixbuf/gdk-pixbuf.c      |   46 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/gdk-pixbuf/gdk-pixbuf-core.h b/gdk-pixbuf/gdk-pixbuf-core.h
index d542437..643f578 100644
--- a/gdk-pixbuf/gdk-pixbuf-core.h
+++ b/gdk-pixbuf/gdk-pixbuf-core.h
@@ -252,6 +252,11 @@ guchar       *gdk_pixbuf_get_pixels          (const GdkPixbuf *pixbuf);
 int           gdk_pixbuf_get_width           (const GdkPixbuf *pixbuf);
 int           gdk_pixbuf_get_height          (const GdkPixbuf *pixbuf);
 int           gdk_pixbuf_get_rowstride       (const GdkPixbuf *pixbuf);
+gsize         gdk_pixbuf_get_byte_length     (const GdkPixbuf *pixbuf);
+
+guchar       *gdk_pixbuf_get_pixels_with_length (const GdkPixbuf *pixbuf,
+                                                 guint           *length);
+
 
 
 
diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c
index 5d5c062..b03cbd7 100644
--- a/gdk-pixbuf/gdk-pixbuf.c
+++ b/gdk-pixbuf/gdk-pixbuf.c
@@ -382,8 +382,7 @@ gdk_pixbuf_copy (const GdkPixbuf *pixbuf)
 	 * rowstride?
 	 */
 
-	size = ((pixbuf->height - 1) * pixbuf->rowstride +
-		pixbuf->width * ((pixbuf->n_channels * pixbuf->bits_per_sample + 7) / 8));
+	size = gdk_pixbuf_get_byte_length (pixbuf);
 
 	buf = g_try_malloc (size * sizeof (guchar));
 	if (!buf)
@@ -541,6 +540,32 @@ gdk_pixbuf_get_pixels (const GdkPixbuf *pixbuf)
 }
 
 /**
+ * gdk_pixbuf_get_pixels_with_length:
+ * @pixbuf: A pixbuf.
+ * @length: (out): The length of the binary data.
+ *
+ * Queries a pointer to the pixel data of a pixbuf.
+ *
+ * Return value: (array length=length): A pointer to the pixbuf's
+ * pixel data.  Please see <xref linkend="image-data"/>
+ * for information about how the pixel data is stored in
+ * memory.
+ *
+ * Rename to: gdk_pixbuf_get_pixels
+ **/
+guchar *
+gdk_pixbuf_get_pixels_with_length (const GdkPixbuf *pixbuf,
+                                   guint           *length)
+{
+	g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
+
+        if (length)
+                *length = gdk_pixbuf_get_byte_length (pixbuf);
+
+	return pixbuf->pixels;
+}
+
+/**
  * gdk_pixbuf_get_width:
  * @pixbuf: A pixbuf.
  *
@@ -589,6 +614,23 @@ gdk_pixbuf_get_rowstride (const GdkPixbuf *pixbuf)
 	return pixbuf->rowstride;
 }
 
+/**
+ * gdk_pixbuf_get_byte_length:
+ * @pixbuf: A pixbuf.
+ *
+ * Returns the length of the pixel data, in bytes.
+ *
+ * Return value: The length of the pixel data.
+ */
+inline gsize
+gdk_pixbuf_get_byte_length (const GdkPixbuf *pixbuf)
+{
+	g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), -1);
+
+        return ((pixbuf->height - 1) * pixbuf->rowstride +
+                pixbuf->width * ((pixbuf->n_channels * pixbuf->bits_per_sample + 7) / 8));
+}
+
 
 
 /* General initialization hooks */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]