[Scummvm-cvs-logs] SF.net SVN: scummvm:[40774] scummvm/trunk/engines/sci

waltervn at users.sourceforge.net waltervn at users.sourceforge.net
Fri May 22 00:03:24 CEST 2009


Revision: 40774
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40774&view=rev
Author:   waltervn
Date:     2009-05-21 22:03:23 +0000 (Thu, 21 May 2009)

Log Message:
-----------
SCI: Added support for KQ6 movies.

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/kernel.cpp
    scummvm/trunk/engines/sci/engine/kernel.h
    scummvm/trunk/engines/sci/engine/kgraphics.cpp
    scummvm/trunk/engines/sci/module.mk

Added Paths:
-----------
    scummvm/trunk/engines/sci/gfx/seq_decoder.cpp
    scummvm/trunk/engines/sci/gfx/seq_decoder.h

Modified: scummvm/trunk/engines/sci/engine/kernel.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.cpp	2009-05-21 21:51:50 UTC (rev 40773)
+++ scummvm/trunk/engines/sci/engine/kernel.cpp	2009-05-21 22:03:23 UTC (rev 40774)
@@ -210,6 +210,7 @@
 	DEFUN("DoSync", kDoSync, ".*"),
 	DEFUN("ResCheck", kResCheck, "iii*"),
 	DEFUN("SetQuitStr", kSetQuitStr, "r"),
+	DEFUN("ShowMovie", kShowMovie, "ri"),
 
 	// Special and NOP stuff
 	{KF_NEW, NULL, k_Unknown, NULL},

Modified: scummvm/trunk/engines/sci/engine/kernel.h
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.h	2009-05-21 21:51:50 UTC (rev 40773)
+++ scummvm/trunk/engines/sci/engine/kernel.h	2009-05-21 22:03:23 UTC (rev 40774)
@@ -433,6 +433,7 @@
 reg_t kDoSync(EngineState *s, int funct_nr, int argc, reg_t *argv);
 reg_t kResCheck(EngineState *s, int funct_nr, int argc, reg_t *argv);
 reg_t kSetQuitStr(EngineState *s, int funct_nr, int argc, reg_t *argv);
+reg_t kShowMovie(EngineState *s, int funct_nr, int argc, reg_t *argv);
 reg_t k_Unknown(EngineState *s, int funct_nr, int argc, reg_t *argv);
 
 // The Unknown/Unnamed kernel function

Modified: scummvm/trunk/engines/sci/engine/kgraphics.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-05-21 21:51:50 UTC (rev 40773)
+++ scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-05-21 22:03:23 UTC (rev 40774)
@@ -24,6 +24,7 @@
  */
 
 #include "common/system.h"
+#include "common/events.h"
 
 #include "sci/sci.h"
 #include "sci/resource.h"
@@ -32,6 +33,7 @@
 #include "sci/gfx/gfx_gui.h"
 #include "sci/gfx/gfx_widgets.h"
 #include "sci/gfx/gfx_state_internal.h"	// required for GfxContainer, GfxPort, GfxVisual
+#include "sci/gfx/seq_decoder.h"
 
 namespace Sci {
 
@@ -3312,4 +3314,45 @@
 	return s->r_acc;
 }
 
+reg_t kShowMovie(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+	const char *filename = kernel_dereference_char_pointer(s, argv[0], 0);
+	int framerate = UKPV(1); // FIXME: verify
+	SeqDecoder seq;
+
+	if (!seq.loadFile(filename)) {
+		warning("Failed to open movie file %s", filename);
+		return s->r_acc;
+	}
+
+	bool play = true;
+	while (play) {
+		gfx_pixmap_t *pixmap = seq.getFrame(play);
+		gfx_xlate_pixmap(pixmap, s->gfx_state->driver->mode, GFX_XLATE_FILTER_NONE);
+		GFX_ASSERT(gfxop_draw_pixmap(s->gfx_state, pixmap, gfx_rect(0, 0, 320, 200), Common::Point(pixmap->xoffset, pixmap->yoffset)));
+		gfxop_update_box(s->gfx_state, gfx_rect(0, 0, 320, 200));
+		gfx_free_pixmap(pixmap);
+
+		uint32 startTime = g_system->getMillis();
+
+		// Wait before showing the next frame
+		while (play && (g_system->getMillis() < startTime + 1000 / framerate)) {
+			// FIXME: we should probably make a function that handles quitting in these kinds of situations
+			Common::Event curEvent;
+			Common::EventManager *eventMan = g_system->getEventManager();
+
+			// Process quit events
+			while (eventMan->pollEvent(curEvent)) {
+				if (curEvent.type == Common::EVENT_QUIT) {
+					play = false;
+					quit_vm();
+				}
+			}
+
+			g_system->delayMillis(10);
+		}
+	}
+
+	return s->r_acc;
+}
+
 } // End of namespace Sci

Added: scummvm/trunk/engines/sci/gfx/seq_decoder.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/seq_decoder.cpp	                        (rev 0)
+++ scummvm/trunk/engines/sci/gfx/seq_decoder.cpp	2009-05-21 22:03:23 UTC (rev 40774)
@@ -0,0 +1,197 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/archive.h"
+#include "sci/gfx/seq_decoder.h"
+#include "sci/gfx/gfx_resource.h"
+#include "sci/gfx/gfx_tools.h"
+
+namespace Sci {
+
+SeqDecoder::~SeqDecoder() {
+	closeFile();
+}
+
+bool SeqDecoder::loadFile(const char *fileName) {
+	closeFile();
+
+	_fileStream = SearchMan.createReadStreamForMember(fileName);
+	if (!_fileStream)
+		return false;
+
+	_frameCount = _fileStream->readUint16LE();
+	int paletteSize = _fileStream->readUint32LE();
+
+	byte *paletteData = new byte[paletteSize];
+	_fileStream->read(paletteData, paletteSize);
+	_palette = gfxr_read_pal11(-1, paletteData, paletteSize);
+	delete[] paletteData;
+
+	_currentFrame = 0;
+
+	return true;
+}
+
+void SeqDecoder::closeFile() {
+	if (!_fileStream)
+		return;
+
+	delete _fileStream;
+	_fileStream = 0;
+
+	delete _palette;
+	_palette = 0;
+}
+
+#define WRITE_TO_BUFFER(n) \
+	if (writeRow * width + writeCol + (n) > width * height) { \
+		warning("SEQ player: writing out of bounds, aborting"); \
+		return false; \
+	} \
+	if (litPos + (n) > litSize) { \
+		warning("SEQ player: reading out of bounds, aborting"); \
+	} \
+	memcpy(dest + writeRow * width + writeCol, litData + litPos, n);
+
+bool SeqDecoder::decodeFrame(byte *rleData, int rleSize, byte *litData, int litSize, byte *dest, int width, int height, int colorKey) {
+	int writeRow = 0;
+	int writeCol = 0;
+	int litPos = 0;
+	int rlePos = 0;
+
+	memset(dest, colorKey, width * height);
+
+	while (rlePos < rleSize) {
+		int op = rleData[rlePos++];
+
+		if ((op & 0xc0) == 0xc0) {
+			op &= 0x3f;
+			if (op == 0) {
+				// Go to next line in target buffer
+				writeRow++;
+				writeCol = 0;
+			} else {
+				// Skip bytes on current line
+				writeCol += op;
+			}
+		} else if (op & 0x80) {
+			op &= 0x3f;
+			if (op == 0) {
+				// Copy remainder of current line
+				int rem = width - writeCol;
+
+				WRITE_TO_BUFFER(rem);
+				writeRow++;
+				writeCol = 0;
+				litPos += rem;
+			} else {
+				// Copy bytes
+				WRITE_TO_BUFFER(op);
+				writeCol += op;
+				litPos += op;
+			}
+		} else {
+			uint16 count = ((op & 7) << 8) | rleData[rlePos++];
+
+			switch (op >> 3) {
+			case 2:
+				// Skip bytes
+				writeCol += count;
+				break;
+			case 3:
+				// Copy bytes
+				WRITE_TO_BUFFER(count);
+				writeCol += count;
+				litPos += count;
+				break;
+			case 6: {
+				// Copy rows
+				if (count == 0)
+					count = height - writeRow;
+
+				for (int i = 0; i < count; i++) {
+					WRITE_TO_BUFFER(width);
+					litPos += width;
+					writeRow++;
+				}
+				break;
+			}
+			case 7:
+				// Skip rows
+				if (count == 0)
+					count = height - writeRow;
+
+				writeRow += count;
+				break;
+			default:
+				warning("Unsupported operation %i encountered", op >> 3);
+				return false;
+			}
+		}
+	}
+
+	return true;
+}
+
+gfx_pixmap_t *SeqDecoder::getFrame(bool &hasNext) {
+	int frameWidth = _fileStream->readUint16LE();
+	int frameHeight = _fileStream->readUint16LE();
+	int frameLeft = _fileStream->readUint16LE();
+	int frameTop = _fileStream->readUint16LE();
+	int colorKey = _fileStream->readByte();
+	int type = _fileStream->readByte();
+	_fileStream->seek(2, SEEK_CUR);
+	uint16 bytes = _fileStream->readUint16LE();
+	_fileStream->seek(2, SEEK_CUR);
+	uint16 rle_bytes = _fileStream->readUint16LE();
+	_fileStream->seek(6, SEEK_CUR);
+	uint32 offset = _fileStream->readUint32LE();
+
+	_fileStream->seek(offset);
+	gfx_pixmap_t *pixmap = gfx_new_pixmap(frameWidth, frameHeight, 0, 0, 0);
+
+	assert(pixmap);
+
+	gfx_pixmap_alloc_index_data(pixmap);
+
+	if (type == 0)
+		_fileStream->read(pixmap->index_data, bytes);
+	else {
+		byte *buf = new byte[bytes];
+		_fileStream->read(buf, bytes);
+		decodeFrame(buf, rle_bytes, buf + rle_bytes, bytes - rle_bytes, pixmap->index_data, frameWidth, frameHeight, colorKey);
+	}
+
+	pixmap->xoffset = frameLeft;
+	pixmap->yoffset = frameTop;
+	pixmap->color_key = colorKey;
+	pixmap->palette = _palette->getref();
+
+	hasNext = ++_currentFrame < _frameCount;
+
+	return pixmap;
+}
+
+} // End of namespace Sci


Property changes on: scummvm/trunk/engines/sci/gfx/seq_decoder.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Added: scummvm/trunk/engines/sci/gfx/seq_decoder.h
===================================================================
--- scummvm/trunk/engines/sci/gfx/seq_decoder.h	                        (rev 0)
+++ scummvm/trunk/engines/sci/gfx/seq_decoder.h	2009-05-21 22:03:23 UTC (rev 40774)
@@ -0,0 +1,48 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/file.h"
+#include "sci/gfx/gfx_system.h"
+
+namespace Sci {
+
+class SeqDecoder {
+public:
+	SeqDecoder() : _fileStream(0), _palette(0) { }
+	~SeqDecoder();
+	bool loadFile(const char *fileName);
+	void closeFile();
+	gfx_pixmap_t *getFrame(bool &hasNext);
+
+private:
+	bool decodeFrame(byte *runlength_data, int runlength_size, byte *literal_data, int literal_size, byte *dest, int xl, int yl, int color_key);
+
+	Common::SeekableReadStream *_fileStream;
+	Palette *_palette;
+	int _frameCount;
+	int _currentFrame;
+};
+
+} // End of namespace Sci


Property changes on: scummvm/trunk/engines/sci/gfx/seq_decoder.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/trunk/engines/sci/module.mk
===================================================================
--- scummvm/trunk/engines/sci/module.mk	2009-05-21 21:51:50 UTC (rev 40773)
+++ scummvm/trunk/engines/sci/module.mk	2009-05-21 22:03:23 UTC (rev 40774)
@@ -57,6 +57,7 @@
 	gfx/res_pic.o \
 	gfx/res_view0.o \
 	gfx/res_view1.o \
+	gfx/seq_decoder.o \
 	sfx/adlib_sbi.o \
 	sfx/core.o \
 	sfx/iterator.o \


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