]> git.imager.perl.org - imager.git/blobdiff - t/300-transform/060-map.t
add new comparison method rgb_difference that resembles arithmetical difference per...
[imager.git] / t / 300-transform / 060-map.t
index b91f43d2e5e96a2b0f9ec66b7e13b7bbefe0c348..67a8744ee03baa7c754dc2a70e2c08ffe6f06ce3 100644 (file)
@@ -1,6 +1,7 @@
 #!perl -w
 use strict;
 #!perl -w
 use strict;
-use Test::More tests => 8;
+use Test::More;
+use Imager::Test qw(is_image test_image);
 
 -d "testout" or mkdir "testout";
 
 
 -d "testout" or mkdir "testout";
 
@@ -46,3 +47,40 @@ SKIP: {
      "can't map an empty image");
   is($empty->errstr, "map: empty input image", "check error message");
 }
      "can't map an empty image");
   is($empty->errstr, "map: empty input image", "check error message");
 }
+
+{ # a real map test
+  my $im = Imager->new(xsize => 10, ysize => 10);
+  $im->box(filled => 1, color => [ 255, 128, 128 ], xmax => 4, ymax => 4);
+  $im->box(filled => 1, color => [ 0, 255, 0 ], xmin => 5);
+
+  my $cmp = Imager->new(xsize => 10, ysize => 10);
+  $cmp->box(filled => 1, color => [ 127, 64, 64 ], xmax => 4, ymax => 4);
+  $cmp->box(filled => 1, color => [ 0, 127, 0 ], xmin => 5);
+  my @map = ( map int $_/2, 0 .. 255 );
+  my $out = $im->map(maps => [ \@map, \@map, \@map ]);
+  ok($out, "map()");
+  is_image($out, $cmp, "test map output");
+}
+
+{
+  # test with zero mask: coverity detected a bad channel index problem
+  # that only applies in this case
+  my $im = test_image();
+  $im->setmask(mask => 0x80);
+  is($im->getmask, 0x80, "check we set mask");
+  my @map = ( map int $_ / 2, 0 .. 255 );
+  my $out = $im->map(maps => [ (undef) x 3 ]);
+  ok($out, "map done");
+}
+
+{ # CID 185300
+  # the check for whether a map() channel was used was incorrect
+  my @map1 = ( 0 .. 255 );
+  my $im = test_image;
+  my $cmp = test_image->copy;
+  ok($im->map(maps => [ \@map1, undef, \@map1 ]),
+     "map with gap in maps");
+  is_image($im, $cmp, "should be no changes");
+}
+
+done_testing();