]> git.imager.perl.org - imager.git/blob - t/t104ppm.t
was sizeof(int *)
[imager.git] / t / t104ppm.t
1 use Imager ':all';
2
3 print "1..6\n";
4
5 init_log("testout/t104ppm.log",1);
6
7 $green=i_color_new(0,255,0,255);
8 $blue=i_color_new(0,0,255,255);
9 $red=i_color_new(255,0,0,255);
10
11 $img=Imager::ImgRaw::new(150,150,3);
12 $cmpimg=Imager::ImgRaw::new(150,150,3);
13
14 i_box_filled($img,70,25,130,125,$green);
15 i_box_filled($img,20,25,80,125,$blue);
16 i_arc($img,75,75,30,0,361,$red);
17 i_conv($img,[0.1, 0.2, 0.4, 0.2, 0.1]);
18
19 my $timg = Imager::ImgRaw::new(20, 20, 4);
20 my $trans = i_color_new(255, 0, 0, 127);
21 i_box_filled($timg, 0, 0, 20, 20, $green);
22 i_box_filled($timg, 2, 2, 18, 18, $trans);
23
24 open(FH,">testout/t104.ppm") || die "Cannot open testout/t104.ppm\n";
25 binmode(FH);
26 i_writeppm($img,fileno(FH)) || die "Cannot write testout/t104.ppm\n";
27 close(FH);
28
29 print "ok 1\n";
30
31 open(FH,"testout/t104.ppm") || die "Cannot open testout/t104.ppm\n";
32 binmode(FH);
33
34 my $IO = Imager::io_new_fd(fileno(FH));
35 $cmpimg=i_readpnm_wiol($IO,-1) || die "Cannot read testout/t104.ppm\n";
36 close(FH);
37
38 print "ok 2\n";
39
40 print i_img_diff($img, $cmpimg) 
41   ? "not ok 3 # saved image different\n" : "ok 3\n";
42
43 # build a grayscale image
44 my $gimg = Imager::ImgRaw::new(150, 150, 1);
45 my $gray = i_color_new(128, 0, 0, 255);
46 my $dgray = i_color_new(64, 0, 0, 255);
47 my $white = i_color_new(255, 0, 0, 255);
48 i_box_filled($gimg, 20, 20, 130, 130, $gray);
49 i_box_filled($gimg, 40, 40, 110, 110, $dgray);
50 i_arc($gimg, 75, 75, 30, 0, 361, $white);
51 open FH, "> testout/t104_gray.pgm"
52   or die "Cannot create testout/t104_gray.pgm: $!\n";
53 binmode FH;
54 i_writeppm($gimg, fileno(FH))
55   or print "not ";
56 print "ok 4\n";
57 close FH;
58 open FH, "< testout/t104_gray.pgm"
59   or die "Cannot open testout/t104_gray.pgm: $!\n";
60 binmode FH;
61 $IO = Imager::io_new_fd(fileno(FH));
62 my $gcmpimg = i_readpnm_wiol($IO, -1) 
63   or print "not ";
64 print "ok 5\n";
65 i_img_diff($gimg, $gcmpimg) == 0 or print "not ";
66 print "ok 6\n";
67