[Scummvm-git-logs] scummvm master -> ad04df748ce173f88384e39cbc2c0a875626b548

bluegr noreply at scummvm.org
Sun Mar 2 00:34:13 UTC 2025


This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
4867e171bf IMAGE: Add more validation for Codec::setOutputPixelFormat
953ccc3d6c VIDEO: Add a version of setOutputPixelFormat that accepts a list of formats
61c650eeb1 SWORD1: Detect availability of RGB colour support at runtime
ad04df748c SWORD2: Detect availability of RGB colour support at runtime


Commit: 4867e171bf2d702d1fab5a06e9561e6684504442
    https://github.com/scummvm/scummvm/commit/4867e171bf2d702d1fab5a06e9561e6684504442
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-03-02T02:34:07+02:00

Commit Message:
IMAGE: Add more validation for Codec::setOutputPixelFormat

Changed paths:
    image/codecs/cinepak.cpp
    image/codecs/indeo/indeo.h
    image/codecs/indeo3.h
    image/codecs/mjpeg.h
    image/codecs/mpeg.h
    image/codecs/svq1.h
    image/codecs/xan.h
    image/jpeg.h
    video/bink_decoder.h
    video/mkv_decoder.h
    video/mpegps_decoder.cpp
    video/psx_decoder.h
    video/theora_decoder.h


diff --git a/image/codecs/cinepak.cpp b/image/codecs/cinepak.cpp
index c47c908999a..fda0329312e 100644
--- a/image/codecs/cinepak.cpp
+++ b/image/codecs/cinepak.cpp
@@ -651,6 +651,9 @@ bool CinepakDecoder::setOutputPixelFormat(const Graphics::PixelFormat &format) {
 	if (_bitsPerPixel == 8)
 		return false;
 
+	if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+		return false;
+
 	_pixelFormat = format;
 	return true;
 }
diff --git a/image/codecs/indeo/indeo.h b/image/codecs/indeo/indeo.h
index ac35010a8f9..5b2f45fc237 100644
--- a/image/codecs/indeo/indeo.h
+++ b/image/codecs/indeo/indeo.h
@@ -540,7 +540,12 @@ protected:
 	 * Select the preferred format to use, for codecs where this is faster than converting
 	 * the image afterwards. Returns true if supported, and false otherwise.
 	 */
-	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override { _pixelFormat = format; return true; }
+	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
+		if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+			return false;
+		_pixelFormat = format;
+		return true;
+	}
 
 	/**
 	 * Decode the Indeo picture header.
diff --git a/image/codecs/indeo3.h b/image/codecs/indeo3.h
index 5ca0c4d45c9..9e45ee85afa 100644
--- a/image/codecs/indeo3.h
+++ b/image/codecs/indeo3.h
@@ -50,7 +50,12 @@ public:
 
 	const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
 	Graphics::PixelFormat getPixelFormat() const override;
-	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override { _pixelFormat = format; return true; }
+	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
+		if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+			return false;
+		_pixelFormat = format;
+		return true;
+	}
 
 	static bool isIndeo3(Common::SeekableReadStream &stream);
 
diff --git a/image/codecs/mjpeg.h b/image/codecs/mjpeg.h
index ea62520915e..55b83b77940 100644
--- a/image/codecs/mjpeg.h
+++ b/image/codecs/mjpeg.h
@@ -48,7 +48,12 @@ public:
 	const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
 	void setCodecAccuracy(CodecAccuracy accuracy) override;
 	Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
-	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override { _pixelFormat = format; return true; }
+	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
+		if (format.isCLUT8())
+			return false;
+		_pixelFormat = format;
+		return true;
+	}
 
 private:
 	Graphics::PixelFormat _pixelFormat;
diff --git a/image/codecs/mpeg.h b/image/codecs/mpeg.h
index 903354c49ec..cb648c2ae92 100644
--- a/image/codecs/mpeg.h
+++ b/image/codecs/mpeg.h
@@ -53,7 +53,12 @@ public:
 	// Codec interface
 	const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
 	Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
-	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override { _pixelFormat = format; return true; }
+	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
+		if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+			return false;
+		_pixelFormat = format;
+		return true;
+	}
 
 	// MPEGPSDecoder call
 	bool decodePacket(Common::SeekableReadStream &packet, uint32 &framePeriod, Graphics::Surface *dst = 0);
diff --git a/image/codecs/svq1.h b/image/codecs/svq1.h
index f5090c27f7b..55e84cd52b1 100644
--- a/image/codecs/svq1.h
+++ b/image/codecs/svq1.h
@@ -45,7 +45,12 @@ public:
 
 	const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
 	Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
-	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override { _pixelFormat = format; return true; }
+	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
+		if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+			return false;
+		_pixelFormat = format;
+		return true;
+	}
 
 private:
 	Graphics::PixelFormat _pixelFormat;
diff --git a/image/codecs/xan.h b/image/codecs/xan.h
index 513fd748c1f..14fec8c3d7b 100644
--- a/image/codecs/xan.h
+++ b/image/codecs/xan.h
@@ -47,7 +47,12 @@ public:
 
 	const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
 	Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
-	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override { _pixelFormat = format; return true; }
+	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
+		if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+			return false;
+		_pixelFormat = format;
+		return true;
+	}
 
 private:
 	void decodeFrameType0(Common::SeekableReadStream &stream);
diff --git a/image/jpeg.h b/image/jpeg.h
index c5581f347de..c59cb8786f3 100644
--- a/image/jpeg.h
+++ b/image/jpeg.h
@@ -60,7 +60,12 @@ public:
 	const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
 	void setCodecAccuracy(CodecAccuracy accuracy) override;
 	Graphics::PixelFormat getPixelFormat() const override;
-	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override { _requestedPixelFormat = format; return true; }
+	bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
+		if (format.isCLUT8())
+			return false;
+		_requestedPixelFormat = format;
+		return true;
+	}
 
 	// Special API for JPEG
 	enum ColorSpace {
diff --git a/video/bink_decoder.h b/video/bink_decoder.h
index cbf44635f3a..b12c24ce45c 100644
--- a/video/bink_decoder.h
+++ b/video/bink_decoder.h
@@ -153,7 +153,13 @@ private:
 		uint16 getWidth() const override { return _width; }
 		uint16 getHeight() const  override{ return _height; }
 		Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
-		bool setOutputPixelFormat(const Graphics::PixelFormat &format) override { _pixelFormat = format; return true; }
+		bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
+			if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+				return false;
+			_pixelFormat = format;
+			return true;
+		}
+
 		int getCurFrame() const override { return _curFrame; }
 		int getFrameCount() const override { return _frameCount; }
 		const Graphics::Surface *decodeNextFrame() override { return _surface; }
diff --git a/video/mkv_decoder.h b/video/mkv_decoder.h
index e651041baf4..7416480f463 100644
--- a/video/mkv_decoder.h
+++ b/video/mkv_decoder.h
@@ -95,7 +95,13 @@ private:
 		uint16 getWidth() const { return _width; }
 		uint16 getHeight() const { return _height; }
 		Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; }
-		bool setOutputPixelFormat(const Graphics::PixelFormat &format) { _pixelFormat = format; return true; }
+		bool setOutputPixelFormat(const Graphics::PixelFormat &format) {
+			if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+				return false;
+			_pixelFormat = format;
+			return true;
+		}
+
 		int getCurFrame() const { return _curFrame; }
 		uint32 getNextFrameStartTime() const { return (uint32)(_nextFrameStartTime * 1000); }
 		const Graphics::Surface *decodeNextFrame();
diff --git a/video/mpegps_decoder.cpp b/video/mpegps_decoder.cpp
index 9e7fed1a335..9c32c980bd3 100644
--- a/video/mpegps_decoder.cpp
+++ b/video/mpegps_decoder.cpp
@@ -622,6 +622,8 @@ Graphics::PixelFormat MPEGPSDecoder::MPEGVideoTrack::getPixelFormat() const {
 }
 
 bool MPEGPSDecoder::MPEGVideoTrack::setOutputPixelFormat(const Graphics::PixelFormat &format) {
+	if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+		return false;
 	_pixelFormat = format;
 	return true;
 }
diff --git a/video/psx_decoder.h b/video/psx_decoder.h
index 0199fb91862..b29b4c3f19c 100644
--- a/video/psx_decoder.h
+++ b/video/psx_decoder.h
@@ -84,6 +84,8 @@ private:
 		uint16 getHeight() const override { return _height; }
 		Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
 		bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
+			if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+				return false;
 			_pixelFormat = format;
 			return true;
 		}
diff --git a/video/theora_decoder.h b/video/theora_decoder.h
index a0f0a2e2703..5ce7ab5b10b 100644
--- a/video/theora_decoder.h
+++ b/video/theora_decoder.h
@@ -86,7 +86,13 @@ private:
 		uint16 getWidth() const { return _width; }
 		uint16 getHeight() const { return _height; }
 		Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; }
-		bool setOutputPixelFormat(const Graphics::PixelFormat &format) { _pixelFormat = format; return true; }
+		bool setOutputPixelFormat(const Graphics::PixelFormat &format) {
+			if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
+				return false;
+			_pixelFormat = format;
+			return true;
+		}
+
 		int getCurFrame() const { return _curFrame; }
 		const Common::Rational &getFrameRate() const { return _frameRate; }
 		uint32 getNextFrameStartTime() const { return (uint32)(_nextFrameStartTime * 1000); }


Commit: 953ccc3d6c0d5b8eb069c8abb985f088c7e0c8a9
    https://github.com/scummvm/scummvm/commit/953ccc3d6c0d5b8eb069c8abb985f088c7e0c8a9
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-03-02T02:34:07+02:00

Commit Message:
VIDEO: Add a version of setOutputPixelFormat that accepts a list of formats

Changed paths:
    engines/asylum/views/video.cpp
    video/video_decoder.cpp
    video/video_decoder.h


diff --git a/engines/asylum/views/video.cpp b/engines/asylum/views/video.cpp
index 013c71dd026..0d206b2edaa 100644
--- a/engines/asylum/views/video.cpp
+++ b/engines/asylum/views/video.cpp
@@ -191,8 +191,7 @@ void VideoPlayer::play(const Common::Path &filename, bool showSubtitles) {
 	int32 currentSubtitle = 0;
 
 	if (_vm->checkGameVersion("Steam") || _vm->isAltDemo()) {
-		Graphics::PixelFormat bestFormat = g_system->getSupportedFormats().front();
-		_decoder->setOutputPixelFormat(bestFormat);
+		_decoder->setOutputPixelFormats(g_system->getSupportedFormats());
 
 		Graphics::PixelFormat decoderFormat = _decoder->getPixelFormat();
 		initGraphics(640, 480, &decoderFormat);
diff --git a/video/video_decoder.cpp b/video/video_decoder.cpp
index 9029143074c..3037dcf94f2 100644
--- a/video/video_decoder.cpp
+++ b/video/video_decoder.cpp
@@ -568,6 +568,14 @@ bool VideoDecoder::setOutputPixelFormat(const Graphics::PixelFormat &format) {
 	return result;
 }
 
+bool VideoDecoder::setOutputPixelFormats(const Common::List<Graphics::PixelFormat> &formatList) {
+	for (Common::List<Graphics::PixelFormat>::const_iterator i = formatList.begin(); i != formatList.end(); ++i) {
+		if (setOutputPixelFormat(*i))
+			return true;
+	}
+	return false;
+}
+
 void VideoDecoder::setVideoCodecAccuracy(Image::CodecAccuracy accuracy) {
 	_videoCodecAccuracy = accuracy;
 
diff --git a/video/video_decoder.h b/video/video_decoder.h
index f924220c949..81fc3e234c3 100644
--- a/video/video_decoder.h
+++ b/video/video_decoder.h
@@ -407,6 +407,18 @@ public:
 	 */
 	bool setOutputPixelFormat(const Graphics::PixelFormat &format);
 
+	/**
+	 * Pick the default high color format from a list for videos that convert
+	 * from YUV.
+	 *
+	 * This should be called after loadStream(), but before a decodeNextFrame()
+	 * call. This is enforced.
+	 *
+	 * @param format The preferred output pixel format
+	 * @return true on success, false otherwise
+	 */
+	bool setOutputPixelFormats(const Common::List<Graphics::PixelFormat> &formatList);
+
 	/**
 	 * Set the accuracy of the video decoder
 	 */


Commit: 61c650eeb11197a044b84b0d8e610aac601a3c3b
    https://github.com/scummvm/scummvm/commit/61c650eeb11197a044b84b0d8e610aac601a3c3b
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-03-02T02:34:07+02:00

Commit Message:
SWORD1: Detect availability of RGB colour support at runtime

Changed paths:
    engines/sword1/animation.cpp
    engines/sword1/animation.h
    engines/sword1/logic.cpp


diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp
index ef8362604af..0c1a28ad7bd 100644
--- a/engines/sword1/animation.cpp
+++ b/engines/sword1/animation.cpp
@@ -102,7 +102,7 @@ static const char *const sequenceListPSX[20] = {
 ///////////////////////////////////////////////////////////////////////////////
 
 MoviePlayer::MoviePlayer(SwordEngine *vm, Text *textMan, ResMan *resMan, Sound *sound, OSystem *system, Video::VideoDecoder *decoder, DecoderType decoderType)
-	: _vm(vm), _textMan(textMan), _resMan(resMan), _sound(sound), _system(system), _textX(0), _textY(0), _textWidth(0), _textHeight(0), _textColor(1) {
+	: _vm(vm), _textMan(textMan), _resMan(resMan), _sound(sound), _system(system), _textX(0), _textY(0), _textWidth(0), _textHeight(0), _textColor(1), _modeChange(false) {
 	_decoderType = decoderType;
 	_decoder = decoder;
 
@@ -118,7 +118,7 @@ MoviePlayer::~MoviePlayer() {
  * Plays an animated cutscene.
  * @param id the id of the file
  */
-bool MoviePlayer::load(uint32 id) {
+Common::Error MoviePlayer::load(uint32 id) {
 	Common::Path filename;
 
 	if (SwordEngine::_systemVars.showText) {
@@ -188,16 +188,23 @@ bool MoviePlayer::load(uint32 id) {
 		break;
 	}
 
+	if (!_decoder->loadFile(filename)) {
+		return Common::Error(Common::kPathDoesNotExist, filename.toString());
+	}
+
 	// Need to switch to true color for PSX/MP2 videos
-	if (_decoderType == kVideoDecoderPSX || _decoderType == kVideoDecoderMP2)
-		initGraphics(g_system->getWidth(), g_system->getHeight(), nullptr);
+	if (!_decoder->getPixelFormat().isCLUT8()) {
+		if (!_decoder->setOutputPixelFormats(g_system->getSupportedFormats()))
+			return Common::kUnsupportedColorMode;
 
-	if (!_decoder->loadFile(filename)) {
-		// Go back to 8bpp color
-		if (_decoderType == kVideoDecoderPSX || _decoderType == kVideoDecoderMP2)
-			initGraphics(g_system->getWidth(), g_system->getHeight());
+		Graphics::PixelFormat format = _decoder->getPixelFormat();
+		initGraphics(g_system->getWidth(), g_system->getHeight(), &format);
 
-		return false;
+		if (g_system->getScreenFormat() != format) {
+			return Common::kUnsupportedColorMode;
+		} else {
+			_modeChange = true;
+		}
 	}
 
 	// For DXA/MP2, also add the external sound file
@@ -205,7 +212,7 @@ bool MoviePlayer::load(uint32 id) {
 		_decoder->addStreamFileTrack(sequenceList[id]);
 
 	_decoder->start();
-	return true;
+	return Common::kNoError;
 }
 
 void MoviePlayer::play() {
@@ -231,7 +238,7 @@ void MoviePlayer::play() {
 void MoviePlayer::performPostProcessing(byte *screen) {
 	// TODO: We don't support displaying these in true color yet,
 	// nor using the PSX fonts to display subtitles.
-	if (_vm->isPsx() || _decoderType == kVideoDecoderMP2)
+	if (_vm->isPsx() || _modeChange)
 		return;
 
 	if (!_movieTexts.empty()) {
@@ -425,18 +432,20 @@ bool MoviePlayer::playVideo() {
 	}
 
 	// Need to jump back to paletted color
-	if (_decoderType == kVideoDecoderPSX || _decoderType == kVideoDecoderMP2)
+	if (_modeChange) {
 		initGraphics(g_system->getWidth(), g_system->getHeight());
+		_modeChange = false;
+	}
 
 	return !_vm->shouldQuit() && !skipped;
 }
 
 uint32 MoviePlayer::getBlackColor() {
-	return (_decoderType == kVideoDecoderPSX || _decoderType == kVideoDecoderMP2) ? g_system->getScreenFormat().RGBToColor(0x00, 0x00, 0x00) : _black;
+	return (_modeChange) ? g_system->getScreenFormat().RGBToColor(0x00, 0x00, 0x00) : _black;
 }
 
 uint32 MoviePlayer::findTextColor() {
-	if (_decoderType == kVideoDecoderPSX || _decoderType == kVideoDecoderMP2) {
+	if (_modeChange) {
 		// We're in true color mode, so return the actual colors
 		switch (_textColor) {
 		case 1:
@@ -524,15 +533,9 @@ MoviePlayer *makeMoviePlayer(uint32 id, SwordEngine *vm, Text *textMan, ResMan *
 		filename = ((vm->_systemVars.isDemo && id == 4) ? Common::Path("intro.str") : Common::Path(Common::String(sequenceListPSX[id]) + ".str"));
 
 		if (Common::File::exists(filename)) {
-#ifdef USE_RGB_COLOR
 			// All BS1 PSX videos run the videos at 2x speed
 			Video::VideoDecoder *psxDecoder = new Video::PSXStreamDecoder(Video::PSXStreamDecoder::kCD2x);
 			return new MoviePlayer(vm, textMan, resMan, sound, system, psxDecoder, kVideoDecoderPSX);
-#else
-			GUI::MessageDialog dialog(Common::U32String::format(_("PSX stream cutscene '%s' cannot be played in paletted mode"), filename.toString().c_str()), _("OK"));
-			dialog.runModal();
-			return 0;
-#endif
 		}
 	}
 
diff --git a/engines/sword1/animation.h b/engines/sword1/animation.h
index 9ab1d765dab..84effd73c15 100644
--- a/engines/sword1/animation.h
+++ b/engines/sword1/animation.h
@@ -62,7 +62,7 @@ class MoviePlayer {
 public:
 	MoviePlayer(SwordEngine *vm, Text *textMan, ResMan *resMan, Sound *sound, OSystem *system, Video::VideoDecoder *decoder, DecoderType decoderType);
 	virtual ~MoviePlayer();
-	bool load(uint32 id);
+	Common::Error load(uint32 id);
 	void play();
 
 protected:
@@ -77,6 +77,7 @@ protected:
 	uint32 _black;
 	uint32 _c1Color, _c2Color, _c3Color, _c4Color;
 	DecoderType _decoderType;
+	bool _modeChange;
 
 	Video::VideoDecoder *_decoder;
 
diff --git a/engines/sword1/logic.cpp b/engines/sword1/logic.cpp
index ab77ac23b6b..c6d502adb84 100644
--- a/engines/sword1/logic.cpp
+++ b/engines/sword1/logic.cpp
@@ -39,6 +39,7 @@
 
 #include "sword1/debug.h"
 
+#include "gui/error.h"
 #include "gui/message.h"
 
 namespace Sword1 {
@@ -1014,9 +1015,14 @@ int Logic::fnPlaySequence(Object *cpt, int32 id, int32 sequenceId, int32 d, int3
 	} else {
 		MoviePlayer *player = makeMoviePlayer(sequenceId, _vm, _textMan, _resMan, _sound, _system);
 		if (player) {
+			Common::Error err;
+
 			_screen->clearScreen();
-			if (player->load(sequenceId))
+			err = player->load(sequenceId);
+			if (err.getCode() == Common::kNoError)
 				player->play();
+			else
+				GUI::displayErrorDialog(err);
 			delete player;
 
 			// In some instances, when you start a video when the palette is still fading


Commit: ad04df748ce173f88384e39cbc2c0a875626b548
    https://github.com/scummvm/scummvm/commit/ad04df748ce173f88384e39cbc2c0a875626b548
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-03-02T02:34:07+02:00

Commit Message:
SWORD2: Detect availability of RGB colour support at runtime

Changed paths:
    engines/sword2/animation.cpp
    engines/sword2/animation.h
    engines/sword2/function.cpp


diff --git a/engines/sword2/animation.cpp b/engines/sword2/animation.cpp
index 67b28a59d6b..64bdac2671d 100644
--- a/engines/sword2/animation.cpp
+++ b/engines/sword2/animation.cpp
@@ -59,7 +59,7 @@ namespace Sword2 {
 ///////////////////////////////////////////////////////////////////////////////
 
 MoviePlayer::MoviePlayer(Sword2Engine *vm, OSystem *system, Video::VideoDecoder *decoder, DecoderType decoderType)
-	: _vm(vm), _system(system) {
+	: _vm(vm), _system(system), _modeChange(false) {
 	_decoderType = decoderType;
 	_decoder = decoder;
 
@@ -75,11 +75,7 @@ MoviePlayer::~MoviePlayer() {
  * Plays an animated cutscene.
  * @param id the id of the file
  */
-bool MoviePlayer::load(const char *name) {
-	// This happens when quitting during the "eye" cutscene.
-	if (_vm->shouldQuit())
-		return false;
-
+Common::Error MoviePlayer::load(const char *name) {
 	_textSurface = nullptr;
 
 	Common::String filename;
@@ -100,16 +96,23 @@ bool MoviePlayer::load(const char *name) {
 		break;
 	}
 
+	if (!_decoder->loadFile(Common::Path(filename))) {
+		return Common::Error(Common::kPathDoesNotExist, filename);
+	}
+
 	// Need to switch to true color for PSX/MP2 videos
-	if (_decoderType == kVideoDecoderPSX || _decoderType == kVideoDecoderMP2)
-		initGraphics(g_system->getWidth(), g_system->getHeight(), nullptr);
+	if (!_decoder->getPixelFormat().isCLUT8()) {
+		if (!_decoder->setOutputPixelFormats(g_system->getSupportedFormats()))
+			return Common::kUnsupportedColorMode;
 
-	if (!_decoder->loadFile(Common::Path(filename))) {
-		// Go back to 8bpp color
-		if (_decoderType == kVideoDecoderPSX || _decoderType == kVideoDecoderMP2)
-			initGraphics(g_system->getWidth(), g_system->getHeight());
+		Graphics::PixelFormat format = _decoder->getPixelFormat();
+		initGraphics(g_system->getWidth(), g_system->getHeight(), &format);
 
-		return false;
+		if (g_system->getScreenFormat() != format) {
+			return Common::kUnsupportedColorMode;
+		} else {
+			_modeChange = true;
+		}
 	}
 
 	// For DXA/MP2, also add the external sound file
@@ -117,7 +120,7 @@ bool MoviePlayer::load(const char *name) {
 		_decoder->addStreamFileTrack(name);
 
 	_decoder->start();
-	return true;
+	return Common::kNoError;
 }
 
 void MoviePlayer::play(MovieText *movieTexts, uint32 numMovieTexts, uint32 leadIn, uint32 leadOut) {
@@ -143,8 +146,10 @@ void MoviePlayer::play(MovieText *movieTexts, uint32 numMovieTexts, uint32 leadI
 	}
 
 	// Need to jump back to paletted color
-	if (_decoderType == kVideoDecoderPSX || _decoderType == kVideoDecoderMP2)
+	if (_modeChange) {
 		initGraphics(640, 480);
+		_modeChange = false;
+	}
 }
 
 void MoviePlayer::openTextObject(uint32 index) {
@@ -385,11 +390,11 @@ bool MoviePlayer::playVideo() {
 }
 
 uint32 MoviePlayer::getBlackColor() {
-	return (_decoderType == kVideoDecoderPSX || _decoderType == kVideoDecoderMP2) ? g_system->getScreenFormat().RGBToColor(0x00, 0x00, 0x00) : _black;
+	return _modeChange ? g_system->getScreenFormat().RGBToColor(0x00, 0x00, 0x00) : _black;
 }
 
 uint32 MoviePlayer::getWhiteColor() {
-	return (_decoderType == kVideoDecoderPSX || _decoderType == kVideoDecoderMP2) ? g_system->getScreenFormat().RGBToColor(0xFF, 0xFF, 0xFF) : _white;
+	return _modeChange ? g_system->getScreenFormat().RGBToColor(0xFF, 0xFF, 0xFF) : _white;
 }
 
 void MoviePlayer::drawFramePSX(const Graphics::Surface *frame) {
@@ -414,19 +419,17 @@ void MoviePlayer::drawFramePSX(const Graphics::Surface *frame) {
 ///////////////////////////////////////////////////////////////////////////////
 
 MoviePlayer *makeMoviePlayer(const char *name, Sword2Engine *vm, OSystem *system, uint32 frameCount) {
+	// This happens when quitting during the "eye" cutscene.
+	if (vm->shouldQuit())
+		return nullptr;
+
 	Common::String filename;
 
 	filename = Common::String::format("%s.str", name);
 
 	if (Common::File::exists(Common::Path(filename))) {
-#ifdef USE_RGB_COLOR
 		Video::VideoDecoder *psxDecoder = new Video::PSXStreamDecoder(Video::PSXStreamDecoder::kCD2x, frameCount);
 		return new MoviePlayer(vm, system, psxDecoder, kVideoDecoderPSX);
-#else
-		GUI::MessageDialog dialog(_("PSX cutscenes found but ScummVM has been built without RGB color support"), _("OK"));
-		dialog.runModal();
-		return nullptr;
-#endif
 	}
 
 	filename = Common::String::format("%s.smk", name);
diff --git a/engines/sword2/animation.h b/engines/sword2/animation.h
index 18ff9f52e98..9c057a22e86 100644
--- a/engines/sword2/animation.h
+++ b/engines/sword2/animation.h
@@ -64,7 +64,7 @@ public:
 	MoviePlayer(Sword2Engine *vm, OSystem *system, Video::VideoDecoder *decoder, DecoderType decoderType);
 	virtual ~MoviePlayer();
 
-	bool load(const char *name);
+	Common::Error load(const char *name);
 	void play(MovieText *movieTexts, uint32 numMovieTexts, uint32 leadIn, uint32 leadOut);
 
 protected:
@@ -77,6 +77,7 @@ protected:
 	int _textX, _textY;
 	byte _white, _black;
 	DecoderType _decoderType;
+	bool _modeChange;
 
 	Video::VideoDecoder *_decoder;
 
diff --git a/engines/sword2/function.cpp b/engines/sword2/function.cpp
index 3ffce083215..43de1af952a 100644
--- a/engines/sword2/function.cpp
+++ b/engines/sword2/function.cpp
@@ -40,6 +40,8 @@
 #include "sword2/sound.h"
 #include "sword2/animation.h"
 
+#include "gui/error.h"
+
 namespace Sword2 {
 
 int32 Logic::fnTestFunction(int32 *params) {
@@ -2143,8 +2145,12 @@ int32 Logic::fnPlaySequence(int32 *params) {
 
 	_moviePlayer = makeMoviePlayer(filename, _vm, _vm->_system, frameCount);
 
-	if (_moviePlayer && _moviePlayer->load(filename)) {
-		_moviePlayer->play(_sequenceTextList, _sequenceTextLines, _smackerLeadIn, _smackerLeadOut);
+	if (_moviePlayer) {
+		Common::Error err = _moviePlayer->load(filename);
+		if (err.getCode() == Common::kNoError)
+			_moviePlayer->play(_sequenceTextList, _sequenceTextLines, _smackerLeadIn, _smackerLeadOut);
+		else
+			GUI::displayErrorDialog(err);
 	}
 
 	_sequenceTextLines = 0;




More information about the Scummvm-git-logs mailing list