GLK: FROTZ: Improved palette reading

This commit is contained in:
Paul Gilbert 2019-02-27 19:16:46 -08:00
parent 1c75912ecf
commit acb39303f1
2 changed files with 22 additions and 7 deletions

View File

@ -149,13 +149,7 @@ Common::SeekableReadStream *Pics::createReadStreamForMember(const Common::String
error("Reading failed");
if (e._dataSize) {
if (e._paletteOffset) {
// Read in the image's palette
assert(e._paletteOffset);
f.seek(e._paletteOffset);
_palette->resize(f.readByte() * 3);
f.read(&(*_palette)[0], _palette->size());
}
loadPalette(f, e, *_palette);
f.seek(e._dataOffset);
Common::SeekableReadStream *src = f.readStream(e._dataSize);
@ -176,5 +170,20 @@ Common::SeekableReadStream *Pics::createReadStreamForMember(const Common::String
return nullptr;
}
void Pics::loadPalette(Common::File &f, const Entry &e, Common::Array<byte> &palette) const {
if (e._paletteOffset) {
// Read in the image's palette
assert(e._paletteOffset);
f.seek(e._paletteOffset);
_palette->resize(f.readByte() * 3);
f.read(&(*_palette)[0], _palette->size());
}
if (e._flags & 1) {
byte *entry = &palette[(e._flags >> 12) * 3];
Common::fill(entry, entry + 3, 0);
}
}
} // End of namespace Frotz
} // End of namespace Glk

View File

@ -25,6 +25,7 @@
#include "common/archive.h"
#include "common/array.h"
#include "common/file.h"
namespace Glk {
namespace Frotz {
@ -71,6 +72,11 @@ private:
* Returns the filename for the pictures archive
*/
static Common::String getFilename();
/**
* Read in the palette
*/
void loadPalette(Common::File &f, const Entry &e, Common::Array<byte> &palette) const;
public:
/**
* Returns true if an mg1 file exists for the game