2 BEGIN { $| = 1; print "1..43\n"; }
3 END {print "not ok 1\n" unless $loaded;}
10 Imager::init('log'=>'testout/t64copyflip.log');
12 $img=Imager->new() or die "unable to create image object\n";
14 $img->open(file=>'testimg/scale.ppm',type=>'pnm');
15 $nimg = $img->copy() or skip ( "\# warning ".$img->{'ERRSTR'}."\n" );
18 # test if ->copy() works
20 $diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
21 if ($diff > 0) { print "not ok 2 # copy and original differ!\n"; }
22 else { print "ok 2\n"; }
25 # test if ->flip(dir=>'h')->flip(dir=>'h') doesn't alter the image
27 $nimg->flip(dir=>"h")->flip(dir=>"h");
28 $diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
29 if ($diff > 0) { print "not ok 3 # double horizontal flip and original differ!\n"; }
30 else { print "ok 3\n"; }
33 # test if ->flip(dir=>'v')->flip(dir=>'v') doesn't alter the image
35 $nimg->flip(dir=>"v")->flip(dir=>"v");
36 $diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
37 if ($diff > 0) { print "not ok 4 # double vertical flip and original differ!\n"; }
38 else { print "ok 4\n"; }
41 # test if ->flip(dir=>'h')->flip(dir=>'v') is same as ->flip(dir=>'hv')
43 $nimg->flip(dir=>"v")->flip(dir=>"h")->flip(dir=>"hv");;
44 $diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
46 print "not ok 5 # double flips and original differ!\n";
47 $nimg->write(file=>"testout/t64copyflip_error.ppm") or die $nimg->errstr();
49 else { print "ok 5\n"; }
51 rot_test(6, $img, 90, 4);
52 rot_test(10, $img, 180, 2);
53 rot_test(14, $img, 270, 4);
54 rot_test(18, $img, 0, 1);
56 my $pimg = $img->to_paletted();
57 rot_test(22, $pimg, 90, 4);
58 rot_test(26, $pimg, 180, 2);
59 rot_test(30, $pimg, 270, 4);
60 rot_test(34, $pimg, 0, 1);
62 my $timg = $img->rotate(right=>90)->rotate(right=>270);
63 Imager::i_img_diff($img->{IMG}, $timg->{IMG}) and print "not ";
65 $timg = $img->rotate(right=>90)->rotate(right=>180)->rotate(right=>90);
66 Imager::i_img_diff($img->{IMG}, $timg->{IMG}) and print "not ";
69 # this could use more tests
70 my $rimg = $img->rotate(degrees=>10)
73 if (!$rimg->write(file=>"testout/t64_rot10.ppm")) {
74 print "# Cannot save: ",$rimg->errstr,"\n";
77 # rotate with background
78 $rimg = $img->rotate(degrees=>10, back=>Imager::Color->new(builtin=>'red'))
81 if (!$rimg->write(file=>"testout/t64_rot10_back.ppm")) {
82 print "# Cannot save: ",$rimg->errstr,"\n";
86 my $trimg = $img->matrix_transform(matrix=>[ 1.2, 0, 0,
91 $trimg->write(file=>"testout/t64_trans.ppm")
92 or print "# Cannot save: ",$trimg->errstr,"\n";
94 $trimg = $img->matrix_transform(matrix=>[ 1.2, 0, 0,
97 back=>Imager::Color->new(builtin=>'blue'))
100 $trimg->write(file=>"testout/t64_trans_back.ppm")
101 or print "# Cannot save: ",$trimg->errstr,"\n";
104 my ($testnum, $src, $degrees, $count) = @_;
106 my $cimg = $src->copy();
110 $cimg = $cimg->rotate(right=>$degrees)
114 print "ok ",$testnum++,"\n";
115 my $diff = Imager::i_img_diff($src->{IMG}, $cimg->{IMG});
117 print "not ok ",$testnum++," # final image doesn't match input\n";
119 print "ok ",$testnum++," # skipped\n";
123 # check that other parameters match
124 $src->type eq $cimg->type or print "not ";
125 print "ok ",$testnum++," # type\n";
126 $src->bits eq $cimg->bits or print "not ";
127 print "ok ",$testnum++," # bits\n";
128 $src->getchannels eq $cimg->getchannels or print "not ";
129 print "ok ",$testnum++," # channels \n";
133 print "not ok ",$testnum++," # rotate returned undef:",$in->errstr,"\n";
135 print "ok ",$testnum++," # skipped\n";
142 print "ok 2 # skip\n";
143 print "ok 3 # skip\n";
144 print "ok 4 # skip\n";
145 print "ok 5 # skip\n";