BMP file format Analysis
BMP (Bitmap-file) is a Windows Image File Format. All image processing software running in Windows supports the BMP image file format. In Windows, Image Rendering is based on BMP. The BMP image file format before Windows 3.0 is related to the display device. Therefore, the BMP image file format is called the device-Dependent Bitmap File Format. BMP image files after Windows 3.0 have nothing to do with the display device. Therefore, this BMP image file format is called device-independent Bitmap (DIB) format (Note: After Windows 3.0, the DDB bitmap still exists in the system. functions such as bitblt () are based on the DDB bitmap, but if you want to save the image to a disk file in BMP format, microsoft strongly recommends that you store images in Dib format) to enable Windows to display stored images on any type of display device. The default file extension of a BMP bitmap file is BMP or BMP (sometimes it uses. DiB or. RLE as the extension ).
6.1.2 file structure
A bitmap file is composed of four parts: Bitmap-file header, bitmap-Information header, and color table) and the byte array that defines the bitmap. It has the following format.
Composition of Bitmap files |
Structure name |
Symbol |
Bitmap-File Header) |
Bitmapfileheader |
Bmfh |
Bitmap-Information Header) |
Bitmapinfoheader |
Bmih |
Color Table) |
Rgbquad |
Acolors [] |
Image Data array bytes |
Byte |
Abitmapbits [] |
The structure of the bitmap file can be integrated in Table 6-01.
Table 01 structure Summary of Bitmap files
|
Offset |
Domain Name |
Size |
Content |
Image files Header |
0000 h |
File ID |
2 bytes |
The two-byte content is used to identify the bitmap type: 'Bm ': Windows 3.1x, 95, NT ,... 'Ba': OS/2 bitmap Array 'Cies': OS/2 color icon 'Cp': OS/2 color pointer 'Ic ': OS/2 icon 'Pt': OS/2 pointer Note: Because OS/2 systems are not widely used, you only need to determine the first "BM" in programming. |
|
0002 H |
File Size |
1 DWORD |
Size of the entire file in bytes |
|
0006 H |
Reserved |
1 DWORD |
Reserved, must be set to 0 |
|
000ah |
Bitmap data offset |
1 DWORD |
Offset between the data (bitmap data) starting from the file to the graph data |
|
000eh |
Bitmap header size |
1 DWORD |
The length of the bitmap info header, used to describe the color and compression method of the bitmap. The following length: 28 h-Windows 3.1x, 95, NT ,... 0ch-OS/2 1.x F0h-OS/2 2.x Note: in Windows 95, 98, 2000, and other operating systems, the length of the Bitmap header is not necessarily 28 h, because Microsoft has developed a new BMP file format, the structure of the information header changes greatly and the length is extended. Therefore, it is best not to directly use the constant 28 h, but to read the value from a specific file. This ensures program compatibility. |
|
0012 H |
Width |
1 DWORD |
The width of the bitmap, in pixels. |
|
0016 H |
Height |
1 DWORD |
The height of the bitmap, in pixels. |
|
001ah |
Planes |
1 word |
Bitmap bit number (Note: This value will always be 1) |
Image Information Header |
001ch |
Bits per pixel |
1 word |
Number of digits in each pixel 1-monochrome Bitmap (in fact, there are two colors, black and white by default. You can define these two colors by yourself) 4-16 color bitmap 8-256-color bitmap 16-16 bit high-color bitmap 24-24bit true color bitmap 32-32bit enhanced true color bitmap |
|
001eh |
Compression |
1 DWORD |
Compression description: 0-no compression (in bi_rgb format) 1-RLE 8-use the 8-bit RLE compression method (represented by bi_rle8) 2-RLE 4-use the 4-bit RLE compression method (represented by bi_rle4) 3-bitfields-bit domain storage method (represented by bi_bitfields) |
|
0022 H |
Bitmap data size |
1 DWORD |
The size of the bitmap data expressed by the number of cells. The value must be a multiple of 4. |
|
0026 H |
Hresolution |
1 DWORD |
Horizontal resolution in pixels/meters |
|
002ah |
Vresolution |
1 DWORD |
Vertical Resolution in pixels/meters |
|
002eh |
Colors |
1 DWORD |
The number of colors used by the bitmap. For example, 8-bit/pixel represents 256 h or. |
|
0032 H |
Important colors |
1 DWORD |
Specify the number of important colors. When the value of this field is equal to the number of colors (or equal to 0), it indicates that all colors are equally important. |
Color Palette data |
Varies with the BMP version. |
Palette |
N * 4 byte |
Color Palette specification. For each table item in the color palette, use the following methods to describe the values of RGB:
|
1 byte for the blue component |
|
1 byte for green component |
|
1 byte for red weight |
|
1 byte for padding (set to 0) |
|
Image Data |
The size varies depending on the BMP version and palette size. |
Bitmap data |
Xxx bytes |
The size of this field depends on the compression method, image size, and image bit depth. It contains all bitmap data bytes, which may be the index number of the color palette, it may also be the actual RGB value, which is determined based on the bit depth value in the Image Information header. |