5 BEGIN { require "t/testtools.pl"; }
6 init_log("testout/t108tga.log",1);
9 my $img = create_test_image();
12 write_test(1, $img, "testout/t108_24bit.tga", 0, 0, "");
13 write_test(2, $img, "testout/t108_24bit_rle.tga", 0, 1, "");
14 write_test(3, $img, "testout/t108_15bit.tga", 1, 1, "");
15 write_test(4, $img, "testout/t108_15bit_rle.tga", 1, 1, "");
17 # 'webmap' is noticably faster than the default
18 my $im8 = Imager::i_img_to_pal($img, { make_colors=>'webmap',
19 translate=>'errdiff'});
21 write_test(5, $im8, "testout/t108_8bit.tga", 0, 0, "");
22 write_test(6, $im8, "testout/t108_8bit_rle.tga", 0, 1, "");
23 write_test(7, $im8, "testout/t108_8_15bit.tga", 1, 0, "");
24 write_test(8, $im8, "testout/t108_8_15bit_rle.tga", 1, 1, "");
27 # use a fixed palette so we get reproducible results for the compressed
30 my @bit4 = map { NC($_) }
31 qw(605844 966600 0148b2 00f800 bf0a33 5e009e
32 2ead1b 0000f8 004b01 fd0000 0e1695 000002);
34 my @bit1 = (NC(0, 0, 0), NC(176, 160, 144));
36 my $im4 = Imager::i_img_to_pal($img, { colors=>\@bit4,
37 make_colors=>'none' });
39 my $im1 = Imager::i_img_to_pal($img, { colors=>\@bit1,
41 translate=>'errdiff' });
43 write_test(9, $im4, "testout/t108_4bit.tga", 0, 1, "");
44 write_test(10, $im1, "testout/t108_1bit.tga", 0, 1, "This is a comment!");
46 read_test(11, "testout/t108_24bit.tga", $img);
47 read_test(12, "testout/t108_8bit.tga", $im8);
48 read_test(13, "testout/t108_4bit.tga", $im4);
49 read_test(14, "testout/t108_1bit.tga", $im1);
51 # the following might have slight differences
53 $base_diff = i_img_diff($img, $im8) * 2;
55 print "# base difference $base_diff\n";
57 my $imoo = Imager->new;
58 if ($imoo->read(file=>'testout/t108_24bit.tga')) {
61 print "not ok 15 # ",$imoo->errstr,"\n";
64 if ($imoo->write(file=>'testout/t108_oo.tga')) {
67 print "not ok 16 # ",$imoo->errstr,"\n";
70 my ($type) = $imoo->tags(name=>'i_format');
71 isn(17, $type, 'tga', "check i_format tag");
73 # in 0.44 and earlier, reading an image with an idstring of 128 or more
74 # bytes would result in an allocation error, if the platform char type
77 okn(18, $imoo->read(file=>'testimg/longid.tga'), "read long id image");
78 my ($id) = $imoo->tags(name=>'tga_idstring');
79 isn(19, $id, "X" x 128, "check tga_idstring tag");
80 my ($bitspp) = $imoo->tags(name=>'tga_bitspp');
81 isn(20, $bitspp, 24, "check tga_bitspp tag");
82 my ($compressed) = $imoo->tags(name=>'compressed');
83 isn(21, $compressed, 1, "check compressed tag");
86 my ($test_num, $im, $filename, $wierdpack, $compress, $idstring) = @_;
89 if (open FH, "> $filename") {
91 my $IO = Imager::io_new_fd(fileno(FH));
92 if (Imager::i_writetga_wiol($im, $IO, $wierdpack, $compress, $idstring)) {
93 print "ok $test_num\n";
95 print "not ok $test_num # ",Imager->_error_as_msg(),"\n";
100 print "not ok $test_num # $!\n";
106 my ($test_num, $filename, $im, %tags) = @_;
109 if (open FH, "< $filename") {
111 my $IO = Imager::io_new_fd(fileno(FH));
112 my $im_read = Imager::i_readtga_wiol($IO,-1);
114 my $diff = i_img_diff($im, $im_read);
115 if ($diff > $base_diff) {
116 print "not ok $test_num # image mismatch $diff\n";
118 print "ok $test_num\n";
120 print "not ok $test_num # ",Imager->_error_as_msg(),"\n";
125 print "not ok $test_num # $!\n";
131 sub create_test_image {
133 my $green = i_color_new(0,255,0,255);
134 my $blue = i_color_new(0,0,255,255);
135 my $red = i_color_new(255,0,0,255);
137 my $img = Imager::ImgRaw::new(150,150,3);
139 i_box_filled($img, 70, 25, 130, 125, $green);
140 i_box_filled($img, 20, 25, 80, 125, $blue);
141 i_arc($img, 75, 75, 30, 0, 361, $red);
142 i_conv($img, [0.1, 0.2, 0.4, 0.2, 0.1]);