mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-04 01:46:42 +00:00
GLK: FROTZ: Fix handling of empty rect picture resources
This commit is contained in:
parent
7fda941302
commit
ab8ff73453
@ -24,6 +24,7 @@
|
||||
#include "glk/frotz/pics_decoder.h"
|
||||
#include "glk/glk.h"
|
||||
#include "common/algorithm.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
namespace Glk {
|
||||
namespace Frotz {
|
||||
@ -68,7 +69,10 @@ Pics::Pics() : Common::Archive(), _filename(getFilename()) {
|
||||
}
|
||||
}
|
||||
|
||||
e._filename = Common::String::format("pic%u.raw", e._number);
|
||||
if (e._dataOffset)
|
||||
e._filename = Common::String::format("pic%u.raw", e._number);
|
||||
else
|
||||
e._filename = Common::String::format("pic%u.rect", e._number);
|
||||
}
|
||||
|
||||
// Further processing of index to calculate data sizes
|
||||
@ -128,6 +132,8 @@ const Common::ArchiveMemberPtr Pics::getMember(const Common::String &name) const
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *Pics::createReadStreamForMember(const Common::String &name) const {
|
||||
PictureDecoder decoder;
|
||||
|
||||
for (uint idx = 0; idx < _index.size(); ++idx) {
|
||||
const Entry &e = _index[idx];
|
||||
if (e._filename.equalsIgnoreCase(name)) {
|
||||
@ -137,19 +143,21 @@ Common::SeekableReadStream *Pics::createReadStreamForMember(const Common::String
|
||||
if (!f.open(_filename))
|
||||
error("Reading failed");
|
||||
|
||||
// Read in the image's palette
|
||||
assert(e._paletteOffset);
|
||||
f.seek(e._paletteOffset);
|
||||
palette.resize(f.readByte() * 3);
|
||||
f.read(&palette[0], palette.size());
|
||||
|
||||
PictureDecoder decoder;
|
||||
if (e._dataSize) {
|
||||
// Read in the image's palette
|
||||
assert(e._paletteOffset);
|
||||
f.seek(e._paletteOffset);
|
||||
palette.resize(f.readByte() * 3);
|
||||
f.read(&palette[0], palette.size());
|
||||
|
||||
Common::SeekableReadStream *src = f.readStream(e._dataSize);
|
||||
dest = decoder.decode(*src, e._flags, palette, MCGA, e._width, e._height);
|
||||
delete src;
|
||||
} else {
|
||||
error("TODO: Empty rect renderings");
|
||||
byte *rect = (byte *)malloc(2 * sizeof(uint16));
|
||||
WRITE_LE_UINT16(rect, e._width);
|
||||
WRITE_LE_UINT16(rect + 2, e._height);
|
||||
dest = new Common::MemoryReadStream(rect, 2 * sizeof(uint16), DisposeAfterUse::YES);
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
@ -103,6 +103,7 @@ Picture *Pictures::retrieve(uint id, bool scaled) {
|
||||
Picture *Pictures::load(uint32 id) {
|
||||
::Image::PNGDecoder png;
|
||||
::Image::JPEGDecoder jpg;
|
||||
Graphics::Surface rectImg;
|
||||
RawDecoder raw;
|
||||
const Graphics::Surface *img;
|
||||
const byte *palette = nullptr;
|
||||
@ -128,6 +129,10 @@ Picture *Pictures::load(uint32 id) {
|
||||
img = raw.getSurface();
|
||||
palette = raw.getPalette();
|
||||
palCount = raw.getPaletteColorCount();
|
||||
} else if (f.open(Common::String::format("pic%u.rect", id))) {
|
||||
rectImg.w = f.readUint16LE();
|
||||
rectImg.h = f.readUint16LE();
|
||||
img = &rectImg;
|
||||
} else {
|
||||
// No such picture
|
||||
return nullptr;
|
||||
@ -138,7 +143,9 @@ Picture *Pictures::load(uint32 id) {
|
||||
pic->_id = id;
|
||||
pic->_scaled = false;
|
||||
|
||||
if (!palette) {
|
||||
if (!img->getPixels()) {
|
||||
// Area definition without any content
|
||||
} else if (!palette) {
|
||||
pic->blitFrom(*img);
|
||||
} else {
|
||||
uint pal[256];
|
||||
|
Loading…
x
Reference in New Issue
Block a user