diff options
-rw-r--r-- | engines/sci/engine/kernel.cpp | 1 | ||||
-rw-r--r-- | engines/sci/engine/kernel.h | 1 | ||||
-rw-r--r-- | engines/sci/engine/kgraphics.cpp | 43 | ||||
-rw-r--r-- | engines/sci/gfx/seq_decoder.cpp | 197 | ||||
-rw-r--r-- | engines/sci/gfx/seq_decoder.h | 48 | ||||
-rw-r--r-- | engines/sci/module.mk | 1 |
6 files changed, 291 insertions, 0 deletions
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index b84466e852..7985d3301b 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -210,6 +210,7 @@ SciKernelFunction kfunct_mappers[] = { 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}, diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index da3dca9ec4..c7110d5165 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -433,6 +433,7 @@ reg_t kDoAudio(EngineState *s, int funct_nr, int argc, reg_t *argv); 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 diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index a0bb426584..14e82a9a62 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -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 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { 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 diff --git a/engines/sci/gfx/seq_decoder.cpp b/engines/sci/gfx/seq_decoder.cpp new file mode 100644 index 0000000000..ac12678b09 --- /dev/null +++ b/engines/sci/gfx/seq_decoder.cpp @@ -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 diff --git a/engines/sci/gfx/seq_decoder.h b/engines/sci/gfx/seq_decoder.h new file mode 100644 index 0000000000..99126c056a --- /dev/null +++ b/engines/sci/gfx/seq_decoder.h @@ -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 diff --git a/engines/sci/module.mk b/engines/sci/module.mk index 08318aad2a..979bf08cd9 100644 --- a/engines/sci/module.mk +++ b/engines/sci/module.mk @@ -57,6 +57,7 @@ MODULE_OBJS = \ 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 \ |