Compression of 8-Bit-Per-Pixel DIBs

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:

Both modes can occur anywhere throughout a single bitmap.

Encoded Mode 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 0 to indicate an escape that denotes an end of line, end of bit map, 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 - 2.

The following table lists the meaning of the second byte values:

Second Byte

0 1 2

Absolute Mode Absolute mode is signalled by the first byte set to 0 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 2-digit values represent a color index for a single pixel.

┌──────────────────────────────┬──────────────────────────────┐
│Compressed Data               │Expanded Data                 │
├──────────────────────────────┼──────────────────────────────┤
│03 04                         │04 04 04                      │
│05 06                         │06 06 06 06 06                │
│00 03 45 56 67 00             │45 56 67                      │
│02 78                         │78 78                         │
│00 02 05 01                   │move 5 right and 1 down       │
│02 78                         │78 78                         │
│00 00                         │end of line                   │
│09 1E                         │1E 1E 1E 1E 1E 1E 1E 1E 1E    │
│00 01                         │end of RLE bitmap             │
└──────────────────────────────┴──────────────────────────────┘


[Back: Windows 3.0 Bitmap Compression Formats]
[Next: Compression of 4-Bit-Per-Pixel DIBs]