2.2.2.4.10.1.5 Compressed Bitmap
The Compressed Bitmap structure describes a compressed 4-bits-per-pixel or 8-bits-per-pixel bitmap.
|
|
|
|
|
|
|
|
|
|
1 |
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
3 |
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
cbCompFirstRowSize |
cbCompMainBodySize |
||||||||||||||||||||||||||||||
|
cbScanWidth |
cbUncompressedSize |
||||||||||||||||||||||||||||||
|
data (variable) |
|||||||||||||||||||||||||||||||
|
... |
|||||||||||||||||||||||||||||||
cbCompFirstRowSize (2 bytes): MUST be set to 0x0000.
cbCompMainBodySize (2 bytes): The size, in bytes, of the data field.
cbScanWidth (2 bytes): The width, in bytes, of each bitmap row. This value MUST be divisible by 4.
cbUncompressedSize (2 bytes): The uncompressed size, in bytes, of the bitmap.
data (variable): An array of codes that describe compressed structures in the bitmap. The following steps MUST be taken to decode structures.
If the highest order 2 bits of the first byte do not consist entirely of ones, compare the highest order 3 bits to the 3-bit structure codes and choose the appropriate fields.
If the highest order 3 bits of the first byte do not consist entirely of ones, compare the highest order 4 bits to the 4-bit structure codes and choose the appropriate fields.
Otherwise, compare the byte to the 8-bit structure codes and choose the appropriate fields.
3-Bit Structure Codes
Meaning
MEGA_BG_RUN
0x0
A run where each byte matches the uncompressed byte from the previous line and the other 5 bits of the code are all 0. The length of the run, in bytes, is 32 plus the value (a number between 0 and 255) that is contained in the next byte. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
BG_RUN
0x0
A run where each byte matches the uncompressed byte from the previous line and the other 5 bits of the code are not all 0. The length of the run, in bytes, is the other 5 bits of the byte. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
MEGA_FG_RUN
0x1
A run where each byte is the XOR of the uncompressed byte from the previous line with the foreground color and the other 5 bits of the code are all 0. The length of the run, in bytes, is 32 plus the value (a number between 0 and 255) that is contained in the next byte. If this code occurs on the first line, the foreground color alone SHOULD be used.
FG_RUN
0x1
A run where each byte is the XOR of the uncompressed byte from the previous line that has the foreground color, and the other 5 bits of the byte are not all 0. The length of the run, in bytes, is the other 5 bits of the byte. If this code occurs on the first line, the foreground color alone SHOULD be used.
MEGA_FG_BG_IMAGE
0x2
A run where the other 5 bits of the code are all 0 and each byte is either the matching uncompressed byte from the previous line or the XOR of that byte with the foreground color. The length of the run, in bytes, is 1 plus the value (a number between 0 and 255) that is contained in the next byte. The data is specified in the following bytes: a 1 bit signifies the XOR of the byte from the previous line that has the foreground color and a 0 bit signifies that byte alone. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
FG_BG_IMAGE
0x2
A run where the other 5 bits of the code are all not 0 and each byte is either the matching uncompressed byte from the previous line or the XOR of that byte with the foreground color. The length of the run, in bytes, is 8 multiplied by the value (a number between 0 and 31) of the other 5 bits of the byte. The data is specified in the following bytes: a 1 bit signifies the XOR of the byte from the previous line that has the foreground color and a 0 bit signifies that byte alone. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
MEGA_COLOR_RUN
0x3
A single-color run where the other 5 bits of the code are all 0. The length of the run, in bytes, is 32 plus the value (a number between 0 and 255) that is contained in the next byte. The color is specified in the following byte.
COLOR_RUN
0x3
A single-color run where the other 5 bits of the code are not all 0. The length of the run, in bytes, is the other 5 bits of the byte. The color is specified in the following byte.
MEGA_COLOR_IMAGE
0x4
An uncompressed run where the other 5 bits of the code are all 0. The length of the run, in bytes, is 32 plus the value (a number between 0 and 255) that is contained in the next byte. The data is specified in the following bytes as 1 pixel per byte.
COLOR_IMAGE
0x4
An uncompressed run where the other 5 bits of the code are not all 0. The length of the run, in bytes, is the other 5 bits of the byte. The data is specified in the following bytes as 1 pixel per byte.
MEGA_PACKED_CLR_IMAGE
0x5
An uncompressed run where the other 5 bits of the code are all 0. The length of the run, in bytes, is 32 plus the value (a number between 0 and 255) that is contained in the next byte. The data is specified in the following bytes as 2 pixels per byte, because of the high-order nibble of all colors in the run that contains 0.
PACKED_COLOR_IMAGE
0x5
An uncompressed run where the other 5 bits of the code are not all 0. The length of the run, in bytes, is the other 5 bits of the byte. The data is specified in the following bytes as 2 pixels per byte, because of the high-order nibble of all colors in the run that contains 0.
-
4-Bit Structure Codes
Meaning
SET_FG_MEGA_FG_RUN
0xC
A run where each byte is the XOR of the uncompressed byte from the previous line that has a new foreground color and the other 4 bits of the code are all 0. The length of the run, in bytes, is 16 plus the value (a number between 0 and 255) that is contained in the next byte. The new foreground color is specified in the following byte. If this code occurs on the first line, the foreground color alone SHOULD be used.
SET_FG_FG_RUN
0xC
A run where each byte is the XOR of the uncompressed byte from the previous line that has a new foreground color and the other 4 bits of the code are not all 0. The length of the run, in bytes, is the other 4 bits of the byte. The new foreground color is specified in the following byte. If this code occurs on the first line, the foreground color alone SHOULD be used.
SET_FG_MEGA_FG_BG
0xD
A run where the other 4 bits of the code are all 0 and each byte is either the matching uncompressed byte from the previous line or the XOR of that byte with the foreground color. The length of the run, in bytes, is 1 plus the value (a number between 0 and 255) that is contained in the next byte. The new foreground color is specified in the byte after the length. The data is specified in the following bytes: a 1 bit signifies the XOR of the byte from the previous line that has the new foreground color and a 0 bit signifies that byte alone. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
SET_FG_FG_BG
0xD
A run where the other 4 bits of the code are not all 0 and each byte is either the matching uncompressed byte from the previous line or the XOR of that byte with the foreground color. The length of the run, in bytes, is 8 multiplied by the value (a number between 0 and 15) of the other 4 bits of the byte. The new foreground color is specified in the next byte. The data is specified in the following bytes: a 1 bit that signifies the XOR of the byte from the previous line that has the new foreground color and a 0 bit that signifies that byte alone. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
MEGA_DITHERED_RUN
0xE
An alternating run of two colors where the other 4 bits of the code are all 0. The length of the run, in bytes, is 16 plus the value (a number between 0 and 255) that is contained in the next byte. The colors are specified in the following two bytes as one byte each.
DITHERED_RUN
0xE
An alternating run of two colors where the other 4 bits of the code are not all 0. The length of the run, in bytes, is the other 4 bits of the byte. The colors are specified in the following 2 bytes as one byte each.
-
8-Bit Structure Codes
Meaning
MEGA_MEGA_BG_RUN
0xF0
A run where each byte matches the uncompressed byte from the previous line. The length of the run, in bytes, is specified in the next 2 bytes between 1 and 65,536. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
MEGA_MEGA_FG_RUN
0xF1
A run where each byte is the XOR of the uncompressed byte from the previous line that has the foreground color. The length of the run, in bytes, is specified in the next 2 bytes between 1 and 65,536. If this code occurs on the first line, the foreground color alone SHOULD be used.
MEGA_MEGA_FGBG
0xF2
A long run where each byte is either the uncompressed byte from the previous line or the XOR of that byte that has the foreground color. The length of the run, in bytes, is specified in the next two bytes, a value between 1 and 65,536. The data is specified in the following bytes: a 1 bit signifies the XOR of the byte from the previous line that has the foreground color and a 0 bit signifies that byte alone. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
MEGA_MEGA_COLOR_RUN
0xF3
A long single-color run of pixels. The length of the run, in bytes, is specified in the next 2 bytes, a value between 1 and 65,536. The color is specified in the following byte.
MEGA_MEGA_CLR_IMG
0xF4
A long, uncompressed run of pixels. The length of the run, in bytes, is specified in the next 2 bytes, a value between 1 and 65,536. The data is specified in the following bytes as 1 pixel per byte.
MEGA_MEGA_PACKED_CLR
0xF5
A long, uncompressed run of pixels that are packed 2 pixels to a byte. The length of the run, in bytes, is specified in the next 2 bytes between 1 and 65,536. The data is specified in the following bytes as 2 pixels per byte, due to the high-order nibble of all colors in the run that contains 0.
MEGA_MEGA_SET_FG_RUN
0xF6
A long run where each byte is the XOR of the uncompressed byte from the previous line with a new foreground color. The length of the run, in bytes, is specified in the next two bytes between 1 and 65,536. The new foreground color is specified in the following byte. If this code occurs on the first line, the foreground color alone SHOULD be used.
MEGA_MEGA_SET_FGBG
0xF7
A long run where each byte is either the uncompressed byte from the previous line or the XOR of that byte with a new foreground color. The length of the run, in bytes, is specified in the next 2 bytes between 1 and 65,536. The new foreground color is specified in the byte after the length. The data is specified in the following bytes, with a 1 bit signifying the XOR of the byte from the previous line that has the foreground color and a 0 bit signifying that byte alone. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
MEGA_MEGA_DITHER
0xF8
A long alternating run of two colors. The length of the run, in bytes, is specified in the next 2 bytes between 1 and 65,536. The colors are specified in the following 2 bytes as 1 byte each.
SPECIAL_FGBG_CODE_1
0xF9
The 2 bytes that are the XOR of the uncompressed bytes from the previous line that has the foreground color, followed by the 6 uncompressed bytes of the previous line. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
SPECIAL_FGBG_CODE_2
0xFA
A byte that is the XOR of the uncompressed bytes from the previous line that has the foreground color, an uncompressed byte from the previous line, another XOR byte, and finally 5 uncompressed bytes. If this code occurs on the first line, the last line SHOULD be considered to have the value 0x00.
BLACK
0xFD
A single black pixel.
WHITE
0xFE
A single white pixel.
START_LOSSY
0xFF
A code specifying that all the following codes SHOULD have their byte count doubled: MEGA_COLOR_IMAGE, COLOR_IMAGE, MEGA_PACKED_CLR_IMAGE, PACKED_COLOR_IMAGE, MEGA_MEGA_CLR_IMG, and MEGA_MEGA_PACKED_CLR. Pixel pairs that begin with black SHOULD render as two black pixels followed by two of the next pixel. All other pairs SHOULD render dithered.
By default, the foreground color is assumed to be 0xFF (white). This color can be changed at any point in the bitmap for all the pixels through the use of the following codes: SET_FG_MEGA_FG_RUN, SET_FG_FG_RUN, SET_FG_MEGA_FG_BG, SET_FG_FG_BG, MEGA_MEGA_SET_FG_RUN, or MEGA_MEGA_SET_FGBG.
Encoding MUST NOT cross the boundary between the first line and the rest of the bitmap.
Any sequence of two BG_RUN codes MUST be separated by a single byte, which is the XOR of the byte from the previous line with the foreground color. The same applies to any combination of MEGA_MEGA_BG_RUN, MEGA_BG_RUN, and BG_RUN.
Note: 4 bits-per-pixel images MUST be expanded to a full byte before compression.