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);
12 test($imbase, {type=>'autolevels'}, 'testout/t61_autolev.ppm');
14 test($imbase, {type=>'contrast', intensity=>0.5},
15 'testout/t61_contrast.ppm');
17 # this one's kind of cool
18 test($imbase, {type=>'conv', coef=>[ -0.5, 1, -0.5, ], },
19 'testout/t61_conv.ppm');
21 test($imbase, {type=>'gaussian', stddev=>5 },
22 'testout/t61_gaussian.ppm');
24 test($imbase, { type=>'gradgen', dist=>1,
27 colors=> [ NC('#FF0000'), NC('#FFFF00'), NC('#00FFFF') ]},
28 'testout/t61_gradgen.ppm');
30 test($imbase, {type=>'mosaic', size=>8}, 'testout/t61_mosaic.ppm');
32 test($imbase, {type=>'hardinvert'}, 'testout/t61_hardinvert.ppm');
34 test($imbase, {type=>'noise'}, 'testout/t61_noise.ppm');
36 test($imbase, {type=>'radnoise'}, 'testout/t61_radnoise.ppm');
38 test($imbase, {type=>'turbnoise'}, 'testout/t61_turbnoise.ppm');
40 test($imbase, {type=>'bumpmap', bump=>$im_other, lightx=>30, lighty=>30},
41 'testout/t61_bumpmap.ppm');
43 test($imbase, {type=>'bumpmap_complex', bump=>$im_other}, 'testout/t61_bumpmap_complex.ppm');
45 test($imbase, {type=>'postlevels', levels=>3}, 'testout/t61_postlevels.ppm');
47 test($imbase, {type=>'watermark', wmark=>$im_other },
48 'testout/t61_watermark.ppm');
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,
54 'testout/t61_fountain.ppm');
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,
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');
70 test($imbase, { type=>'fountain', xa=>20, ya=>130, xb=>130, yb=>20,
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');
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");
100 skip(1, "missing comp or diff image") unless $im3 && $diff;
102 is(Imager::i_img_diff($im3->{IMG}, $diff->{IMG}), 0,
103 "compare test image and diff image");
107 my ($in, $params, $out) = @_;
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";
117 skip("couldn't filter", 1);