[gnome-photos/wip/rishi/buffer-decoder: 240/240] base-item, thumnailer: Use the new GeglBuffer codec API




commit 95312f4bed033389e9dbcbdf651817c7d34b675d
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Sep 6 11:06:01 2018 +0200

    base-item, thumnailer: Use the new GeglBuffer codec API
    
    Unlike the older GeglOperation based API, the newer API is cancellable,
    supports error handling, and doesn't make any assumptions about the
    paths being UTF-8 encoded.
    
    https://gitlab.gnome.org/GNOME/gnome-photos/issues/63

 src/meson.build          |   1 -
 src/photos-base-item.c   |  23 ++-------
 src/photos-pixbuf.c      | 119 -----------------------------------------------
 src/photos-pixbuf.h      |  38 ---------------
 src/photos-thumbnailer.c |  22 ++++-----
 5 files changed, 16 insertions(+), 187 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 9d1a21f5..f92896c2 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -433,7 +433,6 @@ executable(
 )
 
 sources = common_sources + files(
-  'photos-pixbuf.c',
   'photos-thumbnailer.c',
   'photos-thumbnailer-main.c',
 )
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index e4007853..cb8ebb10 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -45,6 +45,7 @@
 #include "photos-error.h"
 #include "photos-filterable.h"
 #include "photos-gegl.h"
+#include "photos-gegl-buffer-io.h"
 #include "photos-glib.h"
 #include "photos-local-item.h"
 #include "photos-pipeline.h"
@@ -1463,10 +1464,6 @@ photos_base_item_load_buffer (PhotosBaseItem *self, GCancellable *cancellable, G
   g_autoptr (GFile) file = NULL;
   g_autoptr (GeglBuffer) buffer = NULL;
   GeglBuffer *ret_val = NULL;
-  GeglNode *buffer_sink;
-  g_autoptr (GeglNode) graph = NULL;
-  GeglNode *load;
-  g_autofree gchar *path = NULL;
   gint64 end;
   gint64 start;
 
@@ -1476,22 +1473,12 @@ photos_base_item_load_buffer (PhotosBaseItem *self, GCancellable *cancellable, G
   if (file == NULL)
     goto out;
 
-  path = g_file_get_path (file);
-  if (!g_utf8_validate (path, -1, NULL))
-    {
-      g_set_error (error, PHOTOS_ERROR, 0, "Path is not UTF-8 encoded");
-      goto out;
-    }
-
-  graph = gegl_node_new ();
-  load = gegl_node_new_child (graph, "operation", "gegl:load", "path", path, NULL);
-  buffer_sink = gegl_node_new_child (graph, "operation", "gegl:buffer-sink", "buffer", &buffer, NULL);
-
-  gegl_node_link (load, buffer_sink);
-
   start = g_get_monotonic_time ();
 
-  gegl_node_process (buffer_sink);
+  buffer = photos_gegl_buffer_new_from_file (file, cancellable, error);
+  if (buffer == NULL)
+    goto out;
+
   ret_val = photos_gegl_buffer_apply_orientation (buffer, priv->orientation);
 
   end = g_get_monotonic_time ();
diff --git a/src/photos-thumbnailer.c b/src/photos-thumbnailer.c
index 60470075..0627998d 100644
--- a/src/photos-thumbnailer.c
+++ b/src/photos-thumbnailer.c
@@ -29,8 +29,8 @@
 #include "photos-debug.h"
 #include "photos-error.h"
 #include "photos-gegl.h"
+#include "photos-gegl-buffer-io.h"
 #include "photos-pipeline.h"
-#include "photos-pixbuf.h"
 #include "photos-thumbnailer.h"
 #include "photos-thumbnailer-dbus.h"
 
@@ -341,11 +341,10 @@ photos_thumbnailer_generate_thumbnail_process (GObject *source_object, GAsyncRes
 
 
 static void
-photos_thumbnailer_generate_thumbnail_pixbuf (GObject *source_object, GAsyncResult *res, gpointer user_data)
+photos_thumbnailer_generate_thumbnail_buffer (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
   GCancellable *cancellable;
   g_autoptr (GTask) task = G_TASK (user_data);
-  g_autoptr (GdkPixbuf) pixbuf = NULL;
   g_autoptr (GeglBuffer) buffer = NULL;
   g_autoptr (GeglBuffer) buffer_oriented = NULL;
   GeglNode *buffer_source;
@@ -359,7 +358,7 @@ photos_thumbnailer_generate_thumbnail_pixbuf (GObject *source_object, GAsyncResu
   {
     g_autoptr (GError) error = NULL;
 
-    pixbuf = photos_pixbuf_new_from_file_at_size_finish (res, &error);
+    buffer = photos_gegl_buffer_new_from_file_finish (res, &error);
     if (error != NULL)
       {
         g_task_return_error (task, g_steal_pointer (&error));
@@ -367,7 +366,6 @@ photos_thumbnailer_generate_thumbnail_pixbuf (GObject *source_object, GAsyncResu
       }
   }
 
-  buffer = photos_gegl_buffer_new_from_pixbuf (pixbuf);
   buffer_oriented = photos_gegl_buffer_apply_orientation (buffer, data->orientation);
 
   buffer_source = gegl_node_new_child (data->graph, "operation", "gegl:buffer-source", "buffer", 
buffer_oriented, NULL);
@@ -459,12 +457,14 @@ photos_thumbnailer_generate_thumbnail_pipeline (GObject *source_object, GAsyncRe
     photos_debug (PHOTOS_DEBUG_NETWORK, "Downloading %s (%s)", uri, path);
 
   photos_debug (PHOTOS_DEBUG_THUMBNAILER, "Loading %s at %d×%d", uri, load_width, load_height);
-  photos_pixbuf_new_from_file_at_size_async (path,
-                                             load_width,
-                                             load_height,
-                                             cancellable,
-                                             photos_thumbnailer_generate_thumbnail_pixbuf,
-                                             g_object_ref (task));
+  photos_gegl_buffer_new_from_file_at_scale_async (data->file,
+                                                   load_width,
+                                                   load_height,
+                                                   FALSE,
+                                                   G_PRIORITY_DEFAULT,
+                                                   cancellable,
+                                                   photos_thumbnailer_generate_thumbnail_buffer,
+                                                   g_object_ref (task));
 
  out:
   return;


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