CgBI file format

From iPhone Development Wiki

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)

At least the lower parts of the content correspond to the documented CGBitmapInfo bitmask.



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


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