4 $^W=1; # warnings during command-line tests
5 $|=1; # give us some progress in the test harness
6 init_log("testout/t106tiff.log",1);
8 $green=i_color_new(0,255,0,255);
9 $blue=i_color_new(0,0,255,255);
10 $red=i_color_new(255,0,0,255);
12 $img=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 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);
24 if (!i_has_format("tiff")) {
26 print "ok $_ # skip no tiff support\n";
29 Imager::i_tags_add($img, "i_xres", 0, "300", 0);
30 Imager::i_tags_add($img, "i_yres", 0, undef, 250);
31 # resolutionunit is centimeters
32 Imager::i_tags_add($img, "tiff_resolutionunit", 0, undef, 3);
33 open(FH,">testout/t106.tiff") || die "cannot open testout/t10.tiff for writing\n";
35 my $IO = Imager::io_new_fd(fileno(FH));
36 i_writetiff_wiol($img, $IO);
41 open(FH,"testout/t106.tiff") or die "cannot open testout/t106.tiff\n";
43 $IO = Imager::io_new_fd(fileno(FH));
44 $cmpimg = i_readtiff_wiol($IO, -1);
48 print "# tiff average mean square pixel difference: ",sqrt(i_img_diff($img,$cmpimg))/150*150,"\n";
51 i_img_diff($img, $cmpimg) and print "not ";
54 # check the tags are ok
55 my %tags = map { Imager::i_tags_get($cmpimg, $_) }
56 0 .. Imager::i_tags_count($cmpimg) - 1;
57 abs($tags{i_xres} - 300) < 0.5 or print "not ";
59 abs($tags{i_yres} - 250) < 0.5 or print "not ";
61 $tags{tiff_resolutionunit} == 3 or print "not ";
64 $IO = Imager::io_new_bufchain();
66 Imager::i_writetiff_wiol($img, $IO) or die "Cannot write to bufferchain\n";
67 my $tiffdata = Imager::io_slurp($IO);
69 open(FH,"testout/t106.tiff");
75 if ($odata eq $tiffdata) {
81 # test Micksa's tiff writer
83 my $faximg = Imager::ImgRaw::new(1728, 2000, 1);
84 my $black = i_color_new(0,0,0,255);
85 my $white = i_color_new(255,255,255,255);
86 # vaguely test-patterny
87 i_box_filled($faximg, 0, 0, 1728, 2000, $white);
88 i_box_filled($faximg, 100,100,1628, 200, $black);
91 while ($width+$pos < 1628) {
92 i_box_filled($faximg, $pos, 300, $pos+$width-1, 400, $black);
96 open FH, "> testout/t106tiff_fax.tiff"
97 or die "Cannot create testout/t106tiff_fax.tiff: $!";
99 $IO = Imager::io_new_fd(fileno(FH));
100 i_writetiff_wiol_faxable($faximg, $IO, 1)
105 # test the OO interface
106 my $ooim = Imager->new;
107 $ooim->read(file=>'testout/t106.tiff')
110 $ooim->write(file=>'testout/t106_oo.tiff')
114 # OO with the fax image
115 my $oofim = Imager->new;
116 $oofim->read(file=>'testout/t106tiff_fax.tiff')
120 # this should have tags set for the resolution
121 %tags = map @$_, $oofim->tags;
122 $tags{i_xres} == 204 or print "not ";
124 $tags{i_yres} == 196 or print "not ";
126 $tags{i_aspect_only} and print "not ";
129 $tags{tiff_resolutionunit} == 2 or print "not ";
132 $oofim->write(file=>'testout/t106_oo_fax.tiff', class=>'fax')
136 # the following should fail since there's no type and no filename
138 $ooim->write(data=>\$oodata)
143 $ooim->write(data=>\$oodata, type=>'tiff')
146 $oodata eq $tiffdata or print "not ";
149 # make sure we can write non-fine mode
150 $oofim->write(file=>'testout/t106_oo_faxlo.tiff', class=>'fax', fax_fine=>0)