[gegl] gegl_serialize add flags



commit 52f01ba49e2246df24a504084863b12794682d37
Author: Øyvind Kolås <pippin gimp org>
Date:   Sun Mar 26 04:42:25 2017 +0200

    gegl_serialize add flags
    
    This is API breakage - but the abi would break in compatible ways and the api
    is recent enough that not much code should start rotting because of this
    change.

 bin/gegl.c                         |    3 ++-
 bin/ui.c                           |    4 ++--
 gegl/gegl-serialize.c              |   24 +++++++++++++-----------
 gegl/gegl-utils.h                  |    7 ++++++-
 gegl/opencl/gegl-cl-init.c         |    1 +
 operations/common/newsprint.c      |    2 +-
 tests/simple/test-buffer-sharing.c |   18 +++++++++++-------
 tests/simple/test-serialize.c      |    2 +-
 8 files changed, 37 insertions(+), 24 deletions(-)
---
diff --git a/bin/gegl.c b/bin/gegl.c
index d0777b1..d6cdc40 100644
--- a/bin/gegl.c
+++ b/bin/gegl.c
@@ -220,7 +220,8 @@ main (gint    argc,
       if (o->serialize)
       {
         fprintf (stderr, "%s\n", gegl_serialize (iter,
-            gegl_node_get_producer (proxy, "input", NULL), "/"));
+            gegl_node_get_producer (proxy, "input", NULL), "/",
+            GEGL_SERIALIZE_TRIM_DEFAULTS));
       }
     }
   }
diff --git a/bin/ui.c b/bin/ui.c
index 8f49139..f148611 100644
--- a/bin/ui.c
+++ b/bin/ui.c
@@ -44,7 +44,7 @@
 
 /* set this to 1 to print the active gegl chain
  */
-//#define DEBUG_OP_LIST  1
+// #define DEBUG_OP_LIST  1
 
 
 static int audio_len    = 0;
@@ -1938,7 +1938,7 @@ static void save_cb (MrgEvent *event, void *data1, void *data2)
   gegl_node_link_many (load, o->source, NULL);
   {
     char *containing_path = get_path_parent (o->path);
-    serialized = gegl_serialize (NULL, o->sink, containing_path);
+    serialized = gegl_serialize (NULL, o->sink, containing_path, GEGL_SERIALIZE_TRIM_DEFAULTS);
     free (containing_path);
   }
   gegl_node_remove_child (o->gegl, load);
diff --git a/gegl/gegl-serialize.c b/gegl/gegl-serialize.c
index e4d01a2..a258a91 100644
--- a/gegl/gegl-serialize.c
+++ b/gegl/gegl-serialize.c
@@ -492,9 +492,10 @@ void gegl_create_chain (const char *str, GeglNode *op_start, GeglNode *op_end, d
   }
 }
 
-static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basepath, GHashTable *ht)
+static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basepath, GHashTable *ht, 
GeglSerializeFlag flags)
 {
   char *ret = NULL;
+  gboolean trim_defaults = flags & GEGL_SERIALIZE_TRIM_DEFAULTS;
   GeglNode *iter;
 
   GString *str = g_string_new ("");
@@ -575,7 +576,7 @@ static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basep
               gfloat value;
               gchar  str[G_ASCII_DTOSTR_BUF_SIZE];
               gegl_node_get (iter, properties[i]->name, &value, NULL);
-              if (value != defval)
+              if (value != defval || (!trim_defaults))
               {
                 g_ascii_dtostr (str, sizeof(str), value);
                 g_string_append_printf (s2, " %s=%s", property_name, str);
@@ -587,7 +588,7 @@ static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basep
               gdouble value;
               gchar   str[G_ASCII_DTOSTR_BUF_SIZE];
               gegl_node_get (iter, property_name, &value, NULL);
-              if (value != defval)
+              if (value != defval || (!trim_defaults))
               {
                 g_ascii_dtostr (str, sizeof(str), value);
                 g_string_append_printf (s2, " %s=%s", property_name, str);
@@ -599,7 +600,7 @@ static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basep
               gint  value;
               gchar str[64];
               gegl_node_get (iter, properties[i]->name, &value, NULL);
-              if (value != defval)
+              if (value != defval || (!trim_defaults))
               {
                 g_snprintf (str, sizeof (str), "%i", value);
                 g_string_append_printf (s2, " %s=%s", property_name, str);
@@ -610,7 +611,7 @@ static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basep
               gboolean value;
               gboolean defval = g_value_get_boolean (default_value);
               gegl_node_get (iter, properties[i]->name, &value, NULL);
-              if (value != defval)
+              if (value != defval || (!trim_defaults))
               {
                 if (value)
                   g_string_append_printf (s2, " %s=true", property_name);
@@ -623,7 +624,7 @@ static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basep
               gchar *value;
               const gchar *defval = g_value_get_string (default_value);
               gegl_node_get (iter, properties[i]->name, &value, NULL);
-              if (!g_str_equal (defval, value))
+              if (!g_str_equal (defval, value) || (!trim_defaults))
               {
                 g_string_append_printf (s2, " %s='%s'", property_name, value);
               }
@@ -636,7 +637,7 @@ static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basep
               gint value;
 
               gegl_node_get (iter, properties[i]->name, &value, NULL);
-              if (value != defval)
+              if (value != defval || (!trim_defaults))
               {
                 GEnumValue *evalue = g_enum_get_value (eclass, value);
                 g_string_append_printf (s2, " %s=%s", property_name, evalue->value_nick);
@@ -655,7 +656,7 @@ static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basep
                 g_object_get (defcolor, "string", &defvalue, NULL);
               }
               g_object_unref (color);
-              if (defvalue && !g_str_equal (defvalue, value))
+              if ((defvalue && !g_str_equal (defvalue, value)) || (!trim_defaults))
                 g_string_append_printf (s2, " %s='%s'", property_name, value);
               g_free (value);
             }
@@ -670,7 +671,7 @@ static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basep
             GeglNode *aux = gegl_node_get_producer (iter, "aux", NULL);
             if (aux)
             {
-              char *str = gegl_serialize2 (NULL, aux, basepath, ht);
+              char *str = gegl_serialize2 (NULL, aux, basepath, ht, flags);
               g_string_append_printf (s2, " aux=[%s ]", str);
               g_free (str);
             }
@@ -690,13 +691,14 @@ static gchar *gegl_serialize2 (GeglNode *start, GeglNode *end, const char *basep
   return ret;
 }
 
-gchar *gegl_serialize (GeglNode *start, GeglNode *end, const char *basepath)
+gchar *gegl_serialize (GeglNode *start, GeglNode *end, const char *basepath,
+                       GeglSerializeFlag flags)
 {
   gchar *ret;
   gchar *ret2;
 
   GHashTable *ht = g_hash_table_new (g_direct_hash, g_direct_equal);
-  ret = gegl_serialize2 (start, end, basepath, ht);
+  ret = gegl_serialize2 (start, end, basepath, ht, flags);
   g_hash_table_destroy (ht);
   ret2 = ret;
   while (ret2[0] == ' ')
diff --git a/gegl/gegl-utils.h b/gegl/gegl-utils.h
index 6b51447..62ba75b 100644
--- a/gegl/gegl-utils.h
+++ b/gegl/gegl-utils.h
@@ -260,11 +260,16 @@ gint        _gegl_float_epsilon_zero  (float     value);
 gint        _gegl_float_epsilon_equal (float     v1,
                                        float     v2);
 
+typedef enum GeglSerializeFlag {
+  GEGL_SERIALIZE_TRIM_DEFAULTS = (1<<0),
+  GEGL_SERIALIZE_VERSION       = (1<<1)
+} GeglSerializeFlag;
+
 /**
   */
 void gegl_create_chain_argv (char **ops, GeglNode *start, GeglNode *proxy, double time, int rel_dim, GError 
**error);
 void gegl_create_chain (const char *str, GeglNode *op_start, GeglNode *op_end, double time, int rel_dim, 
GError **error);
-gchar *gegl_serialize         (GeglNode *start, GeglNode *end, const char *basepath);
+gchar *gegl_serialize         (GeglNode *start, GeglNode *end, const char *basepath, GeglSerializeFlag 
serialize_flags);
 GeglNode *gegl_node_new_from_serialized (const gchar *xmldata,
                                          const gchar *path_root);
 
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index a5eb95c..eb08296 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -843,6 +843,7 @@ gegl_cl_compile_and_build (const char *program_source, const char *kernel_name[]
           GEGL_NOTE (GEGL_DEBUG_OPENCL, "Build Error: %s\n%s",
                                         gegl_cl_errstring (build_errcode),
                                         msg);
+          g_warning ("%s\n%s\n", gegl_cl_errstring (build_errcode), msg);
           g_free (msg);
           return NULL;
         }
diff --git a/operations/common/newsprint.c b/operations/common/newsprint.c
index e2852a3..34f56b5 100644
--- a/operations/common/newsprint.c
+++ b/operations/common/newsprint.c
@@ -25,7 +25,7 @@ enum_start (gegl_newsprint_pattern)
   enum_value (GEGL_NEWSPRINT_PATTERN_LINE,     "line",     N_("Line"))
   enum_value (GEGL_NEWSPRINT_PATTERN_CIRCLE,   "circle",   N_("Circle"))
   enum_value (GEGL_NEWSPRINT_PATTERN_DIAMOND,  "diamond",  N_("Diamond"))
-  enum_value (GEGL_NEWSPRINT_PATTERN_PSCIRCLE, "psquare",  N_("Square (or Euclidian) dot"))
+  enum_value (GEGL_NEWSPRINT_PATTERN_PSCIRCLE, "pssquare", N_("PSSquare (or Euclidian) dot"))
   enum_value (GEGL_NEWSPRINT_PATTERN_CROSS,    "cross",    N_("Orthogonal Lines"))
 enum_end (GeglNewsprintPattern)
 
diff --git a/tests/simple/test-buffer-sharing.c b/tests/simple/test-buffer-sharing.c
index 245f089..a6c5911 100644
--- a/tests/simple/test-buffer-sharing.c
+++ b/tests/simple/test-buffer-sharing.c
@@ -57,7 +57,7 @@ assert_color_equal(GeglColor *expect, GeglColor *actual) {
     unsigned char a[4];
     gegl_color_get_pixel(expect, format, (gpointer)e);
     gegl_color_get_pixel(actual, format, (gpointer)a);
-
+    {
     const gboolean equal =
         a[0] == e[0] &&
         a[1] == e[1] &&
@@ -71,6 +71,7 @@ assert_color_equal(GeglColor *expect, GeglColor *actual) {
         g_print("\n");
         return FALSE;
     }
+    }
     return TRUE;
 }
 
@@ -80,8 +81,8 @@ buffer_get_color(GeglBuffer *buffer) {
     guint8 pixel[4];
     GeglRectangle r = { 0, 0, 1, pixels };
     const Babl *format = babl_format("R'G'B'A u8");
-    gegl_buffer_get(buffer, &r, 1.0, format, (gpointer)(pixel), GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
     GeglColor *color = gegl_color_new(NULL);
+    gegl_buffer_get(buffer, &r, 1.0, format, (gpointer)(pixel), GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
     gegl_color_set_pixel(color, format, (gpointer)pixel);
     return color;
 }
@@ -164,8 +165,12 @@ on_timeout(gpointer user_data) {
     return FALSE;
 }
 
+#include <unistd.h>
+
 static void
 test_init(TestData *data) {
+    GeglRectangle rect = { 0, 0, 100, 100 };
+    GeglColor *blank = gegl_color_new("transparent");
 
     data->loop = g_main_loop_new(NULL, TRUE);
     data->temp_dir = g_strdup("test-buffer-sharing-XXXXXX");
@@ -174,8 +179,6 @@ test_init(TestData *data) {
 
     data->a = gegl_buffer_open(data->file_path);
     // FIXME: if not setting an extent and adding some data, the written on-disk file seems to be corrupt
-    GeglRectangle rect = { 0, 0, 100, 100 };
-    GeglColor *blank = gegl_color_new("transparent");
     gegl_buffer_set_extent(data->a, &rect);
     gegl_buffer_set_color(data->a, &rect, blank);
     gegl_buffer_flush(data->a); // ensure file exists on disk
@@ -186,7 +189,7 @@ test_init(TestData *data) {
     data->b = gegl_buffer_open(data->file_path);
     data->state = TestInitialized;
 
-    gegl_buffer_signal_connect(data->b, "changed", on_buffer_changed, data);
+    gegl_buffer_signal_connect(data->b, "changed", (void*)on_buffer_changed, data);
     g_timeout_add_seconds(10, on_timeout, data);
 }
 
@@ -207,16 +210,17 @@ int
 main (int    argc,
       char  *argv[])
 {
+    int exitcode;
     TestData test;
-    gegl_init (&argc, &argv);
     TestData *data = &test;
+    gegl_init (&argc, &argv);
 
     test_init(data);
 
     test_change_state(data, TestSetBlue);
 
     g_main_loop_run(data->loop);
-    const int exitcode = (data->state == TestSucceed) ? 0 : 1;
+    exitcode = (data->state == TestSucceed) ? 0 : 1;
     g_print("%s\n", (data->state == TestSucceed) ? "PASS" : "FAIL");
     test_destroy(data);
     return exitcode;
diff --git a/tests/simple/test-serialize.c b/tests/simple/test-serialize.c
index ed8eba5..63713d8 100644
--- a/tests/simple/test-serialize.c
+++ b/tests/simple/test-serialize.c
@@ -124,7 +124,7 @@ 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), "/", 
GEGL_SERIALIZE_TRIM_DEFAULTS);
     if (strcmp (serialization, tests[i].expected_serialization))
     {
       printf ("%s\nexpected:\n%s\nbut got:\n%s\n", 


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