From e5134e67aa547f84245c59afd57a31f3d19634a8 Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 14 Dec 2024 14:42:37 +0100 Subject: [PATCH] libgimp*, plug-ins: filter ID are now usable in script-fu. Marshalled PDB procedures into script-fu can now convert a filter ID into the proper object. For instance, here would be the code to append a new gaussian blur filter to the drawable with ID 2 (with specific settings), then making invisible: ```script-fu (define filter (gimp-drawable-append-new-filter 2 "gegl:gaussian-blur" "hello" LAYER-MODE-COLOR-ERASE 1.0 "std-dev-x" 20 "abyss-policy" "none")) (gimp-drawable-filter-set-visible filter FALSE) (gimp-drawable-update 2 0 0 -1 -1) ``` --- libgimp/gimpgpparams-body.c | 13 +++++++++ libgimpconfig/gimpconfig-params.c | 25 ++++++++--------- .../script-fu/libscriptfu/scheme-wrapper.c | 27 +++++++++++++++++++ 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/libgimp/gimpgpparams-body.c b/libgimp/gimpgpparams-body.c index 27d072fe29..7130c87c31 100644 --- a/libgimp/gimpgpparams-body.c +++ b/libgimp/gimpgpparams-body.c @@ -290,6 +290,11 @@ _gimp_gp_param_def_to_param_spec (const GPParamDef *param_def) return gimp_param_spec_path (name, nick, blurb, param_def->meta.m_id.none_ok, flags); + + if (! strcmp (param_def->type_name, "GimpParamDrawableFilter")) + return gimp_param_spec_drawable_filter (name, nick, blurb, + param_def->meta.m_id.none_ok, + flags); break; case GP_PARAM_DEF_TYPE_ID_ARRAY: @@ -585,6 +590,14 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec, param_def->meta.m_id.none_ok = ispec->none_ok; } + else if (GIMP_IS_PARAM_SPEC_DRAWABLE_FILTER (pspec)) + { + GimpParamSpecDrawableFilter *fspec = GIMP_PARAM_SPEC_DRAWABLE_FILTER (pspec); + + param_def->param_def_type = GP_PARAM_DEF_TYPE_ID; + + param_def->meta.m_id.none_ok = fspec->none_ok; + } else if (pspec_type == GIMP_TYPE_PARAM_DISPLAY) { GimpParamSpecDisplay *ispec = GIMP_PARAM_SPEC_DISPLAY (pspec); diff --git a/libgimpconfig/gimpconfig-params.c b/libgimpconfig/gimpconfig-params.c index fc4f4b5869..9902b95eab 100644 --- a/libgimpconfig/gimpconfig-params.c +++ b/libgimpconfig/gimpconfig-params.c @@ -310,21 +310,22 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec) GType value_type = G_PARAM_SPEC_VALUE_TYPE (pspec); const gchar *type_name = g_type_name (value_type); - if (value_type == G_TYPE_FILE || + if (value_type == G_TYPE_FILE || /* These types are not visibile in libgimpconfig so we compare * with type names instead. */ - g_strcmp0 (type_name, "GimpImage") == 0 || - g_strcmp0 (type_name, "GimpDisplay") == 0 || - g_strcmp0 (type_name, "GimpDrawable") == 0 || - g_strcmp0 (type_name, "GimpLayer") == 0 || - g_strcmp0 (type_name, "GimpGroupLayer") == 0 || - g_strcmp0 (type_name, "GimpTextLayer") == 0 || - g_strcmp0 (type_name, "GimpChannel") == 0 || - g_strcmp0 (type_name, "GimpItem") == 0 || - g_strcmp0 (type_name, "GimpLayerMask") == 0 || - g_strcmp0 (type_name, "GimpSelection") == 0 || - g_strcmp0 (type_name, "GimpPath") == 0) + g_strcmp0 (type_name, "GimpImage") == 0 || + g_strcmp0 (type_name, "GimpDisplay") == 0 || + g_strcmp0 (type_name, "GimpDrawable") == 0 || + g_strcmp0 (type_name, "GimpLayer") == 0 || + g_strcmp0 (type_name, "GimpGroupLayer") == 0 || + g_strcmp0 (type_name, "GimpTextLayer") == 0 || + g_strcmp0 (type_name, "GimpChannel") == 0 || + g_strcmp0 (type_name, "GimpItem") == 0 || + g_strcmp0 (type_name, "GimpLayerMask") == 0 || + g_strcmp0 (type_name, "GimpSelection") == 0 || + g_strcmp0 (type_name, "GimpPath") == 0 || + g_strcmp0 (type_name, "GimpDrawableFilter") == 0) { copy = g_param_spec_object (name, nick, blurb, value_type, diff --git a/plug-ins/script-fu/libscriptfu/scheme-wrapper.c b/plug-ins/script-fu/libscriptfu/scheme-wrapper.c index a3f1ca6df2..f0b9adafd4 100644 --- a/plug-ins/script-fu/libscriptfu/scheme-wrapper.c +++ b/plug-ins/script-fu/libscriptfu/scheme-wrapper.c @@ -1024,6 +1024,33 @@ script_fu_marshal_arg_to_value (scheme *sc, } } } + else if (GIMP_VALUE_HOLDS_DRAWABLE_FILTER (value)) + { + if (! sc->vptr->is_number (arg_val)) + { + return script_type_error (sc, "numeric", arg_index, proc_name); + } + else + { + gint id; + + id = sc->vptr->ivalue (arg_val); + + if (gimp_drawable_filter_id_is_valid (id)) + { + GimpDrawableFilter *filter = gimp_drawable_filter_get_by_id (id); + + g_value_set_object (value, filter); + } + else + { + /* Filter ID is invalid. + * Usually 0 or -1, passed for a nullable arg. + */ + g_value_set_object (value, NULL); + } + } + } else if (GIMP_VALUE_HOLDS_INT32_ARRAY (value)) { vector = arg_val;