BMP file format
Applies to:
BG1, BG1: TotS, BG2, BG2: ToB, PST, IWD, IWD:HoW, IWD:TotL, IWD2
General Description
http://www.daubnet.com/formats/BMP.htmlTable of Contents
- Basic Description
- Basic File Format
- Raster Data Encoding
- Portability
- Trademarks, Patents and Royalties
- Cross Checking Software
- Resources
Basic Description
This file format is the MS-Windows standard format. It holds black&white-, 16-color, 256-color and Truecolor images. The palletized 16-color and 256-color images may be compressed via run length encoding. Notice there is also a OS/2-BMP format.
Basic File Format
Name | Size | Description | ||
---|---|---|---|---|
Header | 14 bytes | Windows Structure: BITMAPFILEHEADER | ||
0x00 | Signature | 2 bytes | 'BM' | |
0x02 | FileSize | 4 bytes | File size in bytes | |
0x06 | Reserved | 4 bytes | unused (=0) | |
0x0a | DataOffset | 4 bytes | File offset to Raster Data | |
InfoHeader | 40 bytes | Windows Structure: BITMAPINFOHEADER | ||
0x0e | Size | 4 bytes | Size of InfoHeader =40 | |
0x12 | Width | 4 bytes | Bitmap Width | |
0x16 | Height | 4 bytes | Bitmap Height | |
0x1a | Planes | 2 bytes | Number of Planes (=1) | |
0x1c | BitCount | 2 bytes | Bits per Pixel 1 = monochrome palette. NumColors = 1 4 = 4bit palletized. NumColors = 16 8 = 8bit palletized. NumColors = 256 16 = 16bit RGB. NumColors = 65536 (?) 24 = 24bit RGB. NumColors = 16M |
|
0x1e | Compression | 4 bytes | Type of Compression 0 = BI_RGB no compression 1 = BI_RLE8 8bit RLE encoding 2 = BI_RLE4 4bit RLE encoding |
|
0x22 | ImageSize | 4 bytes | (compressed) Size of Image It is valid to set this =0 if Compression = 0 |
|
0x26 | XpixelsPerM | 4 bytes | horizontal resolution: Pixels/meter | |
0x2a | YpixelsPerM | 4 bytes | vertical resolution: Pixels/meter | |
0x2e | ColorsUsed | 4 bytes | Number of actually used colors | |
0x32 | ColorsImportant | 4 bytes | Number of important colors 0 = all |
|
0x36 | ColorTable | 4 * NumColors bytes | present only if Info.BitsPerPixel
<= 8 colors should be ordered by importance |
|
Red | 1 byte | Red intensity | ||
Green | 1 byte | Green intensity | ||
Blue | 1 byte | Blue intensity | ||
reserved | 1 byte | unused (=0) | ||
repeated NumColors times | ||||
Raster Data | Info.ImageSize bytes | The pixel data |
Raster Data compression for 8bit / 256 color imagesBitCount = 8 Compression = 1The pixel data is stored in 2bytes / 16bit chunks. The first of these specifies the number of consecutive pixels with the same color. The second byte defines their color index. If the first byte is zero, the second defines an escape code. The End-of-Bitmap is zero padded to end on a 32bit boundary. Due to the 16bit-ness of this structure this will always be either two zero bytes or none.
|
Portability
Although BMPs were invented by Microsoft for its Windows platform, a lot of programs on other platforms are capable of reading and writing them. Notice the Intel order in 2byte and 4-byte integer values (Least significant byte first). The 16bit BMPs have been introduced to Windows after the others, still puzzling many applications.
Trademarks, Patents and Royalties
To my knowledge: None.
Cross-Checking Software
This section is for programmers, who wish to cross-check their implementation with others. This is an incomplete list of programs, which are available as freeware / shareware / try-before-buy etc.
The following software is able to decode BMP files
- easiest: Make the file the MS-Windows' background.
- MS-Paint / Paintbrush
- JASC Paint Shop Pro
The following software is able to encode BMP files
- JASC Paint Shop Pro
- MS-Paint / Paintbrush
Online Resources
http://www.dcs.ed.ac.uk/~mxr/gfx/
Paper Resources
MS-Windows SDK
[German:] Referenzhandbuch Dateiformate by Günter Born.
The following suggestions are from the Graphics Fileformats FAQ:
- Inside Windows File Formats, Tom Swan, Sams Publishing 1993.
ISBN 0-672-30338-8 $24.95 softcover, 337 pages and 1 disk (3.5 in.).
Order: Sams Publishing, 2201 West 103rd Street, Indianapolis, IN 46290 - Luse, Marv. "The BMP File Format," Dr. Dobb's Journal, #219 September
1994 (Vol 9, Issue 10), pp. 18-22.
code available at: ftp://ftp.mv.com/pub/ddj/1994/1994.09/bmp.zip - The BMP File Format: Part I+II, Dr.
Dobb's Journal, David Charlap, #228+#229
March+April 1995 (Vol. 20, Issue 3+4).
code available at: ftp://ftp.mv.com/pub/ddj/1995/1995.03/bmp.zip