Permalink
Browse files

PNG re-work: test results of new and old read handlers

  • Loading branch information...
1 parent 2d78f29 commit a4fa5d5e137b4a32d8873576f3483ccf262d66b0 @tonycoz committed Apr 9, 2012
View
@@ -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
View
@@ -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
View
@@ -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
View
@@ -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) = @_;
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a4fa5d5

Please sign in to comment.