1use warnings; 2use strict; 3use Test::More; 4use Image::PNG::Libpng ':all'; 5use Image::PNG::Const ':all'; 6use FindBin '$Bin'; 7 8BEGIN: { 9 use lib "$Bin"; 10 use IPNGLT; 11}; 12 13use utf8; 14use FindBin '$Bin'; 15use Scalar::Util 'looks_like_number'; 16binmode STDOUT, ":utf8"; 17my $builder = Test::More->builder; 18binmode $builder->output, ":utf8"; 19binmode $builder->failure_output, ":utf8"; 20binmode $builder->todo_output, ":utf8"; 21 22# http://www.cpantesters.org/cpan/report/6174e60e-6bf3-1014-896f-3999f29aa079 23 24# and similar, this appears to be a bug in libpng version 1.6.3. 25 26skip_itxt (); 27skip_old (); 28 29my @stuff = ( 30{ 31file => 'ct0n0g04', 32comment => 'no textual data', 33empty => 1, 34}, 35{ 36file => 'ct1n0g04', 37comment => 'with textual data', 38chunks => [ 39{ 40lang => undef, 41itxt_length => 0, 42text_length => 8, 43text => 'PngSuite', 44lang_key => undef, 45compression => -1, 46key => 'Title', 47}, 48{ 49key => 'Author', 50itxt_length => 0, 51text_length => 42, 52lang_key => undef, 53compression => -1, 54text => 'Willem A.J. van Schaik 55(willem@schaik.com)', 56lang => undef, 57}, 58{ 59lang => undef, 60lang_key => undef, 61compression => -1, 62text => 'Copyright Willem van Schaik, Singapore 1995-96', 63text_length => 46, 64itxt_length => 0, 65key => 'Copyright', 66}, 67{ 68lang_key => undef, 69text => 'A compilation of a set of images created to test the 70various color-types of the PNG format. Included are 71black&white, color, paletted, with alpha channel, with 72transparency formats. All bit-depths allowed according 73to the spec are present.', 74compression => -1, 75text_length => 239, 76itxt_length => 0, 77lang => undef, 78key => 'Description', 79}, 80{ 81key => 'Software', 82text_length => 48, 83itxt_length => 0, 84lang_key => undef, 85text => 'Created on a NeXTstation color using "pnmtopng".', 86compression => -1, 87lang => undef, 88}, 89{ 90key => 'Disclaimer', 91compression => -1, 92lang_key => undef, 93text => 'Freeware.', 94text_length => 9, 95itxt_length => 0, 96lang => undef, 97}, 98], 99}, 100{ 101file => 'ctzn0g04', 102comment => 'with compressed textual data', 103chunks => [ 104{ 105key => 'Title', 106lang => undef, 107text => 'PngSuite', 108lang_key => undef, 109compression => -1, 110text_length => 8, 111itxt_length => 0, 112}, 113{ 114key => 'Author', 115itxt_length => 0, 116text_length => 42, 117compression => -1, 118lang_key => undef, 119text => 'Willem A.J. van Schaik 120(willem@schaik.com)', 121lang => undef, 122}, 123{ 124key => 'Copyright', 125lang => undef, 126text_length => 46, 127itxt_length => 0, 128lang_key => undef, 129text => 'Copyright Willem van Schaik, Singapore 1995-96', 130compression => 0, 131}, 132{ 133key => 'Description', 134lang_key => undef, 135text => 'A compilation of a set of images created to test the 136various color-types of the PNG format. Included are 137black&white, color, paletted, with alpha channel, with 138transparency formats. All bit-depths allowed according 139to the spec are present.', 140compression => 0, 141itxt_length => 0, 142text_length => 239, 143lang => undef, 144}, 145{ 146lang => undef, 147compression => 0, 148lang_key => undef, 149text => 'Created on a NeXTstation color using "pnmtopng".', 150text_length => 48, 151itxt_length => 0, 152key => 'Software', 153}, 154{ 155lang_key => undef, 156text => 'Freeware.', 157compression => 0, 158itxt_length => 0, 159text_length => 9, 160lang => undef, 161key => 'Disclaimer', 162}, 163], 164}, 165{ 166file => 'cten0g04', 167comment => 'english', 168chunks => [ 169{ 170lang => 'en', 171text => 'PngSuite', 172lang_key => 'Title', 173compression => 1, 174itxt_length => 8, 175text_length => 0, 176key => 'Title', 177}, 178{ 179key => 'Author', 180lang => 'en', 181lang_key => 'Author', 182text => 'Willem van Schaik (willem@schaik.com)', 183compression => 1, 184text_length => 0, 185itxt_length => 37, 186}, 187{ 188key => 'Copyright', 189itxt_length => 40, 190text_length => 0, 191lang_key => 'Copyright', 192compression => 1, 193text => 'Copyright Willem van Schaik, Canada 2011', 194lang => 'en', 195}, 196{ 197itxt_length => 239, 198text_length => 0, 199lang_key => 'Description', 200compression => 1, 201text => 'A compilation of a set of images created to test the various color-types of the PNG format. Included are black&white, color, paletted, with alpha channel, with transparency formats. All bit-depths allowed according to the spec are present.', 202lang => 'en', 203key => 'Description', 204}, 205{ 206lang => 'en', 207lang_key => 'Software', 208compression => 1, 209text => 'Created on a NeXTstation color using "pnmtopng".', 210itxt_length => 48, 211text_length => 0, 212key => 'Software', 213}, 214{ 215key => 'Disclaimer', 216itxt_length => 9, 217text_length => 0, 218lang_key => 'Disclaimer', 219text => 'Freeware.', 220compression => 1, 221lang => 'en', 222}, 223], 224}, 225{ 226file => 'ctfn0g04', 227comment => 'finnish', 228chunks => [ 229{ 230key => 'Title', 231lang_key => 'Otsikko', 232compression => 1, 233text => 'PngSuite', 234itxt_length => 8, 235text_length => 0, 236lang => 'fi', 237}, 238{ 239key => 'Author', 240lang => 'fi', 241itxt_length => 37, 242text_length => 0, 243lang_key => 'Tekijä', 244compression => 1, 245text => 'Willem van Schaik (willem@schaik.com)', 246}, 247{ 248lang => 'fi', 249itxt_length => 40, 250text_length => 0, 251lang_key => 'Tekijänoikeudet', 252compression => 1, 253text => 'Copyright Willem van Schaik, Kanada 2011', 254key => 'Copyright', 255}, 256{ 257key => 'Description', 258text_length => 0, 259itxt_length => 211, 260text => 'kokoelma joukon kuvia luotu testata eri väri-tyyppisiä PNG-muodossa. Mukana on mustavalkoinen, väri, paletted, alpha-kanava, avoimuuden muodossa. Kaikki bit-syvyydessä mukaan sallittua spec on läsnä.', 261lang_key => 'Kuvaus', 262compression => 1, 263lang => 'fi', 264}, 265{ 266lang => 'fi', 267itxt_length => 37, 268text_length => 0, 269text => 'Luotu NeXTstation väriä "pnmtopng".', 270lang_key => 'Ohjelmistot', 271compression => 1, 272key => 'Software', 273}, 274{ 275key => 'Disclaimer', 276lang => 'fi', 277itxt_length => 9, 278text_length => 0, 279compression => 1, 280lang_key => 'Vastuuvapauslauseke', 281text => 'Freeware.', 282}, 283], 284}, 285{ 286file => 'ctgn0g04', 287comment => 'greek', 288chunks => [ 289{ 290key => 'Title', 291itxt_length => 8, 292text_length => 0, 293text => 'PngSuite', 294lang_key => 'Τίτλος', 295compression => 1, 296lang => 'el', 297}, 298{ 299text_length => 0, 300itxt_length => 37, 301lang_key => 'Συγγραφέας', 302text => 'Willem van Schaik (willem@schaik.com)', 303compression => 1, 304lang => 'el', 305key => 'Author', 306}, 307{ 308lang_key => 'Πνευματικά δικαιώματα', 309text => 'Πνευματικά δικαιώματα Schaik van Willem, Καναδάς 2011', 310compression => 1, 311itxt_length => 80, 312text_length => 0, 313lang => 'el', 314key => 'Copyright', 315}, 316{ 317lang => 'el', 318text => 'Μια συλλογή από ένα σύνολο εικόνων που δημιουργήθηκαν για τη δοκιμή των διαφόρων χρωμάτων-τύπων του μορφή PNG. Περιλαμβάνονται οι ασπρόμαυρες, χρώμα, paletted, με άλφα κανάλι, με μορφές της διαφάνειας. Όλοι λίγο-βάθη επιτρέπεται σύμφωνα με το spec είναι παρόντες.', 319lang_key => 'Περιγραφή', 320compression => 1, 321itxt_length => 465, 322text_length => 0, 323key => 'Description', 324}, 325{ 326text_length => 0, 327itxt_length => 104, 328lang_key => 'Λογισμικό', 329text => 'Δημιουργήθηκε σε ένα χρώμα NeXTstation χρησιμοποιώντας "pnmtopng".', 330compression => 1, 331lang => 'el', 332key => 'Software', 333}, 334{ 335key => 'Disclaimer', 336text => 'Δωρεάν λογισμικό.', 337lang_key => 'Αποποίηση', 338compression => 1, 339itxt_length => 32, 340text_length => 0, 341lang => 'el', 342}, 343], 344}, 345{ 346file => 'cthn0g04', 347comment => 'hindi', 348chunks => [ 349{ 350key => 'Title', 351text_length => 0, 352itxt_length => 8, 353lang_key => 'शीर्षक', 354text => 'PngSuite', 355compression => 1, 356lang => 'hi', 357}, 358{ 359key => 'Author', 360lang => 'hi', 361text => 'Willem van Schaik (willem@schaik.com)', 362lang_key => 'लेखक', 363compression => 1, 364text_length => 0, 365itxt_length => 37, 366}, 367{ 368lang_key => 'कॉपीराइट', 369text => 'कॉपीराइट Willem van Schaik, 2011 कनाडा', 370compression => 1, 371itxt_length => 64, 372text_length => 0, 373lang => 'hi', 374key => 'Copyright', 375}, 376{ 377key => 'Description', 378lang => 'hi', 379lang_key => 'विवरण', 380text => 'करने के लिए PNG प्रारूप के विभिन्न रंग प्रकार परीक्षण बनाया छवियों का एक सेट का एक संकलन. शामिल काले और सफेद, रंग, पैलेटेड हैं, अल्फा चैनल के साथ पारदर्शिता स्वरूपों के साथ. सभी बिट गहराई कल्पना के अनुसार की अनुमति दी मौजूद हैं.', 381compression => 1, 382text_length => 0, 383itxt_length => 580, 384}, 385{ 386text_length => 0, 387itxt_length => 103, 388text => 'एक NeXTstation "pnmtopng \'का उपयोग कर रंग पर बनाया गया.', 389lang_key => 'सॉफ्टवेयर', 390compression => 1, 391lang => 'hi', 392key => 'Software', 393}, 394{ 395lang => 'hi', 396text_length => 0, 397itxt_length => 25, 398lang_key => 'अस्वीकरण', 399compression => 1, 400text => 'फ्रीवेयर.', 401key => 'Disclaimer', 402}, 403], 404}, 405{ 406file => 'ctjn0g04', 407comment => 'japanese', 408chunks => [ 409{ 410key => 'Title', 411itxt_length => 8, 412text_length => 0, 413text => 'PngSuite', 414lang_key => 'タイトル', 415compression => 1, 416lang => 'ja', 417}, 418{ 419key => 'Author', 420compression => 1, 421lang_key => '著者', 422text => 'Willem van Schaik (willem@schaik.com)', 423itxt_length => 37, 424text_length => 0, 425lang => 'ja', 426}, 427{ 428lang => 'ja', 429itxt_length => 58, 430text_length => 0, 431text => '著作権ウィレムヴァンシャイク、カナダ2011', 432lang_key => '本文へ', 433compression => 1, 434key => 'Copyright', 435}, 436{ 437lang_key => '概要', 438text => 'PNG形式の様々な色の種類をテストするために作成されたイメージのセットのコンパイル。含まれているのは透明度のフォーマットで、アルファチャネルを持つ、白黒、カラー、パレットです。すべてのビット深度が存在している仕様に従ったことができました。', 439compression => 1, 440itxt_length => 351, 441text_length => 0, 442lang => 'ja', 443key => 'Description', 444}, 445{ 446lang => 'ja', 447text => '"pnmtopng"を使用してNeXTstation色上に作成されます。', 448lang_key => 'ソフトウェア', 449compression => 1, 450itxt_length => 66, 451text_length => 0, 452key => 'Software', 453}, 454{ 455itxt_length => 21, 456text_length => 0, 457lang_key => '免責事項', 458text => 'フリーウェア。', 459compression => 1, 460lang => 'ja', 461key => 'Disclaimer', 462}, 463], 464}, 465); 466 467# There are some instances of libpngs which return 2 468# (PNG_ITXT_COMPRESSION_zTXt) for the text compression. However, this 469# does not occur in any of the examples, so it seems like there must 470# be a faulty libpng. 471 472for my $test (@stuff) { 473 my $png = read_png_file ("$Bin/libpng/$test->{file}.png"); 474 my $texts = $png->get_text (); 475 if ($texts) { 476 for my $text (@$texts) { 477 if ($text->{compression} == 2) { 478 479 # There are no examples in pngsuite with compression 480 # value 2 (PNG_ITXT_COMPRESSION_zTXt). The following 481 # test failure dates from before I introduced 482 # "bogus.t" to get the version number of libpng: 483 484 # http://www.cpantesters.org/cpan/report/717bf5a4-8284-11e3-bd14-e3bee4621ba3 485 486 # The following still doesn't seem to work to skip the 487 # tests though, so we also test the version at the top 488 # of this file and stop if the version is 1.6.3 or 489 # less. 490 491 plan skip_all => 'Bad compression value detected, your libpng is faulty'; 492 goto end; 493 } 494 } 495 } 496} 497 498for my $test (@stuff) { 499 my $png = read_png_file ("$Bin/libpng/$test->{file}.png"); 500 my $texts = $png->get_text (); 501 if ($test->{empty}) { 502 ok (! $texts, 503 "There were no text chunks in $test->{file}, as expected"); 504 } 505 else { 506 my $chunks = $test->{chunks}; 507 is_deeply ($texts, $chunks, 508 "Text chunk from $test->{file} was as expected"); 509 } 510} 511 512# Escape route for broken libpngs. 513 514end: 515 516done_testing (); 517 518# Local variables: 519# mode: perl 520# End: 521