From b0ac59b4218b6c45a1704ff15728afa915ca5e01 Mon Sep 17 00:00:00 2001 From: Jehan Date: Sun, 15 Dec 2024 19:01:29 +0100 Subject: [PATCH] app, pdb, plug-ins: replace (plug-in-plasma). This time, it's a Python plug-in, which is a bit more involved than C or Script-fu usage (where we have variable args one-liner function) though it's not too bad either. It's actually very similar (on purpose) to how PDB procedures are run. --- app/pdb/internal-procs.c | 2 +- app/pdb/plug-in-compat-cmds.c | 103 ---------------------------------- pdb/groups/plug_in_compat.pdb | 62 -------------------- plug-ins/python/foggify.py | 21 ++++--- 4 files changed, 14 insertions(+), 174 deletions(-) diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index 8202d4e781..08a3a1e141 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -30,7 +30,7 @@ #include "internal-procs.h" -/* 725 procedures registered total */ +/* 724 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c index cefafd9a5f..670562f020 100644 --- a/app/pdb/plug-in-compat-cmds.c +++ b/app/pdb/plug-in-compat-cmds.c @@ -738,61 +738,6 @@ plug_in_gauss_invoker (GimpProcedure *procedure, error ? *error : NULL); } -static GimpValueArray * -plug_in_plasma_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - GimpDrawable *drawable; - gint seed; - gdouble turbulence; - - drawable = g_value_get_object (gimp_value_array_index (args, 2)); - seed = g_value_get_int (gimp_value_array_index (args, 3)); - turbulence = g_value_get_double (gimp_value_array_index (args, 4)); - - if (success) - { - if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, - GIMP_PDB_ITEM_CONTENT, error) && - gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) - { - GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); - GeglNode *node; - gint x, y, width, height; - - gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height); - - if (! gimp_channel_is_empty (gimp_image_get_mask (image))) - x = y = 0; - - node = gegl_node_new_child (NULL, - "operation", "gegl:plasma", - "seed", seed, - "turbulence", turbulence, - "x", x, - "y", y, - "width", width, - "height", height, - NULL); - - gimp_drawable_apply_operation (drawable, progress, - C_("undo-type", "Plasma"), - node); - g_object_unref (node); - } - else - success = FALSE; - } - - return gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); -} - static GimpValueArray * plug_in_rotate_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -1287,54 +1232,6 @@ register_plug_in_compat_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); - /* - * gimp-plug-in-plasma - */ - procedure = gimp_procedure_new (plug_in_plasma_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "plug-in-plasma"); - gimp_procedure_set_static_help (procedure, - "Create a random plasma texture", - "This plug-in produces plasma fractal images.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Compatibility procedure. Please see 'gegl:plasma' for credits.", - "Compatibility procedure. Please see 'gegl:plasma' for credits.", - "2013"); - gimp_procedure_add_argument (procedure, - g_param_spec_enum ("run-mode", - "run mode", - "The run mode", - GIMP_TYPE_RUN_MODE, - GIMP_RUN_INTERACTIVE, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_argument (procedure, - gimp_param_spec_image ("image", - "image", - "Input image (unused)", - FALSE, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_argument (procedure, - gimp_param_spec_drawable ("drawable", - "drawable", - "Input drawable", - FALSE, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_argument (procedure, - g_param_spec_int ("seed", - "seed", - "Random seed", - -1, G_MAXINT, -1, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_argument (procedure, - g_param_spec_double ("turbulence", - "turbulence", - "The value of the turbulence", - 0.0, 7.0, 0.0, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - /* * gimp-plug-in-rotate */ diff --git a/pdb/groups/plug_in_compat.pdb b/pdb/groups/plug_in_compat.pdb index db7ac52148..dea016aa07 100644 --- a/pdb/groups/plug_in_compat.pdb +++ b/pdb/groups/plug_in_compat.pdb @@ -378,67 +378,6 @@ CODE # We simplify the GEGL signature, reducing tile width and height to just size -sub plug_in_plasma { - $blurb = 'Create a random plasma texture'; - - $help = <<'HELP'; -This plug-in produces plasma fractal images. -HELP - - &std_pdb_compat('gegl:plasma'); - $date = '2013'; - - @inargs = ( - { name => 'run_mode', type => 'enum GimpRunMode', dead => 1, - desc => 'The run mode' }, - { name => 'image', type => 'image', dead => 1, - desc => 'Input image (unused)' }, - { name => 'drawable', type => 'drawable', - desc => 'Input drawable' }, - { name => 'seed', type => '-1 <= int32 <= G_MAXINT', - desc => 'Random seed' }, - { name => 'turbulence', type => '0.0 <= double <= 7.0', - desc => 'The value of the turbulence' } - ); - - %invoke = ( - code => <<'CODE' -{ - if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, - GIMP_PDB_ITEM_CONTENT, error) && - gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) - { - GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); - GeglNode *node; - gint x, y, width, height; - - gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height); - - if (! gimp_channel_is_empty (gimp_image_get_mask (image))) - x = y = 0; - - node = gegl_node_new_child (NULL, - "operation", "gegl:plasma", - "seed", seed, - "turbulence", turbulence, - "x", x, - "y", y, - "width", width, - "height", height, - NULL); - - gimp_drawable_apply_operation (drawable, progress, - C_("undo-type", "Plasma"), - node); - g_object_unref (node); - } - else - success = FALSE; -} -CODE - ); -} - sub plug_in_rotate { $blurb = 'Rotates a layer or the whole image by 90, 180 or 270 degrees'; @@ -971,7 +910,6 @@ CODE plug_in_displace plug_in_emboss plug_in_gauss - plug_in_plasma plug_in_rotate plug_in_noisify); diff --git a/plug-ins/python/foggify.py b/plug-ins/python/foggify.py index 52506fd866..9270d4ed04 100755 --- a/plug-ins/python/foggify.py +++ b/plug-ins/python/foggify.py @@ -71,14 +71,19 @@ def foggify(procedure, run_mode, image, drawables, config, data): fog.add_mask(mask) # add some clouds to the layer - pdb_proc = Gimp.get_pdb().lookup_procedure('plug-in-plasma') - pdb_config = pdb_proc.create_config() - pdb_config.set_property('run-mode', Gimp.RunMode.NONINTERACTIVE) - pdb_config.set_property('image', image) - pdb_config.set_property('drawable', mask) - pdb_config.set_property('seed', int(time.time())) - pdb_config.set_property('turbulence', turbulence) - pdb_proc.run(pdb_config) + _, x, y, width, height = mask.mask_intersect() + if not Gimp.Selection.is_empty(image): + x = 0 + y = 0 + plasma_filter = Gimp.DrawableFilter.new(mask, "gegl:plasma", "") + plasma_filter_config = plasma_filter.get_config() + plasma_filter_config.set_property("seed", int(time.time())) + plasma_filter_config.set_property("turbulence", turbulence) + plasma_filter_config.set_property("x", x) + plasma_filter_config.set_property("y", y) + plasma_filter_config.set_property("width", width) + plasma_filter_config.set_property("height", height) + mask.merge_filter (plasma_filter) # apply the clouds to the layer fog.remove_mask(Gimp.MaskApplyMode.APPLY)