Escape 122
- Company: Eidos Technologies
- Samples: http://samples.mplayerhq.hu/game-formats/rpl/bigredracing-escape122/
The ESCAPE 122 codec is a relatively simple 8-bit palettized video compression engine based on multipass BTC encoding and operates with 8x8 "superblocks" combined from 2x2 macroblocks.
The packed video stream is usually stored within an ARMovie container. Each frame chunk begins with an 8-byte header (here and below all numbers are little-endian):
dword video_size - size of the video portion dword audio_size - size of the audio portion
Video data starts immediately after this header and is followed by audio data (if any).
Note: The existing original decoder implementation only supports 320x200 video. Only one sample file encoded in this resolution is known so far.
Video portion
The first 2 bytes of the chunk indicate the length of the following palette block. Palette is stored as standard VGA DAC B-G-R triplets and includes a variable number of color entries, which can be determined by dividing palette length by 3 and rounding result toward zero (thus, block length may not necessarily be a multiple of 3). Right after the palette block the actual compressed frame data begins.
The Video decoding algorithm operates as follows:
repeat
skip_value = RICE_Decode()
skip skip_value number of 8x8 superblocks (keep them unchanged from the last frame)
if all blocks drawn/skipped
finish
while next bit of the stream is zero
new_block = Decode_MacroBlock()
mask = read 4*4 (number of macroblocks in superblock) bits
for each macroblock of superblock (left to right, top to bottom)
if next bit of mask (from low to high) is set
macroblock = new_block
if next bit of the stream is zero
mask = read 4*4 (number of macroblocks in superblock) bits
for each macroblock of superblock (left to right, top to bottom)
if next bit of mask (from low to high) is set
macroblock = Decode_MacroBlock()
advance to the next superblock
The RICE_Decode performs RICE-like value unpacking and operates as follows:
value = 0
more_bits = read 1 bit from the stream
if 1 bit of more_bits is set
value = value + more_bits
more_bits = read 3 bits from the stream
value = value + more_bits
if 3 bits of more_bits is set
more_bits = read 7 bits from the stream
value = value + more_bits
if 7 bits of more_bits is set
more_bits = read 12 bits from the stream
value = value + more_bits
Decode_Macroblock performs 2x2 macroblock decoding:
read 2*2 (number of pixels in macroblock) mask bits from the stream
if all mask bits are set or clear
read 7 top bits of color from the stream
the lowest bit of color is the any bit of mask
fill whole macroblock with color
else
read 8 bits of color0 from the stream
read 8 bits of color1 from the stream
for each pixel of macroblock (left to right, top to bottom)
if next bit of mask (from low to high) is set
pixel = color1
else
pixel = color0
Audio portion
TODO: Insert IMA ADPCM description & link here