3 # Before `make install' is performed this script should be runnable with
4 # `make test'. After `make install' it should work as `perl test.pl'
6 ######################### We start with some black magic to print on failure.
8 # Change 1..1 below to 1..last_test_to_print .
9 # (It may become useful if the test is moved to ./t subdirectory.)
10 use lib qw(blib/lib blib/arch);
12 BEGIN { $| = 1; print "1..13\n"; }
13 BEGIN { require 't/testtools.pl'; }
14 BEGIN { useokx('Imager', 'load Imager', ':all') }
15 init_log("testout/t102png.log",1);
17 i_has_format("png") && print "# has png\n";
19 my $green = i_color_new(0, 255, 0, 255);
20 my $blue = i_color_new(0, 0, 255, 255);
21 my $red = i_color_new(255, 0, 0, 255);
23 my $img = Imager::ImgRaw::new(150, 150, 3);
25 i_box_filled($img, 70, 25, 130, 125, $green);
26 i_box_filled($img, 20, 25, 80, 125, $blue);
27 i_arc($img, 75, 75, 30, 0, 361, $red);
28 i_conv($img,[0.1, 0.2, 0.4, 0.2, 0.1]);
30 my $timg = Imager::ImgRaw::new(20, 20, 4);
31 my $trans = i_color_new(255, 0, 0, 127);
32 i_box_filled($timg, 0, 0, 20, 20, $green);
33 i_box_filled($timg, 2, 2, 18, 18, $trans);
35 if (!i_has_format("png")) {
36 skipx(12, "no png support");
38 Imager::i_tags_add($img, "i_xres", 0, "300", 0);
39 Imager::i_tags_add($img, "i_yres", 0, undef, 200);
40 # the following confuses the GIMP
41 #Imager::i_tags_add($img, "i_aspect_only", 0, undef, 1);
42 open(FH,">testout/t102.png") || die "cannot open testout/t102.png for writing\n";
44 my $IO = Imager::io_new_fd(fileno(FH));
45 okx(i_writepng_wiol($img, $IO), "write");
48 open(FH,"testout/t102.png") || die "cannot open testout/t102.png\n";
50 $IO = Imager::io_new_fd(fileno(FH));
51 my $cmpimg = i_readpng_wiol($IO, -1);
53 okx($cmpimg, "read png");
55 print "# png average mean square pixel difference: ",sqrt(i_img_diff($img,$cmpimg))/150*150,"\n";
56 isx(i_img_diff($img, $cmpimg), 0, "compare saved and original images");
58 my %tags = map { Imager::i_tags_get($cmpimg, $_) }
59 0..Imager::i_tags_count($cmpimg) - 1;
60 okx(abs($tags{i_xres} - 300) < 1, "i_xres: $tags{i_xres}");
61 okx(abs($tags{i_yres} - 200) < 1, "i_yres: $tags{i_yres}");
62 isx($tags{i_format}, "png", "i_format: $tags{i_format}");
64 open FH, "> testout/t102_trans.png"
65 or die "Cannot open testout/t102_trans.png: $!";
67 $IO = Imager::io_new_fd(fileno(FH));
68 okx(i_writepng_wiol($timg, $IO), "write tranparent");
71 open FH,"testout/t102_trans.png"
72 or die "cannot open testout/t102_trans.png\n";
74 $IO = Imager::io_new_fd(fileno(FH));
75 $cmpimg = i_readpng_wiol($IO, -1);
76 okx($cmpimg, "read transparent");
79 print "# png average mean square pixel difference: ",sqrt(i_img_diff($timg,$cmpimg))/150*150,"\n";
80 isx(i_img_diff($timg, $cmpimg), 0, "compare saved and original transparent");
83 # png.c 1.1 would produce an incorrect image when loading images with
84 # less than 8 bits/pixel with a transparent palette entry
85 open FH, "< testimg/palette.png"
86 or die "cannot open testimg/palette.png: $!\n";
88 $IO = Imager::io_new_fd(fileno(FH));
89 # 1.1 may segfault here (it does with libefence)
90 my $pimg = i_readpng_wiol($IO,-1);
91 okx($pimg, "read transparent paletted image");
94 open FH, "< testimg/palette_out.png"
95 or die "cannot open testimg/palette_out.png: $!\n";
97 $IO = Imager::io_new_fd(fileno(FH));
98 my $poimg = i_readpng_wiol($IO, -1);
99 okx($poimg, "read palette_out image");
101 if (!isx(i_img_diff($pimg, $poimg), 0, "images the same")) {
103 # this tests a bug in Imager's png.c v1.1
104 # if also tickles a bug in libpng before 1.0.5, so you may need to