From efdf96517072445c07f17fdef17efd86e2bdc68c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 1 Aug 2019 22:04:36 -0700 Subject: GLK: Properly handle Blorb images that have an adaptive palette --- engines/glk/picture.cpp | 27 +++++++++++++++++++++++++++ engines/glk/picture.h | 4 +++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/glk/picture.cpp b/engines/glk/picture.cpp index 1663fa43ef..5cb44c8857 100644 --- a/engines/glk/picture.cpp +++ b/engines/glk/picture.cpp @@ -30,6 +30,14 @@ namespace Glk { +Pictures::Pictures() : _refCount(0) { + Common::File f; + if (f.open("apal")) { + while (f.pos() < f.size()) + _adaptivePics.push_back(f.readUint32BE()); + } +} + void Pictures::clear() { for (uint idx = 0; idx < _store.size(); ++idx) { if (_store[idx]._picture) @@ -120,10 +128,12 @@ Picture *Pictures::load(uint32 id) { Common::File f; if (f.open(Common::String::format("pic%u.png", id))) { + png.setKeepTransparencyPaletted(true); png.loadStream(f); img = png.getSurface(); palette = png.getPalette(); palCount = png.getPaletteColorCount(); + transColor = png.getTransparentColor(); } else if (f.open(Common::String::format("pic%u.jpg", id))) { jpg.setOutputPixelFormat(g_system->getScreenFormat()); jpg.loadStream(f); @@ -143,6 +153,23 @@ Picture *Pictures::load(uint32 id) { return nullptr; } + // Also check if it's going to be an adaptive pic + bool isAdaptive = false; + for (uint idx = 0; idx < _adaptivePics.size() && !isAdaptive; ++idx) + isAdaptive = _adaptivePics[idx] == id; + + if (isAdaptive) { + // It is, so used previously saved palette + assert(!_savedPalette.empty()); + palette = &_savedPalette[0]; + palCount = _savedPalette.size() / 3; + } else if (palette) { + // It's a picture with a valid palette, so save a copy of it for later + _savedPalette.resize(palCount * 3); + Common::copy(palette, palette + palCount * 3, &_savedPalette[0]); + } + + // Create new picture based on the image pic = new Picture(img->w, img->h, g_system->getScreenFormat()); pic->_refCount = 1; pic->_id = id; diff --git a/engines/glk/picture.h b/engines/glk/picture.h index e3b65602a2..a8b7e0a9b2 100644 --- a/engines/glk/picture.h +++ b/engines/glk/picture.h @@ -90,6 +90,8 @@ class Pictures { private: int _refCount; Common::Array _store; + Common::Array _adaptivePics; + Common::Array _savedPalette; private: /** * Stores an original picture in the store @@ -104,7 +106,7 @@ public: /** * Constructor */ - Pictures() : _refCount(0) {} + Pictures(); /** * Destructor -- cgit v1.2.3