Calculate the ADLER32 checksum of a section of a buffer. Code largely taken from: https://github.com/SheetJS/js-adler32
Calculate the length of an IDAT chunk. Because it uses both ZLib chunking and a row filter byte at the start of each row, it isn't as simple as width * height.
PNG files can have palettes of varying sizes, up to 256 colors. If we want to try to save some space, we can use a smaller palette.
Zlibbed data takes up more space than the raw data itself - we aren't compressing it but we do need to add block headers and the like.
Make sure that we're dealing with a PNG file. Throws an error if the file does not start with the standard PNG header.
Calculate the CRC value of a selected slice of an ArrayBuffer. Code from: https://github.com/alexgorbatchev/node-crc/blob/master/src/crc32.js
Create a PngPong-suitable PNG ArrayBuffer from an existing RGBA array. Combine this with PNGJS to transform an existing PNG image into something PngPong can use.
How many extra palette entries should we make available for new colors, after we've added the colors from the existing array?
Create a PngPong-suitable ArrayBuffer based on the arguments provided.
Must be at least 1, and at least 2 if specifying a background color.
Quick function to convert from Base64, works in both Node and browser.
Read out the values contained within IHDR. Does not let you edit these values, as changing pretty much any of them would make the IDAT chunk totally invalid.
Take an ArrayWalker and parse out the PLTE chunk and, if it exists, the tRNS chunk. If it exists, the tRNS chunk MUST immediately follow the PLTE chunk.
Utility function to parse out a Zlib-encoded block (at a compression level of 0 only). Will skip over Zlib headers and block markers, and call the dataCallback repeatedly when actual data is available.
Quick function to convert a string to Base64, that works in both Node and the browser
Write an IDAT chunk all at once. Typically used when creating a new blank image.
Write an IDAT chunk without wasting memory on a source ArrayBuffer - if we want it all to be one palette index.
The palette index we want all the pixels to be
There is no actual content in an IEND chunk, just the identifier and CRC.
Write both the PLTE and tRNS chunks of the PNG file.
PNG files have a very basic header that identifies the PNG file as... a PNG file. We need to write that out.
Generated using TypeDoc
IHDR length is always 13 bytes. So we can store this as a constant.