diff options
-rw-r--r-- | engines/gob/videoplayer.cpp | 12 | ||||
-rw-r--r-- | graphics/video/coktel_decoder.cpp | 62 | ||||
-rw-r--r-- | graphics/video/coktel_decoder.h | 16 |
3 files changed, 77 insertions, 13 deletions
diff --git a/engines/gob/videoplayer.cpp b/engines/gob/videoplayer.cpp index d15c3cc20c..715d5cfb9a 100644 --- a/engines/gob/videoplayer.cpp +++ b/engines/gob/videoplayer.cpp @@ -136,19 +136,17 @@ int VideoPlayer::openVideo(bool primary, const Common::String &file, Properties if (!_vm->_draw->_spritesArray[properties.sprite]) { properties.sprite = -1; video->surface.reset(); - // video->decoder->setVideoMemory(); + video->decoder->setSurfaceMemory(); } else { video->surface = _vm->_draw->_spritesArray[properties.sprite]; - /* - video->decoder->setVideoMemory(video->surface->getVidMem(), - video->surface->getWidth(), video->surface->getHeight()); - */ + video->decoder->setSurfaceMemory(video->surface->getVidMem(), + video->surface->getWidth(), video->surface->getHeight(), 1); } } else { properties.sprite = -1; video->surface.reset(); - // video->decoder->setVideoMemory(); + video->decoder->setSurfaceMemory(); } if (primary) @@ -270,7 +268,7 @@ bool VideoPlayer::playFrame(int slot, Properties &properties) { WRITE_VAR(11, video->decoder->getCurFrame()); - blitFrame(video->surface, *surface); + // blitFrame(video->surface, *surface); if (_woodruffCohCottWorkaround && (properties.startFrame == 31)) { // WORKAROUND: This frame mistakenly masks Coh Cott, making her vanish diff --git a/graphics/video/coktel_decoder.cpp b/graphics/video/coktel_decoder.cpp index 0c5b637c2b..d13e678d44 100644 --- a/graphics/video/coktel_decoder.cpp +++ b/graphics/video/coktel_decoder.cpp @@ -34,7 +34,8 @@ CoktelDecoder::State::State() : left(0), top(0), right(0), bottom(0), flags(0), CoktelDecoder::CoktelDecoder(Audio::Mixer &mixer, Audio::Mixer::SoundType soundType) : - _mixer(&mixer), _soundType(soundType), _width(0), _height(0), _frameCount(0), _paletteDirty(false) { + _mixer(&mixer), _soundType(soundType), _width(0), _height(0), _frameCount(0), + _paletteDirty(false), _ownSurface(true) { memset(_palette, 0, 768); } @@ -42,6 +43,59 @@ CoktelDecoder::CoktelDecoder(Audio::Mixer &mixer, Audio::Mixer::SoundType soundT CoktelDecoder::~CoktelDecoder() { } +void CoktelDecoder::setSurfaceMemory(void *mem, uint16 width, uint16 height, uint8 bpp) { + freeSurface(); + + assert((width > 0) && (height > 0)); + assert(bpp == getPixelFormat().bytesPerPixel); + + _surface.w = width; + _surface.h = height; + _surface.pitch = width * bpp; + _surface.pixels = mem; + _surface.bytesPerPixel = bpp; + + _ownSurface = false; +} + +void CoktelDecoder::setSurfaceMemory() { + freeSurface(); + createSurface(); + + _ownSurface = true; +} + +bool CoktelDecoder::hasSurface() { + return _surface.pixels != 0; +} + +void CoktelDecoder::createSurface() { + if (hasSurface()) + return; + + if ((_width > 0) && (_height > 0)) + _surface.create(_width, _height, getPixelFormat().bytesPerPixel); + + _ownSurface = true; +} + +void CoktelDecoder::freeSurface() { + if (!_ownSurface) { + _surface.w = 0; + _surface.h = 0; + _surface.pitch = 0; + _surface.pixels = 0; + _surface.bytesPerPixel = 0; + } else + _surface.free(); + + _ownSurface = true; +} + +void CoktelDecoder::close() { + freeSurface(); +} + uint16 CoktelDecoder::getWidth() const { return _width; } @@ -129,8 +183,6 @@ bool PreIMDDecoder::load(Common::SeekableReadStream &stream) { _frameCount = _stream->readUint16LE(); - _surface.create(_width, _height, 1); - _videoBufferSize = _width * _height; _videoBuffer = new byte[_videoBufferSize]; @@ -142,7 +194,7 @@ bool PreIMDDecoder::load(Common::SeekableReadStream &stream) { void PreIMDDecoder::close() { reset(); - _surface.free(); + CoktelDecoder::close(); delete _stream; @@ -162,6 +214,8 @@ Surface *PreIMDDecoder::decodeNextFrame() { if (!isVideoLoaded() || endOfVideo()) return 0; + createSurface(); + processFrame(); renderFrame(); diff --git a/graphics/video/coktel_decoder.h b/graphics/video/coktel_decoder.h index b354a5cd9d..ec9acbe879 100644 --- a/graphics/video/coktel_decoder.h +++ b/graphics/video/coktel_decoder.h @@ -64,8 +64,15 @@ public: virtual bool seek(int32 frame, int whence = SEEK_SET, bool restart = false) = 0; + /** Draw directly onto the specified video memory. */ + void setSurfaceMemory(void *mem, uint16 width, uint16 height, uint8 bpp); + /** Reset the video memory. */ + void setSurfaceMemory(); + // VideoDecoder interface + void close(); + uint16 getWidth() const; uint16 getHeight() const; @@ -86,8 +93,15 @@ protected: byte _palette[768]; bool _paletteDirty; + bool _ownSurface; + Surface _surface; + Common::Rational _frameRate; + bool hasSurface(); + void createSurface(); + void freeSurface(); + // FixedRateVideoDecoder interface Common::Rational getFrameRate() const; }; @@ -117,8 +131,6 @@ private: byte *_videoBuffer; uint32 _videoBufferSize; - Surface _surface; - void processFrame(); void renderFrame(); }; |