diff options
Diffstat (limited to 'engines/sci/engine/kvideo.cpp')
-rw-r--r-- | engines/sci/engine/kvideo.cpp | 72 |
1 files changed, 24 insertions, 48 deletions
diff --git a/engines/sci/engine/kvideo.cpp b/engines/sci/engine/kvideo.cpp index 5851b015aa..03ed698f17 100644 --- a/engines/sci/engine/kvideo.cpp +++ b/engines/sci/engine/kvideo.cpp @@ -50,17 +50,14 @@ namespace Sci { -void playVideo(Video::VideoDecoder *videoDecoder, VideoState videoState) { - if (!videoDecoder) - return; - - videoDecoder->start(); +void playVideo(Video::VideoDecoder &videoDecoder) { + videoDecoder.start(); Common::SpanOwner<SciSpan<byte> > scaleBuffer; - byte bytesPerPixel = videoDecoder->getPixelFormat().bytesPerPixel; - uint16 width = videoDecoder->getWidth(); - uint16 height = videoDecoder->getHeight(); - uint16 pitch = videoDecoder->getWidth() * bytesPerPixel; + byte bytesPerPixel = videoDecoder.getPixelFormat().bytesPerPixel; + uint16 width = videoDecoder.getWidth(); + uint16 height = videoDecoder.getHeight(); + uint16 pitch = videoDecoder.getWidth() * bytesPerPixel; uint16 screenWidth = g_sci->_gfxScreen->getDisplayWidth(); uint16 screenHeight = g_sci->_gfxScreen->getDisplayHeight(); uint32 numPixels; @@ -70,7 +67,7 @@ void playVideo(Video::VideoDecoder *videoDecoder, VideoState videoState) { height *= 2; pitch *= 2; numPixels = width * height * bytesPerPixel; - scaleBuffer->allocate(numPixels, videoState.fileName + " scale buffer"); + scaleBuffer->allocate(numPixels, "video scale buffer"); } uint16 x = (screenWidth - width) / 2; @@ -78,27 +75,27 @@ void playVideo(Video::VideoDecoder *videoDecoder, VideoState videoState) { bool skipVideo = false; - if (videoDecoder->hasDirtyPalette()) { - const byte *palette = videoDecoder->getPalette(); + if (videoDecoder.hasDirtyPalette()) { + const byte *palette = videoDecoder.getPalette(); g_system->getPaletteManager()->setPalette(palette, 0, 255); } - while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) { - if (videoDecoder->needsUpdate()) { - const Graphics::Surface *frame = videoDecoder->decodeNextFrame(); + while (!g_engine->shouldQuit() && !videoDecoder.endOfVideo() && !skipVideo) { + if (videoDecoder.needsUpdate()) { + const Graphics::Surface *frame = videoDecoder.decodeNextFrame(); if (frame) { if (scaleBuffer) { const SciSpan<const byte> input((const byte *)frame->getPixels(), frame->w * frame->h * bytesPerPixel); // TODO: Probably should do aspect ratio correction in KQ6 - g_sci->_gfxScreen->scale2x(input, *scaleBuffer, videoDecoder->getWidth(), videoDecoder->getHeight(), bytesPerPixel); + g_sci->_gfxScreen->scale2x(input, *scaleBuffer, videoDecoder.getWidth(), videoDecoder.getHeight(), bytesPerPixel); g_system->copyRectToScreen(scaleBuffer->getUnsafeDataAt(0, pitch * height), pitch, x, y, width, height); } else { g_system->copyRectToScreen(frame->getPixels(), frame->pitch, x, y, width, height); } - if (videoDecoder->hasDirtyPalette()) { - const byte *palette = videoDecoder->getPalette(); + if (videoDecoder.hasDirtyPalette()) { + const byte *palette = videoDecoder.getPalette(); g_system->getPaletteManager()->setPalette(palette, 0, 255); } @@ -116,8 +113,6 @@ void playVideo(Video::VideoDecoder *videoDecoder, VideoState videoState) { g_system->delayMillis(10); } - - delete videoDecoder; } reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) { @@ -130,9 +125,9 @@ reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) { uint16 screenWidth = g_system->getWidth(); uint16 screenHeight = g_system->getHeight(); - Video::VideoDecoder *videoDecoder = 0; + Common::ScopedPtr<Video::VideoDecoder> videoDecoder; - if (argv[0].getSegment() != 0) { + if (argv[0].isPointer()) { Common::String filename = s->_segMan->getString(argv[0]); if (g_sci->getPlatform() == Common::kPlatformMacintosh) { @@ -147,19 +142,18 @@ reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) { return NULL_REG; } - videoDecoder = new Video::QuickTimeDecoder(); + videoDecoder.reset(new Video::QuickTimeDecoder()); if (!videoDecoder->loadFile(filename)) error("Could not open '%s'", filename.c_str()); } else { // DOS SEQ // SEQ's are called with no subops, just the string and delay // Time is specified as ticks - videoDecoder = new SEQDecoder(argv[1].toUint16()); + videoDecoder.reset(new SEQDecoder(argv[1].toUint16())); if (!videoDecoder->loadFile(filename)) { warning("Failed to open movie file %s", filename.c_str()); - delete videoDecoder; - videoDecoder = 0; + videoDecoder.reset(); } } } else { @@ -170,28 +164,10 @@ reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) { switch (argv[0].toUint16()) { case 0: { Common::String filename = s->_segMan->getString(argv[1]); - - if (filename.equalsIgnoreCase("gk2a.avi")) { - // HACK: Switch to 16bpp graphics for Indeo3. - // The only known movie to do use this codec is the GK2 demo trailer - // If another video turns up that uses Indeo, we may have to add a better - // check. - initGraphics(screenWidth, screenHeight, nullptr); - - if (g_system->getScreenFormat().bytesPerPixel == 1) { - warning("This video requires >8bpp color to be displayed, but could not switch to RGB color mode"); - return NULL_REG; - } - } - - videoDecoder = new Video::AVIDecoder(); - + videoDecoder.reset(new Video::AVIDecoder()); if (!videoDecoder->loadFile(filename.c_str())) { warning("Failed to open movie file %s", filename.c_str()); - delete videoDecoder; - videoDecoder = 0; - } else { - s->_videoState.fileName = filename; + videoDecoder.reset(); } break; } @@ -201,13 +177,13 @@ reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) { } if (videoDecoder) { - playVideo(videoDecoder, s->_videoState); + playVideo(*videoDecoder); // HACK: Switch back to 8bpp if we played a true color video. // We also won't be copying the screen to the SCI screen... if (g_system->getScreenFormat().bytesPerPixel != 1) initGraphics(screenWidth, screenHeight); - else if (getSciVersion() < SCI_VERSION_2) { + else { g_sci->_gfxScreen->kernelSyncWithFramebuffer(); g_sci->_gfxPalette16->kernelSyncScreenPalette(); } |