# Sub-Pictures

The typical arrangement of data in the 53220 byte buffer for sub-pictures is

SPUH | PXDtf | PXDbf | SP_DCSQT
--- | --- | --- | ---

However, the only requirement is that the header (SPUH) be first, all other areas are reached by pointers.

#### SPUH

Sub-Picture Unit Header
2 words (least significant byte last)

offset | name | contents
--- | --- | ---
0 | SPDSZ | the size of the total sub-picture data (which may span packets)
2 | SP_DCSQTA | offset within the Sub-Picture Unit to the SP_DCSQT

#### PXDtf and PXDbf

PiXel Data
These are the rle compressed pixel data for the top field (lines 1, 3, 5, etc) and the bottom field (lines 2, 4, 6, etc) respectively
Individual pixels may have one of four values, commonly referred to as background (0), pattern (1), emphasis 1 (2), and emphasis 2 (3) Each coded value indicates the number of pixels having the same code value, and can be in one of four forms, depending on the number of identical pixels

range | bits | format
--- | --- | ---
1-3 | 4 | n n c c
4-15 | 8 | 0 0 n n n n c c
16-63 | 12 | 0 0 0 0 n n n n n n c c
64-255 | 16 | 0 0 0 0 0 0 n n n n n n n n c c

One special case, encoding a count of zero using the 16-bit format indicates the same pixel value until the end of the line.
If, at the end of a line, the bit count is not a multiple of 8, four fill bits of 0 are added.

#### SP_DCSQT

Sub-Picture Display Control SeQuence Table
This area contains blocks (SP_DCSQ) of commands to the decoder. Each SP_DCSQ begins with a 2 word header

offset | name | contents
--- | --- | ---
0 | SP_DCSQ_STM | delay to wait before executing these commands. The units are 90KHz clock (same as PTM) divided by 1024 - see conversion aids
2 | SP_NXT_DCSQ_SA | offset within the Sub-Picture Unit to the next SP_DCSQ. If this is the last SP_DCSQ, it points to itself.

#### Commands

There are eight commands available for Sub-Pictures. The first SP_DCSQ should contain, as a minimum, SET_COLOR, SET_CONTR, SET_DAREA, and SET_DSPXA.

FF - CMD_END - ends one SP_DCSQ

00 - FSTA_DSP - Forced Start Display, no arguments

01 - STA_DSP - Start Display, no arguments

02 - STP_DSP - Stop Display, no arguments

03 - SET_COLOR - provides four indices into the CLUT for the current PGC to associate with the four pixel values. One nibble per pixel value for a total of 2 bytes.
e2 e1 p b

04 - SET_CONTR - directly provides the four contrast (alpha blend) values to associate with the four pixel values. One nibble per pixel value for a total of 2 bytes. 0x0 = transparent, 0xF = opaque
e2 e1 p b

05 - SET_DAREA - defines the display area, each pair (X and Y) of values is 3 bytes wide, for a total of 6 bytes, and has the form
sx sx sx ex ex ex sy sy sy ey ey ey
sx = starting X coordinate
ex = ending X coordinate
sy = starting Y coordinate
ey = ending Y coordinate

06 - SET_DSPXA - defines the pixel data addresses. First a 2-byte offset to the top field data, followed by a 2-byte offset to the bottom field data, for a total of 4 bytes.

07 - CHG_COLCON - allows for changing the COLor and CONtrast within one or more areas of the display. This command contains a series of parameters, arranged in a hierarchy.
Following the command byte is a 2-byte value for the total size of the parameter area, including the size word.
The parameter sequence begins with a LN_CTLI, which defines a vertically bounded area of the display. The LN_CTLI may include from one to eight PX_CTLI parameters, which define a starting horizontal position and new color and contrast value to apply from that column on towards the right to the next PX_CTLI or the right side of the display.

LN_CTLI, 4 bytes, special value of 0f ff ff ff signifies the end of the parameter area (this termination code MUST be present as the last parameter)
0 s s s n t t t
sss = csln, the starting (top-most) line number for this area (must be > previous LN_CTLI ttt)
n = number_of_changes - number of PX_CTLI to follow (1 to 8)
ttt = ctln, the terminating (bottom-most) line number for this area (must be >= sss)

PX_CTLI, 6 bytes, defines a starting column and new color and contrast values
bytes 0 and 1 - starting column number (must be 8 or more greater than the previous PX_CTLI)
bytes 2 and 3 - new color values, as per SET_COLOR
bytes 4 and 5 - new contrast values, as per SET_CONTR

#### Converting frames and time to SP_DCSQ_STM values

The direct method of converting time to delay values is to multiply time in seconds by 90000/1024 and truncate the value. Rounding up will cause the display to occur one frame late.

Frames | value for NTSC (30fps) | value for PAL/SECAM (25fps)
--- | --- | ---
1 | 2 | 3
2 | 5 | 7
3 | 8 | 10
4 | 11 | 14
5 | 14 | 17
6 | 17 | 21
7 | 20 | 24
8 | 23 | 28
9 | 26 | 31
10 | 29 | 35
11 | 32 | 38
12 | 35 | 42
13 | 38 | 45
14 | 41 | 49
15 | 43 | 52
16 | 46 | 56
17 | 49 | 59
18 | 52 | 63
19 | 55 | 66
20 | 58 | 70
21 | 61 | 73
22 | 64 | 77
23 | 67 | 80
24 | 70 | 84
25 | 73 | (87)
26 | 76 | (91)
27 | 79 | (94)
28 | 82 | (98)
29 | 84 | (101)
seconds | value
--- | ---
1 | 87
2 | 175
3 | 263
4 | 351
5 | 439
6 | 527
7 | 615
8 | 703
9 | 791
10 | 878
20 | 1757
30 | 2636
40 | 3515
50 | 4394
60 | 5273

DVD-Video info home | Copyright © 2001 - 2020 STN Software, all rights reserved.