From: Tony Cook Date: Mon, 9 Apr 2012 11:02:39 +0000 (+1000) Subject: PNG re-work: test results of new and old read handlers X-Git-Tag: v0.90~2^2~18 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/a4fa5d5e137b4a32d8873576f3483ccf262d66b0 PNG re-work: test results of new and old read handlers --- diff --git a/MANIFEST b/MANIFEST index 3324a349..756b81ed 100644 --- 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 diff --git a/PNG/MANIFEST b/PNG/MANIFEST index 50b01a7c..9bd6644d 100644 --- a/PNG/MANIFEST +++ b/PNG/MANIFEST @@ -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 diff --git a/PNG/impng.c b/PNG/impng.c index 142baae8..583a2b7a 100644 --- a/PNG/impng.c +++ b/PNG/impng.c @@ -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 diff --git a/PNG/t/10png.t b/PNG/t/10png.t index a23cde40..33680ba1 100644 --- a/PNG/t/10png.t +++ b/PNG/t/10png.t @@ -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 index 00000000..8b3907b9 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 index 00000000..61273dac Binary files /dev/null and b/PNG/testimg/coveri.png differ diff --git a/PNG/testimg/coverpal.png b/PNG/testimg/coverpal.png index da8d6572..3bfe909c 100644 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 index 00000000..b0321d01 Binary files /dev/null and b/PNG/testimg/coverpali.png differ