show alpha2 country code strings next to the flag in the country code selectors....
[twcon.git] / src / engine / shared / huffman.h
blob0d15ed9979ad2ee13d3ee952f7a735fed9c4e73a
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
8 class CHuffman
10 enum
12 HUFFMAN_EOF_SYMBOL = 256,
14 HUFFMAN_MAX_SYMBOLS=HUFFMAN_EOF_SYMBOL+1,
15 HUFFMAN_MAX_NODES=HUFFMAN_MAX_SYMBOLS*2-1,
17 HUFFMAN_LUTBITS = 10,
18 HUFFMAN_LUTSIZE = (1<<HUFFMAN_LUTBITS),
19 HUFFMAN_LUTMASK = (HUFFMAN_LUTSIZE-1)
22 struct CNode
24 // symbol
25 unsigned m_Bits;
26 unsigned m_NumBits;
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];
37 CNode *m_pStartNode;
38 int m_NumNodes;
40 void Setbits_r(CNode *pNode, int Bits, unsigned Depth);
41 void ConstructTree(const unsigned *pFrequencies);
43 public:
45 Function: huffman_init
46 Inits the compressor/decompressor.
48 Parameters:
49 huff - Pointer to the state to init
50 frequencies - A pointer to an array of 256 entries of the frequencies of the bytes
52 Remarks:
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.
62 Parameters:
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
69 Returns:
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
76 Decompresses a buffer
78 Parameters:
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
85 Returns:
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__