Apple Icon Image | |
Uniform Type: | com.apple.icns |
Owner: | Apple Inc. |
Genre: | Icon file format |
The Apple Icon Image format (.icns) 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 (example: open and closed folders). 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 instead.[1]
The file format consists of an 8 byte header, followed by any number of icons.
Offset | Size | Purpose | |
---|---|---|---|
0 | 4 | Magic literal, must be "icns" (0x69, 0x63, 0x6e, 0x73) | |
4 | 4 | Length of file, in bytes, msb first |
Offset | Size | Purpose | |
---|---|---|---|
0 | 4 | Icon type, see OSType below. | |
4 | 4 | Length of data, in bytes (including type and length), msb first | |
8 | Variable | Icon data |
OSType | Length (bytes) | Size (pixels) | Supported OS Version | Description | |
---|---|---|---|---|---|
128 | 32×32 | 1.0 | 1-bit mono icon | ||
256 | 32×32 | 6.0 | 1-bit mono icon with 1-bit mask | ||
48 | 16×12 | 6.0 | 1 bit mono icon with 1-bit mask | ||
96 | 16×12 | 7.0 | 4 bit icon | ||
192 | 16×12 | 7.0 | 8 bit icon | ||
64 | 16×16 | 6.0 | 1-bit mono icon with 1-bit mask | ||
128 | 16×16 | 7.0 | 4-bit icon | ||
256 | 16×16 | 7.0 | 8 bit icon | ||
varies (768) | 16×16 | 8.5 | 24-bit RGB icon | ||
256 | 16×16 | 8.5 | 8-bit mask | ||
512 | 32×32 | 7.0 | 4-bit icon | ||
1024 | 32×32 | 7.0 | 8-bit icon | ||
varies (3072) | 32×32 | 8.5 | 24-bit RGB icon | ||
1024 | 32×32 | 8.5 | 8-bit mask | ||
576 | 48×48 | 8.5 | 1-bit mono icon with 1-bit mask | ||
1152 | 48×48 | 8.5 | 4-bit icon | ||
2304 | 48×48 | 8.5 | 8-bit icon | ||
varies (6912) | 48×48 | 8.5 | 24-bit RGB icon | ||
2304 | 48×48 | 8.5 | 8-bit mask | ||
varies (49152 + 4) | 128×128 | 10.0 | 24-bit RGB icon | ||
16384 | 128×128 | 10.0 | 8-bit mask | ||
varies | 16x16 | 10.7 | JPEG 2000 or PNG format or 24-bit RGB icon | ||
varies | 32x32 | 10.7 | JPEG 2000 or PNG format or 24-bit RGB icon | ||
varies | 48x48 | 10.7 | JPEG 2000 or PNG format | ||
varies | 128x128 | 10.7 | JPEG 2000 or PNG format | ||
varies | 256x256 | 10.5 | JPEG 2000 or PNG format | ||
varies | 512x512 | 10.5 | JPEG 2000 or PNG format | ||
varies | 1024x1024 | 10.7 | JPEG 2000 or PNG format (512x512@2x "retina" in 10.8) | ||
varies | 32x32 | 10.8 | JPEG 2000 or PNG format (16x16@2x "retina") | ||
varies | 64x64 | 10.8 | JPEG 2000 or PNG format (32x32@2x "retina") | ||
varies | 256x256 | 10.8 | JPEG 2000 or PNG format (128x128@2x "retina") | ||
varies | 512x512 | 10.8 | JPEG 2000 or PNG format (256x256@2x "retina") | ||
varies (1024) | 16x16 | ARGB or JPEG 2000 or PNG format | |||
varies (4096) | 32x32 | ARGB or JPEG 2000 or PNG format (16x16@2x "retina") | |||
varies (1296) | 18x18 | ARGB or JPEG 2000 or PNG format | |||
varies | 36x36 | JPEG 2000 or PNG format (18x18@2x "retina") | |||
varies | 24x24 | JPEG 2000 or PNG format | |||
varies | 48x48 | JPEG 2000 or PNG format (24x24@2x "retina") |
OSType | Description | |
---|---|---|
"Table of Contents" a list of all image types in the file, and their sizes (added in Mac OS X 10.7).A TOC is written out as an identifier (4 bytes) and size (4 bytes). Each subsequent record (8 bytes each) mapsto the icon formats found in the file. The data isn't included in this phase. | ||
4-byte big endian float - equal to the bundle version number of Icon Composer.app that created the icon | ||
Usage unknown (all tested files use either "icon" or "template"). | ||
Info binary plist. Usage unknown (only name field seems to be used). | ||
Nested "template" icns file. Usage unknown. | ||
Nested "selected" icns file. Usage unknown. | ||
Nested "dark" icns file. Allows automatic icon switching in Dark mode. (added in macOS 10.14).Note: The contents of this record is a full .icns file with multiple formats. If the record bytes are written outto disk, the icns file header and file size are still required to see the full dark mode icon. |
Element types that deal with ARGB (32-bit) or RGB (24-bit) image formats require different types of headers before the binary data. It is important to note that this header is part of the image data and is not the 4-byte big endian icon element type value (e.g. ic04 or ic05).[2]
ARGB ElementsARGB 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 (e.g. ARGBARGBARGB), an image with three pixels would be stored in individual channels of pixel data (e.g. AAARRRGGGBBB). In addition, each channel of pixel data needs to be encoded as mentioned below.
RGB ElementsRGB 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 (e.g. RRRGGGBBB instead of RGBRGBRGB). Each channel must also be encoded as mentioned below.
Mask ElementsMask 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.
lead | tail | result |
---|---|---|
bytes | ||
byte | copies | |
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 (per channel) with a format similar to PackBits.[3] 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 (tested on macOS 11).
Here is a GitHub repo with some swift code that appears to pass the test for both encoding and decoding as described here: ByteRunLengthCoder
The following pseudocode decompresses the data:Example: should decompress to
The following pseudocode compresses the data:Example: should compress to
As of macOS 11, there are certain issues / bugs with the file format:
Various image viewers can load *.icns files, and free and open source converters from or to PNG also exist.[4] [5] GTK+ can load *.icns resources since 2007.[6] 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.