Commit 9258cc20 authored by Marc Lehmann's avatar Marc Lehmann
Browse files

see plug-ins/perl/Changes

parent ea0e9231
Revision history for Gimp-Perl extension.
- improved gouge ;) In a sense, it's actually pretty code now!
- region functions (except data) wrongly returned transposed matrices.
Now the order of dimensions is bpp <- width <- height.
- implemented and added examples/gouge.
......
......@@ -9,19 +9,10 @@ use Gimp::Fu;
use Gimp::Util;
use PDL::LiteF;
register "gouge_smooth",
"smooth (low pass filter) an image using the gouge algorithm",
"Low-Pass filtering (smoothing) using a fast algorithm found in a paper by James O. Gouge.",
"Marc Lehmann",
"Marc Lehmann <pcg\@goof.com>",
"19990723",
"<Image>/Filters/Blur/Gouge",
"RGB*, GRAY*",
[],
sub {
my($image,$drawable)=@_;
sub iterate {
my ($drawable,$message,$kernel)=@_;
Gimp->progress_init ("Gouge smoothing...");
Gimp->progress_init ($message);
my @bounds = $drawable->mask;
my @off = $drawable->offsets;
......@@ -33,19 +24,15 @@ register "gouge_smooth",
my $bpp = $src->bpp > 1 ? ":," : "";
$iter = Gimp->pixel_rgns_register ($dst);
my $iter = Gimp->pixel_rgns_register ($dst);
my $area = $bounds[2]*$bounds[3];
my $progress = 0;
do {
my ($x,$y,$w,$h)=($dst->x,$dst->y,$dst->w,$dst->h);
my $reg = $src->get_rect($x,$y,$w+1,$h+1)->convert(short);
$dst->data(($reg->slice("${bpp}0:-2,0:-2")+
$reg->slice("${bpp}1:-1,0:-2")+
$reg->slice("${bpp}1:-1,1:-1")+
$reg->slice("${bpp}0:-2,1:-1"))>>2);
Gimp->progress_update (($dst->y-$bounds[1])/$bounds[2]);
$dst->data($kernel->($bpp,$src->get_rect($x,$y,$w+1,$h+1)->convert(short)));
$progress += $w*$h/$area;
Gimp->progress_update ($progress);
} while (Gimp->pixel_rgns_process ($iter));
}
Gimp->progress_update (1);
......@@ -54,6 +41,28 @@ register "gouge_smooth",
$drawable->update (@bounds);
();
}
register "gouge_smooth",
"smooth (low pass filter) an image using the gouge algorithm",
"Low-Pass filtering (smoothing) using a fast algorithm found in a paper by James O. Gouge.",
"Marc Lehmann",
"Marc Lehmann <pcg\@goof.com>",
"19990723",
"<Image>/Filters/Blur/Gouge",
"RGB*, GRAY*",
[],
sub {
my($image,$drawable)=@_;
iterate $drawable,
"Gouge smoothing...",
sub {
($_[1]->slice("$_[0]0:-2,0:-2")+
$_[1]->slice("$_[0]1:-1,0:-2")+
$_[1]->slice("$_[0]1:-1,1:-1")+
$_[1]->slice("$_[0]0:-2,1:-1"))>>2;
};
};
register "gouge_contrast",
......@@ -68,38 +77,14 @@ register "gouge_contrast",
sub {
my($image,$drawable)=@_;
Gimp->progress_init ("Gouge contrast enhancing...");
iterate $drawable,
"Gouge contrast enhancing...",
sub {
my $T = $_[1]->slice("$_[0]0:-2,0:-2");
my $D = $_[1]->slice("$_[0]1:-1,1:-1");
my @bounds = $drawable->mask;
my @off = $drawable->offsets;
$bounds[2]-- if $bounds[0]+$bounds[2] >= ($drawable->offsets)[0]+$drawable->width;
$bounds[3]-- if $bounds[1]+$bounds[3] >= ($drawable->offsets)[1]+$drawable->height;
{
my $src = new PixelRgn ($drawable->get,@bounds[0,1],$bounds[2]+1,$bounds[3]+1,0,0);
my $dst = new PixelRgn ($drawable->get,@bounds,1,1);
my $bpp = $src->bpp > 1 ? ":," : "";
$iter = Gimp->pixel_rgns_register ($dst);
do {
my ($x,$y,$w,$h)=($dst->x,$dst->y,$dst->w,$dst->h);
my $reg = $src->get_rect($x,$y,$w+1,$h+1)->convert(short);
my $T = $reg->slice("${bpp}0:-2,0:-2");
my $D = $reg->slice("${bpp}1:-1,1:-1");
$dst->data((($T<<1)-$D)->clip(0,255));
Gimp->progress_update (($dst->y-$bounds[1])/$bounds[2]);
} while (Gimp->pixel_rgns_process ($iter));
}
Gimp->progress_update (1);
$drawable->merge_shadow (1);
$drawable->update (@bounds);
();
(($T<<1)-$D)->clip(0,255);
};
};
register "gouge_edge",
......@@ -113,43 +98,20 @@ register "gouge_edge",
[],
sub {
my($image,$drawable)=@_;
Gimp->progress_init ("Gouge edge detection...");
my @bounds = $drawable->mask;
my @off = $drawable->offsets;
$bounds[2]-- if $bounds[0]+$bounds[2] >= ($drawable->offsets)[0]+$drawable->width;
$bounds[3]-- if $bounds[1]+$bounds[3] >= ($drawable->offsets)[1]+$drawable->height;
{
my $src = new PixelRgn ($drawable->get,@bounds[0,1],$bounds[2]+1,$bounds[3]+1,0,0);
my $dst = new PixelRgn ($drawable->get,@bounds,1,1);
my $bpp = $src->bpp > 1 ? ":," : "";
$iter = Gimp->pixel_rgns_register ($dst);
do {
my ($x,$y,$w,$h)=($dst->x,$dst->y,$dst->w,$dst->h);
my $reg = $src->get_rect($x,$y,$w+1,$h+1)->convert(short);
my $T = $reg->slice("${bpp}0:-2,0:-2");
my $R = $reg->slice("${bpp}1:-1,0:-2");
my $D = $reg->slice("${bpp}1:-1,1:-1");
$dst->data(abs(cat($T-$R,$T-$D))
->convert(byte)
->mv(!!$bpp+2,0)
->maximum);
Gimp->progress_update (($src->y-$bounds[1])/$bounds[2]);
} while (Gimp->pixel_rgns_process ($iter));
}
Gimp->progress_update (1);
$drawable->merge_shadow (1);
$drawable->update (@bounds);
();
my $bpp = 3-!!($drawable->gray);
iterate $drawable,
"Gouge edge detection...",
sub {
my $T = $_[1]->slice("$_[0]0:-2,0:-2");
my $R = $_[1]->slice("$_[0]1:-1,0:-2");
my $D = $_[1]->slice("$_[0]1:-1,1:-1");
255-abs(cat($T-$R,$T-$D))
->convert(byte)
->mv($bpp,0)
->maximum;
};
};
exit main;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment