BMP

BMP is a family of raster image file formats primarily used on Microsoft Windows and OS/2 operating systems. The format is sometimes known as Device-Independent Bitmap (DIB), since, when loaded into memory using Windows software, the image is held as a DIB structure.

Though seemingly a simple format, it is complicated by its many different versions, lack of an official specification, lack of any version control process, and ambiguities and contradictions in the documentation.

Discussion
The term DIB can mean several different things:
 * A synonym for BMP file format.
 * An in-memory DIB object, with no file header. The header data and the bitmap data do not have to be stored contiguously. Some Win32 API functions use this format.
 * A "packed DIB" memory object or file component, with no file header. The header data and the bitmap data are stored contiguously. This is a standard clipboard format, for example.
 * A "packed DIB" stored in a file by itself.

A number of Windows-centric formats contain some nonstandard modified or compressed form of BMP/DIB, intended to be reconstructed as a DIB at runtime.

Compression
Images are usually uncompressed, but RLE compression can be used under some conditions. JPEG, PNG, and Huffman 1D compression are also theoretically possible, but rarely supported.

File structure
A BMP file starts with a 14-byte "BITMAPFILEHEADER" structure.

Immediately after that is another header which we'll refer to as the "info header", though some versions of it are named "core header" instead. There are a number of different versions and sub-versions of it. It starts with 4-byte integer indicating its size, which mostly reveals its version.

The pixel data is pointed to by a field in BITMAPFILEHEADER. There can be other data segments, e.g. for a color palette, before (and, rarely, after) the pixel data.

Pixel data is usually stored from bottom up (but is top-down if the header indicates a negative height). If uncompressed, each row is padded to a multiple of 4 bytes.

Identifiers
No MIME type has been officially registered. Strings found in practice are: image/bmp; image/x-bmp; image/x-ms-bmp

The usual filename extension is .bmp. Extensions .rle (for RLE-compressed images) and .dib (which sometimes indicates that the file lacks a file header) are also sometimes seen. Many other extensions have been used by various applications.

Identification
BMP files start with the ASCII signature "".

The bytes at the beginning of the file match one of these two patterns:

42 4d ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 0c 00 00 00 ?? ?? ?? ?? 01 00 ?? 00

or

42 4d ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 ?? 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? 01 00 ?? 00

The "reserved" bytes at offset 6 to 9 are usually all zero, but a few OS/2 BMP files have nonzero "hotspot coordinates" there.

Compare to VBM (VDC BitMap), an obscure format with a similar signature.

Windows BMP v2

 * Info header size: 12
 * Info header name: BITMAPCOREHEADER
 * PRONOM:

See also OS/2 BMP 1.0, below.

Windows BMP v3

 * Info header size: 40
 * Info header name: BITMAPINFOHEADER
 * PRONOM: ,

This is by far the most widely used version of BMP. It was introduced with Windows 3.x. Windows NT extended it to support 16 and 32 bits/pixel.

Windows CE also extended it, for example to allow 2 bits/pixel (see Pocket PC Bitmap), but its extensions were not migrated to the BMP v4 and v5 formats.

Microsoft's GDI+ reportedly supports BMP images with 64 bits/pixel, but no technical documentation of this extension has been located.

It is apparently possible for OS/2 BMP 2.0 format to masquerade as Windows BMP v3. The upshot is that if the compression type is 3 and the bit depth is 1, or the compression type is 4 and the bit depth is 24, then the file should be treated as OS/2 BMP 2.0.

Windows BMP v4

 * Info header size: 108
 * Info header name: BITMAPV4HEADER
 * PRONOM:

Introduced with Windows 95. Adds support for transparency and colorimetry.

Windows BMP v5

 * Info header size: 124
 * Info header name: BITMAPV5HEADER
 * PRONOM:

Introduced with Windows 98. Adds support for ICC profiles.

Windows BMP v1

 * PRONOM:

Also called DDB, this is the bitmap file format used by Windows 1.0. It's not really a BMP format. Refer to Windows DDB.

OS/2 BMP 1.0

 * See also the OS/2 BMP disambiguation page.


 * Info header size: 12
 * Info header name: BITMAPCOREHEADER or OS21XBITMAPHEADER
 * PRONOM: (deprecated),

For practical purposes, OS/2 BMP 1.0 is identical to Windows BMP v2. But there can be at least one small difference: In OS/2 formats, the "Size" field at offset 2 (variously named "cbSize", "FileSize", or "bfSize") is sometimes set to the size of the headers, instead of the size of the file. For v1, that means it will be 26 (14+12). For v2, it can range from 30 to 78.

OS/2 BMP 2.0

 * Info header size: 16–64 (16, 24, 40, 48, and 64 may be most common)
 * Info header name: BITMAPCOREHEADER2 or OS22XBITMAPHEADER
 * PRONOM:

OS/2 BMP 2.0 defines several file subtypes; here we are describing only the "Bitmap" subtype (files with a signature of "BM"). For other subtypes, see OS/2 bitmap family.

The header size can be reduced from its full size of 64 bytes. Omitted fields are assumed to have a value of zero.

The fields in the first 40 bytes of the header are (nearly) identical to those in Windows BMP v3, v4, and v5. The remaining fields are different.

OS/2 BMP 2.0 supports compression types "Huffman 1D" and "RLE24", unlike any other version of BMP.

BITMAPV2INFOHEADER

 * Info header size: 52
 * Info header name: BITMAPV2INFOHEADER

Uncertain; possibly an abbreviated V4/V5 header.

BITMAPV3INFOHEADER

 * Info header size: 56
 * Info header name: BITMAPV3INFOHEADER

Uncertain; possibly an abbreviated V4/V5 header.

Packed DIB file
Same as the common BMP formats, but omits the 14-byte file header.

OS/2 Bitmap Array
Sometimes, an OS/2 Bitmap Array file containing one or more bitmaps is considered to be a kind of BMP file. Such a file begins with an extra 14-byte header, with signature " ". (But note that deleting this header is not quite enough to get a valid BMP file.)

Symbol definitions
Here are the definitions, from the Windows SDKs, of some of the symbols used in the BMP documentation.

All integers use little-endian byte order.

Specifications

 * Most of the format (but not the BITMAPFILEHEADER) is defined in the Windows Metafile Specification (as "DeviceIndependentBitmap")
 * Defined in the RIFF specification (as Device Independent Bitmap File Format)
 * BITMAPFILEHEADER
 * BITMAPCOREHEADER
 * BITMAPINFOHEADER
 * BITMAPINFOHEADER (Windows CE 5.0)
 * BITMAPV4HEADER
 * BITMAPV5HEADER
 * Another site with format descriptions
 * OS/2 Presentation Manager Programming Reference Guide, Vol III
 * Specification of BMP headers
 * BMP format information by T. Schultz

Software
BMP is widely supported by graphics software, including web browsers. Software listed here has been arbitrarily selected.
 * Netpbm: bmptopnm, ppmtobmp
 * ImageMagick
 * XnView
 * Tom's Viewer

Windows BMP v2
This format is fairly common, but examples of it can be hard to spot amidst all the BMPv3 files.
 * money-2-(os2).bmp, money-16-(os2).bmp, money-256-(os2).bmp, money-24bit-os2.bmp
 * → BMPS*.ZIP, OS2ORBIT.ZIP, REALMERL.BMP

OS/2 BMP 2.0

 * teamlog2.zip → TEAMcol.bmp, teamcol2.bmp
 * test4os2v2.bmp
 * - Most of the files are OS/2 BMP 2.0
 * - Some of the files are files OS/2 BMP 2.0
 * → os2bmp*.zip
 * → os2bmp*.zip

Various

 * Example BMP images (all Windows v3 except as indicated)
 * OS/2 BBS Files Archive → 13-Bitmap.zip - Lots of OS/2 BMP 1.0 & 2.0 files
 * BMP Suite Image List
 * https://telparia.com/fileFormatSamples/image/bmp/

Links

 * Wikipedia: BMP file format
 * , from the Encyclopedia of Graphics File Formats
 * , from the Encyclopedia of Graphics File Formats
 * Bad Peggy: scans images for problems
 * ForensicsWiki entry (not much useful info except for a link to an iOS tool for reading metadata)
 * Graphic documenting format