How SubPictures Work - Part 2
Compression and Colors
Just a 2-bit RLE
Before I get into where the colors come from, let's talk about how the subpicture image is compressed. The method chosen allows each pixel to be assigned one of four values. By convention the pixel values are called:0 background (B)
1 pattern (P)
2 emphasis 1 (E1)
3 emphasis 2 (E2)
The compression method is run length encoded (RLE), which, simply stated, means each compressed code conveys 2 pieces of information, the pixel value (code) and the number of pixels in succesion having the same value (run). RLE works well when large areas have the same value, and so is a good choice for subpictures.
The encoding
The compressed codes are multiples of 4 bits (called nibbles) long. In all encodings the last 2 bits (least significant) contain the pixel value. To encode from 1 to 3 pixels a single nibble is used, with the run length in the first 2 bits. 4 to 15 pixels use 2 nibbles (one byte), and the run length is in the first 6 bits. Notice 2 things, though.- The first 2 bits are 0, so the decoder knows this is not a 4-bit code.
- The next 2 bits are not zero, so the decoder knows this is an 8-bit code.
Run lengths from 16 to 63 use 12 bits, and 64 to 255 use the longest code, the 16-bit code.
Special Cases and Considerations
- If all the pixels from the current position to the end of the line have the same value, it is encoded with 14 zero bits and the pixel value.
- There is no "end of line" code, a line ends when either the width number of pixels have been encoded, or the "until end of line" code (above) is used.
- Each line is encoded seperately, there is no "wrapping". In other words, even if the pixels at the end of one line have the same value as the pixels at the start of the next line, they are encoded seperately.
- A code of 4 zeroes is used to pad out the data to the next byte if a multiple of 8 bits was not used.
- The maximum number of coded bits per line is 1440 (180 bytes).
- The maximun size for subpicture data (including the commands, which are covered later) is 53,220 bytes.
So, where do the 4 colors get defined?
The colors are defined in another layer of indirection. Within the commands for each subpicture are 2 commands, Set Color and Set Contr. The Set Color command specifies a 4-bit value for each of the 4 pixel values. This 4-bit value is an index into the Color LookUp Table (CLUT) with the currently executing PGC.This allows each subpicture to act as a template, with the PGC specifying the actual colors. This is the same method that Windows or most forums (including our own) use to apply color "themes" to page templates.
The Set Contrast command specifies the contrast, or alpha blending, of each pixel value directly.
But is 4 colors per subpicture the max?
NO! Another command, Chg_ColCon (Change Color and Contrast) allows you to divide the subpicture area up into smaller areas, each with its own color and contrast values. There is no arbitrary limit on the number of areas you may define, so it is possible to use all 256 combinations of CLUT colors and contrast values in one subpicture.It is through the use of this command, coupled with the timing ability of subpictures, that wipes and fades of all kinds are performed.
More on this command later.