VIDEO: PACo decoder framerate and palette

Move the VideoTrack to FixedRateVideoTrack. It handles frame duration
internally and removes the need to use nextFrameStartTime accounting.

Add getPalette function.
This commit is contained in:
Roland van Laar 2022-02-28 19:10:09 +01:00
parent 1d20d016ad
commit 6a3b192ead
2 changed files with 17 additions and 10 deletions

View File

@ -91,21 +91,27 @@ void PacoDecoder::copyDirtyRectsToBuffer(uint8 *dst, uint pitch) {
((PacoVideoTrack *)track)->copyDirtyRectsToBuffer(dst, pitch);
}
const byte* PacoDecoder::getPalette(){
Track *track = getTrack(0);
if (track)
return ((PacoVideoTrack *)track)->getPalette();
return nullptr;
}
PacoDecoder::PacoVideoTrack::PacoVideoTrack(
Common::SeekableReadStream *stream, uint16 frameRate, uint16 frameCount, bool hasAudio, uint16 width, uint16 height) {
_fileStream = stream;
_frameDelay = 1000 / frameRate; // frameRate is in fps, ms per frame
_frameRate = frameRate;
_frameCount = frameCount;
_surface = new Graphics::Surface();
_surface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
_palette = new byte[3 * 256]();
memcpy(_palette, quickTimeDefaultPalette256, 256 * 3);
_palette = const_cast<byte *>(quickTimeDefaultPalette256);
_dirtyPalette = false;
_curFrame = 0;
_nextFrameStartTime = 0;
for (uint i = 0; i < _frameCount; i++) {
_frameSizes[i] = stream->readUint32BE();
@ -114,8 +120,6 @@ PacoDecoder::PacoVideoTrack::PacoVideoTrack(
PacoDecoder::PacoVideoTrack::~PacoVideoTrack() {
delete _fileStream;
delete[] _palette;
_surface->free();
delete _surface;
}
@ -184,7 +188,6 @@ const Graphics::Surface *PacoDecoder::PacoVideoTrack::decodeNextFrame() {
}
_curFrame++;
_nextFrameStartTime += _frameDelay;
return _surface;
}

View File

@ -53,9 +53,11 @@ public:
const Common::List<Common::Rect> *getDirtyRects() const;
void clearDirtyRects();
void copyDirtyRectsToBuffer(uint8 *dst, uint pitch);
const byte *getPalette();
protected:
class PacoVideoTrack : public VideoTrack {
class PacoVideoTrack : public FixedRateVideoTrack {
public:
PacoVideoTrack(
Common::SeekableReadStream *stream, uint16 frameRate, uint16 frameCount,
@ -70,7 +72,6 @@ protected:
Graphics::PixelFormat getPixelFormat() const;
int getCurFrame() const { return _curFrame; }
int getFrameCount() const { return _frameCount; }
uint32 getNextFrameStartTime() const { return _nextFrameStartTime; }
virtual const Graphics::Surface *decodeNextFrame();
virtual void handleFrame(uint32 chunkSize);
const byte *getPalette() const { return _palette; }
@ -79,6 +80,8 @@ protected:
const Common::List<Common::Rect> *getDirtyRects() const { return &_dirtyRects; }
void clearDirtyRects() { _dirtyRects.clear(); }
void copyDirtyRectsToBuffer(uint8 *dst, uint pitch);
Common::Rational getFrameRate() const { return Common::Rational(_frameRate, 1); }
protected:
Common::SeekableReadStream *_fileStream;
@ -87,12 +90,13 @@ protected:
int _curFrame;
byte *_palette;
int _frameSizes[65536]; // can be done differently?
mutable bool _dirtyPalette;
uint32 _frameCount;
uint32 _frameDelay;
uint32 _nextFrameStartTime;
uint16 _frameRate;
Common::List<Common::Rect> _dirtyRects;
};