Apple Icon Image format
The Apple Icon Image format is an 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.
As of macOS 11, asset catalogs are the preferred file format for macOS custom icons.
File structure
The file format consists of an 8 byte header, followed by any number of icons.Header
Icon data
Icon types
- The value inside the parenthesis is the uncompressed length for ARGB and 24-bit RGB icons.
- data always starts with a header of four zero-bytes. Usage unknown, the four zero-bytes can be any value and are quietly ignored.
- These formats are supported in standalone icns files but do not display properly if used as application icon inside a package.
Image data format
- Mono icons with alpha mask can display three colors: white, black, and transparent.
- The 4-bit an 8-bit icons use a fixed color palette with 16 colors and 256 colors, respectively.
- The 24-bit RGB format consists of the three compressed channels tightly packed. The icon must start with a four-byte header, see footnote above.
- The ARGB format consists of the ascii values for 'ARGB' and the four compressed channels tightly packed.
Compatibility
- the ARGB fields also accept files in PNG format – but not vice versa, you can not put ARGB images in any of the PNG-only fields.
- ARGB images are only supported in macOS 11 and newer – macOS 10.15.7 does not display ARGB images. Yet, even the ARGB keys can be displayed on macOS 10.15 if you set a JPEG 2000 or PNG image.
- The 24-bit RGB icons also allow images in JPEG 2000 and PNG format.
- The support for newer image types seems to be introduced later than the key field. Therefore, the supported OS version may not be accurate or adjusted based on file format.
Other types
- The table of contents is a list of all contained types.
- The data for all nested icns files does not contain the icns file-header. So, if you want to save the data to a file you have to prepend the [|icns header].
Non-PNG / JPEG2000 Element Types
ARGB Elements
ARGB images must have their binary portion of the image data preceded by the four byte 'ARGB' header. After that, instead of each pixel with each of its four channels stored together, an image with three pixels would be stored in individual channels of pixel data. In addition, each channel of pixel data needs to be encoded as mentioned below.
RGB Elements
RGB images have their binary portion of the image data preceded by four zero byte characters only when the element type is 'it32'. In all other cases, no header is needed. Channel data is separated as with the ARGB binary data. Each channel must also be encoded as mentioned below.
Mask Elements
Mask elements are not encoded like ARGB and RGB image color channel data. The data is the same as that of an ARGB image except only the alpha channel data is provided. So for an image that has two pixels, ARGBARGB, the mask data is AA.
Compression
Over time the format has been improved and there is support for compression of some parts of the pixel data. The 24-bit RGB and ARGB pixel data are compressed with a format similar to PackBits.Some sources mention that the OS supports both compressed or uncompressed data chunks. However, manually crafting icns files with uncompressed 24-bit RGB or ARGB images will not display properly – at least on newer macOS releases.
Here is a GitHub repo with some swift code that appears to pass the test for both encoding and decoding as described here:
The following pseudocode decompresses the data:
Example: should decompress to
The following pseudocode compresses the data:
Example: should compress to
Known issues
As of macOS 11, there are certain issues / bugs with the file format:- Setting or will display a proper icon. But setting ignores the transparency mask and displays an icon without transparency.
- Compressed ARGB data is not interpreted correctly. The last value of the blue channel is ignored and treated as if it were all zero-bytes. Usually this is no issue since most icons will have transparency at the bottom right corner anyway. However, it can become an issue if the last value is a repeating byte. Potentially, up to 130 pixels can lack the blue channel value.
- *
- *
- macOS 10.15.7 and later versions have an issue displaying PNG and JPEG 2000 icons for the keys , , and . The keys work fine in a standalone icns file but if used in an application, the icons are displayed completely scrambled. Either use the new ARGB format and or the old 24-bit RGB + alpha mask format. Use the latter with the old keys and, or with the newer keys and . If using ARGB image data, make sure to provide alternative formats for macOS 10.15 and earlier. This issue is especially tricky to detect if you provide both, 16x16 and 16x16@2x icons, because if you connect your Mac to a non-retina monitor, the non-retina 16x16 icon will be used and thus the icon will be displayed scrambled. The field does not seem to be used in application icons and can safely be ignored. Additionally, if you don't provide the smaller icon sizes at all the bug will also manifest when the OS scales down your larger PNG/JPEG 2000 icons, so make sure to render smaller sizes and include them.
Support
MacOS offers the built-in
iconutil command line tool to pack and unpack *.icns files.