mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
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.
This commit is contained in:
parent
082ba3bb1f
commit
b0ac59b421
4 changed files with 14 additions and 174 deletions
|
@ -30,7 +30,7 @@
|
||||||
#include "internal-procs.h"
|
#include "internal-procs.h"
|
||||||
|
|
||||||
|
|
||||||
/* 725 procedures registered total */
|
/* 724 procedures registered total */
|
||||||
|
|
||||||
void
|
void
|
||||||
internal_procs_init (GimpPDB *pdb)
|
internal_procs_init (GimpPDB *pdb)
|
||||||
|
|
|
@ -738,61 +738,6 @@ plug_in_gauss_invoker (GimpProcedure *procedure,
|
||||||
error ? *error : NULL);
|
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 *
|
static GimpValueArray *
|
||||||
plug_in_rotate_invoker (GimpProcedure *procedure,
|
plug_in_rotate_invoker (GimpProcedure *procedure,
|
||||||
Gimp *gimp,
|
Gimp *gimp,
|
||||||
|
@ -1287,54 +1232,6 @@ register_plug_in_compat_procs (GimpPDB *pdb)
|
||||||
gimp_pdb_register_procedure (pdb, procedure);
|
gimp_pdb_register_procedure (pdb, procedure);
|
||||||
g_object_unref (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
|
* gimp-plug-in-rotate
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -378,67 +378,6 @@ CODE
|
||||||
|
|
||||||
# We simplify the GEGL signature, reducing tile width and height to just size
|
# 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 {
|
sub plug_in_rotate {
|
||||||
$blurb = 'Rotates a layer or the whole image by 90, 180 or 270 degrees';
|
$blurb = 'Rotates a layer or the whole image by 90, 180 or 270 degrees';
|
||||||
|
|
||||||
|
@ -971,7 +910,6 @@ CODE
|
||||||
plug_in_displace
|
plug_in_displace
|
||||||
plug_in_emboss
|
plug_in_emboss
|
||||||
plug_in_gauss
|
plug_in_gauss
|
||||||
plug_in_plasma
|
|
||||||
plug_in_rotate
|
plug_in_rotate
|
||||||
plug_in_noisify);
|
plug_in_noisify);
|
||||||
|
|
||||||
|
|
|
@ -71,14 +71,19 @@ def foggify(procedure, run_mode, image, drawables, config, data):
|
||||||
fog.add_mask(mask)
|
fog.add_mask(mask)
|
||||||
|
|
||||||
# add some clouds to the layer
|
# add some clouds to the layer
|
||||||
pdb_proc = Gimp.get_pdb().lookup_procedure('plug-in-plasma')
|
_, x, y, width, height = mask.mask_intersect()
|
||||||
pdb_config = pdb_proc.create_config()
|
if not Gimp.Selection.is_empty(image):
|
||||||
pdb_config.set_property('run-mode', Gimp.RunMode.NONINTERACTIVE)
|
x = 0
|
||||||
pdb_config.set_property('image', image)
|
y = 0
|
||||||
pdb_config.set_property('drawable', mask)
|
plasma_filter = Gimp.DrawableFilter.new(mask, "gegl:plasma", "")
|
||||||
pdb_config.set_property('seed', int(time.time()))
|
plasma_filter_config = plasma_filter.get_config()
|
||||||
pdb_config.set_property('turbulence', turbulence)
|
plasma_filter_config.set_property("seed", int(time.time()))
|
||||||
pdb_proc.run(pdb_config)
|
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
|
# apply the clouds to the layer
|
||||||
fog.remove_mask(Gimp.MaskApplyMode.APPLY)
|
fog.remove_mask(Gimp.MaskApplyMode.APPLY)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue