Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Apple Icon Image format

From Wikipedia, the free encyclopedia

Apple Icon Image
ICNS icon.
Filename extension
.icns
Internet media typeimage/x-icns
Type codeicns
Uniform Type Identifier (UTI)com.apple.icns
Magic number69 63 6e 73
Developed byApple Inc.
Type of formatIconfile format

TheApple Icon Image format (.icns) is anicon format used inApple Inc.'smacOS. It supports icons of 16 × 16, 32 × 32, 48 × 48, 128 × 128, 256 × 256, 512 × 512 points at 1x and 2x scale, with both1- and8-bitalpha 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 ofmacOS 11, asset catalogs are the preferred file format for macOS custom icons.[1]

File structure

[edit]

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

Header

[edit]
OffsetSizePurpose
04Magic literal, must be "icns" (0x69, 0x63, 0x6e, 0x73)
44Length of file, in bytes, msb first

Icon data

[edit]
OffsetSizePurpose
04Icon type, see OSType below.
44Length of data, in bytes (including type and length), msb first
8VariableIcon data

Icon types

[edit]
OSTypeLength (bytes)Size (pixels)Supported OS VersionDescription
ICON12832×321.01-bit mono icon
ICN#25632×326.01-bit mono icon with 1-bit mask
icm#4816×126.01 bit mono icon with 1-bit mask
icm49616×127.04 bit icon
icm819216×127.08 bit icon
ics#6416×166.01-bit mono icon with 1-bit mask
ics412816×167.04-bit icon
ics825616×167.08 bit icon
is32varies1 (768)16×168.524-bit RGB icon
s8mk25616×168.58-bit mask
icl451232×327.04-bit icon
icl8102432×327.08-bit icon
il32varies1 (3072)32×328.524-bit RGB icon
l8mk102432×328.58-bit mask
ich#57648×488.51-bit mono icon with 1-bit mask
ich4115248×488.54-bit icon
ich8230448×488.58-bit icon
ih32varies1 (6912)48×488.524-bit RGB icon
h8mk230448×488.58-bit mask
it32varies1 (49152 + 4)2128×12810.024-bit RGB icon
t8mk16384128×12810.08-bit mask
icp4varies16x1610.7JPEG 2000 orPNG format or 24-bit RGB icon[2]
icp5varies32x3210.7JPEG 2000 orPNG format or 24-bit RGB icon[2]
icp6varies48x4810.7JPEG 2000 orPNG format
ic07varies128x12810.7JPEG 2000 orPNG format
ic08varies256x25610.5JPEG 2000 orPNG format
ic09varies512x51210.5JPEG 2000 orPNG format
ic10varies1024x102410.7JPEG 2000 orPNG format (512x512@2x "retina" in 10.8)
ic11varies32x3210.8JPEG 2000 orPNG format (16x16@2x "retina")
ic12varies64x6410.8JPEG 2000 orPNG format (32x32@2x "retina")
ic13varies256x25610.8JPEG 2000 orPNG format (128x128@2x "retina")
ic14varies512x51210.8JPEG 2000 orPNG format (256x256@2x "retina")
ic04varies1 (1024)16x16ARGB orJPEG 2000 orPNG format
ic05varies1 (4096)32x32ARGB orJPEG 2000 orPNG format (16x16@2x "retina")
icsbvaries1 (1296)18x18ARGB orJPEG 2000 orPNG format
icsBvaries36x36JPEG 2000 orPNG format (18x18@2x "retina")
sb24varies24x24JPEG 2000 orPNG format
SB24varies48x48JPEG 2000 orPNG format (24x24@2x "retina")
  • 1. The value inside the parenthesis is the uncompressed length for ARGB and 24-bit RGB icons.
  • 2.it32 data always starts with a header of four zero-bytes (tested all icns files in macOS 10.15.7 and macOS 11). 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.app package.

Image data format

[edit]
  • 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 (seeCompression). Theit32 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 (seeCompression).

Compatibility

[edit]
  • 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 (tested on macOS 11).
  • 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 (see footnote on usage in app packages above).
  • The 24-bit RGB icons (is32,il32,ih32,it32) also allow images in JPEG 2000 and PNG format (tested on macOS 10.15.7 and macOS 11).
  • The support for newer image types seems to be introduced later than the key field (see previous two points). Therefore, the supported OS version may not be accurate or adjusted based on file format.

Other types

[edit]
OSTypeDescription
'TOC '"Table of Contents" a list of all image types in the file, and their sizes (added inMac 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.

'icnV'4-byte big endian float - equal to the bundle version number of Icon Composer.app that created the icon
'name'Usage unknown (all tested files use either "icon"[3] or "template"[4]).
'info'Info binaryplist. Usage unknown (only name field seems to be used).
'sbtp'Nested "template" icns file. Usage unknown.
'slct'Nested "selected" icns file. Usage unknown.
FD D9 2F A8Nested "dark" icns file. Allows automatic icon switching inDark mode. (added inmacOS 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.

  • The table of contents is a list of all contained types (4 byte type-name + 4 byte length).
  • 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 theicns header.

Non-PNG / JPEG2000 Element Types

[edit]

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).[5]

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 arenot 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

[edit]
lead
value
tail
bytes
result
uncompressed
  0...1271...1281...128 bytes
128...2551 byte3...130 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 (is32,il32,ih32,it32,icp4,icp5) and ARGB (ic04,ic05,icsb) pixel data are compressed (per channel) with a format similar toPackBits.[6]Some sources mention that the OS supports both compressed or uncompressed data chunks.[citation needed] 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 followingpseudocode decompresses the data:

While thereis compressed data:    Read one byteas anunsigned number NIf N < 0x80:        Output the next (N + 1) bytesElse:        Output the next byte (N - 0x80 + 3) times

Example:02 01 02 02 80 03 81 04 82 05 should decompress to01 02 02 03 03 03 04 04 04 04 05 05 05 05 05

The followingpseudocode compresses the data:

function Encode(input data)Initialize outputas anempty arraySet indexto 0While index< the count of dataInitialize sequenceas anempty arraySet countto 0// Unique sequenceWhile count 0x7Fand index< count of dataIf index + 2< count of dataand data[index]= data[index+1]and data[index]= data[index+2]Break theloop// Start of a repeating sequenceEndIfAppend data[index]to sequence      Increment index      Increment countEndWhileIf sequenceis not emptyAppend (count - 1)to outputAppend all itemsin sequenceto outputEndIfIf index count of dataBreak theloopEndIf// Repeating sequenceSet repeatedByteto data[index]Set countto 0While count 0x7Fand index dataand data[index]= repeatedByte      Increment index      Increment countEndWhileIf count 3Append (0x80 + count - 3)to outputAppend repeatedByteto outputElse// Less than 3 repeating bytesAppend (count - 1)to outputRepeat (count) timesAppend repeatedByteto outputEndRepeatEndIfEndWhileReturn outputEndfunction

Example:01 02 02 03 03 03 04 04 04 04 05 05 05 05 05 should compress to02 01 02 02 80 03 81 04 82 05

Known issues

[edit]

As of macOS 11, there are certain issues / bugs with the file format:

  1. Settingis32+ics8 orih32+ich8 will display a proper icon. But settingil32+icl8 ignores the transparency mask and displays an icon without transparency.
  2. Compressed ARGB data is not interpreted correctly. The last value of the blue channel (aka. the very last value) 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 (seeCompression). Potentially, up to 130 pixels can lack the blue channel value.
    A workaround is to append an additional byte at the end which is interpreted as a control character without following data. You can compare the difference with these two examples:
    • 69636E73 00000024 69633034 0000001C 41524742 FFFFFBFF FF00FB00 FF00FB00 FFFFFBFF
    • 69636E73 00000025 69633034 0000001D 41524742 FFFFFBFF FF00FB00 FF00FB00 FFFFFBFF 00
  3. macOS 10.15.7 (likely earlier) and later versions have an issue displaying PNG and JPEG 2000 icons for the keysicp4 (16x16),icp5 (32x32), andicp6 (64x64). 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 formatic04 andic05 (macOS 11+) or the old 24-bit RGB + alpha mask format. Use the latter with the old keysis32+s8mk andil32+l8mk, or with the newer keysicp4+s8mk andicp5+l8mk (writing RGB data into PNG fields[2]). 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. Theicp6 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

[edit]

Various apps can open*.icns files includingPreview andGTK+, with some offering the ability to convert*.icns to and fromPNG as well.[7][8][9] Former tools specializing in icon file support includeIcon Composer andicns Browser from Apple,IconBuilder fromThe Iconfactory, andCandyBar fromPanic.

MacOS offers the built-iniconutil command line tool to pack and unpack*.icns files.[10]

See also

[edit]

References

[edit]
  1. ^"Human Interface Guidelines". Apple Inc.Archived from the original on June 18, 2018. RetrievedApril 10, 2021.
  2. ^abcSystem icon: /System/Library/CoreServices/Applications/Screen Sharing.app/Contents/Resources/InternetLocationVNC.icns, macOS 11
  3. ^System icon: /System/Library/PrivateFrameworks/PassKitCore.framework/Versions/A/Resources/GenericIcon.icns, macOS 10.15.7
  4. ^System icon: /System/Library/PrivateFrameworks/ConsoleKit.framework/Versions/A/Resources/SidebariPhone.icns, macOS 10.15.7
  5. ^Fiahfy ICNS Repo
  6. ^Macintosh Icons
  7. ^"libicns".SourceForge project icns. 2009. RetrievedAugust 18, 2016.
  8. ^"png2icns". Moin Uddin. 2016. RetrievedMay 25, 2017.
  9. ^Lyonel Vincent (2007)."Mac OS X icons for GTK+". RetrievedAugust 18, 2016.
  10. ^"Optimizing for High Resolution".developer.apple.com. RetrievedMarch 22, 2025.

External links

[edit]
  • IconFamily (last update 2013) – Open source Objective C class to read and write Apple icns files
  • osxiconutils (not maintained) – Command line tools to work with Apple icns files
  • icnsutil – Python library to read and write icns files
  • icns - Rust crate to read and write icns files
  • createicns - C library to read and write icns files
  • icon_records_extractor - C library to extract all icns records as their own icons include dark mode icns.
Versions
Mac OS X
OS X
macOS
Predecessors
Applications
Core
applications
Developer
Tools
Xcode
Former
Former
Utilities
Discontinued
Technologies,
user interface
Deprecated
Discontinued
  • Italics denote upcoming products.
  •  Category
Raster
Raw
Vector
Compound
Metadata
Retrieved from "https://en.wikipedia.org/w/index.php?title=Apple_Icon_Image_format&oldid=1305033426"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp