diff options
author | Jasper St. Pierre <jstpierre@mecheye.net> | 2011-10-06 16:58:17 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2011-12-16 17:49:31 -0500 |
commit | deaf15acf911dd892cf72483ba4c704f20b51ee2 (patch) | |
tree | f544522e0aad357f8b1485bbd5f444cac1ac50a7 /gdk-pixbuf/gdk-pixbuf.c | |
parent | ae8ab1d8540f4e85c727be0e607d91ac80ac815a (diff) | |
download | gdk-pixbuf-deaf15acf911dd892cf72483ba4c704f20b51ee2.tar.gz |
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
Diffstat (limited to 'gdk-pixbuf/gdk-pixbuf.c')
-rw-r--r-- | gdk-pixbuf/gdk-pixbuf.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c index 5d5c06288..b03cbd7d2 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 */ |