Huffman Codec
object HuffmanCodec
Nintendo DS Huffman codec.
Supports both the 4-bit (magic 0x24) and 8-bit (magic 0x28) variants of the Nintendo DS Huffman compression format as documented in GBATek / CUE references.
Compressed file layout
byte 0 : magic (0x24 = 4-bit, 0x28 = 8-bit)
bytes 1-3 : uncompressed size, 24-bit little-endian
byte 4 : halfTreeSize (H) — tree occupies (H+1)*2 bytes
bytes 5..5+(H+1)*2-1 : Huffman tree node pairs
(padding to next 4-byte boundary)
remaining : compressed data as 32-bit little-endian words, bits consumed MSB-firstContent copied to clipboard
Tree node pair format
Each node is a pair of two bytes at indices [2*n, 2*n+1]:
leftDesc = tree[2*n]rightDesc = tree[2*n+1]
For a descriptor byte d at node pair index n:
bits 5-0 : offset from the next pair; child pair index =
n + 1 + (d & 0x3F)bit 7 of
leftDesc: left child is a leafbit 6 of
leftDesc: right child is a leaf
When the child is a leaf, the symbol value is stored in tree[childPair * 2] (first byte of the child pair).