Skip to content

Commit

Permalink
ZVISION: Fix an off-by-one error in the RLF decoder
Browse files Browse the repository at this point in the history
A regression from 7f61a09. The current frame is the currently
displayed frame, not the frame that should be displayed next. Thanks to
clone2727 and Marisa-Chan for the explanation and fixes
  • Loading branch information
bluegr committed Dec 30, 2014
1 parent df60506 commit 88ba96a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions engines/zvision/video/rlf_decoder.cpp
Expand Up @@ -56,7 +56,7 @@ RLFDecoder::RLFVideoTrack::RLFVideoTrack(Common::SeekableReadStream *stream)
_height(0),
_frameTime(0),
_frames(0),
_curFrame(-1),
_displayedFrame(-1),
_frameBufferByteSize(0) {

if (!readHeader()) {
Expand Down Expand Up @@ -161,11 +161,11 @@ bool RLFDecoder::RLFVideoTrack::seek(const Audio::Timestamp &time) {
uint frame = getFrameAtTime(time);
assert(frame < (int)_frameCount);

if ((uint)_curFrame == frame)
if ((uint)_displayedFrame == frame)
return true;

int closestFrame = _curFrame;
int distance = (int)frame - _curFrame;
int closestFrame = _displayedFrame;
int distance = (int)frame - closestFrame;

if (distance < 0) {
for (uint i = 0; i < _completeFrames.size(); ++i) {
Expand All @@ -189,18 +189,18 @@ bool RLFDecoder::RLFVideoTrack::seek(const Audio::Timestamp &time) {
applyFrameToCurrent(i);
}

_curFrame = frame;
_displayedFrame = frame - 1;

return true;
}

const Graphics::Surface *RLFDecoder::RLFVideoTrack::decodeNextFrame() {
if (_curFrame == (int)_frameCount)
if (_displayedFrame >= (int)_frameCount)
return NULL;

applyFrameToCurrent(_curFrame);
_displayedFrame++;
applyFrameToCurrent(_displayedFrame);

_curFrame++;
return &_currentFrameBuffer;
}

Expand Down
4 changes: 2 additions & 2 deletions engines/zvision/video/rlf_decoder.h
Expand Up @@ -46,7 +46,7 @@ class RLFDecoder : public Video::VideoDecoder {
uint16 getWidth() const { return _width; }
uint16 getHeight() const { return _height; }
Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); /* RGB 555 */ }
int getCurFrame() const { return _curFrame; }
int getCurFrame() const { return _displayedFrame; }
int getFrameCount() const { return _frameCount; }
const Graphics::Surface *decodeNextFrame();
bool isSeekable() const { return true; }
Expand Down Expand Up @@ -121,7 +121,7 @@ class RLFDecoder : public Video::VideoDecoder {
Frame *_frames;
Common::Array<uint> _completeFrames;

int _curFrame;
int _displayedFrame;
Graphics::Surface _currentFrameBuffer;
uint32 _frameBufferByteSize;

Expand Down

0 comments on commit 88ba96a

Please sign in to comment.