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

For plug-in writers reference, these are equivalent:

- (plug-in-noisify RUN-NONINTERACTIVE theImage mLayer TRUE r g b a)
+ (gimp-drawable-merge-new-filter mLayer "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
+                                 "independent" TRUE "red" r "green" g "blue" b "alpha" a
+                                 "correlated" FALSE "seed" (msrg-rand) "linear" TRUE)

Notes:

* When "independent" is FALSE, then you only need to set "red" (which is
  equivalent to a "value" field) and "alpha".
* Original plug-in was using the second value ('g', a.k.a. noise_2 in
  the PDB args) as alpha when the source drawable was grayscale. This
  logic is meaningless now. Just set "alpha".
* The PDB procedure was wrapping the operation between
  "gegl:cast-format" nodes to cast the input buffer to linear. This is
  useless as the "gegl:noise-rgb" has already a "linear" argument
  (defaulting to TRUE, but I specify it explicitly in this commit, for
  clarity) which requests linear input when set.
This commit is contained in:
Jehan 2024-12-16 16:37:25 +01:00
parent dc4daa8396
commit c26b2cd08f
10 changed files with 35 additions and 351 deletions

View File

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

View File

@ -146,65 +146,6 @@ wrap_in_selection_bounds (GeglNode *node,
}
}
static GeglNode *
wrap_in_gamma_cast (GeglNode *node,
GimpDrawable *drawable)
{
if (gimp_drawable_get_trc (drawable) != GIMP_TRC_LINEAR)
{
const Babl *drawable_format;
const Babl *cast_format;
GeglNode *new_node;
GeglNode *input;
GeglNode *output;
GeglNode *cast_before;
GeglNode *cast_after;
drawable_format = gimp_drawable_get_format (drawable);
cast_format =
gimp_babl_format (gimp_babl_format_get_base_type (drawable_format),
gimp_babl_precision (gimp_babl_format_get_component_type (drawable_format),
GIMP_TRC_LINEAR),
babl_format_has_alpha (drawable_format),
babl_format_get_space (drawable_format));
new_node = gegl_node_new ();
gegl_node_add_child (new_node, node);
g_object_unref (node);
gimp_gegl_node_set_underlying_operation (new_node, node);
input = gegl_node_get_input_proxy (new_node, "input");
output = gegl_node_get_output_proxy (new_node, "output");
cast_before = gegl_node_new_child (new_node,
"operation", "gegl:cast-format",
"input-format", drawable_format,
"output-format", cast_format,
NULL);
cast_after = gegl_node_new_child (new_node,
"operation", "gegl:cast-format",
"input-format", cast_format,
"output-format", drawable_format,
NULL);
gegl_node_link_many (input,
cast_before,
node,
cast_after,
output,
NULL);
return new_node;
}
else
{
return node;
}
}
static GeglNode *
create_buffer_source_node (GeglNode *parent,
GimpDrawable *drawable)
@ -673,79 +614,6 @@ plug_in_rotate_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GimpValueArray *
plug_in_noisify_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpDrawable *drawable;
gboolean independent;
gdouble noise_1;
gdouble noise_2;
gdouble noise_3;
gdouble noise_4;
drawable = g_value_get_object (gimp_value_array_index (args, 2));
independent = g_value_get_boolean (gimp_value_array_index (args, 3));
noise_1 = g_value_get_double (gimp_value_array_index (args, 4));
noise_2 = g_value_get_double (gimp_value_array_index (args, 5));
noise_3 = g_value_get_double (gimp_value_array_index (args, 6));
noise_4 = g_value_get_double (gimp_value_array_index (args, 7));
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;
gdouble r, g, b, a;
if (gimp_drawable_is_gray (drawable))
{
r = noise_1;
g = noise_1;
b = noise_1;
a = noise_2;
}
else
{
r = noise_1;
g = noise_2;
b = noise_3;
a = noise_4;
}
node = gegl_node_new_child (NULL,
"operation", "gegl:noise-rgb",
"correlated", FALSE,
"independent", independent,
"red", r,
"green", g,
"blue", b,
"alpha", a,
"seed", g_random_int (),
NULL);
node = wrap_in_gamma_cast (node, drawable);
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Noisify"),
node);
g_object_unref (node);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
void
register_plug_in_compat_procs (GimpPDB *pdb)
{
@ -1050,70 +918,4 @@ register_plug_in_compat_procs (GimpPDB *pdb)
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-plug-in-noisify
*/
procedure = gimp_procedure_new (plug_in_noisify_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"plug-in-noisify");
gimp_procedure_set_static_help (procedure,
"Adds random noise to image channels",
"Add normally distributed random values to image channels. For color images each color channel may be treated together or independently.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Compatibility procedure. Please see 'gegl:noise-rgb' for credits.",
"Compatibility procedure. Please see 'gegl:noise-rgb' 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_boolean ("independent",
"independent",
"Noise in channels independent",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_double ("noise-1",
"noise 1",
"Noise in the first channel (red, gray)",
0.0, 1.0, 0.0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_double ("noise-2",
"noise 2",
"Noise in the second channel (green, gray_alpha)",
0.0, 1.0, 0.0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_double ("noise-3",
"noise 3",
"Noise in the third channel (blue)",
0.0, 1.0, 0.0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_double ("noise-4",
"noise 4",
"Noise in the fourth channel (alpha)",
0.0, 1.0, 0.0,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
}

View File

@ -337,86 +337,6 @@ CODE
);
}
sub plug_in_noisify {
$blurb = 'Adds random noise to image channels';
$help = <<'HELP';
Add normally distributed random values to image channels. For color
images each color channel may be treated together or independently.
HELP
&std_pdb_compat('gegl:noise-rgb');
$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 => 'independent', type => 'boolean',
desc => 'Noise in channels independent' },
{ name => 'noise_1', type => '0.0 <= double <= 1.0',
desc => 'Noise in the first channel (red, gray)' },
{ name => 'noise_2', type => '0.0 <= double <= 1.0',
desc => 'Noise in the second channel (green, gray_alpha)' },
{ name => 'noise_3', type => '0.0 <= double <= 1.0',
desc => 'Noise in the third channel (blue)' },
{ name => 'noise_4', type => '0.0 <= double <= 1.0',
desc => 'Noise in the fourth channel (alpha)' }
);
%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;
gdouble r, g, b, a;
if (gimp_drawable_is_gray (drawable))
{
r = noise_1;
g = noise_1;
b = noise_1;
a = noise_2;
}
else
{
r = noise_1;
g = noise_2;
b = noise_3;
a = noise_4;
}
node = gegl_node_new_child (NULL,
"operation", "gegl:noise-rgb",
"correlated", FALSE,
"independent", independent,
"red", r,
"green", g,
"blue", b,
"alpha", a,
"seed", g_random_int (),
NULL);
node = wrap_in_gamma_cast (node, drawable);
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Noisify"),
node);
g_object_unref (node);
}
else
success = FALSE;
}
CODE
);
}
$extra{app}->{code} = <<'CODE';
static GeglNode *
wrap_in_graph (GeglNode *node)
@ -502,65 +422,6 @@ wrap_in_selection_bounds (GeglNode *node,
}
}
static GeglNode *
wrap_in_gamma_cast (GeglNode *node,
GimpDrawable *drawable)
{
if (gimp_drawable_get_trc (drawable) != GIMP_TRC_LINEAR)
{
const Babl *drawable_format;
const Babl *cast_format;
GeglNode *new_node;
GeglNode *input;
GeglNode *output;
GeglNode *cast_before;
GeglNode *cast_after;
drawable_format = gimp_drawable_get_format (drawable);
cast_format =
gimp_babl_format (gimp_babl_format_get_base_type (drawable_format),
gimp_babl_precision (gimp_babl_format_get_component_type (drawable_format),
GIMP_TRC_LINEAR),
babl_format_has_alpha (drawable_format),
babl_format_get_space (drawable_format));
new_node = gegl_node_new ();
gegl_node_add_child (new_node, node);
g_object_unref (node);
gimp_gegl_node_set_underlying_operation (new_node, node);
input = gegl_node_get_input_proxy (new_node, "input");
output = gegl_node_get_output_proxy (new_node, "output");
cast_before = gegl_node_new_child (new_node,
"operation", "gegl:cast-format",
"input-format", drawable_format,
"output-format", cast_format,
NULL);
cast_after = gegl_node_new_child (new_node,
"operation", "gegl:cast-format",
"input-format", cast_format,
"output-format", drawable_format,
NULL);
gegl_node_link_many (input,
cast_before,
node,
cast_after,
output,
NULL);
return new_node;
}
else
{
return node;
}
}
static GeglNode *
create_buffer_source_node (GeglNode *parent,
GimpDrawable *drawable)
@ -776,8 +637,7 @@ CODE
plug_in_autocrop_layer
plug_in_bump_map
plug_in_displace
plug_in_rotate
plug_in_noisify);
plug_in_rotate);
%exports = (app => [@procs], lib => []);

View File

@ -26,7 +26,9 @@
(gimp-context-set-background '(255 255 255))
(gimp-drawable-edit-fill layer-one FILL-BACKGROUND)
(plug-in-noisify RUN-NONINTERACTIVE img layer-one FALSE 0.7 0.7 0.7 0.7)
(gimp-drawable-merge-new-filter layer-one "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" FALSE "red" 0.7 "alpha" 0.7
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(set! layer-two (car (gimp-layer-copy layer-one 0)))
(gimp-layer-set-mode layer-two LAYER-MODE-MULTIPLY)
@ -38,7 +40,9 @@
(set! bump-layer (vector-ref (car (gimp-image-get-selected-layers img)) 0))
(gimp-drawable-merge-new-filter bump-layer "gegl:stretch-contrast" 0 LAYER-MODE-REPLACE 1.0 "keep-colors" FALSE)
(plug-in-noisify RUN-NONINTERACTIVE img bump-layer FALSE 0.2 0.2 0.2 0.2)
(gimp-drawable-merge-new-filter bump-layer "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" FALSE "red" 0.2 "alpha" 0.2
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(plug-in-bump-map RUN-NONINTERACTIVE img tdrawable bump-layer azimuth elevation depth 0 0 0 0 FALSE FALSE 0)
(gimp-image-delete img)

View File

@ -66,7 +66,9 @@
(gimp-selection-all theImage)
(gimp-drawable-edit-clear mLayer)
(gimp-selection-none theImage)
(plug-in-noisify RUN-NONINTERACTIVE theImage mLayer TRUE 0 0 0 0.5)
(gimp-drawable-merge-new-filter mLayer "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" TRUE "red" 0.0 "green" 0.0 "blue" 0.0 "alpha" 0.5
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(gimp-drawable-merge-new-filter mLayer "gegl:gaussian-blur" 0 LAYER-MODE-REPLACE 1.0 "std-dev-x" 1.6 "std-dev-y" 1.6 "filter" "auto")
(set! theLayer (car (gimp-image-flatten theImage)))
)

View File

@ -31,7 +31,9 @@
(gimp-context-set-background '(127 127 127))
(gimp-image-insert-layer work-image map-layer 0 0)
(gimp-drawable-edit-fill map-layer FILL-BACKGROUND)
(plug-in-noisify RUN-NONINTERACTIVE work-image map-layer FALSE 1.0 1.0 1.0 0.0)
(gimp-drawable-merge-new-filter map-layer "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" FALSE "red" 1.0 "alpha" 0.0
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(plug-in-tile RUN-NONINTERACTIVE work-image (vector map-layer) (* width 3) (* height 3) FALSE)
(gimp-drawable-merge-new-filter map-layer "gegl:gaussian-blur" 0 LAYER-MODE-REPLACE 1.0 "std-dev-x" 11.2 "std-dev-y" 11.2 "filter" "auto")
(gimp-drawable-equalize map-layer TRUE)

View File

@ -28,7 +28,9 @@
(gimp-context-set-background '(255 255 255))
(gimp-drawable-edit-fill layer-one FILL-BACKGROUND)
(plug-in-noisify RUN-NONINTERACTIVE img layer-one FALSE 0.7 0.7 0.7 0.7)
(gimp-drawable-merge-new-filter layer-one "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" FALSE "red" 0.7 "alpha" 0.7
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(set! layer-two (car (gimp-layer-copy layer-one 0)))
(gimp-layer-set-mode layer-two LAYER-MODE-MULTIPLY)
@ -40,7 +42,9 @@
(set! bump-layer (vector-ref (cadr (gimp-image-get-selected-layers img)) 0))
(gimp-drawable-merge-new-filter bump-layer "gegl:stretch-contrast" 0 LAYER-MODE-REPLACE 1.0 "keep-colors" FALSE)
(plug-in-noisify RUN-NONINTERACTIVE img bump-layer FALSE 0.2 0.2 0.2 0.2)
(gimp-drawable-merge-new-filter bump-layer "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" FALSE "red" 0.2 "alpha" 0.2
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(plug-in-bump-map RUN-NONINTERACTIVE img tdrawable bump-layer azimuth elevation depth 0 0 0 0 FALSE FALSE 0)
(gimp-image-delete img)

View File

@ -29,7 +29,9 @@
(gimp-context-set-background '(255 255 255))
(gimp-drawable-edit-fill layer-one FILL-BACKGROUND)
(plug-in-noisify RUN-NONINTERACTIVE img layer-one FALSE 0.7 0.7 0.7 0.7)
(gimp-drawable-merge-new-filter layer-one "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" FALSE "red" 0.7 "alpha" 0.7
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(set! layer-two (car (gimp-layer-copy layer-one 0)))
(gimp-layer-set-mode layer-two LAYER-MODE-MULTIPLY)
@ -43,7 +45,9 @@
(set! bump-layer (car (list (vector-ref (cadr (gimp-image-get-selected-layers img)) 0))))
(gimp-drawable-merge-new-filter bump-layer "gegl:stretch-contrast" 0 LAYER-MODE-REPLACE 1.0 "keep-colors" FALSE)
(plug-in-noisify RUN-NONINTERACTIVE img bump-layer FALSE 0.2 0.2 0.2 0.2)
(gimp-drawable-merge-new-filter bump-layer "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" FALSE "red" 0.2 "alpha" 0.2
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(plug-in-bump-map RUN-NONINTERACTIVE img tdrawable bump-layer azimuth elevation depth 0 0 0 0 FALSE FALSE 0)
(gimp-image-delete img)

View File

@ -33,7 +33,9 @@
(gimp-context-set-background '(255 255 255))
(gimp-drawable-edit-fill layer-one FILL-BACKGROUND)
(plug-in-noisify RUN-NONINTERACTIVE img layer-one FALSE 0.7 0.7 0.7 0.7)
(gimp-drawable-merge-new-filter layer-one "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" FALSE "red" 0.7 "alpha" 0.7
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(set! layer-two (gimp-layer-copy layer-one 0))
(gimp-layer-set-mode layer-two LAYER-MODE-MULTIPLY)
@ -49,7 +51,9 @@
(set! bump-layer (vector-ref (cadr (gimp-image-get-selected-layers img)) 0))
(gimp-drawable-merge-new-filter bump-layer "gegl:stretch-contrast" 0 LAYER-MODE-REPLACE 1.0 "keep-colors" FALSE)
(plug-in-noisify RUN-NONINTERACTIVE img bump-layer FALSE 0.2 0.2 0.2 0.2)
(gimp-drawable-merge-new-filter bump-layer "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" FALSE "red" 0.2 "alpha" 0.2
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(plug-in-bump-map RUN-NONINTERACTIVE img tdrawable bump-layer azimuth elevation depth 0 0 0 0 FALSE FALSE 0)
(gimp-image-delete img)

View File

@ -283,7 +283,9 @@
(gimp-image-insert-layer img drawable 0 -1)
(gimp-context-set-background '(255 255 255))
(gimp-drawable-edit-fill drawable FILL-BACKGROUND)
(plug-in-noisify RUN-NONINTERACTIVE img drawable FALSE dense dense dense dense)
(gimp-drawable-merge-new-filter drawable "gegl:noise-rgb" 0 LAYER-MODE-REPLACE 1.0
"independent" FALSE "red" dense "alpha" dense
"correlated" FALSE "seed" (msrg-rand) "linear" TRUE)
(gimp-drawable-merge-new-filter drawable "gegl:stretch-contrast" 0 LAYER-MODE-REPLACE 1.0 "keep-colors" FALSE)
(cond ((eq? orientation 'horizontal)
(gimp-drawable-merge-new-filter drawable "gegl:gaussian-blur" 0 LAYER-MODE-REPLACE 1.0 "std-dev-x" (* 0.32 length) "std-dev-y" 0.0 "filter" "auto"))