3.1.9.2 Run-Length Encoding

Each color plane can be individually run-length compressed. The RDP 6.0 Bitmap Compressor uses a simple scan-line compressor that breaks each scan-line into segments consisting of RAW and RUN components.

A RAW component is a non-repeating sequence in the segment, and a RUN is a sequence of the last RAW value repeated run-length times. A RUN in a segment MUST be at least three values long (shorter sequences are encoded as RAW values). In the majority of cases, a segment will contain both a RAW and a RUN component. However, depending on the scan-line to be compressed, it is possible that only a RAW or RUN component is present. In the absence of a RAW component, the RAW value used to decode the RUN component is assumed to be the value zero.

For example, an initial scan-line containing the following 12 ANSI characters:

 AAAABBCCCCCD

Would become the following:

 RAW [A];   RUN [3] - Segment 1     
 RAW [BBC]; RUN [4] - Segment 2 (BB is too short to be a RUN.)
 RAW [D];   RUN [0] - Segment 3 (The scan line is completed.)

The encoded RAW and RUN values are either absolute values (this is the case for the first scan-line) or delta values (this is the case for all other scan-lines). Delta values are relative to the previous scan-line values. The delta value calculation is performed by subtracting the previous scan-line value at the current column location from the current scan-line value being encoded.

An example of delta value usage follows (decimal values used for clarity).

 10, 20, 30, 40, 50, 60 - First scan-line
  5, 15, 25, 35, 45, 55 - Second scan-line
  5, 15, 25, 35, 45, 55 - Third scan-line

Converted to delta values:

  
 10, 20, 30, 40, 50, 60 - First scan-line (absolute values)
 -5, -5, -5, -5, -5, -5 - Second scan-line (delta values)
  0,  0,  0,  0,  0,  0 - Third scan-line (delta values)

Which, converted to segments, become the following:

  
 RAW [10,20,30,40,50,60]; RUN [0]
 RAW [-5];                RUN [5]
 RAW [<none>];            RUN [6] (Previous base value assumed to be 0.)

Due to the fact that the lengths of RAW and RUN components are limited to 4-bit values (see section 2.2.2.5.1.2), individual segments can be broken up further into subsegments during encoding to produce RUN sequences consisting of more than 16 values.