Commit 5079977d authored by Debarshi Ray's avatar Debarshi Ray

base-item: Add photos_base_item_save_guess_sizes_async

https://bugzilla.gnome.org/show_bug.cgi?id=759363
parent 6e976255
......@@ -966,6 +966,53 @@ photos_base_item_process_idle (gpointer user_data)
}
static void
photos_base_item_save_guess_sizes_from_buffer (GeglBuffer *buffer,
gsize *out_size,
gsize *out_size_1,
GCancellable *cancellable)
{
GeglNode *buffer_source;
GeglNode *graph;
GeglNode *guess_sizes;
gsize sizes[0];
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",
"optimize", FALSE,
"progressive", FALSE,
"sampling", TRUE,
NULL);
gegl_node_link (buffer_source, guess_sizes);
gegl_node_process (guess_sizes);
gegl_node_get (guess_sizes, "size", &sizes[0], "size-1", &sizes[1], NULL);
if (out_size != NULL)
*out_size = sizes[0];
if (out_size_1 != NULL)
*out_size_1 = sizes[1];
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 *sizes;
sizes = g_malloc0_n (2, sizeof (gsize));
photos_base_item_save_guess_sizes_from_buffer (buffer, &sizes[0], &sizes[1], cancellable);
g_task_return_pointer (task, sizes, g_free);
}
static void
photos_base_item_save_save_to_stream (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
......@@ -2067,6 +2114,71 @@ 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;
GeglBuffer *buffer;
GeglNode *graph;
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->load_graph != NULL);
g_return_if_fail (priv->pipeline != 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);
buffer = photos_utils_create_buffer_from_node (graph);
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,
gsize *out_size_1,
GError **error)
{
GTask *task = G_TASK (res);
gboolean ret_val = FALSE;
gsize *sizes;
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);
sizes = g_task_propagate_pointer (task, error);
if (g_task_had_error (task))
goto out;
ret_val = TRUE;
if (out_size != NULL)
*out_size = sizes[0];
if (out_size_1 != NULL)
*out_size_1 = sizes[1];
out:
return ret_val;
}
void
photos_base_item_set_default_app (PhotosBaseItem *self, GAppInfo *default_app)
{
......
......@@ -227,6 +227,17 @@ 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,
gsize *out_size_1,
GError **error);
void photos_base_item_set_default_app (PhotosBaseItem *self, GAppInfo *default_app);
void photos_base_item_set_default_app_name (PhotosBaseItem *self, const gchar *default_app_name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment