]> git.imager.perl.org - imager.git/commitdiff
PNG re-work: test results of new and old read handlers
authorTony Cook <tony@develop-help.com>
Mon, 9 Apr 2012 11:02:39 +0000 (21:02 +1000)
committerTony Cook <tony@develop-help.com>
Sun, 29 Apr 2012 03:40:56 +0000 (13:40 +1000)
MANIFEST
PNG/MANIFEST
PNG/impng.c
PNG/t/10png.t
PNG/testimg/cover16i.png [new file with mode: 0644]
PNG/testimg/coveri.png [new file with mode: 0644]
PNG/testimg/coverpal.png
PNG/testimg/coverpali.png [new file with mode: 0644]

index 3324a3490e732a64b2781fc659348b21d38e8ce5..756b81edd08d887c3fde8b98c1d3a7118613a34e 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -229,7 +229,10 @@ PNG/testimg/badcrc.png
 PNG/testimg/bilevel.png
 PNG/testimg/cover.png
 PNG/testimg/cover16.png
+PNG/testimg/cover16i.png
+PNG/testimg/coveri.png
 PNG/testimg/coverpal.png
+PNG/testimg/coverpali.png
 PNG/testimg/gray.png
 PNG/testimg/graya.png
 PNG/testimg/pal.png
index 50b01a7c3c2ae9b7984212c36f587688fa51f8e5..9bd6644d40cf884a696ea9ff889b4809bfa553c7 100644 (file)
@@ -14,7 +14,10 @@ testimg/badcrc.png
 testimg/bilevel.png
 testimg/cover.png
 testimg/cover16.png
+testimg/cover16i.png
+testimg/coveri.png
 testimg/coverpal.png
+testimg/coverpali.png
 testimg/gray.png
 testimg/graya.png
 testimg/pal.png
index 142baae8f636bdefbcb21c24d92ab328a35ce3f8..583a2b7ad474396ebb7aacc6d41917b61b49fe1e 100644 (file)
@@ -618,17 +618,23 @@ get_png_tags(i_img *im, png_structp png_ptr, png_infop info_ptr, int bit_depth)
       i_tags_setn(&im->tags, "i_aspect_only", 1);
     }
   }
-  switch (png_get_interlace_type(png_ptr, info_ptr)) {
-  case PNG_INTERLACE_NONE:
-    i_tags_setn(&im->tags, "png_interlace", 0);
-    break;
-  case PNG_INTERLACE_ADAM7:
-    i_tags_set(&im->tags, "png_interlace", "adam7", -1);
-    break;
-
-  default:
-    i_tags_set(&im->tags, "png_interlace", "unknown", -1);
-    break;
+  {
+    int interlace = png_get_interlace_type(png_ptr, info_ptr);
+
+    i_tags_setn(&im->tags, "png_interlace", interlace != PNG_INTERLACE_NONE);
+    switch (interlace) {
+    case PNG_INTERLACE_NONE:
+      i_tags_set(&im->tags, "png_interlace_name", "none", -1);
+      break;
+      
+    case PNG_INTERLACE_ADAM7:
+      i_tags_set(&im->tags, "png_interlace_name", "adam7", -1);
+      break;
+      
+    default:
+      i_tags_set(&im->tags, "png_interlace_name", "unknown", -1);
+      break;
+    }
   }
 
   /* the various readers can call png_set_expand(), libpng will make
index a23cde404fa3409eeed8e9cc149cf7ac1f491615..33680ba17e41aaa11c51168bd62bbb1887b3d5ad 100644 (file)
@@ -10,10 +10,10 @@ my $debug_writes = 1;
 
 init_log("testout/t102png.log",1);
 
-$Imager::formats{"png"}
-  or plan skip_all => "No png support";
+plan tests => 151;
 
-plan tests => 93;
+# this loads Imager::File::PNG too
+ok($Imager::formats{"png"}, "must have png format");
 
 diag("Library version " . Imager::File::PNG::i_png_lib_version());
 
@@ -296,15 +296,133 @@ SKIP:
   is($im_i->getchannels, 3, "check channel count");
   is($im_i->type, "direct", "check type");
   is($im_i->tags(name => "png_bits"), 8, "check png_bits");
-  is($im_i->tags(name => "png_interlace"), "adam7", "check png_interlace");
+  is($im_i->tags(name => "png_interlace"), 1, "check png_interlace");
 
   my $im = Imager->new(file => "testimg/rgb8.png", filetype => "png");
   ok($im, "read non-interlaced")
     or skip("Could not read testimg/rgb8.png: " . Imager->errstr, 2);
-  is($im->tags(name => "png_interlace"), "0", "check png_interlace");
+  is($im->tags(name => "png_interlace"), 0, "check png_interlace");
   is_image($im_i, $im, "compare interlaced and non-interlaced");
 }
 
+{
+  my @match =
+    (
+     [ "cover.png", "coveri.png" ],
+     [ "cover16.png", "cover16i.png" ],
+     [ "coverpal.png", "coverpali.png" ],
+    );
+  for my $match (@match) {
+    my ($normal, $interlace) = @$match;
+
+    my $n_im = Imager->new(file => "testimg/$normal");
+    ok($n_im, "read $normal")
+      or diag "reading $normal: ", Imager->errstr;
+    my $i_im = Imager->new(file => "testimg/$interlace");
+    ok($i_im, "read $interlace")
+      or diag "reading $interlace: ", Imager->errstr;
+  SKIP:
+    {
+      $n_im && $i_im
+       or skip("Couldn't read a file", 1);
+      is_image($i_im, $n_im, "check normal and interlace files read the same");
+    }
+  }
+}
+
+{
+  my $interlace = 0;
+  for my $name ("cover.png", "coveri.png") {
+  SKIP: {
+      my $im = Imager->new(file => "testimg/$name");
+      ok($im, "read $name")
+       or diag "Failed to read $name: ", Imager->errstr;
+      $im
+       or skip("Couldn't load $name", 5);
+      is($im->tags(name => "i_format"), "png", "$name: i_format");
+      is($im->tags(name => "png_bits"), 8, "$name: png_bits");
+      is($im->tags(name => "png_interlace"), $interlace,
+        "$name: png_interlace");
+      is($im->getchannels, 4, "$name: four channels");
+      is($im->type, "direct", "$name: direct type");
+
+      is_deeply([ $im->getsamples(y => 0, width => 5) ],
+               [ ( 255, 255, 0, 255 ), ( 255, 255, 0, 191 ),
+                 ( 255, 255, 0, 127 ), ( 255, 255, 0, 63 ),
+                 ( 0, 0, 0, 0) ],
+               "$name: check expected samples row 0");
+      is_deeply([ $im->getsamples(y => 1, width => 5) ],
+               [ ( 255, 0, 0, 255 ), ( 255, 0, 0, 191 ),
+                 ( 255, 0, 0, 127 ), ( 255, 0, 0, 63 ),
+                 ( 0, 0, 0, 0) ],
+               "$name: check expected samples row 1");
+    }
+    $interlace = 1;
+  }
+}
+
+{
+  my $interlace = 0;
+  for my $name ("coverpal.png", "coverpali.png") {
+  SKIP: {
+      my $im = Imager->new(file => "testimg/$name");
+      ok($im, "read $name")
+       or diag "Failed to read $name: ", Imager->errstr;
+      $im
+       or skip("Couldn't load $name", 5);
+      is($im->tags(name => "i_format"), "png", "$name: i_format");
+      is($im->tags(name => "png_bits"), 4, "$name: png_bits");
+      is($im->tags(name => "png_interlace"), $interlace,
+        "$name: png_interlace");
+      is($im->getchannels, 4, "$name: four channels");
+      is($im->type, "paletted", "$name: paletted type");
+
+      is_deeply([ $im->getsamples(y => 0, width => 5) ],
+               [ ( 255, 255, 0, 255 ), ( 255, 255, 0, 191 ),
+                 ( 255, 255, 0, 127 ), ( 255, 255, 0, 63 ),
+                 ( 0, 0, 0, 0) ],
+               "$name: check expected samples row 0");
+      is_deeply([ $im->getsamples(y => 1, width => 5) ],
+               [ ( 255, 0, 0, 255 ), ( 255, 0, 0, 191 ),
+                 ( 255, 0, 0, 127 ), ( 255, 0, 0, 63 ),
+                 ( 0, 0, 0, 0) ],
+               "$name: check expected samples row 1");
+    }
+    $interlace = 1;
+  }
+}
+
+{
+  my $interlace = 0;
+  for my $name ("cover16.png", "cover16i.png") {
+  SKIP: {
+      my $im = Imager->new(file => "testimg/$name");
+      ok($im, "read $name")
+       or diag "Failed to read $name: ", Imager->errstr;
+      $im
+       or skip("Couldn't load $name", 5);
+      is($im->tags(name => "i_format"), "png", "$name: i_format");
+      is($im->tags(name => "png_bits"), 16, "$name: png_bits");
+      is($im->tags(name => "png_interlace"), $interlace,
+        "$name: png_interlace");
+      is($im->getchannels, 4, "$name: four channels");
+      is($im->type, "direct", "$name: direct type");
+
+      is_deeply([ $im->getsamples(y => 0, width => 5, type => "16bit") ],
+               [ ( 65535, 65535, 0, 65535 ), ( 65535, 65535, 0, 49087 ),
+                 ( 65535, 65535, 0, 32639 ), ( 65535, 65535, 0, 16191 ),
+                 ( 65535, 65535, 65535, 0) ],
+               "$name: check expected samples row 0");
+      is_deeply([ $im->getsamples(y => 1, width => 5, type => "16bit") ],
+               [ ( 65535, 0, 0, 65535 ), ( 65535, 0, 0, 49087 ),
+                 ( 65535, 0, 0, 32639 ), ( 65535, 0, 0, 16191 ),
+                 ( 65535, 65535, 65535, 0) ],
+               "$name: check expected samples row 1");
+    }
+    $interlace = 1;
+  }
+}
+
 sub limited_write {
   my ($limit) = @_;
 
diff --git a/PNG/testimg/cover16i.png b/PNG/testimg/cover16i.png
new file mode 100644 (file)
index 0000000..8b3907b
Binary files /dev/null and b/PNG/testimg/cover16i.png differ
diff --git a/PNG/testimg/coveri.png b/PNG/testimg/coveri.png
new file mode 100644 (file)
index 0000000..61273da
Binary files /dev/null and b/PNG/testimg/coveri.png differ
index da8d6572471038d6d832725cb347a321fae2f7ac..3bfe909cbf435589de92eb49c36480d053e3f6f9 100644 (file)
Binary files a/PNG/testimg/coverpal.png and b/PNG/testimg/coverpal.png differ
diff --git a/PNG/testimg/coverpali.png b/PNG/testimg/coverpali.png
new file mode 100644 (file)
index 0000000..b0321d0
Binary files /dev/null and b/PNG/testimg/coverpali.png differ