xoreos  0.0.5
huffman.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef COMMON_HUFFMAN_H
26 #define COMMON_HUFFMAN_H
27 
28 #include <vector>
29 #include <list>
30 
31 #include "src/common/types.h"
32 
33 namespace Common {
34 
35 class BitStream;
36 
37 struct HuffmanTable {
39  size_t codeCount;
40 
41  const uint32 *codes;
42  const uint8 *lengths;
43  const uint32 *symbols;
44 };
45 
47 class Huffman {
48 public:
57  Huffman(uint8 maxLength, size_t codeCount, const uint32 *codes,
58  const uint8 *lengths, const uint32 *symbols = 0);
59  Huffman(const HuffmanTable &table);
60  ~Huffman();
61 
63  void setSymbols(const uint32 *symbols = 0);
64 
66  uint32 getSymbol(BitStream &bits) const;
67 
68 private:
69  struct Symbol {
72 
73  Symbol(uint32 c, uint32 s);
74  };
75 
76  typedef std::list<Symbol> CodeList;
77  typedef std::vector<CodeList> CodeLists;
78  typedef std::vector<Symbol *> SymbolList;
79 
82 
85 
86  void init(uint8 maxLength, size_t codeCount, const uint32 *codes,
87  const uint8 *lengths, const uint32 *symbols);
88 };
89 
90 } // End of namespace Common
91 
92 #endif // COMMON_HUFFMAN_H
void setSymbols(const uint32 *symbols=0)
Modify the codes&#39; symbols.
Definition: huffman.cpp:80
Symbol(uint32 c, uint32 s)
Definition: huffman.cpp:34
Definition: 2dafile.h:39
std::list< Symbol > CodeList
Definition: huffman.h:76
uint8_t uint8
Definition: types.h:200
const uint8 * lengths
The lengths of the individual codes.
Definition: huffman.h:42
uint32 getSymbol(BitStream &bits) const
Return the next symbol in the bitstream.
Definition: huffman.cpp:85
uint8 maxLength
Maximal code length. If 0, it&#39;s searched for.
Definition: huffman.h:38
Huffman(uint8 maxLength, size_t codeCount, const uint32 *codes, const uint8 *lengths, const uint32 *symbols=0)
Construct a Huffman decoder.
Definition: huffman.cpp:42
Decode a Huffman&#39;d bitstream.
Definition: huffman.h:47
std::vector< Symbol * > SymbolList
Definition: huffman.h:78
Low-level type definitions to handle fixed width types portably.
SymbolList _symbols
Sorted list of pointers to the symbols.
Definition: huffman.h:84
const uint32 * symbols
The symbols, 0 if identical to the codes.
Definition: huffman.h:43
uint32_t uint32
Definition: types.h:204
CodeLists _codes
Lists of codes and their symbols, sorted by code length.
Definition: huffman.h:81
size_t codeCount
Number of codes.
Definition: huffman.h:39
const uint32 * codes
The actual codes.
Definition: huffman.h:41
void init(uint8 maxLength, size_t codeCount, const uint32 *codes, const uint8 *lengths, const uint32 *symbols)
Definition: huffman.cpp:48
A bit stream.
Definition: bitstream.h:40
std::vector< CodeList > CodeLists
Definition: huffman.h:77