Introduction
The OS/2 icon is a black and white icon stored as a BMP file with the type code
IC. It holds one 1-bit bitmap twice the icon’s height, made of two masks
one above the other. Together the masks make each pixel black, white, transparent or
the inverse of whatever is behind it.
OS/2 icons are usually named .ico, but they are not the same format as a
Windows icon. An icon file often holds several sizes for
different screens, in which case it is a bitmap
array whose entries are IC or colour
icon images.
Structure
The file has the same parts as a bitmap. The DIB header describes a 1-bit image whose height is twice the icon’s height, and the colour table has two entries. All numbers are little-endian.
0File headerIC, size, hotspot and the offset of the pixels14 bytes14DIB header width, double height, 1 bit per pixel, in the 12-byte or OS/2 2.x layout12 to 64 bytes…Colour table two entries, black and white, of 3 or 4 bytes each6 or 8 bytes…Masks 1-bit rows padded to 4 bytes: first the XOR mask, then the AND maskvaries
File header
OS/2 gives the two reserved fields of the bitmap file header a use:
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 2 | char[2] | usType | The signature IC (49 43), the constant BFT_ICON. |
| 2 | 4 | u32 | cbSize | IBM defines this as the size of the header structure, the file header with the DIB header it holds. Some programs write something else, so readers should not depend on it. |
| 6 | 2 | i16 | xHotspot | The hotspot’s x position. It matters for pointers; icons usually leave it 0. |
| 8 | 2 | i16 | yHotspot | The hotspot’s y position. |
| 10 | 4 | u32 | offBits | The offset from the start of the file to the mask bits. |
How the masks combine
The file holds the XOR mask first and the AND mask second, each as 1-bit rows padded to 4 bytes and stored bottom row first. Since the bitmap is one picture of twice the icon’s height, drawn bottom-up, the AND mask appears above the XOR mask when it is shown as stored. Each pixel of the icon has one bit in the AND mask and one in the XOR mask. When the icon is drawn, the screen is ANDed with the AND mask and then XORed with the XOR mask:
| AND | XOR | Result |
|---|---|---|
0 | 0 | Black |
0 | 1 | White |
1 | 0 | Transparent: the screen shows through |
1 | 1 | The screen, inverted |
The explorer draws the icon this way, with inverted pixels shown in magenta, as they cannot be drawn without a screen behind them.
Which mask comes first
IBM’s documents describe the order in two ways that agree once the bitmap’s row order is taken into account. Presentation Manager bitmaps start at the lower-left corner: “the pel in the lower-left corner is the first in the bit map”, so the rows near the start of the data are the bottom of the picture.
- The Bitmap File Format page of the OS/2 Toolkit, in data order: “The first bitmap definition is the XOR mask … The second is the AND mask”.
- The Presentation Manager Programming Guide, in picture order: “The top half of the bit map is an AND mask” and “The lower half of the bit map is an XOR mask”. Its sentence that “the first half” defines the AND mask, also in WinCreatePointer, counts halves from the top in the same way.
- Working OS/2 code agrees: the OS/2 port of SDL builds the double-height bitmap it
passes to
WinCreatePointerwith the pointer’s image in the first half of the data and the AND mask in the second.
So the file holds the XOR mask first and the AND mask second, and the stored bitmap, drawn bottom-up, shows the AND mask above the XOR mask. David Charlap’s 1995 article in Dr. Dobb’s Journal puts the XOR mask in the top half, the one source found that reads the other way. No OS/2 icon file was available to check against, so this rests on the documents and the SDL code.
Telling it apart
The file starts with IC (49 43), and its DIB header gives 1
bit per pixel with a height twice the width. An OS/2
pointer is laid out the same way and differs only in its type code,
PT. A colour icon starts with
CI instead and has a second file header. A Windows .ico file
starts with 00 00 01 00.
Also used for
- Windows icon – Windows icons and cursors: one picture in several sizes, as bitmaps or PNGs.
Variants
- Windows bitmap (BM) – Windows 3.0 and later: a 40- to 124-byte header
- Windows 2 and OS/2 1.x bitmap (BM) – the first bitmaps, with a 12-byte header
- OS/2 2.x bitmap (BM) – a 16- to 64-byte header, with Huffman 1D and RLE24
- OS/2 bitmap array (BA) – several OS/2 bitmaps, icons or pointers for different screens, chained in one file
- OS/2 icon (IC) – a black and white OS/2 icon: AND and XOR masks in one 1-bit bitmap
- OS/2 colour icon (CI) – a colour OS/2 icon: a 1-bit mask bitmap followed by a colour image
- OS/2 pointer (PT) – a black and white OS/2 mouse pointer, with its hotspot in the header
- OS/2 colour pointer (CP) – a colour OS/2 mouse pointer: masks, a colour image and a hotspot