aboutsummaryrefslogtreecommitdiff
path: root/engines/supernova/graphics.cpp
diff options
context:
space:
mode:
authorThierry Crozat2017-09-30 16:28:42 +0100
committerThierry Crozat2018-01-23 02:15:33 +0000
commit0f4d364e63bbc1cb2a14917245a4e8d0abe82150 (patch)
tree27d140479266f118182f38dd7e108f2c1e39daf1 /engines/supernova/graphics.cpp
parenta13086ad25b573e7b6f580f7ed38c4c37f6a9d17 (diff)
downloadscummvm-rg350-0f4d364e63bbc1cb2a14917245a4e8d0abe82150.tar.gz
scummvm-rg350-0f4d364e63bbc1cb2a14917245a4e8d0abe82150.tar.bz2
scummvm-rg350-0f4d364e63bbc1cb2a14917245a4e8d0abe82150.zip
SUPERNOVA: Add getting translated images from the engine data file
Diffstat (limited to 'engines/supernova/graphics.cpp')
-rw-r--r--engines/supernova/graphics.cpp95
1 files changed, 72 insertions, 23 deletions
diff --git a/engines/supernova/graphics.cpp b/engines/supernova/graphics.cpp
index 70f05903ea..87485e0edc 100644
--- a/engines/supernova/graphics.cpp
+++ b/engines/supernova/graphics.cpp
@@ -24,11 +24,13 @@
#include "common/file.h"
#include "common/stream.h"
#include "common/system.h"
+#include "common/config-manager.h"
#include "graphics/palette.h"
#include "graphics/surface.h"
#include "graphics.h"
#include "msn_def.h"
+#include "supernova.h"
namespace Supernova {
@@ -57,6 +59,48 @@ bool MSNImageDecoder::init(int filenumber) {
return true;
}
+bool MSNImageDecoder::loadFromEngineDataFile() {
+ Common::String name;
+ if (_filenumber == 1)
+ name = "IMG1";
+ else if (_filenumber == 2)
+ name = "IMG2";
+ else
+ return false;
+
+ Common::String cur_lang = ConfMan.get("language");
+
+ // Note: we don't print any warning or errors here if we cannot find the file
+ // or the format is not as expected. We will get those warning when reading the
+ // strings anyway (actually the engine will even refuse to start).
+ Common::File f;
+ if (!f.open(SUPERNOVA_DAT))
+ return false;
+
+ char id[5], lang[5];
+ id[4] = lang[4] = '\0';
+ f.read(id, 3);
+ if (strncmp(id, "MSN", 3) != 0)
+ return false;
+ int version = f.readByte();
+ if (version != SUPERNOVA_DAT_VERSION)
+ return false;
+
+ while (!f.eos()) {
+ f.read(id, 4);
+ f.read(lang, 4);
+ uint32 size = f.readUint32LE();
+ if (f.eos())
+ break;
+ if (name == id && cur_lang == lang) {
+ return f.read(_encodedImage, size) == size;
+ } else
+ f.skip(size);
+ }
+
+ return false;
+}
+
bool MSNImageDecoder::loadStream(Common::SeekableReadStream &stream) {
destroy();
@@ -113,30 +157,35 @@ bool MSNImageDecoder::loadStream(Common::SeekableReadStream &stream) {
_clickField[i].next = stream.readByte();
}
- byte zwCodes[256] = {0};
- byte numRepeat = stream.readByte();
- byte numZw = stream.readByte();
- stream.read(zwCodes, numZw);
- numZw += numRepeat;
-
- byte input = 0;
- uint i = 0;
-
- while (stream.read(&input, 1)) {
- if (input < numRepeat) {
- ++input;
- byte value = stream.readByte();
- for (--value; input > 0; --input) {
- _encodedImage[i++] = value;
+ // Newspaper images may be in the engine data file. So first try to read
+ // it from there.
+ if (!loadFromEngineDataFile()) {
+ // Load the image from the stream
+ byte zwCodes[256] = {0};
+ byte numRepeat = stream.readByte();
+ byte numZw = stream.readByte();
+ stream.read(zwCodes, numZw);
+ numZw += numRepeat;
+
+ byte input = 0;
+ uint i = 0;
+
+ while (stream.read(&input, 1)) {
+ if (input < numRepeat) {
+ ++input;
+ byte value = stream.readByte();
+ for (--value; input > 0; --input) {
+ _encodedImage[i++] = value;
+ }
+ } else if (input < numZw) {
+ input = zwCodes[input - numRepeat];
+ --input;
+ _encodedImage[i++] = input;
+ _encodedImage[i++] = input;
+ } else {
+ input -= pal_diff;
+ _encodedImage[i++] = input;
}
- } else if (input < numZw) {
- input = zwCodes[input - numRepeat];
- --input;
- _encodedImage[i++] = input;
- _encodedImage[i++] = input;
- } else {
- input -= pal_diff;
- _encodedImage[i++] = input;
}
}