]> git.imager.perl.org - imager.git/blob - t/t70newgif.t
changed Imager::read() to always return an arrayref of Imager::Color
[imager.git] / t / t70newgif.t
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl test.pl'
3
4 ######################### We start with some black magic to print on failure.
5
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
8
9
10 BEGIN { $| = 1; print "1..8\n"; }
11 END {print "not ok 1\n" unless $loaded;}
12
13 use Imager qw(:all :handy);
14 $loaded=1;
15
16 print "ok 1\n";
17
18 Imager::init('log'=>'testout/t70newgif.log');
19
20 $green=i_color_new(0,255,0,0);
21 $blue=i_color_new(0,0,255,0);
22
23 $img=Imager->new();
24 $img->open(file=>'testimg/scale.ppm',type=>'pnm') || print "failed: ",$img->{ERRSTR},"\n";
25 print "ok 2\n";
26
27
28 $img->write(file=>'testout/t70newgif.gif',type=>'gif',gifplanes=>1,gifquant=>'lm',lmfixed=>[$green,$blue]) || print "failed: ",$img->{ERRSTR},"\n";
29 print "ok 3\n";
30
31 # make sure the palette is loaded properly (minimal test)
32 my $im2 = Imager->new();
33 my $map;
34 if ($im2->read(file=>'testimg/bandw.gif', colors=>\$map)) {
35   print "ok 4\n";
36   # check the palette
37   if ($map) {
38     print "ok 5\n";
39     if (@$map == 2) {
40       print "ok 6\n";
41       my @sorted = sort { comp_entry($a,$b) } @$map;
42       # first entry must be #000000 and second #FFFFFF
43       if (comp_entry($sorted[0], NC(0,0,0)) == 0) {
44         print "ok 7\n";
45       }
46       else {
47         print "not ok 7 # entry should be black\n";
48       }
49       if (comp_entry($sorted[1], NC(255,255,255)) == 0) {
50         print "ok 8\n";
51       }
52       else {
53         print "not ok 8 # entry should be white\n";
54       }
55     }
56     else {
57       print "not ok 6 # bad map size\n";
58       print "ok 7 # skipped bad map size\n";
59       print "ok 8 # skipped bad map size\n";
60     }
61   }
62   else {
63     print "not ok 5 # no map returned\n";
64     for (6..8) {
65       print "ok $_ # skipped no map returned\n";
66     }
67   }
68 }
69 else {
70   print "not ok 4 # ",$im2->errstr,"\n";
71   print "ok 5 # skipped - couldn't load image\n";
72 }
73
74 sub comp_entry {
75   my ($l, $r) = @_;
76   my @l = $l->rgba;
77   my @r = $r->rgba;
78   return $l[0] <=> $r[0]
79     || $l[1] <=> $r[1]
80       || $l[2] <=> $r[2];
81 }