[TOC]
.bmp = bitmap
BITMAPFILEHEADER bmfh; 14 bytes
BITMAPINFOHEADER bmih; 40 bytes
RGBQUAD aColors[];
BYTE aBitmapBits[];
integers are stored in bytes least significant bit first
e.g. M = decimal char = 76 = (big endian) 0100 1100 = (little endian) 0011 0010
- Use ms paint to create a 2 wide by 2 high .bmp file (all red filesize = 70 bytes)
- Use ms paint to create a 8 wide by 8 high .bmp file (all white)
BITMAPFILEHEADER = 14 bytes
1. The first two bytes are the character 'B' , then the character 'M'
char byte sequence 66 77
2. The next 4 bytes = the size of the BMP file in bytes
red-2-by-2.bmp = 70 0 0 0 (14 + 40 + 16)
3. 2 bytes reserved (depends on the creating app?)
char byte sequence 0 0
4. 2 bytes reserved (depends on the creating app?)
char byte sequence 0 0
5. 4 byte offset = address where the data is found
char byte sequence of 54 0 0 0
(for all white from byte 55 on it is all 255 255 255 bytes = in all white bmp)
for all red it is 00 00 FF
BIT MAP INFORMATION HEADER (DIB) = 40 bytes
6. 4 bytes = size of this section (DIB HEADER version, could also be 108 or 124)
in this case it is 40 (most compatible - Windows 3.0)
char byte sequence of 40 0 0 0
7. 4 bytes = bitmap width in pixels
char byte sequence of 8 0 0 0
red-2-by-2.bmp = 2 0 0 0
8. 4 bytes = bitmap height in pixels
char byte sequence of 8 0 0 0
red-2-by-2.bmp = 2 0 0 0
9. 2 bytes = number of color planes*
char byte sequence of 1 0
10. 2 bytes = # of bits per pixel**
(color depth, e.g. 1 monochrome, 4, 8 VGA, 16 bit, 24 Truecolor, 32)
char byte sequence of 24 0
11. 4 bytes = compression method = 0 (BI_RGB), 1 (BI_RLE8) , 2 (BI_RLE4)
3 (BI_BITFIELDS)
char byte sequence of 0 0 0 0
12. 4 bytes = size of the raw data bitmap ( 54 header + 192 data = 246 full size)
char byte sequence of 192 0 0 0
char byte sequence of 16 0 0 0
13. 4 bytes = horizontal resolution***
char byte sequence of 0 0 0 0
14. 4 bytes = vertical resolution
char byte sequence of 0 0 0 0
15. 4 bytes = number of colors in the palette
char byte sequence of 0 0 0 0
16. 4 bytes = number of "important" colors (or 0 when every color is important)
char byte sequence of 0 0 0 0
55th byte = begin data ... red 2x2 (x,y with top left = 0,0)
0 0 255 = one red pixel at 0,1 (NOTE RGB REVERSED IS BLUE GREEN RED)
0 0 255 = one red pixel at 1,1
0 0 = padding for 4 byte alignment
0 0 255 = one red pixel at 0,0
0 0 255 = one red pixel at 0,1
0 0 = padding for 4 byte alignment
55th byte = begin data ... red 3x2 (x,y with top left = 0,0 with blue dot) demonstrates that it works bottom to top and alignment bytes per line
0 0 255 = one red pixel at 0,1
0 0 255 = one red pixel at 1,1
0 0 255 = one red pixel at 2,1
0 0 0 = padding for byte alignment
255 0 0 = one blue pixel at 0,0
0 0 255 = one red pixel at 1,0
0 0 255 = one red pixel at 2,0
0 0 0 = padding for alignment
55th byte = begin data ... blue gree red white (clockwise from top left)
0 0 255 = one red pixel at 0,1
255 255 255 = one white pixel at 1,1
0 0 = padding for 4 byte alignment
255 0 0 = one green pixel at 1,0
0 255 0 = one blue pixel at 0,0
0 0 = padding for 4 byte alignment
COLOR PALETTE
Stored Blue Green Red in little endian bit order
* Instead of assigning a single RGB value to each pixel, color planes can use the
combination of two planes to determine that pixel's color by separating the graphic
into each of the primary color components (red, green, blue), and storing them in
their own planes (to allow for greater color depth with 8- and 16-bit video).
Usually only 1 plane is required with modern systems.
** BITS PER PIXEL
1 Bitmap is monochrome and the color table contains two entries. Each
bit in the bitmap array represents a pixel. If the bit is clear, the pixel is
displayed with the color of the first entry in the color table. If the bit is
set, the pixel has the color of the second entry in the table.
4 Bitmap has a maximum of 16 colors. Each pixel in the bitmap is
represented by a 4-bit index into the color table. For example, if the first
byte in the bitmap is 0x1F, the byte represents two pixels. The first pixel
contains the color in the second table entry, and the second pixel contains
the color in the sixteenth table entry.
8 Bitmap has a maximum of 256 colors. Each pixel in the bitmap is
represented by a 1-byte index into the color table. For example, if the first
byte in the bitmap is 0x1F, the first pixel has the color of the
thirty-second table entry.
24 Bitmap has a maximum of 2^24 colors. The bmiColors (or bmciColors)
member is NULL, and each 3-byte sequence in the bitmap array represents the
relative intensities of red, green, and blue, respectively, for a pixel.
HORIZONTAL RESOLUTION
Misc
PNG FORMAT: http://www.faqs.org/rfcs/rfc2083.html