Skip to content

Commit c70ffce

Browse files
author
Jehan
committed
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.
1 parent 3c0c4db commit c70ffce

File tree

6 files changed

+12
-158
lines changed

6 files changed

+12
-158
lines changed

app/pdb/internal-procs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "internal-procs.h"
3131

3232

33-
/* 727 procedures registered total */
33+
/* 726 procedures registered total */
3434

3535
void
3636
internal_procs_init (GimpPDB *pdb)

app/pdb/plug-in-compat-cmds.c

-83
Original file line numberDiff line numberDiff line change
@@ -916,47 +916,6 @@ plug_in_noisify_invoker (GimpProcedure *procedure,
916916
error ? *error : NULL);
917917
}
918918

919-
static GimpValueArray *
920-
plug_in_threshold_alpha_invoker (GimpProcedure *procedure,
921-
Gimp *gimp,
922-
GimpContext *context,
923-
GimpProgress *progress,
924-
const GimpValueArray *args,
925-
GError **error)
926-
{
927-
gboolean success = TRUE;
928-
GimpDrawable *drawable;
929-
gint threshold;
930-
931-
drawable = g_value_get_object (gimp_value_array_index (args, 2));
932-
threshold = g_value_get_int (gimp_value_array_index (args, 3));
933-
934-
if (success)
935-
{
936-
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
937-
GIMP_PDB_ITEM_CONTENT, error) &&
938-
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
939-
gimp_drawable_has_alpha (drawable))
940-
{
941-
GeglNode *node =
942-
gegl_node_new_child (NULL,
943-
"operation", "gimp:threshold-alpha",
944-
"value", threshold / 255.0,
945-
NULL);
946-
947-
gimp_drawable_apply_operation (drawable, progress,
948-
C_("undo-type", "Threshold Alpha"),
949-
node);
950-
g_object_unref (node);
951-
}
952-
else
953-
success = FALSE;
954-
}
955-
956-
return gimp_procedure_get_return_values (procedure, success,
957-
error ? *error : NULL);
958-
}
959-
960919
static GimpValueArray *
961920
plug_in_waves_invoker (GimpProcedure *procedure,
962921
Gimp *gimp,
@@ -1553,48 +1512,6 @@ register_plug_in_compat_procs (GimpPDB *pdb)
15531512
gimp_pdb_register_procedure (pdb, procedure);
15541513
g_object_unref (procedure);
15551514

1556-
/*
1557-
* gimp-plug-in-threshold-alpha
1558-
*/
1559-
procedure = gimp_procedure_new (plug_in_threshold_alpha_invoker);
1560-
gimp_object_set_static_name (GIMP_OBJECT (procedure),
1561-
"plug-in-threshold-alpha");
1562-
gimp_procedure_set_static_help (procedure,
1563-
"Make transparency all-or-nothing",
1564-
"Make transparency all-or-nothing.",
1565-
NULL);
1566-
gimp_procedure_set_static_attribution (procedure,
1567-
"Spencer Kimball & Peter Mattis",
1568-
"Spencer Kimball & Peter Mattis",
1569-
"1997");
1570-
gimp_procedure_add_argument (procedure,
1571-
g_param_spec_enum ("run-mode",
1572-
"run mode",
1573-
"The run mode",
1574-
GIMP_TYPE_RUN_MODE,
1575-
GIMP_RUN_INTERACTIVE,
1576-
GIMP_PARAM_READWRITE));
1577-
gimp_procedure_add_argument (procedure,
1578-
gimp_param_spec_image ("image",
1579-
"image",
1580-
"Input image (unused)",
1581-
FALSE,
1582-
GIMP_PARAM_READWRITE));
1583-
gimp_procedure_add_argument (procedure,
1584-
gimp_param_spec_drawable ("drawable",
1585-
"drawable",
1586-
"Input drawable",
1587-
FALSE,
1588-
GIMP_PARAM_READWRITE));
1589-
gimp_procedure_add_argument (procedure,
1590-
g_param_spec_int ("threshold",
1591-
"threshold",
1592-
"Threshold",
1593-
0, 255, 0,
1594-
GIMP_PARAM_READWRITE));
1595-
gimp_pdb_register_procedure (pdb, procedure);
1596-
g_object_unref (procedure);
1597-
15981515
/*
15991516
* gimp-plug-in-waves
16001517
*/

pdb/groups/plug_in_compat.pdb

-48
Original file line numberDiff line numberDiff line change
@@ -575,53 +575,6 @@ CODE
575575
);
576576
}
577577

578-
sub plug_in_threshold_alpha {
579-
$blurb = 'Make transparency all-or-nothing';
580-
581-
$help = <<'HELP';
582-
Make transparency all-or-nothing.
583-
HELP
584-
585-
&std_pdb_misc;
586-
$date = '1997';
587-
588-
@inargs = (
589-
{ name => 'run_mode', type => 'enum GimpRunMode', dead => 1,
590-
desc => 'The run mode' },
591-
{ name => 'image', type => 'image', dead => 1,
592-
desc => 'Input image (unused)' },
593-
{ name => 'drawable', type => 'drawable',
594-
desc => 'Input drawable' },
595-
{ name => 'threshold', type => '0 <= int32 <= 255',
596-
desc => 'Threshold' }
597-
);
598-
599-
%invoke = (
600-
code => <<'CODE'
601-
{
602-
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
603-
GIMP_PDB_ITEM_CONTENT, error) &&
604-
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
605-
gimp_drawable_has_alpha (drawable))
606-
{
607-
GeglNode *node =
608-
gegl_node_new_child (NULL,
609-
"operation", "gimp:threshold-alpha",
610-
"value", threshold / 255.0,
611-
NULL);
612-
613-
gimp_drawable_apply_operation (drawable, progress,
614-
C_("undo-type", "Threshold Alpha"),
615-
node);
616-
g_object_unref (node);
617-
}
618-
else
619-
success = FALSE;
620-
}
621-
CODE
622-
);
623-
}
624-
625578
sub plug_in_waves {
626579
$blurb = 'Distort the image with waves';
627580

@@ -1092,7 +1045,6 @@ CODE
10921045
plug_in_plasma
10931046
plug_in_rotate
10941047
plug_in_noisify
1095-
plug_in_threshold_alpha
10961048
plug_in_waves);
10971049

10981050
%exports = (app => [@procs], lib => []);

plug-ins/file-ico/ico-dialog.c

+5-12
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
462462
GimpImage *image;
463463
GimpImage *tmp_image;
464464
GimpLayer *tmp_layer;
465-
GimpProcedure *procedure;
466-
GimpValueArray *return_vals;
467465

468466
image = gimp_item_get_image (GIMP_ITEM (layer));
469467

@@ -490,16 +488,11 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
490488
if (gimp_drawable_is_indexed (layer))
491489
gimp_image_convert_rgb (tmp_image);
492490

493-
procedure = gimp_pdb_lookup_procedure (gimp_get_pdb (),
494-
"plug-in-threshold-alpha");
495-
return_vals = gimp_procedure_run (procedure,
496-
"run-mode", GIMP_RUN_NONINTERACTIVE,
497-
"image", tmp_image,
498-
"drawable", tmp_layer,
499-
"threshold", ICO_ALPHA_THRESHOLD,
500-
NULL);
501-
502-
gimp_value_array_unref (return_vals);
491+
gimp_drawable_merge_new_filter (GIMP_DRAWABLE (tmp_layer),
492+
"gimp:threshold-alpha", NULL,
493+
GIMP_LAYER_MODE_REPLACE, 1.0,
494+
"value", ICO_ALPHA_THRESHOLD / 255.0,
495+
NULL);
503496

504497
pixbuf = gimp_drawable_get_thumbnail (GIMP_DRAWABLE (tmp_layer),
505498
MIN (w, 128), MIN (h, 128),

plug-ins/file-ico/ico-export.c

+5-13
Original file line numberDiff line numberDiff line change
@@ -840,19 +840,11 @@ ico_image_get_reduced_buf (GimpDrawable *layer,
840840
}
841841
else if (bpp == 24)
842842
{
843-
GimpProcedure *procedure;
844-
GimpValueArray *return_vals;
845-
846-
procedure = gimp_pdb_lookup_procedure (gimp_get_pdb (),
847-
"plug-in-threshold-alpha");
848-
return_vals = gimp_procedure_run (procedure,
849-
"run-mode", GIMP_RUN_NONINTERACTIVE,
850-
"image", tmp_image,
851-
"drawable", tmp_layer,
852-
"threshold", ICO_ALPHA_THRESHOLD,
853-
NULL);
854-
855-
gimp_value_array_unref (return_vals);
843+
gimp_drawable_merge_new_filter (GIMP_DRAWABLE (tmp_layer),
844+
"gimp:threshold-alpha", NULL,
845+
GIMP_LAYER_MODE_REPLACE, 1.0,
846+
"value", ICO_ALPHA_THRESHOLD / 255.0,
847+
NULL);
856848
}
857849

858850
gimp_layer_add_alpha (tmp_layer);

plug-ins/script-fu/scripts/distress-selection.scm

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
(plug-in-gauss RUN-NONINTERACTIVE
9090
theImage theLayer horizontalRadius verticalRadius 0)
9191
(gimp-layer-scale theLayer theWidth theHeight TRUE)
92-
(plug-in-threshold-alpha RUN-NONINTERACTIVE theImage theLayer (* inThreshold 255))
92+
(gimp-drawable-merge-new-filter theLayer "gimp:threshold-alpha" 0 LAYER-MODE-REPLACE 1.0 "value" inThreshold)
9393
(plug-in-gauss RUN-NONINTERACTIVE theImage theLayer 0.32 0.32 0)
9494
(gimp-image-select-item inImage CHANNEL-OP-REPLACE theLayer)
9595
(gimp-image-remove-layer theImage theLayer)

0 commit comments

Comments
 (0)