For example a checkerboard could be encoded
10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B 10 W 10 B instead of B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B B W W W W W W W W W W B B B B B B B B B BA BMP file consists of the four following parts:
typedef struct tagBITMAPFILEHEADER { /* bmfh */ UINT bfType; DWORD bfSize; UINT bfReserved1; UINT bfReserved2; DWORD bfOffBits; } BITMAPFILEHEADER; typedef struct tagBITMAPINFOHEADER { /* bmih */ DWORD biSize; LONG biWidth; LONG biHeight; WORD biPlanes; WORD biBitCount; DWORD biCompression; DWORD biSizeImage; LONG biXPelsPerMeter; LONG biYPelsPerMeter; DWORD biClrUsed; DWORD biClrImportant; } BITMAPINFOHEADER; typedef struct tagRGBQUAD { /* rgbq */ BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; } RGBQUAD;The following is a description of the above structures.
The maximum number of colors = 2N. Where N = biBitCount. 2N is the same as 1 << N. The same as you can get powers of 10 by shifting the decimal point in a decimal number, only it is binary.
"BI_RLE8
When the biCompression member is set to BI_RLE8, the bitmap is compressed using a run-length encoding format for an 8-bit bitmap. This format may be compressed in either of two modes: encoded and absolute. Both modes can occur anywhere throughout a single bitmap. Encoded mode consists of two bytes: the first byte specifies the number of consecutive pixels to be drawn using the color index contained in the second byte. In addition, the first byte of the pair can be set to zero to indicate an escape that denotes an end of line, end of bitmap, or a delta. The interpretation of the escape depends on the value of the second byte of the pair. The following list shows the meaning of the second byte:
Value Meaning 0 End of line. 1 End of bitmap. 2 Delta. The two bytes following the escape contain unsigned values indicating the horizontal and vertical offset of the next pixel from the current position.Absolute mode is signaled by the first byte set to zero and the second byte set to a value between 0x03 and 0xFF. In absolute mode, the second byte represents the number of bytes that follow, each of which contains the color index of a single pixel. When the second byte is set to 2 or less, the escape has the same meaning as in encoded mode. In absolute mode, each run must be aligned on a word boundary. The following example shows the hexadecimal values of an 8-bit compressed bitmap:
03 04 05 06 00 03 45 56 67 00 02 78 00 02 05 01 02 78 00 00 09 1E 00 01This bitmap would expand as follows (two-digit values represent a color index for a single pixel):
04 04 04 06 06 06 06 06 45 56 67 78 78 move current position 5 right and 1 down 78 78 end of line 1E 1E 1E 1E 1E 1E 1E 1E 1E end of RLE bitmap"
To display an image with VGA 256 color mode the 256 DAC (Digital to Analog Converter) registers must be loaded with the RGB values from the color map. Once the color map is loaded you can poke the color map indices into the video segment (0XA000) at the offset given by y*screen_width+x where x & y are the column & row for the pixel.
Note: The DAC registers are only 6 bits and the RGB values must be shifted right 2 bits before being loaded into the DAC registers.
I have C source code for a simple program to display BMP files. This simple program can only display 8 bit BMP files (compressed or non-compressed). It does not check to see if the pixels are on the screen before displaying them, so it may cause a problem if the image is larger than 320 x 200 pixels.
This code uses three include files for some in-line assembly functions needed for displaying the pixels. If you know a little about the EGA/VGA BIOS and 8086 assembly language these functions should be easy to program.
PC Intern By Michael Tischer, Published by Abacus is an excellent book on DOS system programming, and explains how to program such functions.
Or, for a nominal fee, you can buy my source code on my Shareware & Freeware page, which includes the needed include files.
Click here for bmpvu.c you can save it to your hard disk from your browsers file menu.