diff options
Diffstat (limited to 'common/huffman.cpp')
-rw-r--r-- | common/huffman.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/common/huffman.cpp b/common/huffman.cpp index 668e2216c9..a8ebe4142a 100644 --- a/common/huffman.cpp +++ b/common/huffman.cpp @@ -34,12 +34,17 @@ Huffman::Symbol::Symbol(uint32 c, uint32 s) : code(c), symbol(s) { Huffman::Huffman(uint8 maxLength, uint32 codeCount, const uint32 *codes, const uint8 *lengths, const uint32 *symbols) { - assert(maxLength > 0); assert(codeCount > 0); assert(codes); assert(lengths); + if (maxLength == 0) + for (uint32 i = 0; i < codeCount; i++) + maxLength = MAX(maxLength, lengths[i]); + + assert(maxLength <= 32); + _codes.resize(maxLength); _symbols.resize(codeCount); @@ -63,7 +68,7 @@ void Huffman::setSymbols(const uint32 *symbols) { _symbols[i]->symbol = symbols ? *symbols++ : i; } -uint32 Huffman::getSymbol(BitStream &bits) { +uint32 Huffman::getSymbol(BitStream &bits) const { uint32 code = 0; for (uint32 i = 0; i < _codes.size(); i++) { |