CgBI file format
This document was extracted from a backup of iPhoneDevWiki on 2026-11-30.
The CgBI file format, thus named for its extra header, is Apple’s proprietary extension to the PNG1 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 0x060x50 0x00 0x20 0x02(seen if input image was already RGBA)
At least the lower parts of the content correspond to the documented CGBitmapInfo bitmask.
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”, archived 2026-01-17)