Personal tools
ViewsIphone PNG imagesFrom ModMyi - Wiki
[edit] BackgroundThe PNG images found on the iPhone cannot be viewed by a standard image viewer. Apple, for some unknown reason, implemented a non-standard PNG format that includes an extra data before the PNG header and compressed image data without the traditional headers and footers. In addition, the red blue pixels are flipped (BGRA instead of RGBA). All iPhone PNG images appear to follow this format. [edit] DiscussionThe PNG format consists of a header, followed by a set of data atoms, or chunks. According to the PNG spec, the 'IHDR', or PNG header chunk, should always come first. In Apple's iPhone format, a 'CgBI' chunk appears before the header. This chunk's data is four bytes long and contains a value of 0x30, or 48 decimal and is marked mandatory and private, which means that the data contained in the 'CgBL' chunk a third party extension to the PNG format that must be implemented by the parser. The purpose of this chunk, other than to signify that the PNG in iPhone format, is unknown. It could be a format version identifier. Compressed image data, stored in the 'IDAT' chunk, contains deflate compressed data without the zlib headers, footers, or checksums that normal PNGs contain. When using zlib to decompress data, a negative value must be passed as the windowSize to use zlib's undocumented 'skip headers and crc' feature. There does not appear to be a good technical reason for using this format instead of the standard. For some reason, the red and blue pixels are reversed in the deflated data. This could be an optimization to prevent the iPhone from having to do a pixel swap before writing the image to the screen buffer. To convert an iPhone PNG to a standard PNG:
[edit] CodeConversion code for both purposes may be retrieved using anonymous svn from svn://svn.poop.nl/pub/iphone-fixpng (guaranteed to be the most-recent), or using the tarball at http://www.poop.nl/files/iphone-fixpng.tgz, whichever you prefer. Tested using the iPhone wallpaper images (/Library/Wallpaper) on both Intel and PowerPC Macs with OSX. The Makefile in SVN now compiles for both ppc and x86. You'll need zlib for fixpng.c and libpng for flipchannels.c if you don't have libpng installed, a nice universal installer can be found here: http://ethan.tira-thompson.com/Mac%20OS%20X%20Ports.html Once you have libpng installed, cd to the directory where fixpng is and type "make" Here is an alternative Makefile for building on darwin. It assumes that fink is installed with the libpng package whereas the included Makefile assumes a binary installation into /usr/local. ZLib is included with MacOS X.
You only need to make a small modification to be able to compile the code on Linux, here is the Makefile that I've tested on Kubuntu GNU/Linux 7.10, you'll need to have the libpng package installed, the zlib package is automatically installed.
[edit] Alternative CodeTo normalize downloaded PNG files from the iPhone and iPod touch you can download and use this python script at: http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer (multiplatform) This script is recommended for Windows users that cannot use the iphone-fixpng. To normalize PNG online, you can use at : http://zope.release78.org/beta2/iconvert/ atPurpose (http://www.atpurpose.com) have created 2 QuickLook plugins for Mac OS X that can preview PNG crushed images and PVR textures right from the Finder. They can be downloaded here http://atpeek.download.atpurpose.com/PngUncrush.zip and here http://atpeek.download.atpurpose.com/PvrUncrush.zip |





