aboutsummaryrefslogtreecommitdiff
path: root/video
diff options
context:
space:
mode:
Diffstat (limited to 'video')
-rw-r--r--video/dxa_decoder.cpp130
-rw-r--r--video/dxa_decoder.h102
2 files changed, 116 insertions, 116 deletions
diff --git a/video/dxa_decoder.cpp b/video/dxa_decoder.cpp
index 7d1112a59c..5ac9bd2088 100644
--- a/video/dxa_decoder.cpp
+++ b/video/dxa_decoder.cpp
@@ -37,41 +37,43 @@
namespace Video {
DXADecoder::DXADecoder() {
- _fileStream = 0;
- _surface = 0;
- _dirtyPalette = false;
+}
- _frameBuffer1 = 0;
- _frameBuffer2 = 0;
- _scaledBuffer = 0;
+DXADecoder::~DXADecoder() {
+ close();
+}
- _inBuffer = 0;
- _inBufferSize = 0;
+bool DXADecoder::loadStream(Common::SeekableReadStream *stream) {
+ close();
- _decompBuffer = 0;
- _decompBufferSize = 0;
+ uint32 tag = stream->readUint32BE();
- _width = 0;
- _height = 0;
+ if (tag != MKTAG('D','E','X','A')) {
+ close();
+ return false;
+ }
- _frameSize = 0;
- _frameCount = 0;
- _frameRate = 0;
+ DXAVideoTrack *track = new DXAVideoTrack(stream);
+ addTrack(track);
- _scaleMode = S_NONE;
-}
+ readSoundData(stream);
-DXADecoder::~DXADecoder() {
- close();
+ track->setFrameStartPos();
+ return true;
}
-bool DXADecoder::loadStream(Common::SeekableReadStream *stream) {
- close();
+void DXADecoder::readSoundData(Common::SeekableReadStream *stream) {
+ // Skip over the tag by default
+ stream->readUint32BE();
+}
+DXADecoder::DXAVideoTrack::DXAVideoTrack(Common::SeekableReadStream *stream) {
_fileStream = stream;
-
- uint32 tag = _fileStream->readUint32BE();
- assert(tag == MKTAG('D','E','X','A'));
+ _curFrame = -1;
+ _frameStartOffset = 0;
+ _decompBuffer = 0;
+ _inBuffer = 0;
+ memset(_palette, 0, 256 * 3);
uint8 flags = _fileStream->readByte();
_frameCount = _fileStream->readUint16BE();
@@ -105,18 +107,14 @@ bool DXADecoder::loadStream(Common::SeekableReadStream *stream) {
_frameSize = _width * _height;
_decompBufferSize = _frameSize;
- _frameBuffer1 = (uint8 *)malloc(_frameSize);
+ _frameBuffer1 = new byte[_frameSize];
memset(_frameBuffer1, 0, _frameSize);
- _frameBuffer2 = (uint8 *)malloc(_frameSize);
+ _frameBuffer2 = new byte[_frameSize];
memset(_frameBuffer2, 0, _frameSize);
- if (!_frameBuffer1 || !_frameBuffer2)
- error("DXADecoder: Error allocating frame buffers (size %u)", _frameSize);
_scaledBuffer = 0;
if (_scaleMode != S_NONE) {
- _scaledBuffer = (uint8 *)malloc(_frameSize);
- if (!_scaledBuffer)
- error("Error allocating scale buffer (size %u)", _frameSize);
+ _scaledBuffer = new byte[_frameSize];
memset(_scaledBuffer, 0, _frameSize);
}
@@ -148,36 +146,33 @@ bool DXADecoder::loadStream(Common::SeekableReadStream *stream) {
} while (tag != 0);
}
#endif
-
- // Read the sound header
- _soundTag = _fileStream->readUint32BE();
-
- return true;
}
-void DXADecoder::close() {
- if (!_fileStream)
- return;
-
+DXADecoder::DXAVideoTrack::~DXAVideoTrack() {
delete _fileStream;
- _fileStream = 0;
-
delete _surface;
- _surface = 0;
+ delete[] _frameBuffer1;
+ delete[] _frameBuffer2;
+ delete[] _scaledBuffer;
+ delete[] _inBuffer;
+ delete[] _decompBuffer;
+}
- free(_frameBuffer1);
- free(_frameBuffer2);
- free(_scaledBuffer);
- free(_inBuffer);
- free(_decompBuffer);
+bool DXADecoder::DXAVideoTrack::rewind() {
+ _curFrame = -1;
+ _fileStream->seek(_frameStartOffset);
+ return true;
+}
- _inBuffer = 0;
- _decompBuffer = 0;
+Graphics::PixelFormat DXADecoder::DXAVideoTrack::getPixelFormat() const {
+ return _surface->format;
+}
- reset();
+void DXADecoder::DXAVideoTrack::setFrameStartPos() {
+ _frameStartOffset = _fileStream->pos();
}
-void DXADecoder::decodeZlib(byte *data, int size, int totalSize) {
+void DXADecoder::DXAVideoTrack::decodeZlib(byte *data, int size, int totalSize) {
#ifdef USE_ZLIB
unsigned long dstLen = totalSize;
Common::uncompress(data, &dstLen, _inBuffer, size);
@@ -187,14 +182,13 @@ void DXADecoder::decodeZlib(byte *data, int size, int totalSize) {
#define BLOCKW 4
#define BLOCKH 4
-void DXADecoder::decode12(int size) {
+void DXADecoder::DXAVideoTrack::decode12(int size) {
#ifdef USE_ZLIB
- if (_decompBuffer == NULL) {
- _decompBuffer = (byte *)malloc(_decompBufferSize);
+ if (!_decompBuffer) {
+ _decompBuffer = new byte[_decompBufferSize];
memset(_decompBuffer, 0, _decompBufferSize);
- if (_decompBuffer == NULL)
- error("Error allocating decomp buffer (size %u)", _decompBufferSize);
}
+
/* decompress the input data */
decodeZlib(_decompBuffer, size, _decompBufferSize);
@@ -287,15 +281,13 @@ void DXADecoder::decode12(int size) {
#endif
}
-void DXADecoder::decode13(int size) {
+void DXADecoder::DXAVideoTrack::decode13(int size) {
#ifdef USE_ZLIB
uint8 *codeBuf, *dataBuf, *motBuf, *maskBuf;
- if (_decompBuffer == NULL) {
- _decompBuffer = (byte *)malloc(_decompBufferSize);
+ if (!_decompBuffer) {
+ _decompBuffer = new byte[_decompBufferSize];
memset(_decompBuffer, 0, _decompBufferSize);
- if (_decompBuffer == NULL)
- error("Error allocating decomp buffer (size %u)", _decompBufferSize);
}
/* decompress the input data */
@@ -475,7 +467,7 @@ void DXADecoder::decode13(int size) {
#endif
}
-const Graphics::Surface *DXADecoder::decodeNextFrame() {
+const Graphics::Surface *DXADecoder::DXAVideoTrack::decodeNextFrame() {
uint32 tag = _fileStream->readUint32BE();
if (tag == MKTAG('C','M','A','P')) {
_fileStream->read(_palette, 256 * 3);
@@ -486,11 +478,10 @@ const Graphics::Surface *DXADecoder::decodeNextFrame() {
if (tag == MKTAG('F','R','A','M')) {
byte type = _fileStream->readByte();
uint32 size = _fileStream->readUint32BE();
- if ((_inBuffer == NULL) || (_inBufferSize < size)) {
- free(_inBuffer);
- _inBuffer = (byte *)malloc(size);
- if (_inBuffer == NULL)
- error("Error allocating input buffer (size %u)", size);
+
+ if (!_inBuffer || _inBufferSize < size) {
+ delete[] _inBuffer;
+ _inBuffer = new byte[size];
memset(_inBuffer, 0, size);
_inBufferSize = size;
}
@@ -551,9 +542,6 @@ const Graphics::Surface *DXADecoder::decodeNextFrame() {
_curFrame++;
- if (_curFrame == 0)
- _startTime = g_system->getMillis();
-
return _surface;
}
diff --git a/video/dxa_decoder.h b/video/dxa_decoder.h
index d13cd3076c..a0caca4b95 100644
--- a/video/dxa_decoder.h
+++ b/video/dxa_decoder.h
@@ -41,62 +41,74 @@ namespace Video {
* - sword1
* - sword2
*/
-class DXADecoder : public FixedRateVideoDecoder {
+class DXADecoder : public AdvancedVideoDecoder {
public:
DXADecoder();
virtual ~DXADecoder();
bool loadStream(Common::SeekableReadStream *stream);
- void close();
-
- bool isVideoLoaded() const { return _fileStream != 0; }
- uint16 getWidth() const { return _width; }
- uint16 getHeight() const { return _height; }
- uint32 getFrameCount() const { return _frameCount; }
- const Graphics::Surface *decodeNextFrame();
- Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat::createFormatCLUT8(); }
- const byte *getPalette() { _dirtyPalette = false; return _palette; }
- bool hasDirtyPalette() const { return _dirtyPalette; }
+protected:
/**
- * Get the sound chunk tag of the loaded DXA file
+ * Read the sound data out of the given DXA stream
*/
- uint32 getSoundTag() { return _soundTag; }
-
-protected:
- Common::Rational getFrameRate() const { return _frameRate; }
-
- Common::SeekableReadStream *_fileStream;
+ virtual void readSoundData(Common::SeekableReadStream *stream);
private:
- void decodeZlib(byte *data, int size, int totalSize);
- void decode12(int size);
- void decode13(int size);
-
- enum ScaleMode {
- S_NONE,
- S_INTERLACED,
- S_DOUBLE
+ class DXAVideoTrack : public FixedRateVideoTrack {
+ public:
+ DXAVideoTrack(Common::SeekableReadStream *stream);
+ ~DXAVideoTrack();
+
+ bool isRewindable() const { return true; }
+ bool rewind();
+
+ uint16 getWidth() const { return _width; }
+ uint16 getHeight() const { return _height; }
+ Graphics::PixelFormat getPixelFormat() const;
+ int getCurFrame() const { return _curFrame; }
+ int getFrameCount() const { return _frameCount; }
+ const Graphics::Surface *decodeNextFrame();
+ const byte *getPalette() const { _dirtyPalette = false; return _palette; }
+ bool hasDirtyPalette() const { return _dirtyPalette; }
+
+ void setFrameStartPos();
+
+ protected:
+ Common::Rational getFrameRate() const { return _frameRate; }
+
+ private:
+ void decodeZlib(byte *data, int size, int totalSize);
+ void decode12(int size);
+ void decode13(int size);
+
+ enum ScaleMode {
+ S_NONE,
+ S_INTERLACED,
+ S_DOUBLE
+ };
+
+ Common::SeekableReadStream *_fileStream;
+ Graphics::Surface *_surface;
+
+ byte *_frameBuffer1;
+ byte *_frameBuffer2;
+ byte *_scaledBuffer;
+ byte *_inBuffer;
+ uint32 _inBufferSize;
+ byte *_decompBuffer;
+ uint32 _decompBufferSize;
+ uint16 _curHeight;
+ uint32 _frameSize;
+ ScaleMode _scaleMode;
+ uint16 _width, _height;
+ uint32 _frameRate;
+ uint32 _frameCount;
+ byte _palette[256 * 3];
+ mutable bool _dirtyPalette;
+ int _curFrame;
+ uint32 _frameStartOffset;
};
-
- Graphics::Surface *_surface;
- byte _palette[256 * 3];
- bool _dirtyPalette;
-
- byte *_frameBuffer1;
- byte *_frameBuffer2;
- byte *_scaledBuffer;
- byte *_inBuffer;
- uint32 _inBufferSize;
- byte *_decompBuffer;
- uint32 _decompBufferSize;
- uint16 _curHeight;
- uint32 _frameSize;
- ScaleMode _scaleMode;
- uint32 _soundTag;
- uint16 _width, _height;
- uint32 _frameRate;
- uint32 _frameCount;
};
} // End of namespace Video