From 87b4ef5547c23db116466bedaf8b67dd57c19f75 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Mon, 18 Jul 2011 10:27:26 -0400 Subject: COMMON: Update code from eos --- common/huffman.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'common/huffman.cpp') 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++) { -- cgit v1.2.3