I am trying to write a decoder for an old video format used in a DOS game, the Psygnosis SMV video format, but I'm having a hard time understanding the image decoding process, specifically this section:
Macroblocks drawing
Macroblocks are stored in the following format:
u8 pixels[16 * num_mblocks]
u4 nibbles[num_mblocks]
Size of pixels[] is equal to ST chunk's nibbles.
For each macroblock draw it by indexing its pixels by nibbles.
First nibble stored in top 4 bits of byte.
Here are the properties of the frame I am trying to decode:
- image width = 320
- image height = 192
- macroblock width = 16
- macroblock height = 16
- nibbles = 3840
- frame size in bytes = 34560
So according these, I computed the following values:
num_mblocks = nibbles / 16 = 3840 / 16 = 240 macroblocks
further checking:
(image width / macroblock width) * (image height / macroblock height)
= (320 / 16) * (192 / 16)
= 20 * 12
= 240 macroblocks
1st problem:
The size of u8 pixels[16 * num_mblocks]
is indeed 3840 bytes, but what is the size of u4 nibbles[num_mblocks]
supposed to be ? 240 bytes or half that amount since the type is u4
?
2nd problem:
When I divide the frame size in bytes
by the number of macroblocks
I end up with only 144 bytes per macroblock (34560 / 240 = 144), but to me this is very far from what it's supposed to be, I guess I'm wrong somewhere.
3rd problem:
The author wrote:
For each macroblock draw it by indexing its pixels by nibbles.
But what does that mean exactly ?
Question
Can you explain/shed some light on how one is supposed to decode a frame ?