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

sev- sev at scummvm.org
Mon Nov 18 02:02:27 CET 2019


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

Summary:
83285746b0 TOON: add support for cutscene subtitles
b6ff8f77b7 fix always true condition
f7e039d3c2 TOON: fix strings without null termination
ff039617bb TOON: formatting
d08027ae1f TOON: simplify method to pick subtitles color
2a21ef0bb6 TOON: order imports
656246d50d TOON: typedef not needed
a81b47633e TOON: comment out non-warning
a2a4278c0f TOON: support SUBTITLES.PAK
e87e18052c TOON:  fix types + remove unused import
32b9b7226c TOON: plaintext format for subtitles
47462e9810 TOON: formatting
d30ee1df37 TOON: add create subtitles tools
21be04a332 TOON: remove assertion and unused import
c130cb0748 TOON: ignore extension check


Commit: 83285746b0cbaa7223592fa008af22b31484e0d6
    https://github.com/scummvm/scummvm/commit/83285746b0cbaa7223592fa008af22b31484e0d6
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: add support for cutscene subtitles

Changed paths:
  A engines/toon/subtitles.cpp
  A engines/toon/subtitles.h
    engines/toon/font.cpp
    engines/toon/font.h
    engines/toon/module.mk
    engines/toon/movie.cpp
    engines/toon/movie.h
    engines/toon/toon.cpp
    engines/toon/toon.h


diff --git a/engines/toon/font.cpp b/engines/toon/font.cpp
index 9b08e43..29dbf40 100644
--- a/engines/toon/font.cpp
+++ b/engines/toon/font.cpp
@@ -191,7 +191,7 @@ void FontRenderer::setFontColor(int32 fontColor1, int32 fontColor2, int32 fontCo
 	_currentFontColor[3] = fontColor3;
 }
 
-void FontRenderer::renderMultiLineText(int16 x, int16 y, const Common::String &origText, int32 mode) {
+void FontRenderer::renderMultiLineText(int16 x, int16 y, const Common::String &origText, int32 mode, Graphics::Surface& frame) {
 	debugC(5, kDebugFont, "renderMultiLineText(%d, %d, %s, %d)", x, y, origText.c_str(), mode);
 
 	// divide the text in several lines
@@ -289,7 +289,7 @@ void FontRenderer::renderMultiLineText(int16 x, int16 y, const Common::String &o
 
 		while (*line) {
 			byte curChar = textToFont(*line);
-			if (curChar != 32) _currentFont->drawFontFrame(_vm->getMainSurface(), curChar, curX + _vm->state()->_currentScrollValue, curY, _currentFontColor);
+			if (curChar != 32) _currentFont->drawFontFrame(frame, curChar, curX + _vm->state()->_currentScrollValue, curY, _currentFontColor);
 			curX = curX + MAX<int32>(_currentFont->getFrameWidth(curChar) - 2, 0);
 			//height = MAX(height, _currentFont->getFrameHeight(curChar));
 			line++;
diff --git a/engines/toon/font.h b/engines/toon/font.h
index bbbccd0..48d4b85 100644
--- a/engines/toon/font.h
+++ b/engines/toon/font.h
@@ -35,7 +35,7 @@ public:
 	void setFont(Animation *font);
 	void computeSize(const Common::String &origText, int16 *retX, int16 *retY);
 	void renderText(int16 x, int16 y, const Common::String &origText, int32 mode);
-	void renderMultiLineText(int16 x, int16 y, const Common::String &origText, int32 mode);
+	void renderMultiLineText(int16 x, int16 y, const Common::String &origText, int32 mode, Graphics::Surface& frame);
 	void setFontColorByCharacter(int32 characterId);
 	void setFontColor(int32 fontColor1, int32 fontColor2, int32 fontColor3);
 protected:
diff --git a/engines/toon/module.mk b/engines/toon/module.mk
index 7796203..411b8e7 100644
--- a/engines/toon/module.mk
+++ b/engines/toon/module.mk
@@ -20,7 +20,8 @@ MODULE_OBJS := \
 	state.o \
 	text.o \
 	tools.o \
-	toon.o
+	toon.o \
+	subtitles.o
 
 # This module can be built as a plugin
 ifeq ($(ENABLE_TOON), DYNAMIC_PLUGIN)
diff --git a/engines/toon/movie.cpp b/engines/toon/movie.cpp
index 498e402..634135d 100644
--- a/engines/toon/movie.cpp
+++ b/engines/toon/movie.cpp
@@ -31,6 +31,7 @@
 #include "toon/audio.h"
 #include "toon/movie.h"
 #include "toon/toon.h"
+#include "toon/subtitles.h"
 
 namespace Toon {
 
@@ -67,6 +68,7 @@ Movie::Movie(ToonEngine *vm , ToonstruckSmackerDecoder *decoder) {
 	_vm = vm;
 	_playing = false;
 	_decoder = decoder;
+	_subtitle = new SubtitleRenderer(_vm);
 }
 
 Movie::~Movie() {
@@ -87,6 +89,7 @@ void Movie::play(const Common::String &video, int32 flags) {
 		_vm->getAudioManager()->setMusicVolume(0);
 	if (!_decoder->loadFile(video.c_str()))
 		error("Unable to play video %s", video.c_str());
+	_subtitle->load(video.c_str());
 	playVideo(isFirstIntroVideo);
 	_vm->flushPalette(true);
 	if (flags & 1)
@@ -103,6 +106,7 @@ void Movie::playVideo(bool isFirstIntroVideo) {
 	while (!_vm->shouldQuit() && !_decoder->endOfVideo()) {
 		if (_decoder->needsUpdate()) {
 			const Graphics::Surface *frame = _decoder->decodeNextFrame();
+			byte unused = 0;
 			if (frame) {
 				if (_decoder->isLowRes()) {
 					// handle manually 2x scaling here
@@ -115,9 +119,31 @@ void Movie::playVideo(bool isFirstIntroVideo) {
 				} else {
 					_vm->_system->copyRectToScreen(frame->getPixels(), frame->pitch, 0, 0, frame->w, frame->h);
 
+    				int32 currentFrame = _decoder->getCurFrame();
+
+					int len = frame->w * frame->h;
+					byte pixels[310000] = {0};
+					memcpy(pixels, frame->getPixels(), len);
+					for (byte i = 1; i < 256; i++) 
+					{
+						int j;
+						for (j = 0; j < len; j++) {
+							if (pixels[j] == i) {
+								break; 
+							}
+						}
+				
+						if (j == len && i != 255) {
+							unused = i;
+							break;
+						}
+					}
+
+					_subtitle->render(*frame, currentFrame, unused);
+
 					// WORKAROUND: There is an encoding glitch in the first intro video. This hides this using the adjacent pixels.
 					if (isFirstIntroVideo) {
-						int32 currentFrame = _decoder->getCurFrame();
+						// int32 currentFrame = _decoder->getCurFrame();
 						if (currentFrame >= 956 && currentFrame <= 1038) {
 							debugC(1, kDebugMovie, "Triggered workaround for glitch in first intro video...");
 							_vm->_system->copyRectToScreen(frame->getBasePtr(frame->w-188, 123), frame->pitch, frame->w-188, 124, 188, 1);
@@ -128,7 +154,17 @@ void Movie::playVideo(bool isFirstIntroVideo) {
 					}
 				}
 			}
-			_vm->_system->getPaletteManager()->setPalette(_decoder->getPalette(), 0, 256);
+
+			byte palette[768] = {0};
+			memcpy(palette, _decoder->getPalette(), 768);
+
+			if (unused) {
+				palette[3 * unused] = 0xff;
+				palette[3 * unused + 1] = 0xff;
+				palette[3 * unused + 2] = 0x0;
+			}
+
+			_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
 			_vm->_system->updateScreen();
 		}
 
diff --git a/engines/toon/movie.h b/engines/toon/movie.h
index 54d4fd4..4bbd0a9 100644
--- a/engines/toon/movie.h
+++ b/engines/toon/movie.h
@@ -28,6 +28,8 @@
 
 namespace Toon {
 
+class SubtitleRenderer;
+
 class ToonstruckSmackerDecoder : public Video::SmackerDecoder {
 public:
 	ToonstruckSmackerDecoder();
@@ -57,6 +59,7 @@ protected:
 	ToonEngine *_vm;
 	ToonstruckSmackerDecoder *_decoder;
 	bool _playing;
+	SubtitleRenderer *_subtitle;
 };
 
 } // End of namespace Toon
diff --git a/engines/toon/subtitles.cpp b/engines/toon/subtitles.cpp
new file mode 100644
index 0000000..1349778
--- /dev/null
+++ b/engines/toon/subtitles.cpp
@@ -0,0 +1,97 @@
+/* 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.
+ *
+ */
+
+#include "common/debug.h"
+#include "common/rect.h"
+#include "common/system.h"
+
+#include "toon/subtitles.h"
+
+namespace Toon {
+SubtitleRenderer::SubtitleRenderer(ToonEngine *vm) : _vm(vm) {
+    _subSurface = new Graphics::Surface();
+	_subSurface->create(TOON_SCREEN_WIDTH, TOON_SCREEN_HEIGHT, Graphics::PixelFormat::createFormatCLUT8());
+    _hasSubtitles = false;
+}
+
+SubtitleRenderer::~SubtitleRenderer() {
+}
+
+
+void SubtitleRenderer::render(const Graphics::Surface& frame, uint32 frameNumber, char color) {
+    if (!_hasSubtitles || _index > _last) {
+        return;
+    }
+
+    _subSurface->copyFrom(frame);
+    // char strf[384] = {0};
+    // sprintf(strf, "Time passed: %d", frameNumber);
+    // _vm->drawCostumeLine(0, 0, strf, _subSurface);
+    // _vm->_system->copyRectToScreen(_subSurface->getBasePtr(0, 0), _subSurface->pitch, 0, 0, _subSurface->w,  _subSurface->h);
+
+    if (frameNumber > _tw[_index].fend) {
+        _index++;
+        if (_index > _last) {
+            return;
+        }
+        _currentLine = (char*)_fileData + _tw[_index].foffset;
+    }
+
+    if (frameNumber < _tw[_index].fstart) {
+        return;
+    }
+
+    _vm->drawCustomText(TOON_SCREEN_WIDTH / 2, TOON_SCREEN_HEIGHT, _currentLine, _subSurface, color);
+    _vm->_system->copyRectToScreen(_subSurface->getBasePtr(0, 0), _subSurface->pitch, 0, 0, _subSurface->w,  _subSurface->h);
+}
+
+bool SubtitleRenderer::load(const Common::String &video) {
+    warning(video.c_str());
+
+    _hasSubtitles = false;
+    _index = 0;
+
+    char srtfile[20] = {0};
+    strcpy(srtfile, video.c_str());
+    int ln = strlen(srtfile);
+    srtfile[ln - 3] = 't';
+    srtfile[ln - 2] = 's';
+    srtfile[ln - 1] = 's';
+
+    uint32 fileSize = 0;
+	uint8 *fileData = _vm->resources()->getFileData(srtfile, &fileSize);
+	if (!fileData) {
+	 	return false;
+    }
+
+    uint32 numOflines = *((uint32*) fileData);
+    uint32 idx_size = numOflines * sizeof(TimeWindow);
+    memcpy(_tw, sizeof(numOflines) + fileData, idx_size);
+    _fileData = sizeof(numOflines) + fileData + idx_size;
+    _last = numOflines - 1;
+
+    _currentLine = (char*)_fileData + _tw[0].foffset;
+    _hasSubtitles = true;
+    return _hasSubtitles;
+}
+
+}
\ No newline at end of file
diff --git a/engines/toon/subtitles.h b/engines/toon/subtitles.h
new file mode 100644
index 0000000..7eb7fe1
--- /dev/null
+++ b/engines/toon/subtitles.h
@@ -0,0 +1,59 @@
+/* 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.
+ *
+ */
+
+#ifndef TOON_SUBTITLES_H
+#define TOON_SUBTITLES_H
+
+#include "toon/toon.h"
+#include "graphics/surface.h"
+
+namespace Toon {
+
+typedef struct {
+    uint32 fstart;
+    uint32 fend;
+    uint32 foffset;
+} TimeWindow;
+
+class SubtitleRenderer {
+public:
+	SubtitleRenderer(ToonEngine *vm);
+	~SubtitleRenderer();
+
+    bool load(const Common::String &video);
+    void render(const Graphics::Surface& frame, uint32 frameNumber, char color);
+protected:
+	ToonEngine *_vm;
+    Graphics::Surface* _subSurface;
+    bool _hasSubtitles;
+
+    char* _lines[384];
+    TimeWindow _tw[384];
+    uint8 *_fileData;
+    uint16 _index;
+    uint16 _last;
+    char* _currentLine;
+};
+
+} // End of namespace Toon
+
+#endif
\ No newline at end of file
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 46132a4..4d2578e 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -3290,7 +3290,18 @@ void ToonEngine::drawConversationLine() {
 	if (_currentTextLine && _showConversationText) {
 		_fontRenderer->setFontColorByCharacter(_currentTextLineCharacterId);
 		_fontRenderer->setFont(_currentFont);
-		_fontRenderer->renderMultiLineText(_currentTextLineX, _currentTextLineY, _currentTextLine, 0);
+		_fontRenderer->renderMultiLineText(_currentTextLineX, _currentTextLineY, _currentTextLine, 0, *_mainSurface);
+	}
+}
+
+void ToonEngine::drawCustomText(int16 x, int16 y, char* line, Graphics::Surface* frame, char color) {
+	if (line) {
+		byte col = color; // 0xce
+		_fontRenderer->setFontColor(0, col, col);
+		//_fontRenderer->setFontColorByCharacter(_currentTextLineCharacterId);
+		_gameState->_currentScrollValue = 0;
+		_fontRenderer->setFont(_currentFont);
+		_fontRenderer->renderMultiLineText(x, y, line, 0, *frame);
 	}
 }
 
diff --git a/engines/toon/toon.h b/engines/toon/toon.h
index efb473f..cbabaff 100644
--- a/engines/toon/toon.h
+++ b/engines/toon/toon.h
@@ -33,6 +33,7 @@
 #include "toon/state.h"
 #include "toon/picture.h"
 #include "toon/anim.h"
+#include "toon/subtitles.h"
 #include "toon/movie.h"
 #include "toon/font.h"
 #include "toon/text.h"
@@ -212,6 +213,8 @@ public:
 	void waitForScriptStep();
 	void doMagnifierEffect();
 
+	void drawCustomText(int16 x, int16 y, char* line, Graphics::Surface* frame, char color);
+
 	bool canSaveGameStateCurrently();
 	bool canLoadGameStateCurrently();
 	void pauseEngineIntern(bool pause);


Commit: b6ff8f77b70bb8243114c384126d96331c98b3fc
    https://github.com/scummvm/scummvm/commit/b6ff8f77b70bb8243114c384126d96331c98b3fc
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
fix always true condition

Changed paths:
    engines/toon/movie.cpp


diff --git a/engines/toon/movie.cpp b/engines/toon/movie.cpp
index 634135d..f646eb2 100644
--- a/engines/toon/movie.cpp
+++ b/engines/toon/movie.cpp
@@ -124,7 +124,7 @@ void Movie::playVideo(bool isFirstIntroVideo) {
 					int len = frame->w * frame->h;
 					byte pixels[310000] = {0};
 					memcpy(pixels, frame->getPixels(), len);
-					for (byte i = 1; i < 256; i++) 
+					for (int i = 1; i < 256; i++) 
 					{
 						int j;
 						for (j = 0; j < len; j++) {


Commit: f7e039d3c2d62a51f619e4b4a246fd8b58862609
    https://github.com/scummvm/scummvm/commit/f7e039d3c2d62a51f619e4b4a246fd8b58862609
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: fix strings without null termination

Changed paths:
    engines/toon/subtitles.cpp


diff --git a/engines/toon/subtitles.cpp b/engines/toon/subtitles.cpp
index 1349778..8996e3b 100644
--- a/engines/toon/subtitles.cpp
+++ b/engines/toon/subtitles.cpp
@@ -72,6 +72,7 @@ bool SubtitleRenderer::load(const Common::String &video) {
 
     char srtfile[20] = {0};
     strcpy(srtfile, video.c_str());
+    srtfile[19] = '\0';
     int ln = strlen(srtfile);
     srtfile[ln - 3] = 't';
     srtfile[ln - 2] = 's';


Commit: ff039617bb8bfa832efbf4249c84d9e242f19568
    https://github.com/scummvm/scummvm/commit/ff039617bb8bfa832efbf4249c84d9e242f19568
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: formatting

Changed paths:
    engines/toon/font.cpp
    engines/toon/font.h
    engines/toon/module.mk
    engines/toon/subtitles.cpp
    engines/toon/subtitles.h
    engines/toon/toon.cpp
    engines/toon/toon.h


diff --git a/engines/toon/font.cpp b/engines/toon/font.cpp
index 29dbf40..06454ad 100644
--- a/engines/toon/font.cpp
+++ b/engines/toon/font.cpp
@@ -191,7 +191,7 @@ void FontRenderer::setFontColor(int32 fontColor1, int32 fontColor2, int32 fontCo
 	_currentFontColor[3] = fontColor3;
 }
 
-void FontRenderer::renderMultiLineText(int16 x, int16 y, const Common::String &origText, int32 mode, Graphics::Surface& frame) {
+void FontRenderer::renderMultiLineText(int16 x, int16 y, const Common::String &origText, int32 mode, Graphics::Surface &frame) {
 	debugC(5, kDebugFont, "renderMultiLineText(%d, %d, %s, %d)", x, y, origText.c_str(), mode);
 
 	// divide the text in several lines
diff --git a/engines/toon/font.h b/engines/toon/font.h
index 48d4b85..e6cf916 100644
--- a/engines/toon/font.h
+++ b/engines/toon/font.h
@@ -35,7 +35,7 @@ public:
 	void setFont(Animation *font);
 	void computeSize(const Common::String &origText, int16 *retX, int16 *retY);
 	void renderText(int16 x, int16 y, const Common::String &origText, int32 mode);
-	void renderMultiLineText(int16 x, int16 y, const Common::String &origText, int32 mode, Graphics::Surface& frame);
+	void renderMultiLineText(int16 x, int16 y, const Common::String &origText, int32 mode, Graphics::Surface &frame);
 	void setFontColorByCharacter(int32 characterId);
 	void setFontColor(int32 fontColor1, int32 fontColor2, int32 fontColor3);
 protected:
diff --git a/engines/toon/module.mk b/engines/toon/module.mk
index 411b8e7..6387e62 100644
--- a/engines/toon/module.mk
+++ b/engines/toon/module.mk
@@ -18,10 +18,10 @@ MODULE_OBJS := \
 	script.o \
 	script_func.o \
 	state.o \
+	subtitles.o \
 	text.o \
 	tools.o \
-	toon.o \
-	subtitles.o
+	toon.o
 
 # This module can be built as a plugin
 ifeq ($(ENABLE_TOON), DYNAMIC_PLUGIN)
diff --git a/engines/toon/subtitles.cpp b/engines/toon/subtitles.cpp
index 8996e3b..5861b6c 100644
--- a/engines/toon/subtitles.cpp
+++ b/engines/toon/subtitles.cpp
@@ -28,71 +28,67 @@
 
 namespace Toon {
 SubtitleRenderer::SubtitleRenderer(ToonEngine *vm) : _vm(vm) {
-    _subSurface = new Graphics::Surface();
+	_subSurface = new Graphics::Surface();
 	_subSurface->create(TOON_SCREEN_WIDTH, TOON_SCREEN_HEIGHT, Graphics::PixelFormat::createFormatCLUT8());
-    _hasSubtitles = false;
+	_hasSubtitles = false;
 }
 
 SubtitleRenderer::~SubtitleRenderer() {
 }
 
 
-void SubtitleRenderer::render(const Graphics::Surface& frame, uint32 frameNumber, char color) {
-    if (!_hasSubtitles || _index > _last) {
-        return;
-    }
+void SubtitleRenderer::render(const Graphics::Surface &frame, uint32 frameNumber, byte color) {
+	if (!_hasSubtitles || _index > _last) {
+		return;
+	}
 
-    _subSurface->copyFrom(frame);
-    // char strf[384] = {0};
-    // sprintf(strf, "Time passed: %d", frameNumber);
-    // _vm->drawCostumeLine(0, 0, strf, _subSurface);
-    // _vm->_system->copyRectToScreen(_subSurface->getBasePtr(0, 0), _subSurface->pitch, 0, 0, _subSurface->w,  _subSurface->h);
+	_subSurface->copyFrom(frame);
+	// char strf[384] = {0};
+	// sprintf(strf, "Time passed: %d", frameNumber);
+	// _vm->drawCostumeLine(0, 0, strf, _subSurface);
+	// _vm->_system->copyRectToScreen(_subSurface->getBasePtr(0, 0), _subSurface->pitch, 0, 0, _subSurface->w,  _subSurface->h);
 
-    if (frameNumber > _tw[_index].fend) {
-        _index++;
-        if (_index > _last) {
-            return;
-        }
-        _currentLine = (char*)_fileData + _tw[_index].foffset;
-    }
+	if (frameNumber > _tw[_index].fend) {
+		_index++;
+		if (_index > _last) {
+			return;
+		}
+		_currentLine = (char*)_fileData + _tw[_index].foffset;
+	}
 
-    if (frameNumber < _tw[_index].fstart) {
-        return;
-    }
+	if (frameNumber < _tw[_index].fstart) {
+		return;
+	}
 
-    _vm->drawCustomText(TOON_SCREEN_WIDTH / 2, TOON_SCREEN_HEIGHT, _currentLine, _subSurface, color);
-    _vm->_system->copyRectToScreen(_subSurface->getBasePtr(0, 0), _subSurface->pitch, 0, 0, _subSurface->w,  _subSurface->h);
+	_vm->drawCustomText(TOON_SCREEN_WIDTH / 2, TOON_SCREEN_HEIGHT, _currentLine, _subSurface, color);
+	_vm->_system->copyRectToScreen(_subSurface->getBasePtr(0, 0), _subSurface->pitch, 0, 0, _subSurface->w,  _subSurface->h);
 }
 
 bool SubtitleRenderer::load(const Common::String &video) {
-    warning(video.c_str());
+	warning(video.c_str());
 
-    _hasSubtitles = false;
-    _index = 0;
+	_hasSubtitles = false;
+	_index = 0;
 
-    char srtfile[20] = {0};
-    strcpy(srtfile, video.c_str());
-    srtfile[19] = '\0';
-    int ln = strlen(srtfile);
-    srtfile[ln - 3] = 't';
-    srtfile[ln - 2] = 's';
-    srtfile[ln - 1] = 's';
+	Common::String subfile(video);
+	Common::String ext("tss");
+	subfile.replace(subfile.size() - ext.size(), ext.size(), ext);
 
-    uint32 fileSize = 0;
-	uint8 *fileData = _vm->resources()->getFileData(srtfile, &fileSize);
+	uint32 fileSize = 0;
+	uint8 *fileData = _vm->resources()->getFileData(subfile, &fileSize);
 	if (!fileData) {
-	 	return false;
-    }
-
-    uint32 numOflines = *((uint32*) fileData);
-    uint32 idx_size = numOflines * sizeof(TimeWindow);
-    memcpy(_tw, sizeof(numOflines) + fileData, idx_size);
-    _fileData = sizeof(numOflines) + fileData + idx_size;
-    _last = numOflines - 1;
-
-    _currentLine = (char*)_fileData + _tw[0].foffset;
-    _hasSubtitles = true;
-    return _hasSubtitles;
+		return false;
+	}
+
+	uint32 numOflines = *((uint32 *) fileData);
+	uint32 idx_size = numOflines * sizeof(TimeWindow);
+	memcpy(_tw, sizeof(numOflines) + fileData, idx_size);
+	_fileData = sizeof(numOflines) + fileData + idx_size;
+	_last = numOflines - 1;
+
+	_currentLine = (char *)_fileData + _tw[0].foffset;
+	_hasSubtitles = true;
+	return _hasSubtitles;
 }
 
-}
\ No newline at end of file
+}
diff --git a/engines/toon/subtitles.h b/engines/toon/subtitles.h
index 7eb7fe1..14c7c35 100644
--- a/engines/toon/subtitles.h
+++ b/engines/toon/subtitles.h
@@ -29,9 +29,9 @@
 namespace Toon {
 
 typedef struct {
-    uint32 fstart;
-    uint32 fend;
-    uint32 foffset;
+	uint32 fstart;
+	uint32 fend;
+	uint32 foffset;
 } TimeWindow;
 
 class SubtitleRenderer {
@@ -39,21 +39,20 @@ public:
 	SubtitleRenderer(ToonEngine *vm);
 	~SubtitleRenderer();
 
-    bool load(const Common::String &video);
-    void render(const Graphics::Surface& frame, uint32 frameNumber, char color);
+	bool load(const Common::String &video);
+	void render(const Graphics::Surface &frame, uint32 frameNumber, byte color);
 protected:
 	ToonEngine *_vm;
-    Graphics::Surface* _subSurface;
-    bool _hasSubtitles;
-
-    char* _lines[384];
-    TimeWindow _tw[384];
-    uint8 *_fileData;
-    uint16 _index;
-    uint16 _last;
-    char* _currentLine;
+	Graphics::Surface *_subSurface;
+	bool _hasSubtitles;
+	char *_lines[384];
+	TimeWindow _tw[384];
+	uint8 *_fileData;
+	uint16 _index;
+	uint16 _last;
+	char *_currentLine;
 };
 
 } // End of namespace Toon
 
-#endif
\ No newline at end of file
+#endif
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 4d2578e..518110b 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -3294,7 +3294,7 @@ void ToonEngine::drawConversationLine() {
 	}
 }
 
-void ToonEngine::drawCustomText(int16 x, int16 y, char* line, Graphics::Surface* frame, char color) {
+void ToonEngine::drawCustomText(int16 x, int16 y, char *line, Graphics::Surface *frame, char color) {
 	if (line) {
 		byte col = color; // 0xce
 		_fontRenderer->setFontColor(0, col, col);
diff --git a/engines/toon/toon.h b/engines/toon/toon.h
index cbabaff..cfb12a7 100644
--- a/engines/toon/toon.h
+++ b/engines/toon/toon.h
@@ -212,9 +212,7 @@ public:
 	void playRoomMusic();
 	void waitForScriptStep();
 	void doMagnifierEffect();
-
-	void drawCustomText(int16 x, int16 y, char* line, Graphics::Surface* frame, char color);
-
+	void drawCustomText(int16 x, int16 y, char *line, Graphics::Surface *frame, char color);
 	bool canSaveGameStateCurrently();
 	bool canLoadGameStateCurrently();
 	void pauseEngineIntern(bool pause);


Commit: d08027ae1f44fdaf0c24594994ba189c59424152
    https://github.com/scummvm/scummvm/commit/d08027ae1f44fdaf0c24594994ba189c59424152
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: simplify method to pick subtitles color

Changed paths:
    engines/toon/movie.cpp


diff --git a/engines/toon/movie.cpp b/engines/toon/movie.cpp
index f646eb2..d8c3ed4 100644
--- a/engines/toon/movie.cpp
+++ b/engines/toon/movie.cpp
@@ -119,22 +119,21 @@ void Movie::playVideo(bool isFirstIntroVideo) {
 				} else {
 					_vm->_system->copyRectToScreen(frame->getPixels(), frame->pitch, 0, 0, frame->w, frame->h);
 
-    				int32 currentFrame = _decoder->getCurFrame();
+					int32 currentFrame = _decoder->getCurFrame();
 
+					// find unused color key to replace with subtitles color
 					int len = frame->w * frame->h;
-					byte pixels[310000] = {0};
-					memcpy(pixels, frame->getPixels(), len);
-					for (int i = 1; i < 256; i++) 
-					{
-						int j;
-						for (j = 0; j < len; j++) {
-							if (pixels[j] == i) {
-								break; 
-							}
-						}
-				
-						if (j == len && i != 255) {
-							unused = i;
+					const byte* pixels = (const byte *)frame->getPixels();
+					byte counts[256];
+					memset(counts, 0, sizeof(counts));
+					for (int i = 0; i < len; i++) {
+						counts[pixels[i]] = 1;
+					}
+
+					// 0 is already used for the border color and should not be used here, so it can be skipped over.
+					for (int j = 1; j < 256; j++) {
+						if (counts[j] == 0) {
+							unused = j;
 							break;
 						}
 					}
@@ -155,16 +154,11 @@ void Movie::playVideo(bool isFirstIntroVideo) {
 				}
 			}
 
-			byte palette[768] = {0};
-			memcpy(palette, _decoder->getPalette(), 768);
-
+			byte subtitleColor[3] = {0xff, 0xff, 0x0};
+			_vm->_system->getPaletteManager()->setPalette(_decoder->getPalette(), 0, 256);
 			if (unused) {
-				palette[3 * unused] = 0xff;
-				palette[3 * unused + 1] = 0xff;
-				palette[3 * unused + 2] = 0x0;
+				_vm->_system->getPaletteManager()->setPalette(subtitleColor, unused, 1);
 			}
-
-			_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
 			_vm->_system->updateScreen();
 		}
 


Commit: 2a21ef0bb6a3aa22ba2a681f7273364f0c33b7d5
    https://github.com/scummvm/scummvm/commit/2a21ef0bb6a3aa22ba2a681f7273364f0c33b7d5
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: order imports

Changed paths:
    engines/toon/subtitles.h


diff --git a/engines/toon/subtitles.h b/engines/toon/subtitles.h
index 14c7c35..0d2575e 100644
--- a/engines/toon/subtitles.h
+++ b/engines/toon/subtitles.h
@@ -23,8 +23,8 @@
 #ifndef TOON_SUBTITLES_H
 #define TOON_SUBTITLES_H
 
-#include "toon/toon.h"
 #include "graphics/surface.h"
+#include "toon/toon.h"
 
 namespace Toon {
 


Commit: 656246d50d1dabb13b6a1b123a58c06ef8c18524
    https://github.com/scummvm/scummvm/commit/656246d50d1dabb13b6a1b123a58c06ef8c18524
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: typedef not needed

Changed paths:
    engines/toon/subtitles.h


diff --git a/engines/toon/subtitles.h b/engines/toon/subtitles.h
index 0d2575e..41b1263 100644
--- a/engines/toon/subtitles.h
+++ b/engines/toon/subtitles.h
@@ -28,11 +28,11 @@
 
 namespace Toon {
 
-typedef struct {
+struct TimeWindow {
 	uint32 fstart;
 	uint32 fend;
 	uint32 foffset;
-} TimeWindow;
+};
 
 class SubtitleRenderer {
 public:


Commit: a81b47633e2cf1bb7de5d82a012dcd2c04dc3903
    https://github.com/scummvm/scummvm/commit/a81b47633e2cf1bb7de5d82a012dcd2c04dc3903
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: comment out non-warning

Changed paths:
    engines/toon/subtitles.cpp


diff --git a/engines/toon/subtitles.cpp b/engines/toon/subtitles.cpp
index 5861b6c..7fb5845 100644
--- a/engines/toon/subtitles.cpp
+++ b/engines/toon/subtitles.cpp
@@ -65,7 +65,7 @@ void SubtitleRenderer::render(const Graphics::Surface &frame, uint32 frameNumber
 }
 
 bool SubtitleRenderer::load(const Common::String &video) {
-	warning(video.c_str());
+	// warning(video.c_str());
 
 	_hasSubtitles = false;
 	_index = 0;


Commit: a2a4278c0f31f6a0134227c102fc90c0bb7bf7e4
    https://github.com/scummvm/scummvm/commit/a2a4278c0f31f6a0134227c102fc90c0bb7bf7e4
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: support SUBTITLES.PAK

Changed paths:
    engines/toon/toon.cpp


diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 518110b..40b19c0 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -106,6 +106,9 @@ void ToonEngine::init() {
 	resources()->openPackage("ONETIME.PAK");
 	resources()->openPackage("DREW.PAK");
 
+	// load subtitles if available (if fails to load it only return false, so there's no need to check)
+	resources()->openPackage("SUBTITLES.PAK");
+
 	for (int32 i = 0; i < 32; i++)
 		_characters[i] = NULL;
 


Commit: e87e18052c517737c7327ada531fb737fafa5ef4
    https://github.com/scummvm/scummvm/commit/e87e18052c517737c7327ada531fb737fafa5ef4
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON:  fix types + remove unused import

Changed paths:
    engines/toon/movie.cpp
    engines/toon/subtitles.cpp
    engines/toon/toon.cpp
    engines/toon/toon.h


diff --git a/engines/toon/movie.cpp b/engines/toon/movie.cpp
index d8c3ed4..a706456 100644
--- a/engines/toon/movie.cpp
+++ b/engines/toon/movie.cpp
@@ -122,17 +122,17 @@ void Movie::playVideo(bool isFirstIntroVideo) {
 					int32 currentFrame = _decoder->getCurFrame();
 
 					// find unused color key to replace with subtitles color
-					int len = frame->w * frame->h;
-					const byte* pixels = (const byte *)frame->getPixels();
-					byte counts[256];
-					memset(counts, 0, sizeof(counts));
-					for (int i = 0; i < len; i++) {
-						counts[pixels[i]] = 1;
+					uint len = frame->w * frame->h;
+					const byte *pixels = (const byte *)frame->getPixels();
+					bool counts[256];
+					memset(counts, false, sizeof(counts));
+					for (uint i = 0; i < len; i++) {
+						counts[pixels[i]] = true;
 					}
 
 					// 0 is already used for the border color and should not be used here, so it can be skipped over.
 					for (int j = 1; j < 256; j++) {
-						if (counts[j] == 0) {
+						if (!counts[j]) {
 							unused = j;
 							break;
 						}
diff --git a/engines/toon/subtitles.cpp b/engines/toon/subtitles.cpp
index 7fb5845..5181180 100644
--- a/engines/toon/subtitles.cpp
+++ b/engines/toon/subtitles.cpp
@@ -53,7 +53,7 @@ void SubtitleRenderer::render(const Graphics::Surface &frame, uint32 frameNumber
 		if (_index > _last) {
 			return;
 		}
-		_currentLine = (char*)_fileData + _tw[_index].foffset;
+		_currentLine = (char *)_fileData + _tw[_index].foffset;
 	}
 
 	if (frameNumber < _tw[_index].fstart) {
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 40b19c0..2407966 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -3297,7 +3297,7 @@ void ToonEngine::drawConversationLine() {
 	}
 }
 
-void ToonEngine::drawCustomText(int16 x, int16 y, char *line, Graphics::Surface *frame, char color) {
+void ToonEngine::drawCustomText(int16 x, int16 y, char *line, Graphics::Surface *frame, byte color) {
 	if (line) {
 		byte col = color; // 0xce
 		_fontRenderer->setFontColor(0, col, col);
diff --git a/engines/toon/toon.h b/engines/toon/toon.h
index cfb12a7..1d69387 100644
--- a/engines/toon/toon.h
+++ b/engines/toon/toon.h
@@ -33,7 +33,6 @@
 #include "toon/state.h"
 #include "toon/picture.h"
 #include "toon/anim.h"
-#include "toon/subtitles.h"
 #include "toon/movie.h"
 #include "toon/font.h"
 #include "toon/text.h"
@@ -212,7 +211,7 @@ public:
 	void playRoomMusic();
 	void waitForScriptStep();
 	void doMagnifierEffect();
-	void drawCustomText(int16 x, int16 y, char *line, Graphics::Surface *frame, char color);
+	void drawCustomText(int16 x, int16 y, char *line, Graphics::Surface *frame, byte color);
 	bool canSaveGameStateCurrently();
 	bool canLoadGameStateCurrently();
 	void pauseEngineIntern(bool pause);


Commit: 32b9b7226ca35eb2b47ff0a030472f78640101cd
    https://github.com/scummvm/scummvm/commit/32b9b7226ca35eb2b47ff0a030472f78640101cd
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: plaintext format for subtitles

Changed paths:
    engines/toon/subtitles.cpp
    engines/toon/subtitles.h
    engines/toon/toon.cpp
    engines/toon/toon.h


diff --git a/engines/toon/subtitles.cpp b/engines/toon/subtitles.cpp
index 5181180..f3205ed 100644
--- a/engines/toon/subtitles.cpp
+++ b/engines/toon/subtitles.cpp
@@ -38,7 +38,7 @@ SubtitleRenderer::~SubtitleRenderer() {
 
 
 void SubtitleRenderer::render(const Graphics::Surface &frame, uint32 frameNumber, byte color) {
-	if (!_hasSubtitles || _index > _last) {
+	if (!_hasSubtitles || _tw.empty()) {
 		return;
 	}
 
@@ -48,19 +48,18 @@ void SubtitleRenderer::render(const Graphics::Surface &frame, uint32 frameNumber
 	// _vm->drawCostumeLine(0, 0, strf, _subSurface);
 	// _vm->_system->copyRectToScreen(_subSurface->getBasePtr(0, 0), _subSurface->pitch, 0, 0, _subSurface->w,  _subSurface->h);
 
-	if (frameNumber > _tw[_index].fend) {
-		_index++;
-		if (_index > _last) {
+	if (frameNumber > _tw.front()._endFrame) {
+		_tw.pop_front();
+		if (_tw.empty()) {
 			return;
 		}
-		_currentLine = (char *)_fileData + _tw[_index].foffset;
 	}
 
-	if (frameNumber < _tw[_index].fstart) {
+	if (frameNumber < _tw.front()._startFrame) {
 		return;
 	}
 
-	_vm->drawCustomText(TOON_SCREEN_WIDTH / 2, TOON_SCREEN_HEIGHT, _currentLine, _subSurface, color);
+	_vm->drawCustomText(TOON_SCREEN_WIDTH / 2, TOON_SCREEN_HEIGHT, _tw.front()._text.c_str(), _subSurface, color);
 	_vm->_system->copyRectToScreen(_subSurface->getBasePtr(0, 0), _subSurface->pitch, 0, 0, _subSurface->w,  _subSurface->h);
 }
 
@@ -68,25 +67,45 @@ bool SubtitleRenderer::load(const Common::String &video) {
 	// warning(video.c_str());
 
 	_hasSubtitles = false;
-	_index = 0;
 
 	Common::String subfile(video);
 	Common::String ext("tss");
 	subfile.replace(subfile.size() - ext.size(), ext.size(), ext);
 
-	uint32 fileSize = 0;
-	uint8 *fileData = _vm->resources()->getFileData(subfile, &fileSize);
-	if (!fileData) {
+	Common::SeekableReadStream *file;
+	file = _vm->resources()->openFile(subfile);
+	if (!file) {
 		return false;
 	}
 
-	uint32 numOflines = *((uint32 *) fileData);
-	uint32 idx_size = numOflines * sizeof(TimeWindow);
-	memcpy(_tw, sizeof(numOflines) + fileData, idx_size);
-	_fileData = sizeof(numOflines) + fileData + idx_size;
-	_last = numOflines - 1;
+	Common::String line;
+	int lineNo = 0;
+
+	_tw.clear();
+	while (!file->eos() && !file->err()) {
+		line = file->readLine();
+
+		lineNo++;
+		if (line.empty() || line[0] == '#') {
+			continue;
+		}
+
+		const char *ptr = line.c_str();
+
+		int startFrame = strtoul(ptr, const_cast<char **>(&ptr), 10);
+		int endFrame = strtoul(ptr, const_cast<char **>(&ptr), 10);
+
+		while (*ptr && Common::isSpace(*ptr))
+			ptr++;
+
+		if (startFrame > endFrame) {
+			warning("%s:%d: startFrame (%d) > endFrame (%d)", subfile.c_str(), lineNo, startFrame, endFrame);
+			continue;
+		}
+
+		_tw.push_back(TimeWindow(startFrame, endFrame, ptr));
+	}
 
-	_currentLine = (char *)_fileData + _tw[0].foffset;
 	_hasSubtitles = true;
 	return _hasSubtitles;
 }
diff --git a/engines/toon/subtitles.h b/engines/toon/subtitles.h
index 41b1263..133964c 100644
--- a/engines/toon/subtitles.h
+++ b/engines/toon/subtitles.h
@@ -28,10 +28,16 @@
 
 namespace Toon {
 
-struct TimeWindow {
-	uint32 fstart;
-	uint32 fend;
-	uint32 foffset;
+class TimeWindow {
+public:
+	uint16 _startFrame;
+	uint16 _endFrame;
+	Common::String _text;
+	TimeWindow(int startFrame, int endFrame, const Common::String &text) {
+		_startFrame = startFrame;
+		_endFrame = endFrame;
+		_text = text;
+	}
 };
 
 class SubtitleRenderer {
@@ -45,12 +51,7 @@ protected:
 	ToonEngine *_vm;
 	Graphics::Surface *_subSurface;
 	bool _hasSubtitles;
-	char *_lines[384];
-	TimeWindow _tw[384];
-	uint8 *_fileData;
-	uint16 _index;
-	uint16 _last;
-	char *_currentLine;
+	Common::List<TimeWindow> _tw;
 };
 
 } // End of namespace Toon
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 2407966..0f03536 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -1434,7 +1434,7 @@ void ToonEngine::updateAnimationSceneScripts(int32 timeElapsed) {
 
 	do {
 		if (_sceneAnimationScripts[_lastProcessedSceneScript]._lastTimer <= _system->getMillis() &&
-		        !_sceneAnimationScripts[_lastProcessedSceneScript]._frozen && !_sceneAnimationScripts[_lastProcessedSceneScript]._frozenForConversation) {
+				!_sceneAnimationScripts[_lastProcessedSceneScript]._frozen && !_sceneAnimationScripts[_lastProcessedSceneScript]._frozenForConversation) {
 			_animationSceneScriptRunFlag = true;
 
 			while (_animationSceneScriptRunFlag && _sceneAnimationScripts[_lastProcessedSceneScript]._lastTimer <= _system->getMillis() && !_shouldQuit) {
@@ -2992,8 +2992,8 @@ int32 ToonEngine::showInventory() {
 				int32 x = 57 * (i % 7) + 114;
 				int32 y = ((9 * (i % 7)) & 0xf) + 56 * (i / 7) + 80;
 				if (_mouseX >= (_gameState->_currentScrollValue + x - 6) &&
-				        _mouseX <= (_gameState->_currentScrollValue + x + 44 + 7) &&
-				        _mouseY >= y - 6 && _mouseY <= y + 50) {
+						_mouseX <= (_gameState->_currentScrollValue + x + 44 + 7) &&
+						_mouseY >= y - 6 && _mouseY <= y + 50) {
 					foundObj = i;
 					break;
 				}
@@ -3297,7 +3297,7 @@ void ToonEngine::drawConversationLine() {
 	}
 }
 
-void ToonEngine::drawCustomText(int16 x, int16 y, char *line, Graphics::Surface *frame, byte color) {
+void ToonEngine::drawCustomText(int16 x, int16 y, const char *line, Graphics::Surface *frame, byte color) {
 	if (line) {
 		byte col = color; // 0xce
 		_fontRenderer->setFontColor(0, col, col);
diff --git a/engines/toon/toon.h b/engines/toon/toon.h
index 1d69387..836dfe5 100644
--- a/engines/toon/toon.h
+++ b/engines/toon/toon.h
@@ -211,7 +211,7 @@ public:
 	void playRoomMusic();
 	void waitForScriptStep();
 	void doMagnifierEffect();
-	void drawCustomText(int16 x, int16 y, char *line, Graphics::Surface *frame, byte color);
+	void drawCustomText(int16 x, int16 y, const char *line, Graphics::Surface *frame, byte color);
 	bool canSaveGameStateCurrently();
 	bool canLoadGameStateCurrently();
 	void pauseEngineIntern(bool pause);


Commit: 47462e9810b19809688a2b26fb3a4043da20a802
    https://github.com/scummvm/scummvm/commit/47462e9810b19809688a2b26fb3a4043da20a802
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: formatting

Changed paths:
    engines/toon/subtitles.cpp


diff --git a/engines/toon/subtitles.cpp b/engines/toon/subtitles.cpp
index f3205ed..2d77b56 100644
--- a/engines/toon/subtitles.cpp
+++ b/engines/toon/subtitles.cpp
@@ -72,8 +72,7 @@ bool SubtitleRenderer::load(const Common::String &video) {
 	Common::String ext("tss");
 	subfile.replace(subfile.size() - ext.size(), ext.size(), ext);
 
-	Common::SeekableReadStream *file;
-	file = _vm->resources()->openFile(subfile);
+	Common::SeekableReadStream *file = _vm->resources()->openFile(subfile);
 	if (!file) {
 		return false;
 	}


Commit: d30ee1df37c2b0f38768ba452ca1ffae9a3ea628
    https://github.com/scummvm/scummvm/commit/d30ee1df37c2b0f38768ba452ca1ffae9a3ea628
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: add create subtitles tools

Changed paths:
  A devtools/create_toon/subtitles/pakdir.py
  A devtools/create_toon/subtitles/submaker.py


diff --git a/devtools/create_toon/subtitles/pakdir.py b/devtools/create_toon/subtitles/pakdir.py
new file mode 100644
index 0000000..7e3ad94
--- /dev/null
+++ b/devtools/create_toon/subtitles/pakdir.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+
+"""
+This script generates subtitles for Toonstrack cutscenes
+in a single SUBTITLES.PAK file from given directory of .SBV subtitles
+
+Usage:
+```
+pakdir.py SUBTITLES_DIR
+````
+"""
+
+import struct
+from itertools import chain
+
+from submaker import sbv2tss
+
+def write_uint32_le(number):
+    return struct.pack('<I', number)
+
+def calculate_index_length(pak_index):
+    return sum(len(write_index_entry(fname, 0)) for fname in pak_index)
+
+def write_index_entry(fname, offset):
+    return write_uint32_le(offset) + fname.encode() + b'\00'
+
+def generate_index(data_files):
+    end = ('\00\00\00\00', b'')
+    pak_index, rdata = zip(*chain(data_files, (end,)))
+    off = calculate_index_length(pak_index)
+    for fname, fdata in zip(pak_index, rdata):
+        yield write_index_entry(fname, off), fdata
+        off += len(fdata)
+
+def create_entry(filename):
+    name, ext = os.path.splitext(os.path.basename(filename))
+    assert ext.lower() == '.sbv', ext.lower()
+    return name + '.tss', ''.join(sbv2tss(filename)).encode()
+
+if __name__ == "__main__":
+    import os
+    import glob
+    import sys
+
+    if len(sys.argv) < 2:
+        print("Usage: pakdir.py SUBTITLES_DIR")
+        exit(1)
+
+    paths = sys.argv[1:]
+    paths = (os.path.join(path, '*.sbv') for path in paths)
+    files = sorted(set(chain.from_iterable(glob.iglob(r) for r in paths)))
+    print(files)
+    index, data = zip(*generate_index(create_entry(filename) for filename in files))
+    with open('SUBTITLES.PAK', 'wb') as output:
+        output.write(b''.join(index))
+        output.write(b''.join(data))
diff --git a/devtools/create_toon/subtitles/submaker.py b/devtools/create_toon/subtitles/submaker.py
new file mode 100644
index 0000000..40a9f9b
--- /dev/null
+++ b/devtools/create_toon/subtitles/submaker.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+
+'''
+This script generates subtitles for Toonstrack cutscenes
+from .SBV subtitiles.
+
+Usage:
+```
+submaker.py INFILE.sbv OUTFILE.tss
+````
+
+Subtitles format:
+<start frame> <end frame> <subtitle text>
+'''
+import io
+import sys
+
+from datetime import datetime
+
+TIME_FORMAT = '%H:%M:%S.%f'
+BASETIME = datetime(1900, 1, 1)
+FPS = 15
+
+def time2frame(time, fps=FPS):
+    return round(fps * (datetime.strptime('0' + time + '000', TIME_FORMAT) - BASETIME).total_seconds())
+
+def sbv2tss(infile, fps=FPS):
+    with open(infile, 'r') as sub_file:
+        lines = sub_file.read().split('\n\n')
+
+    # ignore empty lines
+    lines = [line for line in lines if line]
+
+    for line in lines:
+        time_window, text = line.split('\n')[:2]
+        start, end = time_window.split(',')
+        start = time2frame(start, fps=fps)
+        end = time2frame(end[:-1], fps=fps)
+
+        yield '{start} {end} {line}\n'.format(start=start, end=end, line=text)
+
+if __name__ == '__main__':
+    if len(sys.argv) < 3:
+        print('Usage: toon_submaker.py INFILE.sbv OUTFILE.tss')
+        exit(1)
+
+    infile = sys.argv[1]
+    outfile = sys.argv[2]
+
+    with open(outfile, 'w') as sub_file:
+        for line in sbv2tss(infile):
+            sub_file.write(line)


Commit: 21be04a332505410b501a541932c9a450039268c
    https://github.com/scummvm/scummvm/commit/21be04a332505410b501a541932c9a450039268c
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: remove assertion and unused import

Changed paths:
    devtools/create_toon/subtitles/pakdir.py
    devtools/create_toon/subtitles/submaker.py


diff --git a/devtools/create_toon/subtitles/pakdir.py b/devtools/create_toon/subtitles/pakdir.py
index 7e3ad94..108465c 100644
--- a/devtools/create_toon/subtitles/pakdir.py
+++ b/devtools/create_toon/subtitles/pakdir.py
@@ -34,7 +34,6 @@ def generate_index(data_files):
 
 def create_entry(filename):
     name, ext = os.path.splitext(os.path.basename(filename))
-    assert ext.lower() == '.sbv', ext.lower()
     return name + '.tss', ''.join(sbv2tss(filename)).encode()
 
 if __name__ == "__main__":
diff --git a/devtools/create_toon/subtitles/submaker.py b/devtools/create_toon/subtitles/submaker.py
index 40a9f9b..177a04e 100644
--- a/devtools/create_toon/subtitles/submaker.py
+++ b/devtools/create_toon/subtitles/submaker.py
@@ -12,7 +12,6 @@ submaker.py INFILE.sbv OUTFILE.tss
 Subtitles format:
 <start frame> <end frame> <subtitle text>
 '''
-import io
 import sys
 
 from datetime import datetime


Commit: c130cb074818926ef99c7923d8a9d8ba84aa39b3
    https://github.com/scummvm/scummvm/commit/c130cb074818926ef99c7923d8a9d8ba84aa39b3
Author: BLooperZ (blooperz at users.noreply.github.com)
Date: 2019-11-18T02:02:14+01:00

Commit Message:
TOON: ignore extension check

Changed paths:
    devtools/create_toon/subtitles/pakdir.py


diff --git a/devtools/create_toon/subtitles/pakdir.py b/devtools/create_toon/subtitles/pakdir.py
index 108465c..9c7b01c 100644
--- a/devtools/create_toon/subtitles/pakdir.py
+++ b/devtools/create_toon/subtitles/pakdir.py
@@ -33,7 +33,7 @@ def generate_index(data_files):
         off += len(fdata)
 
 def create_entry(filename):
-    name, ext = os.path.splitext(os.path.basename(filename))
+    name, _ = os.path.splitext(os.path.basename(filename))
     return name + '.tss', ''.join(sbv2tss(filename)).encode()
 
 if __name__ == "__main__":





More information about the Scummvm-git-logs mailing list