app, pdb, plug-ins: replace (plug-in-threshold-alpha).

For plug-in writers reference, these are equivalent:

- (plug-in-threshold-alpha RUN-NONINTERACTIVE image layer threshold))
+ (gimp-drawable-merge-new-filter layer "gimp:threshold-alpha" 0 LAYER-MODE-REPLACE 1.0 "value" (/ threshold 255))

The main difference is that threshold arg was a [0; 255] int whereas
"value" is a [0.0; 1.0] double.

This commit also shows how to run filters in C plug-ins (file-ico here)
as a one-liner too, thanks to the varargs conviency function.
This commit is contained in:
Jehan 2024-12-15 17:48:37 +01:00
parent 3c0c4db614
commit c70ffcec91
6 changed files with 12 additions and 158 deletions

View file

@ -30,7 +30,7 @@
#include "internal-procs.h"
/* 727 procedures registered total */
/* 726 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)

View file

@ -916,47 +916,6 @@ plug_in_noisify_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GimpValueArray *
plug_in_threshold_alpha_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpDrawable *drawable;
gint threshold;
drawable = g_value_get_object (gimp_value_array_index (args, 2));
threshold = g_value_get_int (gimp_value_array_index (args, 3));
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) &&
gimp_drawable_has_alpha (drawable))
{
GeglNode *node =
gegl_node_new_child (NULL,
"operation", "gimp:threshold-alpha",
"value", threshold / 255.0,
NULL);
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Threshold Alpha"),
node);
g_object_unref (node);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
plug_in_waves_invoker (GimpProcedure *procedure,
Gimp *gimp,
@ -1553,48 +1512,6 @@ register_plug_in_compat_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-plug-in-threshold-alpha
*/
procedure = gimp_procedure_new (plug_in_threshold_alpha_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"plug-in-threshold-alpha");
gimp_procedure_set_static_help (procedure,
"Make transparency all-or-nothing",
"Make transparency all-or-nothing.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997");
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 ("threshold",
"threshold",
"Threshold",
0, 255, 0,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-plug-in-waves
*/

View file

@ -575,53 +575,6 @@ CODE
);
}
sub plug_in_threshold_alpha {
$blurb = 'Make transparency all-or-nothing';
$help = <<'HELP';
Make transparency all-or-nothing.
HELP
&std_pdb_misc;
$date = '1997';
@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 => 'threshold', type => '0 <= int32 <= 255',
desc => 'Threshold' }
);
%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) &&
gimp_drawable_has_alpha (drawable))
{
GeglNode *node =
gegl_node_new_child (NULL,
"operation", "gimp:threshold-alpha",
"value", threshold / 255.0,
NULL);
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Threshold Alpha"),
node);
g_object_unref (node);
}
else
success = FALSE;
}
CODE
);
}
sub plug_in_waves {
$blurb = 'Distort the image with waves';
@ -1092,7 +1045,6 @@ CODE
plug_in_plasma
plug_in_rotate
plug_in_noisify
plug_in_threshold_alpha
plug_in_waves);
%exports = (app => [@procs], lib => []);

View file

@ -462,8 +462,6 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
GimpImage *image;
GimpImage *tmp_image;
GimpLayer *tmp_layer;
GimpProcedure *procedure;
GimpValueArray *return_vals;
image = gimp_item_get_image (GIMP_ITEM (layer));
@ -490,16 +488,11 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
if (gimp_drawable_is_indexed (layer))
gimp_image_convert_rgb (tmp_image);
procedure = gimp_pdb_lookup_procedure (gimp_get_pdb (),
"plug-in-threshold-alpha");
return_vals = gimp_procedure_run (procedure,
"run-mode", GIMP_RUN_NONINTERACTIVE,
"image", tmp_image,
"drawable", tmp_layer,
"threshold", ICO_ALPHA_THRESHOLD,
NULL);
gimp_value_array_unref (return_vals);
gimp_drawable_merge_new_filter (GIMP_DRAWABLE (tmp_layer),
"gimp:threshold-alpha", NULL,
GIMP_LAYER_MODE_REPLACE, 1.0,
"value", ICO_ALPHA_THRESHOLD / 255.0,
NULL);
pixbuf = gimp_drawable_get_thumbnail (GIMP_DRAWABLE (tmp_layer),
MIN (w, 128), MIN (h, 128),

View file

@ -840,19 +840,11 @@ ico_image_get_reduced_buf (GimpDrawable *layer,
}
else if (bpp == 24)
{
GimpProcedure *procedure;
GimpValueArray *return_vals;
procedure = gimp_pdb_lookup_procedure (gimp_get_pdb (),
"plug-in-threshold-alpha");
return_vals = gimp_procedure_run (procedure,
"run-mode", GIMP_RUN_NONINTERACTIVE,
"image", tmp_image,
"drawable", tmp_layer,
"threshold", ICO_ALPHA_THRESHOLD,
NULL);
gimp_value_array_unref (return_vals);
gimp_drawable_merge_new_filter (GIMP_DRAWABLE (tmp_layer),
"gimp:threshold-alpha", NULL,
GIMP_LAYER_MODE_REPLACE, 1.0,
"value", ICO_ALPHA_THRESHOLD / 255.0,
NULL);
}
gimp_layer_add_alpha (tmp_layer);

View file

@ -89,7 +89,7 @@
(plug-in-gauss RUN-NONINTERACTIVE
theImage theLayer horizontalRadius verticalRadius 0)
(gimp-layer-scale theLayer theWidth theHeight TRUE)
(plug-in-threshold-alpha RUN-NONINTERACTIVE theImage theLayer (* inThreshold 255))
(gimp-drawable-merge-new-filter theLayer "gimp:threshold-alpha" 0 LAYER-MODE-REPLACE 1.0 "value" inThreshold)
(plug-in-gauss RUN-NONINTERACTIVE theImage theLayer 0.32 0.32 0)
(gimp-image-select-item inImage CHANNEL-OP-REPLACE theLayer)
(gimp-image-remove-layer theImage theLayer)