[Scummvm-git-logs] scummvm master -> 17a4318a724b08d5fec7edfb32d38b98a4090295

sev- noreply at scummvm.org
Sun Aug 6 12:46:15 UTC 2023


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:
5ff6bd08cb VIDEO: Allow drawing subtitles in const methods
b1420626e6 SCI: Show SRT subtitles on SCI32 videos
cf13eb315f SCI:  Calculate subtitle position by draw rect
17a4318a72 SCI: Add comments regarding usage of SRT subtitles


Commit: 5ff6bd08cbf6bfc38e38a19346b2a98ab42228be
    https://github.com/scummvm/scummvm/commit/5ff6bd08cbf6bfc38e38a19346b2a98ab42228be
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2023-08-06T14:46:10+02:00

Commit Message:
VIDEO: Allow drawing subtitles in const methods

Changed paths:
    video/subtitles.cpp
    video/subtitles.h


diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index 91007387974..19b12075891 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -216,7 +216,7 @@ bool SRTParser::parseFile(const char *fname) {
 	return true;
 }
 
-Common::String SRTParser::getSubtitle(uint32 timestamp) {
+Common::String SRTParser::getSubtitle(uint32 timestamp) const {
 	SRTEntry test(0, timestamp, 0, "");
 	SRTEntry *testptr = &test;
 
@@ -299,7 +299,7 @@ void Subtitles::setPadding(uint16 horizontal, uint16 vertical) {
 	_vPad = vertical;
 }
 
-bool Subtitles::drawSubtitle(uint32 timestamp, bool force) {
+bool Subtitles::drawSubtitle(uint32 timestamp, bool force) const {
 	Common::String subtitle;
 	if (_loaded) {
 		subtitle = _srtParser.getSubtitle(timestamp);
@@ -375,7 +375,7 @@ bool Subtitles::drawSubtitle(uint32 timestamp, bool force) {
 	return true;
 }
 
-void Subtitles::renderSubtitle() {
+void Subtitles::renderSubtitle() const {
 	_surface->fillRect(Common::Rect(0, 0, _surface->w, _surface->h), _transparentColor);
 
 	Common::Array<Common::U32String> lines;
diff --git a/video/subtitles.h b/video/subtitles.h
index f649921567b..0060e610fd1 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -52,7 +52,7 @@ public:
 
 	void cleanup();
 	bool parseFile(const char *fname);
-	Common::String getSubtitle(uint32 timestamp);
+	Common::String getSubtitle(uint32 timestamp) const;
 
 private:
 	Common::Array<SRTEntry *> _entries;
@@ -69,11 +69,11 @@ public:
 	void setBBox(const Common::Rect bbox);
 	void setColor(byte r, byte g, byte b);
 	void setPadding(uint16 horizontal, uint16 vertical);
-	bool drawSubtitle(uint32 timestamp, bool force = false);
+	bool drawSubtitle(uint32 timestamp, bool force = false) const;
 	bool isLoaded() const { return _loaded || _subtitleDev; }
 
 private:
-	void renderSubtitle();
+	void renderSubtitle() const;
 
 	SRTParser _srtParser;
 	bool _loaded;
@@ -85,13 +85,13 @@ private:
 
 	Graphics::Surface *_surface;
 
-	Common::Rect _drawRect;
+	mutable Common::Rect _drawRect;
 	Common::Rect _requestedBBox;
-	Common::Rect _realBBox;
-	int16 _lastOverlayWidth, _lastOverlayHeight;
+	mutable Common::Rect _realBBox;
+	mutable int16 _lastOverlayWidth, _lastOverlayHeight;
 
 	Common::String _fname;
-	Common::String _subtitle;
+	mutable Common::String _subtitle;
 	uint32 _color;
 	uint32 _blackColor;
 	uint32 _transparentColor;


Commit: b1420626e68fb61564ff40d7657228232ed2c1c7
    https://github.com/scummvm/scummvm/commit/b1420626e68fb61564ff40d7657228232ed2c1c7
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2023-08-06T14:46:10+02:00

Commit Message:
SCI: Show SRT subtitles on SCI32 videos

Changed paths:
    engines/sci/graphics/video32.cpp
    engines/sci/graphics/video32.h


diff --git a/engines/sci/graphics/video32.cpp b/engines/sci/graphics/video32.cpp
index 5d8f16f5058..39f7c1b9fd2 100644
--- a/engines/sci/graphics/video32.cpp
+++ b/engines/sci/graphics/video32.cpp
@@ -130,6 +130,18 @@ VideoPlayer::EventFlags VideoPlayer::playUntilEvent(const EventFlags flags, cons
 	_decoder->start();
 
 	EventFlags stopFlag = kEventFlagNone;
+
+	if (_subtitles.isLoaded()) {
+		const int16 h = g_system->getOverlayHeight(),
+			        w = g_system->getOverlayWidth();
+		_subtitles.setBBox(Common::Rect(20, h - 120, w - 20, h - 20));
+		_subtitles.setColor(0xff, 0xff, 0xff);
+		_subtitles.setFont("FreeSans.ttf");
+
+		g_system->clearOverlay();
+		g_system->showOverlay(false);
+	}
+
 	for (;;) {
 		if (!_needsUpdate) {
 			g_sci->sleep(MIN(_decoder->getTimeToNextFrame(), maxSleepMs));
@@ -178,6 +190,11 @@ VideoPlayer::EventFlags VideoPlayer::playUntilEvent(const EventFlags flags, cons
 		g_sci->_gfxFrameout->updateScreen();
 	}
 
+	if (_subtitles.isLoaded()) {
+		g_system->hideOverlay();
+	}
+	_subtitles.close();
+
 	return stopFlag;
 }
 
@@ -269,6 +286,8 @@ void VideoPlayer::renderFrame(const Graphics::Surface &nextFrame) const {
 	g_system->copyRectToScreen(convertedFrame->getPixels(), convertedFrame->pitch, _drawRect.left, _drawRect.top, _drawRect.width(), _drawRect.height());
 	g_sci->_gfxFrameout->updateScreen();
 
+	_subtitles.drawSubtitle(_decoder->getTime(), true);
+
 	if (freeConvertedFrame) {
 		convertedFrame->free();
 		delete convertedFrame;
@@ -613,6 +632,9 @@ VMDPlayer::IOStatus VMDPlayer::open(const Common::String &fileName, const OpenFl
 		if (flags & kOpenFlagMute) {
 			_decoder->setVolume(0);
 		}
+		Common::String subtitlesName = Common::String::format("%s.srt", fileName.c_str());
+		_subtitles.loadSRTFile(subtitlesName.c_str());
+
 		return kIOSuccess;
 	}
 
@@ -1179,6 +1201,9 @@ void DuckPlayer::open(const GuiResourceId resourceId, const int displayMode, con
 		g_sci->_gfxFrameout->setPixelFormat(_decoder->getPixelFormat());
 	}
 
+	Common::String subtitlesName = Common::String::format("%s.srt", fileName.c_str());
+	_subtitles.loadSRTFile(subtitlesName.c_str());
+
 	_status = kDuckOpen;
 }
 
diff --git a/engines/sci/graphics/video32.h b/engines/sci/graphics/video32.h
index 90f05ca1a44..bc0b2e3df7a 100644
--- a/engines/sci/graphics/video32.h
+++ b/engines/sci/graphics/video32.h
@@ -33,6 +33,7 @@
 #include "sci/video/robot_decoder.h" // for RobotDecoder
 #include "sci/sound/audio32.h"    // for Audio32::kMaxVolume
 #include "video/avi_decoder.h"    // for AVIDecoder::setVolume
+#include "video/subtitles.h"      // for Video::Subtitles
 
 namespace Video {
 class AdvancedVMDDecoder;
@@ -184,6 +185,9 @@ protected:
 	 */
 	const Graphics::Surface* _currentFrame;
 
+
+	Video::Subtitles _subtitles;
+
 #ifdef USE_RGB_COLOR
 	/**
 	 * Whether or not the player is currently in high-quality video rendering


Commit: cf13eb315f8f6f52e3ed90231a90d86278c99af1
    https://github.com/scummvm/scummvm/commit/cf13eb315f8f6f52e3ed90231a90d86278c99af1
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2023-08-06T14:46:10+02:00

Commit Message:
SCI:  Calculate subtitle position by draw rect

Changed paths:
    engines/sci/graphics/video32.cpp
    engines/sci/graphics/video32.h


diff --git a/engines/sci/graphics/video32.cpp b/engines/sci/graphics/video32.cpp
index 39f7c1b9fd2..c171fa7fdcf 100644
--- a/engines/sci/graphics/video32.cpp
+++ b/engines/sci/graphics/video32.cpp
@@ -121,6 +121,21 @@ bool VideoPlayer::endHQVideo() {
 	return false;
 }
 
+void VideoPlayer::setSubtitlePosition() const {
+	const int16 overlayHeight = g_system->getOverlayHeight(),
+				overlayWidth = g_system->getOverlayWidth(),
+				drawHeight = _drawRect.height(),
+				drawWidth = _drawRect.width();
+	_subtitles.setBBox(
+		Common::Rect(
+			(_drawRect.left + 20) * overlayWidth / drawWidth,
+			(_drawRect.bottom - 80) * overlayHeight / drawHeight,
+			(_drawRect.right - 20)  * overlayWidth / drawWidth,
+			(_drawRect.bottom - 10) * overlayHeight / drawHeight
+		)
+	);
+}
+
 VideoPlayer::EventFlags VideoPlayer::playUntilEvent(const EventFlags flags, const uint32 maxSleepMs) {
 	// Flushing all the keyboard and mouse events out of the event manager keeps
 	// events queued from before the start of playback from accidentally
@@ -132,9 +147,7 @@ VideoPlayer::EventFlags VideoPlayer::playUntilEvent(const EventFlags flags, cons
 	EventFlags stopFlag = kEventFlagNone;
 
 	if (_subtitles.isLoaded()) {
-		const int16 h = g_system->getOverlayHeight(),
-			        w = g_system->getOverlayWidth();
-		_subtitles.setBBox(Common::Rect(20, h - 120, w - 20, h - 20));
+		setSubtitlePosition();
 		_subtitles.setColor(0xff, 0xff, 0xff);
 		_subtitles.setFont("FreeSans.ttf");
 
@@ -286,6 +299,8 @@ void VideoPlayer::renderFrame(const Graphics::Surface &nextFrame) const {
 	g_system->copyRectToScreen(convertedFrame->getPixels(), convertedFrame->pitch, _drawRect.left, _drawRect.top, _drawRect.width(), _drawRect.height());
 	g_sci->_gfxFrameout->updateScreen();
 
+	if (_subtitles.isLoaded())
+		setSubtitlePosition();
 	_subtitles.drawSubtitle(_decoder->getTime(), true);
 
 	if (freeConvertedFrame) {
diff --git a/engines/sci/graphics/video32.h b/engines/sci/graphics/video32.h
index bc0b2e3df7a..2c98b2aa182 100644
--- a/engines/sci/graphics/video32.h
+++ b/engines/sci/graphics/video32.h
@@ -168,6 +168,12 @@ protected:
 	 */
 	void setDrawRect(const int16 x, const int16 y, const int16 width, const int16 height);
 
+	/**
+	 * Sets the subtitle position according to the draw rect and overlay size.
+	 * 
+	 */
+	void setSubtitlePosition() const;
+
 	/**
 	 * The rectangle where the video will be drawn, in screen coordinates.
 	 */
@@ -186,7 +192,7 @@ protected:
 	const Graphics::Surface* _currentFrame;
 
 
-	Video::Subtitles _subtitles;
+	mutable Video::Subtitles _subtitles;
 
 #ifdef USE_RGB_COLOR
 	/**


Commit: 17a4318a724b08d5fec7edfb32d38b98a4090295
    https://github.com/scummvm/scummvm/commit/17a4318a724b08d5fec7edfb32d38b98a4090295
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2023-08-06T14:46:10+02:00

Commit Message:
SCI: Add comments regarding usage of SRT subtitles

Changed paths:
    engines/sci/graphics/video32.cpp
    engines/sci/graphics/video32.h


diff --git a/engines/sci/graphics/video32.cpp b/engines/sci/graphics/video32.cpp
index c171fa7fdcf..ffc70321707 100644
--- a/engines/sci/graphics/video32.cpp
+++ b/engines/sci/graphics/video32.cpp
@@ -647,6 +647,8 @@ VMDPlayer::IOStatus VMDPlayer::open(const Common::String &fileName, const OpenFl
 		if (flags & kOpenFlagMute) {
 			_decoder->setVolume(0);
 		}
+
+		// Try load fan-made SRT subtitles for current video
 		Common::String subtitlesName = Common::String::format("%s.srt", fileName.c_str());
 		_subtitles.loadSRTFile(subtitlesName.c_str());
 
@@ -1216,6 +1218,7 @@ void DuckPlayer::open(const GuiResourceId resourceId, const int displayMode, con
 		g_sci->_gfxFrameout->setPixelFormat(_decoder->getPixelFormat());
 	}
 
+	// Try load fan-made SRT subtitles for current video
 	Common::String subtitlesName = Common::String::format("%s.srt", fileName.c_str());
 	_subtitles.loadSRTFile(subtitlesName.c_str());
 
diff --git a/engines/sci/graphics/video32.h b/engines/sci/graphics/video32.h
index 2c98b2aa182..482937dae77 100644
--- a/engines/sci/graphics/video32.h
+++ b/engines/sci/graphics/video32.h
@@ -191,7 +191,9 @@ protected:
 	 */
 	const Graphics::Surface* _currentFrame;
 
-
+	/**
+	 * Video SRT subtitles used by fan translation projects for phantasmagoria 1 & 2.
+	 */
 	mutable Video::Subtitles _subtitles;
 
 #ifdef USE_RGB_COLOR




More information about the Scummvm-git-logs mailing list