[gegl] add GeglParamSpecFormat



commit 41abf5a4ca79455c5b259535ad77e83c74d76ec0
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Mon Sep 30 15:38:00 2013 -0700

    add GeglParamSpecFormat

 gegl/gegl-chant.h                     |   28 +++++++++++++++++
 gegl/gegl-xml.c                       |   22 +++++++++++++
 gegl/property-types/gegl-paramspecs.c |   55 +++++++++++++++++++++++++++++++++
 gegl/property-types/gegl-paramspecs.h |   33 +++++++++++++++++++-
 4 files changed, 137 insertions(+), 1 deletions(-)
---
diff --git a/gegl/gegl-chant.h b/gegl/gegl-chant.h
index 09c2703..4920dee 100644
--- a/gegl/gegl-chant.h
+++ b/gegl/gegl-chant.h
@@ -346,6 +346,7 @@ gegl_module_register (GTypeModule *module)
 #define gegl_chant_multiline(name, nick, def, blurb)
 #define gegl_chant_object(name,nick,  blurb)
 #define gegl_chant_pointer(name, nick, blurb)
+#define gegl_chant_format(name, nick, blurb)
 #define gegl_chant_color(name, nick, def, blurb)
 #define gegl_chant_curve(name, nick, blurb)
 #define gegl_chant_seed(name, nick, blurb)
@@ -398,6 +399,7 @@ GType enum_name ## _get_type (void)               \
 #undef gegl_chant_multiline
 #undef gegl_chant_object
 #undef gegl_chant_pointer
+#undef gegl_chant_format
 #undef gegl_chant_color
 #undef gegl_chant_curve
 #undef gegl_chant_seed
@@ -429,6 +431,7 @@ struct _GeglChantO
 #define gegl_chant_multiline(name, nick, def, blurb)                            gchar             *name;
 #define gegl_chant_object(name,nick,  blurb)                                    GObject           *name;
 #define gegl_chant_pointer(name, nick, blurb)                                   gpointer           name;
+#define gegl_chant_format(name, nick, blurb)                                    gpointer           name;
 #define gegl_chant_color(name, nick, def, blurb)                                GeglColor         *name;
 #define gegl_chant_curve(name, nick, blurb)                                     GeglCurve         *name;
 #define gegl_chant_seed(name, nick, blurb)                                      gint               name;
@@ -448,6 +451,7 @@ struct _GeglChantO
 #undef gegl_chant_multiline
 #undef gegl_chant_object
 #undef gegl_chant_pointer
+#undef gegl_chant_format
 #undef gegl_chant_color
 #undef gegl_chant_curve
 #undef gegl_chant_seed
@@ -470,6 +474,7 @@ enum
 #define gegl_chant_multiline(name, nick, def, blurb)                            PROP_##name,
 #define gegl_chant_object(name, nick, blurb)                                    PROP_##name,
 #define gegl_chant_pointer(name, nick, blurb)                                   PROP_##name,
+#define gegl_chant_format(name, nick, blurb)                                    PROP_##name,
 #define gegl_chant_color(name, nick, def, blurb)                                PROP_##name,
 #define gegl_chant_curve(name, nick, blurb)                                     PROP_##name,
 #define gegl_chant_seed(name, nick, blurb)                                      PROP_##name,
@@ -488,6 +493,7 @@ enum
 #undef gegl_chant_multiline
 #undef gegl_chant_object
 #undef gegl_chant_pointer
+#undef gegl_chant_format
 #undef gegl_chant_color
 #undef gegl_chant_curve
 #undef gegl_chant_seed
@@ -551,6 +557,10 @@ get_property (GObject      *gobject,
     case PROP_##name:                                         \
       g_value_set_pointer (value, properties->name);          \
       break;
+#define gegl_chant_format(name, nick, blurb)                 \
+    case PROP_##name:                                         \
+      g_value_set_pointer (value, properties->name);          \
+      break;
 #define gegl_chant_color(name, nick, def, blurb)              \
     case PROP_##name:                                         \
       g_value_set_object (value, properties->name);           \
@@ -581,6 +591,7 @@ get_property (GObject      *gobject,
 #undef gegl_chant_multiline
 #undef gegl_chant_object
 #undef gegl_chant_pointer
+#undef gegl_chant_format
 #undef gegl_chant_color
 #undef gegl_chant_curve
 #undef gegl_chant_seed
@@ -656,6 +667,10 @@ set_property (GObject      *gobject,
     case PROP_##name:                                                 \
       properties->name = g_value_get_pointer (value);                 \
       break;
+#define gegl_chant_format(name, nick, blurb)                          \
+    case PROP_##name:                                                 \
+      properties->name = g_value_get_pointer (value);                 \
+      break;
 #define gegl_chant_color(name, nick, def, blurb)                      \
     case PROP_##name:                                                 \
       if (properties->name != NULL)                                   \
@@ -704,6 +719,7 @@ set_property (GObject      *gobject,
 #undef gegl_chant_multiline
 #undef gegl_chant_object
 #undef gegl_chant_pointer
+#undef gegl_chant_format
 #undef gegl_chant_color
 #undef gegl_chant_curve
 #undef gegl_chant_seed
@@ -752,6 +768,7 @@ static void gegl_chant_destroy_notify (gpointer data)
       properties->name = NULL;                      \
     }
 #define gegl_chant_pointer(name, nick, blurb)
+#define gegl_chant_format(name, nick, blurb)
 #define gegl_chant_color(name, nick, def, blurb)    \
   if (properties->name)                             \
     {                                               \
@@ -785,6 +802,7 @@ static void gegl_chant_destroy_notify (gpointer data)
 #undef gegl_chant_multiline
 #undef gegl_chant_object
 #undef gegl_chant_pointer
+#undef gegl_chant_format
 #undef gegl_chant_color
 #undef gegl_chant_curve
 #undef gegl_chant_seed
@@ -818,6 +836,7 @@ gegl_chant_constructor (GType                  type,
 #define gegl_chant_multiline(name, nick, def, blurb)
 #define gegl_chant_object(name, nick, blurb)
 #define gegl_chant_pointer(name, nick, blurb)
+#define gegl_chant_format(name, nick, blurb)
 #define gegl_chant_color(name, nick, def, blurb)              \
     if (properties->name == NULL) \
     {properties->name = gegl_color_new(def?def:"black");}
@@ -838,6 +857,7 @@ gegl_chant_constructor (GType                  type,
 #undef gegl_chant_multiline
 #undef gegl_chant_object
 #undef gegl_chant_pointer
+#undef gegl_chant_format
 #undef gegl_chant_color
 #undef gegl_chant_curve
 #undef gegl_chant_seed
@@ -946,6 +966,13 @@ gegl_chant_class_intern_init (gpointer klass)
                                                         G_PARAM_READWRITE |  \
                                                         G_PARAM_CONSTRUCT |  \
                                                         GEGL_PARAM_PAD_INPUT)));
+#define gegl_chant_format(name, nick, blurb)                                 \
+  g_object_class_install_property (object_class, PROP_##name,                \
+                                   gegl_param_spec_format (#name, nick, blurb, \
+                                                          (GParamFlags) (      \
+                                                          G_PARAM_READWRITE |  \
+                                                          G_PARAM_CONSTRUCT |  \
+                                                          GEGL_PARAM_PAD_INPUT)));
 #define gegl_chant_color(name, nick, def, blurb)                             \
   g_object_class_install_property (object_class, PROP_##name,                \
                                    gegl_param_spec_color_from_string (#name, nick, blurb,\
@@ -993,6 +1020,7 @@ gegl_chant_class_intern_init (gpointer klass)
 #undef gegl_chant_multiline
 #undef gegl_chant_object
 #undef gegl_chant_pointer
+#undef gegl_chant_format
 #undef gegl_chant_color
 #undef gegl_chant_curve
 #undef gegl_chant_seed
diff --git a/gegl/gegl-xml.c b/gegl/gegl-xml.c
index dd035a5..f66c62a 100644
--- a/gegl/gegl-xml.c
+++ b/gegl/gegl-xml.c
@@ -211,6 +211,16 @@ set_clone_prop_as_well:
           gegl_path_parse_string (path, param_value);
           gegl_node_set (new, param_name, path, NULL);
         }
+      else if (paramspec->value_type == G_TYPE_POINTER &&
+               GEGL_IS_PARAM_SPEC_FORMAT (paramspec))
+        {
+          const Babl *format = NULL;
+
+          if (strlen (param_value))
+            format = babl_format (param_value);
+
+          gegl_node_set (new, param_name, format, NULL);
+        }
       else
         {
           g_warning ("operation desired unknown parapspec type for %s",
@@ -884,6 +894,18 @@ serialize_properties (SerializeState *ss,
 
               g_object_unref (path);
             }
+          else if (properties[i]->value_type == G_TYPE_POINTER &&
+                   GEGL_IS_PARAM_SPEC_FORMAT (properties[i]))
+            {
+              const Babl  *format;
+              const gchar *value;
+              gegl_node_get (node, properties[i]->name, &format, NULL);
+              if (format)
+                value = babl_get_name (format);
+              else
+                value = "";
+              xml_param (ss, indent + 2, properties[i]->name, value);
+            }
           else
             {
               g_warning ("%s: serialization of %s properties not implemented",
diff --git a/gegl/property-types/gegl-paramspecs.c b/gegl/property-types/gegl-paramspecs.c
index cd4abe6..0652667 100644
--- a/gegl/property-types/gegl-paramspecs.c
+++ b/gegl/property-types/gegl-paramspecs.c
@@ -685,3 +685,58 @@ gegl_param_spec_seed (const gchar *name,
 
   return G_PARAM_SPEC (pspec);
 }
+
+/*
+ * GEGL_TYPE_PARAM_FORMAT
+ */
+
+static void       gegl_param_format_class_init (GParamSpecClass *klass);
+static void       gegl_param_format_init       (GParamSpec      *pspec);
+
+GType
+gegl_param_format_get_type (void)
+{
+  static GType type = 0;
+
+  if (!type)
+    {
+      const GTypeInfo info =
+      {
+        sizeof (GParamSpecClass),
+        NULL, NULL,
+        (GClassInitFunc) gegl_param_format_class_init,
+        NULL, NULL,
+        sizeof (GeglParamSpecFormat),
+        0,
+        (GInstanceInitFunc) gegl_param_format_init
+      };
+      type = g_type_register_static (G_TYPE_PARAM_POINTER,
+                                     "GeglParamFormat", &info, 0);
+    }
+  return type;
+}
+
+static void
+gegl_param_format_class_init (GParamSpecClass *klass)
+{
+  klass->value_type = G_TYPE_POINTER;
+}
+
+static void
+gegl_param_format_init (GParamSpec *pspec)
+{
+}
+
+GParamSpec *
+gegl_param_spec_format (const gchar *name,
+                        const gchar *nick,
+                        const gchar *blurb,
+                        GParamFlags  flags)
+{
+  GeglParamSpecFormat *pspec;
+
+  pspec = g_param_spec_internal (GEGL_TYPE_PARAM_FORMAT,
+                                 name, nick, blurb, flags);
+
+  return G_PARAM_SPEC (pspec);
+}
diff --git a/gegl/property-types/gegl-paramspecs.h b/gegl/property-types/gegl-paramspecs.h
index 350d551..6142e46 100644
--- a/gegl/property-types/gegl-paramspecs.h
+++ b/gegl/property-types/gegl-paramspecs.h
@@ -36,7 +36,7 @@ typedef struct _GeglParamSpecString GeglParamSpecString;
 typedef struct _GeglParamSpecDouble GeglParamSpecDouble;
 typedef struct _GeglParamSpecInt    GeglParamSpecInt;
 typedef struct _GeglParamSpecSeed   GeglParamSpecSeed;
-
+typedef struct _GeglParamSpecFormat GeglParamSpecFormat;
 
 
 /*
@@ -343,5 +343,36 @@ GParamSpec * gegl_param_spec_seed (const gchar *name,
                                    const gchar *blurb,
                                    GParamFlags  flags);
 
+/*
+ * GEGL_TYPE_PARAM_FORMAT
+ */
+
+#define GEGL_TYPE_PARAM_FORMAT           (gegl_param_format_get_type ())
+#define GEGL_PARAM_SPEC_FORMAT(pspec)    (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GEGL_TYPE_PARAM_FORMAT, 
GeglParamSpecFormat))
+#define GEGL_IS_PARAM_SPEC_FORMAT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GEGL_TYPE_PARAM_FORMAT))
+
+struct _GeglParamSpecFormat
+{
+  GParamSpecPointer parent_instance;
+};
+
+GType        gegl_param_format_get_type (void) G_GNUC_CONST;
+
+/**
+ * gegl_param_spec_format:
+ * @name: canonical name of the property specified
+ * @nick: nick name for the property specified
+ * @blurb: description of the property specified
+ * @flags: flags for the property specified
+ *
+ * Creates a new #GeglParamSpecFormat instance specifying a Babl format.
+ *
+ * Returns: (transfer full): a newly created parameter specification
+ */
+GParamSpec * gegl_param_spec_format (const gchar *name,
+                                     const gchar *nick,
+                                     const gchar *blurb,
+                                     GParamFlags  flags);
+
 G_END_DECLS
 #endif  /*  __GEGL_PARAM_SPECS_H__  */


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