Difference between revisions of "CgBI file format"

From iPhone Development Wiki
Jump to: navigation, search
(CgBI?!)
 
(Implementations: use xcrun so that the command isn't dependant on the xcode installation path)
Line 18: Line 18:
 
==Implementations==
 
==Implementations==
 
===Encoding===
 
===Encoding===
* Apple's modified pngcrush (<tt>/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush -iphone</tt>)
+
* Apple's modified pngcrush (<tt>xcrun -sdk iphoneos pngcrush -iphone</tt>)
 
* [http://github.com/DHowett/pincrush pincrush]
 
* [http://github.com/DHowett/pincrush pincrush]
 
===Decoding===
 
===Decoding===
* Apple's modified pngcrush (<tt>/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush -revert-iphone-optimizations</tt>)
+
* Apple's modified pngcrush (<tt>xcrun -sdk iphoneos pngcrush -revert-iphone-optimizations</tt>)
 
* [http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer ipin.py] ("iPhone PNG Image Normalizer")
 
* [http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer ipin.py] ("iPhone PNG Image Normalizer")
 +
 
==References==
 
==References==
 
<references/>
 
<references/>

Revision as of 10:24, 18 November 2013

The CgBI file format, thus named for its extra header, is Apple's proprietary extension to the PNG[1] image format.

Differences from PNG

These modifications cause the generated images to be invalid as per the current version of the PNG standard.

  • extra critical chunk (CgBI)
  • byteswapped (RGBA -> BGRA) pixel data, presumably for high-speed direct blitting to the framebuffer
  • zlib header, footer, and CRC removed from the IDAT chunk
  • premultiplied alpha (color' = color * alpha / 255)

To account for or apply these modifications, libpng needs to be patched to accept the "invalid" zlib compression window (a 15-bit window is the default, supplying -15 to zlib will cause it to omit headers/footers/CRC info).

CgBI Chunk

CgBI is a four-byte critical chunk added to the beginning of all "optimized" PNG files.

Known Contents

  • 0x50 0x00 0x20 0x06
  • 0x50 0x00 0x20 0x02 (seen if input image was already RGBA)

Implementations

Encoding

  • Apple's modified pngcrush (xcrun -sdk iphoneos pngcrush -iphone)
  • pincrush

Decoding

  • Apple's modified pngcrush (xcrun -sdk iphoneos pngcrush -revert-iphone-optimizations)
  • ipin.py ("iPhone PNG Image Normalizer")

References