[gegl/meta-json] TEMP: wip on property forwarding \n FIXME: must store gvalues in get/set_property
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/meta-json] TEMP: wip on property forwarding \n FIXME: must store gvalues in get/set_property
- Date: Mon, 5 Jan 2015 10:01:00 +0000 (UTC)
commit b0fbe23e15b109d262e5d0b9e1fa7627ea9ea814
Author: Jon Nordby <jononor gmail com>
Date: Mon Jan 5 11:00:35 2015 +0100
TEMP: wip on property forwarding \n FIXME: must store gvalues in get/set_property
operations/common/c2g.c | 2 +-
operations/common/gaussian-blur.c | 3 +
operations/core/json.c | 133 ++++++++++++++++++++++++-------
operations/json/dropshadow2.fbp | 10 ++-
operations/json/dropshadow2.json | 17 ++++-
operations/json/grey.fbp | 8 ++
operations/json/grey2.json | 31 +++++++-
tests/compositions/Makefile.am | 3 +-
tests/compositions/dropshadow-json.xml | 4 +-
tests/compositions/dropshadow.xml | 13 +++
tests/compositions/grey-json.xml | 14 ++++
11 files changed, 198 insertions(+), 40 deletions(-)
---
diff --git a/operations/common/c2g.c b/operations/common/c2g.c
index 74e9b5c..c8e4fe6 100644
--- a/operations/common/c2g.c
+++ b/operations/common/c2g.c
@@ -35,7 +35,7 @@ property_int (radius, _("Radius"), 300)
property_int (samples, _("Samples"), 4)
description (_("Number of samples to do per iteration looking for the range of colors"))
- value_range (1, 1000)
+ value_range (1, 1000)
ui_range (3, 17)
property_int (iterations, _("Iterations"), 10)
diff --git a/operations/common/gaussian-blur.c b/operations/common/gaussian-blur.c
index 24a0b75..52e565b 100644
--- a/operations/common/gaussian-blur.c
+++ b/operations/common/gaussian-blur.c
@@ -625,6 +625,9 @@ process (GeglOperation *operation,
gboolean horizontal_irr;
gboolean vertical_irr;
+ o->std_dev_x = 100.0;
+ o->std_dev_y = 100.0;
+
rect.x = result->x - op_area->left;
rect.width = result->width + op_area->left + op_area->right;
rect.y = result->y - op_area->top;
diff --git a/operations/core/json.c b/operations/core/json.c
index a912308..9da154b 100644
--- a/operations/core/json.c
+++ b/operations/core/json.c
@@ -45,12 +45,14 @@ typedef struct _JsonOp
GeglOperationMetaJson parent_instance;
JsonObject *json_root;
GHashTable *nodes;
+ GValue *properties;
} JsonOp;
typedef struct
{
GeglOperationMetaJsonClass parent_class;
JsonObject *json_root;
+ guint no_props;
} JsonOpClass;
@@ -133,7 +135,35 @@ set_prop(GeglNode *t, const gchar *port, GParamSpec *paramspec, GValue *value)
return FALSE;
}
-static void
+static GParamSpec *
+copy_param_spec(GParamSpec *in, const gchar *name) {
+
+ const gchar * blurb = g_param_spec_get_blurb(in);
+ GParamSpec *out = NULL;
+
+ // TODO: handle more things
+ if (G_IS_PARAM_SPEC_FLOAT(in)) {
+ GParamSpecFloat *f = G_PARAM_SPEC_FLOAT(in);
+ out = g_param_spec_double(name, name, blurb, f->minimum, f->maximum, f->default_value, in->flags);
+ } else if (G_IS_PARAM_SPEC_DOUBLE(in)) {
+ GParamSpecDouble *d = G_PARAM_SPEC_DOUBLE(in);
+ out = g_param_spec_double(name, name, blurb, d->minimum, d->maximum, d->default_value, in->flags);
+ } else if (G_IS_PARAM_SPEC_INT(in)) {
+ GParamSpecInt *i = G_PARAM_SPEC_INT(in);
+ out = g_param_spec_int(name, name, blurb, i->minimum, i->maximum, i->default_value, in->flags);
+ } else if (G_IS_PARAM_SPEC_UINT(in)) {
+ GParamSpecUInt *u = G_PARAM_SPEC_UINT(in);
+ out = g_param_spec_int(name, name, blurb, u->minimum, u->maximum, u->default_value, in->flags);
+ } else if (G_IS_PARAM_SPEC_LONG(in)) {
+ GParamSpecLong *l = G_PARAM_SPEC_LONG(in);
+ out = g_param_spec_int(name, name, blurb, l->minimum, l->maximum, l->default_value, in->flags);
+ } else {
+ g_critical("Unknown param spec type");
+ }
+ return out;
+}
+
+static guint
install_properties(JsonOpClass *json_op_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (json_op_class);
@@ -152,14 +182,28 @@ install_properties(JsonOpClass *json_op_class)
JsonObject *conn = json_object_get_object_member(inports, name);
const gchar *proc = json_object_get_string_member(conn, "process");
const gchar *port = json_object_get_string_member(conn, "port");
- GParamSpec *spec = NULL;
-
- g_print("adding property %s, pointing to %s %s\n", name, port, proc);
-
- // TODO: look up property on the class/op the port points to and use that paramspec
- spec = g_param_spec_int (name, name, "DUMMY description", 0, 1000, 1,
- (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
GEGL_PARAM_PAD_INPUT));
- g_object_class_install_property (object_class, prop++, spec);
+ JsonObject *processes = json_object_get_object_member(root, "processes");
+ JsonObject *p = json_object_get_object_member(processes, proc);
+ const gchar *component = json_object_get_string_member(p, "component");
+
+ {
+ GParamSpec *target_spec = NULL;
+ gchar *opname = component2geglop(component);
+ // HACK: should avoid instantiating node to determine prop
+ GeglNode *n = gegl_node_new();
+ g_assert(n);
+ gegl_node_set(n, "operation", opname, NULL);
+ target_spec = gegl_node_find_property(n, port);
+ if (target_spec) {
+// GParamSpec *spec = g_param_spec_override (name, target_spec);
+
+ GParamSpec *spec = copy_param_spec(target_spec, name);
+ g_print("adding property %s, pointing to %s %s\n", name, port, proc);
+ g_object_class_install_property (object_class, prop++, spec);
+ }
+ g_object_unref(n);
+ g_free(opname);
+ }
}
}
@@ -176,7 +220,7 @@ install_properties(JsonOpClass *json_op_class)
}
}
*/
-
+ return prop-1;
}
static GObject *
@@ -200,11 +244,12 @@ get_property (GObject *gobject,
GValue *value,
GParamSpec *pspec)
{
- switch (property_id)
- {
- default:
-// G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
- break;
+ JsonOpClass * json_op_class = (JsonOpClass *)G_OBJECT_GET_CLASS(gobject);
+ JsonOp * self = (JsonOp *)(gobject);
+ if (property_id <= json_op_class->no_props) {
+ g_value_copy (self->properties+property_id, value);
+ } else {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
}
}
@@ -214,11 +259,12 @@ set_property (GObject *gobject,
const GValue *value,
GParamSpec *pspec)
{
- switch (property_id)
- {
- default:
-// G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
- break;
+ JsonOpClass * json_op_class = (JsonOpClass *)G_OBJECT_GET_CLASS(gobject);
+ JsonOp * self = (JsonOp *)(gobject);
+ if (property_id <= json_op_class->no_props) {
+ g_value_copy (value, self->properties+property_id);
+ } else {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
}
}
@@ -333,6 +379,36 @@ attach (GeglOperation *operation)
}
static void
+json_op_init (JsonOp *self)
+{
+ JsonOpClass *json_op_class = (JsonOpClass *)G_OBJECT_GET_CLASS(self);
+
+ self->nodes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
+
+ const guint n = json_op_class->no_props+1;
+ self->properties = g_new(GValue, n);
+ for (int i=0; i<n; ++) {
+ g_value_unset(self->properties+i);
+ }
+}
+
+static void
+finalize (GObject *gobject)
+{
+ JsonOp *self = (JsonOp *)(gobject);
+ JsonOpClass *json_op_class = (JsonOpClass *)G_OBJECT_GET_CLASS(self);
+
+ g_hash_table_unref (self->nodes);
+
+ const guint n = json_op_class->no_props+1;
+ for (int i=0; i<n; ++) {
+ g_value_unset(self->properties+i);
+ }
+
+ G_OBJECT_GET_CLASS(gobject)->finalize (gobject);
+}
+
+static void
json_op_class_init (gpointer klass, gpointer class_data)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -343,14 +419,15 @@ json_op_class_init (gpointer klass, gpointer class_data)
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->constructor = constructor;
+ object_class->finalize = finalize;
operation_class->attach = attach;
- install_properties(json_op_class);
+ json_op_class->no_props = install_properties(json_op_class);
// FIXME: unharcode, look up in properties
gegl_operation_class_set_keys (operation_class,
- "name", "gegl:dropshadow2",
+ "name", "gegl:greyy",
"categories", "effects:light",
"description", "Creates a dropshadow effect on the input buffer",
NULL);
@@ -360,15 +437,10 @@ json_op_class_init (gpointer klass, gpointer class_data)
static void
json_op_class_finalize (JsonOpClass *self)
{
-}
-
-static void
-json_op_init (JsonOp *self)
-{
- self->nodes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref); // FIXME: free
}
+
static GType
json_op_register_type (GTypeModule *type_module, const gchar *name, gpointer klass_data)
{
@@ -408,7 +480,7 @@ json_op_register_type_for_file (GTypeModule *type_module, const gchar *filepath)
g_assert(root_node);
g_print("%s: %p\n", __PRETTY_FUNCTION__, root_node);
// FIXME: unhardoce name, look up in json structure, fallback to basename
- ret = json_op_register_type(type_module, "dropshadow_json", root);
+ ret = json_op_register_type(type_module, "grey_json", root);
}
// g_object_unref(parser);
@@ -421,7 +493,8 @@ static void
json_register_operations(GTypeModule *module)
{
// FIXME: unhardcode, follow GEGL_PATH properly
- json_op_register_type_for_file (module, JSON_OP_DIR "/dropshadow2.json");
+// json_op_register_type_for_file (module, JSON_OP_DIR "/dropshadow2.json");
+ json_op_register_type_for_file (module, JSON_OP_DIR "/grey2.json");
}
diff --git a/operations/json/dropshadow2.fbp b/operations/json/dropshadow2.fbp
index c83fbf6..5049184 100644
--- a/operations/json/dropshadow2.fbp
+++ b/operations/json/dropshadow2.fbp
@@ -2,7 +2,9 @@ INPORT=translate.X:X
INPORT=translate.Y:Y
INPORT=color.VALUE:COLOR
INPORT=blur.STD_DEV_X:RADIUS
-INPORT=input.OUTPUT:INPUT
+INPORT=opacity.VALUE:OPACITY
+
+INPORT=input.INPUT:INPUT
OUTPORT=over.OUTPUT:OUTPUT
# FIXME: multiple export mapping? INPORT=blur.STD-DEV-Y:RADIUS
@@ -13,4 +15,8 @@ input(gegl/nop) OUTPUT -> INPUT darken(gegl/src_in) OUTPUT -> INPUT blur(gegl/ga
input OUTPUT -> AUX over
color(gegl/color) OUTPUT -> AUX darken
-'rgb(0.0,0.0,0.0)' -> VALUE color
+'rgba(0.0, 0.0, 0.0, 0.0)' -> VALUE color
+'0.5' -> VALUE opacity
+'10' -> STD_DEV_Y blur
+'20' -> Y translate
+'20' -> X translate
diff --git a/operations/json/dropshadow2.json b/operations/json/dropshadow2.json
index e247d02..b7ad9df 100644
--- a/operations/json/dropshadow2.json
+++ b/operations/json/dropshadow2.json
@@ -100,11 +100,18 @@
}
},
{
- "data": "rgb(0.0,0.0,0.0)",
+ "data": "rgba(0.0, 0.0, 0.0, 0.0)",
"tgt": {
"process": "color",
"port": "value"
}
+ },
+ {
+ "data": "0.5",
+ "tgt": {
+ "process": "opacity",
+ "port": "value"
+ }
}
],
"inports": {
@@ -122,11 +129,15 @@
},
"radius": {
"process": "blur",
- "port": "std_dev_x"
+ "port": "std-dev-x"
+ },
+ "opacity": {
+ "process": "opacity",
+ "port": "value"
},
"input": {
"process": "input",
- "port": "output"
+ "port": "input"
}
},
"outports": {
diff --git a/operations/json/grey.fbp b/operations/json/grey.fbp
new file mode 100644
index 0000000..9e0596b
--- /dev/null
+++ b/operations/json/grey.fbp
@@ -0,0 +1,8 @@
+INPORT=in.INPUT:INPUT
+OUTPORT=out.OUTPUT:OUTPUT
+INPORT=g.SAMPLES:SAMPLES
+INPORT=g.ITERATIONS:ITERATIONS
+INPORT=tr.HEIGHT:HEIGHT
+INPORT=tr.WIDTH:WIDTH
+
+in(gegl/nop) OUTPUT -> INPUT g(gegl/c2g) OUTPUT -> INPUT tr(gegl/crop) OUTPUT -> INPUT out(gegl/nop)
diff --git a/operations/json/grey2.json b/operations/json/grey2.json
index 89eb789..a2934a4 100644
--- a/operations/json/grey2.json
+++ b/operations/json/grey2.json
@@ -4,7 +4,10 @@
"component": "gegl/nop"
},
"g": {
- "component": "gegl/grey"
+ "component": "gegl/c2g"
+ },
+ "tr": {
+ "component": "gegl/crop"
},
"out": {
"component": "gegl/nop"
@@ -27,6 +30,16 @@
"port": "output"
},
"tgt": {
+ "process": "tr",
+ "port": "input"
+ }
+ },
+ {
+ "src": {
+ "process": "tr",
+ "port": "output"
+ },
+ "tgt": {
"process": "out",
"port": "input"
}
@@ -36,6 +49,22 @@
"input": {
"process": "in",
"port": "input"
+ },
+ "samples": {
+ "process": "g",
+ "port": "samples"
+ },
+ "iterations": {
+ "process": "g",
+ "port": "iterations"
+ },
+ "height": {
+ "process": "tr",
+ "port": "height"
+ },
+ "width": {
+ "process": "tr",
+ "port": "width"
}
},
"outports": {
diff --git a/tests/compositions/Makefile.am b/tests/compositions/Makefile.am
index b6217c6..6281bf6 100644
--- a/tests/compositions/Makefile.am
+++ b/tests/compositions/Makefile.am
@@ -79,7 +79,8 @@ if HAVE_UMFPACK
TESTS += matting-levin.xml
endif
-TESTS=dropshadow-json.xml
+# TESTS=dropshadow.xml dropshadow-json.xml
+TESTS=grey-json.xml
check-TESTS: $(TESTS)
$(PYTHON) $(srcdir)/run-compositions.py \
diff --git a/tests/compositions/dropshadow-json.xml b/tests/compositions/dropshadow-json.xml
index ac5d2e1..59a38ef 100644
--- a/tests/compositions/dropshadow-json.xml
+++ b/tests/compositions/dropshadow-json.xml
@@ -2,12 +2,12 @@
<gegl>
<node operation='gegl:dropshadow2'>
<params>
- <param name='radius'>10</param>
+ <param name='radius'>100</param>
</params>
</node>
<node operation='gegl:load'>
<params>
- <param name='path'>data/car-stack.png</param>
+ <param name='path'>data/gegl.png</param>
</params>
</node>
</gegl>
diff --git a/tests/compositions/dropshadow.xml b/tests/compositions/dropshadow.xml
new file mode 100644
index 0000000..9c8b9c0
--- /dev/null
+++ b/tests/compositions/dropshadow.xml
@@ -0,0 +1,13 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<gegl>
+ <node operation='gegl:dropshadow'>
+ <params>
+ <param name='radius'>10</param>
+ </params>
+ </node>
+ <node operation='gegl:load'>
+ <params>
+ <param name='path'>data/car-stack.png</param>
+ </params>
+ </node>
+</gegl>
diff --git a/tests/compositions/grey-json.xml b/tests/compositions/grey-json.xml
new file mode 100644
index 0000000..8f8ab41
--- /dev/null
+++ b/tests/compositions/grey-json.xml
@@ -0,0 +1,14 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<gegl>
+ <node operation='gegl:greyy'>
+ <params>
+ <param name='height'>100</param>
+ <param name='width'>100</param>
+ </params>
+ </node>
+ <node operation='gegl:load'>
+ <params>
+ <param name='path'>data/car-stack.png</param>
+ </params>
+ </node>
+</gegl>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]