From cfc4bc1996d0bab0d71134855a02d612dac07eb8 Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Wed, 2 Aug 2023 11:43:02 -0500 Subject: [PATCH] PNG: parsing PNG data No UI yet, but the parser seems mostly done. --- public/common/bytes.js | 28 +++ public/png/constants.js | 99 +++++++++++ public/png/crc32.js | 28 +++ public/png/index.html | 2 +- public/png/parsePng.js | 305 +++++++++++++++++++++++++++++++++ public/png/png.js | 13 +- test/common/base64url.test.ts | 6 +- test/common/bytes.test.ts | 20 +++ test/helpers.ts | 25 +++ test/png/crc32.test.ts | 21 +++ test/png/fixtures/basi0g01.png | Bin 0 -> 217 bytes test/png/fixtures/basi0g02.png | Bin 0 -> 154 bytes test/png/fixtures/basi0g04.png | Bin 0 -> 247 bytes test/png/fixtures/basi0g08.png | Bin 0 -> 254 bytes test/png/fixtures/basi0g16.png | Bin 0 -> 299 bytes test/png/fixtures/basi2c08.png | Bin 0 -> 315 bytes test/png/fixtures/basi2c16.png | Bin 0 -> 595 bytes test/png/fixtures/basi3p01.png | Bin 0 -> 132 bytes test/png/fixtures/basi3p02.png | Bin 0 -> 193 bytes test/png/fixtures/basi3p04.png | Bin 0 -> 327 bytes test/png/fixtures/basi3p08.png | Bin 0 -> 1527 bytes test/png/fixtures/basi4a08.png | Bin 0 -> 214 bytes test/png/fixtures/basi4a16.png | Bin 0 -> 2855 bytes test/png/fixtures/basi6a08.png | Bin 0 -> 361 bytes test/png/fixtures/basi6a16.png | Bin 0 -> 4180 bytes test/png/fixtures/basn0g01.png | Bin 0 -> 164 bytes test/png/fixtures/basn0g02.png | Bin 0 -> 104 bytes test/png/fixtures/basn0g04.png | Bin 0 -> 145 bytes test/png/fixtures/basn0g08.png | Bin 0 -> 138 bytes test/png/fixtures/basn0g16.png | Bin 0 -> 167 bytes test/png/fixtures/basn2c08.png | Bin 0 -> 145 bytes test/png/fixtures/basn2c16.png | Bin 0 -> 302 bytes test/png/fixtures/basn3p01.png | Bin 0 -> 112 bytes test/png/fixtures/basn3p02.png | Bin 0 -> 146 bytes test/png/fixtures/basn3p04.png | Bin 0 -> 216 bytes test/png/fixtures/basn3p08.png | Bin 0 -> 1286 bytes test/png/fixtures/basn4a08.png | Bin 0 -> 126 bytes test/png/fixtures/basn4a16.png | Bin 0 -> 2206 bytes test/png/fixtures/basn6a08.png | Bin 0 -> 184 bytes test/png/fixtures/basn6a16.png | Bin 0 -> 3435 bytes test/png/fixtures/bgai4a08.png | Bin 0 -> 214 bytes test/png/fixtures/bgai4a16.png | Bin 0 -> 2855 bytes test/png/fixtures/bgan6a08.png | Bin 0 -> 184 bytes test/png/fixtures/bgan6a16.png | Bin 0 -> 3435 bytes test/png/fixtures/bgbn4a08.png | Bin 0 -> 140 bytes test/png/fixtures/bggn4a16.png | Bin 0 -> 2220 bytes test/png/fixtures/bgwn6a08.png | Bin 0 -> 202 bytes test/png/fixtures/bgyn6a16.png | Bin 0 -> 3453 bytes test/png/fixtures/ccwn2c08.png | Bin 0 -> 1514 bytes test/png/fixtures/ccwn3p08.png | Bin 0 -> 1554 bytes test/png/fixtures/cdfn2c08.png | Bin 0 -> 404 bytes test/png/fixtures/cdhn2c08.png | Bin 0 -> 344 bytes test/png/fixtures/cdsn2c08.png | Bin 0 -> 232 bytes test/png/fixtures/cdun2c08.png | Bin 0 -> 724 bytes test/png/fixtures/ch1n3p04.png | Bin 0 -> 258 bytes test/png/fixtures/ch2n3p08.png | Bin 0 -> 1810 bytes test/png/fixtures/cm0n0g04.png | Bin 0 -> 292 bytes test/png/fixtures/cm7n0g04.png | Bin 0 -> 292 bytes test/png/fixtures/cm9n0g04.png | Bin 0 -> 292 bytes test/png/fixtures/cs3n2c16.png | Bin 0 -> 214 bytes test/png/fixtures/cs3n3p08.png | Bin 0 -> 259 bytes test/png/fixtures/cs5n2c08.png | Bin 0 -> 186 bytes test/png/fixtures/cs5n3p08.png | Bin 0 -> 271 bytes test/png/fixtures/cs8n2c08.png | Bin 0 -> 149 bytes test/png/fixtures/cs8n3p08.png | Bin 0 -> 256 bytes test/png/fixtures/ct0n0g04.png | Bin 0 -> 273 bytes test/png/fixtures/ct1n0g04.png | Bin 0 -> 792 bytes test/png/fixtures/cten0g04.png | Bin 0 -> 742 bytes test/png/fixtures/ctfn0g04.png | Bin 0 -> 716 bytes test/png/fixtures/ctgn0g04.png | Bin 0 -> 1182 bytes test/png/fixtures/cthn0g04.png | Bin 0 -> 1269 bytes test/png/fixtures/ctjn0g04.png | Bin 0 -> 941 bytes test/png/fixtures/ctzn0g04.png | Bin 0 -> 753 bytes test/png/fixtures/exif2c08.png | Bin 0 -> 1788 bytes test/png/fixtures/f00n0g08.png | Bin 0 -> 319 bytes test/png/fixtures/f00n2c08.png | Bin 0 -> 2475 bytes test/png/fixtures/f01n0g08.png | Bin 0 -> 321 bytes test/png/fixtures/f01n2c08.png | Bin 0 -> 1180 bytes test/png/fixtures/f02n0g08.png | Bin 0 -> 355 bytes test/png/fixtures/f02n2c08.png | Bin 0 -> 1729 bytes test/png/fixtures/f03n0g08.png | Bin 0 -> 389 bytes test/png/fixtures/f03n2c08.png | Bin 0 -> 1291 bytes test/png/fixtures/f04n0g08.png | Bin 0 -> 269 bytes test/png/fixtures/f04n2c08.png | Bin 0 -> 985 bytes test/png/fixtures/f99n0g04.png | Bin 0 -> 426 bytes test/png/fixtures/g03n0g16.png | Bin 0 -> 345 bytes test/png/fixtures/g03n2c08.png | Bin 0 -> 370 bytes test/png/fixtures/g03n3p04.png | Bin 0 -> 214 bytes test/png/fixtures/g04n0g16.png | Bin 0 -> 363 bytes test/png/fixtures/g04n2c08.png | Bin 0 -> 377 bytes test/png/fixtures/g04n3p04.png | Bin 0 -> 219 bytes test/png/fixtures/g05n0g16.png | Bin 0 -> 339 bytes test/png/fixtures/g05n2c08.png | Bin 0 -> 350 bytes test/png/fixtures/g05n3p04.png | Bin 0 -> 206 bytes test/png/fixtures/g07n0g16.png | Bin 0 -> 321 bytes test/png/fixtures/g07n2c08.png | Bin 0 -> 340 bytes test/png/fixtures/g07n3p04.png | Bin 0 -> 207 bytes test/png/fixtures/g10n0g16.png | Bin 0 -> 262 bytes test/png/fixtures/g10n2c08.png | Bin 0 -> 285 bytes test/png/fixtures/g10n3p04.png | Bin 0 -> 214 bytes test/png/fixtures/g25n0g16.png | Bin 0 -> 383 bytes test/png/fixtures/g25n2c08.png | Bin 0 -> 405 bytes test/png/fixtures/g25n3p04.png | Bin 0 -> 215 bytes test/png/fixtures/oi1n0g16.png | Bin 0 -> 167 bytes test/png/fixtures/oi1n2c16.png | Bin 0 -> 302 bytes test/png/fixtures/oi2n0g16.png | Bin 0 -> 179 bytes test/png/fixtures/oi2n2c16.png | Bin 0 -> 314 bytes test/png/fixtures/oi4n0g16.png | Bin 0 -> 203 bytes test/png/fixtures/oi4n2c16.png | Bin 0 -> 338 bytes test/png/fixtures/oi9n0g16.png | Bin 0 -> 1283 bytes test/png/fixtures/oi9n2c16.png | Bin 0 -> 3038 bytes test/png/fixtures/pp0n2c16.png | Bin 0 -> 962 bytes test/png/fixtures/pp0n6a08.png | Bin 0 -> 818 bytes test/png/fixtures/ps1n0g08.png | Bin 0 -> 1456 bytes test/png/fixtures/ps1n2c16.png | Bin 0 -> 1620 bytes test/png/fixtures/ps2n0g08.png | Bin 0 -> 2320 bytes test/png/fixtures/ps2n2c16.png | Bin 0 -> 2484 bytes test/png/fixtures/s01i3p01.png | Bin 0 -> 113 bytes test/png/fixtures/s01n3p01.png | Bin 0 -> 113 bytes test/png/fixtures/s02i3p01.png | Bin 0 -> 114 bytes test/png/fixtures/s02n3p01.png | Bin 0 -> 115 bytes test/png/fixtures/s03i3p01.png | Bin 0 -> 118 bytes test/png/fixtures/s03n3p01.png | Bin 0 -> 120 bytes test/png/fixtures/s04i3p01.png | Bin 0 -> 126 bytes test/png/fixtures/s04n3p01.png | Bin 0 -> 121 bytes test/png/fixtures/s05i3p02.png | Bin 0 -> 134 bytes test/png/fixtures/s05n3p02.png | Bin 0 -> 129 bytes test/png/fixtures/s06i3p02.png | Bin 0 -> 143 bytes test/png/fixtures/s06n3p02.png | Bin 0 -> 131 bytes test/png/fixtures/s07i3p02.png | Bin 0 -> 149 bytes test/png/fixtures/s07n3p02.png | Bin 0 -> 138 bytes test/png/fixtures/s08i3p02.png | Bin 0 -> 149 bytes test/png/fixtures/s08n3p02.png | Bin 0 -> 139 bytes test/png/fixtures/s09i3p02.png | Bin 0 -> 147 bytes test/png/fixtures/s09n3p02.png | Bin 0 -> 143 bytes test/png/fixtures/s32i3p04.png | Bin 0 -> 355 bytes test/png/fixtures/s32n3p04.png | Bin 0 -> 263 bytes test/png/fixtures/s33i3p04.png | Bin 0 -> 385 bytes test/png/fixtures/s33n3p04.png | Bin 0 -> 329 bytes test/png/fixtures/s34i3p04.png | Bin 0 -> 349 bytes test/png/fixtures/s34n3p04.png | Bin 0 -> 248 bytes test/png/fixtures/s35i3p04.png | Bin 0 -> 399 bytes test/png/fixtures/s35n3p04.png | Bin 0 -> 338 bytes test/png/fixtures/s36i3p04.png | Bin 0 -> 356 bytes test/png/fixtures/s36n3p04.png | Bin 0 -> 258 bytes test/png/fixtures/s37i3p04.png | Bin 0 -> 393 bytes test/png/fixtures/s37n3p04.png | Bin 0 -> 336 bytes test/png/fixtures/s38i3p04.png | Bin 0 -> 357 bytes test/png/fixtures/s38n3p04.png | Bin 0 -> 245 bytes test/png/fixtures/s39i3p04.png | Bin 0 -> 420 bytes test/png/fixtures/s39n3p04.png | Bin 0 -> 352 bytes test/png/fixtures/s40i3p04.png | Bin 0 -> 357 bytes test/png/fixtures/s40n3p04.png | Bin 0 -> 256 bytes test/png/fixtures/tbbn0g04.png | Bin 0 -> 429 bytes test/png/fixtures/tbbn2c16.png | Bin 0 -> 2041 bytes test/png/fixtures/tbbn3p08.png | Bin 0 -> 1499 bytes test/png/fixtures/tbgn2c16.png | Bin 0 -> 2041 bytes test/png/fixtures/tbgn3p08.png | Bin 0 -> 1499 bytes test/png/fixtures/tbrn2c08.png | Bin 0 -> 1633 bytes test/png/fixtures/tbwn0g16.png | Bin 0 -> 1313 bytes test/png/fixtures/tbwn3p08.png | Bin 0 -> 1496 bytes test/png/fixtures/tbyn3p08.png | Bin 0 -> 1499 bytes test/png/fixtures/tm3n3p02.png | Bin 0 -> 116 bytes test/png/fixtures/tp0n0g08.png | Bin 0 -> 719 bytes test/png/fixtures/tp0n2c08.png | Bin 0 -> 1594 bytes test/png/fixtures/tp0n3p08.png | Bin 0 -> 1476 bytes test/png/fixtures/tp1n3p08.png | Bin 0 -> 1483 bytes test/png/fixtures/xc1n0g08.png | Bin 0 -> 138 bytes test/png/fixtures/xc9n2c08.png | Bin 0 -> 145 bytes test/png/fixtures/xcrn0g04.png | Bin 0 -> 145 bytes test/png/fixtures/xcsn0g01.png | Bin 0 -> 164 bytes test/png/fixtures/xd0n2c08.png | Bin 0 -> 145 bytes test/png/fixtures/xd3n2c08.png | Bin 0 -> 145 bytes test/png/fixtures/xd9n2c08.png | Bin 0 -> 145 bytes test/png/fixtures/xdtn0g01.png | Bin 0 -> 61 bytes test/png/fixtures/xhdn0g08.png | Bin 0 -> 138 bytes test/png/fixtures/xlfn0g04.png | Bin 0 -> 145 bytes test/png/fixtures/xs1n0g01.png | Bin 0 -> 164 bytes test/png/fixtures/xs2n0g01.png | Bin 0 -> 164 bytes test/png/fixtures/xs4n0g01.png | Bin 0 -> 164 bytes test/png/fixtures/xs7n0g01.png | Bin 0 -> 164 bytes test/png/fixtures/z00n2c08.png | Bin 0 -> 3172 bytes test/png/fixtures/z03n2c08.png | Bin 0 -> 232 bytes test/png/fixtures/z06n2c08.png | Bin 0 -> 224 bytes test/png/fixtures/z09n2c08.png | Bin 0 -> 224 bytes test/png/parseHash.test.ts | 35 ++-- test/png/parsePng.test.ts | 124 ++++++++++++++ types/png.d.ts | 19 ++ 188 files changed, 699 insertions(+), 26 deletions(-) create mode 100644 public/common/bytes.js create mode 100644 public/png/constants.js create mode 100644 public/png/crc32.js create mode 100644 public/png/parsePng.js create mode 100644 test/common/bytes.test.ts create mode 100644 test/helpers.ts create mode 100644 test/png/crc32.test.ts create mode 100644 test/png/fixtures/basi0g01.png create mode 100644 test/png/fixtures/basi0g02.png create mode 100644 test/png/fixtures/basi0g04.png create mode 100644 test/png/fixtures/basi0g08.png create mode 100644 test/png/fixtures/basi0g16.png create mode 100644 test/png/fixtures/basi2c08.png create mode 100644 test/png/fixtures/basi2c16.png create mode 100644 test/png/fixtures/basi3p01.png create mode 100644 test/png/fixtures/basi3p02.png create mode 100644 test/png/fixtures/basi3p04.png create mode 100644 test/png/fixtures/basi3p08.png create mode 100644 test/png/fixtures/basi4a08.png create mode 100644 test/png/fixtures/basi4a16.png create mode 100644 test/png/fixtures/basi6a08.png create mode 100644 test/png/fixtures/basi6a16.png create mode 100644 test/png/fixtures/basn0g01.png create mode 100644 test/png/fixtures/basn0g02.png create mode 100644 test/png/fixtures/basn0g04.png create mode 100644 test/png/fixtures/basn0g08.png create mode 100644 test/png/fixtures/basn0g16.png create mode 100644 test/png/fixtures/basn2c08.png create mode 100644 test/png/fixtures/basn2c16.png create mode 100644 test/png/fixtures/basn3p01.png create mode 100644 test/png/fixtures/basn3p02.png create mode 100644 test/png/fixtures/basn3p04.png create mode 100644 test/png/fixtures/basn3p08.png create mode 100644 test/png/fixtures/basn4a08.png create mode 100644 test/png/fixtures/basn4a16.png create mode 100644 test/png/fixtures/basn6a08.png create mode 100644 test/png/fixtures/basn6a16.png create mode 100644 test/png/fixtures/bgai4a08.png create mode 100644 test/png/fixtures/bgai4a16.png create mode 100644 test/png/fixtures/bgan6a08.png create mode 100644 test/png/fixtures/bgan6a16.png create mode 100644 test/png/fixtures/bgbn4a08.png create mode 100644 test/png/fixtures/bggn4a16.png create mode 100644 test/png/fixtures/bgwn6a08.png create mode 100644 test/png/fixtures/bgyn6a16.png create mode 100644 test/png/fixtures/ccwn2c08.png create mode 100644 test/png/fixtures/ccwn3p08.png create mode 100644 test/png/fixtures/cdfn2c08.png create mode 100644 test/png/fixtures/cdhn2c08.png create mode 100644 test/png/fixtures/cdsn2c08.png create mode 100644 test/png/fixtures/cdun2c08.png create mode 100644 test/png/fixtures/ch1n3p04.png create mode 100644 test/png/fixtures/ch2n3p08.png create mode 100644 test/png/fixtures/cm0n0g04.png create mode 100644 test/png/fixtures/cm7n0g04.png create mode 100644 test/png/fixtures/cm9n0g04.png create mode 100644 test/png/fixtures/cs3n2c16.png create mode 100644 test/png/fixtures/cs3n3p08.png create mode 100644 test/png/fixtures/cs5n2c08.png create mode 100644 test/png/fixtures/cs5n3p08.png create mode 100644 test/png/fixtures/cs8n2c08.png create mode 100644 test/png/fixtures/cs8n3p08.png create mode 100644 test/png/fixtures/ct0n0g04.png create mode 100644 test/png/fixtures/ct1n0g04.png create mode 100644 test/png/fixtures/cten0g04.png create mode 100644 test/png/fixtures/ctfn0g04.png create mode 100644 test/png/fixtures/ctgn0g04.png create mode 100644 test/png/fixtures/cthn0g04.png create mode 100644 test/png/fixtures/ctjn0g04.png create mode 100644 test/png/fixtures/ctzn0g04.png create mode 100644 test/png/fixtures/exif2c08.png create mode 100644 test/png/fixtures/f00n0g08.png create mode 100644 test/png/fixtures/f00n2c08.png create mode 100644 test/png/fixtures/f01n0g08.png create mode 100644 test/png/fixtures/f01n2c08.png create mode 100644 test/png/fixtures/f02n0g08.png create mode 100644 test/png/fixtures/f02n2c08.png create mode 100644 test/png/fixtures/f03n0g08.png create mode 100644 test/png/fixtures/f03n2c08.png create mode 100644 test/png/fixtures/f04n0g08.png create mode 100644 test/png/fixtures/f04n2c08.png create mode 100644 test/png/fixtures/f99n0g04.png create mode 100644 test/png/fixtures/g03n0g16.png create mode 100644 test/png/fixtures/g03n2c08.png create mode 100644 test/png/fixtures/g03n3p04.png create mode 100644 test/png/fixtures/g04n0g16.png create mode 100644 test/png/fixtures/g04n2c08.png create mode 100644 test/png/fixtures/g04n3p04.png create mode 100644 test/png/fixtures/g05n0g16.png create mode 100644 test/png/fixtures/g05n2c08.png create mode 100644 test/png/fixtures/g05n3p04.png create mode 100644 test/png/fixtures/g07n0g16.png create mode 100644 test/png/fixtures/g07n2c08.png create mode 100644 test/png/fixtures/g07n3p04.png create mode 100644 test/png/fixtures/g10n0g16.png create mode 100644 test/png/fixtures/g10n2c08.png create mode 100644 test/png/fixtures/g10n3p04.png create mode 100644 test/png/fixtures/g25n0g16.png create mode 100644 test/png/fixtures/g25n2c08.png create mode 100644 test/png/fixtures/g25n3p04.png create mode 100644 test/png/fixtures/oi1n0g16.png create mode 100644 test/png/fixtures/oi1n2c16.png create mode 100644 test/png/fixtures/oi2n0g16.png create mode 100644 test/png/fixtures/oi2n2c16.png create mode 100644 test/png/fixtures/oi4n0g16.png create mode 100644 test/png/fixtures/oi4n2c16.png create mode 100644 test/png/fixtures/oi9n0g16.png create mode 100644 test/png/fixtures/oi9n2c16.png create mode 100644 test/png/fixtures/pp0n2c16.png create mode 100644 test/png/fixtures/pp0n6a08.png create mode 100644 test/png/fixtures/ps1n0g08.png create mode 100644 test/png/fixtures/ps1n2c16.png create mode 100644 test/png/fixtures/ps2n0g08.png create mode 100644 test/png/fixtures/ps2n2c16.png create mode 100644 test/png/fixtures/s01i3p01.png create mode 100644 test/png/fixtures/s01n3p01.png create mode 100644 test/png/fixtures/s02i3p01.png create mode 100644 test/png/fixtures/s02n3p01.png create mode 100644 test/png/fixtures/s03i3p01.png create mode 100644 test/png/fixtures/s03n3p01.png create mode 100644 test/png/fixtures/s04i3p01.png create mode 100644 test/png/fixtures/s04n3p01.png create mode 100644 test/png/fixtures/s05i3p02.png create mode 100644 test/png/fixtures/s05n3p02.png create mode 100644 test/png/fixtures/s06i3p02.png create mode 100644 test/png/fixtures/s06n3p02.png create mode 100644 test/png/fixtures/s07i3p02.png create mode 100644 test/png/fixtures/s07n3p02.png create mode 100644 test/png/fixtures/s08i3p02.png create mode 100644 test/png/fixtures/s08n3p02.png create mode 100644 test/png/fixtures/s09i3p02.png create mode 100644 test/png/fixtures/s09n3p02.png create mode 100644 test/png/fixtures/s32i3p04.png create mode 100644 test/png/fixtures/s32n3p04.png create mode 100644 test/png/fixtures/s33i3p04.png create mode 100644 test/png/fixtures/s33n3p04.png create mode 100644 test/png/fixtures/s34i3p04.png create mode 100644 test/png/fixtures/s34n3p04.png create mode 100644 test/png/fixtures/s35i3p04.png create mode 100644 test/png/fixtures/s35n3p04.png create mode 100644 test/png/fixtures/s36i3p04.png create mode 100644 test/png/fixtures/s36n3p04.png create mode 100644 test/png/fixtures/s37i3p04.png create mode 100644 test/png/fixtures/s37n3p04.png create mode 100644 test/png/fixtures/s38i3p04.png create mode 100644 test/png/fixtures/s38n3p04.png create mode 100644 test/png/fixtures/s39i3p04.png create mode 100644 test/png/fixtures/s39n3p04.png create mode 100644 test/png/fixtures/s40i3p04.png create mode 100644 test/png/fixtures/s40n3p04.png create mode 100644 test/png/fixtures/tbbn0g04.png create mode 100644 test/png/fixtures/tbbn2c16.png create mode 100644 test/png/fixtures/tbbn3p08.png create mode 100644 test/png/fixtures/tbgn2c16.png create mode 100644 test/png/fixtures/tbgn3p08.png create mode 100644 test/png/fixtures/tbrn2c08.png create mode 100644 test/png/fixtures/tbwn0g16.png create mode 100644 test/png/fixtures/tbwn3p08.png create mode 100644 test/png/fixtures/tbyn3p08.png create mode 100644 test/png/fixtures/tm3n3p02.png create mode 100644 test/png/fixtures/tp0n0g08.png create mode 100644 test/png/fixtures/tp0n2c08.png create mode 100644 test/png/fixtures/tp0n3p08.png create mode 100644 test/png/fixtures/tp1n3p08.png create mode 100644 test/png/fixtures/xc1n0g08.png create mode 100644 test/png/fixtures/xc9n2c08.png create mode 100644 test/png/fixtures/xcrn0g04.png create mode 100644 test/png/fixtures/xcsn0g01.png create mode 100644 test/png/fixtures/xd0n2c08.png create mode 100644 test/png/fixtures/xd3n2c08.png create mode 100644 test/png/fixtures/xd9n2c08.png create mode 100644 test/png/fixtures/xdtn0g01.png create mode 100644 test/png/fixtures/xhdn0g08.png create mode 100644 test/png/fixtures/xlfn0g04.png create mode 100644 test/png/fixtures/xs1n0g01.png create mode 100644 test/png/fixtures/xs2n0g01.png create mode 100644 test/png/fixtures/xs4n0g01.png create mode 100644 test/png/fixtures/xs7n0g01.png create mode 100644 test/png/fixtures/z00n2c08.png create mode 100644 test/png/fixtures/z03n2c08.png create mode 100644 test/png/fixtures/z06n2c08.png create mode 100644 test/png/fixtures/z09n2c08.png create mode 100644 test/png/parsePng.test.ts create mode 100644 types/png.d.ts diff --git a/public/common/bytes.js b/public/common/bytes.js new file mode 100644 index 0000000..7337a73 --- /dev/null +++ b/public/common/bytes.js @@ -0,0 +1,28 @@ +// @ts-check + +/** + * @param {Uint8Array} a + * @param {Uint8Array} b + * @returns {boolean} + */ +export const areBytesEqual = (a, b) => { + if (a.length !== b.length) return false; + for (let i = 0; i < a.length; i++) { + if (a[i] !== b[i]) return false; + } + return true; +}; + +/** + * @param {Uint8Array} bytes + * @param {number} size + * @returns {Uint8Array[]} + */ +export const chunkBytes = (bytes, size) => { + /** @type {Uint8Array[]} */ + const result = []; + for (let i = 0; i < bytes.byteLength; i += size) { + result.push(bytes.subarray(i, i + size)); + } + return result; +}; diff --git a/public/png/constants.js b/public/png/constants.js new file mode 100644 index 0000000..5f4ce5a --- /dev/null +++ b/public/png/constants.js @@ -0,0 +1,99 @@ +// @ts-check + +/** @enum {string} */ +export const PngNodeType = [ + "root", + "signature", + + "unknownChunk", + "chunkLength", + "chunkType", + "chunkData", + "chunkCrc", + + "ihdr", + "ihdrChunkData", + "ihdrWidth", + "ihdrHeight", + "ihdrBitDepth", + "ihdrColourType", + "ihdrCompressionMethod", + "ihdrFilterMethod", + "ihdrInterlaceMethod", + + "plte", + "plteChunkData", + "plteColor", + + "idat", + "idatChunkData", + + "iend", + "iendChunkLength", + + "trns", + + "chrm", + + "gama", + + "iccp", + + "sbit", + + "srgb", + + "cicp", + + "text", + "textData", + "textKeyword", + "textNullSeparator", + "textString", + + "ztxt", + "ztxtData", + "ztxtCompressionMethod", + "ztxtString", + + "itxt", + + "bkgd", + + "hist", + + "phys", + + "splt", + + "exif", + + "time", + + "actl", + + "fctl", + + "fdat", + + "offs", + + "pcal", + + "scal", + + "gifg", + + "gifx", + + "gift", + + "ster", + + "dsig", + + "idot", +].reduce((result, id) => { + result[id] = id; + return result; +}, Object.create(null)); diff --git a/public/png/crc32.js b/public/png/crc32.js new file mode 100644 index 0000000..37028be --- /dev/null +++ b/public/png/crc32.js @@ -0,0 +1,28 @@ +// @ts-check + +/** * @type {number[]} */ +const crcTable = []; +for (let i = 0; i < 256; i++) { + let b = i; + for (let j = 0; j < 8; j++) { + b = b & 1 ? 0xedb88320 ^ (b >>> 1) : b >>> 1; + } + crcTable[i] = b >>> 0; +} + +/** + * Compute the CRC32 checksum of some `Uint8Array`s. + * @param {Uint8Array[]} uint8arrays + * @returns {number} + */ +export default (...uint8arrays) => { + let crc = -1; + + for (const bytes of uint8arrays) { + for (let i = 0; i < bytes.length; i++) { + crc = crcTable[(crc ^ bytes[i]) & 0xff] ^ (crc >>> 8); + } + } + + return (crc ^ -1) >>> 0; +}; diff --git a/public/png/index.html b/public/png/index.html index 786effd..a83c846 100644 --- a/public/png/index.html +++ b/public/png/index.html @@ -11,7 +11,7 @@ - +