[gnome-photos/wip/rishi/unit-tests-gegl: 1/5] 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: 1/5] gegl: Add photos_gegl_pixbuf_new_from_buffer
- Date: Fri, 30 Nov 2018 14:41:15 +0000 (UTC)
commit 5f54518a3c2432cf8c75d1e19c31758af96cbb94
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.
Bump minimum GdkPixbuf version to 2.36.8.
configure.ac | 2 +-
meson.build | 2 +-
src/photos-gegl.c | 40 ++++++++++++++++++++++++++++++++++++++++
src/photos-gegl.h | 2 ++
4 files changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9f1cd7ea..d9026d00 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,7 +41,7 @@ GLIB_GSETTINGS
CAIRO_MIN_VERSION=1.14.0
DAZZLE_MIN_VERSION=3.26.0
GDATA_MIN_VERSION=0.15.2
-GDK_PIXBUF_MIN_VERSION=2.32
+GDK_PIXBUF_MIN_VERSION=2.36.8
GEGL_MIN_VERSION=0.4.0
GEXIV2_MIN_VERSION=0.10.8
GFBGRAPH_MIN_VERSION=0.2.1
diff --git a/meson.build b/meson.build
index 0b10a637..1e461517 100644
--- a/meson.build
+++ b/meson.build
@@ -150,7 +150,7 @@ libgd_dep = libgd.get_variable('libgd_dep')
babl_dep = dependency('babl')
cairo_dep = dependency('cairo', version: '>= 1.14.0')
-gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>= 2.32')
+gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>= 2.36.8')
gegl_dep = dependency('gegl-0.4', version: '>= 0.4.0')
geocode_glib_dep = dependency('geocode-glib-1.0')
gexiv_dep = dependency('gexiv2', version: '>= 0.10.8')
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index cb62073c..d385b921 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -652,6 +652,46 @@ 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 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");
+
+ stride = gdk_pixbuf_calculate_rowstride (GDK_COLORSPACE_RGB, has_alpha, 8, bbox.width, bbox.height);
+ if (stride == -1)
+ goto out;
+
+ 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]