mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-03 15:21:40 +00:00
VIDEO: Use new BitStreamMemory class for SmackerDecoder
This commit is contained in:
parent
edfdbb9dd7
commit
e72f681ceb
@ -29,7 +29,6 @@
|
|||||||
#include "common/endian.h"
|
#include "common/endian.h"
|
||||||
#include "common/util.h"
|
#include "common/util.h"
|
||||||
#include "common/stream.h"
|
#include "common/stream.h"
|
||||||
#include "common/memstream.h"
|
|
||||||
#include "common/bitstream.h"
|
#include "common/bitstream.h"
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
#include "common/textconsole.h"
|
#include "common/textconsole.h"
|
||||||
@ -54,9 +53,9 @@ enum SmkBlockTypes {
|
|||||||
|
|
||||||
class SmallHuffmanTree {
|
class SmallHuffmanTree {
|
||||||
public:
|
public:
|
||||||
SmallHuffmanTree(Common::BitStream8LSB &bs);
|
SmallHuffmanTree(Common::BitStreamMemory8LSB &bs);
|
||||||
|
|
||||||
uint16 getCode(Common::BitStream8LSB &bs);
|
uint16 getCode(Common::BitStreamMemory8LSB &bs);
|
||||||
private:
|
private:
|
||||||
enum {
|
enum {
|
||||||
SMK_NODE = 0x8000
|
SMK_NODE = 0x8000
|
||||||
@ -70,10 +69,10 @@ private:
|
|||||||
uint16 _prefixtree[256];
|
uint16 _prefixtree[256];
|
||||||
byte _prefixlength[256];
|
byte _prefixlength[256];
|
||||||
|
|
||||||
Common::BitStream8LSB &_bs;
|
Common::BitStreamMemory8LSB &_bs;
|
||||||
};
|
};
|
||||||
|
|
||||||
SmallHuffmanTree::SmallHuffmanTree(Common::BitStream8LSB &bs)
|
SmallHuffmanTree::SmallHuffmanTree(Common::BitStreamMemory8LSB &bs)
|
||||||
: _treeSize(0), _bs(bs) {
|
: _treeSize(0), _bs(bs) {
|
||||||
uint32 bit = _bs.getBit();
|
uint32 bit = _bs.getBit();
|
||||||
assert(bit);
|
assert(bit);
|
||||||
@ -118,7 +117,7 @@ uint16 SmallHuffmanTree::decodeTree(uint32 prefix, int length) {
|
|||||||
return r1+r2+1;
|
return r1+r2+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16 SmallHuffmanTree::getCode(Common::BitStream8LSB &bs) {
|
uint16 SmallHuffmanTree::getCode(Common::BitStreamMemory8LSB &bs) {
|
||||||
byte peek = bs.peekBits(MIN<uint32>(bs.size() - bs.pos(), 8));
|
byte peek = bs.peekBits(MIN<uint32>(bs.size() - bs.pos(), 8));
|
||||||
uint16 *p = &_tree[_prefixtree[peek]];
|
uint16 *p = &_tree[_prefixtree[peek]];
|
||||||
bs.skip(_prefixlength[peek]);
|
bs.skip(_prefixlength[peek]);
|
||||||
@ -139,11 +138,11 @@ uint16 SmallHuffmanTree::getCode(Common::BitStream8LSB &bs) {
|
|||||||
|
|
||||||
class BigHuffmanTree {
|
class BigHuffmanTree {
|
||||||
public:
|
public:
|
||||||
BigHuffmanTree(Common::BitStream8LSB &bs, int allocSize);
|
BigHuffmanTree(Common::BitStreamMemory8LSB &bs, int allocSize);
|
||||||
~BigHuffmanTree();
|
~BigHuffmanTree();
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
uint32 getCode(Common::BitStream8LSB &bs);
|
uint32 getCode(Common::BitStreamMemory8LSB &bs);
|
||||||
private:
|
private:
|
||||||
enum {
|
enum {
|
||||||
SMK_NODE = 0x80000000
|
SMK_NODE = 0x80000000
|
||||||
@ -159,13 +158,13 @@ private:
|
|||||||
byte _prefixlength[256];
|
byte _prefixlength[256];
|
||||||
|
|
||||||
/* Used during construction */
|
/* Used during construction */
|
||||||
Common::BitStream8LSB &_bs;
|
Common::BitStreamMemory8LSB &_bs;
|
||||||
uint32 _markers[3];
|
uint32 _markers[3];
|
||||||
SmallHuffmanTree *_loBytes;
|
SmallHuffmanTree *_loBytes;
|
||||||
SmallHuffmanTree *_hiBytes;
|
SmallHuffmanTree *_hiBytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
BigHuffmanTree::BigHuffmanTree(Common::BitStream8LSB &bs, int allocSize)
|
BigHuffmanTree::BigHuffmanTree(Common::BitStreamMemory8LSB &bs, int allocSize)
|
||||||
: _bs(bs) {
|
: _bs(bs) {
|
||||||
uint32 bit = _bs.getBit();
|
uint32 bit = _bs.getBit();
|
||||||
if (!bit) {
|
if (!bit) {
|
||||||
@ -256,7 +255,7 @@ uint32 BigHuffmanTree::decodeTree(uint32 prefix, int length) {
|
|||||||
return r1+r2+1;
|
return r1+r2+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 BigHuffmanTree::getCode(Common::BitStream8LSB &bs) {
|
uint32 BigHuffmanTree::getCode(Common::BitStreamMemory8LSB &bs) {
|
||||||
byte peek = bs.peekBits(MIN<uint32>(bs.size() - bs.pos(), 8));
|
byte peek = bs.peekBits(MIN<uint32>(bs.size() - bs.pos(), 8));
|
||||||
uint32 *p = &_tree[_prefixtree[peek]];
|
uint32 *p = &_tree[_prefixtree[peek]];
|
||||||
bs.skip(_prefixlength[peek]);
|
bs.skip(_prefixlength[peek]);
|
||||||
@ -386,7 +385,7 @@ bool SmackerDecoder::loadStream(Common::SeekableReadStream *stream) {
|
|||||||
byte *huffmanTrees = (byte *) malloc(_header.treesSize);
|
byte *huffmanTrees = (byte *) malloc(_header.treesSize);
|
||||||
_fileStream->read(huffmanTrees, _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);
|
videoTrack->readTrees(bs, _header.mMapSize, _header.mClrSize, _header.fullSize, _header.typeSize);
|
||||||
|
|
||||||
_firstFrameStart = _fileStream->pos();
|
_firstFrameStart = _fileStream->pos();
|
||||||
@ -469,7 +468,7 @@ void SmackerDecoder::readNextPacket() {
|
|||||||
|
|
||||||
_fileStream->read(frameData, frameDataSize);
|
_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);
|
videoTrack->decodeFrame(bs);
|
||||||
|
|
||||||
_fileStream->seek(startPos + frameSize);
|
_fileStream->seek(startPos + frameSize);
|
||||||
@ -553,14 +552,14 @@ Graphics::PixelFormat SmackerDecoder::SmackerVideoTrack::getPixelFormat() const
|
|||||||
return _surface->format;
|
return _surface->format;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmackerDecoder::SmackerVideoTrack::readTrees(Common::BitStream8LSB &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);
|
_MMapTree = new BigHuffmanTree(bs, mMapSize);
|
||||||
_MClrTree = new BigHuffmanTree(bs, mClrSize);
|
_MClrTree = new BigHuffmanTree(bs, mClrSize);
|
||||||
_FullTree = new BigHuffmanTree(bs, fullSize);
|
_FullTree = new BigHuffmanTree(bs, fullSize);
|
||||||
_TypeTree = new BigHuffmanTree(bs, typeSize);
|
_TypeTree = new BigHuffmanTree(bs, typeSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmackerDecoder::SmackerVideoTrack::decodeFrame(Common::BitStream8LSB &bs) {
|
void SmackerDecoder::SmackerVideoTrack::decodeFrame(Common::BitStreamMemory8LSB &bs) {
|
||||||
_MMapTree->reset();
|
_MMapTree->reset();
|
||||||
_MClrTree->reset();
|
_MClrTree->reset();
|
||||||
_FullTree->reset();
|
_FullTree->reset();
|
||||||
@ -774,7 +773,7 @@ Audio::AudioStream *SmackerDecoder::SmackerAudioTrack::getAudioStream() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SmackerDecoder::SmackerAudioTrack::queueCompressedBuffer(byte *buffer, uint32 bufferSize, uint32 unpackedSize) {
|
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();
|
bool dataPresent = audioBS.getBit();
|
||||||
|
|
||||||
if (!dataPresent)
|
if (!dataPresent)
|
||||||
|
@ -91,9 +91,9 @@ protected:
|
|||||||
const byte *getPalette() const { _dirtyPalette = false; return _palette; }
|
const byte *getPalette() const { _dirtyPalette = false; return _palette; }
|
||||||
bool hasDirtyPalette() const { return _dirtyPalette; }
|
bool hasDirtyPalette() const { return _dirtyPalette; }
|
||||||
|
|
||||||
void readTrees(Common::BitStream8LSB &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 increaseCurFrame() { _curFrame++; }
|
||||||
void decodeFrame(Common::BitStream8LSB &bs);
|
void decodeFrame(Common::BitStreamMemory8LSB &bs);
|
||||||
void unpackPalette(Common::SeekableReadStream *stream);
|
void unpackPalette(Common::SeekableReadStream *stream);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user