Skip to content

Commit

Permalink
GLK: Properly handle Blorb images that have an adaptive palette
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Aug 2, 2019
1 parent 8a8ac63 commit efdf965
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 27 additions & 0 deletions engines/glk/picture.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion engines/glk/picture.h
Expand Up @@ -90,6 +90,8 @@ class Pictures {
private:
int _refCount;
Common::Array<PictureEntry> _store;
Common::Array<uint> _adaptivePics;
Common::Array<byte> _savedPalette;
private:
/**
* Stores an original picture in the store
Expand All @@ -104,7 +106,7 @@ class Pictures {
/**
* Constructor
*/
Pictures() : _refCount(0) {}
Pictures();

/**
* Destructor
Expand Down

0 comments on commit efdf965

Please sign in to comment.