Hi Alin,

I've written a PNG file decoder earlier this year. Here's how it works,

There is a small wrapper that has the signature, image size and some other details in it, including color depth and transparency.

You then have 'chunks' of either metedata, possibly a colour palette, and then the main data blocks - see Portable Network Graphics (PNG) Specification (Second Edition)

The data blocks consist of 'lines'. The first byte of the line tells you how this has been pre-filtered to help increase the redundancy in the pixel values, then pixel data for that line. See PNG Specification: Filter Algorithms

These lines are then compressed using LZSS compressed and Huffman coding, following the "deflate" standard detailed in in RFC1951 and RFC1950 - Deflate - Wikipedia and
The 'Deflate' algorithm uses either a fixed symbol dictionary or a custom dictionary. The custom dictionary is once again LZSS compressed and Huffman coded, using a smaller symbol set that can be optimized by the encoder.

So to read to read a PNG file you have to be
- Comfortable with reading 'chunked' data files
- Able to 'undo' the pixel filtering algorithms
- familiar with color palettes and transparency
- able to unpack binary data
- able to convert pixels between different color depths and formats (e.g. 4bpp to 24bpp)
- Able to decompress Huffman Codes
- Able to expand LZSS compression

It's a big project with lots of learning.