[gnome-photos/wip/rishi/orientation: 3/8] gegl: Add photos_gegl_buffer_new_from_pixbuf



commit 1a59f348fe7ca2a6691ac31f92c6b0f4de4b5b92
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Nov 23 11:36:24 2017 +0100

    gegl: Add photos_gegl_buffer_new_from_pixbuf
    
    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.
    
    A subsequent commit will use this method to optimize the application of
    a BaseItem's embedded orientation.
    
    Bump minimum GdkPixbuf version to 2.32.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781736

 configure.ac      |    3 ++-
 src/photos-gegl.c |   30 ++++++++++++++++++++++++++++++
 src/photos-gegl.h |    2 ++
 3 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ca84e53..b115df7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,6 +38,7 @@ GLIB_GSETTINGS
 
 CAIRO_MIN_VERSION=1.14.0
 GDATA_MIN_VERSION=0.15.2
+GDK_PIXBUF_MIN_VERSION=2.32
 GEGL_MIN_VERSION=0.3.15
 GFBGRAPH_MIN_VERSION=0.2.1
 GLIB_MIN_VERSION=2.44.0
@@ -103,7 +104,7 @@ PKG_CHECK_MODULES(GDATA, [libgdata >= $GDATA_MIN_VERSION])
 PKG_CHECK_MODULES(GEGL, [gegl-0.3 >= $GEGL_MIN_VERSION])
 PKG_CHECK_MODULES(GEOCODE, [geocode-glib-1.0])
 PKG_CHECK_MODULES(GEXIV2, [gexiv2])
-PKG_CHECK_MODULES(GDK_PIXBUF, [gdk-pixbuf-2.0])
+PKG_CHECK_MODULES(GDK_PIXBUF, [gdk-pixbuf-2.0 >= $GDK_PIXBUF_MIN_VERSION])
 PKG_CHECK_MODULES(GLIB, [glib-2.0 >= $GLIB_MIN_VERSION])
 PKG_CHECK_MODULES(GIO, [gio-2.0 gio-unix-2.0])
 
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index 6ccaec3..a5af71a 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -69,6 +69,36 @@ static const gchar *REQUIRED_GEGL_OPS[] =
 };
 
 
+GeglBuffer *
+photos_gegl_buffer_new_from_pixbuf (GdkPixbuf *pixbuf)
+{
+  const Babl *format;
+  GeglBuffer *buffer = NULL;
+  GeglRectangle bbox;
+  gint height;
+  gint stride;
+  gint width;
+  const guint8 *pixels;
+
+  height = gdk_pixbuf_get_height (pixbuf);
+  width = gdk_pixbuf_get_width (pixbuf);
+  gegl_rectangle_set (&bbox, 0, 0, (guint) width, (guint) height);
+
+  if (gdk_pixbuf_get_has_alpha (pixbuf))
+    format = babl_format ("R'G'B'A u8");
+  else
+    format = babl_format ("R'G'B' u8");
+
+  buffer = gegl_buffer_new (&bbox, format);
+
+  pixels = gdk_pixbuf_read_pixels (pixbuf);
+  stride = gdk_pixbuf_get_rowstride (pixbuf);
+  gegl_buffer_set (buffer, &bbox, 0, format, pixels, stride);
+
+  return buffer;
+}
+
+
 static GeglBuffer *
 photos_gegl_buffer_zoom (GeglBuffer *buffer, gdouble zoom, GCancellable *cancellable, GError **error)
 {
diff --git a/src/photos-gegl.h b/src/photos-gegl.h
index b5b68ca..83cb2ed 100644
--- a/src/photos-gegl.h
+++ b/src/photos-gegl.h
@@ -29,6 +29,8 @@
 
 G_BEGIN_DECLS
 
+GeglBuffer      *photos_gegl_buffer_new_from_pixbuf       (GdkPixbuf *pixbuf);
+
 void             photos_gegl_buffer_zoom_async            (GeglBuffer *buffer,
                                                            gdouble zoom,
                                                            GCancellable *cancellable,


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