[Scummvm-git-logs] scummvm master -> 3f611f9d511f094a98ec386951c6f9b727dde91f
sev-
noreply at scummvm.org
Fri Sep 23 09:05:17 UTC 2022
This automated email contains information about 18 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
b45599fdb2 VIDEO: Initial implementation of SRT parser
aafcce2a9a VIDEO: Sort SRT subtitles after loading
d9fdaa3fe1 VIDEO: Implemented subtitle retrieval for SRT subtitles
f555592e10 VIDEO: Fixed subtitle search method
d02ff2ea5a VIDEO: Renamed srt_parser.* to subtitles.*
bb42c9bda4 VIDEO: Started implementation of generic Subtitles class
5e05bacb1c GROOVIE: Initial plug in of subtitles to video player
8fa9f74d59 VIDEO: Fix crash on subtitles reload
9cb80bc9fb VIDEO: Load font for Subtitles
af8c37db9d VIDEO: Initial code for drawing subtitles on overlay
2ca793f720 VIDEO: Finished subtitle drawing implementation
7c18243c1c GROOVIE: Show subtitles during video playback
f255467bd3 VIDEO: Center subtitles on screen
57ba69d046 VIDEO: Switched to Unicode
dff6943cbf VIDEO: Render subtitles without antialiasing (less artifacts)
0a093d5e0a VIDEO: Attempt to fake font outline
a72b97097c VIDEO: With shadow we do not need to render monochrome anymore
3f611f9d51 VIDEO: Adapt subtitles overlay to text size
Commit: b45599fdb2e240832bc25165e97a381d9d91f14d
https://github.com/scummvm/scummvm/commit/b45599fdb2e240832bc25165e97a381d9d91f14d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Initial implementation of SRT parser
Changed paths:
A video/srt_parser.cpp
A video/srt_parser.h
video/module.mk
diff --git a/video/module.mk b/video/module.mk
index 797aab5b7ea..2fee0de0750 100644
--- a/video/module.mk
+++ b/video/module.mk
@@ -13,6 +13,7 @@ MODULE_OBJS := \
psx_decoder.o \
qt_decoder.o \
smk_decoder.o \
+ srt_parser.o \
video_decoder.o
ifdef USE_BINK
diff --git a/video/srt_parser.cpp b/video/srt_parser.cpp
new file mode 100644
index 00000000000..0c72ff79b43
--- /dev/null
+++ b/video/srt_parser.cpp
@@ -0,0 +1,175 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "common/file.h"
+
+#include "video/srt_parser.h"
+
+namespace Video {
+
+SRTParser::SRTParser() {
+}
+
+SRTParser::~SRTParser() {
+}
+
+bool parseTime(const char **pptr, uint32 *res) {
+ int hours, mins, secs, msecs;
+ const char *ptr = *pptr;
+
+ hours = (*ptr++ - '0') * 10;
+ hours += *ptr++ - '0';
+
+ if (hours > 24 || hours < 0)
+ return false;
+
+ if (*ptr++ != ':')
+ return false;
+
+ mins = (*ptr++ - '0') * 10;
+ mins += *ptr++ - '0';
+
+ if (mins > 60 || mins < 0)
+ return false;
+
+ if (*ptr++ != ':')
+ return false;
+
+ secs = (*ptr++ - '0') * 10;
+ secs += *ptr++ - '0';
+
+ if (secs > 60 || secs < 0)
+ return false;
+
+ if (*ptr++ != ',')
+ return false;
+
+ msecs = (*ptr++ - '0') * 100;
+ msecs += (*ptr++ - '0') * 10;
+ msecs += *ptr++ - '0';
+
+ if (msecs > 1000 || msecs < 0)
+ return false;
+
+ *res = 1000 * (3600 * hours + 60 * mins + secs) + msecs;
+
+ *pptr = ptr;
+
+ return true;
+}
+
+
+bool SRTParser::parseFile(const char *fname) {
+ Common::File f;
+
+ if (!f.open(fname))
+ return false;
+
+ byte buf[3];
+ f.read(buf, 3);
+
+ int line = 0;
+
+ // Skip UTF header if present
+ if (buf[0] != 0xef || buf[1] != 0xbb || buf[2] != 0xbf)
+ f.seek(0);
+
+ while (!f.eos()) {
+ Common::String sseq, stimespec, stmp, text;
+
+ sseq = f.readLine(); line++;
+ stimespec = f.readLine(); line++;
+ text = f.readLine(); line++;
+
+ if (sseq.empty()) {
+ if (f.eos()) {
+ // Normal end of stream
+ break;
+ } else {
+ warning("Bad SRT file format (spec): %s at line %d", fname, line);
+ break;
+ }
+ }
+
+ if (stimespec.empty() || text.empty()) {
+ warning("Bad SRT file format (spec): %s at line %d", fname, line);
+ break;
+ }
+
+ // Read all multiline text
+ while (!f.eos()) {
+ stmp = f.readLine(); line++;
+
+ if (!stmp.empty()) {
+ text += '\n';
+ text += stmp;
+ } else {
+ break;
+ }
+ }
+
+ uint32 seq = atol(sseq.c_str());
+ if (seq == 0) {
+ warning("Bad SRT file format (seq): %s at line %d", fname, line);
+ break;
+ }
+
+ // 00:20:41,150 --> 00:20:45,109
+ if (stimespec.size() < 29) {
+ warning("Bad SRT file format (timespec length %d): %s at line %d", stimespec.size(), fname, line);
+ break;
+ }
+
+ const char *ptr = stimespec.c_str();
+ uint32 start, end;
+ if (!parseTime(&ptr, &start)) {
+ warning("Bad SRT file format (timespec start): %s at line %d", fname, line);
+ break;
+ }
+
+ while (*ptr == ' ')
+ ptr++;
+
+ while (*ptr == '-')
+ ptr++;
+
+ if (*ptr != '>') {
+ warning("Bad SRT file format (timespec middle ('%c')): %s at line %d", *ptr, fname, line);
+ break;
+ }
+
+ ptr++;
+
+ while (*ptr == ' ')
+ ptr++;
+
+ if (!parseTime(&ptr, &end)) {
+ warning("Bad SRT file format (timespec end): %s at line %d", fname, line);
+ break;
+ }
+
+ _entries.push_back(SRTEntry(seq, start, end, text));
+ }
+
+ return true;
+}
+
+} // End of namespace Video
diff --git a/video/srt_parser.h b/video/srt_parser.h
new file mode 100644
index 00000000000..6541cde9f1c
--- /dev/null
+++ b/video/srt_parser.h
@@ -0,0 +1,55 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef SRT_PARSER_H
+#define SRT_PARSER_H
+
+#include "common/str.h"
+#include "common/array.h"
+
+namespace Video {
+
+struct SRTEntry {
+ uint seq;
+ uint32 start;
+ uint32 end;
+
+ Common::String text;
+
+ SRTEntry(uint seq_, uint32 start_, uint32 end_, Common::String text_) {
+ seq = seq_; start = start_; end = end_; text = text_;
+ }
+};
+
+class SRTParser {
+public:
+ SRTParser();
+ ~SRTParser();
+
+ bool parseFile(const char *fname);
+
+private:
+ Common::Array<SRTEntry> _entries;
+};
+
+} // End of namespace Video
+
+#endif
Commit: aafcce2a9a0d32f101151774f665de5e2ec67c38
https://github.com/scummvm/scummvm/commit/aafcce2a9a0d32f101151774f665de5e2ec67c38
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Sort SRT subtitles after loading
Changed paths:
video/srt_parser.cpp
video/srt_parser.h
diff --git a/video/srt_parser.cpp b/video/srt_parser.cpp
index 0c72ff79b43..c313af3744d 100644
--- a/video/srt_parser.cpp
+++ b/video/srt_parser.cpp
@@ -29,6 +29,12 @@ SRTParser::SRTParser() {
}
SRTParser::~SRTParser() {
+ cleanup();
+}
+
+void SRTParser::cleanup() {
+ for (Common::Array<SRTEntry *>::const_iterator item = _entries.begin(); item != _entries.end(); ++item)
+ delete *item;
}
bool parseTime(const char **pptr, uint32 *res) {
@@ -76,6 +82,11 @@ bool parseTime(const char **pptr, uint32 *res) {
return true;
}
+struct SRTEntryComparator {
+ bool operator()(const SRTEntry *l, const SRTEntry *r) {
+ return (l->start < r->start);
+ }
+};
bool SRTParser::parseFile(const char *fname) {
Common::File f;
@@ -166,9 +177,11 @@ bool SRTParser::parseFile(const char *fname) {
break;
}
- _entries.push_back(SRTEntry(seq, start, end, text));
+ _entries.push_back(new SRTEntry(seq, start, end, text));
}
+ Common::sort(_entries.begin(), _entries.end(), SRTEntryComparator());
+
return true;
}
diff --git a/video/srt_parser.h b/video/srt_parser.h
index 6541cde9f1c..0d26ff154d8 100644
--- a/video/srt_parser.h
+++ b/video/srt_parser.h
@@ -44,10 +44,11 @@ public:
SRTParser();
~SRTParser();
+ void cleanup();
bool parseFile(const char *fname);
private:
- Common::Array<SRTEntry> _entries;
+ Common::Array<SRTEntry *> _entries;
};
} // End of namespace Video
Commit: d9fdaa3fe16db93657ee955e8483678f210af007
https://github.com/scummvm/scummvm/commit/d9fdaa3fe16db93657ee955e8483678f210af007
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Implemented subtitle retrieval for SRT subtitles
Changed paths:
video/srt_parser.cpp
video/srt_parser.h
diff --git a/video/srt_parser.cpp b/video/srt_parser.cpp
index c313af3744d..d8c67b5cf5d 100644
--- a/video/srt_parser.cpp
+++ b/video/srt_parser.cpp
@@ -82,11 +82,12 @@ bool parseTime(const char **pptr, uint32 *res) {
return true;
}
-struct SRTEntryComparator {
- bool operator()(const SRTEntry *l, const SRTEntry *r) {
- return (l->start < r->start);
- }
-};
+int SRTEntryComparator(const void *item1, const void *item2) {
+ const SRTEntry *l = *(const SRTEntry **)item1;
+ const SRTEntry *r = *(const SRTEntry **)item2;
+
+ return l->start - r->start;
+}
bool SRTParser::parseFile(const char *fname) {
Common::File f;
@@ -180,9 +181,20 @@ bool SRTParser::parseFile(const char *fname) {
_entries.push_back(new SRTEntry(seq, start, end, text));
}
- Common::sort(_entries.begin(), _entries.end(), SRTEntryComparator());
+ qsort(_entries.data(), _entries.size(), sizeof(SRTEntry *), &SRTEntryComparator);
return true;
}
+Common::String SRTParser::getSubtitle(uint32 timestamp) {
+ SRTEntry test(0, timestamp, 0, "");
+
+ const SRTEntry *entry = (const SRTEntry *)bsearch(&test, _entries.data(), _entries.size(), sizeof(SRTEntry *), &SRTEntryComparator);
+
+ if (entry->start >= timestamp && entry->end <= timestamp)
+ return entry->text;
+
+ return "";
+}
+
} // End of namespace Video
diff --git a/video/srt_parser.h b/video/srt_parser.h
index 0d26ff154d8..8ea5e6608c4 100644
--- a/video/srt_parser.h
+++ b/video/srt_parser.h
@@ -46,6 +46,7 @@ public:
void cleanup();
bool parseFile(const char *fname);
+ Common::String getSubtitle(uint32 timestamp);
private:
Common::Array<SRTEntry *> _entries;
Commit: f555592e10efc324c56c58629385fc1f4e880178
https://github.com/scummvm/scummvm/commit/f555592e10efc324c56c58629385fc1f4e880178
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Fixed subtitle search method
Changed paths:
video/srt_parser.cpp
diff --git a/video/srt_parser.cpp b/video/srt_parser.cpp
index d8c67b5cf5d..ce9268d7a44 100644
--- a/video/srt_parser.cpp
+++ b/video/srt_parser.cpp
@@ -89,6 +89,19 @@ int SRTEntryComparator(const void *item1, const void *item2) {
return l->start - r->start;
}
+int SRTEntryComparatorBSearch(const void *item1, const void *item2) {
+ const SRTEntry *k = *(const SRTEntry **)item1;
+ const SRTEntry *i = *(const SRTEntry **)item2;
+
+ if (k->start < i->start)
+ return -1;
+
+ if (k->start > i->end - 1)
+ return 1;
+
+ return 0;
+}
+
bool SRTParser::parseFile(const char *fname) {
Common::File f;
@@ -188,13 +201,14 @@ bool SRTParser::parseFile(const char *fname) {
Common::String SRTParser::getSubtitle(uint32 timestamp) {
SRTEntry test(0, timestamp, 0, "");
+ SRTEntry *testptr = &test;
- const SRTEntry *entry = (const SRTEntry *)bsearch(&test, _entries.data(), _entries.size(), sizeof(SRTEntry *), &SRTEntryComparator);
+ const SRTEntry **entry = (const SRTEntry **)bsearch(&testptr, _entries.data(), _entries.size(), sizeof(SRTEntry *), &SRTEntryComparatorBSearch);
- if (entry->start >= timestamp && entry->end <= timestamp)
- return entry->text;
+ if (entry == NULL)
+ return "";
- return "";
+ return (*entry)->text;
}
} // End of namespace Video
Commit: d02ff2ea5ae519cf39d5dd5df99747160e0f4d31
https://github.com/scummvm/scummvm/commit/d02ff2ea5ae519cf39d5dd5df99747160e0f4d31
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Renamed srt_parser.* to subtitles.*
Changed paths:
A video/subtitles.cpp
A video/subtitles.h
R video/srt_parser.cpp
R video/srt_parser.h
video/module.mk
diff --git a/video/module.mk b/video/module.mk
index 2fee0de0750..f9125f26b3b 100644
--- a/video/module.mk
+++ b/video/module.mk
@@ -13,7 +13,7 @@ MODULE_OBJS := \
psx_decoder.o \
qt_decoder.o \
smk_decoder.o \
- srt_parser.o \
+ subtitles.o \
video_decoder.o
ifdef USE_BINK
diff --git a/video/srt_parser.cpp b/video/subtitles.cpp
similarity index 99%
rename from video/srt_parser.cpp
rename to video/subtitles.cpp
index ce9268d7a44..8c8fe388900 100644
--- a/video/srt_parser.cpp
+++ b/video/subtitles.cpp
@@ -21,7 +21,7 @@
#include "common/file.h"
-#include "video/srt_parser.h"
+#include "video/subtitles.h"
namespace Video {
diff --git a/video/srt_parser.h b/video/subtitles.h
similarity index 100%
rename from video/srt_parser.h
rename to video/subtitles.h
Commit: bb42c9bda416a549e91f7175fd6ed20907261d2a
https://github.com/scummvm/scummvm/commit/bb42c9bda416a549e91f7175fd6ed20907261d2a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Started implementation of generic Subtitles class
Changed paths:
video/subtitles.cpp
video/subtitles.h
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index 8c8fe388900..f67b96c8d1c 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -19,6 +19,7 @@
*
*/
+#include "common/debug.h"
#include "common/file.h"
#include "video/subtitles.h"
@@ -105,6 +106,8 @@ int SRTEntryComparatorBSearch(const void *item1, const void *item2) {
bool SRTParser::parseFile(const char *fname) {
Common::File f;
+ cleanup();
+
if (!f.open(fname))
return false;
@@ -211,4 +214,16 @@ Common::String SRTParser::getSubtitle(uint32 timestamp) {
return (*entry)->text;
}
+Subtitles::Subtitles() : _loaded(false) {
+}
+
+Subtitles::~Subtitles() {
+}
+
+void Subtitles::loadSRTFile(const char *fname) {
+ debug(1, "loadSRTFile('%s')", fname);
+
+ _loaded = _srtParser.parseFile(fname);
+}
+
} // End of namespace Video
diff --git a/video/subtitles.h b/video/subtitles.h
index 8ea5e6608c4..000aa8d90b6 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -19,8 +19,8 @@
*
*/
-#ifndef SRT_PARSER_H
-#define SRT_PARSER_H
+#ifndef VIDEO_SUBTITLES_H
+#define VIDEO_SUBTITLES_H
#include "common/str.h"
#include "common/array.h"
@@ -52,6 +52,18 @@ private:
Common::Array<SRTEntry *> _entries;
};
+class Subtitles {
+public:
+ Subtitles();
+ ~Subtitles();
+
+ void loadSRTFile(const char *fname);
+
+private:
+ SRTParser _srtParser;
+ bool _loaded;
+};
+
} // End of namespace Video
#endif
Commit: 5e05bacb1cdcb20f46c67ab581bbceedcf3df19c
https://github.com/scummvm/scummvm/commit/5e05bacb1cdcb20f46c67ab581bbceedcf3df19c
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
GROOVIE: Initial plug in of subtitles to video player
Changed paths:
engines/groovie/script.cpp
engines/groovie/video/player.h
diff --git a/engines/groovie/script.cpp b/engines/groovie/script.cpp
index 259ba8431fd..58be183e8a5 100644
--- a/engines/groovie/script.cpp
+++ b/engines/groovie/script.cpp
@@ -950,6 +950,18 @@ bool Script::playvideofromref(uint32 fileref, bool loopUntilAudioDone) {
if (_version == kGroovieCDY && _scriptFile == "26a_graf.grv")
_bitflags |= 1;
_vm->_videoPlayer->load(_videoFile, _bitflags);
+
+ // Find correct filename
+ ResInfo info;
+ _vm->_resMan->getResInfo(fileref, info);
+
+ // Remove the extension and add ".txt"
+ info.filename.deleteLastChar();
+ info.filename.deleteLastChar();
+ info.filename.deleteLastChar();
+ info.filename += "txt";
+
+ _vm->_videoPlayer->loadSubtitles(info.filename.c_str());
} else {
error("Groovie::Script: Couldn't open file");
return true;
diff --git a/engines/groovie/video/player.h b/engines/groovie/video/player.h
index e5f74e1f96d..2f8c947de3f 100644
--- a/engines/groovie/video/player.h
+++ b/engines/groovie/video/player.h
@@ -23,6 +23,7 @@
#define GROOVIE_VIDEO_PLAYER_H
#include "common/system.h"
+#include "video/subtitles.h"
namespace Audio {
class QueuingAudioStream;
@@ -48,6 +49,8 @@ public:
virtual void copyfgtobg(uint8 arg) {}
void setOverrideSpeed(bool isOverride);
+ void loadSubtitles(const char *fname) { _subtitles.loadSRTFile(fname); }
+
protected:
// To be implemented by subclasses
virtual uint16 loadInternal() = 0;
@@ -71,6 +74,8 @@ private:
uint32 _lastFrameTime;
float _frameTimeDrift;
+ Video::Subtitles _subtitles;
+
protected:
void waitFrame();
};
Commit: 8fa9f74d5919ca70e4c9487bf6248360ee11d280
https://github.com/scummvm/scummvm/commit/8fa9f74d5919ca70e4c9487bf6248360ee11d280
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Fix crash on subtitles reload
Changed paths:
video/subtitles.cpp
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index f67b96c8d1c..f6710fa4231 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -36,6 +36,8 @@ SRTParser::~SRTParser() {
void SRTParser::cleanup() {
for (Common::Array<SRTEntry *>::const_iterator item = _entries.begin(); item != _entries.end(); ++item)
delete *item;
+
+ _entries.clear();
}
bool parseTime(const char **pptr, uint32 *res) {
@@ -199,6 +201,8 @@ bool SRTParser::parseFile(const char *fname) {
qsort(_entries.data(), _entries.size(), sizeof(SRTEntry *), &SRTEntryComparator);
+ debug(6, "SRTParser: Loaded %d entries", _entries.size());
+
return true;
}
Commit: 9cb80bc9fbd356cc4ac80e79ee0da82d98427568
https://github.com/scummvm/scummvm/commit/9cb80bc9fbd356cc4ac80e79ee0da82d98427568
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Load font for Subtitles
Changed paths:
video/subtitles.cpp
video/subtitles.h
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index f6710fa4231..e7e2698a2eb 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -22,6 +22,9 @@
#include "common/debug.h"
#include "common/file.h"
+#include "graphics/fonts/ttf.h"
+#include "graphics/fontman.h"
+
#include "video/subtitles.h"
namespace Video {
@@ -218,12 +221,32 @@ Common::String SRTParser::getSubtitle(uint32 timestamp) {
return (*entry)->text;
}
-Subtitles::Subtitles() : _loaded(false) {
+Subtitles::Subtitles() : _loaded(false), _font(nullptr) {
}
Subtitles::~Subtitles() {
}
+void Subtitles::loadFont(const char *fontname, int height) {
+ Common::File file;
+
+ _fontHeight = height;
+
+ if (!file.open(fontname)) {
+ _font = Graphics::loadTTFFont(file, _fontHeight, Graphics::kTTFSizeModeCharacter, 96);
+ }
+
+ if (!_font)
+ _font = FontMan.getFontByName(fontname);
+
+ if (!_font) {
+ warning("Cannot load font %s", fontname);
+
+ _font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
+ }
+
+}
+
void Subtitles::loadSRTFile(const char *fname) {
debug(1, "loadSRTFile('%s')", fname);
diff --git a/video/subtitles.h b/video/subtitles.h
index 000aa8d90b6..e47c1fdd009 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -25,6 +25,10 @@
#include "common/str.h"
#include "common/array.h"
+namespace Graphics {
+class Font;
+}
+
namespace Video {
struct SRTEntry {
@@ -58,10 +62,14 @@ public:
~Subtitles();
void loadSRTFile(const char *fname);
+ void loadFont(const char *fontname, int height = 30);
private:
SRTParser _srtParser;
bool _loaded;
+
+ const Graphics::Font *_font;
+ int _fontHeight;
};
} // End of namespace Video
Commit: af8c37db9d7c619cb03dbea3b5b619fdec0452c4
https://github.com/scummvm/scummvm/commit/af8c37db9d7c619cb03dbea3b5b619fdec0452c4
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Initial code for drawing subtitles on overlay
Changed paths:
video/subtitles.cpp
video/subtitles.h
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index e7e2698a2eb..aebbe356938 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -21,9 +21,12 @@
#include "common/debug.h"
#include "common/file.h"
+#include "common/system.h"
#include "graphics/fonts/ttf.h"
+#include "graphics/font.h"
#include "graphics/fontman.h"
+#include "graphics/surface.h"
#include "video/subtitles.h"
@@ -222,9 +225,11 @@ Common::String SRTParser::getSubtitle(uint32 timestamp) {
}
Subtitles::Subtitles() : _loaded(false), _font(nullptr) {
+ _surface = new Graphics::Surface();
}
Subtitles::~Subtitles() {
+ delete _surface;
}
void Subtitles::loadFont(const char *fontname, int height) {
@@ -253,4 +258,37 @@ void Subtitles::loadSRTFile(const char *fname) {
_loaded = _srtParser.parseFile(fname);
}
+void Subtitles::setBBox(const Common::Rect bbox) {
+ _bbox = bbox;
+
+ _surface->create(_bbox.width(), _bbox.height(), g_system->getOverlayFormat());
+}
+
+
+void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
+ if (!_loaded)
+ return;
+
+ Common::String subtitle = _srtParser.getSubtitle(timestamp);
+
+ if (!force && subtitle == _prevSubtitle)
+ return;
+
+ _prevSubtitle = subtitle;
+
+ Common::Array<Common::String> lines;
+
+ int maxlineWidth = _font->wordWrapText(subtitle, _bbox.width(), lines);
+
+ int y = _bbox.top;
+
+ for (int i = 0; i < lines.size(); i++) {
+ _font->drawString(_surface, lines[i], _bbox.left, y, _bbox.width(), _color);
+
+ y += _font->getFontHeight();
+ }
+
+ g_system->copyRectToOverlay(_surface->getPixels(), _surface->pitch, _bbox.left, _bbox.right, _bbox.width(), _bbox.height());
+}
+
} // End of namespace Video
diff --git a/video/subtitles.h b/video/subtitles.h
index e47c1fdd009..134843d4291 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -24,9 +24,11 @@
#include "common/str.h"
#include "common/array.h"
+#include "common/rect.h"
namespace Graphics {
class Font;
+struct Surface;
}
namespace Video {
@@ -63,6 +65,9 @@ public:
void loadSRTFile(const char *fname);
void loadFont(const char *fontname, int height = 30);
+ void setBBox(const Common::Rect bbox);
+ void setColor(int color) { _color = color; }
+ void drawSubtitle(uint32 timestamp, bool force = false);
private:
SRTParser _srtParser;
@@ -70,6 +75,14 @@ private:
const Graphics::Font *_font;
int _fontHeight;
+
+ Graphics::Surface *_surface;
+
+ Common::Rect _bbox;
+ Common::Rect _dirtyRect;
+
+ Common::String _prevSubtitle;
+ uint32 _color;
};
} // End of namespace Video
Commit: 2ca793f720cd6728c4a2e4cce7c977b78b70e47a
https://github.com/scummvm/scummvm/commit/2ca793f720cd6728c4a2e4cce7c977b78b70e47a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Finished subtitle drawing implementation
Changed paths:
video/subtitles.cpp
video/subtitles.h
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index aebbe356938..973a1b96ba3 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -92,15 +92,15 @@ bool parseTime(const char **pptr, uint32 *res) {
}
int SRTEntryComparator(const void *item1, const void *item2) {
- const SRTEntry *l = *(const SRTEntry **)item1;
- const SRTEntry *r = *(const SRTEntry **)item2;
+ const SRTEntry *l = *(const SRTEntry * const *)item1;
+ const SRTEntry *r = *(const SRTEntry * const *)item2;
return l->start - r->start;
}
int SRTEntryComparatorBSearch(const void *item1, const void *item2) {
- const SRTEntry *k = *(const SRTEntry **)item1;
- const SRTEntry *i = *(const SRTEntry **)item2;
+ const SRTEntry *k = *(const SRTEntry * const *)item1;
+ const SRTEntry *i = *(const SRTEntry * const *)item2;
if (k->start < i->start)
return -1;
@@ -232,17 +232,19 @@ Subtitles::~Subtitles() {
delete _surface;
}
-void Subtitles::loadFont(const char *fontname, int height) {
+void Subtitles::setFont(const char *fontname, int height) {
Common::File file;
_fontHeight = height;
- if (!file.open(fontname)) {
+ if (file.open(fontname)) {
_font = Graphics::loadTTFFont(file, _fontHeight, Graphics::kTTFSizeModeCharacter, 96);
}
- if (!_font)
+ if (!_font) {
+ warning("Cannot load font %s directly", fontname);
_font = FontMan.getFontByName(fontname);
+ }
if (!_font) {
warning("Cannot load font %s", fontname);
@@ -264,6 +266,10 @@ void Subtitles::setBBox(const Common::Rect bbox) {
_surface->create(_bbox.width(), _bbox.height(), g_system->getOverlayFormat());
}
+void Subtitles::setColor(byte r, byte g, byte b) {
+ _color = _surface->format.ARGBToColor(255, r, g, b);
+ _transparentColor = _surface->format.ARGBToColor(0, 0, 0, 0);
+}
void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
if (!_loaded)
@@ -274,21 +280,29 @@ void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
if (!force && subtitle == _prevSubtitle)
return;
+ debug(1, "%d: %s", timestamp, subtitle.c_str());
+
+ _surface->fillRect(Common::Rect(0, 0, _surface->w, _surface->h), _transparentColor);
+
_prevSubtitle = subtitle;
Common::Array<Common::String> lines;
- int maxlineWidth = _font->wordWrapText(subtitle, _bbox.width(), lines);
+ _font->wordWrapText(subtitle, _bbox.width(), lines);
- int y = _bbox.top;
+ int y = 0;
for (int i = 0; i < lines.size(); i++) {
- _font->drawString(_surface, lines[i], _bbox.left, y, _bbox.width(), _color);
+ _font->drawString(_surface, lines[i], 0, y, _bbox.width(), _color);
y += _font->getFontHeight();
+
+ if (y > _bbox.bottom)
+ break;
}
- g_system->copyRectToOverlay(_surface->getPixels(), _surface->pitch, _bbox.left, _bbox.right, _bbox.width(), _bbox.height());
+ g_system->copyRectToOverlay(_surface->getPixels(), _surface->pitch, _bbox.left, _bbox.top, _bbox.width(), _bbox.height());
+ g_system->updateScreen();
}
} // End of namespace Video
diff --git a/video/subtitles.h b/video/subtitles.h
index 134843d4291..49101994cae 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -64,9 +64,9 @@ public:
~Subtitles();
void loadSRTFile(const char *fname);
- void loadFont(const char *fontname, int height = 30);
+ void setFont(const char *fontname, int height = 18);
void setBBox(const Common::Rect bbox);
- void setColor(int color) { _color = color; }
+ void setColor(byte r, byte g, byte b);
void drawSubtitle(uint32 timestamp, bool force = false);
private:
@@ -83,6 +83,7 @@ private:
Common::String _prevSubtitle;
uint32 _color;
+ uint32 _transparentColor;
};
} // End of namespace Video
Commit: 7c18243c1cba74989eaaeb8dc600467852a86f40
https://github.com/scummvm/scummvm/commit/7c18243c1cba74989eaaeb8dc600467852a86f40
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
GROOVIE: Show subtitles during video playback
Changed paths:
engines/groovie/video/player.cpp
diff --git a/engines/groovie/video/player.cpp b/engines/groovie/video/player.cpp
index 230b89a25d6..4404c8de8a8 100644
--- a/engines/groovie/video/player.cpp
+++ b/engines/groovie/video/player.cpp
@@ -32,6 +32,12 @@ namespace Groovie {
VideoPlayer::VideoPlayer(GroovieEngine *vm) :
_vm(vm), _syst(vm->_system), _file(nullptr), _audioStream(nullptr), _fps(0), _overrideSpeed(false), _flags(0),
_begunPlaying(false), _millisBetweenFrames(0), _lastFrameTime(0), _frameTimeDrift(0) {
+
+ int16 h = g_system->getOverlayHeight();
+
+ _subtitles.setBBox(Common::Rect(20, h - 120, g_system->getOverlayWidth() - 20, h - 20));
+ _subtitles.setColor(0xff, 0xff, 0xff);
+ _subtitles.setFont("FreeSans.ttf");
}
bool VideoPlayer::load(Common::SeekableReadStream *file, uint16 flags) {
@@ -80,6 +86,9 @@ bool VideoPlayer::playFrame() {
end = playFrameInternal();
}
+ uint32 currTime = _syst->getMillis();
+ _subtitles.drawSubtitle(currTime - _frameTimeDrift);
+
// The file has been completely processed
if (end) {
_file = nullptr;
@@ -95,6 +104,8 @@ bool VideoPlayer::playFrame() {
end = false;
}
}
+
+ g_system->hideOverlay();
}
return end;
@@ -109,12 +120,15 @@ void VideoPlayer::waitFrame() {
_begunPlaying = true;
_lastFrameTime = currTime;
_frameTimeDrift = 0.0f;
+
+ g_system->showOverlay();
+ g_system->clearOverlay();
} else {
uint32 millisDiff = currTime - _lastFrameTime;
float fMillis = _millisBetweenFrames + _frameTimeDrift;
// use floorf instead of roundf, because delayMillis often slightly over-sleeps
uint32 millisSleep = fmaxf(0.0f, floorf(fMillis) - float(millisDiff));
-
+
if (millisSleep > 0) {
debugC(7, kDebugVideo, "Groovie::Player: Delaying %d (currTime=%d, _lastFrameTime=%d, millisDiff=%d, _millisBetweenFrame=%.2f, _frameTimeDrift=%.2f)",
millisSleep, currTime, _lastFrameTime, millisDiff, _millisBetweenFrames, _frameTimeDrift);
Commit: f255467bd3cc304ec12d8f7a6c9c835dd63c14e3
https://github.com/scummvm/scummvm/commit/f255467bd3cc304ec12d8f7a6c9c835dd63c14e3
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Center subtitles on screen
Changed paths:
video/subtitles.cpp
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index 973a1b96ba3..2a2c4945523 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -293,7 +293,7 @@ void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
int y = 0;
for (int i = 0; i < lines.size(); i++) {
- _font->drawString(_surface, lines[i], 0, y, _bbox.width(), _color);
+ _font->drawString(_surface, lines[i], 0, y, _bbox.width(), _color, Graphics::kTextAlignCenter);
y += _font->getFontHeight();
Commit: 57ba69d046063239f80ad07599ab8f95088ea88e
https://github.com/scummvm/scummvm/commit/57ba69d046063239f80ad07599ab8f95088ea88e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Switched to Unicode
Changed paths:
video/subtitles.cpp
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index 2a2c4945523..9c5c3863731 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -22,6 +22,7 @@
#include "common/debug.h"
#include "common/file.h"
#include "common/system.h"
+#include "common/ustr.h"
#include "graphics/fonts/ttf.h"
#include "graphics/font.h"
@@ -286,9 +287,9 @@ void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
_prevSubtitle = subtitle;
- Common::Array<Common::String> lines;
+ Common::Array<Common::U32String> lines;
- _font->wordWrapText(subtitle, _bbox.width(), lines);
+ _font->wordWrapText(convertUtf8ToUtf32(subtitle), _bbox.width(), lines);
int y = 0;
Commit: dff6943cbfe52bbdab0ffb651101a6c30456aba3
https://github.com/scummvm/scummvm/commit/dff6943cbfe52bbdab0ffb651101a6c30456aba3
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Render subtitles without antialiasing (less artifacts)
Changed paths:
video/subtitles.cpp
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index 9c5c3863731..63ea74e4fec 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -239,7 +239,7 @@ void Subtitles::setFont(const char *fontname, int height) {
_fontHeight = height;
if (file.open(fontname)) {
- _font = Graphics::loadTTFFont(file, _fontHeight, Graphics::kTTFSizeModeCharacter, 96);
+ _font = Graphics::loadTTFFont(file, _fontHeight, Graphics::kTTFSizeModeCharacter, 96, Graphics::kTTFRenderModeMonochrome);
}
if (!_font) {
Commit: 0a093d5e0ab5cad9c845c35bfe8b5dad47c7028b
https://github.com/scummvm/scummvm/commit/0a093d5e0ab5cad9c845c35bfe8b5dad47c7028b
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Attempt to fake font outline
Changed paths:
video/subtitles.cpp
video/subtitles.h
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index 63ea74e4fec..f0a4603cede 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -225,6 +225,8 @@ Common::String SRTParser::getSubtitle(uint32 timestamp) {
return (*entry)->text;
}
+#define SHADOW 2
+
Subtitles::Subtitles() : _loaded(false), _font(nullptr) {
_surface = new Graphics::Surface();
}
@@ -264,11 +266,12 @@ void Subtitles::loadSRTFile(const char *fname) {
void Subtitles::setBBox(const Common::Rect bbox) {
_bbox = bbox;
- _surface->create(_bbox.width(), _bbox.height(), g_system->getOverlayFormat());
+ _surface->create(_bbox.width() + SHADOW * 2, _bbox.height() + SHADOW * 2, g_system->getOverlayFormat());
}
void Subtitles::setColor(byte r, byte g, byte b) {
_color = _surface->format.ARGBToColor(255, r, g, b);
+ _blackColor = _surface->format.ARGBToColor(255, 0, 0, 0);
_transparentColor = _surface->format.ARGBToColor(0, 0, 0, 0);
}
@@ -294,7 +297,12 @@ void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
int y = 0;
for (int i = 0; i < lines.size(); i++) {
- _font->drawString(_surface, lines[i], 0, y, _bbox.width(), _color, Graphics::kTextAlignCenter);
+ _font->drawString(_surface, lines[i], 0, y, _bbox.width(), _blackColor, Graphics::kTextAlignCenter);
+ _font->drawString(_surface, lines[i], SHADOW * 2, y, _bbox.width(), _blackColor, Graphics::kTextAlignCenter);
+ _font->drawString(_surface, lines[i], 0, y + SHADOW * 2, _bbox.width(), _blackColor, Graphics::kTextAlignCenter);
+ _font->drawString(_surface, lines[i], SHADOW * 2, y + SHADOW * 2, _bbox.width(), _blackColor, Graphics::kTextAlignCenter);
+
+ _font->drawString(_surface, lines[i], SHADOW, y + SHADOW, _bbox.width(), _color, Graphics::kTextAlignCenter);
y += _font->getFontHeight();
diff --git a/video/subtitles.h b/video/subtitles.h
index 49101994cae..b2a6c684dcf 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -83,6 +83,7 @@ private:
Common::String _prevSubtitle;
uint32 _color;
+ uint32 _blackColor;
uint32 _transparentColor;
};
Commit: a72b97097cede8104df91c5c4c1dc6b1367bc537
https://github.com/scummvm/scummvm/commit/a72b97097cede8104df91c5c4c1dc6b1367bc537
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: With shadow we do not need to render monochrome anymore
Changed paths:
video/subtitles.cpp
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index f0a4603cede..57f609ec334 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -225,7 +225,7 @@ Common::String SRTParser::getSubtitle(uint32 timestamp) {
return (*entry)->text;
}
-#define SHADOW 2
+#define SHADOW 1
Subtitles::Subtitles() : _loaded(false), _font(nullptr) {
_surface = new Graphics::Surface();
@@ -241,7 +241,7 @@ void Subtitles::setFont(const char *fontname, int height) {
_fontHeight = height;
if (file.open(fontname)) {
- _font = Graphics::loadTTFFont(file, _fontHeight, Graphics::kTTFSizeModeCharacter, 96, Graphics::kTTFRenderModeMonochrome);
+ _font = Graphics::loadTTFFont(file, _fontHeight, Graphics::kTTFSizeModeCharacter, 96);
}
if (!_font) {
Commit: 3f611f9d511f094a98ec386951c6f9b727dde91f
https://github.com/scummvm/scummvm/commit/3f611f9d511f094a98ec386951c6f9b727dde91f
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2022-09-23T11:05:01+02:00
Commit Message:
VIDEO: Adapt subtitles overlay to text size
Changed paths:
video/subtitles.cpp
video/subtitles.h
diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index 57f609ec334..ace0284bd0c 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -227,7 +227,7 @@ Common::String SRTParser::getSubtitle(uint32 timestamp) {
#define SHADOW 1
-Subtitles::Subtitles() : _loaded(false), _font(nullptr) {
+Subtitles::Subtitles() : _loaded(false), _font(nullptr), _hPad(0), _vPad(0) {
_surface = new Graphics::Surface();
}
@@ -275,6 +275,11 @@ void Subtitles::setColor(byte r, byte g, byte b) {
_transparentColor = _surface->format.ARGBToColor(0, 0, 0, 0);
}
+void Subtitles::setPadding(uint16 horizontal, uint16 vertical) {
+ _hPad = horizontal;
+ _vPad = vertical;
+}
+
void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
if (!_loaded)
return;
@@ -294,23 +299,33 @@ void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
_font->wordWrapText(convertUtf8ToUtf32(subtitle), _bbox.width(), lines);
- int y = 0;
+ if (lines.empty())
+ return;
+
+ int height = _vPad;
+
+ int width = 0;
+ for (uint i = 0; i < lines.size(); i++)
+ width = MAX(_font->getStringWidth(lines[i]), width);
+ width = MIN(width + 2 * _hPad, (int)_bbox.width());
- for (int i = 0; i < lines.size(); i++) {
- _font->drawString(_surface, lines[i], 0, y, _bbox.width(), _blackColor, Graphics::kTextAlignCenter);
- _font->drawString(_surface, lines[i], SHADOW * 2, y, _bbox.width(), _blackColor, Graphics::kTextAlignCenter);
- _font->drawString(_surface, lines[i], 0, y + SHADOW * 2, _bbox.width(), _blackColor, Graphics::kTextAlignCenter);
- _font->drawString(_surface, lines[i], SHADOW * 2, y + SHADOW * 2, _bbox.width(), _blackColor, Graphics::kTextAlignCenter);
+ for (uint i = 0; i < lines.size(); i++) {
+ _font->drawString(_surface, lines[i], 0, height, width, _blackColor, Graphics::kTextAlignCenter);
+ _font->drawString(_surface, lines[i], SHADOW * 2, height, width, _blackColor, Graphics::kTextAlignCenter);
+ _font->drawString(_surface, lines[i], 0, height + SHADOW * 2, width, _blackColor, Graphics::kTextAlignCenter);
+ _font->drawString(_surface, lines[i], SHADOW * 2, height + SHADOW * 2, width, _blackColor, Graphics::kTextAlignCenter);
- _font->drawString(_surface, lines[i], SHADOW, y + SHADOW, _bbox.width(), _color, Graphics::kTextAlignCenter);
+ _font->drawString(_surface, lines[i], SHADOW, height + SHADOW, width, _color, Graphics::kTextAlignCenter);
- y += _font->getFontHeight();
+ height += _font->getFontHeight();
- if (y > _bbox.bottom)
+ if (height + _vPad > _bbox.bottom)
break;
}
- g_system->copyRectToOverlay(_surface->getPixels(), _surface->pitch, _bbox.left, _bbox.top, _bbox.width(), _bbox.height());
+ height += _vPad;
+
+ g_system->copyRectToOverlay(_surface->getPixels(), _surface->pitch, _bbox.left + (_bbox.width() - width) / 2, _bbox.top, width + SHADOW * 2, height + SHADOW * 2);
g_system->updateScreen();
}
diff --git a/video/subtitles.h b/video/subtitles.h
index b2a6c684dcf..0e5cdf95635 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -67,6 +67,7 @@ public:
void setFont(const char *fontname, int height = 18);
void setBBox(const Common::Rect bbox);
void setColor(byte r, byte g, byte b);
+ void setPadding(uint16 horizontal, uint16 vertical);
void drawSubtitle(uint32 timestamp, bool force = false);
private:
@@ -85,6 +86,8 @@ private:
uint32 _color;
uint32 _blackColor;
uint32 _transparentColor;
+ uint16 _hPad;
+ uint16 _vPad;
};
} // End of namespace Video
More information about the Scummvm-git-logs
mailing list