[Scummvm-cvs-logs] SF.net SVN: scummvm:[49951] scummvm/trunk/engines/sci/engine/kgraphics.cpp

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Thu Jun 17 23:00:45 CEST 2010


Revision: 49951
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49951&view=rev
Author:   mthreepwood
Date:     2010-06-17 21:00:45 +0000 (Thu, 17 Jun 2010)

Log Message:
-----------
Only do video scaling when required (hopefully fixes SQ6). Adapt the scaling code to normal SCI videos as well.

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/kgraphics.cpp

Modified: scummvm/trunk/engines/sci/engine/kgraphics.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kgraphics.cpp	2010-06-17 20:52:53 UTC (rev 49950)
+++ scummvm/trunk/engines/sci/engine/kgraphics.cpp	2010-06-17 21:00:45 UTC (rev 49951)
@@ -1085,6 +1085,58 @@
 	return g_sci->_gfxPaint16->kernelDisplay(g_sci->strSplit(text.c_str()).c_str(), argc, argv);
 }
 
+void playVideo(Graphics::VideoDecoder *videoDecoder) {
+	if (!videoDecoder)
+		return;
+
+	byte *scaleBuffer = 0;
+	uint16 width = videoDecoder->getWidth();
+	uint16 height = videoDecoder->getHeight();
+	uint16 screenWidth = g_system->getWidth();
+	uint16 screenHeight = g_system->getHeight();
+
+	if (screenWidth == 640 && width <= 320 && height <= 240) {
+		assert(videoDecoder->getPixelFormat().bytesPerPixel == 1);
+		width *= 2;
+		height *= 2;
+		scaleBuffer = new byte[width * height];
+	}
+
+	uint16 x = (screenWidth - width) / 2;
+	uint16 y = (screenHeight - height) / 2;
+	bool skipVideo = false;
+
+	while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) {
+		if (videoDecoder->needsUpdate()) {
+			Graphics::Surface *frame = videoDecoder->decodeNextFrame();
+			if (frame) {
+				if (scaleBuffer) {
+					// TODO: Probably should do aspect ratio correction in e.g. GK1 Windows 
+					g_sci->_gfxScreen->scale2x((byte *)frame->pixels, scaleBuffer, videoDecoder->getWidth(), videoDecoder->getHeight());
+					g_system->copyRectToScreen(scaleBuffer, width, x, y, width, height);
+				} else
+					g_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, width, height);
+
+				if (videoDecoder->hasDirtyPalette())
+					videoDecoder->setSystemPalette();
+
+				g_system->updateScreen();
+			}
+		}
+
+		Common::Event event;
+		while (g_system->getEventManager()->pollEvent(event)) {
+			if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP)
+				skipVideo = true;
+		}
+
+		g_system->delayMillis(10);
+	}
+
+	delete[] scaleBuffer;
+	delete videoDecoder;
+}
+
 reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) {
 	// Hide the cursor if it's showing and then show it again if it was
 	// previously visible.
@@ -1161,40 +1213,14 @@
 	}
 
 	if (videoDecoder) {
-		uint16 x = (screenWidth - videoDecoder->getWidth()) / 2;
-		uint16 y = (screenHeight - videoDecoder->getHeight()) / 2;
-		bool skipVideo = false;
+		playVideo(videoDecoder);
 
-		while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) {
-			if (videoDecoder->needsUpdate()) {
-				Graphics::Surface *frame = videoDecoder->decodeNextFrame();
-				if (frame) {
-					g_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h);
-
-					if (videoDecoder->hasDirtyPalette())
-						videoDecoder->setSystemPalette();
-
-					g_system->updateScreen();
-				}
-			}
-
-			Common::Event event;
-			while (g_system->getEventManager()->pollEvent(event)) {
-				if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP)
-					skipVideo = true;
-			}
-
-			g_system->delayMillis(10);
-		}
-
 		// HACK: Switch back to 8bpp if we played a QuickTime video.
 		// We also won't be copying the screen to the SCI screen...
 		if (g_system->getScreenFormat().bytesPerPixel != 1)
 			initGraphics(screenWidth, screenHeight, screenWidth > 320);
 		else
 			g_sci->_gfxScreen->kernelSyncWithFramebuffer();
-		
-		delete videoDecoder;
 	}
 
 	if (reshowCursor)
@@ -1255,53 +1281,9 @@
 		if (reshowCursor)
 			g_sci->_gfxCursor->kernelHide();
 
-		if (videoDecoder && videoDecoder->loadFile(fileName)) {
-			//uint16 x = (g_system->getWidth() - videoDecoder->getWidth()) / 2;
-			//uint16 y = (g_system->getHeight() - videoDecoder->getHeight()) / 2;
-			uint16 w = videoDecoder->getWidth() * 2;
-			uint16 h = videoDecoder->getHeight() * 2;
-			uint16 x = (g_system->getWidth() - w) / 2;
-			uint16 y = (g_system->getHeight() - h) / 2;
-			byte *frameBuf = new byte[w * h];
+		if (videoDecoder && videoDecoder->loadFile(fileName))
+			playVideo(videoDecoder);
 
-			bool skipVideo = false;
-
-			while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) {
-				if (videoDecoder->needsUpdate()) {
-					Graphics::Surface *frame = videoDecoder->decodeNextFrame();
-
-					if (frame) {
-						//g_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h);
-						// All the VMD videos in SCI2.1 need to be scaled by 2
-						// TODO: This isn't optimized much, but since the VMD decoder code will be revamped, we
-						// don't really care about performance at this point anyway
-						g_sci->_gfxScreen->scale2x((byte *)frame->pixels, frameBuf, videoDecoder->getWidth(), videoDecoder->getHeight());
-						g_system->copyRectToScreen(frameBuf, frame->pitch * 2, x, y, frame->w * 2, frame->h * 2);
-
-						if (videoDecoder->hasDirtyPalette())
-							videoDecoder->setSystemPalette();
-
-						g_system->updateScreen();
-					}
-				}
-
-				Common::Event event;
-				while (g_system->getEventManager()->pollEvent(event)) {
-					if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP)
-						skipVideo = true;
-				}
-
-				g_system->delayMillis(10);
-			}
-		
-			// Copy video contents to screen buffer
-			g_sci->_gfxScreen->kernelSyncWithFramebuffer();
-
-			delete[] frameBuf;
-			delete videoDecoder;
-		} else
-			warning("Could not play video %s\n", fileName.c_str());
-
 		if (reshowCursor)
 			g_sci->_gfxCursor->kernelShow();
 		break;


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