For pngopti I need a tool which just removes chunks I supply on the command-line. Pngout recompresses everthing and is not included by default. Pngcrush also recompresses the IDAT. So I decided to write my own code and succeeded in a quite short amount of time. The file is checked by pngcheck before, so we can be quite sure it's valid. Then I go for the fixed position where IHDR should be. I check wether the chunk name consists of the bytes 65 - 90 || 97 - 122. Then I parse the length and forward to the next header and so on. For each header the position and the length are saved. Is this procedure sufficient? Or do I have to check the CRC?
counting_pine at
Re: How to scan structure of PNG
You shouldn't need a CRC check. pngcheck should catch anything that would be basic enough to cause problems doing simple operations on the PNG structure, so you should be able to assume that the header is OK, that the chunk names, lengths and CRCs are OK, and that the file ends where it's supposed to. Simple checks like that would only really be necessary for your own piece of mind, or if you want to provide it for use as a standalone tool.
In either case, the CRCs don't need to be correct for you to remove chunks, and the CRCs of the remaining chunks won't be affected, so if you want you could leave the CRCs (whether valid or not) for another tool to check. I'd say the same for chunk names too, except that checking them is considerably easier to do.