Video Encoding

Overview

Video is represented on a 4-bit gray scale, with 0 representing white and 15 representing black. Two sizes are supported, either 160 x 120, or 320 x 240 pixels (vertical x horizontal). Each video frame is subdivided into 8 x 8 pixel squares. Each square is identified by a Square ID, numbered consecutively from 0, left to right, top to bottom. A square is transmitted if it is sufficiently different from the version that was most recently transmitted, or if a specified number of frames have elapsed since it was last transmitted (the latter mechanism provides a degree of redundancy to mitigate the effect of lost packets). A square that has been selected for transmission is compressed in the spatial domain using a lossless algorithm that works as follows.

The ith row in a square, Row[i], is constructed from the preceding row, Row[i-1], according to the following formula:

Row[i] = Row[i-1] - InterRow[i] + IntraRow[i]   for i = 1,2,...,8.
Each term in the equation is a 32-bit quantity, and operations are performed using standard integer arithmetic. When constructing the 1st row in a square, Row[i-1] is always taken to be 0x88888888. The value of InterRow[i] is determined from a 4-bit code, C[i], according to the table given below. The value of IntraRow[i] is determined by 0, 8, 16 or 32 bits of additional data, the amount of which is determined by C[i] according to the IntraRow Bits column in the table below. The values of C and InterRow are displayed in hexadecimal.

  C     InterRow  IntraRow Bits		

  1     DDDDDDDE       0
  4     EEEEEEEF       0
  7     00000000       0
  A     11111111       0
  D     22222222       0

  2     EEEEEEEF       8 
  5     00000000       8
  8     11111111       8
  B     22222222       8
  E     33333333       8

  3     00000000      16
  6     11111111      16
  9     22222222      16
  C     33333333      16
  F     44444444      16

  0     00000000      32
 
When there are 0 IntraRow Bits, the value of IntraRow is 0. When there are 8 IntraRow Bits, the value of IntraRow satisfies 0xEEEEEEEE & IntraRow = 0, with the 8 bits of additional data corresponding to the least significant bits of each of the 4-bit nibbles in IntraRow. When there are 16 IntraRow Bits, the value of IntraRow satisfies 0xCCCCCCCC & IntraRow = 0, with the 16 bits of additional data corresponding to the least significant 2 bits of each 4-bit nibble in IntraRow. The following table displays the conversion of 1 or 2 bytes of IntraRow Data into an IntraRow value, in binary notation:
IntraRow Bits  IntraRow Data                   IntraRow
     8         abcdefgh             000a000b000c000d000e000f000g000h
    16         abcdefgh ijklmnop    00ab00cd00ef00gh00ij00kl00mn00op
When there are 32 IntraRow Bits, then the additional data is the actual value of the current row.

Video Packet Format


A compressed square is represented in a video packet according to the format given below. This pattern is repeated for as many squares as need be transmitted.
    0              8              16             24            31
    +--------------+--------------+--------------+--------------+
    |          Square ID          |   C1  |  C2  |  C3  |   C4  |
    +--------------+--------------+--------------+--------------+
    |   C5 |  C6   |  C7   |  C8  |       IntraRow Data         |
    +--------------+--------------+                             |
                              ...
    |                                            +--------------+
    |                                            |
    +--------------+--------------+--------------+  

00h - Square ID (2 bytes - unsigned integer)
A value in the range 0-299 for 120 x 160 video, or the range 0-1199 for 240 x 320 video, which identifies the location of the subsequent 8x8 compressed square in the video image. Square ID numbering begins in the upper left corner of the image and proceeds left to right, top to bottom.

02h - C1...C8 (4 bytes - array of 4-bit values)
An array of 8 4-bit codes, one for each row in the square. The value of the ith code, along with the value of the (i-1)th row, plus 0, 8, 16 or 32 bits of additional IntraRow data, determines the value of the ith row in the square.

06h - IntraRow Data (0 - 32 bytes - array of char)
Between 0 and 32 bytes of supporting data that define the variation within each square row which is not predicted by a constant offset from the preceding row. Each of the 8 rows requires 0,1,2 or 4 bytes of supporting data, as determined by the value of C[i].