Escape 122
The ESCAPE 122 codec is a relatively simple 8-bit palletized video compression engine based on multipass BTC encoding and operates with 8x8 "superblocks" combined from 2x2 macroblocks.
Packed video stream usually stored within ARMovie container. Each frame chunk begins with 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 started immediately after this header and followed by audio data (if any).
Note: Existing original decoder implementation only supports 320x200 video. Only one sample file encoded in this resolution is known so far.
Video portion
First 2 bytes of the chunk indicates following palette block length. Palette stored as standard VGA DAC B-G-R triplets and includes variable number of color entries, which can be determinated by dividing palette length by 3 and rounding result toward zero (thus, block length may not necessarily be a multiply of 3). Right after pallete block actual compressed frame data begins.
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 is 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