status of this document: work in progress
|
|
Name | Size | Description | ||
---|---|---|---|---|
Header | 14 bytes | Windows Structure: BITMAPFILEHEADER | ||
Signature | 2 bytes | 'BM' | ||
FileSize | 4 bytes | File size in bytes | ||
reserved | 4 bytes | unused (=0) | ||
DataOffset | 4 bytes | File offset to Raster Data | ||
InfoHeader | 40 bytes | Windows Structure: BITMAPINFOHEADER | ||
Size | 4 bytes | Size of InfoHeader =40 | ||
Width | 4 bytes | Bitmap Width | ||
Height | 4 bytes | Bitmap Height | ||
Planes | 2 bytes | Number of Planes (=1) | ||
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 | ||
Compression | 4 bytes | Type of Compression 0 = BI_RGB no compression 1 = BI_RLE8 8bit RLE encoding 2 = BI_RLE4 4bit RLE encoding | ||
ImageSize | 4 bytes | (compressed) Size of Image It is valid to set this =0 if Compression = 0 | ||
XpixelsPerM | 4 bytes | horizontal resolution: Pixels/meter | ||
YpixelsPerM | 4 bytes | vertical resolution: Pixels/meter | ||
ColorsUsed | 4 bytes | Number of actually used colors | ||
ColorsImportant | 4 bytes | Number of important colors 0 = all | ||
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 |
BitCount = 8 Compression = 1 |
n (byte 1) | c (Byte 2) | Description |
---|---|---|
>0 | any | n pixels of color number c |
0 | 0 | End-of-line |
0 | 1 | EndOfBitmap |
0 | 2 | Delta. The following 2 bytes define an unsigned offset in x and y direction (y being up) The skipped pixels should get a color zero. |
0 | >=3 | The following c bytes will be read as single pixel colors just as in uncompressed files. A zero follows, if c is odd, putting the file/memory pointer on a 16bit boundary again. |
Compressed Data | Expanded data |
---|---|
03 04 | 04 04 04 |
05 06 | 06 06 06 06 06 |
00 03 45 56 67 00 | 45 56 67 |
02 78 | 78 78 |
00 02 05 01 | Move 5 right and 1 up. (Windows docs say down, which is wrong) |
00 00 | End-of-line |
09 1E | 1E 1E 1E 1E 1E 1E 1E 1E 1E |
00 01 | End-of-bitmap |
00 00 | Zero padding for 32bit boundary |
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. |
To my knowledge: None. |
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.
|
http://www.dcs.ed.ac.uk/~mxr/gfx/ |
|
BMP File 은 다음과 같이 구성되어 있다.
BMP FILE HEADER (14 bytes)
BMP INFO HEADER (40 bytes)
RGB QUAD (color table - pallette 정보)
IMAGE BITS
color 색상 수에 따라 어떻게 바뀌는 지 본다. 지겨운 정보는 나중에 쓴다.
1. 24bit Color
BMP FILE HEADER
BMP INFO HEADER
RGB QUAD 는 없다. - full color 이므로 pallette 정보가 불필요하다.
그림은 거꾸로 저장된다. 3byte 가 1 pixel 이다.
예를 들면 화면에 그림이 다음과 같다면 RGB 로 분해한 후 거꾸로 저장된다.
1 2 3
4 5 6
7 8 9
=>
B7 G7 R7 B8 G8 R8 B9 G9 R9 00 00 00
B4 G4 R4 B5 G5 R5 B6 G6 R6 00 00 00
B1 G1 R1 B2 G2 R2 B3 G3 R3 00 00 00
1 line 이 저장될 때, 4의 배수로 저장되어야 한다.
위와 같은 경우, 3x3 인데, X pixel 수는 3이고, RGB 로 하면 9 bytes 가 되어 4의 배수가 되기 위헤서는 3개의 NULL 이 필요하다.
RGB 는 저장될 때, BGR 순서로 저장된다.
2. 256색 color
BMP FILE HEADER
BMP INFO HEADER
RGB QUAD - 256 * 4
RGBQUAD structure 는 BGR0 의 4bytes 로 구성되어 있다.
그림은 역시 거꾸로 저장되며, 1byte 가 한 pixel이다.
이 때 1byte 의 값은 0~255 의 pallette index 번호이다.
예를 들어 RGB QUAD 의 F9 번째 index 에 BGR0 data 가 0x00,0x00,0xFF,0x00 로 되어 있다.
이 때, F9 index 의 color 는 빨간색이다. FF index 에는 흰색이 있다고 하자.
위 full color data 에서 9번 째 pixel 만 빨간색이고 나머지는 흰색이라면 data 는 다음과 같이 된다.
=>
FF FF F9 00
FF FF FF 00
FF FF FF 00
1 line 이 저장될 때, 역시 4의 배수로 저장된다.
3. 16색 color
BMP FILE HEADER
BMP INFO HEADER
RGB QUAD - 16 * 4
0~15 의 pallette index 가 있다.
16색이므로 4bit 만 필요하다. 1byte 에 2개의 pixel 정보가 있다.
상위 byte 부터 저장된다.
9번째 index 가 빨간색, F번째 index 가 흰색이라면, 위와 같은 예에서 data 는 다음과 같다.
=>
FF 90 00 00
FF F0 00 00
FF F0 00 00
4. 단색 color
BMP FILE HEADER
BMP INFO HEADER
RGB QUAD - 2 * 4
0~1 의 pallette index 가 있다. 검은색, 하얀색이다.
단색이므로 1bit 만 필요하다. 1byte 에 8개의 pixel 정보가 있다.
상위 bit부터 순서대로 저장된다.
위와 같은 예에서 data 는 다음과 같다.
=>
C0 00 00 00
E0 00 00 00
E0 00 00 00
빨간색은 검은색이 되어버린다.
BITMAP FILE HEADER 구조는 다음과 같다.
typedef struct tagBITMAPFILEHEADER { // bmfh
WORD bfType; // FILE Type "BM"
DWORD bfSize; // file size
WORD bfReserved1; // 0
WORD bfReserved2; // 0
DWORD bfOffBits; // file 의 처음에서 image data 까지의 offset (byte 단위)
} BITMAPFILEHEADER;
BITMAP INFO HEADER 구조는 다음과 같다.
typedef struct tagBITMAPINFOHEADER{ // bmih
DWORD biSize; // bitmap info header 구조체의 크기 (byte)
LONG biWidth; // image 폭 (pixel)
LONG biHeight; // image 높이 (pixel)
WORD biPlanes;
WORD biBitCount // pixel 당 bit수
DWORD biCompression;
DWORD biSizeImage; // image data 의 size
LONG biXPelsPerMeter; // 해상도
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;
