Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
NSCodec run-length encoding produces three types of sequences:
Literal sequences
Short run sequences
Long run sequences
The data in an input stream MUST be transformed according to the following rules:
If there are four or fewer bytes remaining in the input stream, copy the bytes unmodified to the output stream. The encoding is finished.
If the current byte to encode is followed by a byte with a different value, a literal has been identified. Write the byte value to the output stream and advance forward in the input stream by one byte.
If the total count of repeating byte values starting at the current position in the input stream and before the last four bytes is larger than 1 and strictly less than 256, then a short run has been identified. Write the current byte value to the output stream twice, and then write the count of identical positions minus 2. Advance forward in the input stream by the number of bytes equal to the count.
If the total count of repeating byte values starting at the current position and before the end of the stream is 256 or more, a long run has been identified. Write the current byte value to the output stream twice, write the constant 0xFF to the output stream, and then write the count of identical positions as a 32-bit little-endian value. Advance forward in the input stream by the number of bytes equal to the count.
Note that a run greater than 2^32 bytes is not possible, as the maximum size of an individual desktop is capped at 4,096 x 2,048 pixels (33,554,432 bytes at 32bpp); see [MS-RDPBCGR] section 2.2.1.3.2, specifically the desktopWidth and desktopHeight fields, which point out the server-side restriction.
The following flowchart illustrates how an input stream is processed by using the NSCodec RLE rules to produce run-length sequences.
Figure 3: Encoding data by using NSCodec run-length encoding (RLE)