What is a DIB File?
A DIB file stores a Windows device-independent bitmap using defined headers, optional color tables, and pixel data. Its representation is closely related to BMP and is designed to be independent of a particular display device.
How DIB Files work
A DIB describes raster pixels with a bitmap information header, optional color masks or a color table, and scan lines aligned to four bytes. The same structure appears in three places: inside a BMP file after the 14-byte BITMAPFILEHEADER, as a packed DIB in memory, and on the Windows clipboard as CF_DIB or CF_DIBV5. Windows treats .dib as a second extension for BMP, whereas some tools use DIB to mean the headerless form. Four header generations exist (BITMAPCOREHEADER, BITMAPINFOHEADER, BITMAPV4HEADER, BITMAPV5HEADER), told apart by the size value in their first four bytes. A color table is mandatory at 1, 4, and 8 bits per pixel, and BI_BITFIELDS bitmaps place three color masks directly after a BITMAPINFOHEADER, so an importer has to read the declared layout rather than assume 24-bit pixels.
Key facts
- 1DIB can mean data with or without the BMP file header. Windows’ BMP codec registers both
.bmpand.dibfor the sameimage/bmpformat, which starts with aBITMAPFILEHEADER(bytesBM); clipboardCF_DIBdata is aBITMAPINFOfollowed directly by the pixel bits; and ImageMagick defines itsDIBformat as a BMP file without the BMP header. Check for theBMsignature before choosing a parser. - 2Uncompressed scan lines are padded to a multiple of four bytes, and the padding is not pixel data: a 10×10 24-bit bitmap carries two padding bytes per row. Compute the row stride as
((width * bitsPerPixel + 31) & ~31) >> 3. RLE-compressed bitmaps are the exception and are not aligned this way. - 3A positive height means bottom-up storage, where the first stored row is the bottom of the image, and a negative height means top-down. Top-down is available only for uncompressed data: RLE-compressed bitmaps and
BITMAPCOREHEADERbitmaps cannot be top-down. - 4Do not assume a 32-bit DIB carries valid transparency. Microsoft’s BMP codec ignores the extra channel of 16-bit and 32-bit bitmaps because many legacy files hold invalid data there; starting with Windows 8 it reads alpha only from 32-bit files written with a
BITMAPV5HEADER. That is one codec’s policy, not a format limit: the earlierBITMAPV4HEADERalso defines an alpha mask, so confirm how your own decoder treats the fourth channel.
When DIB Files matter
Expect DIB data in Windows graphics APIs, clipboard transfers, and legacy image workflows. Correct parsing requires attention to header variants, row padding, color tables, and whether pixel rows are stored bottom-up.
Sources
- Microsoft Learn: Device-Independent Bitmaps
- Microsoft Learn: Bitmap Header Types (header generations, color tables, scan-line alignment)
- Microsoft Learn: Bitmap Storage (BMP file layout with BITMAPFILEHEADER)
- Microsoft Learn: BITMAPINFOHEADER structure (height sign, color tables, stride)
- Microsoft Learn: BITMAPV4HEADER structure (color and alpha masks)
- Microsoft Learn: Standard Clipboard Formats (CF_DIB, CF_DIBV5)
- Microsoft Learn: BMP Format Overview, Windows Imaging Component (extensions and alpha handling)
- ImageMagick: Image Formats, DIB entry