]> git.imager.perl.org - imager.git/commitdiff
added OO interfaces for some filters
authorTony Cook <tony@develop=help.com>
Sun, 19 Aug 2001 13:14:02 +0000 (13:14 +0000)
committerTony Cook <tony@develop=help.com>
Sun, 19 Aug 2001 13:14:02 +0000 (13:14 +0000)
added a test script for the filters
committing some BMP changes I forgot to commit

Changes
Imager.pm
MANIFEST
feat.h
filters.c
image.h
t/t61filters.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 2552b403b5b7c9a23a7a68086a784f3a4177d131..2d5f0285ddc6870b476e914801879b9310b9c555 100644 (file)
--- a/Changes
+++ b/Changes
@@ -474,6 +474,9 @@ Revision history for Perl extension Imager.
         - minor problem in handling of canon option
         - low-level bmp writing (moving it to laptop)
         - Windows BMP reading and writing
+        - added OO interfaces for the mosaic, bumpmap, postlevels and
+          watermark filters
+        - added t/t61filters.t to test the filters
 
 =================================================================
 
index 3fa138177eff5bcde1c46847b27894c971e8e2eb..6eed0e0bc384673c86ca8d1eaee0a4bebd4f574d 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -226,6 +226,39 @@ BEGIN {
                         defaults => { },
                         callsub => sub { my %hsh = @_; i_gaussian($hsh{image}, $hsh{stddev}); },
                        };
+  $filters{mosaic} =
+    {
+     callseq => [ qw(image size) ],
+     defaults => { size => 20 },
+     callsub => sub { my %hsh = @_; i_mosaic($hsh{image}, $hsh{size}) },
+    };
+  $filters{bumpmap} =
+    {
+     callseq => [ qw(image bump elevation lightx lighty st) ],
+     defaults => { elevation=>0, st=> 2 },
+     callsub => sub { 
+       my %hsh = @_;
+       i_bumpmap($hsh{image}, $hsh{bump}{IMG}, $hsh{elevation},
+                 $hsh{lightx}, $hsh{lighty}, $hsh{st});
+     },
+    };
+  $filters{postlevels} =
+    {
+     callseq  => [ qw(image levels) ],
+     defaults => { levels => 10 },
+     callsub  => sub { my %hsh = @_; i_postlevels($hsh{image}, $hsh{levels}); },
+    };
+  $filters{watermark} =
+    {
+     callseq  => [ qw(image wmark tx ty pixdiff) ],
+     defaults => { pixdiff=>10, tx=>0, ty=>0 },
+     callsub  => 
+     sub { 
+       my %hsh = @_; 
+       i_watermark($hsh{image}, $hsh{wmark}{IMG}, $hsh{tx}, $hsh{ty}, 
+                   $hsh{pixdiff}); 
+     },
+    };
 
   $FORMATGUESS=\&def_guess_type;
 }
@@ -2797,14 +2830,17 @@ source.
 
   Filter          Arguments
   autolevels      lsat(0.1) usat(0.1) skew(0)
+  bumpmap         bump elevation(0) lightx lighty st(2)
   contrast        intensity
   conv            coef
   gaussian        stddev
   gradgen         xo yo colors dist
   hardinvert
   noise           amount(3) subtype(0)
+  postlevels      levels(10)
   radnoise        xo(100) yo(100) ascale(17.0) rscale(0.02)
   turbnoise       xo(0.0) yo(0.0) scale(10.0)
+  watermark       wmark pixdiff(10) tx(0) ty(0)
 
 The default values are in parenthesis.  All parameters must have some
 value but if a parameter has a default value it may be omitted when
@@ -2821,6 +2857,12 @@ cover the whole possible range for the channel.  I<lsat> and I<usat>
 truncate the range by the specified fraction at the top and bottom of
 the range respectivly..
 
+=item bumpmap
+
+uses the channel I<elevation> image I<bump> as a bumpmap on your
+image, with the light at (I<lightx>, I<lightty>), with a shadow length
+of I<st>.
+
 =item contrast
 
 scales each channel by I<intensity>.  Values of I<intensity> < 1.0
@@ -2863,15 +2905,25 @@ renders radiant Perlin turbulent noise.  The centre of the noise is at
 (I<xo>, I<yo>), I<ascale> controls the angular scale of the noise ,
 and I<rscale> the radial scale, higher numbers give more detail.
 
+=item postlevels
+
+alters the image to have only I<levels> distinct level in each
+channel.
+
 =item turbnoise
 
 renders Perlin turbulent noise.  (I<xo>, I<yo>) controls the origin of
 the noise, and I<scale> the scale of the noise, with lower numbers
 giving more detail.
 
+=item watermark
+
+applies I<wmark> as a watermark on the image with strength I<pixdiff>,
+with an origin at (I<tx>, I<ty>)
+
 =back
 
-A demonstration of the the filters can be found at:
+A demonstration of most of the filters can be found at:
 
   http://www.develop-help.com/imager/filters.html
 
index 6732f336b464bc3033d199ec7e33bb6f647a2da4..b2ccc6b006e86f20056ff5399ab94bc8563be8ca 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4,10 +4,11 @@ Imager.xs
 MANIFEST
 README
 Makefile.PL
-draw.c
-draw.h
+bmp.c
 conv.c
 convert.c
+draw.c
+draw.h
 map.c
 error.c
 gaussian.c
@@ -72,6 +73,7 @@ t/t103raw.t
 t/t104ppm.t
 t/t105gif.t
 t/t106tiff.t
+t/t107bmp.t
 t/t15color.t
 t/t30t1font.t
 t/t35ttfont.t
@@ -86,6 +88,7 @@ t/t57infix.t
 t/t58trans2.t
 t/t59assem.t
 t/t60dyntest.t
+t/t61filters.t
 t/t65crop.t
 t/t66paste.t
 t/t69rubthru.t
@@ -93,6 +96,8 @@ t/t70newgif.t
 t/t75polyaa.t
 t/t90cc.t
 testimg/bandw.gif
+testimg/comp4.bmp
+testimg/comp8.bmp
 testimg/expected.gif
 testimg/junk.ppm
 testimg/loccmap.gif
diff --git a/feat.h b/feat.h
index a935c62a2be4ae263872e9701175a9921b9768af..c82f953fb03efaba3e8fbbca111134095fa41a19 100644 (file)
--- a/feat.h
+++ b/feat.h
@@ -27,5 +27,6 @@ static char *i_format_list[]={
 #endif
   "raw",
   "pnm",
+  "bmp",
   NULL};
 
index 9ef9547ad7caceaf15e8bab6cc1243305e360dd2..5747ab4c3dca54d0706db791240f0b4b5e433d34 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -774,21 +774,6 @@ i_gradgen(i_img *im, int num, int *xo, int *yo, i_color *ival, int dmeasure) {
   
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 void
 i_nearest_color_foo(i_img *im, int num, int *xo, int *yo, i_color *ival, int dmeasure) {
 
diff --git a/image.h b/image.h
index 7c6a223020c91e3951ae8404e316e2384edafa9b..45f50408f4c60de5731df5838f9d252b8ae91b42 100644 (file)
--- a/image.h
+++ b/image.h
@@ -480,6 +480,7 @@ i_img   * i_readpnm_wiol(io_glue *ig, int length);
 undef_int i_writeppm_wiol(i_img *im, io_glue *ig);
 
 extern int i_writebmp_wiol(i_img *im, io_glue *ig);
+extern i_img *i_readbmp_wiol(io_glue *ig);
 
 i_img * i_scaleaxis(i_img *im, float Value, int Axis);
 i_img * i_scale_nn(i_img *im, float scx, float scy);
diff --git a/t/t61filters.t b/t/t61filters.t
new file mode 100644 (file)
index 0000000..17cdbc8
--- /dev/null
@@ -0,0 +1,66 @@
+#!perl -w
+use strict;
+use Imager qw(:handy);
+
+# meant for testing the filters themselves
+my $imbase = Imager->new;
+$imbase->open(file=>'testout/t104.ppm') or die;
+my $im_other = Imager->new(xsize=>150, ysize=>150);
+$im_other->box(xmin=>30, ymin=>60, xmax=>120, ymax=>90, filled=>1);
+
+print "1..26\n";
+
+test($imbase, 1, {type=>'autolevels'}, 'testout/t61_autolev.ppm');
+
+test($imbase, 3, {type=>'contrast', intensity=>0.5}, 
+     'testout/t61_contrast.ppm');
+
+# this one's kind of cool
+test($imbase, 5, {type=>'conv', coef=>[ -0.5, 1, -0.5, ], },
+     'testout/t61_conv.ppm');
+
+test($imbase, 7, {type=>'gaussian', stddev=>5 },
+     'testout/t61_gaussian.ppm');
+
+test($imbase, 9, { type=>'gradgen', dist=>1,
+                   xo=>[ 10,  10, 120 ],
+                   yo=>[ 10, 140,  60 ],
+                   colors=> [ NC('#FF0000'), NC('#FFFF00'), NC('#00FFFF') ]},
+     'testout/t61_gradgen.ppm');
+
+test($imbase, 11, {type=>'mosaic', size=>8}, 'testout/t61_mosaic.ppm');
+
+test($imbase, 13, {type=>'hardinvert'}, 'testout/t61_hardinvert.ppm');
+
+test($imbase, 15, {type=>'noise'}, 'testout/t61_noise.ppm');
+
+test($imbase, 17, {type=>'radnoise'}, 'testout/t61_radnoise.ppm');
+
+test($imbase, 19, {type=>'turbnoise'}, 'testout/t61_turbnoise.ppm');
+
+test($imbase, 21, {type=>'bumpmap', bump=>$im_other, lightx=>30, lighty=>30},
+     'testout/t61_bumpmap.ppm');
+
+test($imbase, 23, {type=>'postlevels', levels=>3}, 'testout/t61_postlevels.ppm');
+
+test($imbase, 25, {type=>'watermark', wmark=>$im_other },
+     'testout/t61_watermark.ppm');
+
+sub test {
+  my ($in, $num, $params, $out) = @_;
+  
+  my $copy = $in->copy;
+  if ($copy->filter(%$params)) {
+    print "ok $num\n";
+    if ($copy->write(file=>$out)) {
+      print "ok ",$num+1,"\n";
+    }
+    else {
+      print "not ok ",$num+1," # ",$copy->errstr,"\n";
+    }
+  }
+  else {
+    print "not ok $num # ",$copy->errstr,"\n";
+    print "ok ",$num+1," # skipped\n";
+  }
+}