Kega Video

From MultimediaWiki
Jump to: navigation, search

Codec used for capturing videos in some Sega emulator called Kega.

It produces output in RGB555 and coding is LZ-like.

Frame starts with two bytes which code real dimensions as multiple of 8 minus 1 block (i.e. width = (src[0] + 1) * 8;, same for height), the rest is coded data.

Coded data consists of 16-bit LSB control words with possible extensions:

  1. 111x xxyy yyyy yyyy - copy (y+3) pixels from positive offset offsets[x] in the previous frame. If offsets[x] is not yet defined for this frame, read 24-bit LSB word after this code word. Naturally, this is possible only in interframes. The offset may wrap around the frame, depending on the current output position.
  2. 110y yyyy yyyy yyyy - read run length value minus four from next byte (i.e. run = get_byte() + 4) and copy pixels from negative offset y+1 (e.g. offset 0 means RLE, offset 1 means repeating last two pixels, etc.)
  3. 101y yyyy yyyy yyyy - same as above but always copy 3 pixels from given offset
  4. 100y yyyy yyyy yyyy - same as above but always copy 2 pixels from given offset
  5. 0ppp pppp pppp pppp - p is pixel value, simply output it.

Implementing decoder is left as an exercise for reader.