From 8d6f281a721ca97fa104a4fa057d86f87f24d500 Mon Sep 17 00:00:00 2001 From: Jehan Date: Wed, 25 Oct 2023 17:40:02 +0200 Subject: [PATCH] plug-ins: replace gimp_[sg]et_data() with an aux str argument in ifs-compose. The argument is the serialized description of the generated fractal. Actually it may even be useful as a non-aux argument. A GFile argument could eventually be interesting too, though one arg per setting would be better of course (it allows more easily to generate animated frames for instance). In such a case, the GFile would be used in priority, otherwise the other args. Notes: * I didn't port to GimpProcedureDialog though it looks like it would not be too hard (most of the GUI would still be custom GTK code, yet we could have the generic "reset to initial|factory values" buttons and load/save). * The custom "Reset" button (identical to what "reset to factory values" would do) works fine anyway. * The "run with last vals" works fine where there were indeed previous runs (which may be in previous sessions), but crashes when it's actually the first run ever. Some of the base structure data were not initialized. It should not be too hard yet would require a bit of code reorganization to fix this. --- plug-ins/ifs-compose/ifs-compose.c | 56 +++++++++++++++++------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/plug-ins/ifs-compose/ifs-compose.c b/plug-ins/ifs-compose/ifs-compose.c index 759b42245f..80d05d883a 100644 --- a/plug-ins/ifs-compose/ifs-compose.c +++ b/plug-ins/ifs-compose/ifs-compose.c @@ -450,6 +450,11 @@ ifs_create_procedure (GimpPlugIn *plug_in, "Owen Taylor", "Owen Taylor", "1997"); + + GIMP_PROC_AUX_ARG_STRING (procedure, "fractal-str", + "The fractal description serialized as string", + NULL, NULL, + GIMP_PARAM_READWRITE); } return procedure; @@ -518,16 +523,12 @@ ifs_run (GimpProcedure *procedure, if (! found_parasite) { - gint length = gimp_get_data_size (PLUG_IN_PROC); + gchar *data = NULL; - if (length > 0) - { - gchar *data = g_new (gchar, length); - - gimp_get_data (PLUG_IN_PROC, data); - ifsvals_parse_string (data, &ifsvals, &elements); - g_free (data); - } + g_object_get (config, "fractal-str", &data, NULL); + if (data != NULL && strlen (data) > 0) + ifsvals_parse_string (data, &ifsvals, &elements); + g_free (data); } /* after ifsvals_parse_string, need to set up naming */ @@ -553,22 +554,28 @@ ifs_run (GimpProcedure *procedure, break; case GIMP_RUN_WITH_LAST_VALS: - { - gint length = gimp_get_data_size (PLUG_IN_PROC); + { + gchar *data = NULL; - if (length > 0) - { - gchar *data = g_new (gchar, length); + g_object_get (config, "fractal-str", &data, NULL); + if (data != NULL && strlen (data) > 0) + { + ifsvals_parse_string (data, &ifsvals, &elements); + } + else + { + /* FIXME: there is a known crash in this code path, because some + * base structures (which are visibly created as part of the + * dialog or with ifsvals_parse_string() on a valid serialized + * fractal) don't exist. This should be fixed so that we can run + * with last vals even when no last vals exist (which should use + * defaults). + */ + ifs_compose_set_defaults (); + } - gimp_get_data (PLUG_IN_PROC, data); - ifsvals_parse_string (data, &ifsvals, &elements); - g_free (data); - } - else - { - ifs_compose_set_defaults (); - } - } + g_free (data); + } break; default: @@ -589,8 +596,7 @@ ifs_run (GimpProcedure *procedure, * as a parasite on this layer */ str = ifsvals_stringify (&ifsvals, elements); - - gimp_set_data (PLUG_IN_PROC, str, strlen (str) + 1); + g_object_set (config, "fractal-str", str, NULL); parasite = gimp_parasite_new (PLUG_IN_PARASITE, GIMP_PARASITE_PERSISTENT |