Lably
Skip to content

BMP file format

Windows Bitmap image file format family

  • 24 min read
  • 3 chapters

Related on Lably

Through Display device and Microsoft Windows

The BMP file format is capable of storing two-dimensional digital images in various color depths, and optionally with data compression, alpha channels, and color profiles.

The format's simplicity, its familiarity on Windows, and its status as a relatively well-documented, open format have made it very widely supported, so that image-processing programs on many operating systems can read and write BMP files. The same bitmap structure is embedded in related Windows formats: ICO and CUR files, for example, contain images that begin with a BITMAPINFOHEADER. Because uncompressed BMP files hold a great deal of redundant data, they can often be reduced substantially by general-purpose lossless compression such as ZIP or RAR.

The bitmap header structures were documented from the outset in Microsoft's general Windows and OS/2 programmer's references rather than in a specification dedicated to BMP alone; a formal specification of the same structures, using normative language, was only later folded into the Windows Metafile (WMF) specification, which Microsoft placed under its Open Specification Promise.

History

The bitmap formats associated with Microsoft Windows are among the oldest image formats on the IBM PC, having originated with the first release of Windows and evolved alongside it — and, for a time, alongside OS/2 — over the following decade. Because the format carries no field recording its header version, the successive variants are distinguished by the size of their header, and an application identifies a variant by reading the header-size field at the start of the bitmap header.

Windows 1.0 (1985) introduced only a simple device-dependent bitmap (DDB) — not yet the device-independent, DIB-based file format described in this article — highly dependent on the output device for which it was created, so a bitmap suited to one display was not necessarily usable on another. A program created such a bitmap through handle-based GDI calls and loaded it from a module's resources; the BITMAP structure recorded only its width, height, plane count and bits-per-pixel, and the raw bits followed in the device's own format, with no color table of its own.

While these early versions of Windows were being developed, Microsoft shared responsibility with IBM for the first releases of OS/2, whose Presentation Manager graphical interface used a closely related bitmap format. According to the Encyclopedia of Graphics File Formats, support for a programmable color palette was added to both Windows and BMP as Windows 2.x (1987) was being developed, making its DIB format identical to that of OS/2 1.1 (1988). This device-independent bitmap (DIB) emerged from that joint work, and sources differ over which side originated it — and even over when it reached Windows. The Encyclopedia credits Windows itself, with Presentation Manager adopting the format afterward. Other accounts instead trace the DIB to OS/2: Charles Petzold writes that the DIB "is new in Windows 3" and "an extension of the bitmap format supported in the OS/2 1.1 Presentation Manager", and a 1990 BYTE column reported that "DIBs first surfaced in OS/2 1.1 as the Graphics Programming Interface bit map". Raymond Chen, a longtime Microsoft engineer, dates this earlier, to Windows 2.0, stating that "Windows 2.0 adopted OS/2's bitmap format in order to foster interoperability" between the two systems.

That early format used a 12-byte information header — later named BITMAPCOREHEADER — whose leading size field was required to be 12. IBM's own documentation, and that same Microsoft reference, instead name this OS/2 header BITMAPINFOHEADER — the same name Microsoft later gave the unrelated 40-byte structure below. To avoid that collision, some secondary sources instead call the OS/2 1.x and 2.x headers OS21XBITMAPHEADER and OS22XBITMAPHEADER; this article uses IBM's own names for them.

Windows 3.0 (1990) carried the device-independent bitmap forward in the form still dominant today, built around a new 40-byte BITMAPINFOHEADER, which superseded the earlier 12-byte header. When written to disk with a BITMAPFILEHEADER, this became the basis of the modern BMP file format. The release also added run-length encoding for 4- and 8-bit-per-pixel (bpp) images (BI_RLE4 and BI_RLE8), and still accepted the older 12-byte header, which it documented as a BITMAPCOREHEADER "compatible with … OS/2 Presentation Manager versions 1.1 and 1.2".

OS/2 2.0 (1992) then extended its version independently. The 64-byte BITMAPINFOHEADER2 widened the dimensions to 32 bits and added 24-bit RLE compression and Huffman 1D compression for bi-level images. OS/2 also defined a bitmap-array container — identified by the BA signature and holding images tagged BM, IC, PT, CI or CP — that could bundle several device-dependent and device-independent renderings of a bitmap, icon or pointer in a single file, the device-independent version first. As the two companies' operating-system efforts diverged, the Windows and OS/2 formats grew steadily further apart.

Windows NT (1993) introduced support for using BI_BITFIELDS with 16- and 32-bpp DIBs, with the color masks following the 40-byte header instead of a color table. Two further, historically undocumented header variants of 52 and 56 bytes, which fold those RGB masks (and an alpha mask) into the header itself, are also encountered (described below).

Windows 95 (1995) introduced the 108-byte BITMAPV4HEADER, later also supported by Windows NT 4.0 (1996), which added an explicit alpha-channel mask together with a color-space identifier, CIE color endpoints and per-channel gamma values, allowing Image Color Matching information to travel with the bitmap. Windows 98 (1998) followed with the 124-byte BITMAPV5HEADER, later also supported by Windows 2000 (1999), which can embed or link an ICC color profile.

Independently of this header-borne alpha mask (see below), the alpha-blending functions available in Windows 2000 and later could take a per-pixel alpha value directly from a 32-bit BI_RGB image, with no color mask involved.

Rather than being defined in a single specification dedicated to BMP, the format's structures were documented release by release inside the general Windows and OS/2 programmer's references, header files and online help. The later Windows Metafile specification was the first to define these structures formally, in normative language.

Sign in to keep reading

2 more chapters are free with a Lably account.

More in Computing and communication