aboutsummaryrefslogtreecommitdiff
path: root/image/codecs
diff options
context:
space:
mode:
authorPaul Gilbert2016-09-10 20:35:02 -0400
committerPaul Gilbert2016-09-10 20:35:02 -0400
commit23b1dbbb0e9c10035a1df98bffa9d6eaa5a6d338 (patch)
treefb2b3194e646bce8e7f6f966424fc217b586c502 /image/codecs
parent9c6a55a2a660d2c59e9c0e22402e4d16e08ef987 (diff)
downloadscummvm-rg350-23b1dbbb0e9c10035a1df98bffa9d6eaa5a6d338.tar.gz
scummvm-rg350-23b1dbbb0e9c10035a1df98bffa9d6eaa5a6d338.tar.bz2
scummvm-rg350-23b1dbbb0e9c10035a1df98bffa9d6eaa5a6d338.zip
IMAGE: Refactored Indeo GetBits class to derive from Common::BitStream
Diffstat (limited to 'image/codecs')
-rw-r--r--image/codecs/indeo/get_bits.cpp440
-rw-r--r--image/codecs/indeo/get_bits.h129
-rw-r--r--image/codecs/indeo/indeo.cpp24
-rw-r--r--image/codecs/indeo4.cpp71
-rw-r--r--image/codecs/indeo5.cpp55
5 files changed, 105 insertions, 614 deletions
diff --git a/image/codecs/indeo/get_bits.cpp b/image/codecs/indeo/get_bits.cpp
index ade4baaa81..ede5fa2a8f 100644
--- a/image/codecs/indeo/get_bits.cpp
+++ b/image/codecs/indeo/get_bits.cpp
@@ -21,439 +21,39 @@
*/
#include "image/codecs/indeo/get_bits.h"
-#include "image/codecs/indeo/mem.h"
-#include "common/algorithm.h"
-#include "common/endian.h"
-#include "common/textconsole.h"
-
-/* Intel Indeo 4 bitstream reader
- *
- * Original copyright note:
- * Copyright (c) 2004 Michael Niedermayer
- */
namespace Image {
namespace Indeo {
-/* Macro documentation
- * name
- * arbitrary name which is used as prefix for local variables
- *
- * OPEN_READER(name)
- * load index into local variable
- *
- * CLOSE_READER(name)
- * store local index back into class state
- *
- * UPDATE_CACHE(name)
- * Refill the internal cache from the bitstream.
- * After this call at least MIN_CACHE_BITS will be available.
- *
- * GET_CACHE(name)
- * Will output the contents of the internal cache,
- * next bit is MSB of 32 or 64 bits (FIXME 64 bits).
- *
- * SHOW_UBITS(name, num)
- * Will return the next num bits.
- *
- * SHOW_SBITS(name, num)
- * Will return the next num bits and do sign extension.
- *
- * SKIP_BITS(name, num)
- * Will skip over the next num bits.
- * Note, this is equivalent to SKIP_CACHE; SKIP_COUNTER.
- *
- * SKIP_CACHE(name, num)
- * Will remove the next num bits from the cache (note SKIP_COUNTER
- * MUST be called before UPDATE_CACHE / CLOSE_READER).
- *
- * SKIP_COUNTER(name, num)
- * Will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS).
- *
- * LAST_SKIP_BITS(name, num)
- * Like SKIP_BITS, to be used if next call is UPDATE_CACHE or CLOSE_READER.
- *
- * BITS_LEFT(name)
- * Return the number of bits left
- *
- * For examples see getBits, show_bits, skip_bits, get_vlc.
- */
-#define BITSTREAM_READER_LE
-
-#ifdef LONG_BITSTREAM_READER
-# define MIN_CACHE_BITS 32
-#else
-# define MIN_CACHE_BITS 25
-#endif
-
-#define NEG_USR32(a,s) (((uint32)(a)) >> (32 -(s)))
-
-#define OPEN_READER_NOSIZE(name) \
- unsigned int name ## _index = _index; \
- unsigned int name ## _cache
-
-#define OPEN_READER(name) OPEN_READER_NOSIZE(name)
-#define BITS_AVAILABLE(name) 1
-
-#define CLOSE_READER(name) _index = name ## _index
-
-# ifdef LONG_BITSTREAM_READER
-# define UPDATE_CACHE_LE(name) name ## _cache = \
- AV_RL64(_buffer + (name ## _index >> 3)) >> (name ## _index & 7)
-
-# define UPDATE_CACHE_BE(name) name ## _cache = \
- AV_RB64(_buffer + (name ## _index >> 3)) >> (32 - (name ## _index & 7))
-#else
-# define UPDATE_CACHE_LE(name) name ## _cache = \
- READ_LE_UINT32(_buffer + (name ## _index >> 3)) >> (name ## _index & 7)
-
-# define UPDATE_CACHE_BE(name) name ## _cache = \
- AV_RB32(_buffer + (name ## _index >> 3)) << (name ## _index & 7)
-#endif
-
-#ifdef BITSTREAM_READER_LE
-# define UPDATE_CACHE(name) UPDATE_CACHE_LE(name)
-# define SKIP_CACHE(name, num) name ## _cache >>= (num)
-#else
-# define UPDATE_CACHE(name) UPDATE_CACHE_BE(name)
-# define SKIP_CACHE(name, num) name ## _cache <<= (num)
-#endif
-
-#define SKIP_COUNTER(name, num) name ## _index += (num)
-
-#define BITS_LEFT(name) ((int)(_size_in_bits - name ## _index))
-
-#define SKIP_BITS(name, num) \
- do { \
- SKIP_CACHE(name, num); \
- SKIP_COUNTER(name, num); \
- } while (0)
-
-#define LAST_SKIP_BITS(name, num) SKIP_COUNTER(name, num)
-
-#define SHOW_UBITS_LE(name, num) zeroExtend(name ## _cache, num)
-#define SHOW_SBITS_LE(name, num) signExtend(name ## _cache, num)
-
-#define SHOW_UBITS_BE(name, num) NEG_USR32(name ## _cache, num)
-#define SHOW_SBITS_BE(name, num) NEG_SSR32(name ## _cache, num)
-
-#ifdef BITSTREAM_READER_LE
-# define SHOW_UBITS(name, num) SHOW_UBITS_LE(name, num)
-# define SHOW_SBITS(name, num) SHOW_SBITS_LE(name, num)
-#else
-# define SHOW_UBITS(name, num) SHOW_UBITS_BE(name, num)
-# define SHOW_SBITS(name, num) SHOW_SBITS_BE(name, num)
-#endif
-
-#define GET_CACHE(name) ((uint32) name ## _cache)
-
-
-static int signExtend(int val, uint bits) {
- uint shift = 8 * sizeof(int) - bits;
- union { uint u; int s; } v = { (unsigned)val << shift };
- return v.s >> shift;
-}
-
-static uint zeroExtend(uint val, uint bits) {
- return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);
-}
-
-GetBits::GetBits(const byte *buffer, size_t totalBits) {
- assert(buffer && totalBits < (MAX_INTEGER - 7));
-
- _buffer = buffer;
- _sizeInBits = totalBits;
- _sizeInBitsPlus8 = totalBits + 8;
- _index = 0;
-}
-
-GetBits::GetBits(const GetBits &src) : _index(src._index), _buffer(src._buffer),
- _sizeInBits(src._sizeInBits), _sizeInBitsPlus8(src._sizeInBitsPlus8){
-}
-
-int GetBits::getXbits(int n) {
- int sign;
- int cache;
- OPEN_READER(re);
- assert(n > 0 && n <= 25);
- UPDATE_CACHE(re);
- cache = GET_CACHE(re);
- sign = ~cache >> 31;
- LAST_SKIP_BITS(re, n);
- CLOSE_READER(re);
- return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
-}
-
-int GetBits::getSbits(int n) {
- int tmp;
- OPEN_READER(re);
- assert(n > 0 && n <= 25);
- UPDATE_CACHE(re);
- tmp = SHOW_SBITS(re, n);
- LAST_SKIP_BITS(re, n);
- CLOSE_READER(re);
- return tmp;
-}
-
-/**
-* Read 1-25 bits.
-*/
-uint GetBits::getBits(int n) {
- int tmp;
- OPEN_READER(re);
- assert(n > 0 && n <= 25);
- UPDATE_CACHE(re);
- tmp = SHOW_UBITS(re, n);
- LAST_SKIP_BITS(re, n);
- CLOSE_READER(re);
- return tmp;
-}
-
-int GetBits::getBitsZ(int n) {
- return n ? getBits(n) : 0;
-}
-
-uint GetBits::getBitsLE(int n) {
- int tmp;
- OPEN_READER(re);
- assert(n > 0 && n <= 25);
- UPDATE_CACHE_LE(re);
- tmp = SHOW_UBITS_LE(re, n);
- LAST_SKIP_BITS(re, n);
- CLOSE_READER(re);
- return tmp;
-}
-
-uint GetBits::showBits(int n) {
- int tmp;
- OPEN_READER_NOSIZE(re);
- assert(n > 0 && n <= 25);
- UPDATE_CACHE(re);
- tmp = SHOW_UBITS(re, n);
- return tmp;
-}
-
-void GetBits::skipBits(int n) {
- OPEN_READER(re);
- LAST_SKIP_BITS(re, n);
- CLOSE_READER(re);
-}
-
-uint GetBits::getBits1() {
- uint index = _index;
- uint8 result = _buffer[index >> 3];
-#ifdef BITSTREAM_READER_LE
- result >>= index & 7;
- result &= 1;
-#else
- result <<= index & 7;
- result >>= 8 - 1;
-#endif
- index++;
- _index = index;
-
- return result;
-}
-
-uint GetBits::showBits1() {
- return showBits(1);
-}
-
-void GetBits::skipBits1() {
- skipBits(1);
-}
-
-/**
-* Read 0-32 bits.
-*/
-uint GetBits::getBitsLong(int n) {
- if (!n) {
- return 0;
- } else if (n <= MIN_CACHE_BITS) {
- return getBits(n);
- } else {
-#ifdef BITSTREAM_READER_LE
- unsigned ret = getBits(16);
- return ret | (getBits(n - 16) << 16);
-#else
- unsigned ret = getBits(16) << (n - 16);
- return ret | getBits(n - 16);
-#endif
- }
-}
-
-/**
- * Read 0-64 bits.
- */
-uint64 GetBits::getBits64(int n) {
- if (n <= 32) {
- return getBitsLong(n);
- } else {
-#ifdef BITSTREAM_READER_LE
- uint64 ret = getBitsLong(32);
- return ret | (uint64)getBitsLong(n - 32) << 32;
-#else
- uint64 ret = (uint64)getBitsLong(n - 32) << 32;
- return ret | getBitsLong(32);
-#endif
- }
-}
-
-int GetBits::getSbitsLong(int n) {
- return signExtend(getBitsLong(n), n);
-}
-
-/**
-* Show 0-32 bits.
-*/
-uint GetBits::showBitsLong(int n) {
- if (n <= MIN_CACHE_BITS) {
- return showBits(n);
- } else {
- GetBits gb(*this);
- return gb.getBitsLong(n);
- }
-}
-
-int GetBits::checkMarker(void *logctx, const char *msg) {
- int bit = getBits1();
- if (!bit)
- warning("Marker bit missing at %d of %d %s\n",
- getBitsCount() - 1, _sizeInBits, msg);
-
- return bit;
-}
-
-const byte *GetBits::alignGetBits() {
- int n = -(int)getBitsCount() & 7;
- if (n)
- skipBits(n);
-
- return _buffer + (_index >> 3);
-}
-
-/**
- * If the vlc code is invalid and max_depth=1, then no bits will be removed.
- * If the vlc code is invalid and max_depth>1, then the number of bits removed
- * is undefined.
- */
-#define GET_VLC(code, name, table, bits, max_depth) \
- do { \
- int n, nb_bits; \
- unsigned int index; \
- \
- index = SHOW_UBITS(name, bits); \
- code = table[index][0]; \
- n = table[index][1]; \
- \
- if (max_depth > 1 && n < 0) { \
- LAST_SKIP_BITS(name, bits); \
- UPDATE_CACHE(name); \
- \
- nb_bits = -n; \
- \
- index = SHOW_UBITS(name, nb_bits) + code; \
- code = table[index][0]; \
- n = table[index][1]; \
- if (max_depth > 2 && n < 0) { \
- LAST_SKIP_BITS(name, nb_bits); \
- UPDATE_CACHE(name); \
- \
- nb_bits = -n; \
- \
- index = SHOW_UBITS(name, nb_bits) + code; \
- code = table[index][0]; \
- n = table[index][1]; \
- } \
- } \
- SKIP_BITS(name, n); \
- } while (0)
-
-#define GET_RL_VLC(level, run, name, table, bits, \
- max_depth, need_update) \
- do { \
- int n, nb_bits; \
- unsigned int index; \
- \
- index = SHOW_UBITS(name, bits); \
- level = table[index].level; \
- n = table[index].len; \
- \
- if (max_depth > 1 && n < 0) { \
- SKIP_BITS(name, bits); \
- if (need_update) { \
- UPDATE_CACHE(name); \
- } \
- \
- nb_bits = -n; \
- \
- index = SHOW_UBITS(name, nb_bits) + level; \
- level = table[index].level; \
- n = table[index].len; \
- if (max_depth > 2 && n < 0) { \
- LAST_SKIP_BITS(name, nb_bits); \
- if (need_update) { \
- UPDATE_CACHE(name); \
- } \
- nb_bits = -n; \
- \
- index = SHOW_UBITS(name, nb_bits) + level; \
- level = table[index].level; \
- n = table[index].len; \
- } \
- } \
- run = table[index].run; \
- SKIP_BITS(name, n); \
- } while (0)
-
-/**
-* Parse a vlc code.
-* @param bits is the number of bits which will be read at once, must be
-* identical to nb_bits in init_vlc()
-* @param max_depth is the number of times bits bits must be read to completely
-* read the longest vlc code
-* = (max_vlc_length + bits - 1) / bits
-*/
int GetBits::getVLC2(int16 (*table)[2], int bits, int maxDepth) {
int code;
+ int n, nbBits;
+ unsigned int index;
- OPEN_READER(re);
- UPDATE_CACHE(re);
+ index = peekBits(bits);
+ code = table[index][0];
+ n = table[index][1];
- GET_VLC(code, re, table, bits, maxDepth);
+ if (maxDepth > 1 && n < 0) {
+ skip(bits);
+ nbBits = -n;
- CLOSE_READER(re);
+ index = peekBits(nbBits) + code;
+ code = table[index][0];
+ n = table[index][1];
- return code;
-}
+ if (maxDepth > 2 && n < 0) {
+ skip(nbBits);
+ nbBits = -n;
-int GetBits::decode012() {
- int n;
- n = getBits1();
- if (n == 0)
- return 0;
- else
- return getBits1() + 1;
-}
-
-int GetBits::decode210() {
- if (getBits1())
- return 0;
- else
- return 2 - getBits1();
-}
-
-int GetBits::skip1stop8dataBits() {
- if (getBitsLeft() <= 0)
- return -1;
-
- while (getBits1()) {
- skipBits(8);
- if (getBitsLeft() <= 0)
- return -1;
+ index = peekBits(nbBits) + code;
+ code = table[index][0];
+ n = table[index][1];
+ }
}
- return 0;
+ skip(n);
+ return code;
}
} // End of namespace Indeo
diff --git a/image/codecs/indeo/get_bits.h b/image/codecs/indeo/get_bits.h
index 986bfc8a99..359d8fcab0 100644
--- a/image/codecs/indeo/get_bits.h
+++ b/image/codecs/indeo/get_bits.h
@@ -20,152 +20,41 @@
*
*/
-#include "common/scummsys.h"
-
-/* Indeo 4 & 5 bitstream reader
- *
- * Original copyright note:
- * Copyright (c) 2004 Michael Niedermayer
- */
-
#ifndef IMAGE_CODECS_INDEO_GET_BITS_H
#define IMAGE_CODECS_INDEO_GET_BITS_H
-#include "common/scummsys.h"
-#include "common/stream.h"
-#include "common/types.h"
+#include "common/bitstream.h"
namespace Image {
namespace Indeo {
-#define AV_INPUT_BUFFER_PADDING_SIZE 32
-
/**
* Intel Indeo Bitstream reader
*/
-class GetBits {
-private:
- const byte *_buffer;
- uint _index;
- uint _sizeInBits;
- uint _sizeInBitsPlus8;
+class GetBits : public Common::BitStream8LSB {
public:
/**
* Constructor
- * @param buffer Bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
- * larger than the actual read bits because some optimized bitstream
- * readers read 32 or 64 bit at once and could read over the end
- * @param bit_size the size of the buffer in bits
- * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
+ * @param stream Source stream to reader from
+ * @param disposeAfterUse Whether to destroy stream in destructor
*/
- GetBits(const byte *buffer, size_t totalBits);
-
- /**
- * Copy constructor
- */
- GetBits(const GetBits &src);
-
- /**
- * Returns the number of bits read
- */
- uint getBitsCount() const { return _index; }
+ GetBits(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse
+ = DisposeAfterUse::YES) : Common::BitStream8LSB(stream, disposeAfterUse) {}
/**
* The number of bits left
*/
- int getBitsLeft() const { return _sizeInBits - _index; }
-
- void skipBitsLong(uint n) { _index += n; }
-
- /**
- * Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
- * if MSB not set it is negative
- * @param n length in bits
- */
- int getXbits(int n);
-
- /**
- * Returns the next n bits, and does sign extension
- */
- int getSbits(int n);
-
- /**
- * Read 1-25 bits.
- */
- uint getBits(int n);
-
- /**
- * Read 0-25 bits.
- */
- int getBitsZ(int n);
-
- uint getBitsLE(int n);
-
- /**
- * Show 1-25 bits.
- * Returns the data without updating the index
- */
- uint showBits(int n);
-
- /**
- * Skips a specified number of bits
- */
- void skipBits(int n);
-
- /**
- * Returns the next bit
- */
- uint getBits1();
-
- /**
- * Shows the next following bit
- */
- uint showBits1();
-
- /**
- * Skips the next bit
- */
- void skipBits1();
-
- /**
- * Read 0-32 bits.
- */
- uint getBitsLong(int n);
-
- /**
- * Read 0-64 bits.
- */
- uint64 getBits64(int n);
-
- /**
- * Read 0-32 bits as a signed integer.
- */
- int getSbitsLong(int n);
-
- /**
- * Show 0-32 bits.
- */
- uint showBitsLong(int n);
-
- int checkMarker(void *logctx, const char *msg);
+ int getBitsLeft() const { return size() - pos(); }
/**
* Parse a VLC code.
* @param bits is the number of bits which will be read at once, must be
- * identical to nb_bits in init_vlc()
- * @param max_depth is the number of times bits bits must be read to completely
+ * identical to nbBits in init_vlc()
+ * @param maxDepth is the number of times bits bits must be read to completely
* read the longest vlc code
* = (max_vlc_length + bits - 1) / bits
*/
int getVLC2(int16 (*table)[2], int bits, int maxDepth);
-
- int decode012();
-
- int decode210();
-
- int skip1stop8dataBits();
-
- const byte *alignGetBits();
};
} // End of namespace Indeo
diff --git a/image/codecs/indeo/indeo.cpp b/image/codecs/indeo/indeo.cpp
index f473b267bf..1250c57196 100644
--- a/image/codecs/indeo/indeo.cpp
+++ b/image/codecs/indeo/indeo.cpp
@@ -582,10 +582,10 @@ int IndeoDecoderBase::decodeIndeoFrame() {
if (_ctx._gb->getBitsLeft() < 8)
return -1;
}
- left = _ctx._gb->getBitsCount() & 0x18;
- _ctx._gb->skipBitsLong(64 - left);
+ left = _ctx._gb->pos() & 0x18;
+ _ctx._gb->skip(64 - left);
if (_ctx._gb->getBitsLeft() > 18 &&
- _ctx._gb->showBitsLong(21) == 0xBFFF8) { // syncheader + inter _type
+ _ctx._gb->peekBits(21) == 0xBFFF8) { // syncheader + inter _type
error("Indeo decoder: Mode not currently implemented in ScummVM");
}
}
@@ -618,7 +618,7 @@ int IndeoDecoderBase::decode_band(IVIBandDesc *band) {
band->_refBuf = band->_bufs[_ctx._refBuf];
band->_bRefBuf = 0;
}
- band->_dataPtr = _ctx._frameData + (_ctx._gb->getBitsCount() >> 3);
+ band->_dataPtr = _ctx._frameData + (_ctx._gb->pos() >> 3);
result = decodeBandHeader(band);
if (result) {
@@ -646,7 +646,7 @@ int IndeoDecoderBase::decode_band(IVIBandDesc *band) {
band->_rvMap->_escSym ^= idx1 ^ idx2;
}
- pos = _ctx._gb->getBitsCount();
+ pos = _ctx._gb->pos();
for (t = 0; t < band->_numTiles; t++) {
tile = &band->_tiles[t];
@@ -656,7 +656,7 @@ int IndeoDecoderBase::decode_band(IVIBandDesc *band) {
band->_mbSize, tile->_mbSize);
return -1;
}
- tile->_isEmpty = _ctx._gb->getBits1();
+ tile->_isEmpty = _ctx._gb->getBit();
if (tile->_isEmpty) {
result = processEmptyTile(band, tile,
(_ctx._planes[0]._bands[0]._mbSize >> 3) - (band->_mbSize >> 3));
@@ -681,7 +681,7 @@ int IndeoDecoderBase::decode_band(IVIBandDesc *band) {
break;
}
- if ((((int)_ctx._gb->getBitsCount() - pos) >> 3) != tile->_dataSize) {
+ if ((((int)_ctx._gb->pos() - pos) >> 3) != tile->_dataSize) {
warning("Tile _dataSize mismatch!");
result = -1;
break;
@@ -704,7 +704,7 @@ int IndeoDecoderBase::decode_band(IVIBandDesc *band) {
band->_rvMap->_escSym ^= idx1 ^ idx2;
}
- _ctx._gb->alignGetBits();
+ _ctx._gb->align();
return result;
}
@@ -1046,14 +1046,14 @@ int IndeoDecoderBase::processEmptyTile(IVIBandDesc *band,
int IndeoDecoderBase::decodeTileDataSize(GetBits *gb) {
int len = 0;
- if (gb->getBits1()) {
+ if (gb->getBit()) {
len = gb->getBits(8);
if (len == 255)
- len = gb->getBitsLong(24);
+ len = gb->getBits(24);
}
// align the bitstream reader on the byte boundary
- gb->alignGetBits();
+ gb->align();
return len;
}
@@ -1189,7 +1189,7 @@ int IndeoDecoderBase::decodeBlocks(GetBits *_gb, IVIBandDesc *band, IVITile *til
}// for blk
}// for mbn
- _gb->alignGetBits();
+ _gb->align();
return 0;
}
diff --git a/image/codecs/indeo4.cpp b/image/codecs/indeo4.cpp
index 78eb036159..60707e6642 100644
--- a/image/codecs/indeo4.cpp
+++ b/image/codecs/indeo4.cpp
@@ -29,6 +29,7 @@
*/
#include "common/endian.h"
+#include "common/memstream.h"
#include "common/stream.h"
#include "common/textconsole.h"
#include "common/util.h"
@@ -58,7 +59,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(buffer, 16 * 8);
+ Indeo::GetBits gb(new Common::MemoryReadStream(buffer, 16 * 8), DisposeAfterUse::YES);
bool isIndeo4 = gb.getBits(18) == 0x3FFF8;
return isIndeo4;
@@ -76,7 +77,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(_ctx._frameData, _ctx._frameSize * 8);
+ _ctx._gb = new GetBits(new Common::MemoryReadStream(_ctx._frameData, _ctx._frameSize * 8));
// Decode the frame
int err = decodeIndeoFrame();
@@ -110,15 +111,15 @@ int Indeo4Decoder::decodePictureHeader() {
if (_ctx._frameType == IVI4_FRAMETYPE_BIDIR)
_ctx._hasBFrames = true;
- _ctx._hasTransp = _ctx._gb->getBits1();
+ _ctx._hasTransp = _ctx._gb->getBit();
// unknown bit: Mac decoder ignores this bit, XANIM returns error
- if (_ctx._gb->getBits1()) {
+ if (_ctx._gb->getBit()) {
warning("Sync bit is set!");
return -1;
}
- _ctx._dataSize = _ctx._gb->getBits1() ? _ctx._gb->getBits(24) : 0;
+ _ctx._dataSize = _ctx._gb->getBit() ? _ctx._gb->getBits(24) : 0;
// null frames don't contain anything else so we just return
if (_ctx._frameType >= IVI4_FRAMETYPE_NULL_FIRST) {
@@ -129,8 +130,8 @@ int Indeo4Decoder::decodePictureHeader() {
// Check key lock status. If enabled - ignore lock word.
// Usually we have to prompt the user for the password, but
// we don't do that because Indeo 4 videos can be decoded anyway
- if (_ctx._gb->getBits1()) {
- _ctx._gb->skipBitsLong(32);
+ if (_ctx._gb->getBit()) {
+ _ctx._gb->skip(32);
warning("Password-protected clip!");
}
@@ -144,7 +145,7 @@ int Indeo4Decoder::decodePictureHeader() {
}
// Decode tile dimensions.
- _ctx._usesTiling = _ctx._gb->getBits1();
+ _ctx._usesTiling = _ctx._gb->getBit();
if (_ctx._usesTiling) {
_picConf._tileHeight = scaleTileSize(_picConf._picHeight, _ctx._gb->getBits(4));
_picConf._tileWidth = scaleTileSize(_picConf._picWidth, _ctx._gb->getBits(4));
@@ -198,39 +199,39 @@ int Indeo4Decoder::decodePictureHeader() {
}
}
- _ctx._frameNum = _ctx._gb->getBits1() ? _ctx._gb->getBits(20) : 0;
+ _ctx._frameNum = _ctx._gb->getBit() ? _ctx._gb->getBits(20) : 0;
// skip decTimeEst field if present
- if (_ctx._gb->getBits1())
- _ctx._gb->skipBits(8);
+ if (_ctx._gb->getBit())
+ _ctx._gb->skip(8);
// decode macroblock and block huffman codebooks
- if (_ctx._mbVlc.decodeHuffDesc(&_ctx, _ctx._gb->getBits1(), IVI_MB_HUFF) ||
- _ctx._blkVlc.decodeHuffDesc(&_ctx, _ctx._gb->getBits1(), IVI_BLK_HUFF))
+ if (_ctx._mbVlc.decodeHuffDesc(&_ctx, _ctx._gb->getBit(), IVI_MB_HUFF) ||
+ _ctx._blkVlc.decodeHuffDesc(&_ctx, _ctx._gb->getBit(), IVI_BLK_HUFF))
return -1;
- _ctx._rvmapSel = _ctx._gb->getBits1() ? _ctx._gb->getBits(3) : 8;
+ _ctx._rvmapSel = _ctx._gb->getBit() ? _ctx._gb->getBits(3) : 8;
- _ctx._inImf = _ctx._gb->getBits1();
- _ctx._inQ = _ctx._gb->getBits1();
+ _ctx._inImf = _ctx._gb->getBit();
+ _ctx._inQ = _ctx._gb->getBit();
_ctx._picGlobQuant = _ctx._gb->getBits(5);
// TODO: ignore this parameter if unused
- _ctx._unknown1 = _ctx._gb->getBits1() ? _ctx._gb->getBits(3) : 0;
+ _ctx._unknown1 = _ctx._gb->getBit() ? _ctx._gb->getBits(3) : 0;
- _ctx._checksum = _ctx._gb->getBits1() ? _ctx._gb->getBits(16) : 0;
+ _ctx._checksum = _ctx._gb->getBit() ? _ctx._gb->getBits(16) : 0;
// skip picture header extension if any
- while (_ctx._gb->getBits1()) {
- _ctx._gb->skipBits(8);
+ while (_ctx._gb->getBit()) {
+ _ctx._gb->skip(8);
}
- if (_ctx._gb->getBits1()) {
+ if (_ctx._gb->getBit()) {
warning("Bad blocks bits encountered!");
}
- _ctx._gb->alignGetBits();
+ _ctx._gb->align();
return 0;
}
@@ -281,13 +282,13 @@ int Indeo4Decoder::decodeBandHeader(IVIBandDesc *band) {
return -1;
}
- band->_isEmpty = _ctx._gb->getBits1();
+ band->_isEmpty = _ctx._gb->getBit();
if (!band->_isEmpty) {
int old_blk_size = band->_blkSize;
// skip header size
// If header size is not given, header size is 4 bytes.
- if (_ctx._gb->getBits1())
- _ctx._gb->skipBits(16);
+ if (_ctx._gb->getBit())
+ _ctx._gb->skip(16);
band->_isHalfpel = _ctx._gb->getBits(2);
if (band->_isHalfpel >= 2) {
@@ -298,7 +299,7 @@ int Indeo4Decoder::decodeBandHeader(IVIBandDesc *band) {
if (!band->_isHalfpel)
_ctx._usesFullpel = true;
- band->_checksumPresent = _ctx._gb->getBits1();
+ band->_checksumPresent = _ctx._gb->getBit();
if (band->_checksumPresent)
band->_checksum = _ctx._gb->getBits(16);
@@ -310,12 +311,12 @@ int Indeo4Decoder::decodeBandHeader(IVIBandDesc *band) {
band->_mbSize = 16 >> indx;
band->_blkSize = 8 >> (indx >> 1);
- band->_inheritMv = _ctx._gb->getBits1();
- band->_inheritQDelta = _ctx._gb->getBits1();
+ band->_inheritMv = _ctx._gb->getBit();
+ band->_inheritQDelta = _ctx._gb->getBit();
band->_globQuant = _ctx._gb->getBits(5);
- if (!_ctx._gb->getBits1() || _ctx._frameType == IVI4_FRAMETYPE_INTRA) {
+ if (!_ctx._gb->getBit() || _ctx._frameType == IVI4_FRAMETYPE_INTRA) {
transformId = _ctx._gb->getBits(5);
if ((uint)transformId >= FF_ARRAY_ELEMS(_transforms) ||
!_transforms[transformId]._invTrans) {
@@ -398,18 +399,18 @@ int Indeo4Decoder::decodeBandHeader(IVIBandDesc *band) {
}
// decode block huffman codebook
- if (!_ctx._gb->getBits1())
+ if (!_ctx._gb->getBit())
band->_blkVlc._tab = _ctx._blkVlc._tab;
else
if (band->_blkVlc.decodeHuffDesc(&_ctx, 1, IVI_BLK_HUFF))
return -1;
// select appropriate rvmap table for this band
- band->_rvmapSel = _ctx._gb->getBits1() ? _ctx._gb->getBits(3) : 8;
+ band->_rvmapSel = _ctx._gb->getBit() ? _ctx._gb->getBits(3) : 8;
// decode rvmap probability corrections if any
band->_numCorr = 0; // there is no corrections
- if (_ctx._gb->getBits1()) {
+ if (_ctx._gb->getBit()) {
band->_numCorr = _ctx._gb->getBits(8); // get number of correction pairs
if (band->_numCorr > 61) {
warning("Too many corrections: %d",
@@ -435,7 +436,7 @@ int Indeo4Decoder::decodeBandHeader(IVIBandDesc *band) {
band->_intraScale = NULL;
band->_interScale = NULL;
- _ctx._gb->alignGetBits();
+ _ctx._gb->align();
if (!band->_scan) {
warning("band->_scan not set");
@@ -476,7 +477,7 @@ int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
mb->_bufOffs = mbOffset;
mb->_bMvX = mb->_bMvY = 0;
- if (_ctx._gb->getBits1()) {
+ if (_ctx._gb->getBit()) {
if (_ctx._frameType == IVI4_FRAMETYPE_INTRA) {
warning("Empty macroblock in an INTRA picture!");
return -1;
@@ -593,7 +594,7 @@ int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
offs += row_offset;
}
- _ctx._gb->alignGetBits();
+ _ctx._gb->align();
return 0;
}
diff --git a/image/codecs/indeo5.cpp b/image/codecs/indeo5.cpp
index d7bb9d97f6..2b33a6b09c 100644
--- a/image/codecs/indeo5.cpp
+++ b/image/codecs/indeo5.cpp
@@ -29,6 +29,7 @@
*/
#include "common/endian.h"
+#include "common/memstream.h"
#include "common/stream.h"
#include "common/textconsole.h"
#include "common/util.h"
@@ -69,7 +70,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(buffer, 16 * 8);
+ Indeo::GetBits gb(new Common::MemoryReadStream(buffer, 16 * 8));
bool isIndeo5 = gb.getBits(5) == 0x1F;
return isIndeo5;
@@ -87,7 +88,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(_ctx._frameData, _ctx._frameSize * 8);
+ _ctx._gb = new GetBits(new Common::MemoryReadStream(_ctx._frameData, _ctx._frameSize * 8));
// Decode the frame
int err = decodeIndeoFrame();
@@ -140,7 +141,7 @@ int Indeo5Decoder::decodePictureHeader() {
if (_ctx._frameType != FRAMETYPE_NULL) {
_ctx._frameFlags = _ctx._gb->getBits(8);
- _ctx._picHdrSize = (_ctx._frameFlags & 1) ? _ctx._gb->getBitsLong(24) : 0;
+ _ctx._picHdrSize = (_ctx._frameFlags & 1) ? _ctx._gb->getBits(24) : 0;
_ctx._checksum = (_ctx._frameFlags & 0x10) ? _ctx._gb->getBits(16) : 0;
@@ -154,10 +155,10 @@ int Indeo5Decoder::decodePictureHeader() {
if (ret < 0)
return ret;
- _ctx._gb->skipBits(3); // FIXME: unknown meaning!
+ _ctx._gb->skip(3); // FIXME: unknown meaning!
}
- _ctx._gb->alignGetBits();
+ _ctx._gb->align();
return 0;
}
@@ -215,7 +216,7 @@ int Indeo5Decoder::decodeBandHeader(IVIBandDesc *band) {
return 0;
}
- band->_dataSize = (_ctx._frameFlags & 0x80) ? _ctx._gb->getBitsLong(24) : 0;
+ band->_dataSize = (_ctx._frameFlags & 0x80) ? _ctx._gb->getBits(24) : 0;
band->_inheritMv = (bandFlags & 2) != 0;
band->_inheritQDelta = (bandFlags & 8) != 0;
@@ -245,7 +246,7 @@ int Indeo5Decoder::decodeBandHeader(IVIBandDesc *band) {
if (ret < 0)
return ret;
- band->_checksumPresent = _ctx._gb->getBits1();
+ band->_checksumPresent = _ctx._gb->getBit();
if (band->_checksumPresent)
band->_checksum = _ctx._gb->getBits(16);
@@ -253,11 +254,11 @@ int Indeo5Decoder::decodeBandHeader(IVIBandDesc *band) {
// skip unknown extension if any
if (bandFlags & 0x20) { // XXX: untested
- _ctx._gb->alignGetBits();
+ _ctx._gb->align();
skip_hdr_extension();
}
- _ctx._gb->alignGetBits();
+ _ctx._gb->align();
return 0;
}
@@ -294,7 +295,7 @@ int Indeo5Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
mb->_yPos = y;
mb->_bufOffs = mbOffset;
- if (_ctx._gb->getBits1()) {
+ if (_ctx._gb->getBit()) {
if (_ctx._frameType == FRAMETYPE_INTRA) {
warning("Empty macroblock in an INTRA picture!");
return -1;
@@ -325,7 +326,7 @@ int Indeo5Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
} else if (_ctx._frameType == FRAMETYPE_INTRA) {
mb->_type = 0; // mb_type is always INTRA for intra-frames
} else {
- mb->_type = _ctx._gb->getBits1();
+ mb->_type = _ctx._gb->getBit();
}
blksPerMb = band->_mbSize != band->_blkSize ? 4 : 1;
@@ -384,7 +385,7 @@ int Indeo5Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
offs += rowOffset;
}
- _ctx._gb->alignGetBits();
+ _ctx._gb->align();
return 0;
}
@@ -401,7 +402,7 @@ int Indeo5Decoder::decode_gop_header() {
_ctx._gopHdrSize = (_ctx._gopFlags & 1) ? _ctx._gb->getBits(16) : 0;
if (_ctx._gopFlags & IVI5_IS_PROTECTED)
- _ctx._lockWord = _ctx._gb->getBitsLong(32);
+ _ctx._lockWord = _ctx._gb->getBits(32);
tile_size = (_ctx._gopFlags & 0x40) ? 64 << _ctx._gb->getBits(2) : 0;
if (tile_size > 256) {
@@ -412,7 +413,7 @@ int Indeo5Decoder::decode_gop_header() {
// decode number of wavelet bands
// num_levels * 3 + 1
picConf._lumaBands = _ctx._gb->getBits(2) * 3 + 1;
- picConf._chromaBands = _ctx._gb->getBits1() * 3 + 1;
+ picConf._chromaBands = _ctx._gb->getBit() * 3 + 1;
isScalable = picConf._lumaBands != 1 || picConf._chromaBands != 1;
if (isScalable && (picConf._lumaBands != 4 || picConf._chromaBands != 1)) {
warning("Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d",
@@ -460,10 +461,10 @@ int Indeo5Decoder::decode_gop_header() {
for (i = 0; i < (!p ? picConf._lumaBands : picConf._chromaBands); i++) {
band = &_ctx._planes[p]._bands[i];
- band->_isHalfpel = _ctx._gb->getBits1();
+ band->_isHalfpel = _ctx._gb->getBit();
- mbSize = _ctx._gb->getBits1();
- blkSize = 8 >> _ctx._gb->getBits1();
+ mbSize = _ctx._gb->getBit();
+ blkSize = 8 >> _ctx._gb->getBit();
mbSize = blkSize << !mbSize;
if (p == 0 && blkSize == 4) {
@@ -477,7 +478,7 @@ int Indeo5Decoder::decode_gop_header() {
band->_blkSize = blkSize;
}
- if (_ctx._gb->getBits1()) {
+ if (_ctx._gb->getBit()) {
warning("Extended transform info");
return -2;
}
@@ -595,22 +596,22 @@ int Indeo5Decoder::decode_gop_header() {
return -1;
}
- if (_ctx._gb->getBits1())
- _ctx._gb->skipBitsLong(24); // skip transparency fill color
+ if (_ctx._gb->getBit())
+ _ctx._gb->skip(24); // skip transparency fill color
}
- _ctx._gb->alignGetBits();
+ _ctx._gb->align();
- _ctx._gb->skipBits(23); // FIXME: unknown meaning
+ _ctx._gb->skip(23); // FIXME: unknown meaning
- // skip GOP extension if any
- if (_ctx._gb->getBits1()) {
+ // skip GOP extension if any
+ if (_ctx._gb->getBit()) {
do {
i = _ctx._gb->getBits(16);
} while (i & 0x8000);
}
- _ctx._gb->alignGetBits();
+ _ctx._gb->align();
return 0;
}
@@ -620,10 +621,10 @@ int Indeo5Decoder::skip_hdr_extension() {
do {
len = _ctx._gb->getBits(8);
- if (8 * len > _ctx._gb->getBitsLeft())
+ if (_ctx._gb->eos())
return -1;
for (i = 0; i < len; i++)
- _ctx._gb->skipBits(8);
+ _ctx._gb->skip(8);
} while (len);
return 0;