[gegl] gegl-serialize: make use of passed in reference id n serialization



commit 5f95e2000f29ef3d58bb177f8ba5cf25e7992a50
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Apr 21 18:38:05 2016 +0100

    gegl-serialize: make use of passed in reference id n serialization

 bin/ui.c                      |    2 +-
 gegl/gegl-serialize.c         |   60 ++++++++++++++++++++++++++++++++++++++--
 operations/common/Makefile.am |    2 +-
 operations/common/c2g.c       |   15 +++++++++-
 operations/core/load.c        |    1 -
 tests/simple/test-serialize.c |   35 +++++++++++-------------
 6 files changed, 88 insertions(+), 27 deletions(-)
---
diff --git a/bin/ui.c b/bin/ui.c
index d605721..73bc6d5 100644
--- a/bin/ui.c
+++ b/bin/ui.c
@@ -1363,7 +1363,7 @@ static void load_path (State *o)
     {
       GSList *nodes, *n;
       char *containing_path = get_path_parent (o->path);
-      o->gegl = gegl_node_new_from_xml (meta, containing_path);
+      o->gegl = gegl_node_new_from_serialized (meta, containing_path);
       free (containing_path);
       o->sink = gegl_node_new_child (o->gegl,
                        "operation", "gegl:nop", NULL);
diff --git a/gegl/gegl-serialize.c b/gegl/gegl-serialize.c
index 87343c9..de6c702 100644
--- a/gegl/gegl-serialize.c
+++ b/gegl/gegl-serialize.c
@@ -150,6 +150,8 @@ void gegl_create_chain_argv (char **ops, GeglNode *start, GeglNode *proxy, doubl
           if (!strcmp (key, "id"))
           {
             g_hash_table_insert (ht, (void*)g_intern_string (value), iter[level]);
+            g_object_set_data (G_OBJECT(iter[level]),
+                               "refname", (void*)g_intern_string (value));
           }
           else if (!strcmp (key, "ref"))
           {
@@ -490,10 +492,11 @@ void gegl_create_chain (const char *str, GeglNode *op_start, GeglNode *op_end, d
   }
 }
 
-gchar *gegl_serialize (GeglNode *start, GeglNode *end)
+static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, GHashTable *ht)
 {
   char *ret = NULL;
   GeglNode *iter;
+
   GString *str = g_string_new ("");
   if (start == NULL && 0)
   {
@@ -502,10 +505,51 @@ gchar *gegl_serialize (GeglNode *start, GeglNode *end)
       start = gegl_node_get_producer (start, "input", NULL);
   }
 
+
   iter = end;
   while (iter)
   {
-    if (iter == start)
+    GeglNode **nodes = NULL;
+    int count = gegl_node_get_consumers (iter, "output", &nodes, NULL);
+    if (count>1)
+    {
+      int val;
+      int last = 0;
+      int cnt = 0;
+
+      if ((val = GPOINTER_TO_INT (g_hash_table_lookup (ht, iter))))
+      {
+        cnt = val - 1;
+        g_hash_table_insert (ht, iter, GINT_TO_POINTER (cnt));
+        if (cnt == 1)
+          last=1;
+      }
+      else
+      {
+        g_hash_table_insert (ht, iter, GINT_TO_POINTER (count));
+        cnt = count;
+      }
+
+      {
+      gchar *str3;
+      
+      gchar *refname = g_object_get_data (G_OBJECT (iter), "refname");
+     
+      if (refname)
+        str3  = g_strdup_printf (" %s=%s", last?"id":"ref", refname);
+      else
+        str3  = g_strdup_printf (" %s=%p", last?"id":"ref", iter);
+      g_string_prepend (str, str3);
+      g_free (str3);
+      }
+      /* if this is not the last reference to it,. keep recursing
+       */
+      if (!last)
+        iter = NULL;
+    }
+    g_free (nodes);
+
+    if (iter == start || !iter)
     {
       iter = NULL;
     }
@@ -626,7 +670,7 @@ gchar *gegl_serialize (GeglNode *start, GeglNode *end)
             GeglNode *aux = gegl_node_get_producer (iter, "aux", NULL);
             if (aux)
             {
-              char *str = gegl_serialize (NULL, aux);
+              char *str = gegl_serialize2 (NULL, aux, ht);
               g_string_append_printf (s2, " aux=[%s ]", str);
               g_free (str);
             }
@@ -642,5 +686,15 @@ gchar *gegl_serialize (GeglNode *start, GeglNode *end)
   ret = str->str;
   g_string_free (str, FALSE);
 
+
+  return ret;
+}
+
+gchar *gegl_serialize (GeglNode *start, GeglNode *end)
+{
+  gchar *ret;
+  GHashTable *ht = g_hash_table_new (g_direct_hash, g_direct_equal);
+  ret = gegl_serialize2 (start, end, ht);
+  g_hash_table_destroy (ht);
   return ret;
 }
diff --git a/operations/common/Makefile.am b/operations/common/Makefile.am
index 928c701..082ad0b 100644
--- a/operations/common/Makefile.am
+++ b/operations/common/Makefile.am
@@ -6,7 +6,7 @@ EXTRA_DIST = $(wildcard $(srcdir)/*.h)
 
 BUILT_SOURCES = $(subst .c,.c.h,$(wildcard $(srcdir)/*.c))
 
-AM_CPPFLAGS += -I$(srcdir)
+AM_CPPFLAGS += -I$(srcdir) 
 
 LIBS = $(op_libs)
 
diff --git a/operations/common/c2g.c b/operations/common/c2g.c
index 29f5f75..d6a6ed0 100644
--- a/operations/common/c2g.c
+++ b/operations/common/c2g.c
@@ -60,7 +60,8 @@ property_double (rgamma, _("Radial Gamma"), 0.0, 8.0, 2.0,
 
 #define RGAMMA 2.0
 
-static void c2g (GeglBuffer          *src,
+static void c2g (GeglOperation       *op,
+                 GeglBuffer          *src,
                  const GeglRectangle *src_rect,
                  GeglBuffer          *dst,
                  const GeglRectangle *dst_rect,
@@ -74,10 +75,15 @@ static void c2g (GeglBuffer          *src,
 
   if (dst_rect->width > 0 && dst_rect->height > 0)
   {
+    /* XXX: compute total pixels and progress by consumption 
+     */
     GeglBufferIterator *i = gegl_buffer_iterator_new (dst, dst_rect, 0, babl_format("YA float"),
                                                       GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
     GeglSampler *sampler = gegl_buffer_sampler_new_at_level (src, format, GEGL_SAMPLER_NEAREST, level);
 
+    float total_pix = dst_rect->width * dst_rect->height;
+    int pix_done = 0.0;
+
     while (gegl_buffer_iterator_next (i))
     {
       gint x,y;
@@ -132,7 +138,12 @@ static void c2g (GeglBuffer          *src,
                 dst_offset+=2;
               }
             }
+      
+            pix_done += i->roi[0].width;
           }
+#if 0
+        gegl_operation_progress (op, pix_done / total_pix, "");
+#endif
     }
     g_object_unref (sampler);
   }
@@ -327,7 +338,7 @@ process (GeglOperation       *operation,
     if(cl_process(operation, input, output, result))
       return TRUE;
 
-  c2g (input, &compute, output, result,
+  c2g (operation, input, &compute, output, result,
        o->radius,
        o->samples,
        o->iterations,
diff --git a/operations/core/load.c b/operations/core/load.c
index 60463f2..8689cfa 100644
--- a/operations/core/load.c
+++ b/operations/core/load.c
@@ -146,7 +146,6 @@ do_setup (GeglOperation *operation, const gchar *new_path, const gchar *new_uri)
                      "string",    "No path specified",
                      NULL);
     }
-
 }
 
 static void attach (GeglOperation *operation)
diff --git a/tests/simple/test-serialize.c b/tests/simple/test-serialize.c
index df3631a..c7dca63 100644
--- a/tests/simple/test-serialize.c
+++ b/tests/simple/test-serialize.c
@@ -35,30 +35,27 @@ TestCase tests[] = {
     {"gaussian-blur", " gegl:gaussian-blur",  ""},
     {"over aux=[ text string='foo bar' ]",    " svg:src-over aux=[ gegl:text string='foo bar' width=35 
height=11 ]", ""},
     {"over aux=[text string='foo bar' ]",     " svg:src-over aux=[ gegl:text string='foo bar' width=35 
height=11 ]", ""},
-    {"over aux=[ text string={ 0='foo bar' } ]",  " svg:src-over aux=[ gegl:text string='foo bar' width=35 
height=11 ]", ""},
     {"over aux= [ ",  " svg:src-over", "No such op 'gegl:['"}, 
     /* the following cause undesired warnings on console */
-    {"over aux=[ string='foo bar' ]",         " svg:src-over", ""},
+    {"over aux=[ string='foo bar' ]",  " svg:src-over", ""},
     /* the following should have error message */
-    {"over aux=[ ",   " svg:src-over",        ""},
-    {"over aux=[ ]",  " svg:src-over",        ""},
-    {"exposure foo=2"," gegl:exposure",       "gegl:exposure has no foo property, properties: 'exposure', 
'offset', 'gamma', "},
+    {"over aux=[ ",   " svg:src-over", ""},
+    {"over aux=[ ]",  " svg:src-over", ""},
+    {"exposure foo=2"," gegl:exposure","gegl:exposure has no foo property, properties: 'exposure', 'offset', 
'gamma', "},
 
-#if 0
-    {"id=foo over aux=[ ref=foo invert ]",  " id=001 svg:src-over aux=[ ref=001 gegl:invert-linear ]", ""},
-#else
-    {"id=foo over aux=[ ref=foo invert ]",  " svg:src-over aux=[ gegl:nop gegl:invert-linear ]", ""},
-#endif
 
     {"over aux=[text string='foo bar']",      " svg:src-over aux=[ gegl:text string='foo bar' width=35 
height=11 ]", ""},
-    /* the following causes crashes */
-#if 0
-    {"over aux=[]",  " svg:src-over", "No such op 'gegl:['"},  /* should report error message */
-#endif
-    {"over aux=[ load path=/ ]",  " svg:src-over aux=[ gegl:load path='/' ]", ""},
+    {"over aux=[ load path=/ ]",    " svg:src-over aux=[ gegl:load path='/' ]", ""},
     {"inver",           "", "No such op 'gegl:inver' suggestions: gegl:invert-gamma gegl:invert-linear"},
 
     {"over aux=[ load path=/abc ]", " svg:src-over aux=[ gegl:load path='/abc' ]", ""},
+
+
+    {"id=foo over aux=[ ref=foo invert ]",  " id=foo svg:src-over aux=[ ref=foo gegl:invert-linear ]", ""},
+    {"id=bar id=foo over aux=[ ref=foo invert ]",  " id=foo svg:src-over aux=[ ref=foo gegl:invert-linear 
]", ""},
+
+    {"over aux=[ text string={ 0='foo bar' } ]", " svg:src-over aux=[ gegl:text string='foo bar' width=35 
height=11 ]", ""},
+
     {NULL, NULL}
 };
 
@@ -80,13 +77,13 @@ test_serialize (void)
     gchar *serialization = NULL;
     gegl_create_chain (tests[i].argv_chain, start, end,
                     0.0, 500, &error);
-    serialization = gegl_serialize (start, gegl_node_get_producer (end, "input", NULL));
+    serialization = gegl_serialize (start, gegl_node_get_producer (end, "input", NULL), "/");
     if (strcmp (serialization, tests[i].expected_serialization))
     {
       printf ("%s\nexpected:\n%s\nbut got:\n%s\n", 
-                      tests[i].argv_chain,
-                      tests[i].expected_serialization,
-                      serialization);
+              tests[i].argv_chain,
+              tests[i].expected_serialization,
+              serialization);
       res = FAILURE;
     }
     g_free (serialization);


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