[gnome-photos/wip/rishi/misc-fixes: 20/20] base-item: Add photos_base_item_save_guess_sizes_async



commit 998ca456acabdadb4d55b854939b699222a58235
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Dec 23 16:49:13 2015 +0100

    base-item: Add photos_base_item_save_guess_sizes_async
    
    https://bugzilla.gnome.org/show_bug.cgi?id=759363

 src/photos-base-item.c |  100 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-base-item.h |   10 +++++
 2 files changed, 110 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 79254f3..9967c17 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -970,6 +970,42 @@ photos_base_item_process_idle (gpointer user_data)
 
 
 static void
+photos_base_item_save_guess_sizes_from_buffer (GCancellable *cancellable, GeglBuffer *buffer, gsize 
*out_size)
+{
+  GeglNode *buffer_source;
+  GeglNode *graph;
+  GeglNode *guess_sizes;
+  gsize size;
+
+  graph = gegl_node_new ();
+  buffer_source = gegl_node_new_child (graph, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
+  guess_sizes = gegl_node_new_child (graph, "operation", "photos:jpg-guess-sizes", NULL);
+  gegl_node_link (buffer_source, guess_sizes);
+  gegl_node_process (guess_sizes);
+
+  gegl_node_get (guess_sizes, "size", &size, NULL);
+  if (out_size != NULL)
+    *out_size = size;
+
+  g_object_unref (graph);
+}
+
+
+static void
+photos_base_item_save_guess_sizes_in_thread_func (GTask *task,
+                                                  gpointer source_object,
+                                                  gpointer task_data,
+                                                  GCancellable *cancellable)
+{
+  GeglBuffer *buffer = GEGL_BUFFER (task_data);
+  gsize size;
+
+  photos_base_item_save_guess_sizes_from_buffer (cancellable, buffer, &size);
+  g_task_return_int (task, (gssize) size);
+}
+
+
+static void
 photos_base_item_save_save_to_stream (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
   GTask *task = G_TASK (user_data);
@@ -2099,6 +2135,70 @@ photos_base_item_save_finish (PhotosBaseItem *self, GAsyncResult *res, GError **
 
 
 void
+photos_base_item_save_guess_sizes_async (PhotosBaseItem *self,
+                                         GCancellable *cancellable,
+                                         GAsyncReadyCallback callback,
+                                         gpointer user_data)
+{
+  PhotosBaseItemPrivate *priv;
+  const Babl *format;
+  GeglBuffer *buffer;
+  GeglNode *graph;
+  GeglRectangle bbox;
+  GTask *task;
+
+  g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
+  priv = self->priv;
+
+  g_return_if_fail (priv->edit_graph != NULL);
+  g_return_if_fail (priv->filename != NULL && priv->filename[0] != '\0');
+  g_return_if_fail (priv->load_graph != NULL);
+  g_return_if_fail (priv->processor != NULL);
+  g_return_if_fail (!gegl_processor_work (priv->processor, NULL));
+
+  graph = photos_pipeline_get_graph (priv->pipeline);
+  bbox = gegl_node_get_bounding_box (graph);
+  format = babl_format ("R'G'B' u8");
+  buffer = gegl_buffer_new (&bbox, format);
+  gegl_node_blit_buffer (graph, buffer, &bbox, 0, GEGL_ABYSS_NONE);
+
+  task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_source_tag (task, photos_base_item_save_guess_sizes_async);
+  g_task_set_task_data (task, g_object_ref (buffer), g_object_unref);
+
+  g_task_run_in_thread (task, photos_base_item_save_guess_sizes_in_thread_func);
+
+  g_object_unref (buffer);
+  g_object_unref (task);
+}
+
+
+gboolean
+photos_base_item_save_guess_sizes_finish (PhotosBaseItem *self, GAsyncResult *res, gsize *out_size, GError 
**error)
+{
+  GTask *task = G_TASK (res);
+  gboolean ret_val = FALSE;
+  gssize size;
+
+  g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
+  g_return_val_if_fail (g_task_get_source_tag (task) == photos_base_item_save_guess_sizes_async, FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  size = g_task_propagate_int (task, error);
+  if (size == -1)
+    goto out;
+
+  ret_val = TRUE;
+
+  if (out_size != NULL)
+    *out_size = (gsize) size;
+
+ out:
+  return ret_val;
+}
+
+
+void
 photos_base_item_save_to_dir_async (PhotosBaseItem *self,
                                     GFile *dir,
                                     GCancellable *cancellable,
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 48ca40a..aceb402 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -229,6 +229,16 @@ gboolean            photos_base_item_save_finish             (PhotosBaseItem *se
                                                               GAsyncResult *res,
                                                               GError **error);
 
+void                photos_base_item_save_guess_sizes_async  (PhotosBaseItem *self,
+                                                              GCancellable *cancellable,
+                                                              GAsyncReadyCallback callback,
+                                                              gpointer user_data);
+
+gboolean            photos_base_item_save_guess_sizes_finish (PhotosBaseItem *self,
+                                                              GAsyncResult *res,
+                                                              gsize *out_size,
+                                                              GError **error);
+
 void                photos_base_item_save_to_dir_async       (PhotosBaseItem *self,
                                                               GFile *dir,
                                                               GCancellable *cancellable,


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