diff options
author | Willem Jan Palenstijn | 2017-08-24 19:51:06 +0200 |
---|---|---|
committer | GitHub | 2017-08-24 19:51:06 +0200 |
commit | bd10131242210262eb23c5a62c223039cabf905c (patch) | |
tree | fe2ad03ea734f45bf79baa790a64e25923fe0072 /image/codecs/indeo/get_bits.h | |
parent | 265fc48d1590cdd503187c79dc254d65623c8d7b (diff) | |
parent | 4278cff7f014ba1f404b3cebfe20016b957fafbf (diff) | |
download | scummvm-rg350-bd10131242210262eb23c5a62c223039cabf905c.tar.gz scummvm-rg350-bd10131242210262eb23c5a62c223039cabf905c.tar.bz2 scummvm-rg350-bd10131242210262eb23c5a62c223039cabf905c.zip |
Merge pull request #975 from wjp/bitstream
Rework and optimize Common::BitStream
Diffstat (limited to 'image/codecs/indeo/get_bits.h')
-rw-r--r-- | image/codecs/indeo/get_bits.h | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/image/codecs/indeo/get_bits.h b/image/codecs/indeo/get_bits.h index 359d8fcab0..f972e68ae0 100644 --- a/image/codecs/indeo/get_bits.h +++ b/image/codecs/indeo/get_bits.h @@ -31,15 +31,14 @@ namespace Indeo { /** * Intel Indeo Bitstream reader */ -class GetBits : public Common::BitStream8LSB { +class GetBits : public Common::BitStreamMemory8LSB { public: /** * Constructor * @param stream Source stream to reader from * @param disposeAfterUse Whether to destroy stream in destructor */ - GetBits(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse - = DisposeAfterUse::YES) : Common::BitStream8LSB(stream, disposeAfterUse) {} + GetBits(const uint8 *ptr, uint32 size) : Common::BitStreamMemory8LSB(new Common::BitStreamMemoryStream(ptr, size), DisposeAfterUse::YES) {} /** * The number of bits left @@ -54,7 +53,37 @@ public: * read the longest vlc code * = (max_vlc_length + bits - 1) / bits */ - int getVLC2(int16 (*table)[2], int bits, int maxDepth); + template <int maxDepth> + int getVLC2(int16 (*table)[2], int bits) { + int code; + int n, nbBits; + unsigned int index; + + index = peekBits(bits); + code = table[index][0]; + n = table[index][1]; + + if (maxDepth > 1 && n < 0) { + skip(bits); + nbBits = -n; + + index = peekBits(nbBits) + code; + code = table[index][0]; + n = table[index][1]; + + if (maxDepth > 2 && n < 0) { + skip(nbBits); + nbBits = -n; + + index = peekBits(nbBits) + code; + code = table[index][0]; + n = table[index][1]; + } + } + + skip(n); + return code; + } }; } // End of namespace Indeo |