From 375f32fbe94e8500a03c19ed32865efdcde8ca8e Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 16 Dec 2010 01:35:13 +0000 Subject: VIDEO: Make VideoDecoder::decodeNextFrame() return a const Surface pointer svn-id: r54927 --- engines/agos/animation.cpp | 4 ++-- engines/gob/videoplayer.cpp | 2 +- engines/mohawk/video.cpp | 24 ++++++++++++------------ engines/saga/introproc_saga2.cpp | 2 +- engines/sci/engine/kvideo.cpp | 2 +- engines/sci/video/seq_decoder.cpp | 2 +- engines/sci/video/seq_decoder.h | 2 +- engines/scumm/he/animation_he.cpp | 2 +- engines/sword1/animation.cpp | 2 +- engines/sword2/animation.cpp | 2 +- engines/sword25/fmv/movieplayer.cpp | 2 +- engines/sword25/fmv/theora_decoder.cpp | 2 +- engines/sword25/fmv/theora_decoder.h | 2 +- engines/toon/movie.cpp | 2 +- engines/tucker/sequences.cpp | 4 ++-- graphics/video/avi_decoder.cpp | 6 +++--- graphics/video/avi_decoder.h | 2 +- graphics/video/coktel_decoder.cpp | 6 +++--- graphics/video/coktel_decoder.h | 6 +++--- graphics/video/dxa_decoder.cpp | 2 +- graphics/video/dxa_decoder.h | 2 +- graphics/video/flic_decoder.cpp | 2 +- graphics/video/flic_decoder.h | 2 +- graphics/video/qt_decoder.cpp | 2 +- graphics/video/qt_decoder.h | 2 +- graphics/video/smk_decoder.cpp | 2 +- graphics/video/smk_decoder.h | 2 +- graphics/video/video_decoder.h | 2 +- 28 files changed, 47 insertions(+), 47 deletions(-) diff --git a/engines/agos/animation.cpp b/engines/agos/animation.cpp index 4fe8f8e6bc..5406e9c7ef 100644 --- a/engines/agos/animation.cpp +++ b/engines/agos/animation.cpp @@ -267,7 +267,7 @@ void MoviePlayerDXA::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) { uint h = getHeight(); uint w = getWidth(); - Graphics::Surface *surface = decodeNextFrame(); + const Graphics::Surface *surface = decodeNextFrame(); byte *src = (byte *)surface->pixels; dst += y * pitch + x; @@ -428,7 +428,7 @@ void MoviePlayerSMK::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) { uint h = getHeight(); uint w = getWidth(); - Graphics::Surface *surface = decodeNextFrame(); + const Graphics::Surface *surface = decodeNextFrame(); byte *src = (byte *)surface->pixels; dst += y * pitch + x; diff --git a/engines/gob/videoplayer.cpp b/engines/gob/videoplayer.cpp index 3d29c2ce26..7448c85ef1 100644 --- a/engines/gob/videoplayer.cpp +++ b/engines/gob/videoplayer.cpp @@ -325,7 +325,7 @@ bool VideoPlayer::playFrame(int slot, Properties &properties) { _vm->_draw->forceBlit(); } - Graphics::Surface *surface = video->decoder->decodeNextFrame(); + const Graphics::Surface *surface = video->decoder->decodeNextFrame(); WRITE_VAR(11, video->decoder->getCurFrame()); diff --git a/engines/mohawk/video.cpp b/engines/mohawk/video.cpp index 863a14335f..e54aa67df3 100644 --- a/engines/mohawk/video.cpp +++ b/engines/mohawk/video.cpp @@ -178,18 +178,19 @@ bool VideoManager::updateBackgroundMovies() { // Check if we need to draw a frame if (_videoStreams[i]->needsUpdate()) { - Graphics::Surface *frame = _videoStreams[i]->decodeNextFrame(); - bool deleteFrame = false; + const Graphics::Surface *frame = _videoStreams[i]->decodeNextFrame(); + Graphics::Surface *convertedFrame = 0; if (frame && _videoStreams[i].enabled) { // Convert from 8bpp to the current screen format if necessary Graphics::PixelFormat pixelFormat = _vm->_system->getScreenFormat(); + if (frame->bytesPerPixel == 1 && pixelFormat.bytesPerPixel != 1) { - Graphics::Surface *newFrame = new Graphics::Surface(); + convertedFrame = new Graphics::Surface(); byte *palette = _videoStreams[i]->getPalette(); assert(palette); - newFrame->create(frame->w, frame->h, pixelFormat.bytesPerPixel); + convertedFrame->create(frame->w, frame->h, pixelFormat.bytesPerPixel); for (uint16 j = 0; j < frame->h; j++) { for (uint16 k = 0; k < frame->w; k++) { @@ -198,14 +199,13 @@ bool VideoManager::updateBackgroundMovies() { byte g = palette[palIndex * 3 + 1]; byte b = palette[palIndex * 3 + 2]; if (pixelFormat.bytesPerPixel == 2) - *((uint16 *)newFrame->getBasePtr(k, j)) = pixelFormat.RGBToColor(r, g, b); + *((uint16 *)convertedFrame->getBasePtr(k, j)) = pixelFormat.RGBToColor(r, g, b); else - *((uint32 *)newFrame->getBasePtr(k, j)) = pixelFormat.RGBToColor(r, g, b); + *((uint32 *)convertedFrame->getBasePtr(k, j)) = pixelFormat.RGBToColor(r, g, b); } } - frame = newFrame; - deleteFrame = true; + frame = convertedFrame; } // Clip the width/height to make sure we stay on the screen (Myst does this a few times) @@ -216,10 +216,10 @@ bool VideoManager::updateBackgroundMovies() { // We've drawn something to the screen, make sure we update it updateScreen = true; - // Delete the frame if we're using the buffer from the 8bpp conversion - if (deleteFrame) { - frame->free(); - delete frame; + // Delete 8bpp conversion surface + if (convertedFrame) { + convertedFrame->free(); + delete convertedFrame; } } } diff --git a/engines/saga/introproc_saga2.cpp b/engines/saga/introproc_saga2.cpp index 785534729e..ec157b4a13 100644 --- a/engines/saga/introproc_saga2.cpp +++ b/engines/saga/introproc_saga2.cpp @@ -103,7 +103,7 @@ void Scene::playMovie(const char *filename) { while (!_vm->shouldQuit() && !smkDecoder->endOfVideo() && !skipVideo) { if (smkDecoder->needsUpdate()) { - Graphics::Surface *frame = smkDecoder->decodeNextFrame(); + const Graphics::Surface *frame = smkDecoder->decodeNextFrame(); if (frame) { _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); diff --git a/engines/sci/engine/kvideo.cpp b/engines/sci/engine/kvideo.cpp index 9245572bbf..b4c3c3bddf 100644 --- a/engines/sci/engine/kvideo.cpp +++ b/engines/sci/engine/kvideo.cpp @@ -67,7 +67,7 @@ void playVideo(Graphics::VideoDecoder *videoDecoder) { while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) { if (videoDecoder->needsUpdate()) { - Graphics::Surface *frame = videoDecoder->decodeNextFrame(); + const Graphics::Surface *frame = videoDecoder->decodeNextFrame(); if (frame) { if (scaleBuffer) { // TODO: Probably should do aspect ratio correction in e.g. GK1 Windows diff --git a/engines/sci/video/seq_decoder.cpp b/engines/sci/video/seq_decoder.cpp index a08f837866..3f4bd458b8 100644 --- a/engines/sci/video/seq_decoder.cpp +++ b/engines/sci/video/seq_decoder.cpp @@ -108,7 +108,7 @@ void SeqDecoder::close() { reset(); } -Graphics::Surface *SeqDecoder::decodeNextFrame() { +const Graphics::Surface *SeqDecoder::decodeNextFrame() { int16 frameWidth = _fileStream->readUint16LE(); int16 frameHeight = _fileStream->readUint16LE(); int16 frameLeft = _fileStream->readUint16LE(); diff --git a/engines/sci/video/seq_decoder.h b/engines/sci/video/seq_decoder.h index 1714477083..4d94d145ce 100644 --- a/engines/sci/video/seq_decoder.h +++ b/engines/sci/video/seq_decoder.h @@ -47,7 +47,7 @@ public: uint16 getWidth() const { return SEQ_SCREEN_WIDTH; } uint16 getHeight() const { return SEQ_SCREEN_HEIGHT; } uint32 getFrameCount() const { return _frameCount; } - Graphics::Surface *decodeNextFrame(); + const Graphics::Surface *decodeNextFrame(); Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat::createFormatCLUT8(); } byte *getPalette() { _dirtyPalette = false; return _palette; } bool hasDirtyPalette() const { return _dirtyPalette; } diff --git a/engines/scumm/he/animation_he.cpp b/engines/scumm/he/animation_he.cpp index 9f1bf22c38..80cfcfcd0b 100644 --- a/engines/scumm/he/animation_he.cpp +++ b/engines/scumm/he/animation_he.cpp @@ -68,7 +68,7 @@ void MoviePlayer::copyFrameToBuffer(byte *dst, int dstType, uint x, uint y, uint uint h = getHeight(); uint w = getWidth(); - Graphics::Surface *surface = decodeNextFrame(); + const Graphics::Surface *surface = decodeNextFrame(); byte *src = (byte *)surface->pixels; if (hasDirtyPalette()) diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp index 441e622184..8df1812098 100644 --- a/engines/sword1/animation.cpp +++ b/engines/sword1/animation.cpp @@ -252,7 +252,7 @@ bool MoviePlayer::playVideo() { while (!_vm->shouldQuit() && !_decoder->endOfVideo()) { if (_decoder->needsUpdate()) { - Graphics::Surface *frame = _decoder->decodeNextFrame(); + const Graphics::Surface *frame = _decoder->decodeNextFrame(); if (frame) _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); diff --git a/engines/sword2/animation.cpp b/engines/sword2/animation.cpp index f664e784d5..617c254ec4 100644 --- a/engines/sword2/animation.cpp +++ b/engines/sword2/animation.cpp @@ -279,7 +279,7 @@ bool MoviePlayer::playVideo() { while (!_vm->shouldQuit() && !_decoder->endOfVideo()) { if (_decoder->needsUpdate()) { - Graphics::Surface *frame = _decoder->decodeNextFrame(); + const Graphics::Surface *frame = _decoder->decodeNextFrame(); if (frame) _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 4193e02b2e..356c2d11ff 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -124,7 +124,7 @@ bool MoviePlayer::pause() { void MoviePlayer::update() { if (_decoder.isVideoLoaded()) { - Graphics::Surface *s = _decoder.decodeNextFrame(); + const Graphics::Surface *s = _decoder.decodeNextFrame(); if (s) { // Transfer the next frame assert(s->bytesPerPixel == 4); diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index d6c2544fe5..8a0397cdfc 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -329,7 +329,7 @@ void TheoraDecoder::close() { reset(); } -Graphics::Surface *TheoraDecoder::decodeNextFrame() { +const Graphics::Surface *TheoraDecoder::decodeNextFrame() { int i, j; // _stateFlag = false; // playback has not begun diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h index f6c622563b..69bf41b741 100644 --- a/engines/sword25/fmv/theora_decoder.h +++ b/engines/sword25/fmv/theora_decoder.h @@ -67,7 +67,7 @@ public: * @note the return surface should *not* be freed * @note this may return 0, in which case the last frame should be kept on screen */ - Graphics::Surface *decodeNextFrame(); + const Graphics::Surface *decodeNextFrame(); bool isVideoLoaded() const { return _fileStream != 0; diff --git a/engines/toon/movie.cpp b/engines/toon/movie.cpp index f0c40366be..34769f028a 100644 --- a/engines/toon/movie.cpp +++ b/engines/toon/movie.cpp @@ -97,7 +97,7 @@ bool Movie::playVideo() { int32 y = 0; while (!_vm->shouldQuit() && !_decoder->endOfVideo()) { if (_decoder->needsUpdate()) { - Graphics::Surface *frame = _decoder->decodeNextFrame(); + const Graphics::Surface *frame = _decoder->decodeNextFrame(); if (frame) _vm->getSystem()->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); _decoder->setSystemPalette(); diff --git a/engines/tucker/sequences.cpp b/engines/tucker/sequences.cpp index 633ed2790d..d804d85d9a 100644 --- a/engines/tucker/sequences.cpp +++ b/engines/tucker/sequences.cpp @@ -765,7 +765,7 @@ void AnimationSequencePlayer::openAnimation(int index, const char *fileName) { } bool AnimationSequencePlayer::decodeNextAnimationFrame(int index, bool copyDirtyRects) { - ::Graphics::Surface *surface = _flicPlayer[index].decodeNextFrame(); + const ::Graphics::Surface *surface = _flicPlayer[index].decodeNextFrame(); if (!copyDirtyRects) { for (uint16 y = 0; (y < surface->h) && (y < kScreenHeight); y++) @@ -804,7 +804,7 @@ void AnimationSequencePlayer::playIntroSeq19_20() { // The intro credits animation. This uses 2 animations: the foreground one, which // is the actual intro credits, and the background one, which is an animation of // cogs, and is being replayed when an intro credit appears - ::Graphics::Surface *surface = 0; + const ::Graphics::Surface *surface = 0; if (_flicPlayer[0].getCurFrame() >= 115) { surface = _flicPlayer[1].decodeNextFrame(); diff --git a/graphics/video/avi_decoder.cpp b/graphics/video/avi_decoder.cpp index aa6844a498..c1346bbe12 100644 --- a/graphics/video/avi_decoder.cpp +++ b/graphics/video/avi_decoder.cpp @@ -316,7 +316,7 @@ uint32 AviDecoder::getElapsedTime() const { return VideoDecoder::getElapsedTime(); } -Surface *AviDecoder::decodeNextFrame() { +const Surface *AviDecoder::decodeNextFrame() { uint32 nextTag = _fileStream->readUint32BE(); if (_fileStream->eos()) @@ -334,9 +334,9 @@ Surface *AviDecoder::decodeNextFrame() { error ("Expected 'rec ' LIST"); // Decode chunks in the list and see if we get a frame - Surface *frame = NULL; + const Surface *frame = NULL; while (_fileStream->pos() < startPos + (int32)listSize) { - Surface *temp = decodeNextFrame(); + const Surface *temp = decodeNextFrame(); if (temp) frame = temp; } diff --git a/graphics/video/avi_decoder.h b/graphics/video/avi_decoder.h index 91c6f8edd3..306b32a076 100644 --- a/graphics/video/avi_decoder.h +++ b/graphics/video/avi_decoder.h @@ -176,7 +176,7 @@ public: uint16 getHeight() const { return _header.height; } uint32 getFrameCount() const { return _header.totalFrames; } uint32 getElapsedTime() const; - Surface *decodeNextFrame(); + const Surface *decodeNextFrame(); PixelFormat getPixelFormat() const; byte *getPalette() { _dirtyPalette = false; return _palette; } bool hasDirtyPalette() const { return _dirtyPalette; } diff --git a/graphics/video/coktel_decoder.cpp b/graphics/video/coktel_decoder.cpp index 394e96d7ac..bcde7ff51e 100644 --- a/graphics/video/coktel_decoder.cpp +++ b/graphics/video/coktel_decoder.cpp @@ -669,7 +669,7 @@ bool PreIMDDecoder::isVideoLoaded() const { return _stream != 0; } -Surface *PreIMDDecoder::decodeNextFrame() { +const Surface *PreIMDDecoder::decodeNextFrame() { if (!isVideoLoaded() || endOfVideo()) return 0; @@ -1128,7 +1128,7 @@ bool IMDDecoder::isVideoLoaded() const { return _stream != 0; } -Surface *IMDDecoder::decodeNextFrame() { +const Surface *IMDDecoder::decodeNextFrame() { if (!isVideoLoaded() || endOfVideo()) return 0; @@ -1925,7 +1925,7 @@ bool VMDDecoder::isVideoLoaded() const { return _stream != 0; } -Surface *VMDDecoder::decodeNextFrame() { +const Surface *VMDDecoder::decodeNextFrame() { if (!isVideoLoaded() || endOfVideo()) return 0; diff --git a/graphics/video/coktel_decoder.h b/graphics/video/coktel_decoder.h index 548e313937..7b54c80304 100644 --- a/graphics/video/coktel_decoder.h +++ b/graphics/video/coktel_decoder.h @@ -227,7 +227,7 @@ public: bool isVideoLoaded() const; - Surface *decodeNextFrame(); + const Surface *decodeNextFrame(); PixelFormat getPixelFormat() const; @@ -260,7 +260,7 @@ public: bool isVideoLoaded() const; - Surface *decodeNextFrame(); + const Surface *decodeNextFrame(); PixelFormat getPixelFormat() const; @@ -364,7 +364,7 @@ public: bool isVideoLoaded() const; - Surface *decodeNextFrame(); + const Surface *decodeNextFrame(); PixelFormat getPixelFormat() const; diff --git a/graphics/video/dxa_decoder.cpp b/graphics/video/dxa_decoder.cpp index 1f7ccc3640..3c52c0fc58 100644 --- a/graphics/video/dxa_decoder.cpp +++ b/graphics/video/dxa_decoder.cpp @@ -477,7 +477,7 @@ void DXADecoder::decode13(int size) { #endif } -Surface *DXADecoder::decodeNextFrame() { +const Surface *DXADecoder::decodeNextFrame() { uint32 tag = _fileStream->readUint32BE(); if (tag == MKID_BE('CMAP')) { _fileStream->read(_palette, 256 * 3); diff --git a/graphics/video/dxa_decoder.h b/graphics/video/dxa_decoder.h index eb4426dbbc..e4688e36cd 100644 --- a/graphics/video/dxa_decoder.h +++ b/graphics/video/dxa_decoder.h @@ -50,7 +50,7 @@ public: uint16 getWidth() const { return _width; } uint16 getHeight() const { return _height; } uint32 getFrameCount() const { return _frameCount; } - Surface *decodeNextFrame(); + const Surface *decodeNextFrame(); PixelFormat getPixelFormat() const { return PixelFormat::createFormatCLUT8(); } byte *getPalette() { _dirtyPalette = false; return _palette; } bool hasDirtyPalette() const { return _dirtyPalette; } diff --git a/graphics/video/flic_decoder.cpp b/graphics/video/flic_decoder.cpp index f55a74f4f3..51c487861e 100644 --- a/graphics/video/flic_decoder.cpp +++ b/graphics/video/flic_decoder.cpp @@ -194,7 +194,7 @@ void FlicDecoder::decodeDeltaFLC(uint8 *data) { #define PSTAMP 18 #define FRAME_TYPE 0xF1FA -Surface *FlicDecoder::decodeNextFrame() { +const Surface *FlicDecoder::decodeNextFrame() { // Read chunk uint32 frameSize = _fileStream->readUint32LE(); uint16 frameType = _fileStream->readUint16LE(); diff --git a/graphics/video/flic_decoder.h b/graphics/video/flic_decoder.h index bba1403c22..b716a87b62 100644 --- a/graphics/video/flic_decoder.h +++ b/graphics/video/flic_decoder.h @@ -59,7 +59,7 @@ public: * @note the return surface should *not* be freed * @note this may return 0, in which case the last frame should be kept on screen */ - Surface *decodeNextFrame(); + const Surface *decodeNextFrame(); bool isVideoLoaded() const { return _fileStream != 0; } uint16 getWidth() const { return _surface->w; } diff --git a/graphics/video/qt_decoder.cpp b/graphics/video/qt_decoder.cpp index 4c7b95abf5..e7c1c3cab1 100644 --- a/graphics/video/qt_decoder.cpp +++ b/graphics/video/qt_decoder.cpp @@ -216,7 +216,7 @@ Codec *QuickTimeDecoder::findDefaultVideoCodec() const { return _streams[_videoStreamIndex]->stsdEntries[0].videoCodec; } -Surface *QuickTimeDecoder::decodeNextFrame() { +const Surface *QuickTimeDecoder::decodeNextFrame() { if (_videoStreamIndex < 0 || _curFrame >= (int32)getFrameCount() - 1) return 0; diff --git a/graphics/video/qt_decoder.h b/graphics/video/qt_decoder.h index 6198c2e24b..e409ebb55d 100644 --- a/graphics/video/qt_decoder.h +++ b/graphics/video/qt_decoder.h @@ -107,7 +107,7 @@ public: void setChunkBeginOffset(uint32 offset) { _beginOffset = offset; } bool isVideoLoaded() const { return _fd != 0; } - Surface *decodeNextFrame(); + const Surface *decodeNextFrame(); bool endOfVideo() const; uint32 getElapsedTime() const; uint32 getTimeToNextFrame() const; diff --git a/graphics/video/smk_decoder.cpp b/graphics/video/smk_decoder.cpp index de1eb4436f..e4d577acd2 100644 --- a/graphics/video/smk_decoder.cpp +++ b/graphics/video/smk_decoder.cpp @@ -519,7 +519,7 @@ void SmackerDecoder::close() { reset(); } -Surface *SmackerDecoder::decodeNextFrame() { +const Surface *SmackerDecoder::decodeNextFrame() { uint i; uint32 chunkSize = 0; uint32 dataSizeUnpacked = 0; diff --git a/graphics/video/smk_decoder.h b/graphics/video/smk_decoder.h index 5faeab4343..da64927b49 100644 --- a/graphics/video/smk_decoder.h +++ b/graphics/video/smk_decoder.h @@ -65,7 +65,7 @@ public: uint16 getHeight() const { return _surface->h; } uint32 getFrameCount() const { return _frameCount; } uint32 getElapsedTime() const; - Surface *decodeNextFrame(); + const Surface *decodeNextFrame(); PixelFormat getPixelFormat() const { return PixelFormat::createFormatCLUT8(); } byte *getPalette() { _dirtyPalette = false; return _palette; } bool hasDirtyPalette() const { return _dirtyPalette; } diff --git a/graphics/video/video_decoder.h b/graphics/video/video_decoder.h index 4ad7ae054f..a84253ac2b 100644 --- a/graphics/video/video_decoder.h +++ b/graphics/video/video_decoder.h @@ -109,7 +109,7 @@ public: * @note the return surface should *not* be freed * @note this may return 0, in which case the last frame should be kept on screen */ - virtual Surface *decodeNextFrame() = 0; + virtual const Surface *decodeNextFrame() = 0; /** * Get the pixel format of the video -- cgit v1.2.3