H2O

From MultimediaWiki
Jump to navigation Jump to search

This is an animation format that uses 16-bit static Huffman coding along with the fill/skip/pattern block coding.

File header (all values are little-endian):

 4 bytes - "H2O\x01"
 4 bytes - frame width
 4 bytes - frame height
 4 bytes - number of frames
 48 bytes - unknown

Each frame starts with 24-bit full frame size and 8-bit flags telling which kinds of payloads frame has. Each payload starts with 32-bit size so it can be skipped. Known payloads are:

  • 0x80 - new frame parameters (first two 32-bit words are new frame width and height)
  • 0x40 - code definitions
  • 0x01 - palette update
  • 0x02 - video data

Please note that video data comes last.

Code definitions

This data defines canonical Huffman codes. It starts with two bytes telling the shortest and the longest code lengths. Then for each of the possible code lengths there is a 16-bit number telling how many codes have such length followed by the 16-bit values for those codes.

The defined codebook is used to unpack video data before processing it further.

Palette update

Palette updates are transmitted as one or more regions. First 16-bit value tells how many regions are total in the update. Each region start with a byte telling how many colours to skip from the end of the previous region (or 0 for the first region) and a byte telling how many colours are there in the region (0 means all 256 colours). Then a standard VGA palette follows.

Video decompression

After unpacking data as a stream of 16-bit values, those values are used as opcodes and data to reconstruct 4x4 blocks.

Top four bits of the opcode represent an operation:

  • 0-3 - fill blocks. Bits 8-13 of the opcode (i.e. including the operation bits) represent run length (0-59 = 1-60, 60-63 = 128,256,512,1024), bits 0-7 are fill value (0 means skip instead of fill);
  • 4 - two-colour pattern fill. Bits 0-11 of the opcode tell how many blocks to process this way (minus one). Then for each block there's 16-bit mask and two colours (16-bit value re-interpreted as two bytes);
  • 5 - masked update. Bits 0-11 of the opcode tell how many blocks to process this way (minus one). Then for each block there's 16-bit mask telling which bits of the block to update and new pixel values packed in 16-bit elements (for odd number of pixels last value is stored in its own 16-bit value);
  • other values are invalid.