aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2017-08-24 19:51:06 +0200
committerGitHub2017-08-24 19:51:06 +0200
commitbd10131242210262eb23c5a62c223039cabf905c (patch)
treefe2ad03ea734f45bf79baa790a64e25923fe0072
parent265fc48d1590cdd503187c79dc254d65623c8d7b (diff)
parent4278cff7f014ba1f404b3cebfe20016b957fafbf (diff)
downloadscummvm-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
-rw-r--r--audio/decoders/qdm2.cpp24
-rw-r--r--common/bitstream.h345
-rw-r--r--common/huffman.cpp15
-rw-r--r--common/huffman.h18
-rw-r--r--engines/groovie/stuffit.cpp6
-rw-r--r--engines/macventure/container.h1
-rw-r--r--engines/macventure/image.cpp12
-rw-r--r--engines/macventure/image.h13
-rw-r--r--image/codecs/indeo/get_bits.cpp60
-rw-r--r--image/codecs/indeo/get_bits.h37
-rw-r--r--image/codecs/indeo/indeo.cpp9
-rw-r--r--image/codecs/indeo4.cpp28
-rw-r--r--image/codecs/indeo5.cpp12
-rw-r--r--image/codecs/svq1.cpp12
-rw-r--r--image/codecs/svq1.h14
-rw-r--r--image/module.mk1
-rw-r--r--test/common/bitstream.h118
-rw-r--r--video/bink_decoder.h6
-rw-r--r--video/psx_decoder.cpp17
-rw-r--r--video/psx_decoder.h15
-rw-r--r--video/smk_decoder.cpp31
-rw-r--r--video/smk_decoder.h6
22 files changed, 497 insertions, 303 deletions
diff --git a/audio/decoders/qdm2.cpp b/audio/decoders/qdm2.cpp
index a2f4326152..b8d007da51 100644
--- a/audio/decoders/qdm2.cpp
+++ b/audio/decoders/qdm2.cpp
@@ -213,9 +213,9 @@ private:
void fill_coding_method_array(sb_int8_array tone_level_idx, sb_int8_array tone_level_idx_temp,
sb_int8_array coding_method, int nb_channels,
int c, int superblocktype_2_3, int cm_table_select);
- void synthfilt_build_sb_samples(Common::BitStream *gb, int length, int sb_min, int sb_max);
- void init_quantized_coeffs_elem0(int8 *quantized_coeffs, Common::BitStream *gb, int length);
- void init_tone_level_dequantization(Common::BitStream *gb, int length);
+ void synthfilt_build_sb_samples(Common::BitStream32LELSB *gb, int length, int sb_min, int sb_max);
+ void init_quantized_coeffs_elem0(int8 *quantized_coeffs, Common::BitStream32LELSB *gb, int length);
+ void init_tone_level_dequantization(Common::BitStream32LELSB *gb, int length);
void process_subpacket_9(QDM2SubPNode *node);
void process_subpacket_10(QDM2SubPNode *node, int length);
void process_subpacket_11(QDM2SubPNode *node, int length);
@@ -224,7 +224,7 @@ private:
void qdm2_decode_super_block(void);
void qdm2_fft_init_coefficient(int sub_packet, int offset, int duration,
int channel, int exp, int phase);
- void qdm2_fft_decode_tones(int duration, Common::BitStream *gb, int b);
+ void qdm2_fft_decode_tones(int duration, Common::BitStream32LELSB *gb, int b);
void qdm2_decode_fft_packets(void);
void qdm2_fft_generate_tone(FFTTone *tone);
void qdm2_fft_tone_synthesizer(uint8 sub_packet);
@@ -677,7 +677,7 @@ void ff_mpa_synth_filter(int16 *synth_buf_ptr, int *synth_buf_offset,
* read the longest vlc code
* = (max_vlc_length + bits - 1) / bits
*/
-static int getVlc2(Common::BitStream *s, int16 (*table)[2], int bits, int maxDepth) {
+static int getVlc2(Common::BitStream32LELSB *s, int16 (*table)[2], int bits, int maxDepth) {
int index = s->peekBits(bits);
int code = table[index][0];
int n = table[index][1];
@@ -1227,7 +1227,7 @@ QDM2Stream::~QDM2Stream() {
delete[] _compressedData;
}
-static int qdm2_get_vlc(Common::BitStream *gb, VLC *vlc, int flag, int depth) {
+static int qdm2_get_vlc(Common::BitStream32LELSB *gb, VLC *vlc, int flag, int depth) {
int value = getVlc2(gb, vlc->table, vlc->bits, depth);
// stage-2, 3 bits exponent escape sequence
@@ -1246,7 +1246,7 @@ static int qdm2_get_vlc(Common::BitStream *gb, VLC *vlc, int flag, int depth) {
return value;
}
-static int qdm2_get_se_vlc(VLC *vlc, Common::BitStream *gb, int depth)
+static int qdm2_get_se_vlc(VLC *vlc, Common::BitStream32LELSB *gb, int depth)
{
int value = qdm2_get_vlc(gb, vlc, 0, depth);
@@ -1612,7 +1612,7 @@ void QDM2Stream::fill_coding_method_array(sb_int8_array tone_level_idx, sb_int8_
* @param sb_min lower subband processed (sb_min included)
* @param sb_max higher subband processed (sb_max excluded)
*/
-void QDM2Stream::synthfilt_build_sb_samples(Common::BitStream *gb, int length, int sb_min, int sb_max) {
+void QDM2Stream::synthfilt_build_sb_samples(Common::BitStream32LELSB *gb, int length, int sb_min, int sb_max) {
int sb, j, k, n, ch, run, channels;
int joined_stereo, zero_encoding, chs;
int type34_first;
@@ -1792,7 +1792,7 @@ void QDM2Stream::synthfilt_build_sb_samples(Common::BitStream *gb, int length, i
* @param gb bitreader context
* @param length packet length in bits
*/
-void QDM2Stream::init_quantized_coeffs_elem0(int8 *quantized_coeffs, Common::BitStream *gb, int length) {
+void QDM2Stream::init_quantized_coeffs_elem0(int8 *quantized_coeffs, Common::BitStream32LELSB *gb, int length) {
int i, k, run, level, diff;
if ((length - gb->pos()) < 16)
@@ -1826,7 +1826,7 @@ void QDM2Stream::init_quantized_coeffs_elem0(int8 *quantized_coeffs, Common::Bit
* @param gb bitreader context
* @param length packet length in bits
*/
-void QDM2Stream::init_tone_level_dequantization(Common::BitStream *gb, int length) {
+void QDM2Stream::init_tone_level_dequantization(Common::BitStream32LELSB *gb, int length) {
int sb, j, k, n, ch;
for (ch = 0; ch < _channels; ch++) {
@@ -2021,7 +2021,7 @@ void QDM2Stream::qdm2_decode_super_block(void) {
average_quantized_coeffs(); // average elements in quantized_coeffs[max_ch][10][8]
Common::MemoryReadStream *d = new Common::MemoryReadStream(_compressedData, _packetSize*8);
- Common::BitStream *gb = new Common::BitStream32LELSB(d);
+ Common::BitStream32LELSB *gb = new Common::BitStream32LELSB(d);
//qdm2_decode_sub_packet_header
header.type = gb->getBits(8);
@@ -2188,7 +2188,7 @@ void QDM2Stream::qdm2_fft_init_coefficient(int sub_packet, int offset, int durat
_fftCoefsIndex++;
}
-void QDM2Stream::qdm2_fft_decode_tones(int duration, Common::BitStream *gb, int b) {
+void QDM2Stream::qdm2_fft_decode_tones(int duration, Common::BitStream32LELSB *gb, int b) {
int channel, stereo, phase, exp;
int local_int_4, local_int_8, stereo_phase, local_int_10;
int local_int_14, stereo_exp, local_int_20, local_int_28;
diff --git a/common/bitstream.h b/common/bitstream.h
index 325118bbee..1fbc0065ab 100644
--- a/common/bitstream.h
+++ b/common/bitstream.h
@@ -29,53 +29,10 @@
#include "common/textconsole.h"
#include "common/stream.h"
#include "common/types.h"
+#include "common/util.h"
namespace Common {
-/** A bit stream. */
-class BitStream {
-public:
- virtual ~BitStream() {
- }
-
- /** Return the stream position in bits. */
- virtual uint32 pos() const = 0;
-
- /** Return the stream size in bits. */
- virtual uint32 size() const = 0;
-
- /** Has the end of the stream been reached? */
- virtual bool eos() const = 0;
-
- /** Rewind the bit stream back to the start. */
- virtual void rewind() = 0;
-
- /** Skip the specified amount of bits. */
- virtual void skip(uint32 n) = 0;
-
- /** Skip the bits to closest data value border. */
- virtual void align() = 0;
-
- /** Read a bit from the bit stream. */
- virtual uint32 getBit() = 0;
-
- /** Read a multi-bit value from the bit stream. */
- virtual uint32 getBits(uint8 n) = 0;
-
- /** Read a bit from the bit stream, without changing the stream's position. */
- virtual uint32 peekBit() = 0;
-
- /** Read a multi-bit value from the bit stream, without changing the stream's position. */
- virtual uint32 peekBits(uint8 n) = 0;
-
- /** Add a bit to the value x, making it an n+1-bit value. */
- virtual void addBit(uint32 &x, uint32 n) = 0;
-
-protected:
- BitStream() {
- }
-};
-
/**
* A template implementing a bit stream for different data memory layouts.
*
@@ -86,14 +43,16 @@ protected:
* for valueBits, isLE and isMSB2LSB, reads 32bit little-endian values
* from the data stream and hands out the bits in the order of LSB to MSB.
*/
-template<int valueBits, bool isLE, bool isMSB2LSB>
-class BitStreamImpl : public BitStream {
+template<class STREAM, int valueBits, bool isLE, bool isMSB2LSB>
+class BitStreamImpl {
private:
- SeekableReadStream *_stream; ///< The input stream.
+ STREAM *_stream; ///< The input stream.
DisposeAfterUse::Flag _disposeAfterUse; ///< Should we delete the stream on destruction?
uint32 _value; ///< Current value.
uint8 _inValue; ///< Position within the current value.
+ uint32 _size; ///< Total bitstream size (in bits)
+ uint32 _pos; ///< Current bitstream position (in bits)
/** Read a data value. */
inline uint32 readData() {
@@ -119,7 +78,7 @@ private:
/** Read the next data value. */
inline void readValue() {
- if ((size() - pos()) < valueBits)
+ if (_size - _pos < valueBits)
error("BitStreamImpl::readValue(): End of bit stream reached");
_value = readData();
@@ -133,19 +92,23 @@ private:
public:
/** Create a bit stream using this input data stream and optionally delete it on destruction. */
- BitStreamImpl(SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::NO) :
- _stream(stream), _disposeAfterUse(disposeAfterUse), _value(0), _inValue(0) {
+ BitStreamImpl(STREAM *stream, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::NO) :
+ _stream(stream), _disposeAfterUse(disposeAfterUse), _value(0), _inValue(0), _pos(0) {
if ((valueBits != 8) && (valueBits != 16) && (valueBits != 32))
error("BitStreamImpl: Invalid memory layout %d, %d, %d", valueBits, isLE, isMSB2LSB);
+
+ _size = (_stream->size() & ~((uint32) ((valueBits >> 3) - 1))) * 8;
}
/** Create a bit stream using this input data stream. */
- BitStreamImpl(SeekableReadStream &stream) :
- _stream(&stream), _disposeAfterUse(DisposeAfterUse::NO), _value(0), _inValue(0) {
+ BitStreamImpl(STREAM &stream) :
+ _stream(&stream), _disposeAfterUse(DisposeAfterUse::NO), _value(0), _inValue(0), _pos(0) {
if ((valueBits != 8) && (valueBits != 16) && (valueBits != 32))
error("BitStreamImpl: Invalid memory layout %d, %d, %d", valueBits, isLE, isMSB2LSB);
+
+ _size = (_stream->size() & ~((uint32) ((valueBits >> 3) - 1))) * 8;
}
~BitStreamImpl() {
@@ -153,14 +116,10 @@ public:
delete _stream;
}
- /** Read a bit from the bit stream. */
- uint32 getBit() {
- // Check if we need the next value
- if (_inValue == 0)
- readValue();
-
+private:
+ uint32 getBit_internal() {
// Get the current bit
- int b = 0;
+ uint32 b = 0;
if (isMSB2LSB)
b = ((_value & 0x80000000) == 0) ? 0 : 1;
else
@@ -172,8 +131,21 @@ public:
else
_value >>= 1;
+ return b;
+ }
+
+public:
+ /** Read a bit from the bit stream. */
+ uint32 getBit() {
+ // Check if we need the next value
+ if (_inValue == 0)
+ readValue();
+
+ uint32 b = getBit_internal();
+
// Increase the position within the current value
_inValue = (_inValue + 1) % valueBits;
+ _pos++;
return b;
}
@@ -198,16 +170,42 @@ public:
// Read the number of bits
uint32 v = 0;
- if (isMSB2LSB) {
- while (n-- > 0)
- v = (v << 1) | getBit();
- } else {
- for (uint32 i = 0; i < n; i++)
- v = (v >> 1) | (((uint32) getBit()) << 31);
+ uint8 nOrig = n;
+ if (_inValue) {
+ int count = MIN((int)n, valueBits - _inValue);
+ for (int i = 0; i < count; ++i) {
+ if (isMSB2LSB) {
+ v = (v << 1) | getBit_internal();
+ } else {
+ v = (v >> 1) | (getBit_internal() << 31);
+ }
+ }
+
+ n -= count;
+ }
+
+ while (n > 0) {
+ // NB: readValue doesn't care that _inValue is incorrect here
+ readValue();
- v >>= (32 - n);
+ int count = MIN((int)n, valueBits);
+ for (int i = 0; i < count; ++i) {
+ if (isMSB2LSB) {
+ v = (v << 1) | getBit_internal();
+ } else {
+ v = (v >> 1) | (getBit_internal() << 31);
+ }
+ }
+
+ n -= count;
}
+ _inValue = (_inValue + nOrig) % valueBits;
+ _pos += nOrig;
+
+ if (!isMSB2LSB)
+ v >>= (32 - nOrig);
+
return v;
}
@@ -215,11 +213,13 @@ public:
uint32 peekBit() {
uint32 value = _value;
uint8 inValue = _inValue;
- uint32 curPos = _stream->pos();
+ uint32 curStreamPos = _stream->pos();
+ uint32 curPos = _pos;
uint32 v = getBit();
- _stream->seek(curPos);
+ _pos = curPos;
+ _stream->seek(curStreamPos);
_inValue = inValue;
_value = value;
@@ -234,11 +234,13 @@ public:
uint32 peekBits(uint8 n) {
uint32 value = _value;
uint8 inValue = _inValue;
- uint32 curPos = _stream->pos();
+ uint32 curStreamPos = _stream->pos();
+ uint32 curPos = _pos;
uint32 v = getBits(n);
- _stream->seek(curPos);
+ _pos = curPos;
+ _stream->seek(curStreamPos);
_inValue = inValue;
_value = value;
@@ -272,6 +274,7 @@ public:
_value = 0;
_inValue = 0;
+ _pos = 0;
}
/** Skip the specified amount of bits. */
@@ -288,47 +291,215 @@ public:
/** Return the stream position in bits. */
uint32 pos() const {
- if (_stream->pos() == 0)
- return 0;
-
- uint32 p = (_inValue == 0) ? _stream->pos() : ((_stream->pos() - 1) & ~((uint32) ((valueBits >> 3) - 1)));
- return p * 8 + _inValue;
+ return _pos;
}
/** Return the stream size in bits. */
uint32 size() const {
- return (_stream->size() & ~((uint32) ((valueBits >> 3) - 1))) * 8;
+ return _size;
}
bool eos() const {
- return _stream->eos() || (pos() >= size());
+ return _stream->eos() || (_pos >= _size);
}
};
+
+
+/**
+ * A cut-down version of MemoryReadStream specifically for use with BitStream.
+ * It removes the virtual call overhead for reading bytes from a memory buffer,
+ * and allows directly inlining this access.
+ *
+ * The code duplication with MemoryReadStream is not ideal.
+ * It might be possible to avoid this by making this a final subclass of
+ * MemoryReadStream, but that is a C++11 feature.
+ */
+class BitStreamMemoryStream {
+private:
+ const byte * const _ptrOrig;
+ const byte *_ptr;
+ const uint32 _size;
+ uint32 _pos;
+ DisposeAfterUse::Flag _disposeMemory;
+ bool _eos;
+
+public:
+ BitStreamMemoryStream(const byte *dataPtr, uint32 dataSize, DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) :
+ _ptrOrig(dataPtr),
+ _ptr(dataPtr),
+ _size(dataSize),
+ _pos(0),
+ _disposeMemory(disposeMemory),
+ _eos(false) {}
+
+ ~BitStreamMemoryStream() {
+ if (_disposeMemory)
+ free(const_cast<byte *>(_ptrOrig));
+ }
+
+ bool eos() const {
+ return _eos;
+ }
+
+ bool err() const {
+ return false;
+ }
+
+ int32 pos() const {
+ return _pos;
+ }
+
+ int32 size() const {
+ return _size;
+ }
+
+ bool seek(uint32 offset) {
+ assert(offset <= _size);
+
+ _eos = false;
+ _pos = offset;
+ _ptr = _ptrOrig + _pos;
+ return true;
+ }
+
+ byte readByte() {
+ if (_pos >= _size) {
+ _eos = true;
+ return 0;
+ }
+
+ _pos++;
+ return *_ptr++;
+ }
+
+ uint16 readUint16LE() {
+ if (_pos + 2 > _size) {
+ _eos = true;
+ if (_pos < _size) {
+ _pos++;
+ return *_ptr++;
+ } else {
+ return 0;
+ }
+ }
+
+ uint16 val = READ_LE_UINT16(_ptr);
+
+ _pos += 2;
+ _ptr += 2;
+
+ return val;
+ }
+
+ uint16 readUint16BE() {
+ if (_pos + 2 > _size) {
+ _eos = true;
+ if (_pos < _size) {
+ _pos++;
+ return (*_ptr++) << 8;
+ } else {
+ return 0;
+ }
+ }
+
+ uint16 val = READ_LE_UINT16(_ptr);
+
+ _pos += 2;
+ _ptr += 2;
+
+ return val;
+ }
+
+ uint32 readUint32LE() {
+ if (_pos + 4 > _size) {
+ uint32 val = readByte();
+ val |= (uint32)readByte() << 8;
+ val |= (uint32)readByte() << 16;
+ val |= (uint32)readByte() << 24;
+
+ return val;
+ }
+
+ uint32 val = READ_LE_UINT32(_ptr);
+
+ _pos += 4;
+ _ptr += 4;
+
+ return val;
+ }
+
+ uint32 readUint32BE() {
+ if (_pos + 4 > _size) {
+ uint32 val = (uint32)readByte() << 24;
+ val |= (uint32)readByte() << 16;
+ val |= (uint32)readByte() << 8;
+ val |= (uint32)readByte();
+
+ return val;
+ }
+
+ uint32 val = READ_BE_UINT32(_ptr);
+
+ _pos += 4;
+ _ptr += 4;
+
+ return val;
+ }
+
+};
+
+
// typedefs for various memory layouts.
/** 8-bit data, MSB to LSB. */
-typedef BitStreamImpl<8, false, true > BitStream8MSB;
+typedef BitStreamImpl<SeekableReadStream, 8, false, true > BitStream8MSB;
/** 8-bit data, LSB to MSB. */
-typedef BitStreamImpl<8, false, false> BitStream8LSB;
+typedef BitStreamImpl<SeekableReadStream, 8, false, false> BitStream8LSB;
/** 16-bit little-endian data, MSB to LSB. */
-typedef BitStreamImpl<16, true , true > BitStream16LEMSB;
+typedef BitStreamImpl<SeekableReadStream, 16, true , true > BitStream16LEMSB;
/** 16-bit little-endian data, LSB to MSB. */
-typedef BitStreamImpl<16, true , false> BitStream16LELSB;
+typedef BitStreamImpl<SeekableReadStream, 16, true , false> BitStream16LELSB;
/** 16-bit big-endian data, MSB to LSB. */
-typedef BitStreamImpl<16, false, true > BitStream16BEMSB;
+typedef BitStreamImpl<SeekableReadStream, 16, false, true > BitStream16BEMSB;
/** 16-bit big-endian data, LSB to MSB. */
-typedef BitStreamImpl<16, false, false> BitStream16BELSB;
+typedef BitStreamImpl<SeekableReadStream, 16, false, false> BitStream16BELSB;
/** 32-bit little-endian data, MSB to LSB. */
-typedef BitStreamImpl<32, true , true > BitStream32LEMSB;
+typedef BitStreamImpl<SeekableReadStream, 32, true , true > BitStream32LEMSB;
/** 32-bit little-endian data, LSB to MSB. */
-typedef BitStreamImpl<32, true , false> BitStream32LELSB;
+typedef BitStreamImpl<SeekableReadStream, 32, true , false> BitStream32LELSB;
/** 32-bit big-endian data, MSB to LSB. */
-typedef BitStreamImpl<32, false, true > BitStream32BEMSB;
+typedef BitStreamImpl<SeekableReadStream, 32, false, true > BitStream32BEMSB;
/** 32-bit big-endian data, LSB to MSB. */
-typedef BitStreamImpl<32, false, false> BitStream32BELSB;
+typedef BitStreamImpl<SeekableReadStream, 32, false, false> BitStream32BELSB;
+
+
+
+/** 8-bit data, MSB to LSB. */
+typedef BitStreamImpl<BitStreamMemoryStream, 8, false, true > BitStreamMemory8MSB;
+/** 8-bit data, LSB to MSB. */
+typedef BitStreamImpl<BitStreamMemoryStream, 8, false, false> BitStreamMemory8LSB;
+
+/** 16-bit little-endian data, MSB to LSB. */
+typedef BitStreamImpl<BitStreamMemoryStream, 16, true , true > BitStreamMemory16LEMSB;
+/** 16-bit little-endian data, LSB to MSB. */
+typedef BitStreamImpl<BitStreamMemoryStream, 16, true , false> BitStreamMemory16LELSB;
+/** 16-bit big-endian data, MSB to LSB. */
+typedef BitStreamImpl<BitStreamMemoryStream, 16, false, true > BitStreamMemory16BEMSB;
+/** 16-bit big-endian data, LSB to MSB. */
+typedef BitStreamImpl<BitStreamMemoryStream, 16, false, false> BitStreamMemory16BELSB;
+
+/** 32-bit little-endian data, MSB to LSB. */
+typedef BitStreamImpl<BitStreamMemoryStream, 32, true , true > BitStreamMemory32LEMSB;
+/** 32-bit little-endian data, LSB to MSB. */
+typedef BitStreamImpl<BitStreamMemoryStream, 32, true , false> BitStreamMemory32LELSB;
+/** 32-bit big-endian data, MSB to LSB. */
+typedef BitStreamImpl<BitStreamMemoryStream, 32, false, true > BitStreamMemory32BEMSB;
+/** 32-bit big-endian data, LSB to MSB. */
+typedef BitStreamImpl<BitStreamMemoryStream, 32, false, false> BitStreamMemory32BELSB;
+
} // End of namespace Common
diff --git a/common/huffman.cpp b/common/huffman.cpp
index afb4fa00b6..3268ddf251 100644
--- a/common/huffman.cpp
+++ b/common/huffman.cpp
@@ -68,19 +68,4 @@ void Huffman::setSymbols(const uint32 *symbols) {
_symbols[i]->symbol = symbols ? *symbols++ : i;
}
-uint32 Huffman::getSymbol(BitStream &bits) const {
- uint32 code = 0;
-
- for (uint32 i = 0; i < _codes.size(); i++) {
- bits.addBit(code, i);
-
- for (CodeList::const_iterator cCode = _codes[i].begin(); cCode != _codes[i].end(); ++cCode)
- if (code == cCode->code)
- return cCode->symbol;
- }
-
- error("Unknown Huffman code");
- return 0;
-}
-
} // End of namespace Common
diff --git a/common/huffman.h b/common/huffman.h
index 5ba7deca87..f703d078dc 100644
--- a/common/huffman.h
+++ b/common/huffman.h
@@ -31,8 +31,6 @@
namespace Common {
-class BitStream;
-
/**
* Huffman bitstream decoding
*
@@ -56,7 +54,21 @@ public:
void setSymbols(const uint32 *symbols = 0);
/** Return the next symbol in the bitstream. */
- uint32 getSymbol(BitStream &bits) const;
+ template<class BITSTREAM>
+ uint32 getSymbol(BITSTREAM &bits) const {
+ uint32 code = 0;
+
+ for (uint32 i = 0; i < _codes.size(); i++) {
+ bits.addBit(code, i);
+
+ for (CodeList::const_iterator cCode = _codes[i].begin(); cCode != _codes[i].end(); ++cCode)
+ if (code == cCode->code)
+ return cCode->symbol;
+ }
+
+ error("Unknown Huffman code");
+ return 0;
+ }
private:
struct Symbol {
diff --git a/engines/groovie/stuffit.cpp b/engines/groovie/stuffit.cpp
index bbfcd3da82..4543e37a27 100644
--- a/engines/groovie/stuffit.cpp
+++ b/engines/groovie/stuffit.cpp
@@ -71,7 +71,7 @@ private:
// Decompression Helpers
void update14(uint16 first, uint16 last, byte *code, uint16 *freq) const;
- void readTree14(Common::BitStream *bits, SIT14Data *dat, uint16 codesize, uint16 *result) const;
+ void readTree14(Common::BitStream8LSB *bits, SIT14Data *dat, uint16 codesize, uint16 *result) const;
};
StuffItArchive::StuffItArchive() : Common::Archive() {
@@ -302,7 +302,7 @@ struct SIT14Data {
if (b->pos() & 7) \
b->skip(8 - (b->pos() & 7))
-void StuffItArchive::readTree14(Common::BitStream *bits, SIT14Data *dat, uint16 codesize, uint16 *result) const {
+void StuffItArchive::readTree14(Common::BitStream8LSB *bits, SIT14Data *dat, uint16 codesize, uint16 *result) const {
uint32 i, l, n;
uint32 k = bits->getBit();
uint32 j = bits->getBits(2) + 2;
@@ -429,7 +429,7 @@ Common::SeekableReadStream *StuffItArchive::decompress14(Common::SeekableReadStr
byte *dst = (byte *)malloc(uncompressedSize);
Common::MemoryWriteStream out(dst, uncompressedSize);
- Common::BitStream *bits = new Common::BitStream8LSB(src);
+ Common::BitStream8LSB *bits = new Common::BitStream8LSB(src);
uint32 i, j, k, l, m, n;
diff --git a/engines/macventure/container.h b/engines/macventure/container.h
index ba1370d108..bd8cd0995a 100644
--- a/engines/macventure/container.h
+++ b/engines/macventure/container.h
@@ -35,7 +35,6 @@
#include "common/file.h"
#include "common/fs.h"
-#include "common/bitstream.h"
namespace MacVenture {
diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp
index 7fccaa81b4..a899341eb9 100644
--- a/engines/macventure/image.cpp
+++ b/engines/macventure/image.cpp
@@ -155,7 +155,7 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array<byte> &data, uint &bitHeight
delete baseStream;
}
-void ImageAsset::decodePPIC0(Common::BitStream &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) {
+void ImageAsset::decodePPIC0(Common::BitStream32BEMSB &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) {
uint words = bitWidth >> 4;
uint bytes = bitWidth & 0xF;
uint v = 0;
@@ -178,15 +178,15 @@ void ImageAsset::decodePPIC0(Common::BitStream &stream, Common::Array<byte> &dat
}
-void ImageAsset::decodePPIC1(Common::BitStream &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) {
+void ImageAsset::decodePPIC1(Common::BitStream32BEMSB &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) {
decodeHuffGraphic(PPIC1Huff, stream, data, bitHeight, bitWidth, rowBytes);
}
-void ImageAsset::decodePPIC2(Common::BitStream &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) {
+void ImageAsset::decodePPIC2(Common::BitStream32BEMSB &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) {
decodeHuffGraphic(PPIC2Huff, stream, data, bitHeight, bitWidth, rowBytes);
}
-void ImageAsset::decodePPIC3(Common::BitStream &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) {
+void ImageAsset::decodePPIC3(Common::BitStream32BEMSB &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) {
// We need to load the huffman from the PPIC itself
PPICHuff huff;
uint16 v, bits;
@@ -238,7 +238,7 @@ void ImageAsset::decodePPIC3(Common::BitStream &stream, Common::Array<byte> &dat
decodeHuffGraphic(huff, stream, data, bitHeight, bitWidth, rowBytes);
}
-void ImageAsset::decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) {
+void ImageAsset::decodeHuffGraphic(const PPICHuff &huff, Common::BitStream32BEMSB &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) {
byte flags = 0;
_walkRepeat = 0;
_walkLast = 0;
@@ -333,7 +333,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stre
}
}
-byte ImageAsset::walkHuff(const PPICHuff &huff, Common::BitStream &stream) {
+byte ImageAsset::walkHuff(const PPICHuff &huff, Common::BitStream32BEMSB &stream) {
if (_walkRepeat) {
_walkRepeat--;
_walkLast = ((_walkLast << 8) & 0xFF00) | (_walkLast >> 8);
diff --git a/engines/macventure/image.h b/engines/macventure/image.h
index 87c5cec2db..9a3a2a10e5 100644
--- a/engines/macventure/image.h
+++ b/engines/macventure/image.h
@@ -33,6 +33,7 @@
#include "macventure/macventure.h"
#include "macventure/container.h"
+#include "common/bitstream.h"
namespace MacVenture {
@@ -76,13 +77,13 @@ public:
private:
void decodePPIC(ObjID id, Common::Array<byte> &data, uint &bitHeight, uint &bitWidth, uint &rowBytes);
- void decodePPIC0(Common::BitStream &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
- void decodePPIC1(Common::BitStream &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
- void decodePPIC2(Common::BitStream &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
- void decodePPIC3(Common::BitStream &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
+ void decodePPIC0(Common::BitStream32BEMSB &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
+ void decodePPIC1(Common::BitStream32BEMSB &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
+ void decodePPIC2(Common::BitStream32BEMSB &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
+ void decodePPIC3(Common::BitStream32BEMSB &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
- void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
- byte walkHuff(const PPICHuff &huff, Common::BitStream &stream);
+ void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream32BEMSB &stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
+ byte walkHuff(const PPICHuff &huff, Common::BitStream32BEMSB &stream);
void blitDirect(Graphics::ManagedSurface *target, int ox, int oy, const Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
void blitBIC(Graphics::ManagedSurface *target, int ox, int oy, const Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes);
diff --git a/image/codecs/indeo/get_bits.cpp b/image/codecs/indeo/get_bits.cpp
deleted file mode 100644
index f808a96e76..0000000000
--- a/image/codecs/indeo/get_bits.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "image/codecs/indeo/get_bits.h"
-
-namespace Image {
-namespace Indeo {
-
-int GetBits::getVLC2(int16 (*table)[2], int bits, int maxDepth) {
- 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
-} // End of namespace Image
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
diff --git a/image/codecs/indeo/indeo.cpp b/image/codecs/indeo/indeo.cpp
index 769790b76f..f420069139 100644
--- a/image/codecs/indeo/indeo.cpp
+++ b/image/codecs/indeo/indeo.cpp
@@ -1258,16 +1258,15 @@ int IndeoDecoderBase::decodeCodedBlocks(GetBits *gb, IVIBandDesc *band,
// zero column flags
memset(colFlags, 0, sizeof(colFlags));
while (scanPos <= numCoeffs) {
- sym = gb->getVLC2(band->_blkVlc._tab->_table,
- IVI_VLC_BITS, 1);
+ sym = gb->getVLC2<1>(band->_blkVlc._tab->_table, IVI_VLC_BITS);
if (sym == rvmap->_eobSym)
break; // End of block
// Escape - run/val explicitly coded using 3 vlc codes
if (sym == rvmap->_escSym) {
- run = gb->getVLC2(band->_blkVlc._tab->_table, IVI_VLC_BITS, 1) + 1;
- lo = gb->getVLC2(band->_blkVlc._tab->_table, IVI_VLC_BITS, 1);
- hi = gb->getVLC2(band->_blkVlc._tab->_table, IVI_VLC_BITS, 1);
+ run = gb->getVLC2<1>(band->_blkVlc._tab->_table, IVI_VLC_BITS) + 1;
+ lo = gb->getVLC2<1>(band->_blkVlc._tab->_table, IVI_VLC_BITS);
+ hi = gb->getVLC2<1>(band->_blkVlc._tab->_table, IVI_VLC_BITS);
// merge them and convert into signed val
val = IVI_TOSIGNED((hi << 6) | lo);
} else {
diff --git a/image/codecs/indeo4.cpp b/image/codecs/indeo4.cpp
index b6ac0882e7..ead1d3a814 100644
--- a/image/codecs/indeo4.cpp
+++ b/image/codecs/indeo4.cpp
@@ -56,7 +56,7 @@ bool Indeo4Decoder::isIndeo4(Common::SeekableReadStream &stream) {
stream.seek(-16, SEEK_CUR);
// Validate the first 18-bit word has the correct identifier
- Indeo::GetBits gb(new Common::MemoryReadStream(buffer, 16 * 8), DisposeAfterUse::YES);
+ Indeo::GetBits gb(buffer, 16 * 8);
bool isIndeo4 = gb.getBits(18) == 0x3FFF8;
return isIndeo4;
@@ -74,7 +74,7 @@ const Graphics::Surface *Indeo4Decoder::decodeFrame(Common::SeekableReadStream &
_ctx._frameSize = stream.size();
// Set up the GetBits instance for reading the data
- _ctx._gb = new GetBits(new Common::MemoryReadStream(_ctx._frameData, _ctx._frameSize));
+ _ctx._gb = new GetBits(_ctx._frameData, _ctx._frameSize);
// Decode the frame
int err = decodeIndeoFrame();
@@ -484,8 +484,8 @@ int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
mb->_qDelta = 0;
if (!band->_plane && !band->_bandNum && _ctx._inQ) {
- mb->_qDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table,
- IVI_VLC_BITS, 1);
+ mb->_qDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table,
+ IVI_VLC_BITS);
mb->_qDelta = IVI_TOSIGNED(mb->_qDelta);
}
@@ -522,8 +522,8 @@ int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
if (refMb) mb->_qDelta = refMb->_qDelta;
} else if (mb->_cbp || (!band->_plane && !band->_bandNum &&
_ctx._inQ)) {
- mb->_qDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table,
- IVI_VLC_BITS, 1);
+ mb->_qDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table,
+ IVI_VLC_BITS);
mb->_qDelta = IVI_TOSIGNED(mb->_qDelta);
}
@@ -543,22 +543,22 @@ int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
}
} else {
// decode motion vector deltas
- mvDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table,
- IVI_VLC_BITS, 1);
+ mvDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table,
+ IVI_VLC_BITS);
mvY += IVI_TOSIGNED(mvDelta);
- mvDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table,
- IVI_VLC_BITS, 1);
+ mvDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table,
+ IVI_VLC_BITS);
mvX += IVI_TOSIGNED(mvDelta);
mb->_mvX = mvX;
mb->_mvY = mvY;
if (mb->_type == 3) {
- mvDelta = _ctx._gb->getVLC2(
+ mvDelta = _ctx._gb->getVLC2<1>(
_ctx._mbVlc._tab->_table,
- IVI_VLC_BITS, 1);
+ IVI_VLC_BITS);
mvY += IVI_TOSIGNED(mvDelta);
- mvDelta = _ctx._gb->getVLC2(
+ mvDelta = _ctx._gb->getVLC2<1>(
_ctx._mbVlc._tab->_table,
- IVI_VLC_BITS, 1);
+ IVI_VLC_BITS);
mvX += IVI_TOSIGNED(mvDelta);
mb->_bMvX = -mvX;
mb->_bMvY = -mvY;
diff --git a/image/codecs/indeo5.cpp b/image/codecs/indeo5.cpp
index aca49c3d55..c4e98d4ac7 100644
--- a/image/codecs/indeo5.cpp
+++ b/image/codecs/indeo5.cpp
@@ -67,7 +67,7 @@ bool Indeo5Decoder::isIndeo5(Common::SeekableReadStream &stream) {
stream.seek(-16, SEEK_CUR);
// Validate the first 5-bit word has the correct identifier
- Indeo::GetBits gb(new Common::MemoryReadStream(buffer, 16 * 8));
+ Indeo::GetBits gb(buffer, 16 * 8);
bool isIndeo5 = gb.getBits(5) == 0x1F;
return isIndeo5;
@@ -85,7 +85,7 @@ const Graphics::Surface *Indeo5Decoder::decodeFrame(Common::SeekableReadStream &
_ctx._frameSize = stream.size();
// Set up the GetBits instance for reading the data
- _ctx._gb = new GetBits(new Common::MemoryReadStream(_ctx._frameData, _ctx._frameSize));
+ _ctx._gb = new GetBits(_ctx._frameData, _ctx._frameSize);
// Decode the frame
int err = decodeIndeoFrame();
@@ -299,7 +299,7 @@ int Indeo5Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
mb->_qDelta = 0;
if (!band->_plane && !band->_bandNum && (_ctx._frameFlags & 8)) {
- mb->_qDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table, IVI_VLC_BITS, 1);
+ mb->_qDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table, IVI_VLC_BITS);
mb->_qDelta = IVI_TOSIGNED(mb->_qDelta);
}
@@ -332,7 +332,7 @@ int Indeo5Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
if (refMb) mb->_qDelta = refMb->_qDelta;
} else if (mb->_cbp || (!band->_plane && !band->_bandNum &&
(_ctx._frameFlags & 8))) {
- mb->_qDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table, IVI_VLC_BITS, 1);
+ mb->_qDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table, IVI_VLC_BITS);
mb->_qDelta = IVI_TOSIGNED(mb->_qDelta);
}
}
@@ -351,9 +351,9 @@ int Indeo5Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
}
} else {
// decode motion vector deltas
- mvDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table, IVI_VLC_BITS, 1);
+ mvDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table, IVI_VLC_BITS);
mvY += IVI_TOSIGNED(mvDelta);
- mvDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table, IVI_VLC_BITS, 1);
+ mvDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table, IVI_VLC_BITS);
mvX += IVI_TOSIGNED(mvDelta);
mb->_mvX = mvX;
mb->_mvY = mvY;
diff --git a/image/codecs/svq1.cpp b/image/codecs/svq1.cpp
index 765d512797..2d86070801 100644
--- a/image/codecs/svq1.cpp
+++ b/image/codecs/svq1.cpp
@@ -282,7 +282,7 @@ const Graphics::Surface *SVQ1Decoder::decodeFrame(Common::SeekableReadStream &st
return _surface;
}
-bool SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, byte *pixels, int pitch) {
+bool SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream32BEMSB *s, byte *pixels, int pitch) {
// initialize list for breadth first processing of vectors
byte *list[63];
list[0] = pixels;
@@ -383,7 +383,7 @@ bool SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, byte *pixels, int p
return true;
}
-bool SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, byte *pixels, int pitch) {
+bool SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream32BEMSB *s, byte *pixels, int pitch) {
// initialize list for breadth first processing of vectors
byte *list[63];
list[0] = pixels;
@@ -497,7 +497,7 @@ static inline int midPred(int a, int b, int c) {
return b;
}
-bool SVQ1Decoder::svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv) {
+bool SVQ1Decoder::svq1DecodeMotionVector(Common::BitStream32BEMSB *s, Common::Point *mv, Common::Point **pmv) {
for (int i = 0; i < 2; i++) {
// get motion code
int diff = _motionComponent->getSymbol(*s);
@@ -611,7 +611,7 @@ void SVQ1Decoder::putPixels16XY2C(byte *block, const byte *pixels, int lineSize,
putPixels8XY2C(block + 8, pixels + 8, lineSize, h);
}
-bool SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
+bool SVQ1Decoder::svq1MotionInterBlock(Common::BitStream32BEMSB *ss, byte *current, byte *previous, int pitch,
Common::Point *motion, int x, int y) {
// predict and decode motion vector
@@ -662,7 +662,7 @@ bool SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss, byte *current, byt
return true;
}
-bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
+bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream32BEMSB *ss, byte *current, byte *previous, int pitch,
Common::Point *motion, int x, int y) {
// predict and decode motion vector (0)
Common::Point *pmv[4];
@@ -749,7 +749,7 @@ bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss, byte *current, b
return true;
}
-bool SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
+bool SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream32BEMSB *ss, byte *current, byte *previous, int pitch,
Common::Point *motion, int x, int y) {
// get block type
uint32 blockType = _blockType->getSymbol(*ss);
diff --git a/image/codecs/svq1.h b/image/codecs/svq1.h
index 236b810294..148501d17f 100644
--- a/image/codecs/svq1.h
+++ b/image/codecs/svq1.h
@@ -23,10 +23,10 @@
#ifndef IMAGE_CODECS_SVQ1_H
#define IMAGE_CODECS_SVQ1_H
+#include "common/bitstream.h"
#include "image/codecs/codec.h"
namespace Common {
-class BitStream;
class Huffman;
struct Point;
}
@@ -60,15 +60,15 @@ private:
Common::Huffman *_interMean;
Common::Huffman *_motionComponent;
- bool svq1DecodeBlockIntra(Common::BitStream *s, byte *pixels, int pitch);
- bool svq1DecodeBlockNonIntra(Common::BitStream *s, byte *pixels, int pitch);
- bool svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv);
+ bool svq1DecodeBlockIntra(Common::BitStream32BEMSB *s, byte *pixels, int pitch);
+ bool svq1DecodeBlockNonIntra(Common::BitStream32BEMSB *s, byte *pixels, int pitch);
+ bool svq1DecodeMotionVector(Common::BitStream32BEMSB *s, Common::Point *mv, Common::Point **pmv);
void svq1SkipBlock(byte *current, byte *previous, int pitch, int x, int y);
- bool svq1MotionInterBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
+ bool svq1MotionInterBlock(Common::BitStream32BEMSB *ss, byte *current, byte *previous, int pitch,
Common::Point *motion, int x, int y);
- bool svq1MotionInter4vBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
+ bool svq1MotionInter4vBlock(Common::BitStream32BEMSB *ss, byte *current, byte *previous, int pitch,
Common::Point *motion, int x, int y);
- bool svq1DecodeDeltaBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
+ bool svq1DecodeDeltaBlock(Common::BitStream32BEMSB *ss, byte *current, byte *previous, int pitch,
Common::Point *motion, int x, int y);
void putPixels8C(byte *block, const byte *pixels, int lineSize, int h);
diff --git a/image/module.mk b/image/module.mk
index 2ede7c3bdb..be049eb818 100644
--- a/image/module.mk
+++ b/image/module.mk
@@ -24,7 +24,6 @@ MODULE_OBJS := \
codecs/smc.o \
codecs/svq1.o \
codecs/truemotion1.o \
- codecs/indeo/get_bits.o \
codecs/indeo/indeo.o \
codecs/indeo/indeo_dsp.o \
codecs/indeo/mem.o \
diff --git a/test/common/bitstream.h b/test/common/bitstream.h
index 3f6a15fcd8..0488169183 100644
--- a/test/common/bitstream.h
+++ b/test/common/bitstream.h
@@ -5,13 +5,14 @@
class BitStreamTestSuite : public CxxTest::TestSuite
{
- public:
- void test_get_bit() {
+private:
+ template<class MS, class BS>
+ void tmpl_get_bit() {
byte contents[] = { 'a' };
- Common::MemoryReadStream ms(contents, sizeof(contents));
+ MS ms(contents, sizeof(contents));
- Common::BitStream8MSB bs(ms);
+ BS bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.getBit(), 0u);
TS_ASSERT_EQUALS(bs.getBit(), 1u);
@@ -19,13 +20,20 @@ class BitStreamTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(bs.pos(), 3u);
TS_ASSERT(!bs.eos());
}
+public:
+ void test_get_bit() {
+ tmpl_get_bit<Common::MemoryReadStream, Common::BitStream8MSB>();
+ tmpl_get_bit<Common::BitStreamMemoryStream, Common::BitStreamMemory8MSB>();
+ }
- void test_get_bits() {
+private:
+ template<class MS, class BS>
+ void tmpl_get_bits() {
byte contents[] = { 'a', 'b' };
- Common::MemoryReadStream ms(contents, sizeof(contents));
+ MS ms(contents, sizeof(contents));
- Common::BitStream8MSB bs(ms);
+ BS bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.getBits(3), 3u);
TS_ASSERT_EQUALS(bs.pos(), 3u);
@@ -33,13 +41,20 @@ class BitStreamTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(bs.pos(), 11u);
TS_ASSERT(!bs.eos());
}
+public:
+ void test_get_bits() {
+ tmpl_get_bits<Common::MemoryReadStream, Common::BitStream8MSB>();
+ tmpl_get_bits<Common::BitStreamMemoryStream, Common::BitStreamMemory8MSB>();
+ }
- void test_skip() {
+private:
+ template<class MS, class BS>
+ void tmpl_skip() {
byte contents[] = { 'a', 'b' };
- Common::MemoryReadStream ms(contents, sizeof(contents));
+ MS ms(contents, sizeof(contents));
- Common::BitStream8MSB bs(ms);
+ BS bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
bs.skip(5);
TS_ASSERT_EQUALS(bs.pos(), 5u);
@@ -48,13 +63,20 @@ class BitStreamTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(bs.getBits(3), 6u);
TS_ASSERT(!bs.eos());
}
+public:
+ void test_skip() {
+ tmpl_skip<Common::MemoryReadStream, Common::BitStream8MSB>();
+ tmpl_skip<Common::BitStreamMemoryStream, Common::BitStreamMemory8MSB>();
+ }
- void test_rewind() {
+private:
+ template<class MS, class BS>
+ void tmpl_rewind() {
byte contents[] = { 'a' };
- Common::MemoryReadStream ms(contents, sizeof(contents));
+ MS ms(contents, sizeof(contents));
- Common::BitStream8MSB bs(ms);
+ BS bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
bs.skip(5);
TS_ASSERT_EQUALS(bs.pos(), 5u);
@@ -65,13 +87,20 @@ class BitStreamTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(bs.size(), 8u);
}
+public:
+ void test_rewind() {
+ tmpl_rewind<Common::MemoryReadStream, Common::BitStream8MSB>();
+ tmpl_rewind<Common::BitStreamMemoryStream, Common::BitStreamMemory8MSB>();
+ }
- void test_peek_bit() {
+private:
+ template<class MS, class BS>
+ void tmpl_peek_bit() {
byte contents[] = { 'a' };
- Common::MemoryReadStream ms(contents, sizeof(contents));
+ MS ms(contents, sizeof(contents));
- Common::BitStream8MSB bs(ms);
+ BS bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.peekBit(), 0u);
TS_ASSERT_EQUALS(bs.pos(), 0u);
@@ -81,13 +110,20 @@ class BitStreamTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(bs.pos(), 1u);
TS_ASSERT(!bs.eos());
}
+public:
+ void test_peek_bit() {
+ tmpl_peek_bit<Common::MemoryReadStream, Common::BitStream8MSB>();
+ tmpl_peek_bit<Common::BitStreamMemoryStream, Common::BitStreamMemory8MSB>();
+ }
- void test_peek_bits() {
+private:
+ template<class MS, class BS>
+ void tmpl_peek_bits() {
byte contents[] = { 'a', 'b' };
- Common::MemoryReadStream ms(contents, sizeof(contents));
+ MS ms(contents, sizeof(contents));
- Common::BitStream8MSB bs(ms);
+ BS bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.peekBits(3), 3u);
TS_ASSERT_EQUALS(bs.pos(), 0u);
@@ -100,13 +136,20 @@ class BitStreamTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(bs.peekBits(5), 2u);
TS_ASSERT(!bs.eos());
}
+public:
+ void test_peek_bits() {
+ tmpl_peek_bits<Common::MemoryReadStream, Common::BitStream8MSB>();
+ tmpl_peek_bits<Common::BitStreamMemoryStream, Common::BitStreamMemory8MSB>();
+ }
- void test_eos() {
+private:
+ template<class MS, class BS>
+ void tmpl_eos() {
byte contents[] = { 'a', 'b' };
- Common::MemoryReadStream ms(contents, sizeof(contents));
+ MS ms(contents, sizeof(contents));
- Common::BitStream8MSB bs(ms);
+ BS bs(ms);
bs.skip(11);
TS_ASSERT_EQUALS(bs.pos(), 11u);
TS_ASSERT_EQUALS(bs.getBits(5), 2u);
@@ -116,13 +159,20 @@ class BitStreamTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT(!bs.eos());
}
+public:
+ void test_eos() {
+ tmpl_eos<Common::MemoryReadStream, Common::BitStream8MSB>();
+ tmpl_eos<Common::BitStreamMemoryStream, Common::BitStreamMemory8MSB>();
+ }
- void test_get_bits_lsb() {
+private:
+ template<class MS, class BS>
+ void tmpl_get_bits_lsb() {
byte contents[] = { 'a', 'b' };
- Common::MemoryReadStream ms(contents, sizeof(contents));
+ MS ms(contents, sizeof(contents));
- Common::BitStream8LSB bs(ms);
+ BS bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.getBits(3), 1u);
TS_ASSERT_EQUALS(bs.pos(), 3u);
@@ -130,13 +180,20 @@ class BitStreamTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(bs.pos(), 11u);
TS_ASSERT(!bs.eos());
}
+public:
+ void test_get_bits_lsb() {
+ tmpl_get_bits_lsb<Common::MemoryReadStream, Common::BitStream8LSB>();
+ tmpl_get_bits_lsb<Common::BitStreamMemoryStream, Common::BitStreamMemory8LSB>();
+ }
- void test_peek_bits_lsb() {
+private:
+ template<class MS, class BS>
+ void tmpl_peek_bits_lsb() {
byte contents[] = { 'a', 'b' };
- Common::MemoryReadStream ms(contents, sizeof(contents));
+ MS ms(contents, sizeof(contents));
- Common::BitStream8LSB bs(ms);
+ BS bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.peekBits(3), 1u);
TS_ASSERT_EQUALS(bs.pos(), 0u);
@@ -149,4 +206,9 @@ class BitStreamTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(bs.peekBits(5), 12u);
TS_ASSERT(!bs.eos());
}
+public:
+ void test_peek_bits_lsb() {
+ tmpl_peek_bits_lsb<Common::MemoryReadStream, Common::BitStream8LSB>();
+ tmpl_peek_bits_lsb<Common::BitStreamMemoryStream, Common::BitStreamMemory8LSB>();
+ }
};
diff --git a/video/bink_decoder.h b/video/bink_decoder.h
index 6f18dd539c..8a67913a03 100644
--- a/video/bink_decoder.h
+++ b/video/bink_decoder.h
@@ -32,6 +32,7 @@
#define VIDEO_BINK_DECODER_H
#include "common/array.h"
+#include "common/bitstream.h"
#include "common/rational.h"
#include "video/video_decoder.h"
@@ -45,7 +46,6 @@ class QueuingAudioStream;
namespace Common {
class SeekableReadStream;
-class BitStream;
class Huffman;
class RDFT;
@@ -100,7 +100,7 @@ private:
uint32 sampleCount;
- Common::BitStream *bits;
+ Common::BitStream32LELSB *bits;
bool first;
@@ -133,7 +133,7 @@ private:
uint32 offset;
uint32 size;
- Common::BitStream *bits;
+ Common::BitStream32LELSB *bits;
VideoFrame();
~VideoFrame();
diff --git a/video/psx_decoder.cpp b/video/psx_decoder.cpp
index 426f5eb608..562da885b1 100644
--- a/video/psx_decoder.cpp
+++ b/video/psx_decoder.cpp
@@ -27,7 +27,6 @@
#include "audio/decoders/raw.h"
#include "common/bitstream.h"
#include "common/huffman.h"
-#include "common/memstream.h"
#include "common/stream.h"
#include "common/system.h"
#include "common/textconsole.h"
@@ -232,7 +231,7 @@ void PSXStreamDecoder::readNextPacket() {
if (curSector == sectorCount - 1) {
// Done assembling the frame
- Common::SeekableReadStream *frame = new Common::MemoryReadStream(partialFrame, frameSize, DisposeAfterUse::YES);
+ Common::BitStreamMemoryStream *frame = new Common::BitStreamMemoryStream(partialFrame, frameSize, DisposeAfterUse::YES);
_videoTrack->decodeFrame(frame, sectorsRead);
@@ -464,10 +463,10 @@ const Graphics::Surface *PSXStreamDecoder::PSXVideoTrack::decodeNextFrame() {
return _surface;
}
-void PSXStreamDecoder::PSXVideoTrack::decodeFrame(Common::SeekableReadStream *frame, uint sectorCount) {
+void PSXStreamDecoder::PSXVideoTrack::decodeFrame(Common::BitStreamMemoryStream *frame, uint sectorCount) {
// A frame is essentially an MPEG-1 intra frame
- Common::BitStream16LEMSB bits(frame);
+ Common::BitStreamMemory16LEMSB bits(frame);
bits.skip(16); // unknown
bits.skip(16); // 0x3800
@@ -499,7 +498,7 @@ void PSXStreamDecoder::PSXVideoTrack::decodeFrame(Common::SeekableReadStream *fr
_nextFrameStartTime = _nextFrameStartTime.addFrames(sectorCount);
}
-void PSXStreamDecoder::PSXVideoTrack::decodeMacroBlock(Common::BitStream *bits, int mbX, int mbY, uint16 scale, uint16 version) {
+void PSXStreamDecoder::PSXVideoTrack::decodeMacroBlock(Common::BitStreamMemory16LEMSB *bits, int mbX, int mbY, uint16 scale, uint16 version) {
int pitchY = _macroBlocksW * 16;
int pitchC = _macroBlocksW * 8;
@@ -546,7 +545,7 @@ void PSXStreamDecoder::PSXVideoTrack::dequantizeBlock(int *coefficients, float *
}
}
-int PSXStreamDecoder::PSXVideoTrack::readDC(Common::BitStream *bits, uint16 version, PlaneType plane) {
+int PSXStreamDecoder::PSXVideoTrack::readDC(Common::BitStreamMemory16LEMSB *bits, uint16 version, PlaneType plane) {
// Version 2 just has its coefficient as 10-bits
if (version == 2)
return readSignedCoefficient(bits);
@@ -576,7 +575,7 @@ int PSXStreamDecoder::PSXVideoTrack::readDC(Common::BitStream *bits, uint16 vers
if (count > 63) \
error("PSXStreamDecoder::readAC(): Too many coefficients")
-void PSXStreamDecoder::PSXVideoTrack::readAC(Common::BitStream *bits, int *block) {
+void PSXStreamDecoder::PSXVideoTrack::readAC(Common::BitStreamMemory16LEMSB *bits, int *block) {
// Clear the block first
for (int i = 0; i < 63; i++)
block[i] = 0;
@@ -611,7 +610,7 @@ void PSXStreamDecoder::PSXVideoTrack::readAC(Common::BitStream *bits, int *block
}
}
-int PSXStreamDecoder::PSXVideoTrack::readSignedCoefficient(Common::BitStream *bits) {
+int PSXStreamDecoder::PSXVideoTrack::readSignedCoefficient(Common::BitStreamMemory16LEMSB *bits) {
uint val = bits->getBits(10);
// extend the sign
@@ -672,7 +671,7 @@ void PSXStreamDecoder::PSXVideoTrack::idct(float *dequantData, float *result) {
}
}
-void PSXStreamDecoder::PSXVideoTrack::decodeBlock(Common::BitStream *bits, byte *block, int pitch, uint16 scale, uint16 version, PlaneType plane) {
+void PSXStreamDecoder::PSXVideoTrack::decodeBlock(Common::BitStreamMemory16LEMSB *bits, byte *block, int pitch, uint16 scale, uint16 version, PlaneType plane) {
// Version 2 just has signed 10 bits for DC
// Version 3 has them huffman coded
int coefficients[8 * 8];
diff --git a/video/psx_decoder.h b/video/psx_decoder.h
index b19bd72fa0..c96642276a 100644
--- a/video/psx_decoder.h
+++ b/video/psx_decoder.h
@@ -23,6 +23,7 @@
#ifndef VIDEO_PSX_DECODER_H
#define VIDEO_PSX_DECODER_H
+#include "common/bitstream.h"
#include "common/endian.h"
#include "common/rational.h"
#include "common/rect.h"
@@ -35,9 +36,7 @@ class QueuingAudioStream;
}
namespace Common {
-class BitStream;
class Huffman;
-class SeekableReadStream;
}
namespace Graphics {
@@ -91,7 +90,7 @@ private:
const Graphics::Surface *decodeNextFrame();
void setEndOfTrack() { _endOfTrack = true; }
- void decodeFrame(Common::SeekableReadStream *frame, uint sectorCount);
+ void decodeFrame(Common::BitStreamMemoryStream *frame, uint sectorCount);
private:
Graphics::Surface *_surface;
@@ -108,19 +107,19 @@ private:
uint16 _macroBlocksW, _macroBlocksH;
byte *_yBuffer, *_cbBuffer, *_crBuffer;
- void decodeMacroBlock(Common::BitStream *bits, int mbX, int mbY, uint16 scale, uint16 version);
- void decodeBlock(Common::BitStream *bits, byte *block, int pitch, uint16 scale, uint16 version, PlaneType plane);
+ void decodeMacroBlock(Common::BitStreamMemory16LEMSB *bits, int mbX, int mbY, uint16 scale, uint16 version);
+ void decodeBlock(Common::BitStreamMemory16LEMSB *bits, byte *block, int pitch, uint16 scale, uint16 version, PlaneType plane);
- void readAC(Common::BitStream *bits, int *block);
+ void readAC(Common::BitStreamMemory16LEMSB *bits, int *block);
Common::Huffman *_acHuffman;
- int readDC(Common::BitStream *bits, uint16 version, PlaneType plane);
+ int readDC(Common::BitStreamMemory16LEMSB *bits, uint16 version, PlaneType plane);
Common::Huffman *_dcHuffmanLuma, *_dcHuffmanChroma;
int _lastDC[3];
void dequantizeBlock(int *coefficients, float *block, uint16 scale);
void idct(float *dequantData, float *result);
- int readSignedCoefficient(Common::BitStream *bits);
+ int readSignedCoefficient(Common::BitStreamMemory16LEMSB *bits);
};
class PSXAudioTrack : public AudioTrack {
diff --git a/video/smk_decoder.cpp b/video/smk_decoder.cpp
index d913707119..55b43bd746 100644
--- a/video/smk_decoder.cpp
+++ b/video/smk_decoder.cpp
@@ -29,7 +29,6 @@
#include "common/endian.h"
#include "common/util.h"
#include "common/stream.h"
-#include "common/memstream.h"
#include "common/bitstream.h"
#include "common/system.h"
#include "common/textconsole.h"
@@ -54,9 +53,9 @@ enum SmkBlockTypes {
class SmallHuffmanTree {
public:
- SmallHuffmanTree(Common::BitStream &bs);
+ SmallHuffmanTree(Common::BitStreamMemory8LSB &bs);
- uint16 getCode(Common::BitStream &bs);
+ uint16 getCode(Common::BitStreamMemory8LSB &bs);
private:
enum {
SMK_NODE = 0x8000
@@ -70,10 +69,10 @@ private:
uint16 _prefixtree[256];
byte _prefixlength[256];
- Common::BitStream &_bs;
+ Common::BitStreamMemory8LSB &_bs;
};
-SmallHuffmanTree::SmallHuffmanTree(Common::BitStream &bs)
+SmallHuffmanTree::SmallHuffmanTree(Common::BitStreamMemory8LSB &bs)
: _treeSize(0), _bs(bs) {
uint32 bit = _bs.getBit();
assert(bit);
@@ -118,7 +117,7 @@ uint16 SmallHuffmanTree::decodeTree(uint32 prefix, int length) {
return r1+r2+1;
}
-uint16 SmallHuffmanTree::getCode(Common::BitStream &bs) {
+uint16 SmallHuffmanTree::getCode(Common::BitStreamMemory8LSB &bs) {
byte peek = bs.peekBits(MIN<uint32>(bs.size() - bs.pos(), 8));
uint16 *p = &_tree[_prefixtree[peek]];
bs.skip(_prefixlength[peek]);
@@ -139,11 +138,11 @@ uint16 SmallHuffmanTree::getCode(Common::BitStream &bs) {
class BigHuffmanTree {
public:
- BigHuffmanTree(Common::BitStream &bs, int allocSize);
+ BigHuffmanTree(Common::BitStreamMemory8LSB &bs, int allocSize);
~BigHuffmanTree();
void reset();
- uint32 getCode(Common::BitStream &bs);
+ uint32 getCode(Common::BitStreamMemory8LSB &bs);
private:
enum {
SMK_NODE = 0x80000000
@@ -159,13 +158,13 @@ private:
byte _prefixlength[256];
/* Used during construction */
- Common::BitStream &_bs;
+ Common::BitStreamMemory8LSB &_bs;
uint32 _markers[3];
SmallHuffmanTree *_loBytes;
SmallHuffmanTree *_hiBytes;
};
-BigHuffmanTree::BigHuffmanTree(Common::BitStream &bs, int allocSize)
+BigHuffmanTree::BigHuffmanTree(Common::BitStreamMemory8LSB &bs, int allocSize)
: _bs(bs) {
uint32 bit = _bs.getBit();
if (!bit) {
@@ -256,7 +255,7 @@ uint32 BigHuffmanTree::decodeTree(uint32 prefix, int length) {
return r1+r2+1;
}
-uint32 BigHuffmanTree::getCode(Common::BitStream &bs) {
+uint32 BigHuffmanTree::getCode(Common::BitStreamMemory8LSB &bs) {
byte peek = bs.peekBits(MIN<uint32>(bs.size() - bs.pos(), 8));
uint32 *p = &_tree[_prefixtree[peek]];
bs.skip(_prefixlength[peek]);
@@ -386,7 +385,7 @@ bool SmackerDecoder::loadStream(Common::SeekableReadStream *stream) {
byte *huffmanTrees = (byte *) malloc(_header.treesSize);
_fileStream->read(huffmanTrees, _header.treesSize);
- Common::BitStream8LSB bs(new Common::MemoryReadStream(huffmanTrees, _header.treesSize, DisposeAfterUse::YES), DisposeAfterUse::YES);
+ Common::BitStreamMemory8LSB bs(new Common::BitStreamMemoryStream(huffmanTrees, _header.treesSize, DisposeAfterUse::YES), DisposeAfterUse::YES);
videoTrack->readTrees(bs, _header.mMapSize, _header.mClrSize, _header.fullSize, _header.typeSize);
_firstFrameStart = _fileStream->pos();
@@ -469,7 +468,7 @@ void SmackerDecoder::readNextPacket() {
_fileStream->read(frameData, frameDataSize);
- Common::BitStream8LSB bs(new Common::MemoryReadStream(frameData, frameDataSize + 1, DisposeAfterUse::YES), DisposeAfterUse::YES);
+ Common::BitStreamMemory8LSB bs(new Common::BitStreamMemoryStream(frameData, frameDataSize + 1, DisposeAfterUse::YES), DisposeAfterUse::YES);
videoTrack->decodeFrame(bs);
_fileStream->seek(startPos + frameSize);
@@ -553,14 +552,14 @@ Graphics::PixelFormat SmackerDecoder::SmackerVideoTrack::getPixelFormat() const
return _surface->format;
}
-void SmackerDecoder::SmackerVideoTrack::readTrees(Common::BitStream &bs, uint32 mMapSize, uint32 mClrSize, uint32 fullSize, uint32 typeSize) {
+void SmackerDecoder::SmackerVideoTrack::readTrees(Common::BitStreamMemory8LSB &bs, uint32 mMapSize, uint32 mClrSize, uint32 fullSize, uint32 typeSize) {
_MMapTree = new BigHuffmanTree(bs, mMapSize);
_MClrTree = new BigHuffmanTree(bs, mClrSize);
_FullTree = new BigHuffmanTree(bs, fullSize);
_TypeTree = new BigHuffmanTree(bs, typeSize);
}
-void SmackerDecoder::SmackerVideoTrack::decodeFrame(Common::BitStream &bs) {
+void SmackerDecoder::SmackerVideoTrack::decodeFrame(Common::BitStreamMemory8LSB &bs) {
_MMapTree->reset();
_MClrTree->reset();
_FullTree->reset();
@@ -774,7 +773,7 @@ Audio::AudioStream *SmackerDecoder::SmackerAudioTrack::getAudioStream() const {
}
void SmackerDecoder::SmackerAudioTrack::queueCompressedBuffer(byte *buffer, uint32 bufferSize, uint32 unpackedSize) {
- Common::BitStream8LSB audioBS(new Common::MemoryReadStream(buffer, bufferSize), DisposeAfterUse::YES);
+ Common::BitStreamMemory8LSB audioBS(new Common::BitStreamMemoryStream(buffer, bufferSize), DisposeAfterUse::YES);
bool dataPresent = audioBS.getBit();
if (!dataPresent)
diff --git a/video/smk_decoder.h b/video/smk_decoder.h
index bc04a683d2..d7a4459c85 100644
--- a/video/smk_decoder.h
+++ b/video/smk_decoder.h
@@ -23,6 +23,7 @@
#ifndef VIDEO_SMK_PLAYER_H
#define VIDEO_SMK_PLAYER_H
+#include "common/bitstream.h"
#include "common/rational.h"
#include "graphics/pixelformat.h"
#include "graphics/surface.h"
@@ -34,7 +35,6 @@ class QueuingAudioStream;
}
namespace Common {
-class BitStream;
class SeekableReadStream;
}
@@ -91,9 +91,9 @@ protected:
const byte *getPalette() const { _dirtyPalette = false; return _palette; }
bool hasDirtyPalette() const { return _dirtyPalette; }
- void readTrees(Common::BitStream &bs, uint32 mMapSize, uint32 mClrSize, uint32 fullSize, uint32 typeSize);
+ void readTrees(Common::BitStreamMemory8LSB &bs, uint32 mMapSize, uint32 mClrSize, uint32 fullSize, uint32 typeSize);
void increaseCurFrame() { _curFrame++; }
- void decodeFrame(Common::BitStream &bs);
+ void decodeFrame(Common::BitStreamMemory8LSB &bs);
void unpackPalette(Common::SeekableReadStream *stream);
protected: