When the biCompression field is set to BI_RLE8, the bitmap is compressed using a run-length encoding format for an 8-bit bitmap. This format uses two modes:
Encoded mode
Absolute mode
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.
Also, 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. In encoded mode, the second byte has a value of 0 to 2.
The following table shows the meaning of the second byte:
Second Byte | 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 signalled by the first byte set to zero and the second byte set to a value between 03H and FFH.
The second byte represents the number of bytes that follow, each of which contains the color index of a single pixel.
Each run must be aligned on a word boundary.
The following example shows the hexadecimal values of an 8-bit RLE bitmap. Under “Expanded Data,” the two-digit values represent a color index for a single pixel.
Compressed Data | Expanded Data |
03 04 05 06 00 03 45 56 67 00 02 78 00 02 05 01 02 78 00 00 09 1E 00 01 | 04 04 04 06 06 06 06 06 45 56 67 78 78 move 5 right and 1 down 78 78 end of line 1E 1E 1E 1E 1E 1E 1E 1E 1E end of RLE bitmap |