[gnome-photos] utils: Add photos_utils_buffer_zoom_async
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] utils: Add photos_utils_buffer_zoom_async
- Date: Wed, 30 Dec 2015 11:53:11 +0000 (UTC)
commit fb3e4eb373d1a38eceb6c6958011d43859063c80
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Dec 29 10:51:39 2015 +0100
utils: Add photos_utils_buffer_zoom_async
https://bugzilla.gnome.org/show_bug.cgi?id=759363
src/photos-utils.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/photos-utils.h | 8 ++++
2 files changed, 105 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index fe4e70b..7d46d4d 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -108,6 +108,103 @@ photos_utils_border_pixbuf (GdkPixbuf *pixbuf)
}
+static GeglBuffer *
+photos_utils_buffer_zoom (GeglBuffer *buffer, gdouble zoom, GCancellable *cancellable, GError **error)
+{
+ GeglBuffer *ret_val = NULL;
+ GeglNode *buffer_sink;
+ GeglNode *buffer_source;
+ GeglNode *graph;
+ GeglNode *scale;
+
+ graph = gegl_node_new ();
+ buffer_source = gegl_node_new_child (graph, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
+ scale = gegl_node_new_child (graph, "operation", "gegl:scale-ratio", "x", zoom, "y", zoom, NULL);
+ buffer_sink = gegl_node_new_child (graph, "operation", "gegl:buffer-sink", "buffer", &ret_val, NULL);
+ gegl_node_link_many (buffer_source, scale, buffer_sink, NULL);
+ gegl_node_process (buffer_sink);
+
+ g_object_unref (graph);
+ return ret_val;
+}
+
+
+static void
+photos_utils_buffer_zoom_in_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ GeglBuffer *buffer = GEGL_BUFFER (source_object);
+ GeglBuffer *result = NULL;
+ GError *error;
+ const gchar *zoom_str = (const gchar *) task_data;
+ gchar *endptr;
+ gdouble zoom;
+
+ zoom = g_ascii_strtod (zoom_str, &endptr);
+ g_assert (*endptr == '\0');
+
+ error = NULL;
+ result = photos_utils_buffer_zoom (buffer, zoom, cancellable, &error);
+ if (error != NULL)
+ {
+ g_task_return_error (task, error);
+ goto out;
+ }
+
+ g_task_return_pointer (task, g_object_ref (result), g_object_unref);
+
+ out:
+ g_clear_object (&result);
+}
+
+
+void
+photos_utils_buffer_zoom_async (GeglBuffer *buffer,
+ gdouble zoom,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+ gchar zoom_str[G_ASCII_DTOSTR_BUF_SIZE];
+
+ g_return_if_fail (GEGL_IS_BUFFER (buffer));
+ g_return_if_fail (zoom > 0.0);
+
+ task = g_task_new (buffer, cancellable, callback, user_data);
+ g_task_set_source_tag (task, photos_utils_buffer_zoom_async);
+
+ if (GEGL_FLOAT_EQUAL ((gfloat) zoom, 1.0))
+ {
+ g_task_return_pointer (task, g_object_ref (buffer), g_object_unref);
+ goto out;
+ }
+
+ g_ascii_dtostr (zoom_str, G_N_ELEMENTS (zoom_str), zoom);
+ g_task_set_task_data (task, g_strdup (zoom_str), g_free);
+
+ g_task_run_in_thread (task, photos_utils_buffer_zoom_in_thread_func);
+
+ out:
+ g_object_unref (task);
+}
+
+
+GeglBuffer *
+photos_utils_buffer_zoom_finish (GeglBuffer *buffer, GAsyncResult *res, GError **error)
+{
+ GTask *task = G_TASK (res);
+
+ g_return_val_if_fail (g_task_is_valid (res, buffer), NULL);
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_utils_buffer_zoom_async, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ return g_task_propagate_pointer (task, error);
+}
+
+
GdkPixbuf *
photos_utils_center_pixbuf (GdkPixbuf *pixbuf, gint size)
{
diff --git a/src/photos-utils.h b/src/photos-utils.h
index d2e503f..cc63745 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -59,6 +59,14 @@ G_BEGIN_DECLS
void photos_utils_border_pixbuf (GdkPixbuf *pixbuf);
+void photos_utils_buffer_zoom_async (GeglBuffer *buffer,
+ gdouble zoom,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+GeglBuffer *photos_utils_buffer_zoom_finish (GeglBuffer *buffer, GAsyncResult *res, GError
**error);
+
GdkPixbuf *photos_utils_center_pixbuf (GdkPixbuf *pixbuf, gint size);
gchar *photos_utils_convert_path_to_uri (const gchar *path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]