mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-03 15:21:40 +00:00
GLK: COMPREHEND: Finish implementing PIcs archive
This commit is contained in:
parent
d59873704c
commit
f7e40621ce
@ -26,6 +26,7 @@
|
||||
#include "glk/comprehend/game_data.h"
|
||||
#include "glk/comprehend/pics.h"
|
||||
#include "glk/comprehend/draw_surface.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
namespace Glk {
|
||||
namespace Comprehend {
|
||||
@ -39,6 +40,7 @@ Pics::ImageFile::ImageFile(const Common::String &filename) {
|
||||
uint16 version;
|
||||
int i;
|
||||
|
||||
_filename = filename;
|
||||
if (!f.open(filename))
|
||||
error("Could not open file - %s", filename.c_str());
|
||||
|
||||
@ -62,7 +64,7 @@ Pics::ImageFile::ImageFile(const Common::String &filename) {
|
||||
}
|
||||
}
|
||||
|
||||
void Pics::ImageFile::draw(uint index, ImageContext *ctx) {
|
||||
void Pics::ImageFile::draw(uint index, ImageContext *ctx) const {
|
||||
if (!ctx->_file.open(_filename))
|
||||
error("Opening image file");
|
||||
|
||||
@ -73,7 +75,7 @@ void Pics::ImageFile::draw(uint index, ImageContext *ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Pics::ImageFile::doImageOp(Pics::ImageContext *ctx) {
|
||||
bool Pics::ImageFile::doImageOp(Pics::ImageContext *ctx) const {
|
||||
uint8 opcode;
|
||||
uint16 a, b;
|
||||
|
||||
@ -256,7 +258,7 @@ bool Pics::ImageFile::doImageOp(Pics::ImageContext *ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16 Pics::ImageFile::imageGetOperand(ImageContext *ctx) {
|
||||
uint16 Pics::ImageFile::imageGetOperand(ImageContext *ctx) const {
|
||||
return ctx->_file.readByte();
|
||||
}
|
||||
|
||||
@ -280,7 +282,7 @@ void Pics::load(const Common::StringArray &roomFiles,
|
||||
int Pics::getPictureNumber(const Common::String &filename) const {
|
||||
// Ensure prefix and suffix
|
||||
if (!filename.hasPrefixIgnoreCase("pic") ||
|
||||
!filename.hasSuffixIgnoreCase(".png"))
|
||||
!filename.hasSuffixIgnoreCase(".raw"))
|
||||
return -1;
|
||||
|
||||
// Get the number part
|
||||
@ -323,11 +325,22 @@ Common::SeekableReadStream *Pics::createReadStreamForMember(const Common::String
|
||||
if (num == -1 || !hasFile(name))
|
||||
return nullptr;
|
||||
|
||||
// TODO
|
||||
error("TODO: createReadStream");
|
||||
// Draw the image
|
||||
drawPicture(num);
|
||||
|
||||
// Create a stream with the data for the surface
|
||||
Common::MemoryReadWriteStream *stream =
|
||||
new Common::MemoryReadWriteStream(DisposeAfterUse::YES);
|
||||
const DrawSurface &ds = *g_comprehend->_drawSurface;
|
||||
stream->writeUint16LE(ds.w);
|
||||
stream->writeUint16LE(ds.h);
|
||||
stream->writeUint16LE(0); // Palette size
|
||||
stream->write(ds.getPixels(), ds.w * ds.h * 4);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
void Pics::drawPicture(int pictureNum) {
|
||||
void Pics::drawPicture(int pictureNum) const {
|
||||
ImageContext ctx(g_comprehend->_drawSurface, g_comprehend->_drawFlags);
|
||||
|
||||
if (pictureNum == DARK_ROOM) {
|
||||
|
@ -111,14 +111,14 @@ class Pics : public Common::Archive {
|
||||
Common::String _filename;
|
||||
|
||||
private:
|
||||
bool doImageOp(ImageContext *ctx);
|
||||
uint16 imageGetOperand(ImageContext *ctx);
|
||||
bool doImageOp(ImageContext *ctx) const;
|
||||
uint16 imageGetOperand(ImageContext *ctx) const;
|
||||
|
||||
public:
|
||||
ImageFile() {}
|
||||
ImageFile(const Common::String &filename);
|
||||
|
||||
void draw(uint index, ImageContext *ctx);
|
||||
void draw(uint index, ImageContext *ctx) const;
|
||||
};
|
||||
|
||||
private:
|
||||
@ -134,7 +134,7 @@ private:
|
||||
/**
|
||||
* Draw the specified picture
|
||||
*/
|
||||
void drawPicture(int pictureNum);
|
||||
void drawPicture(int pictureNum) const;
|
||||
|
||||
public:
|
||||
void clear();
|
||||
|
@ -47,28 +47,37 @@ bool RawDecoder::loadStream(Common::SeekableReadStream &stream) {
|
||||
uint width = stream.readUint16LE();
|
||||
uint height = stream.readUint16LE();
|
||||
_paletteColorCount = stream.readUint16LE();
|
||||
assert(_paletteColorCount > 0);
|
||||
assert(_paletteColorCount == 0 || _paletteColorCount <= 0x100);
|
||||
|
||||
// Read in the palette
|
||||
_palette = new byte[_paletteColorCount * 3];
|
||||
stream.read(_palette, _paletteColorCount * 3);
|
||||
if (_paletteColorCount != 0) {
|
||||
// Read in the palette
|
||||
_palette = new byte[_paletteColorCount * 3];
|
||||
stream.read(_palette, _paletteColorCount * 3);
|
||||
|
||||
// Get the transparent color
|
||||
byte transColor = stream.readByte();
|
||||
if (transColor < _paletteColorCount)
|
||||
_transColor = transColor;
|
||||
// Get the transparent color
|
||||
byte transColor = stream.readByte();
|
||||
if (transColor < _paletteColorCount)
|
||||
_transColor = transColor;
|
||||
} else {
|
||||
_transColor = 0;
|
||||
}
|
||||
|
||||
// Set up the surface and read it in
|
||||
_surface.create(width, height, Graphics::PixelFormat::createFormatCLUT8());
|
||||
// Set up the surface
|
||||
_surface.create(width, height, (_paletteColorCount == 0) ?
|
||||
Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0) :
|
||||
Graphics::PixelFormat::createFormatCLUT8());
|
||||
|
||||
assert((stream.size() - stream.pos()) == (int)(width * height));
|
||||
assert((stream.size() - stream.pos()) ==
|
||||
(int)(width * height * _surface.format.bytesPerPixel));
|
||||
byte *pixels = (byte *)_surface.getPixels();
|
||||
stream.read(pixels, width * height);
|
||||
stream.read(pixels, width * height * _surface.format.bytesPerPixel);
|
||||
|
||||
for (uint idx = 0; idx < width * height; ++idx, ++pixels) {
|
||||
assert(*pixels != 0xff);
|
||||
if (*pixels >= _paletteColorCount)
|
||||
*pixels = _paletteColorCount - 1;
|
||||
if (_palette) {
|
||||
for (uint idx = 0; idx < width * height; ++idx, ++pixels) {
|
||||
assert(*pixels != 0xff);
|
||||
if (*pixels >= _paletteColorCount)
|
||||
*pixels = _paletteColorCount - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user