HomeStoreForumsWikiiPhone Native AppsiPhone Apps modmyifone Downloadsmodmyifone Links
  •  




  • Go Back   iPhone Forums at ModMyiFone.com - iPhone | iPod Touch, news, apps, themes. > ModMyiFone - Wiki
    Register FAQ Members List READ THIS Today's Posts Mark Forums Read


    MMi Super Contest | 30 winners! Over $1500 in Prizes! Enter Today!

    Discuss AppStore Apps! | MMi Cydia Repo Download Stats

    Get more out of ModMyiFone by joining our free community. By registering you get privileges to download files from our downloads section and you may also post your questions in our forums! It's fast, free, and easy!

    2.0 Unlock|Jailbreak OS X / Windows | iPhone 3G Detailed Review w/Pics! | Developers - Port Your Apps to 2.0
    Personal tools

    Iphone PNG images

    From ModMyiFone - Wiki

    Contents

    Background

    The 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.

    Discussion

    The 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 0x40, 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:

    1. Remove the 'CgBl' chunk
    2. Decompress the data using zlib with the windowSize set to a negative number
    3. Swap the red pixel with the blue pixel in the data
    4. Recompress the data using zlib using the default headers and CRC
    5. Replace the image data chunk with the new compressed data in the PNG, and create a new checksum

    Code

    Conversion 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.

    LIBS=-lz -lpng12
    LIBPATH=-L/sw/lib
    CC=gcc
    CFLAGS=-I/sw/include
    all: fixpng
    clean:
    	rm fixpng png
    fixpng: fixpng.c
    	$(CC) $(CFLAGS) -o fixpng fixpng.c $(LIBPATH) $(LIBS)
    	$(CC) $(CFLAGS) -o png png.c $(LIBPATH) $(LIBS)
    

    SOURCE LINK

    Alternative Code

    To 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/

    ModMyMoto.com - ModMyGPhone.com - ModMyiFone.com - Dedicated Server Hosting by SingleHop - iPhone Wallpapers - iPhone forums | iPod touch forums, news, themes, apps, games, unlock, jailbreak community - ModMyiFone.com RSS Feeds - Contact Us - Link to us - Archive - Privacy Statement - - Top
    Copyright © 2007-08 by ModMy, LLC. All rights reserved. You may not copy anything on this site unless you link to the original.
    All times are GMT -6. The time now is 06:35 AM. Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
    Powered by vbWiki Pro 1.3 RC4. Copyright ©2006-2007, NuHit, LLC

    ModMyiFone.com is an independent publication and has not been authorized, sponsored, or otherwise approved by Apple, Inc or Cisco Systems, Inc. The information contained on this site is for educational purposes only.
    Forum skin by poetic_folly