peperzaken / iPhone-optimized-PNG-reverse-script

Using only PHP we reverse the iPhone optimalisation Apple's build process does on packing the .app file
http://peperzaken.nl/1326/iphone-optimized-png-reverse-script-in-php
5 stars 2 forks source link

cannot handle multiple IDAT chunks #2

Open auntieyi opened 12 years ago

auntieyi commented 12 years ago

cannot handle multiple IDAT chunks

zout commented 12 years ago

You are right, we haven't encountered them yet as we use this script for icons only that are created with the safe for web option.

Can you provide the file that had multiple IDAT chunks? I's try to fix it

yarrmateys commented 12 years ago

i also recently stumbled on pngs with multiple idats, and was stumped for a while about why does it only show half of the image until pngcrush told me it has multiple idats and extra compressed data. all existing converter tools only fixed the first chunk.

anyway, here's a sample of iphone optimized png with 2 idat chunks. so far 2 chunks is all i saw. https://dl.dropbox.com/u/62600417/sample_2_idat.png

postypython commented 12 years ago

Dear peperzaken, I've just solved this issue (only half of an image being shown instead of the whole image). This problems is due to the fact that while you must decompress separately each IDAT chunk from the original crushed png, you shall compress them togheter while creating the uncrushed png file (that is you have to concatenate all IDAT uncompressed chunks and then compress them all). After that you can split again each IDAT chunk (whose lenght is arbitrary as per official png specification). By the way, I found uncessary swapping color data (RGBA) and moreover that php gzinflate works well to decompress original IDAT chunks (no external classes required then). I can provide you my source code if you need it. Cheers

Edit: Actually swapping colors can be useful.

CheloXL commented 12 years ago

I have samples with more than 2 chunks (on the new iPad, PNGs can have up to 8 chunks) if you need them...

postypython commented 12 years ago

Hi CheloXL, The following should work with multiple idat chunks: https://github.com/postypython/pnguncrush It is obviously a rewriting of peperzaken's script.

albeebe commented 12 years ago

This PNG does not decode properly using this code, nor does it decode properly with pnguncrush

http://ipashare.com/uploads/icon.png