5 init_log("testout/t103raw.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);
12 my $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 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 open(FH,">testout/t103.raw") || die "Cannot open testout/t103.raw for writing\n";
26 my $IO = Imager::io_new_fd( fileno(FH) );
27 i_writeraw_wiol($img, $IO) || die "Cannot write testout/t103.raw\n";
32 open(FH,"testout/t103.raw") || die "Cannot open testout/t103.raw\n";
34 $IO = Imager::io_new_fd( fileno(FH) );
35 $cmpimg = i_readraw_wiol($IO, 150, 150, 3, 3, 0) || die "Cannot read testout/t103.raw\n";
38 print "# raw average mean square pixel difference: ",sqrt(i_img_diff($img,$cmpimg))/150*150,"\n";
41 # I could have kept the raw images for these tests in binary files in
42 # testimg/, but I think keeping them as hex encoded data in here makes
43 # it simpler to add more if necessary
44 # Later we may change this to read from a scalar instead
45 save_data('testout/t103_base.raw');
46 save_data('testout/t103_3to4.raw');
47 save_data('testout/t103_line_int.raw');
48 save_data('testout/t103_img_int.raw');
51 open FH, "testout/t103_base.raw"
52 or die "Cannot open testout/t103_base.raw: $!";
54 $IO = Imager::io_new_fd( fileno(FH) );
56 my $baseimg = i_readraw_wiol( $IO, 4, 4, 3, 3, 0)
57 or die "Cannot read base raw image";
60 # the actual read tests
61 # each read_test() call does 2 tests:
62 # - check if the read succeeds
63 # - check if it matches $baseimg
64 read_test('testout/t103_3to4.raw', 4, 4, 4, 3, 0, $baseimg, 3);
65 read_test('testout/t103_line_int.raw', 4, 4, 3, 3, 1, $baseimg, 5);
66 # intrl==2 is documented in raw.c but doesn't seem to be implemented
67 #read_test('testout/t103_img_int.raw', 4, 4, 3, 3, 2, $baseimg, 7);
70 my $palim = Imager::i_img_pal_new(20, 20, 3, 256)
73 my $redindex = Imager::i_addcolors($palim, $red);
74 my $blueindex = Imager::i_addcolors($palim, $blue);
76 Imager::i_ppal($palim, 0, $y, ($redindex) x 20);
79 Imager::i_ppal($palim, 0, $y, ($blueindex) x 20);
81 open FH, "> testout/t103_pal.raw"
82 or die "Cannot create testout/t103_pal.raw: $!";
84 $IO = Imager::io_new_fd(fileno(FH));
85 i_writeraw_wiol($palim, $IO) or print "not ";
89 open FH, "testout/t103_pal.raw"
90 or die "Cannot open testout/t103_pal.raw: $!";
92 my $data = do { local $/; <FH> };
93 $data eq "\x0" x 200 . "\x1" x 200
98 # we don't have 16-bit reads yet
99 my $img16 = Imager::i_img_16_new(150, 150, 3)
102 i_box_filled($img16,70,25,130,125,$green);
103 i_box_filled($img16,20,25,80,125,$blue);
104 i_arc($img16,75,75,30,0,361,$red);
105 i_conv($img16,[0.1, 0.2, 0.4, 0.2, 0.1]);
107 open FH, "> testout/t103_16.raw"
108 or die "Cannot create testout/t103_16.raw: $!";
110 $IO = Imager::io_new_fd(fileno(FH));
111 i_writeraw_wiol($img16, $IO) or print "not ";
115 # try a simple virtual image
116 my $maskimg = Imager::i_img_masked_new($img, undef, 0, 0, 150, 150)
120 open FH, "> testout/t103_virt.raw"
121 or die "Cannot create testout/t103_virt.raw: $!";
123 $IO = Imager::io_new_fd(fileno(FH));
124 i_writeraw_wiol($maskimg, $IO) or print "not ";
128 open FH, "testout/t103_virt.raw"
129 or die "Cannot open testout/t103_virt.raw: $!";
131 $IO = Imager::io_new_fd(fileno(FH));
132 my $cmpimgmask = i_readraw_wiol($IO, 150, 150, 3, 3, 0)
135 my $diff = i_img_diff($maskimg, $cmpimgmask);
136 print "# difference for virtual image $diff\n";
137 $diff and print "not ";
141 my ($in, $xsize, $ysize, $data, $store, $intrl, $base, $test) = @_;
142 open FH, $in or die "Cannot open $in: $!";
144 my $IO = Imager::io_new_fd( fileno(FH) );
146 my $img = i_readraw_wiol($IO, $xsize, $ysize, $data, $store, $intrl);
149 if (i_img_diff($img, $baseimg)) {
150 print "ok ",$test+1," # skip images don't match, but maybe I don't understand\n";
153 print "ok ",$test+1,"\n";
157 print "not ok $test # could not read image\n";
158 print "ok ",$test+1," # skip\n";
164 my $data = load_data();
165 open FH, "> $outname" or die "Cannot create $outname: $!";
180 my $result = pack("H*", $hex);
181 #print unpack("H*", $result),"\n";
185 # FIXME: may need tests for 1,2,4 channel images
188 # we keep some packed raw images here
189 # we decode this in the code, ignoring lines starting with #, a subfile
190 # ends with EOF, data is HEX encoded (spaces ignored)
192 # basic 3 channel version of the image
193 001122 011223 021324 031425
194 102132 112233 122334 132435
195 203142 213243 223344 233445
196 304152 314253 324354 334455
199 # test image for reading a 4 channel image into a 3 channel image
201 00112233 01122334 02132435 03142536
202 10213243 11223344 12233445 13243546
203 20314253 21324354 22334455 23344556
204 30415263 31425364 32435465 33445566
207 # test image for line based interlacing
231 # test image for image based interlacing