]> git.imager.perl.org - imager.git/commitdiff
[rt #70126] optimize the flines filter implementations
authorTony Cook <tony@develop-help.com>
Mon, 15 Aug 2011 12:06:28 +0000 (22:06 +1000)
committerTony Cook <tony@develop-help.com>
Mon, 15 Aug 2011 12:06:28 +0000 (22:06 +1000)
and modernize the tests

Changes
Flines/Flines.xs
Flines/t/t00flines.t
dynfilt/flines.c
dynfilt/t/t60dyntest.t

diff --git a/Changes b/Changes
index a5860123f74f5cf8dafadb5d94c20e7d385cf3c1..98062caae200a69484ef07816ec54c0c7f192218 100644 (file)
--- a/Changes
+++ b/Changes
@@ -25,6 +25,10 @@ Bug fixes:
    CPAN::Meta::YAML are available.
    https://rt.cpan.org/Ticket/Display.html?id=69008
 
+ - hoist the per-line calculations for the flines implementations, and
+   modernize the tests a bit.
+   https://rt.cpan.org/Ticket/Display.html?id=70126
+
 Imager 0.84_01 - 8 Aug 2011
 ==============
 
index 282be66607078685ff53f0532f31377804366899..ead4a30ca3b269975cdbbafd6bdd8e7f503ab38d 100644 (file)
@@ -21,30 +21,27 @@ saturate(int in) {
   return 0;
 }
 
-
-
-void
+static void
 flines(i_img *im) {
   i_color vl;
   i_img_dim x,y;
-  
+
   for(y = 0; y < im->ysize; y ++) {
+    float yf, mf;
+    if (!(y%2)) {
+      yf = y/(double)im->ysize;
+    }
+    else {
+      yf = (im->ysize-y)/(double)im->ysize;
+    }
+    mf = 1.2-0.8*yf;
+
     for(x = 0; x < im->xsize; x ++ ) {
       i_gpix(im,x,y,&vl); 
-                       if (!(y%2)) {
-                               float yf = y/(double)im->ysize;
-                               float mf = 1.2-0.8*yf;
-                               vl.rgb.r = saturate(vl.rgb.r*mf);
-                               vl.rgb.g = saturate(vl.rgb.g*mf);
-                               vl.rgb.b = saturate(vl.rgb.b*mf);
-                       } else {
-                               float yf = (im->ysize-y)/(double)im->ysize;
-                               float mf = 1.2-0.8*yf;
-                               vl.rgb.r = saturate(vl.rgb.r*mf);
-                               vl.rgb.g = saturate(vl.rgb.g*mf);
-                               vl.rgb.b = saturate(vl.rgb.b*mf);
-                       } 
-     i_ppix(im,x,y,&vl); 
+      vl.rgb.r = saturate(vl.rgb.r*mf);
+      vl.rgb.g = saturate(vl.rgb.g*mf);
+      vl.rgb.b = saturate(vl.rgb.b*mf);
+      i_ppix(im,x,y,&vl);
     }
   }
 }
index 341c4536a204597fbae68eb4de98788f9580ab37..8c97b3ed1f563245d2082065bd5a59fb5b06a1a2 100644 (file)
@@ -6,17 +6,33 @@ use Test::More tests => 3;
 
 BEGIN { use_ok('Imager::Filter::Flines') }
 
-my $im = Imager->new(xsize=>150, ysize=>150);
+-d "testout" or mkdir "testout";
 
-$im->box(filled=>1, xmin => 70, ymin=>25, xmax =>130, ymax => 125, 
-         color=>'00FF00');
-$im->box(filled=>1, xmin=>20, ymin=>25, xmax=>80, ymax=>125,
-         color => '0000FF');
-$im->arc(x =>75, y=>75, r=>30, color => 'FF0000');
-$im->filter(type=>"conv", coef => [0.1, 0.2, 0.4, 0.2, 0.1]);
+Imager->open_log(log => "testout/t00flines.log");
 
-ok($im->filter(type=>'flines'),
-   "try filter")
-  or print "# ", $im->errstr, "\n";
-ok($im->write(file => '../testout/t00flines.ppm'),
-   "save result");
+{
+  my $im = Imager->new(xsize=>150, ysize=>150);
+  
+  $im->box(filled=>1, xmin => 70, ymin=>25, xmax =>130, ymax => 125, 
+          color=>'00FF00');
+  $im->box(filled=>1, xmin=>20, ymin=>25, xmax=>80, ymax=>125,
+          color => '0000FF');
+  $im->arc(x =>75, y=>75, r=>30, color => 'FF0000');
+  $im->filter(type=>"conv", coef => [0.1, 0.2, 0.4, 0.2, 0.1]);
+
+  ok($im->filter(type=>'flines'),
+     "try filter")
+    or print "# ", $im->errstr, "\n";
+  ok($im->write(file => 'testout/t00flines.ppm'),
+     "save result");
+}
+
+END {
+  Imager->close_log;
+
+  unless ($ENV{IMAGER_KEEP_FILES}) {
+    unlink 'testout/t00flines.ppm';
+    unlink "testout/t00flines.log";
+    rmdir "testout";
+  }
+}
index 0de80e7a9442a18a5895b69e673be76ce78cd6b0..f42a37b1eac6546106417820e5b60612380dcd9a 100644 (file)
@@ -35,22 +35,21 @@ flines(void *INP) {
          i_DFcp(im->xsize,im->ysize), im->channels);
 
   for(y = 0; y < im->ysize; y ++) {
+    float yf, mf;
+    if (!(y%2)) {
+      yf = y/(double)im->ysize;
+    }
+    else {
+      yf = (im->ysize-y)/(double)im->ysize;
+    }
+    mf = 1.2-0.8*yf;
+
     for(x = 0; x < im->xsize; x ++ ) {
       i_gpix(im,x,y,&vl); 
-                       if (!(y%2)) {
-                               float yf = y/(double)im->ysize;
-                               float mf = 1.2-0.8*yf;
-                               vl.rgb.r = saturate(vl.rgb.r*mf);
-                               vl.rgb.g = saturate(vl.rgb.g*mf);
-                               vl.rgb.b = saturate(vl.rgb.b*mf);
-                       } else {
-                               float yf = (im->ysize-y)/(double)im->ysize;
-                               float mf = 1.2-0.8*yf;
-                               vl.rgb.r = saturate(vl.rgb.r*mf);
-                               vl.rgb.g = saturate(vl.rgb.g*mf);
-                               vl.rgb.b = saturate(vl.rgb.b*mf);
-                       } 
-     i_ppix(im,x,y,&vl); 
+      vl.rgb.r = saturate(vl.rgb.r*mf);
+      vl.rgb.g = saturate(vl.rgb.g*mf);
+      vl.rgb.b = saturate(vl.rgb.b*mf);
+      i_ppix(im,x,y,&vl); 
     }
   }
 }
index 29fcca687199d2cc3f1f32b2e7cd3fa5dbbd8abd..f0dc227fe6e9af794cbd66faf3c512af149827c5 100644 (file)
@@ -1,13 +1,16 @@
 #!perl -w
 use strict;
 use lib '../t';
-use Test::More tests => 4;
+use Test::More tests => 8;
 BEGIN { use_ok(Imager => qw(:default)); }
 use Config;
+use Imager::Test qw(test_image);
 
 #$Imager::DEBUG=1;
 
-Imager::init('log'=>'../testout/t60dyntest.log');
+-d "testout" or mkdir "testout";
+
+Imager->open_log(log => 'testout/t60dyntest.log');
 
 my $img=Imager->new() || die "unable to create image object\n";
 
@@ -21,11 +24,27 @@ ok(load_plugin($plug), "load plugin")
 my %hsh=(a=>35,b=>200,type=>'lin_stretch');
 ok($img->filter(%hsh), "call filter");
 
-$img->write(type=>'pnm',file=>'../testout/t60.ppm') 
+$img->write(type=>'pnm',file=>'testout/linstretch.ppm') 
   || die "error in write()\n";
 
 ok(unload_plugin($plug), "unload plugin")
   || die "unable to unload plugin: $Imager::ERRSTR\n";
 
-
+{
+  my $flines = "./flines.$Config{so}";
+  ok(load_plugin($flines), "load flines");
+  my $im = test_image();
+  ok($im->filter(type => "flines"), "do the flines test");
+  ok($im->write(file => "testout/flines.ppm"), "save flines result");
+  ok(unload_plugin($flines), "unload flines");
+}
+
+Imager->close_log;
+
+unless ($ENV{IMAGER_KEEP_FILES}) {
+  unlink "testout/linstretch.ppm";
+  unlink "testout/flines.ppm";
+  unlink "testout/t60dyntest.log";
+  rmdir "testout";
+}