[rt #69243] change i_map() to use the AV* typemap
authorTony Cook <tony@develop-help.com>
Tue, 21 May 2013 11:19:13 +0000 (21:19 +1000)
committerTony Cook <tony@develop-help.com>
Tue, 21 May 2013 11:19:13 +0000 (21:19 +1000)
and add a better test

Changes
Imager.xs
t/300-transform/060-map.t

diff --git a/Changes b/Changes
index 6e99010f177f9cc813e635bf16b64ba0e711d54a..ff820656999d307831797b9c5ff1b5db2f78afac 100644 (file)
--- a/Changes
+++ b/Changes
@@ -20,7 +20,7 @@ Imager release history.  Older releases can be found in Changes.old
    - Imager::Color's rgba() method now returns it's values as integers
      instead of floating point. (IV instead of NV).
 
-   - The XS for i_poly_aa(), i_poly_aa_cfill() and
+   - The XS for i_poly_aa(), i_poly_aa_cfill(), i_map() and
      i_matrix_transform() now use the AV * typemap instead of rolling
      their own.
 
index 5eaa54bcda9d077079a52edfbf267b177d4d4fd1..b6829e1ad1e96c990acc1c0e556e072ea3930031 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -2102,8 +2102,9 @@ i_convert(src, avmain)
 
 
 undef_int
-i_map(im, pmaps)
+i_map(im, pmaps_av)
     Imager::ImgRaw     im
+    AV *pmaps_av
        PREINIT:
          unsigned int mask = 0;
          AV *avmain;
@@ -2113,16 +2114,13 @@ i_map(im, pmaps)
          int i, j;
          unsigned char (*maps)[256];
         CODE:
-         if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
-           croak("i_map: parameter 2 must be an arrayref\n");
-          avmain = (AV*)SvRV(ST(1));
-         len = av_len(avmain)+1;
+         len = av_len(pmaps_av)+1;
          if (im->channels < len) len = im->channels;
 
          maps = mymalloc( len * sizeof(unsigned char [256]) );
 
          for (j=0; j<len ; j++) {
-           temp = av_fetch(avmain, j, 0);
+           temp = av_fetch(pmaps_av, j, 0);
            if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
              avsub = (AV*)SvRV(*temp);
              if(av_len(avsub) != 255) continue;
index b91f43d2e5e96a2b0f9ec66b7e13b7bbefe0c348..ace95218dbf40aadcdd9aa62bfabbe28965d9713 100644 (file)
@@ -1,6 +1,7 @@
 #!perl -w
 use strict;
-use Test::More tests => 8;
+use Test::More tests => 10;
+use Imager::Test qw(is_image);
 
 -d "testout" or mkdir "testout";
 
@@ -46,3 +47,17 @@ SKIP: {
      "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");
+}