| 1 |
#!perl -w |
| 2 |
use strict; |
| 3 |
use Test::More; |
| 4 |
use Imager::Test qw(is_image test_image); |
| 5 |
|
| 6 |
-d "testout" or mkdir "testout"; |
| 7 |
|
| 8 |
Imager::init("log"=>'testout/t68map.log'); |
| 9 |
|
| 10 |
use Imager qw(:all :handy); |
| 11 |
|
| 12 |
my $imbase = Imager::ImgRaw::new(200,300,3); |
| 13 |
|
| 14 |
|
| 15 |
my @map1 = map { int($_/2) } 0..255; |
| 16 |
my @map2 = map { 255-int($_/2) } 0..255; |
| 17 |
my @map3 = 0..255; |
| 18 |
my @maps = 0..24; |
| 19 |
my @mapl = 0..400; |
| 20 |
|
| 21 |
my $tst = 1; |
| 22 |
|
| 23 |
ok(i_map($imbase, [ [], [], \@map1 ]), "map1 in ch 3"); |
| 24 |
ok(i_map($imbase, [ \@map1, \@map1, \@map1 ]), "map1 in ch1-3"); |
| 25 |
|
| 26 |
ok(i_map($imbase, [ \@map1, \@map2, \@map3 ]), "map1-3 in ch 1-3"); |
| 27 |
|
| 28 |
ok(i_map($imbase, [ \@maps, \@mapl, \@map3 ]), "incomplete maps"); |
| 29 |
|
| 30 |
# test the highlevel interface |
| 31 |
# currently this requires visual inspection of the output files |
| 32 |
|
| 33 |
SKIP: { |
| 34 |
my $im = Imager->new; |
| 35 |
$im->read(file=>'testimg/scale.ppm') |
| 36 |
or skip "Cannot load test image testimg/scale.ppm", 2; |
| 37 |
|
| 38 |
ok( $im->map(red=>\@map1, green=>\@map2, blue=>\@map3), |
| 39 |
"test OO interface (maps by color)"); |
| 40 |
ok( $im->map(maps=>[\@map1, [], \@map2]), |
| 41 |
"test OO interface (maps by maps)"); |
| 42 |
} |
| 43 |
|
| 44 |
{ |
| 45 |
my $empty = Imager->new; |
| 46 |
ok(!$empty->map(maps => [ \@map1, \@map2, \@map3 ]), |
| 47 |
"can't map an empty image"); |
| 48 |
is($empty->errstr, "map: empty input image", "check error message"); |
| 49 |
} |
| 50 |
|
| 51 |
{ # a real map test |
| 52 |
my $im = Imager->new(xsize => 10, ysize => 10); |
| 53 |
$im->box(filled => 1, color => [ 255, 128, 128 ], xmax => 4, ymax => 4); |
| 54 |
$im->box(filled => 1, color => [ 0, 255, 0 ], xmin => 5); |
| 55 |
|
| 56 |
my $cmp = Imager->new(xsize => 10, ysize => 10); |
| 57 |
$cmp->box(filled => 1, color => [ 127, 64, 64 ], xmax => 4, ymax => 4); |
| 58 |
$cmp->box(filled => 1, color => [ 0, 127, 0 ], xmin => 5); |
| 59 |
my @map = ( map int $_/2, 0 .. 255 ); |
| 60 |
my $out = $im->map(maps => [ \@map, \@map, \@map ]); |
| 61 |
ok($out, "map()"); |
| 62 |
is_image($out, $cmp, "test map output"); |
| 63 |
} |
| 64 |
|
| 65 |
{ |
| 66 |
# test with zero mask: coverity detected a bad channel index problem |
| 67 |
# that only applies in this case |
| 68 |
no if $] >= 5.014, warnings => 'Imager::channelmask'; |
| 69 |
my $im = test_image(); |
| 70 |
$im->setmask(mask => 0x80); |
| 71 |
is($im->getmask, 0x80, "check we set mask"); |
| 72 |
my @map = ( map int $_ / 2, 0 .. 255 ); |
| 73 |
my $out = $im->map(maps => [ (undef) x 3 ]); |
| 74 |
ok($out, "map done"); |
| 75 |
} |
| 76 |
|
| 77 |
{ # CID 185300 |
| 78 |
# the check for whether a map() channel was used was incorrect |
| 79 |
my @map1 = ( 0 .. 255 ); |
| 80 |
my $im = test_image; |
| 81 |
my $cmp = test_image->copy; |
| 82 |
ok($im->map(maps => [ \@map1, undef, \@map1 ]), |
| 83 |
"map with gap in maps"); |
| 84 |
is_image($im, $cmp, "should be no changes"); |
| 85 |
} |
| 86 |
|
| 87 |
done_testing(); |