[gnome-photos/wip/rishi/serialize] utils: Borrow serialization code from GEGL
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/serialize] utils: Borrow serialization code from GEGL
- Date: Tue, 5 Jan 2016 17:15:14 +0000 (UTC)
commit 94f31e2a963fc7196861bf3288b91542986c47e5
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Jan 5 18:13:26 2016 +0100
utils: Borrow serialization code from GEGL
This is a pre-LGPLv3+ (ie. LGPLv2+) implementation of what is today
known as gegl_node_to_xml. Copying LGPLv2+ code into a GPLv2+ code base
(ie. this one) means that the result is still GPLv2+. On the other
hand, copying LGPLv3+ code would have made the resulting combination
GPLv3+.
We are going to use this to write our own serialization method that
only serializes till a certain node in the graph, instead of going all
the way to the source like gegl_node_to_xml does.
http://www.gnu.org/licenses/gpl-faq.en.html#AllCompatibility
src/photos-utils.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++-
src/photos-utils.h | 4 +-
2 files changed, 185 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 7d46d4d..0677215 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -1,6 +1,7 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2012, 2013, 2014, 2015 Red Hat, Inc.
+ * Copyright © 2006 Øyvind Kolås
+ * Copyright © 2012, 2013, 2014, 2015, 2016 Red Hat, Inc.
* Copyright © 2009 Yorba Foundation
*
* This program is free software; you can redistribute it and/or
@@ -61,6 +62,16 @@
#include "photos-utils.h"
+typedef struct _PhotosUtilsSerializeState PhotosUtilsSerializeState;
+
+struct _PhotosUtilsSerializeState
+{
+ GHashTable *clones;
+ GString *buf;
+ const gchar *path_root;
+ gint clone_count;
+};
+
static const gdouble EPSILON = 1e-5;
@@ -1122,6 +1133,176 @@ photos_utils_get_urns_from_paths (GList *paths, GtkTreeModel *model)
}
+static void
+photos_utils_graph_to_xml_add_stack (GeglNode *head, gint indent, PhotosUtilsSerializeState *ss)
+{
+ if (GEGL_IS_NODE (head))
+ {
+ GeglNode *iter = head;
+
+ while (iter)
+ {
+ GeglPad *input, *aux;
+ const gchar *id = NULL;
+ gchar *class;
+ gegl_node_get (iter, "operation", &class, NULL);
+
+ input = gegl_node_get_pad (iter, "input");
+ aux = gegl_node_get_pad (iter, "aux");
+
+ if (gegl_node_get_num_sinks (iter) > 1)
+ {
+ const gchar *new_id = g_hash_table_lookup (ss->clones, iter);
+ if (new_id)
+ {
+ ind; g_string_append (ss->buf, "<clone ref='");
+ g_string_append (ss->buf, new_id);
+ g_string_append (ss->buf, "'/>\n");
+ return; /* terminate the stack, the cloned part is already
+ serialized */
+ }
+ else
+ {
+ gchar temp_id[64];
+ sprintf (temp_id, "clone%i", ss->clone_count++);
+ id = g_strdup (temp_id);
+ g_hash_table_insert (ss->clones, iter, (gchar *) id);
+ /* the allocation is freed by the hash table */
+ }
+ }
+
+ if (!strcmp (class, "layer"))
+ {
+ serialize_layer (ss, indent, iter);
+ }
+ else
+ {
+ if (aux &&
+ gegl_pad_get_connected_to (aux))
+ {
+ GeglPad *source_pad;
+ GeglNode *source_node;
+ source_pad = gegl_pad_get_connected_to (aux);
+ source_node = gegl_pad_get_node (source_pad);
+ {
+ GeglNode *graph = g_object_get_data (G_OBJECT (source_node),
+ "graph");
+ if (graph)
+ source_node = graph;
+ }
+ ind; g_string_append (ss->buf, "<node");
+
+ {
+ gchar *class;
+ gchar *name;
+ gegl_node_get (iter, "operation", &class,
+ "name", &name,
+ NULL);
+ if (name[0])
+ {
+ xml_attr (ss->buf, "name", name);
+ }
+ xml_attr (ss->buf, "operation", class);
+ if (id != NULL)
+ xml_attr (ss->buf, "id", id);
+ g_free (name);
+ g_free (class);
+ }
+
+ g_string_append (ss->buf, ">\n");
+ serialize_properties (ss, indent + 4, iter);
+ photos_utils_graph_to_xml_add_stack (source_node, indent + 4, ss);
+
+ ind; g_string_append (ss->buf, "</node>\n");
+ }
+ else
+ {
+ if (class)
+ {
+ if (strcmp (class, "nop") &&
+ strcmp (class, "clone"))
+ {
+ ind; g_string_append (ss->buf, "<node");
+
+ {
+ gchar *class;
+ gchar *name;
+ gegl_node_get (iter, "operation", &class,
+ "name", &name,
+ NULL);
+ if (name[0])
+ {
+ xml_attr (ss->buf, "name", name);
+ }
+ xml_attr (ss->buf, "operation", class);
+ if (id != NULL)
+ xml_attr (ss->buf, "id", id);
+ g_free (name);
+ g_free (class);
+ }
+
+ g_string_append (ss->buf, ">\n");
+ serialize_properties (ss, indent + 4, iter);
+ ind; g_string_append (ss->buf, "</node>\n");
+ }
+ }
+ }
+ }
+ id = NULL;
+ if (input)
+ {
+ GeglPad *source_pad;
+ source_pad = gegl_pad_get_connected_to (input);
+ if (source_pad)
+ {
+ GeglNode *source_node = gegl_pad_get_node (source_pad);
+ GeglNode *graph = g_object_get_data (G_OBJECT (source_node),
+ "graph");
+ if (graph)
+ source_node = graph;
+ iter = source_node;
+ }
+ else
+ iter = NULL;
+ }
+ else
+ {
+ iter = NULL;
+ }
+
+ g_free (class);
+ }
+ }
+}
+
+
+gchar *
+photos_utils_graph_to_xml (GeglNode *head, GeglNode *tail, const gchar *path_root)
+{
+ PhotosUtilsSerializeState ss;
+ gchar *ret_val;
+
+ ss.buf = g_string_new ("");
+ ss.clones = g_hash_table_new (NULL, NULL);
+ ss.path_root = path_root;
+
+ head = gegl_node_get_output_proxy (head, "output");
+
+ g_string_append (ss.buf, "<?xml version='1.0' encoding='UTF-8'?>\n");
+ g_string_append (ss.buf, "<gegl>\n");
+
+ photos_utils_graph_to_xml_add_stack (head, 2, &ss);
+
+ g_string_append (ss->buf, "</gegl>\n");
+
+ g_hash_table_foreach (ss->clones, free_clone_id, NULL);
+ g_hash_table_destroy (ss->clones);
+
+ ret_val = g_string_free (ss.buf, FALSE);
+ return ret_val;
+}
+
+
GIcon *
photos_utils_icon_from_rdf_type (const gchar *type)
{
diff --git a/src/photos-utils.h b/src/photos-utils.h
index cc63745..23b419b 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -1,6 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2012, 2013, 2014, 2015 Red Hat, Inc.
+ * Copyright © 2012, 2013, 2014, 2015, 2016 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -139,6 +139,8 @@ GtkBorder *photos_utils_get_thumbnail_frame_border (void);
GList *photos_utils_get_urns_from_paths (GList *paths, GtkTreeModel *model);
+gchar *photos_utils_graph_to_xml (GeglNode *head, GeglNode *tail, const gchar
*path_root);
+
GIcon *photos_utils_icon_from_rdf_type (const gchar *type);
gboolean photos_utils_make_directory_with_parents (GFile *file, GCancellable *cancellable, GError
**error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]