5 init_log("testout/t104ppm.log",1);
7 my $green = i_color_new(0,255,0,255);
8 my $blue = i_color_new(0,0,255,255);
9 my $red = i_color_new(255,0,0,255);
11 my $img = Imager::ImgRaw::new(150,150,3);
13 i_box_filled($img,70,25,130,125,$green);
14 i_box_filled($img,20,25,80,125,$blue);
15 i_arc($img,75,75,30,0,361,$red);
16 i_conv($img,[0.1, 0.2, 0.4, 0.2, 0.1]);
18 my $fh = openimage(">testout/t104.ppm");
19 $IO = Imager::io_new_fd(fileno($fh));
20 i_writeppm_wiol($img, $IO)
21 or die "Cannot write testout/t104.ppm\n";
26 $IO = Imager::io_new_bufchain();
27 i_writeppm_wiol($img, $IO) or die "Cannot write to bufchain";
28 $data = Imager::io_slurp($IO);
31 $fh = openimage("testout/t104.ppm");
32 $IO = Imager::io_new_fd( fileno($fh) );
33 $cmpimg = i_readpnm_wiol($IO,-1) || die "Cannot read testout/t104.ppm\n";
37 print i_img_diff($img, $cmpimg) ? "not ok 4 # saved image different\n" : "ok 4\n";
39 my $rdata = slurp("testout/t104.ppm");
40 print "not " if $rdata ne $data;
44 # build a grayscale image
45 my $gimg = Imager::ImgRaw::new(150, 150, 1);
46 my $gray = i_color_new(128, 0, 0, 255);
47 my $dgray = i_color_new(64, 0, 0, 255);
48 my $white = i_color_new(255, 0, 0, 255);
49 i_box_filled($gimg, 20, 20, 130, 130, $gray);
50 i_box_filled($gimg, 40, 40, 110, 110, $dgray);
51 i_arc($gimg, 75, 75, 30, 0, 361, $white);
53 open FH, "> testout/t104_gray.pgm" or die "Cannot create testout/t104_gray.pgm: $!\n";
55 my $IO = Imager::io_new_fd(fileno(FH));
56 i_writeppm_wiol($gimg, $IO) or print "not ";
60 open FH, "< testout/t104_gray.pgm" or die "Cannot open testout/t104_gray.pgm: $!\n";
62 $IO = Imager::io_new_fd(fileno(FH));
63 my $gcmpimg = i_readpnm_wiol($IO, -1) or print "not ";
65 i_img_diff($gimg, $gcmpimg) == 0 or print "not ";
68 my $ooim = Imager->new;
69 $ooim->read(file=>"testimg/simple.pbm") or print "not ";
72 check_gray(10, Imager::i_get_pixel($ooim->{IMG}, 0, 0), 255);
73 check_gray(11, Imager::i_get_pixel($ooim->{IMG}, 0, 1), 0);
74 check_gray(12, Imager::i_get_pixel($ooim->{IMG}, 1, 0), 0);
75 check_gray(13, Imager::i_get_pixel($ooim->{IMG}, 1, 1), 255);
80 open(FH, $fname) or die "Cannot open $fname: $!\n";
86 my $fh = openimage(shift);
94 my ($num, $c, $gray) = @_;
101 print "not ok $num # $g doesn't match $gray\n";