1 /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2 /* If you are missing that file, acquire a complete release at teeworlds.com. */
3 #ifndef ENGINE_SHARED_HUFFMAN_H
4 #define ENGINE_SHARED_HUFFMAN_H
12 HUFFMAN_EOF_SYMBOL
= 256,
14 HUFFMAN_MAX_SYMBOLS
=HUFFMAN_EOF_SYMBOL
+1,
15 HUFFMAN_MAX_NODES
=HUFFMAN_MAX_SYMBOLS
*2-1,
18 HUFFMAN_LUTSIZE
= (1<<HUFFMAN_LUTBITS
),
19 HUFFMAN_LUTMASK
= (HUFFMAN_LUTSIZE
-1)
28 // don't use pointers for this. shorts are smaller so we can fit more data into the cache
29 unsigned short m_aLeafs
[2];
31 // what the symbol represents
32 unsigned char m_Symbol
;
35 CNode m_aNodes
[HUFFMAN_MAX_NODES
];
36 CNode
*m_apDecodeLut
[HUFFMAN_LUTSIZE
];
40 void Setbits_r(CNode
*pNode
, int Bits
, unsigned Depth
);
41 void ConstructTree(const unsigned *pFrequencies
);
45 Function: huffman_init
46 Inits the compressor/decompressor.
49 huff - Pointer to the state to init
50 frequencies - A pointer to an array of 256 entries of the frequencies of the bytes
53 - Does no allocation what so ever.
54 - You don't have to call any cleanup functions when you are done with it
56 void Init(const unsigned *pFrequencies
);
59 Function: huffman_compress
60 Compresses a buffer and outputs a compressed buffer.
63 huff - Pointer to the huffman state
64 input - Buffer to compress
65 input_size - Size of the buffer to compress
66 output - Buffer to put the compressed data into
67 output_size - Size of the output buffer
70 Returns the size of the compressed data. Negative value on failure.
72 int Compress(const void *pInput
, int InputSize
, void *pOutput
, int OutputSize
);
75 Function: huffman_decompress
79 huff - Pointer to the huffman state
80 input - Buffer to decompress
81 input_size - Size of the buffer to decompress
82 output - Buffer to put the uncompressed data into
83 output_size - Size of the output buffer
86 Returns the size of the uncompressed data. Negative value on failure.
88 int Decompress(const void *pInput
, int InputSize
, void *pOutput
, int OutputSize
);
91 #endif // __HUFFMAN_HEADER__