BMP
|
Introduction
Basic structure
|
The BITMAPFILEHEADER
The header consists of the following fields. The header is 14 bytes in length.
| Size |
Name |
Purpose |
| 2 bytes | bfType | must always be set to 'BM' to declare that this is a .bmp-file. |
| 4 bytes | bfSize | specifies the size of the file in bytes. |
| 2 bytes | bfReserved1 | must always be set to zero. |
| 2 bytes | bfReserved2 | must always be set to zero. |
| 4 bytes | bfOffBits | specifies the offset from the beginning of the file to the bitmap data. |
The BITMAPINFOHEADER
| Size |
name |
purpose |
| 4 bytes | biSize | specifies the size of the BITMAPINFOHEADER structure, in bytes. |
| 4 bytes | biWidth | specifies the width of the image, in pixels. |
| 4 bytes | biHeight | specifies the height of the image, in pixels. |
| 2 bytes | biPlanes | specifies the number of planes of the target device, must be set to zero. |
| 2 bytes | biBitCount | specifies the number of bits per pixel and the maximum number of colors in the bitmap. |
| 4 bytes | biCompression |
Specifies the type of compression, usually set to zero (no compression). 0 - no compression |
| 4 bytes | biSizeImage | specifies the size of the image data, in bytes. If there is
no compression, it is valid to set this member to zero. |
| 4 bytes | biXPelsPerMeter | specifies the the horizontal pixels per meter on the designated
targer device, usually set to zero. |
| 4 bytes | biYPelsPerMeter | specifies the the vertical pixels per meter on the designated targer device, usually set to zero. |
| 4 bytes | BiClrUsed |
specifies the number of colors used in the bitmap, if set to zero the number of colors is calculated using the biBitCount member. The maximum number of colors = 2N. Where N = biBitCount. 2N is the same as 1 << N. |
| 4 bytes | BiClrImportant | specifies the number of color that are 'important' for the bitmap, if set to zero, all colors are important. |
|
The field biBitCount actually specifies the color resolution of the bitmap. The possible values are: 1 (black/white); 4 (16 colors); 8 (256 colors); 24 (16.7 million colors). The biBitCount data element also decides if there is a color table in the file and how it looks like. In 1-bit mode the color table has to contain 2 entries (usually white and black). If a bit in the image data is clear, it points to the first palette entry. If the bit is set, it points to the second. In 4-bit mode the color table must contain 16 colors. Every byte in the image data represents two pixels. The byte is split into the higher 4 bits and the lower 4 bits and each value of them points to a palette entry. In 8-bit mode every byte represents a pixel. The value points to an entry in the color table which contains 256 entries. In 24-bit mode three bytes represent one pixel. The first byte represents
the red part, the second the green and the third the blue part. There
is no need for a palette because every pixel contains a literal RGB-value,
so the palette is omitted. |
The RGBQUAD array
The following table shows a single RGBQUAD structure:
| Size |
Name |
Purpose |
| 1 | rgbBlue | specifies the blue part of the color |
| 1 | rgbGreen | specifies the green part of the color |
| 1 | rgbRed | specifies the red part of the color |
| 1 | rgbReserved | must always be set to zero |
The Pixel Data
| It depends on the BITMAPINFOHEADER structure how the pixel data is to be interpreted. Its size is equal to the biSizeImage field of BITMAPINFOHEADER structure. It is important to know that the rows of a DIB are stored upside down. That means that the uppest row which appears on the screen actually is the lowest row stored in the bitmap, a short example: |
![]() |
![]() |
|
pixels displayed on the screen
|
pixels stored in .bmp-file
|