[Scummvm-cvs-logs] SF.net SVN: scummvm:[35816] scummvm/trunk

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sun Jan 11 04:34:50 CET 2009


Revision: 35816
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35816&view=rev
Author:   thebluegr
Date:     2009-01-11 03:34:50 +0000 (Sun, 11 Jan 2009)

Log Message:
-----------
Committed a modified version of wjp's patch for the video player:
- Split the video player from the video decoders. It's now possible to have one video player for multiple decoders
- Added the palette weight calculation from the BS1 engine into VideoPlayer::setPalette. It's now possible to find the values of the white and black colors via getWhite() and getBlack() (useful for subtitle overlays)
- Adapted FTA2's movie playing code to the new changes to video player
- Fixed a slight bug in the DXA decoder (_videoinfo.startTime was not initialized)

Modified Paths:
--------------
    scummvm/trunk/engines/saga/introproc_fta2.cpp
    scummvm/trunk/graphics/video/dxa_player.cpp
    scummvm/trunk/graphics/video/dxa_player.h
    scummvm/trunk/graphics/video/smk_player.cpp
    scummvm/trunk/graphics/video/smk_player.h
    scummvm/trunk/graphics/video/video_player.cpp
    scummvm/trunk/graphics/video/video_player.h

Modified: scummvm/trunk/engines/saga/introproc_fta2.cpp
===================================================================
--- scummvm/trunk/engines/saga/introproc_fta2.cpp	2009-01-11 00:44:52 UTC (rev 35815)
+++ scummvm/trunk/engines/saga/introproc_fta2.cpp	2009-01-11 03:34:50 UTC (rev 35816)
@@ -52,10 +52,16 @@
 	stopEvent.kbd = Common::KEYCODE_ESCAPE;
 	stopEvents.push_back(stopEvent);
 
-	Graphics::SMKPlayer *smkPlayer = new Graphics::SMKPlayer(_vm->_mixer);
-	smkPlayer->playVideo("trimark.smk", &stopEvents);      // Show Ignite logo
-	smkPlayer->playVideo("intro.smk", &stopEvents);        // Play introduction
-	delete smkPlayer;
+	Graphics::SMKPlayer *smkDecoder = new Graphics::SMKPlayer(_vm->_mixer);
+	Graphics::VideoPlayer *player = new Graphics::VideoPlayer(smkDecoder);
+	if (smkDecoder->loadFile("trimark.smk"))
+		player->playVideo(&stopEvents);      // Show Ignite logo
+	smkDecoder->closeFile();
+	if (smkDecoder->loadFile("intro.smk"))
+		player->playVideo(&stopEvents);        // Play introduction
+	smkDecoder->closeFile();
+	delete player;
+	delete smkDecoder;
 
 	// HACK: Forcibly quit here
 	_vm->quitGame();
@@ -96,13 +102,18 @@
 	stopEvents.push_back(stopEvent);
 
 	// Play ending
-	Graphics::SMKPlayer *smkPlayer = new Graphics::SMKPlayer(_vm->_mixer);
-	smkPlayer->playVideo(videoName, &stopEvents);
-	delete smkPlayer;
+	Graphics::SMKPlayer *smkDecoder = new Graphics::SMKPlayer(_vm->_mixer);
+	Graphics::VideoPlayer *player = new Graphics::VideoPlayer(smkDecoder);
+	if (smkDecoder->loadFile(videoName)) {
+		player->playVideo(&stopEvents);
+		smkDecoder->closeFile();
+	}
+	delete player;
+	delete smkDecoder;
 
 	return SUCCESS;
 }
 
 } // End of namespace Saga
 
-#endif
\ No newline at end of file
+#endif

Modified: scummvm/trunk/graphics/video/dxa_player.cpp
===================================================================
--- scummvm/trunk/graphics/video/dxa_player.cpp	2009-01-11 00:44:52 UTC (rev 35815)
+++ scummvm/trunk/graphics/video/dxa_player.cpp	2009-01-11 03:34:50 UTC (rev 35816)
@@ -25,6 +25,7 @@
 
 #include "common/endian.h"
 #include "common/archive.h"
+#include "common/system.h"
 #include "common/util.h"
 
 #include "graphics/video/dxa_player.h"
@@ -476,6 +477,9 @@
 bool DXAPlayer::decodeNextFrame() {
 	uint32 tag;
 
+	if (_videoInfo.currentFrame == 0)
+		_videoInfo.startTime = g_system->getMillis();
+
 	tag = _fileStream->readUint32BE();
 	if (tag == MKID_BE('CMAP')) {
 		byte rgb[768];

Modified: scummvm/trunk/graphics/video/dxa_player.h
===================================================================
--- scummvm/trunk/graphics/video/dxa_player.h	2009-01-11 00:44:52 UTC (rev 35815)
+++ scummvm/trunk/graphics/video/dxa_player.h	2009-01-11 03:34:50 UTC (rev 35816)
@@ -30,7 +30,7 @@
 
 namespace Graphics {
 
-class DXAPlayer : public VideoPlayer {
+class DXAPlayer : public VideoDecoder {
 public:
 	DXAPlayer();
 	virtual ~DXAPlayer();

Modified: scummvm/trunk/graphics/video/smk_player.cpp
===================================================================
--- scummvm/trunk/graphics/video/smk_player.cpp	2009-01-11 00:44:52 UTC (rev 35815)
+++ scummvm/trunk/graphics/video/smk_player.cpp	2009-01-11 03:34:50 UTC (rev 35816)
@@ -321,6 +321,7 @@
 }
 
 SMKPlayer::~SMKPlayer() {
+	closeFile();
 }
 
 int SMKPlayer::getHeight() {

Modified: scummvm/trunk/graphics/video/smk_player.h
===================================================================
--- scummvm/trunk/graphics/video/smk_player.h	2009-01-11 00:44:52 UTC (rev 35815)
+++ scummvm/trunk/graphics/video/smk_player.h	2009-01-11 03:34:50 UTC (rev 35816)
@@ -44,7 +44,7 @@
 /**
  * Implementation of a Smacker v2/v4 video decoder
  */
-class SMKPlayer : public Graphics::VideoPlayer {
+class SMKPlayer : public Graphics::VideoDecoder {
 public:
 	SMKPlayer(Audio::Mixer *mixer);
 	virtual ~SMKPlayer();

Modified: scummvm/trunk/graphics/video/video_player.cpp
===================================================================
--- scummvm/trunk/graphics/video/video_player.cpp	2009-01-11 00:44:52 UTC (rev 35815)
+++ scummvm/trunk/graphics/video/video_player.cpp	2009-01-11 03:34:50 UTC (rev 35816)
@@ -35,50 +35,51 @@
 
 namespace Graphics {
 
-VideoPlayer::VideoPlayer() : _fileStream(0), _skipVideo(false) {
+VideoDecoder::VideoDecoder() : _fileStream(0) {
+	_black = 0;
+	_white = 255;
 }
 
-VideoPlayer::~VideoPlayer() {
-	closeFile();
+VideoDecoder::~VideoDecoder() {
 }
 
-int VideoPlayer::getWidth() {
+int VideoDecoder::getWidth() {
 	if (!_fileStream)
 		return 0;
 	return _videoInfo.width;
 }
 
-int VideoPlayer::getHeight() {
+int VideoDecoder::getHeight() {
 	if (!_fileStream)
 		return 0;
 	return _videoInfo.height;
 }
 
-int32 VideoPlayer::getCurFrame() {
+int32 VideoDecoder::getCurFrame() {
 	if (!_fileStream)
 		return -1;
 	return _videoInfo.currentFrame;
 }
 
-int32 VideoPlayer::getFrameCount() {
+int32 VideoDecoder::getFrameCount() {
 	if (!_fileStream)
 		return 0;
 	return _videoInfo.frameCount;
 }
 
-int32 VideoPlayer::getFrameRate() {
+int32 VideoDecoder::getFrameRate() {
 	if (!_fileStream)
 		return 0;
 	return _videoInfo.frameRate;
 }
 
-int32 VideoPlayer::getFrameDelay() {
+int32 VideoDecoder::getFrameDelay() {
 	if (!_fileStream)
 		return 0;
 	return _videoInfo.frameDelay;
 }
 
-int32 VideoPlayer::getAudioLag() {
+int32 VideoDecoder::getAudioLag() {
 	if (!_fileStream)
 		return 0;
 
@@ -92,7 +93,7 @@
 	return videoTime - audioTime;
 }
 
-uint32 VideoPlayer::getFrameWaitTime() {
+uint32 VideoDecoder::getFrameWaitTime() {
 	int32 waitTime = (getFrameDelay() + getAudioLag()) / 100;
 
 	if (waitTime < 0)
@@ -101,14 +102,7 @@
 	return waitTime;
 }
 
-bool VideoPlayer::loadFile(const char *fileName) {
-	return false;
-}
-
-void VideoPlayer::closeFile() {
-}
-
-void VideoPlayer::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) {
+void VideoDecoder::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) {
 	uint h = getHeight();
 	uint w = getWidth();
 
@@ -122,25 +116,45 @@
 	} while (--h);
 }
 
-void VideoPlayer::setPalette(byte *pal) {
+void VideoDecoder::setPalette(byte *pal) {
 	byte videoPalette[256 * 4];
 
+	uint32 maxWeight = 0;
+	uint32 minWeight = 0xFFFFFFFF;
+	uint32 weight = 0;
+	byte r, g, b;
+
 	for (int i = 0; i < 256; i++) {
 		videoPalette[i * 4 + 0] = *pal++;
 		videoPalette[i * 4 + 1] = *pal++;
 		videoPalette[i * 4 + 2] = *pal++;
 		videoPalette[i * 4 + 3] = 0;
+
+		// Try and find the white and black colors for the current palette
+		r = videoPalette[i * 4 + 0];
+		g = videoPalette[i * 4 + 1];
+		b = videoPalette[i * 4 + 2];
+
+		weight = 3 * r * r + 6 * g * g + 2 * b * b;
+
+		if (weight >= maxWeight) {
+			_white = i;
+			maxWeight = weight;
+		}
+
+		if (weight <= minWeight) {
+			_black = i;
+			minWeight = i;
+		}
 	}
 
 	g_system->setPalette(videoPalette, 0, 256);
 }
 
-bool VideoPlayer::decodeNextFrame() {
-	return false;
-}
 
-void VideoPlayer::performPostProcessing(byte *screen) {
-}
+/*
+ *  VideoPlayer
+ */
 
 void VideoPlayer::processVideoEvents(Common::List<Common::Event> *stopEvents) {
 	Common::Event curEvent;
@@ -168,35 +182,30 @@
 	}
 }
 
-bool VideoPlayer::playVideo(const char *filename, Common::List<Common::Event> *stopEvents) {
+bool VideoPlayer::playVideo(Common::List<Common::Event> *stopEvents) {
 	_skipVideo = false;
-	debug(0, "Playing video %s", filename);
+	debug(0, "Playing video");
 
-	if (!loadFile(filename)) {
-		warning("Failed to load video file %s", filename);
-		return false;
-	}
-
 	g_system->clearScreen();
 
-	while (getCurFrame() < getFrameCount() && !_skipVideo) {
+	while (_decoder->getCurFrame() < _decoder->getFrameCount() && !_skipVideo) {
 		processVideoEvents(stopEvents);
 
 		uint32 startTime = 0;
-		decodeNextFrame();
+		_decoder->decodeNextFrame();
 
 		Graphics::Surface *screen = g_system->lockScreen();
-		copyFrameToBuffer((byte *)screen->pixels,
-							(g_system->getWidth() - getWidth()) / 2,
-							(g_system->getHeight() - getHeight()) / 2,
+		_decoder->copyFrameToBuffer((byte *)screen->pixels,
+							(g_system->getWidth() - _decoder->getWidth()) / 2,
+							(g_system->getHeight() - _decoder->getHeight()) / 2,
 							g_system->getWidth());
 		performPostProcessing((byte *)screen->pixels);
 		g_system->unlockScreen();
 
-		uint32 waitTime = getFrameWaitTime();
+		uint32 waitTime = _decoder->getFrameWaitTime();
 
 		if (!waitTime) {
-			warning("dropped frame %i", getCurFrame());
+			warning("dropped frame %i", _decoder->getCurFrame());
 			continue;
 		}
 
@@ -212,9 +221,10 @@
 		}
 	}
 
-	closeFile();
+	return !_skipVideo;
+}
 
-	return true;
+void VideoPlayer::performPostProcessing(byte *screen) {
 }
 
 } // End of namespace Graphics

Modified: scummvm/trunk/graphics/video/video_player.h
===================================================================
--- scummvm/trunk/graphics/video/video_player.h	2009-01-11 00:44:52 UTC (rev 35815)
+++ scummvm/trunk/graphics/video/video_player.h	2009-01-11 03:34:50 UTC (rev 35816)
@@ -39,10 +39,10 @@
 /**
  * Implementation of a generic video decoder
  */
-class VideoPlayer {
+class VideoDecoder {
 public:
-	VideoPlayer();
-	virtual ~VideoPlayer();
+	VideoDecoder();
+	virtual ~VideoDecoder();
 
 	/**
 	 * Returns the width of the video
@@ -98,12 +98,12 @@
 	 * Load a video file
 	 * @param filename	the filename to load
 	 */
-	virtual bool loadFile(const char *filename);
+	virtual bool loadFile(const char *filename) = 0;
 
 	/**
 	 * Close a video file
 	 */
-	virtual void closeFile();
+	virtual void closeFile()=0;
 
 	/**
 	 * Returns if a video file is loaded or not
@@ -117,6 +117,16 @@
 	virtual void setPalette(byte *pal);
 
 	/**
+	 * Return the black palette color for the current frame
+	 */
+	byte getBlack() { return _black; }
+
+	/**
+	 * Return the white palette color for the current frame
+	 */
+	byte getWhite() { return _white; }
+
+	/**
 	 * Copy current frame into the specified position of the destination
 	 * buffer.
 	 * @param dst		the buffer
@@ -127,41 +137,53 @@
 	void copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch);
 
 	/**
-	 * Decode the next frame
+	 * Decode the next frame to _videoFrameBuffer
 	 */
-	virtual bool decodeNextFrame();
+	virtual bool decodeNextFrame() = 0;
 
+protected:
+	struct {
+		uint32 width;
+		uint32 height;
+		uint32 frameCount;
+		int32 frameRate;
+		int32 frameDelay;
+		uint32 currentFrame;
+		uint32 startTime;
+	} _videoInfo;
+
+	byte _black, _white;
+
+	Common::SeekableReadStream *_fileStream;
+	byte *_videoFrameBuffer;
+};
+
+class VideoPlayer {
+public:
+	VideoPlayer(VideoDecoder* decoder) : _skipVideo(false), _decoder(decoder)
+		{ }
+	~VideoPlayer() { }
 	/**
 	 * A default implementation of a video player
 	 * Plays a non-interactive full screen video till it's stopped by a
 	 * specific event
 	 * @param filename		the name of the file to play
 	 * @param stopEvents	a list of events that can stop the video
+	 *
+	 * Returns true if the video was played to the end, false if skipped
 	 */
-	bool playVideo(const char *filename, Common::List<Common::Event> *stopEvents);
+	bool playVideo(Common::List<Common::Event> *stopEvents);
 
+protected:
 	/**
 	 * Perform postprocessing once the frame data is copied to the screen,
-	 * right before the frame is drawn. Called from playVideo()
+	 * right before the frame is drawn. Called by playVideo()
 	 */
 	virtual void performPostProcessing(byte *screen);
 
-protected:
-	struct {
-		uint32 width;
-		uint32 height;
-		uint32 frameCount;
-		int32 frameRate;
-		int32 frameDelay;
-		uint32 currentFrame;
-		uint32 startTime;
-	} _videoInfo;
-
-	Common::SeekableReadStream *_fileStream;
-	byte *_videoFrameBuffer;
 	bool _skipVideo;
+	VideoDecoder* _decoder;
 
-private:
 	void processVideoEvents(Common::List<Common::Event> *stopEvents);
 };
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list