A raster-based fixed-resolution pixel layout format. Bitmap images are displayed as rows and columns of pixels, all in a neat, perfect grid. They do not scale well, becuase you will either lose information if you scale them down or add guessed information if you scale them up. Bitmaps are the images which most people are more familiar with.

Besides the image format named "bitmap" (used in Microsoft Paint) (BMP), there are many bitmap-based image formats. JPEG, GIF, PNG, ILBM (LBM), MAC, PCX, PGM, PPM, and TIF are a few examples.

Bitmaps are different from vector-based images, which store shapes, lines and points in an arbitrary-resolution format.

I present to you, dear reader, the inner workings of a bitmap file(.bmp). I have omitted some details, such as the variety of compression choices. Other details have been glossed over, since they are beyond the scope of this write up. That being said, here we go...

In the following table, each letter represents a byte of the file. The letter meanings are explained below.
       0123 4567   89AB CDEF
0x00   AABB BBCC   CCDD DDEE    
0x30   NNOO OOXX   XXXX XXXX....
A - 2 Bytes - Identifier
These two characters identify the type of bitmap.
B - 4 Bytes - File Size
Complete size of file in bytes.
C - 4 Bytes - Reserved
Reserved. Set it to zero and don't worry about it.
D - 4 Bytes - Bitmap Data Offset
Offset from the beginning of the file to the start of the actual bitmap data.
E - 4 Bytes - Bitmap Header Size
Length of the bitmap information header.
F - 4 Bytes - Width
Width of the bitmap in pixels.
G - 4 Bytes - Height
Height of the bitmap in pixels.
H - 2 Bytes - Planes
Number of planes in this bitmap (it should be noted that I have absolutely no clue what this means.)
I - 2 Bytes - Bits Per Pixel
The number of bits used per pixel to store palette information.
J - 4 Bytes - Compression
Specifies what type of compression is used.
K - 4 Bytes - Bitmap Data Size
Size of the bitmap data in bytes, rounded up to the next 4-byte boundry.
L - 4 Bytes - Horizontal Resolution
The horizontal resolution, in pixels per meter.
M - 4 Bytes - Vertical Resolution
The vertical resolution, in pixels per meter.
N - 4 Byte - Colors
The number of colors used by this bitmap.
O - 4 Byte - Important Colors
The number of "important" colors. This will be the same as the colors field if all the colors are important.
X - Variable - Palette
The size of the palette is 4 * C bytes, where C is the number of colors.

Things that need more explaination
These 2 bytes identify the type of bitmap as follows.
BM - Windows 3.1x, 95, NT, etc
BA - OS/2 Bitmap Array
CI - OS/2 Color Icon
CP - OS/2 Color Pointer
IC - OS/2 Icon
PT - OS/2 Pointer

Bits Per Pixel
This field determines how many bits are used per pixel in the actual bitmap data, and thus the maximum number of colors in the palette.
1 - Monochrome bitmap
4 - 16 color bitmap
8 - 256 color bitmap
16 - 16bit bitmap(High Color)
24 - 24bit bitmap(True Color)
32 - 32bit bitmap(True Color)

This specifies the number of colors in the palette that are actually used by the bitmap. If this is 0, it assumes that every index in the palette is used up to the maximum defined by Bits per Pixel.

Important Colors
This specifies how many of the colors in the palette are actually important to displaying the bitmap. If this value is 0, then all colors are important.
Note: I do not know what makes a color "important." I assume this field is used if a program wants to resample or recompress a bitmap.

Putting it all together...
Let's assume that we are using 8 Bits per Pixel and Compression is set to BI_RGB (meaning uncompressed). We will conviniently use 0 for Colors(which, in this case, means that Colors is actually 256 (8 bits per pixel, remember?)) Next we fill the palette with 256 colors. Each color is represented by four bytes. The first byte is the blue value, the second is green and the third is red. The fourth byte is filler, usually set to zero. After the pallete comes the actual bitmap data. In our example, each byte represents a pixel. The actual value of the byte is an index into the pallete(a value between 0 and 255, one for each color in the pallete). The data fills in the image from left to right, bottom to top. Where a row of pixels ends is determined by the horizontal resolution field. The number of rows is given in the vertical resolution field.

If you find an error, or would like me to add something, drop me a /msg. If you would like to explain all of the different compression modes, please feel free to add a write up.

Log in or registerto write something here or to contact authors.