[gnome-photos/wip/rishi/unit-tests-gegl: 2/6] gegl: Add photos_gegl_pixbuf_new_from_buffer
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/unit-tests-gegl: 2/6] gegl: Add photos_gegl_pixbuf_new_from_buffer
- Date: Fri, 30 Nov 2018 13:55:33 +0000 (UTC)
commit aeff4c33e2dcaa74ac7f84ec41cc41eeae2070c4
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Nov 28 19:08:37 2018 +0100
gegl: Add photos_gegl_pixbuf_new_from_buffer
This is part of a new set of APIs for GeglBuffer that don't require the
creation of a graph. These will allow decoding and encoding image file
formats to and from a GeglBuffer through asynchronous and cancellable
methods with error handling. These will follow GIO idioms and be
similar to the codec APIs for GdkPixbuf. There will be a compatibility
layer to convert a GeglBuffer to and from GdkPixbuf for legacy reasons.
These APIs will address the current lack of cancellation and error
handling in gegl:load, and make it easier to port existing code away
from GdkPixbuf.
src/photos-gegl.c | 43 +++++++++++++++++++++++++++++++++++++++++++
src/photos-gegl.h | 2 ++
2 files changed, 45 insertions(+)
---
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index cb62073c..f27a9b5c 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -652,6 +652,49 @@ photos_gegl_init_fishes (void)
}
+GdkPixbuf *
+photos_gegl_pixbuf_new_from_buffer (GeglBuffer *buffer)
+{
+ const Babl *format_buffer;
+ const Babl *format_pixbuf;
+ g_autoptr (GBytes) bytes = NULL;
+ GdkPixbuf *pixbuf = NULL;
+ GeglRectangle bbox;
+ gboolean has_alpha;
+ gint bpp;
+ gint stride;
+ gpointer buf = NULL;
+ gsize size;
+
+ g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
+
+ bbox = *gegl_buffer_get_extent (buffer);
+ format_buffer = gegl_buffer_get_format (buffer);
+ has_alpha = babl_format_has_alpha (format_buffer);
+
+ if (has_alpha)
+ format_pixbuf = babl_format ("R'G'B'A u8");
+ else
+ format_pixbuf = babl_format ("R'G'B' u8");
+
+ bpp = babl_format_get_bytes_per_pixel (format_pixbuf);
+ if (bpp > 0 && bbox.width > 0 && bbox.width > G_MAXINT / bpp)
+ goto out;
+
+ stride = bpp * bbox.width;
+
+ buf = g_malloc0_n ((gsize) bbox.height, (gsize) stride);
+ gegl_buffer_get (buffer, &bbox, 1.0, format_pixbuf, buf, stride, GEGL_ABYSS_NONE);
+
+ size = (gsize) bbox.height * (gsize) stride;
+ bytes = g_bytes_new_take (buf, size);
+ pixbuf = gdk_pixbuf_new_from_bytes (bytes, GDK_COLORSPACE_RGB, has_alpha, 8, bbox.width, bbox.height,
stride);
+
+ out:
+ return pixbuf;
+}
+
+
static gboolean
photos_gegl_processor_process_idle (gpointer user_data)
{
diff --git a/src/photos-gegl.h b/src/photos-gegl.h
index d902300b..27bf3062 100644
--- a/src/photos-gegl.h
+++ b/src/photos-gegl.h
@@ -51,6 +51,8 @@ void photos_gegl_init (void);
void photos_gegl_init_fishes (void);
+GdkPixbuf *photos_gegl_pixbuf_new_from_buffer (GeglBuffer *buffer);
+
void photos_gegl_processor_process_async (GeglProcessor *processor,
GCancellable *cancellable,
GAsyncReadyCallback callback,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]