From 0f57aea2df2a1272b57de896e2f6aad80809e5d3 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Mon, 8 Apr 2019 19:24:00 +0200 Subject: COMMON: Use a prefix table to speed up the Huffman decoder Symbols for codes shorter than the prefix table index width are stored in the table. All the entries in the table with an index starting with the code are set to the symbol value. That way, when decoding it is possible to get the number of bits corresponding to the table width from the bitstream and directly find the symbol value. Longer code still need to be searched for in the codes list. --- image/codecs/svq1.cpp | 12 ++++++------ image/codecs/svq1.h | 15 +++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'image/codecs') diff --git a/image/codecs/svq1.cpp b/image/codecs/svq1.cpp index 2d86070801..eba5fb872a 100644 --- a/image/codecs/svq1.cpp +++ b/image/codecs/svq1.cpp @@ -56,16 +56,16 @@ SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) { _last[2] = 0; // Setup Variable Length Code Tables - _blockType = new Common::Huffman(0, 4, s_svq1BlockTypeCodes, s_svq1BlockTypeLengths); + _blockType = new HuffmanDecoder(0, 4, s_svq1BlockTypeCodes, s_svq1BlockTypeLengths); for (int i = 0; i < 6; i++) { - _intraMultistage[i] = new Common::Huffman(0, 8, s_svq1IntraMultistageCodes[i], s_svq1IntraMultistageLengths[i]); - _interMultistage[i] = new Common::Huffman(0, 8, s_svq1InterMultistageCodes[i], s_svq1InterMultistageLengths[i]); + _intraMultistage[i] = new HuffmanDecoder(0, 8, s_svq1IntraMultistageCodes[i], s_svq1IntraMultistageLengths[i]); + _interMultistage[i] = new HuffmanDecoder(0, 8, s_svq1InterMultistageCodes[i], s_svq1InterMultistageLengths[i]); } - _intraMean = new Common::Huffman(0, 256, s_svq1IntraMeanCodes, s_svq1IntraMeanLengths); - _interMean = new Common::Huffman(0, 512, s_svq1InterMeanCodes, s_svq1InterMeanLengths); - _motionComponent = new Common::Huffman(0, 33, s_svq1MotionComponentCodes, s_svq1MotionComponentLengths); + _intraMean = new HuffmanDecoder(0, 256, s_svq1IntraMeanCodes, s_svq1IntraMeanLengths); + _interMean = new HuffmanDecoder(0, 512, s_svq1InterMeanCodes, s_svq1InterMeanLengths); + _motionComponent = new HuffmanDecoder(0, 33, s_svq1MotionComponentCodes, s_svq1MotionComponentLengths); } SVQ1Decoder::~SVQ1Decoder() { diff --git a/image/codecs/svq1.h b/image/codecs/svq1.h index 148501d17f..4a005761a5 100644 --- a/image/codecs/svq1.h +++ b/image/codecs/svq1.h @@ -27,6 +27,7 @@ #include "image/codecs/codec.h" namespace Common { +template class Huffman; struct Point; } @@ -53,12 +54,14 @@ private: byte *_last[3]; - Common::Huffman *_blockType; - Common::Huffman *_intraMultistage[6]; - Common::Huffman *_interMultistage[6]; - Common::Huffman *_intraMean; - Common::Huffman *_interMean; - Common::Huffman *_motionComponent; + typedef Common::Huffman HuffmanDecoder; + + HuffmanDecoder *_blockType; + HuffmanDecoder *_intraMultistage[6]; + HuffmanDecoder *_interMultistage[6]; + HuffmanDecoder *_intraMean; + HuffmanDecoder *_interMean; + HuffmanDecoder *_motionComponent; bool svq1DecodeBlockIntra(Common::BitStream32BEMSB *s, byte *pixels, int pitch); bool svq1DecodeBlockNonIntra(Common::BitStream32BEMSB *s, byte *pixels, int pitch); -- cgit v1.2.3