Bitmap Format

if "bfType" is not "0x4D42", it is not bitmap file.

overview of bitmap file

offset size structure name of structure
0 14 file header BITMAPFILEHEADER
14 40 information header BITMAPINFOHEADER
54 4byte*biBitCount color palette1 RGBQUAD
bfOffBits depending on bit count. image array(bits)2 byte[biWidth*biHeight*biBitCount/8]3

BITMAPFILEHEADER

0 bfType 2byte unsigned int file type 'BM'=0x4D42
2 bfSize 4byte unsigned long file size byte
6 bfReserved1 2byte unsigned int reserved area1 always 0
8 bfReserved2 2byte unsigned int reserved area2 always 0
10 bfOffBits 4byte unsigned long offset from first of file to image data(byte)4

BITMAPINFOHEADER

14 biSize 4byte unsigned long size of information header[byte] 40
18 biWidth 4byte long width of image[pixel]
22 biHeight 4byte long height of image[pixel]
26 biPlanes 2byte unsigned int number of planes always 1
28 biBitCount 2byte unsigned int number of color bits[bit] 1,4,8,(16),24,32
30 biCompression 4byte unsigned long way of compression 0,1,2,3
34 biSizeImage 4byte unsigned long data size of image[byte]
38 biXPixPerMeter 4byte long horizontal resolution[dot/m] sometimes 0
42 biYPixPerMeter 4byte long vertical resolution[dot/m] sometimes 0
46 biClrUsed 4byte unsigned long number of palettes you use. [number of colors you use] sometimes 0
50 biCirImportant 4byte unsigned long number of important colors sometimes 0

RGBQUAD

typedef struct tagRGBQUAD {
        BYTE    rgbBlue;   
        BYTE    rgbGreen; 
        BYTE    rgbRed;    
        BYTE    rgbReserved;//always 0
} RGBQUAD;

This table is color bits and correspond pallets.
it is easy to calculate $2^{b}$b is color bits. it is power of 2.
color bits number of pallets
1bit  2
4bit 16
8bit 256
24bit none5
32bit none6
en.gif en
ja.gif ja


edit
サポートサイト Wikidot.com