4 use Test::More tests=>57;
9 Imager::init('log'=>'testout/t64copyflip.log');
11 my $img=Imager->new() or die "unable to create image object\n";
13 $img->open(file=>'testimg/scale.ppm',type=>'pnm');
14 my $nimg = $img->copy();
15 ok($nimg, "copy returned something");
17 # test if ->copy() works
19 my $diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
20 is($diff, 0, "copy matches source");
23 # test if ->flip(dir=>'h')->flip(dir=>'h') doesn't alter the image
25 $nimg->flip(dir=>"h")->flip(dir=>"h");
26 $diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
27 is($diff, 0, "double horiz flipped matches original");
29 # test if ->flip(dir=>'v')->flip(dir=>'v') doesn't alter the image
31 $nimg->flip(dir=>"v")->flip(dir=>"v");
32 $diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
33 is($diff, 0, "double vertically flipped image matches original");
36 # test if ->flip(dir=>'h')->flip(dir=>'v') is same as ->flip(dir=>'hv')
38 $nimg->flip(dir=>"v")->flip(dir=>"h")->flip(dir=>"hv");;
39 $diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
40 is($diff, 0, "check flip with hv matches flip v then flip h");
42 rot_test($img, 90, 4);
43 rot_test($img, 180, 2);
44 rot_test($img, 270, 4);
47 my $pimg = $img->to_paletted();
48 rot_test($pimg, 90, 4);
49 rot_test($pimg, 180, 2);
50 rot_test($pimg, 270, 4);
51 rot_test($pimg, 0, 1);
53 my $timg = $img->rotate(right=>90)->rotate(right=>270);
54 is(Imager::i_img_diff($img->{IMG}, $timg->{IMG}), 0,
55 "check rotate 90 then 270 matches original");
56 $timg = $img->rotate(right=>90)->rotate(right=>180)->rotate(right=>90);
57 is(Imager::i_img_diff($img->{IMG}, $timg->{IMG}), 0,
58 "check rotate 90 then 180 then 90 matches original");
60 # this could use more tests
61 my $rimg = $img->rotate(degrees=>10);
62 ok($rimg, "rotation by 10 degrees gave us an image");
63 if (!$rimg->write(file=>"testout/t64_rot10.ppm")) {
64 print "# Cannot save: ",$rimg->errstr,"\n";
67 # rotate with background
68 $rimg = $img->rotate(degrees=>10, back=>Imager::Color->new(builtin=>'red'));
69 ok($rimg, "rotate with background gave us an image");
70 if (!$rimg->write(file=>"testout/t64_rot10_back.ppm")) {
71 print "# Cannot save: ",$rimg->errstr,"\n";
75 my $trimg = $img->matrix_transform(matrix=>[ 1.2, 0, 0,
78 ok($trimg, "matrix_transform() returned an image");
79 $trimg->write(file=>"testout/t64_trans.ppm")
80 or print "# Cannot save: ",$trimg->errstr,"\n";
82 $trimg = $img->matrix_transform(matrix=>[ 1.2, 0, 0,
85 back=>Imager::Color->new(builtin=>'blue'));
86 ok($trimg, "matrix_transform() with back returned an image");
88 $trimg->write(file=>"testout/t64_trans_back.ppm")
89 or print "# Cannot save: ",$trimg->errstr,"\n";
92 my ($src, $degrees, $count) = @_;
94 my $cimg = $src->copy();
98 $cimg = $cimg->rotate(right=>$degrees)
103 ok($cimg, "got a rotated image")
104 or skip("no image to check", 4);
105 my $diff = Imager::i_img_diff($src->{IMG}, $cimg->{IMG});
106 is($diff, 0, "check it matches source")
107 or skip("didn't match", 3);
109 # check that other parameters match
110 is($src->type, $cimg->type, "type check");
111 is($src->bits, $cimg->bits, "bits check");
112 is($src->getchannels, $cimg->getchannels, "channels check");
116 { # http://rt.cpan.org/NoAuth/Bug.html?id=9672
118 local $SIG{__WARN__} =
121 my $printed = $warning;
123 $printed =~ s/\n/\n\#/g;
124 print "# ",$printed, "\n";
126 my $img = Imager->new(xsize=>10, ysize=>10);
128 cmp_ok($warning, '=~', 'void', "correct warning");
129 cmp_ok($warning, '=~', 't64copyflip\\.t', "correct file");
131 $img->rotate(degrees=>5);
132 cmp_ok($warning, '=~', 'void', "correct warning");
133 cmp_ok($warning, '=~', 't64copyflip\\.t', "correct file");
135 $img->matrix_transform(matrix=>[1, 1, 1]);
136 cmp_ok($warning, '=~', 'void', "correct warning");
137 cmp_ok($warning, '=~', 't64copyflip\\.t', "correct file");