Introduction
ICO is the icon format of Microsoft
Windows. One file holds the same picture at several sizes and colour depths, such as
16, 32, 48 and 256 pixels square, and Windows picks the best match for where the icon is
shown. Web sites use it for favicon.ico, the small icon in a browser
tab.
Mouse cursors use the same layout with the extension .cur; their
directory entries give the hotspot, the point that
clicks. Since Windows Vista, each image in the file can be a complete
PNG as well as the older bitmap form.
Structure
An ICO file starts with a 6-byte header: two zero bytes, the type (1 for an icon, 2 for a cursor) and the number of images, all little-endian. A 16-byte directory entry for each image follows, giving its width and height (0 meaning 256), colour count, planes and bit count (or the hotspot in a cursor), its size in bytes and its offset in the file. The header and directory page gives every field and value.
Each image is either a PNG file or a device independent bitmap like those in BMP files, starting at the BITMAPINFOHEADER with no file header. In the bitmap form the stated height is doubled, because the XOR bitmap, which holds the colours, is followed by a 1-bit AND mask of the same size. The two together decide what each pixel does to the screen: replace it, leave it alone or invert it.
0Header reserved, type, image count6 bytes6Directory one entry per image: size, colours, bytes, offset16 bytes each…Images each a PNG, or a bitmap with its AND maskvaries
Reference pages
- Header and directory – ICONDIR and ICONDIRENTRY, field by field, and the resource form used in programs
- Bitmap images – the DIB header, colour table, XOR bitmap and AND mask, with row padding and valid depths
- AND and XOR masks – how the pixels combine, including inverted pixels and 32-bit alpha
- PNG images – how a PNG image is told apart and what it leaves out
- Cursors – the hotspot and how a .cur file differs from an icon
Also used for
- OS/2 bitmap array (BA) – Several OS/2 bitmaps, icons or pointers for different screens, chained in one file.
- OS/2 colour icon (CI) – A colour OS/2 icon: a 1-bit mask bitmap followed by a colour image.
- OS/2 icon (IC) – A black and white OS/2 icon: AND and XOR masks in one 1-bit bitmap.
Links
Software
- GIMP – free image editor that opens and saves ICO (Windows, macOS, Linux)
- IcoFX – icon editor that creates and edits ICO files (Windows)
- IrfanView – image viewer and converter (Windows)
- XnView MP – image viewer and converter (Windows, macOS, Linux)
- ImageMagick – command-line tool that converts images to and from ICO (Windows, macOS, Linux)
- Photopea – image editor that runs in the browser (web browser)
Developers
- Pillow – imaging library that reads and writes ICO (Python)
Reference
- Icons – Microsoft’s article on the format, with the ICONDIR, ICONDIRENTRY and ICONIMAGE structures
- The evolution of the ICO file format – Raymond Chen’s series on the monochrome, colour, alpha and PNG forms
- ICO (file format) – Wikipedia’s technical summary