TITANIC: Further implementation of movie frame decoding

This commit is contained in:
Paul Gilbert 2016-07-12 17:35:48 -04:00
parent 513723c82d
commit 6b250453f9
8 changed files with 56 additions and 24 deletions

View File

@ -23,6 +23,8 @@
#include "titanic/support/avi_surface.h"
#include "titanic/support/screen_manager.h"
#include "titanic/support/video_surface.h"
#include "common/system.h"
#include "graphics/pixelformat.h"
#include "video/avi_decoder.h"
namespace Titanic {
@ -220,7 +222,8 @@ void AVISurface::setupDecompressor() {
AVIDecoder &decoder = *_decoders[idx];
// Setup frame surface
_movieFrameSurface[idx] = CScreenManager::_screenManagerPtr->createSurface(decoder.getWidth(), decoder.getHeight());
_movieFrameSurface[idx] = new Graphics::ManagedSurface(decoder.getWidth(), decoder.getHeight(),
g_system->getScreenFormat());
// TODO: See whether this simplified form of original works
if (idx == 2)
@ -259,15 +262,29 @@ bool AVISurface::renderFrame() {
if (!_decoders[0]->needsUpdate() || (_decoders[1] && !_decoders[1]->needsUpdate()))
return false;
// Get the frame to render, and draw it on the surface
// TODO: Handle transparency
// Decode each decoder's video stream into the appropriate surface
for (int idx = 0; idx < 2; ++idx) {
if (_decoders[idx]) {
const Graphics::Surface *frame = _decoders[idx]->decodeNextFrame();
_videoSurface->blitFrom(Point(0, 0), frame);
if (_movieFrameSurface[idx]->format == frame->format) {
_movieFrameSurface[idx]->blitFrom(*frame);
} else {
// Format mis-match, so we need to convert the frame
Graphics::Surface *s = frame->convertTo(_movieFrameSurface[idx]->format,
_decoders[idx]->getPalette());
_movieFrameSurface[idx]->blitFrom(*s);
s->free();
delete s;
}
}
}
// Blit the primary video frame onto the main overall surface
_videoSurface->lock();
_videoSurface->getRawSurface()->blitFrom(*_movieFrameSurface[0]);
_videoSurface->unlock();
return false;
}
@ -298,14 +315,19 @@ void AVISurface::setFrameRate(double rate) {
}
}
CVideoSurface *AVISurface::getSecondarySurface() {
Graphics::ManagedSurface *AVISurface::getSecondarySurface() {
return _streamCount <= 1 ? nullptr : _movieFrameSurface[1];
}
CVideoSurface *AVISurface::duplicateSecondaryFrame() const {
// TODO: Make this cleaner
OSVideoSurface *src = dynamic_cast<OSVideoSurface *>(_movieFrameSurface[1]);
return new OSVideoSurface(*src);
Graphics::ManagedSurface *AVISurface::duplicateSecondaryFrame() const {
if (_streamCount <= 1) {
return nullptr;
} else {
Graphics::ManagedSurface *dest = new Graphics::ManagedSurface(_movieFrameSurface[1]->w,
_movieFrameSurface[1]->h, _movieFrameSurface[1]->format);
dest->blitFrom(*_movieFrameSurface[1]);
return dest;
}
}
} // End of namespace Titanic

View File

@ -24,6 +24,7 @@
#define TITANIC_AVI_SURFACE_H
#include "video/avi_decoder.h"
#include "graphics/managed_surface.h"
#include "titanic/core/resource_key.h"
#include "titanic/support/movie_range_info.h"
@ -55,7 +56,7 @@ private:
int _priorFrame;
CMovieRangeInfoList _movieRangeInfo;
int _streamCount;
CVideoSurface *_movieFrameSurface[2];
Graphics::ManagedSurface *_movieFrameSurface[2];
private:
/**
* Render a frame to the video surface
@ -148,7 +149,7 @@ public:
/**
* Returns the surface for the secondary video track frame, if present
*/
CVideoSurface *getSecondarySurface();
Graphics::ManagedSurface *getSecondarySurface();
/**
* Get a reference to the movie range info list
@ -160,7 +161,7 @@ public:
/**
* Duplicates the secondary frame, if the movie has a second video track
*/
CVideoSurface *duplicateSecondaryFrame() const;
Graphics::ManagedSurface *duplicateSecondaryFrame() const;
};
} // End of namespace Titanic

View File

@ -85,7 +85,7 @@ void CMouseCursor::loadCursorImages() {
OSMovie movie(key, surface);
movie.setFrame(idx);
CVideoSurface *frameSurface = movie.duplicateFrame();
Graphics::ManagedSurface *frameSurface = movie.duplicateFrame();
_cursors[idx]._frameSurface = frameSurface;
surface->setMovieFrameSurface(frameSurface);
}

View File

@ -25,6 +25,7 @@
#include "common/scummsys.h"
#include "common/rect.h"
#include "graphics/managed_surface.h"
namespace Titanic {
@ -54,7 +55,7 @@ class CVideoSurface;
class CMouseCursor {
struct CursorEntry {
CVideoSurface *_videoSurface;
CVideoSurface *_frameSurface;
Graphics::ManagedSurface *_frameSurface;
Common::Point _centroid;
CursorEntry() : _videoSurface(nullptr), _frameSurface(nullptr) {}

View File

@ -217,7 +217,7 @@ void OSMovie::setFrameRate(double rate) {
_aviSurface.setFrameRate(rate);
}
CVideoSurface *OSMovie::duplicateFrame() const {
Graphics::ManagedSurface *OSMovie::duplicateFrame() const {
return _aviSurface.duplicateSecondaryFrame();
}

View File

@ -135,7 +135,7 @@ public:
/**
* Creates a duplicate of the movie's frame
*/
virtual CVideoSurface *duplicateFrame() const = 0;
virtual Graphics::ManagedSurface *duplicateFrame() const = 0;
/**
* Removes the movie from the list of currently playing movies
@ -233,7 +233,7 @@ public:
/**
* Creates a duplicate of the frame info
*/
virtual CVideoSurface *duplicateFrame() const;
virtual Graphics::ManagedSurface *duplicateFrame() const;
};
} // End of namespace Titanic

View File

@ -541,7 +541,7 @@ void OSVideoSurface::transPixelate() {
unlock();
}
CVideoSurface *OSVideoSurface::dupMovieFrame() const {
Graphics::ManagedSurface *OSVideoSurface::dupMovieFrame() const {
return _movie ? _movie->duplicateFrame() : nullptr;
}

View File

@ -25,6 +25,7 @@
#include "common/scummsys.h"
#include "common/array.h"
#include "graphics/managed_surface.h"
#include "titanic/support/font.h"
#include "titanic/support/direct_draw.h"
#include "titanic/support/movie.h"
@ -62,7 +63,7 @@ protected:
CScreenManager *_screenManager;
Graphics::ManagedSurface *_rawSurface;
bool _pendingLoad;
CVideoSurface *_movieFrameSurface;
Graphics::ManagedSurface *_movieFrameSurface;
int _field48;
int _videoSurfaceNum;
int _field50;
@ -260,7 +261,7 @@ public:
/**
* Duplicates movie frame surface
*/
virtual CVideoSurface *dupMovieFrame() const = 0;
virtual Graphics::ManagedSurface *dupMovieFrame() const = 0;
/**
* Frees the underlying surface
@ -283,13 +284,14 @@ public:
void blitFrom(const Point &destPos, const Graphics::Surface *src);
/**
*
* Sets the movie frame surface containing frame data from an active movie
*/
void setMovieFrameSurface(CVideoSurface *frameSurface) { _movieFrameSurface = frameSurface; }
void setMovieFrameSurface(Graphics::ManagedSurface *frameSurface) { _movieFrameSurface = frameSurface; }
/**
* Get the previously set movie frame surface
*/
CVideoSurface *getMovieFrameSurface() const { return _movieFrameSurface; }
Graphics::ManagedSurface *getMovieFrameSurface() const { return _movieFrameSurface; }
/**
* Get the pixels associated with the surface. Only valid when the
@ -297,6 +299,12 @@ public:
*/
uint16 *getPixels() { return (uint16 *)_rawSurface->getPixels(); }
/**
* Get a reference to the underlying surface. Only valid when the surface
* has been locked for access
*/
Graphics::ManagedSurface *getRawSurface() { return _rawSurface; }
/**
* Returns the transparent color
*/
@ -499,7 +507,7 @@ public:
/**
* Duplicates movie frame surface
*/
virtual CVideoSurface *dupMovieFrame() const;
virtual Graphics::ManagedSurface *dupMovieFrame() const;
/**