[gimp-perl] Remove allowing just PF_IMAGE as return parameter. Bug 728538
- From: Ed J <edj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp-perl] Remove allowing just PF_IMAGE as return parameter. Bug 728538
- Date: Wed, 23 Apr 2014 05:12:45 +0000 (UTC)
commit dbf7ca0fbfb62485f126e9f546f176e6a12ab977
Author: Ed J <m8r-35s8eo mailinator com>
Date: Sat Apr 19 02:28:56 2014 +0100
Remove allowing just PF_IMAGE as return parameter. Bug 728538
Gimp/Fu.pm | 55 +++++++++++++++++++------------------
Gimp/Lib.xs | 4 +-
examples/bricks | 1 -
examples/example-fu | 70 +++++++++++++++++++++++++----------------------
examples/glowing_steel | 2 -
examples/goldenmean | 2 +-
examples/innerbevel | 4 ---
examples/pixelmap | 1 -
examples/randomart1 | 1 -
examples/stamps | 2 +-
examples/yinyang | 1 -
t/perlplugin.t | 29 ++++++++++++++++++-
12 files changed, 96 insertions(+), 76 deletions(-)
---
diff --git a/Gimp/Fu.pm b/Gimp/Fu.pm
index 7b45921..706f058 100644
--- a/Gimp/Fu.pm
+++ b/Gimp/Fu.pm
@@ -103,17 +103,15 @@ my %pf2info = map {
my @scripts;
# Some Standard Arguments
-my @image_params = ([Gimp::PDB_IMAGE, "image", "The image to work on"],
- [Gimp::PDB_DRAWABLE, "drawable", "The drawable to work on"]);
+my @image_params = ([PF_IMAGE, "image", "Input image"],
+ [PF_DRAWABLE, "drawable", "Input drawable"]);
-my @load_params = ([Gimp::PDB_STRING, "filename", "The name of the file"],
- [Gimp::PDB_STRING, "raw_filename", "The name of the file"]);
+my @load_params = ([PF_STRING, "filename", "Filename"],
+ [PF_STRING, "raw_filename", "User-given filename"]);
my @save_params = (@image_params, @load_params);
-my @load_retvals = ([Gimp::PDB_IMAGE, "image", "Output image"]);
-
-my $image_retval = [Gimp::PDB_IMAGE, "image", "The resulting image"];
+my $image_retval = [PF_IMAGE, "image", "Output image"];
# expand all the pod directives in string (currently they are only removed)
sub expand_podsections() {
@@ -171,7 +169,7 @@ sub string2pf($$) {
die __"$s: not a number\n" unless $s==1.0*$s;
$s*1.0;
} elsif($type == PF_COLOUR) {
- $s=Gimp::canonicalize_colour($s);
+ Gimp::canonicalize_colour($s);
} elsif($pf2info{$type}->[0] eq 'boolean') {
$s?1:0;
#} elsif($type == PF_IMAGE) {
@@ -260,13 +258,6 @@ Gimp::on_query {
my($perl_sub,$function,$blurb,$help,$author,$copyright,$date,
$menupath,$imagetypes,$params,$results,$code,$type)= $_;
- for (@$results) {
- next if ref $_;
- if ($_ == Gimp::PDB_IMAGE) {
- $_ = $image_retval;
- }
- }
-
for(@$params) {
next if $_->[0] < Gimp::PDB_END;
$_->[0] = $pf2info{$_->[0]}->[1] // datatype(values %{+{ {$_->[4]}}});
@@ -303,13 +294,17 @@ sub register($$$$$$$$$;@) {
if ($menupath =~ /^<Image>\//) {
$type = Gimp::PLUGIN;
- if (defined $imagetypes and length $imagetypes) {
+ if ($imagetypes) {
unshift @$params, @image_params;
+ } else {
+ # undef or ''
+ unshift @$results, $image_retval
+ if ! $results or $results->[0]->[0] != PF_IMAGE;
}
} elsif ($menupath =~ /^<Load>\//) {
$type = Gimp::PLUGIN;
unshift @$params, @load_params;
- unshift @$results, @load_retvals;
+ unshift @$results, $image_retval;
} elsif ($menupath =~ /^<Save>\//) {
$type = Gimp::PLUGIN;
unshift @$params, @save_params;
@@ -446,6 +441,7 @@ sub register($$$$$$$$$;@) {
}
}
+ Gimp->displays_flush;
wantarray ? @retvals : $retvals[0];
};
@@ -504,7 +500,7 @@ sub save_image($$) {
} elsif ($type eq "PNM") {
$layer->file_pnm_save($path,$path,1);
} else {
- $layer->gimp_file_save($path,$path);
+ $layer->file_save($path,$path);
}
}
@@ -523,7 +519,7 @@ EOF
my $default_text = defined $_->[3]
? " [".(ref $_->[3] eq 'ARRAY' ? "[ {$_->[3]}]" : $_->[3])."]"
: "";
- printf " -%-25s %s%s\n",
+ printf " --%-24s %s%s\n",
"$key $type",
$_->[2],
$default_text;
@@ -644,9 +640,12 @@ If the plugin works on or produces an image.
If the "image types" argument (see below) is defined and non-zero-length,
L<Gimp::Fu> will supply a C<PF_IMAGE> and C<PF_DRAWABLE> as the first
-two parameters to the plugin. If the plugin is intending to create
-an image rather than to work on an existing one, make sure you supply
-C<undef> or C<""> as the "image types".
+two parameters to the plugin.
+
+If the plugin is intending to create an image rather than to work on
+an existing one, make sure you supply C<undef> or C<""> as the "image
+types". In that case, L<Gimp::Fu> will supply a C<PF_IMAGE> return value
+if the first return value is not a C<PF_IMAGE>.
In any case, the plugin will be installed in the specified menu location;
almost always under C<File/Create> or C<Filters>.
@@ -720,9 +719,12 @@ that, e.g.:
"<Image>/Filters/Render/Do Something...",
"*",
[ [PF_INT32, "input", "Input value", 1] ],
- [ [PF_IMAGE, "output image", "Output image", 1] ],
+ [ [PF_IMAGE, "output image", "Output image"] ],
sub { Gimp::Image->new($_[0], $_[0], RGB) };
+If your "image types" is false, then L<Gimp::Fu> will ensure your first
+return parameter is a C<PF_IMAGE>.
+
=item the code
This is either an anonymous sub declaration (C<sub { your code here; }>, or a
@@ -736,10 +738,9 @@ You must make sure your plugin returns the correct types of value, or none:
();
};
-If you want to display images, you must have your script do that
-(and call C<Gimp-E<gt>displays_flush> at the end). C<Gimp::Fu> plugins
-will thereby be good GIMP "citizens", able to fit in with plugins/filters
-written in other languages.
+If you want to display images, you must have your script do
+that. C<Gimp::Fu> plugins will thereby be good GIMP "citizens", able to
+fit in with plugins/filters written in other languages.
=back
diff --git a/Gimp/Lib.xs b/Gimp/Lib.xs
index b0731b5..0d85567 100644
--- a/Gimp/Lib.xs
+++ b/Gimp/Lib.xs
@@ -545,8 +545,8 @@ convert_array2paramdef (AV *av, GimpParamDef **res)
if ((x = av_fetch (av, 0, 0))) type = *x;
if ((x = av_fetch (av, 1, 0))) name = *x;
if ((x = av_fetch (av, 2, 0))) help = *x;
- } else if (SvIOK(sv))
- type = sv;
+ } else
+ croak("Each parameter to a plugin must be an array-ref");
if (type) {
if (def) {
diff --git a/examples/bricks b/examples/bricks
index 1a0e12f..f70f747 100755
--- a/examples/bricks
+++ b/examples/bricks
@@ -153,7 +153,6 @@ register
[PF_STRING, "imageh", "Height of image", 256],
[PF_STRING, "skew", "Random darken/lighten factor (0..20)", 0]
],
- [PF_IMAGE],
\&do_bricks;
exit main();
diff --git a/examples/example-fu b/examples/example-fu
index ba6a2e6..dc98d23 100755
--- a/examples/example-fu
+++ b/examples/example-fu
@@ -5,37 +5,41 @@ use Gimp::Fu;
# expand your terminal to 121 across to read easily...
-register "gimp_fu_example_script", # fill in a function name
- "An example of Gimp::Fu usage, mostly non-functional", # and a short description,
- "Just a starting point to derive new ". # a (possibly multiline) help text
- "scripts. Always remember to put a long".
- "help message here!",
- "Marc Lehmann <pcg\ goof com>", # don't forget your name (author)
- "(c)1998,1999,2000 Marc Lehmann", # and your copyright!
- "20000321", # the date this script was written (YYYYMMDD)
- N_"<Toolbox>/Xtns/Gimp::Fu Example...", # the menu path - the 'N_' is for internationalization
- "", # image types to accept (RGB, RGAB and GRAYA)
- [ # one of each type of parameter here
- # argument type, switch name , a short description , default value, extra arguments
- [PF_SLIDER , "width" , "The image width" , 360, [300, 500]],
- [PF_SPINNER , "height" , "The image height" , 100, [100, 200]],
- [PF_STRING , "text" , "The Message" , "example text"],
- [PF_INT32 , "bordersize" , "The bordersize" , 10],
- [PF_FLOAT , "borderwidth" , "The borderwidth" , 1/5],
- [PF_FONT , "font" , "The Font Family" ],
- [PF_COLOUR , "text_colour" , "The (foreground) text colour", [10,10,10]],
- [PF_COLOUR , "bg_colour" , "The background colour" , [0xff,0x80,0]],
- [PF_TOGGLE , "ignore_cols" , "Ignore colours" , 0],
- [PF_IMAGE , "extra_image" , "An additonal picture to ignore"],
- [PF_DRAWABLE , "extra_draw" , "Somehting to ignroe as well" ],
- [PF_RADIO , "type" , "The effect type" , 0, [small => 0, large => 1]],
- [PF_BRUSH , "a_brush" , "An unused brush" ],
- [PF_PATTERN , "a_pattern" , "An unused pattern" ],
- [PF_GRADIENT , "a_gradients" , "An unused gradients" ],
- ],
- sub {
-
- # now do sth. useful with the garbage we got ;)
+register
+ "gimp_fu_example_script", # fill in a function name
+ "An example of Gimp::Fu usage, mostly non-functional", # and a short description,
+ "Just a starting point to derive new ". # a (possibly multiline) help text
+ "scripts. Always remember to put a long".
+ "help message here!",
+ "Marc Lehmann <pcg\ goof com>", # don't forget your name (author)
+ "(c)1998,1999,2000 Marc Lehmann", # and your copyright!
+ "20000321", # the date this script was written (YYYYMMDD)
+ N_"<Toolbox>/Xtns/Perl/Gimp::Fu Example...", # the menu path - the 'N_' is for internationalization
+ "", # image types to accept (RGB, RGAB and GRAYA) - blank or
undef means don't need one
+ [ # one of each type of parameter here
+ # argument type, switch name , a short description , default value, extra arguments
+ [PF_SLIDER , "width" , "The image width" , 360, [300, 500]],
+ [PF_SPINNER , "height" , "The image height" , 100, [100, 200]],
+ [PF_STRING , "text" , "The Message" , "example text"],
+ [PF_INT32 , "bordersize" , "The bordersize" , 10],
+ [PF_FLOAT , "borderwidth" , "The borderwidth" , 1/5],
+ [PF_FONT , "font" , "The Font Family" ],
+ [PF_COLOUR , "text_colour" , "The (foreground) text colour", [10,10,10]],
+ [PF_COLOUR , "bg_colour" , "The background colour" , [0xff,0x80,0]],
+ [PF_TOGGLE , "ignore_cols" , "Ignore colours" , 0],
+ [PF_IMAGE , "extra_image" , "An additonal picture to ignore"],
+ [PF_DRAWABLE , "extra_draw" , "Somehting to ignroe as well" ],
+ [PF_RADIO , "type" , "The effect type" , 0, [small => 0, large => 1]],
+ [PF_BRUSH , "a_brush" , "An unused brush" ],
+ [PF_PATTERN , "a_pattern" , "An unused pattern" ],
+ [PF_GRADIENT , "a_gradients" , "An unused gradients" ],
+ ],
+ [
+ [PF_IMAGE , "output image", "Output image"],
+ ],
+ sub {
+
+ # now do something useful with our parameters
my($width,$height,$text,$brd1,$brd2,$font,$fg,$bg,$ignore,$xtraimg,$xtradrw,$effecttype,$brush,$pattern,$gradient)=
_;
# set tracing, disable this to get rid of the debugging output
@@ -52,7 +56,7 @@ register "gimp_fu_example_script", # fill in a function name
# the __ before the string in the next line indicates text that must be translated
my $l = new Gimp::Layer ($img, $width, $height, RGB, __"Background", 100, NORMAL_MODE);
- $l->insert_layer(0,0);
+ $l->insert_layer(0, 0);
# now a few syntax examples
@@ -70,7 +74,7 @@ register "gimp_fu_example_script", # fill in a function name
# restore original context
Gimp::Context->pop();
- $img; # return the image, or an empty list, i.e. ()
+ $img; # return the image, as it's on our output parameters
};
exit main;
diff --git a/examples/glowing_steel b/examples/glowing_steel
index ffbd91d..32ac000 100755
--- a/examples/glowing_steel
+++ b/examples/glowing_steel
@@ -316,7 +316,6 @@ register
"film \"Lost In Space\".",
"Aaron Sherman", "Aaron Sherman (c)", "1999-06-14",
N_"<Image>/File/Create/Logos/Glowing Steel",
-
undef,
[
[PF_STRING, "string", "string", "GET LOST"],
@@ -329,7 +328,6 @@ register
[PF_TOGGLE, "highlight_edges", "", 0],
[PF_TOGGLE, "antialias", "", 1]
],
- [PF_IMAGE],
\&perl_fu_glowing_steel;
exit main;
diff --git a/examples/goldenmean b/examples/goldenmean
index ff34e0f..db46657 100755
--- a/examples/goldenmean
+++ b/examples/goldenmean
@@ -27,7 +27,7 @@ sub goldenmean {
$layer->gimp_edit_fill(BACKGROUND_FILL);
Gimp::Context->pop();
- return;
+ return $img;
}
register "golden_mean",
diff --git a/examples/innerbevel b/examples/innerbevel
index e544340..ad1d1ec 100755
--- a/examples/innerbevel
+++ b/examples/innerbevel
@@ -43,11 +43,7 @@ register $regname, $shortdesc, $longdesc, $authorname, $author, $date, $path, $i
[PF_SLIDER, "depth_shape", "Determines the final shape", 7 , [0,64,32]],
[PF_RADIO, "map", "The type of Map to use(0=Linear,1=Spherical,2=Sinusoidal)", 2, [Linear => 0, Spherical
=> 1, Sinusoidal => 2] ],
],
- [
- [PF_IMAGE, "image", "Return image", 0],
- ],
sub {
-
my ($font, $fontsize, $text, $color1, $color2, $azimuth, $elevation, $depth, $maptype) = @_;
# -- step 1 --
diff --git a/examples/pixelmap b/examples/pixelmap
index 667c5f5..2924336 100755
--- a/examples/pixelmap
+++ b/examples/pixelmap
@@ -79,7 +79,6 @@ register "pixelgen",
GRAYA => GRAYA_IMAGE, INDEXED => INDEXED_IMAGE, INDEXEDA
=> INDEXEDA_IMAGE]],
[PF_TEXT, "expression" , "The perl expression to use",
"(\$x*\$y*0.01)\n->slice(\"*\$bpp\")"]
],
- [PF_IMAGE],
sub {
my($w,$h,$type,$expr)= _;
my $image = new Gimp::Image $w, $h, Gimp->layer2imagetype($type);
diff --git a/examples/randomart1 b/examples/randomart1
index b114ffc..4d29a8d 100755
--- a/examples/randomart1
+++ b/examples/randomart1
@@ -33,7 +33,6 @@ register "random_art_1", # Funktionsname
[PF_SLIDER, 'feather', 'Feather Radius', 30, [1, 100]],
[PF_BOOL, 'supersample', 'Adaptive Supersampling?', 0],
],
- [PF_IMAGE],
sub { # Perl-Code
# Die Parameter werden ganz "normal" �bergeben:
my ($w,$h,$num_poly,$edges,$revolutions,$feather,$super)= _;
diff --git a/examples/stamps b/examples/stamps
index 80b4934..08318b2 100755
--- a/examples/stamps
+++ b/examples/stamps
@@ -38,7 +38,7 @@ sub stamps {
# here, at last, comes the clever part! :-)
$layer->offset(1, 0, -($diameter / 2), -($diameter / 2));
- return;
+ return $img;
}
register "stamps",
diff --git a/examples/yinyang b/examples/yinyang
index 5909cdf..69cf9e9 100755
--- a/examples/yinyang
+++ b/examples/yinyang
@@ -126,7 +126,6 @@ register("yinyang",
[PF_STRING, "bottom_eye_filename", "eye 2", ""],
[PF_TOGGLE, "anti_aliasing", "", 1]
],
- [PF_IMAGE],
\&yinyang);
exit main;
diff --git a/t/perlplugin.t b/t/perlplugin.t
index 70dc8bd..b587da1 100644
--- a/t/perlplugin.t
+++ b/t/perlplugin.t
@@ -14,13 +14,13 @@ use Gimp qw(:auto __ N_);
use Gimp::Fu;
sub boilerplate_params {
- my ($testing, $menuloc) = @_;
+ my ($testing, $menuloc, $imagetypes) = @_;
(
("exercise gimp-perl filter testing $testing") x 2,
("boilerplate id") x 2,
"20140310",
N_$menuloc,
- "*",
+ $imagetypes // "*",
);
}
@@ -128,6 +128,25 @@ sub boilerplate_params {
);
®ister(
+ "test_create_return_image",
+ boilerplate_params('retval addition', '<Image>/File/Create/x1', ''),
+ [],
+ [
+ ],
+ sub { Gimp::Image->new(20, 20, RGB) }
+);
+
+®ister(
+ "test_create_return_int_image",
+ boilerplate_params('retval addition', '<Image>/File/Create/x1', ''),
+ [],
+ [
+ [ PF_INT32, "int", "Output int", ],
+ ],
+ sub { (Gimp::Image->new(20, 20, RGB), 2) }
+);
+
+®ister(
"test_perl_filter",
boilerplate_params('filter', '<Image>/Filters'),
[ [PF_STRING, "text", "Text to name layer", "hello"], ],
@@ -187,6 +206,12 @@ eval { Gimp::Plugin->test_return_toomany; };
like($@, qr/too many/, 'too many return values is error');
eval { Gimp::Plugin->test_return_toofew; };
like($@, qr/too few/, 'too few return values is error');
+isa_ok(Gimp::Plugin->test_create_return_image, 'Gimp::Image', 'add image ret');
+is_deeply(
+ [ map { ref($_) || $_ } Gimp::Plugin->test_create_return_int_image ],
+ [ 'Gimp::Image', 2 ],
+ 'add image ret when other ret there'
+);
# if enable next line, brings up script dialog
# color one works, font doesn't - speculate is due to being in "batch mode"
#Gimp::Plugin->test_dialogs(RUN_INTERACTIVE, [0,0,0], "Arial", 150, );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]