5 init_log("testout/t101jpeg.log",1);
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);
11 $img=Imager::ImgRaw::new(150,150,3);
12 $cmpimg=Imager::ImgRaw::new(150,150,3);
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]);
19 i_has_format("jpeg") && print "# has jpeg\n";
20 if (!i_has_format("jpeg")) {
22 print "ok $_ # skip no jpeg support\n";
25 open(FH,">testout/t101.jpg") || die "cannot open testout/t101.jpg for writing\n";
27 $IO = Imager::io_new_fd(fileno(FH));
28 i_writejpeg_wiol($img,$IO,30);
33 open(FH, "testout/t101.jpg") || die "cannot open testout/t101.jpg\n";
35 $IO = Imager::io_new_fd(fileno(FH));
36 ($cmpimg,undef) = i_readjpeg_wiol($IO);
40 my $diff = sqrt(i_img_diff($img,$cmpimg))/150*150;
41 print "# jpeg average mean square pixel difference: ",$diff,"\n";
44 $diff < 10000 or print "not ";
47 Imager::log_entry("Starting 4\n", 1);
48 my $imoo = Imager->new;
49 $imoo->read(file=>'testout/t101.jpg') or print "not ";
51 $imoo->write(file=>'testout/t101_oo.jpg') or print "not ";
52 Imager::log_entry("Starting 5\n", 1);
54 my $oocmp = Imager->new;
55 $oocmp->read(file=>'testout/t101_oo.jpg') or print "not ";
58 $diff = sqrt(i_img_diff($imoo->{IMG},$oocmp->{IMG}))/150*150;
59 print "# OO image difference $diff\n";
60 $diff < 10000 or print "not ";
64 open FH, "< testout/t101.jpg" or die "Cannot open testout/t101.jpg: $!";
66 ok(8, !$imoo->write(fd=>fileno(FH), type=>'jpeg'), 'failure handling');
68 print "# ",$imoo->errstr,"\n";
72 my ($num, $test, $msg) = @_;
78 print "not ok $num # $msg\n";