]> git.imager.perl.org - imager.git/blob - t/t90cc.t
fix formatting and spelling to match the rest
[imager.git] / t / t90cc.t
1 #!perl -w
2 use strict;
3 use Test::More tests => 16;
4
5 use Imager;
6
7 Imager::init('log'=>'testout/t90cc.log');
8
9 {
10   my $img=Imager->new();
11   ok($img->open(file=>'testimg/scale.ppm'), 'load test image')
12     or print "failed: ",$img->{ERRSTR},"\n";
13   
14   ok(defined($img->getcolorcount(maxcolors=>10000)), 'check color count is small enough');
15   print "# color count: ".$img->getcolorcount()."\n";
16   is($img->getcolorcount(), 86, 'expected number of colors');
17   is($img->getcolorcount(maxcolors => 50), undef, 'check overflow handling');
18 }
19
20 {
21   my $black = Imager::Color->new(0, 0, 0);
22   my $blue  = Imager::Color->new(0, 0, 255);
23   my $red   = Imager::Color->new(255, 0, 0);
24   
25   my $im    = Imager->new(xsize=>50, ysize=>50);
26   
27   my $count = $im->getcolorcount();
28   is ($count, 1, "getcolorcount is 1");
29   my @colour_usage = $im->getcolorusage();
30   is_deeply (\@colour_usage, [2500], "2500 are in black");
31   
32   $im->box(filled=>1, color=>$blue, xmin=>25);
33   
34   $count = $im->getcolorcount();
35   is ($count, 2, "getcolorcount is 2");
36   @colour_usage = $im->getcolorusage();
37   is_deeply(\@colour_usage, [1250, 1250] , "1250, 1250: Black and blue");
38   
39   $im->box(filled=>1, color=>$red, ymin=>25);
40   
41   $count = $im->getcolorcount();
42   is ($count, 3, "getcolorcount is 3");
43   @colour_usage = $im->getcolorusage();
44   is_deeply(\@colour_usage, [625, 625, 1250] , 
45             "625, 625, 1250: Black blue and red");
46   @colour_usage = $im->getcolorusage(maxcolors => 2);
47   is(@colour_usage, 0, 'test overflow check');
48   
49   my $colour_usage = $im->getcolorusagehash();
50   my $red_pack = pack("CCC", 255, 0, 0);
51   my $blue_pack = pack("CCC", 0, 0, 255);
52   my $black_pack = pack("CCC", 0, 0, 0);
53   is_deeply( $colour_usage, 
54              { $black_pack => 625, $blue_pack => 625, $red_pack => 1250 },
55              "625, 625, 1250: Black blue and red (hash)");
56   is($im->getcolorusagehash(maxcolors => 2), undef,
57      'test overflow check');
58
59   # test with a greyscale image
60   my $im_g = $im->convert(preset => 'grey');
61   # since the grey preset scales each source channel differently
62   # each of the original colors will be converted to different colors
63   is($im_g->getcolorcount, 3, '3 colors (grey)');
64   is_deeply([ $im_g->getcolorusage ], [ 625, 625, 1250 ], 
65             'color counts (grey)');
66   is_deeply({ "\x00" => 625, "\x12" => 625, "\x38" => 1250 },
67             $im_g->getcolorusagehash,
68             'color usage hash (grey)');
69 }