The Win32 API supports formats for compressing bitmaps that define their colors with 8 or 4 bits per pixel. Compression reduces the disk and memory storage required for the bitmap.
Compression forms part of the following member names in the bitmap information header structures for different platforms. In the discussion that follows, compression is used to mean all of these variants.
Operating System | Compression |
---|---|
Windows NT 3.51 and earlier | biCompression |
Windows NT 4.0 and Windows 95 | bV4Compression |
Windows NT 5.0 and Windows 98 | bV5Compression |
When the Compression member of the bitmap information header structure is BI_RLE8, a run-length encoding (RLE) format is used to compress an 8-bit bitmap. This format can be compressed in encoded or absolute modes. Both modes can occur anywhere in the same bitmap.
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 offsets of the next pixel from the current position. |
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 01
The bitmap expands 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
When the Compression member is BI_RLE4, the bitmap is compressed by using a run-length encoding format for a 4-bit bitmap, which also uses encoded and absolute modes:
The following example shows the hexadecimal values of a 4-bit compressed bitmap.
03 04 05 06 00 06 45 56 67 00 04 78 00 02 05 01
04 78 00 00 09 1E 00 01
The bitmap expands as follows (single-digit values represent a color index for a single pixel):
0 4 0
0 6 0 6 0
4 5 5 6 6 7
7 8 7 8
move current position 5 right and 1 down
7 8 7 8
end of line
1 E 1 E 1 E 1 E 1
end of RLE bitmap