From c97cf30e6e15c9273a7ff95a8b4d6123703770d7 Mon Sep 17 00:00:00 2001 From: Ian Martins Date: Fri, 5 Feb 2021 07:45:01 -0500 Subject: [PATCH] pdb: add a PDB compat procedure for median-blur (cherry picked from commit eb9eec4acbe211fb98b5aa8d4235bdba60272c55) Reviewer note: with re-generated C files for the updated PDB in the main branch. --- app/pdb/internal-procs.c | 2 +- app/pdb/plug-in-compat-cmds.c | 91 +++++++++++++++++++++++++++++++++++ pdb/groups/plug_in_compat.pdb | 51 ++++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index b3863af48b..13594d3f3e 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -28,7 +28,7 @@ #include "internal-procs.h" -/* 757 procedures registered total */ +/* 758 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 a27e863a2a..5a1e61f0d8 100644 --- a/app/pdb/plug-in-compat-cmds.c +++ b/app/pdb/plug-in-compat-cmds.c @@ -2614,6 +2614,49 @@ plug_in_mblur_inward_invoker (GimpProcedure *procedure, error ? *error : NULL); } +static GimpValueArray * +plug_in_median_blur_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpDrawable *drawable; + gint radius; + gdouble percentile; + + drawable = g_value_get_object (gimp_value_array_index (args, 2)); + radius = g_value_get_int (gimp_value_array_index (args, 3)); + percentile = 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)) + { + GeglNode *node = + gegl_node_new_child (NULL, + "operation", "gegl:median-blur", + "radius", radius, + "percentile", percentile, + NULL); + + gimp_drawable_apply_operation (drawable, progress, + C_("undo-type", "Median Blur"), + node); + g_object_unref (node); + } + else + success = FALSE; + } + + return gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); +} + static GimpValueArray * plug_in_mosaic_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -7246,6 +7289,54 @@ register_plug_in_compat_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-plug-in-median-blur + */ + procedure = gimp_procedure_new (plug_in_median_blur_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "plug-in-median-blur"); + gimp_procedure_set_static_help (procedure, + "Blur using the median color near each pixel", + "Blur resulting from computing the median color in the neighborhood of each pixel", + NULL); + gimp_procedure_set_static_attribution (procedure, + "Compatibility procedure. Please see 'gegl:median-blur' for credits.", + "Compatibility procedure. Please see 'gegl:median-blur' for credits.", + "2021"); + 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 ("radius", + "radius", + "Neighborhood radius, a negative value will calculate with inverted percentiles", + -400, 400, -400, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + g_param_spec_double ("percentile", + "percentile", + "Neighborhood color percentile", + 0, 100, 0, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-plug-in-mosaic */ diff --git a/pdb/groups/plug_in_compat.pdb b/pdb/groups/plug_in_compat.pdb index cceb3e79fe..aff1335331 100644 --- a/pdb/groups/plug_in_compat.pdb +++ b/pdb/groups/plug_in_compat.pdb @@ -2525,6 +2525,56 @@ CODE ); } +sub plug_in_median_blur { + $blurb = 'Blur using the median color near each pixel'; + + $help = <<'HELP'; +Blur resulting from computing the median color in the +neighborhood of each pixel +HELP + + &std_pdb_compat('gegl:median-blur'); + $date = '2021'; + + @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 => 'radius', type => '-400 <= int32 <= 400', + desc => 'Neighborhood radius, a negative value will calculate with inverted percentiles' }, + { name => 'percentile', type => '0 <= float <= 100', + desc => 'Neighborhood color percentile' } + ); + + %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)) + { + GeglNode *node = + gegl_node_new_child (NULL, + "operation", "gegl:median-blur", + "radius", radius, + "percentile", percentile, + NULL); + + gimp_drawable_apply_operation (drawable, progress, + C_("undo-type", "Median Blur"), + node); + g_object_unref (node); + } + else + success = FALSE; +} +CODE + ); +} + sub plug_in_mosaic { $blurb = 'Convert the image into irregular tiles'; @@ -5503,6 +5553,7 @@ CODE plug_in_maze plug_in_mblur plug_in_mblur_inward + plug_in_median_blur plug_in_mosaic plug_in_neon plug_in_newsprint