]> git.imager.perl.org - imager.git/blob - t/t61filters.t
65e45048976896ec0c9eaaa8856d353b790ada36
[imager.git] / t / t61filters.t
1 #!perl -w
2 use strict;
3 use Imager qw(:handy);
4 use Test::More tests => 45;
5 Imager::init_log("testout/t61filters.log", 1);
6 # meant for testing the filters themselves
7 my $imbase = Imager->new;
8 $imbase->open(file=>'testout/t104.ppm') or die;
9 my $im_other = Imager->new(xsize=>150, ysize=>150);
10 $im_other->box(xmin=>30, ymin=>60, xmax=>120, ymax=>90, filled=>1);
11
12 test($imbase, {type=>'autolevels'}, 'testout/t61_autolev.ppm');
13
14 test($imbase, {type=>'contrast', intensity=>0.5}, 
15      'testout/t61_contrast.ppm');
16
17 # this one's kind of cool
18 test($imbase, {type=>'conv', coef=>[ -0.5, 1, -0.5, ], },
19      'testout/t61_conv.ppm');
20
21 test($imbase, {type=>'gaussian', stddev=>5 },
22      'testout/t61_gaussian.ppm');
23
24 test($imbase, { type=>'gradgen', dist=>1,
25                    xo=>[ 10,  10, 120 ],
26                    yo=>[ 10, 140,  60 ],
27                    colors=> [ NC('#FF0000'), NC('#FFFF00'), NC('#00FFFF') ]},
28      'testout/t61_gradgen.ppm');
29
30 test($imbase, {type=>'mosaic', size=>8}, 'testout/t61_mosaic.ppm');
31
32 test($imbase, {type=>'hardinvert'}, 'testout/t61_hardinvert.ppm');
33
34 test($imbase, {type=>'noise'}, 'testout/t61_noise.ppm');
35
36 test($imbase, {type=>'radnoise'}, 'testout/t61_radnoise.ppm');
37
38 test($imbase, {type=>'turbnoise'}, 'testout/t61_turbnoise.ppm');
39
40 test($imbase, {type=>'bumpmap', bump=>$im_other, lightx=>30, lighty=>30},
41      'testout/t61_bumpmap.ppm');
42
43 test($imbase, {type=>'bumpmap_complex', bump=>$im_other}, 'testout/t61_bumpmap_complex.ppm');
44
45 test($imbase, {type=>'postlevels', levels=>3}, 'testout/t61_postlevels.ppm');
46
47 test($imbase, {type=>'watermark', wmark=>$im_other },
48      'testout/t61_watermark.ppm');
49
50 test($imbase, {type=>'fountain', xa=>75, ya=>75, xb=>85, yb=>30,
51                repeat=>'triangle', #ftype=>'radial', 
52                super_sample=>'circle', ssample_param => 16,
53               },
54      'testout/t61_fountain.ppm');
55 use Imager::Fountain;
56
57 my $f1 = Imager::Fountain->new;
58 $f1->add(end=>0.2, c0=>NC(255, 0,0), c1=>NC(255, 255,0));
59 $f1->add(start=>0.2, c0=>NC(255,255,0), c1=>NC(0,0,255,0));
60 test($imbase, { type=>'fountain', xa=>20, ya=>130, xb=>130, yb=>20,
61                 #repeat=>'triangle',
62                 segments=>$f1
63               },
64      'testout/t61_fountain2.ppm');
65 my $f2 = Imager::Fountain->new
66   ->add(end=>0.5, c0=>NC(255,0,0), c1=>NC(255,0,0), color=>'hueup')
67   ->add(start=>0.5, c0=>NC(255,0,0), c1=>NC(255,0,0), color=>'huedown');
68 #use Data::Dumper;
69 #print Dumper($f2);
70 test($imbase, { type=>'fountain', xa=>20, ya=>130, xb=>130, yb=>20,
71                     segments=>$f2 },
72      'testout/t61_fount_hsv.ppm');
73 my $f3 = Imager::Fountain->read(gimp=>'testimg/gimpgrad');
74 ok($f3, "read gimpgrad");
75 test($imbase, { type=>'fountain', xa=>75, ya=>75, xb=>90, yb=>15,
76                     segments=>$f3, super_sample=>'grid',
77                     ftype=>'radial_square', combine=>'color' },
78      'testout/t61_fount_gimp.ppm');
79 test($imbase, { type=>'unsharpmask', stddev=>2.0 },
80      'testout/t61_unsharp.ppm');
81 test($imbase, {type=>'conv', coef=>[ -1, 3, -1, ], },
82      'testout/t61_conv_sharp.ppm');
83
84 # Regression test: the checking of the segment type was incorrect
85 # (the comparison was checking the wrong variable against the wrong value)
86 my $f4 = [ [ 0, 0.5, 1, NC(0,0,0), NC(255,255,255), 5, 0 ] ];
87 test($imbase, {type=>'fountain',  xa=>75, ya=>75, xb=>90, yb=>15,
88                segments=>$f4, super_sample=>'grid',
89                ftype=>'linear', combine=>'color' },
90      'testout/t61_regress_fount.ppm');
91 my $im2 = $imbase->copy;
92 $im2->box(xmin=>20, ymin=>20, xmax=>40, ymax=>40, color=>'FF0000', filled=>1);
93 $im2->write(file=>'testout/t61_diff_base.ppm');
94 my $im3 = Imager->new(xsize=>150, ysize=>150, channels=>3);
95 $im3->box(xmin=>20, ymin=>20, xmax=>40, ymax=>40, color=>'FF0000', filled=>1);
96 my $diff = $imbase->difference(other=>$im2);
97 ok($diff, "got difference image");
98 SKIP:
99 {
100   skip(1, "missing comp or diff image") unless $im3 && $diff;
101
102   is(Imager::i_img_diff($im3->{IMG}, $diff->{IMG}), 0,
103      "compare test image and diff image");
104 }
105
106 sub test {
107   my ($in, $params, $out) = @_;
108
109   my $copy = $in->copy;
110   if (ok($copy->filter(%$params), $params->{type})) {
111     ok($copy->write(file=>$out), "write $params->{type}") 
112       or print "# ",$copy->errstr,"\n";
113   }
114   else {
115   SKIP: 
116     {
117       skip("couldn't filter", 1);
118     }
119   }
120 }