2.2.9.1.1.3.1.2.4 RLE Compressed Bitmap Stream (RLE_BITMAP_STREAM)

The RLE_BITMAP_STREAM structure contains a stream of bitmap data compressed using Interleaved Run-Length Encoding (RLE). Bitmap data compressed by the server MUST follow a Compressed Data Header (section 2.2.9.1.1.3.1.2.3) structure unless the exclusion of this header has been specified in the General Capability Set (section 2.2.7.1.1).

A compressed bitmap is sent as a series of compression orders that instruct the decoder how to reassemble a compressed bitmap (a particular bitmap can have many valid compressed representations). A compression order consists of an order header, followed by an optional encoded run length, followed by optional data associated with the compression order. Some orders require the decoder to refer to the previous scanline of bitmap data and because of this fact the first scanline sometimes requires special cases for decoding.

Standard Compression Orders begin with a one-byte order header. The high order bits of this header contain a code identifier, while the low order bits store the unsigned length of the associated run (unless otherwise specified). There are two forms of Standard Compression Orders:

  • The regular form contains a 3-bit code identifier and a 5-bit run length.

  • The lite form contains a 4-bit code identifier and a 4-bit run length.

For both the regular and lite forms a run length of zero indicates an extended run (a MEGA run), where the byte following the order header contains the encoded length of the associated run. The encoded run length is calculated using the following formula (unless otherwise specified):

 EncodedMegaRunLength = RunLength - (MaximumNonMegaRunLength + 1)

The maximum run length that can be stored in a non-MEGA regular order is 31, while a non-MEGA lite order can only store a maximum run length of 15.

Extended Compression Orders begin with a one-byte order header which contains an 8-bit code identifier. There are two types of Extended Compression Orders:

  • The MEGA_MEGA type stores the unsigned length of the associated run in the two bytes following the order header (in little-endian order).

  • The single-byte type is used to encode short, commonly occurring foreground/background sequences and single black or white pixels.

Pseudo-code describing how to decompress a compressed bitmap stream can be found in section 3.1.9.


0


1


2


3


4


5


6


7


8


9

1
0


1


2


3


4


5


6


7


8


9

2
0


1


2


3


4


5


6


7


8


9

3
0


1

rleCompressedBitmapStream (variable)

...

rleCompressedBitmapStream (variable): An array of compression codes describing compressed structures in the bitmap.

Background Run Orders

A Background Run Order encodes a run of pixels where each pixel in the run matches the uncompressed pixel on the previous scanline. If there is no previous scanline then each pixel in the run MUST be black.

When encountering back-to-back background runs, the decompressor MUST write a one-pixel foreground run to the destination buffer before processing the second background run if both runs occur on the first scanline or after the first scanline (if the first run is on the first scanline, and the second run is on the second scanline, then a one-pixel foreground run MUST NOT be written to the destination buffer). This one-pixel foreground run is counted in the length of the run.

The run length encodes the number of pixels in the run. There is no data associated with Background Run Orders.

Code Identifier

Meaning

REGULAR_BG_RUN

0x0

The compression order encodes a regular-form background run. The run length is stored in the five low-order bits of the order header byte. If this value is zero, then the run length is encoded in the byte following the order header and MUST be incremented by 32 to give the final value.

MEGA_MEGA_BG_RUN

0xF0

The compression order encodes a MEGA_MEGA background run. The run length is stored in the two bytes following the order header (in little-endian format).

Foreground Run Orders

A Foreground Run Order encodes a run of pixels where each pixel in the run matches the uncompressed pixel on the previous scanline XOR'd with the current foreground color. The initial foreground color MUST be white. If there is no previous scanline, then each pixel in the run MUST be set to the current foreground color.

The run length encodes the number of pixels in the run.

If the order is a "set" variant, then in addition to encoding a run of pixels, the order also encodes a new foreground color (in little-endian format) in the bytes following the optional run length. The current foreground color MUST be updated with the new value before writing the run to the destination buffer.

Code Identifier

Meaning

REGULAR_FG_RUN

0x1

The compression order encodes a regular-form foreground run. The run length is stored in the five low-order bits of the order header byte. If this value is zero, then the run length is encoded in the byte following the order header and MUST be incremented by 32 to give the final value.

MEGA_MEGA_FG_RUN

0xF1

The compression order encodes a MEGA_MEGA foreground run. The run length is stored in the two bytes following the order header (in little-endian format).

LITE_SET_FG_FG_RUN

0xC

The compression order encodes a "set" variant lite-form foreground run. The run length is stored in the four low-order bits of the order header byte. If this value is zero, then the run length is encoded in the byte following the order header and MUST be incremented by 16 to give the final value.

MEGA_MEGA_SET_FG_RUN

0xF6

The compression order encodes a "set" variant MEGA_MEGA foreground run. The run length is stored in the two bytes following the order header (in little-endian format).

Dithered Run Orders

A Dithered Run Order encodes a run of pixels which is composed of two alternating colors. The two colors are encoded (in little-endian format) in the bytes following the optional run length.

The run length encodes the number of pixel-pairs in the run (not pixels).

Code Identifier

Meaning

LITE_DITHERED_RUN

0xE

The compression order encodes a lite-form dithered run. The run length is stored in the four low-order bits of the order header byte. If this value is zero, then the run length is encoded in the byte following the order header and MUST be incremented by 16 to give the final value.

MEGA_MEGA_DITHERED_RUN

0xF8

The compression order encodes a MEGA_MEGA dithered run. The run length is stored in the two bytes following the order header (in little-endian format).

Color Run Orders

A Color Run Order encodes a run of pixels where each pixel is the same color. The color is encoded (in little-endian format) in the bytes following the optional run length.

The run length encodes the number of pixels in the run.

Code Identifier

Meaning

REGULAR_COLOR_RUN

0x3

The compression order encodes a regular-form color run. The run length is stored in the five low-order bits of the order header byte. If this value is zero, then the run length is encoded in the byte following the order header and MUST be incremented by 32 to give the final value.

MEGA_MEGA_COLOR_RUN

0xF3

The compression order encodes a MEGA_MEGA color run. The run length is stored in the two bytes following the order header (in little-endian format).

Foreground / Background Image Orders

A Foreground/Background Image Order encodes a binary image where each pixel in the image that is not on the first scanline fulfills exactly one of the following two properties:

(a) The pixel matches the uncompressed pixel on the previous scanline XOR'ed with the current foreground color.

(b) The pixel matches the uncompressed pixel on the previous scanline.

If the pixel is on the first scanline then it fulfills exactly one of the following two properties:

(c) The pixel is the current foreground color.

(d) The pixel is black.

The binary image is encoded as a sequence of byte-sized bitmasks which follow the optional run length (the last bitmask in the sequence can be smaller than one byte in size). If the order is a "set" variant then the bitmasks MUST follow the bytes which specify the new foreground color. Each bit in the encoded bitmask sequence represents one pixel in the image. A bit that has a value of 1 represents a pixel that fulfills either property (a) or (c), while a bit that has a value of 0 represents a pixel that fulfills either property (b) or (d). The individual bitmasks MUST each be processed from the low-order bit to the high-order bit.

The run length encodes the number of pixels in the run.

If the order is a "set" variant, then in addition to encoding a binary image, the order also encodes a new foreground color (in little-endian format) in the bytes following the optional run length. The current foreground color MUST be updated with the new value before writing the run to the destination buffer.

Code Identifier

Meaning

REGULAR_FGBG_IMAGE

0x2

The compression order encodes a regular-form foreground/background image. The run length is encoded in the five low-order bits of the order header byte and MUST be multiplied by 8 to give the final value. If this value is zero, then the run length is encoded in the byte following the order header and MUST be incremented by 1 to give the final value.

MEGA_MEGA_FGBG_IMAGE

0xF2

The compression order encodes a MEGA_MEGA foreground/background image. The run length is stored in the two bytes following the order header (in little-endian format).

LITE_SET_FG_FGBG_IMAGE

0xD

The compression order encodes a "set" variant lite-form foreground/background image. The run length is encoded in the four low-order bits of the order header byte and MUST be multiplied by 8 to give the final value. If this value is zero, then the run length is encoded in the byte following the order header and MUST be incremented by 1 to give the final value.

MEGA_MEGA_SET_FGBG_IMAGE

0xF7

The compression order encodes a "set" variant MEGA_MEGA foreground/background image. The run length is stored in the two bytes following the order header (in little-endian format).

Color Image Orders

A Color Image Order encodes a run of uncompressed pixels.

The run length encodes the number of pixels in the run. So, to compute the actual number of bytes which follow the optional run length, the run length MUST be multiplied by the color depth (in bits-per-pixel) of the bitmap data.

Code Identifier

Meaning

REGULAR_COLOR_IMAGE

0x4

The compression order encodes a regular-form color image. The run length is stored in the five low-order bits of the order header byte. If this value is zero, then the run length is encoded in the byte following the order header and MUST be incremented by 32 to give the final value.

MEGA_MEGA_COLOR_IMAGE

0xF4

The compression order encodes a MEGA_MEGA color image. The run length is stored in the two bytes following the order header (in little-endian format).

Special Orders

Code Identifier

Meaning

SPECIAL_FGBG_1

0xF9

The compression order encodes a foreground/background image with an 8-bit bitmask of 0x03.

SPECIAL_FGBG_2

0xFA

The compression order encodes a foreground/background image with an 8-bit bitmask of 0x05.

WHITE

0xFD

The compression order encodes a single white pixel.

BLACK

0xFE

The compression order encodes a single black pixel.

Show: