4 init_log("testout/t103raw.log",1);
6 $green=i_color_new(0,255,0,255);
7 $blue=i_color_new(0,0,255,255);
8 $red=i_color_new(255,0,0,255);
10 $img=Imager::ImgRaw::new(150,150,3);
11 $cmpimg=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 $timg = Imager::ImgRaw::new(20, 20, 4);
19 my $trans = i_color_new(255, 0, 0, 127);
20 i_box_filled($timg, 0, 0, 20, 20, $green);
21 i_box_filled($timg, 2, 2, 18, 18, $trans);
23 open(FH,">testout/t103.raw") || die "Cannot open testout/t103.raw for writing\n";
25 i_writeraw($img,fileno(FH)) || die "Cannot write testout/t103.raw\n";
30 open(FH,"testout/t103.raw") || die "Cannot open testout/t103.raw\n";
32 $cmpimg=i_readraw(fileno(FH),150,150,3,3,0) || die "Cannot read testout/t103.raw\n";
35 print "# raw average mean square pixel difference: ",sqrt(i_img_diff($img,$cmpimg))/150*150,"\n";
38 # I could have kept the raw images for these tests in binary files in
39 # testimg/, but I think keeping them as hex encoded data in here makes
40 # it simpler to add more if necessary
41 # Later we may change this to read from a scalar instead
42 save_data('testout/t103_base.raw');
43 save_data('testout/t103_3to4.raw');
44 save_data('testout/t103_line_int.raw');
45 save_data('testout/t103_img_int.raw');
48 open FH, "testout/t103_base.raw"
49 or die "Cannot open testout/t103_base.raw: $!";
51 my $baseimg = i_readraw(fileno(FH), 4, 4, 3, 3, 0)
52 or die "Cannot read base raw image";
55 # the actual read tests
56 # each read_test() call does 2 tests:
57 # - check if the read succeeds
58 # - check if it matches $baseimg
59 read_test('testout/t103_3to4.raw', 4, 4, 4, 3, 0, $baseimg, 3);
60 read_test('testout/t103_line_int.raw', 4, 4, 3, 3, 1, $baseimg, 5);
61 # intrl==2 is documented in raw.c but doesn't seem to be implemented
62 #read_test('testout/t103_img_int.raw', 4, 4, 3, 3, 2, $baseimg, 7);
65 my ($in, $xsize, $ysize, $data, $store, $intrl, $base, $test) = @_;
66 open FH, $in or die "Cannot open $in: $!";
68 my $img = i_readraw(fileno(FH), $xsize, $ysize, $data, $store, $intrl);
71 if (i_img_diff($img, $baseimg)) {
72 print "ok ",$test+1," # skip images don't match, but maybe I don't understand\n";
75 print "ok ",$test+1,"\n";
79 print "not ok $test # could not read image\n";
80 print "ok ",$test+1," # skip\n";
86 my $data = load_data();
87 open FH, "> $outname" or die "Cannot create $outname: $!";
102 my $result = pack("H*", $hex);
103 print unpack("H*", $result),"\n";
107 # FIXME: may need tests for 1,2,4 channel images
110 # we keep some packed raw images here
111 # we decode this in the code, ignoring lines starting with #, a subfile
112 # ends with EOF, data is HEX encoded (spaces ignored)
114 # basic 3 channel version of the image
115 001122 011223 021324 031425
116 102132 112233 122334 132435
117 203142 213243 223344 233445
118 304152 314253 324354 334455
121 # test image for reading a 4 channel image into a 3 channel image
123 00112233 01122334 02132435 03142536
124 10213243 11223344 12233445 13243546
125 20314253 21324354 22334455 23344556
126 30415263 31425364 32435465 33445566
129 # test image for line based interlacing
153 # test image for image based interlacing