From a4fa5d5e137b4a32d8873576f3483ccf262d66b0 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Mon, 9 Apr 2012 21:02:39 +1000 Subject: [PATCH] PNG re-work: test results of new and old read handlers --- MANIFEST | 3 + PNG/MANIFEST | 3 + PNG/impng.c | 28 +++++---- PNG/t/10png.t | 128 ++++++++++++++++++++++++++++++++++++-- PNG/testimg/cover16i.png | Bin 0 -> 900 bytes PNG/testimg/coveri.png | Bin 0 -> 100 bytes PNG/testimg/coverpal.png | Bin 388 -> 132 bytes PNG/testimg/coverpali.png | Bin 0 -> 136 bytes 8 files changed, 146 insertions(+), 16 deletions(-) create mode 100644 PNG/testimg/cover16i.png create mode 100644 PNG/testimg/coveri.png create mode 100644 PNG/testimg/coverpali.png 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 0000000000000000000000000000000000000000..8b3907b9da076e3907bf0a2f888c8d96f2a83280 GIT binary patch literal 900 zcmeAS@N?(olHy`uVBq!ia0vp^AU2Z#8v_HQ+qZ?RKn`1yx4X-KFyM^%eg`PRS>O>_ z%)r1c1j3A$?$-SQs=ikh5>XPASgue|l%JNFld4csS&*twkz2sPP;u++497lcMG=?p za}K#Ttnv^2URc1q+avPXkH{Nx)i#rl7*Cueck-32{HoW13-l+})%>2v*M69Bt3l!8 zFOSwJy;||gK`bP7t<;+jGmbwlJai&T^i6?jcFD6B=NvPzASN*s{WgXE~nstRBO?=W&RDy=6P*SNvk_J_D(aL z&Wst`a+7bUv@KIi-c<1Pl<4G{2UIw|T;>Gh41-&4Pcne0{Dt5<3N!TeAMN8yucI}-QV{*&3MSpURZ ze)d28R=ciE@msi0*2&aHy$D}eu7PEU zp^=rbv6Zod15)rtPf{gr<{M^)%qReE5Aa|$D3ZD0Y@}hA0qWtn= e-GbC2-D04U0tTZe)-CKn1q`09elF{r5}E)`9CY3Q literal 0 HcmV?d00001 diff --git a/PNG/testimg/coveri.png b/PNG/testimg/coveri.png new file mode 100644 index 0000000000000000000000000000000000000000..61273dac09eaf3bd65fca5eb034e74aee4c7751f GIT binary patch literal 100 zcmeAS@N?(olHy`uVBq!ia0vp^AT|>R8v_HQSX!+ckfZJC;uyj)Gxyj*-UbDR0|%0g z+>1?0Hhntu;lm`g&`+A*=SAwZ3qHKb8)q+;^qRjcFL=8?P#c4%tDnm{r-UW|-ijVY literal 0 HcmV?d00001 diff --git a/PNG/testimg/coverpal.png b/PNG/testimg/coverpal.png index da8d6572471038d6d832725cb347a321fae2f7ac..3bfe909cbf435589de92eb49c36480d053e3f6f9 100644 GIT binary patch literal 132 zcmeAS@N?(olHy`uVBq!ia0vp^AT|>VGmxC@AMhARNeB3ZxB}__aP*(yKO8YItn$m~ z0ZOx%1o;Is?60>6qP-tgEr3FTo-U3d95a(OIFlKg+)@=78MsRs^Tp?y{Qycbc)I$z JtaD0e0syfsB!&P0 literal 388 zcmebD)MC(JU|^`Y_51()hxW|OhZ!Z(Qc^5VG_d|jcL+Y-5G%_NEXU0#!oa}D%)kg# z$pyrWP&N~g%>-n#0BJd(Br{Z;1ITAXQo{vhgY@$VGXn$T6OV*aAV)gDC&U#<|A(Xh4FBPXfnk+j zMh{S$y(Gvlm|=gtJrM2vsA>Te67_U(4B?oWtdWqAz>!eEJgN7T0}})PbjH<+U)nDM P6)