When the field is set to BI_RLE4, the bitmap is compressed using a run-length encoding format for a 4-bit bitmap. This format uses two modes:
Encoded Mode In encoded mode, the first byte of the pair contains the number of pixels to be drawn using the color indexes in the second byte.
The second byte contains two color indexes, one in its high-order nibble (that is, its high-order four bits) and one in its low-order nibble.
The first of the pixels is drawn using the color specified by the high-order nibble; the second, using the color in the low-order nibble; the third, with the color in the high-order nibble; and so on, until all the pixels specified by the first byte have been drawn.
Also, the first byte of the pair can be set to 0 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 from 00H to 02H.
Absolute Mode
In absolute mode, the first byte contains 0, the second byte contains the
number of color indexes that follow, and subsequent bytes contain color
indexes in their high- and low-order nibbles, one color index for each pixel.
Each run must be aligned on a word boundary.
The end-of-line, end-of-bitmap, and delta escapes valid for BI_RLE8 also apply to BI_RLE4.
The following example shows the hexadecimal values of a 4-bit RLE bitmap. Under Expanded Data, the 1-digit values represent a color index for a single pixel.
┌──────────────────────────────┬──────────────────────────────┐ │Compressed Data │Expanded Data │ ├──────────────────────────────┼──────────────────────────────┤ │03 04 │0 4 0 │ │05 06 │0 6 0 6 0 │ │00 06 45 56 67 00 │4 5 5 6 6 7 │ │04 78 │7 8 7 8 │ │00 02 05 01 │move 5 right and 1 down │ │04 78 │7 8 7 8 │ │00 00 │end of line │ │09 1E │1 E 1 E 1 E 1 E 1 │ │00 01 │end of RLE bitmap │ └──────────────────────────────┴──────────────────────────────┘