[gegl] gegl-binary: factor out commandline to chain builder in a function
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] gegl-binary: factor out commandline to chain builder in a function
- Date: Sat, 5 Mar 2016 10:34:11 +0000 (UTC)
commit 96e606bfee76e09cca72c1fedce22a85177d7027
Author: Øyvind Kolås <pippin gimp org>
Date: Sat Mar 5 10:12:11 2016 +0100
gegl-binary: factor out commandline to chain builder in a function
bin/gegl.c | 162 +++++++++++++++++++++++++++++++-----------------------------
bin/ui.c | 15 ++----
2 files changed, 87 insertions(+), 90 deletions(-)
---
diff --git a/bin/gegl.c b/bin/gegl.c
index becb288..defc966 100644
--- a/bin/gegl.c
+++ b/bin/gegl.c
@@ -76,6 +76,7 @@ static gboolean file_is_gegl_xml (const gchar *path)
return FALSE;
}
+
int mrg_ui_main (int argc, char **argv, char **ops);
gint
@@ -192,85 +193,9 @@ main (gint argc,
if (o->rest)
{
- GeglNode *proxy;
- GeglNode *iter;
- GeglNode *new = NULL;
-
- gchar **operation = o->rest;
- char *curop = *operation;
- proxy = gegl_node_get_output_proxy (gegl, "output");
- iter = gegl_node_get_producer (proxy, "input", NULL);
-
- while (*operation)
- {
- if (strchr (*operation, '='))
- {
- GType target_type = G_TYPE_INT;
- GValue gvalue={0,};
- char *key = g_strdup (*operation);
- char *value = strchr (key, '=') + 1;
- unsigned int n_props;
- GParamSpec **pspecs = gegl_operation_list_properties (curop, &n_props);
- int i;
-
- value[-1] = '\0';
- for (i = 0; i < n_props; i++)
- {
- if (!strcmp (pspecs[i]->name, key))
- target_type = pspecs[i]->value_type;
- }
- if (target_type == G_TYPE_DOUBLE || target_type == G_TYPE_FLOAT)
- {
- double val = g_strtod (value, NULL);
- gegl_node_set (iter, key, val, NULL);
- }
- else if (target_type == G_TYPE_BOOLEAN) {
- if (!strcmp (value, "true") || !strcmp (value, "TRUE") ||
- !strcmp (value, "YES") || !strcmp (value, "yes") ||
- !strcmp (value, "y") || !strcmp (value, "Y") ||
- !strcmp (value, "1") || !strcmp (value, "on"))
- {
- gegl_node_set (iter, key, TRUE, NULL);
- }
- else
- {
- gegl_node_set (iter, key, FALSE, NULL);
- }
- }
- else if (target_type == G_TYPE_INT)
- {
- int val = g_strtod (value, NULL);
- gegl_node_set (iter, key, val, NULL);
- }
- else
- {
- GValue gvalue_transformed={0,};
- g_value_init (&gvalue, G_TYPE_STRING);
- g_value_set_string (&gvalue, value);
- g_value_init (&gvalue_transformed, target_type);
- g_value_transform (&gvalue, &gvalue_transformed);
- gegl_node_set_property (iter, key, &gvalue_transformed);
- g_value_unset (&gvalue);
- g_value_unset (&gvalue_transformed);
- }
- g_free (key);
- }
- else if (strchr (*operation, ':'))
- {
- curop = *operation;
- new = gegl_node_new_child (gegl, "operation", curop, NULL);
- if (iter)
- {
- gegl_node_link_many (iter, new, proxy, NULL);
- }
- else
- {
- gegl_node_link_many (new, proxy, NULL);
- }
- iter = new;
- }
- operation++;
- }
+ GeglNode *proxy = gegl_node_get_output_proxy (gegl, "output");
+ GeglNode *iter = gegl_node_get_producer (proxy, "input", NULL);
+ gegl_create_chain (o->rest, iter, proxy);
}
switch (o->mode)
@@ -353,3 +278,82 @@ main (gint argc,
gegl_exit ();
return 0;
}
+
+void gegl_create_chain (char **ops, GeglNode *iter, GeglNode *proxy);
+void gegl_create_chain (char **ops, GeglNode *iter, GeglNode *proxy)
+{
+ GeglNode *new = NULL;
+ gchar **operation = ops;
+ char *curop = *operation;
+
+ while (*operation)
+ {
+ if (strchr (*operation, '='))
+ {
+ GType target_type = G_TYPE_INT;
+ GValue gvalue={0,};
+ char *key = g_strdup (*operation);
+ char *value = strchr (key, '=') + 1;
+ unsigned int n_props;
+ GParamSpec **pspecs = gegl_operation_list_properties (curop, &n_props);
+ int i;
+
+ value[-1] = '\0';
+ for (i = 0; i < n_props; i++)
+ {
+ if (!strcmp (pspecs[i]->name, key))
+ target_type = pspecs[i]->value_type;
+ }
+ if (target_type == G_TYPE_DOUBLE || target_type == G_TYPE_FLOAT)
+ {
+ double val = g_strtod (value, NULL);
+ gegl_node_set (iter, key, val, NULL);
+ }
+ else if (target_type == G_TYPE_BOOLEAN) {
+ if (!strcmp (value, "true") || !strcmp (value, "TRUE") ||
+ !strcmp (value, "YES") || !strcmp (value, "yes") ||
+ !strcmp (value, "y") || !strcmp (value, "Y") ||
+ !strcmp (value, "1") || !strcmp (value, "on"))
+ {
+ gegl_node_set (iter, key, TRUE, NULL);
+ }
+ else
+ {
+ gegl_node_set (iter, key, FALSE, NULL);
+ }
+ }
+ else if (target_type == G_TYPE_INT)
+ {
+ int val = g_strtod (value, NULL);
+ gegl_node_set (iter, key, val, NULL);
+ }
+ else
+ {
+ GValue gvalue_transformed={0,};
+ g_value_init (&gvalue, G_TYPE_STRING);
+ g_value_set_string (&gvalue, value);
+ g_value_init (&gvalue_transformed, target_type);
+ g_value_transform (&gvalue, &gvalue_transformed);
+ gegl_node_set_property (iter, key, &gvalue_transformed);
+ g_value_unset (&gvalue);
+ g_value_unset (&gvalue_transformed);
+ }
+ g_free (key);
+ }
+ else if (strchr (*operation, ':'))
+ {
+ curop = *operation;
+ new = gegl_node_new_child (gegl_node_get_parent (proxy), "operation", curop, NULL);
+ if (iter)
+ {
+ gegl_node_link_many (iter, new, proxy, NULL);
+ }
+ else
+ {
+ gegl_node_link_many (new, proxy, NULL);
+ }
+ iter = new;
+ }
+ operation++;
+ }
+}
diff --git a/bin/ui.c b/bin/ui.c
index 2c7270c..c749e68 100644
--- a/bin/ui.c
+++ b/bin/ui.c
@@ -93,6 +93,7 @@ static void sdl_add_audio_sample (int sample_pos, float left, float right)
static int audio_started = 0;
+void gegl_create_chain (char **ops, GeglNode *iter, GeglNode *proxy);
/* this structure contains the full application state, and is what
* re-renderings of the UI is directly based on.
@@ -1366,17 +1367,9 @@ static void load_path (State *o)
if (o->ops)
{
- int i;
- for (i = 0; o->ops[i]; i++)
- {
- o->active = gegl_node_new_child (o->gegl,
- "operation", o->ops[i], NULL);
-
- gegl_node_link_many (gegl_node_get_producer (o->sink, "input", NULL),
- o->active,
- o->sink,
- NULL);
- }
+ gegl_create_chain(o->ops,
+ gegl_node_get_producer (o->sink, "input", NULL),
+ o->sink);
}
mrg_queue_draw (o->mrg, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]