Apple Icon Image format


The Apple Icon Image format is the icon format used in Apple Inc.'s macOS. It supports icons of 16 × 16, 32 × 32, 48 × 48, 128 × 128, 256 × 256, 512 × 512 points at 1x and 2x scale, with both 1- and 8-bit alpha channels and multiple image states. The fixed-size icons can be scaled by the operating system and displayed at any intermediate size.

File structure

The file format consists of an 8 byte header, followed by any number of icons.

Header

Icon data

Compression

Over time the format has been improved and there is support for compression of some parts of the pixel data. The 32-bit and ARGB pixel data are often compressed with a format similar to PackBits.
Some sources mentioned that the OS supports both compressed or uncompressed data chunks.
The following pseudocode decompresses the data:

While there's compressed data:
Read one byte as an unsigned number N
If N < 0x80:
Output the next bytes
Else:
Output the next byte times

Example: should decompress to

Icon types

Support

Various image viewers can load *.icns files, and free and open source converters from or to PNG also exist. GTK+ can load *.icns resources since 2007. Other tools supporting the format include the Apple Icon Composer and icns Browser, The Iconfactory, and IconBuilder.
MacOS offers the built-in iconutil command line tool to pack and unpack *.icns files.