Skip to main content
The BMP (Bitmap) format is one of the simplest raster image formats in common use. Defined by Microsoft, it stores uncompressed or lightly compressed pixel data along with a fixed-size file header and a variable-size device-independent bitmap (DIB) header. Binary Internals was among the first formats supported in the toolkit, and the BMPFile parser exposes all four logical regions of a BMP file — the Bitmap File Header, the DIB Header, the optional Color Table, and the Pixel Array — as annotated tree nodes with byte offsets and field descriptions.

File Extension

.bmp — the parser is invoked for any file with the .bmp extension.

BMP File Structure

Bitmap File Header (14 bytes)

The BitmapFileHeader is always 14 bytes (BitmapFileHeader.LENGTH = 14) and is the entry point for identifying and validating a BMP file. The magic field is read as a 2-character ASCII string. The most common value is "BM", which covers all modern Windows BMP files. The offset field is used to position the PixelArray in the tree and to decide whether a Color Table is present (if the stream position after the DIB header is less than offset, a Color Table exists in the gap).

DIB Header

The DIB Header immediately follows the Bitmap File Header. Its size determines which variant is in use. The DIBHeader class dispatches to the appropriate inner class based on the size field (the first 4 bytes of the header):

BITMAPCOREHEADER (12 bytes)

The original Windows 3.x format. Fields: size (4 bytes), Width (2 bytes), Height (2 bytes), Planes (2 bytes), BitCount (2 bytes).

BITMAPINFOHEADER (40 bytes)

The most widely used DIB header variant. Fields:

Compression Methods

The Compression field in BITMAPINFOHEADER maps to the CompressionMethod enum:

BITMAPV4HEADER (108 bytes) and BITMAPV5HEADER (124 bytes)

These extended variants add ICC color profile support. BITMAPV4HEADER adds RedMask, GreenMask, BlueMask, AlphaMask, ColorSpaceType, Endpoints (a CIEXYZTRIPLE with RGB CIE XYZ coordinates), and GammaRed, GammaGreen, GammaBlue fields. BITMAPV5HEADER extends this further with Intent, ICCProfileData (byte offset to the ICC profile), ICCProfileSize, and a Reserved field.

Color Table

The ColorTable is present when the stream position after the DIB header is less than the pixel array offset from BitmapFileHeader.offset. This corresponds to images with BitCount ≤ 8 (1, 4, or 8 bpp), where each pixel value is an index into the color table rather than a direct color.

Pixel Array

The PixelArray starts at the byte offset specified by BitmapFileHeader.offset. It contains the raw pixel data. For uncompressed bitmaps, rows are stored bottom-to-top by default (positive Height), and each row is padded to a 4-byte boundary.
If there is any gap between the end of the Color Table and the start of the Pixel Array, Binary Internals labels it as a GAP1 node in the tree with its byte range. This occurs occasionally in files written by applications that insert extra padding.