aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/glk/frotz/pics_decoder.cpp2
-rw-r--r--engines/glk/picture.cpp23
-rw-r--r--engines/glk/picture.h18
-rw-r--r--engines/glk/raw_decoder.cpp11
-rw-r--r--engines/glk/raw_decoder.h2
-rw-r--r--engines/glk/window_graphics.cpp2
6 files changed, 44 insertions, 14 deletions
diff --git a/engines/glk/frotz/pics_decoder.cpp b/engines/glk/frotz/pics_decoder.cpp
index 73032df0d8..375abf20a2 100644
--- a/engines/glk/frotz/pics_decoder.cpp
+++ b/engines/glk/frotz/pics_decoder.cpp
@@ -114,7 +114,7 @@ Common::SeekableReadStream *PictureDecoder::decode(Common::ReadStream &src, uint
// Write out palette
out.writeUint16LE(palette.size() / 3 + 2);
for (int idx = 0; idx < 6; ++idx)
- out.writeByte(0);
+ out.writeByte((idx < 3) ? 0x77 : 0);
if (!palette.empty())
out.write(&palette[0], palette.size());
diff --git a/engines/glk/picture.cpp b/engines/glk/picture.cpp
index 2cebcb2780..59ee50c835 100644
--- a/engines/glk/picture.cpp
+++ b/engines/glk/picture.cpp
@@ -110,6 +110,7 @@ Picture *Pictures::load(uint32 id) {
const Graphics::Surface *img;
const byte *palette = nullptr;
uint palCount = 0;
+ int transColor = -1;
Picture *pic;
// Check if the picture is already in the store
@@ -131,6 +132,7 @@ Picture *Pictures::load(uint32 id) {
img = raw.getSurface();
palette = raw.getPalette();
palCount = raw.getPaletteColorCount();
+ transColor = raw.getTransparentColor();
} else if (f.open(Common::String::format("pic%u.rect", id))) {
rectImg.w = f.readUint16LE();
rectImg.h = f.readUint16LE();
@@ -144,6 +146,8 @@ Picture *Pictures::load(uint32 id) {
pic->_refCount = 1;
pic->_id = id;
pic->_scaled = false;
+ if (transColor != -1)
+ pic->clear(pic->getTransparentColor());
if (!img->getPixels()) {
// Area definition without any content
@@ -158,11 +162,13 @@ Picture *Pictures::load(uint32 id) {
const byte *srcP = (const byte *)img->getPixels();
byte *destP = (byte *)pic->getPixels();
for (int idx = 0; idx < img->w * img->h; ++idx, srcP++, destP += pic->format.bytesPerPixel) {
- uint val = (*srcP >= palCount) ? 0 : pal[*srcP];
- if (pic->format.bytesPerPixel == 2)
- WRITE_LE_UINT16(destP, val);
- else
- WRITE_LE_UINT32(destP, val);
+ if ((int)*srcP != transColor) {
+ uint val = (*srcP >= palCount) ? 0 : pal[*srcP];
+ if (pic->format.bytesPerPixel == 2)
+ WRITE_LE_UINT16(destP, val);
+ else
+ WRITE_LE_UINT32(destP, val);
+ }
}
}
@@ -188,6 +194,13 @@ Picture *Pictures::scale(Picture *src, size_t sx, size_t sy) {
/*--------------------------------------------------------------------------*/
+Picture::Picture(int width, int height, const Graphics::PixelFormat &fmt) :
+ Graphics::ManagedSurface(width, height, fmt), _refCount(0), _id(0), _scaled(false) {
+
+ // Default transparent color chosen at random
+ _transColor = format.RGBToColor(0x77, 0x77, 0x77);
+}
+
void Picture::increment() {
++_refCount;
}
diff --git a/engines/glk/picture.h b/engines/glk/picture.h
index 7c9bcc67d7..e3b65602a2 100644
--- a/engines/glk/picture.h
+++ b/engines/glk/picture.h
@@ -32,6 +32,8 @@ namespace Glk {
* Picture/image class
*/
struct Picture : Graphics::ManagedSurface {
+private:
+ int _transColor;
public:
int _refCount;
uint _id;
@@ -40,14 +42,12 @@ public:
/**
* Constructor
*/
- Picture() : Graphics::ManagedSurface(), _refCount(0), _id(0), _scaled(false) {}
+ Picture() : Graphics::ManagedSurface(), _refCount(0), _id(0), _scaled(false), _transColor(0x7777) {}
/**
* Constructor
*/
- Picture(int width, int height, const Graphics::PixelFormat &fmt) :
- Graphics::ManagedSurface(width, height, fmt), _refCount(0), _id(0), _scaled(false) {}
-
+ Picture(int width, int height, const Graphics::PixelFormat &fmt);
/**
* Increment reference counter
*/
@@ -62,6 +62,16 @@ public:
* Draw the picture
*/
void drawPicture(const Common::Point &destPos, const Common::Rect &box);
+
+ /**
+ * Get the transparency color
+ */
+ uint getTransparentColor() const { return _transColor; }
+
+ /**
+ * Set the transparency color
+ */
+ void setTransparentColor(uint color) { _transColor = color; }
};
/**
diff --git a/engines/glk/raw_decoder.cpp b/engines/glk/raw_decoder.cpp
index 659b333cac..cf3700371b 100644
--- a/engines/glk/raw_decoder.cpp
+++ b/engines/glk/raw_decoder.cpp
@@ -26,7 +26,8 @@
namespace Glk {
-RawDecoder::RawDecoder() : Image::ImageDecoder(), _palette(nullptr), _paletteColorCount(0) {
+RawDecoder::RawDecoder() : Image::ImageDecoder(), _palette(nullptr), _paletteColorCount(0),
+ _transColor(0) {
}
RawDecoder::~RawDecoder() {
@@ -52,11 +53,15 @@ bool RawDecoder::loadStream(Common::SeekableReadStream &stream) {
_palette = new byte[_paletteColorCount * 3];
stream.read(_palette, _paletteColorCount * 3);
+ // Get the transparent color
+ byte transColor = stream.readByte();
+ if (transColor < _paletteColorCount)
+ _transColor = transColor;
+
// Set up the surface and read it in
- stream.readByte();
_surface.create(width, height, Graphics::PixelFormat::createFormatCLUT8());
- assert((stream.size() - stream.pos()) <= (int)(width * height));
+ assert((stream.size() - stream.pos()) == (int)(width * height));
byte *pixels = (byte *)_surface.getPixels();
stream.read(pixels, width * height);
diff --git a/engines/glk/raw_decoder.h b/engines/glk/raw_decoder.h
index 96f25c2512..086cf2555f 100644
--- a/engines/glk/raw_decoder.h
+++ b/engines/glk/raw_decoder.h
@@ -45,6 +45,7 @@ private:
Graphics::Surface _surface;
byte *_palette;
uint16 _paletteColorCount;
+ int _transColor;
public:
RawDecoder();
~RawDecoder();
@@ -54,6 +55,7 @@ public:
virtual const Graphics::Surface *getSurface() const override { return &_surface; }
virtual const byte *getPalette() const override { return _palette; }
virtual uint16 getPaletteColorCount() const override { return _paletteColorCount; }
+ int getTransparentColor() const { return _transColor; }
};
} // End of namespace Glk
diff --git a/engines/glk/window_graphics.cpp b/engines/glk/window_graphics.cpp
index bc762f5ce1..063a590dc6 100644
--- a/engines/glk/window_graphics.cpp
+++ b/engines/glk/window_graphics.cpp
@@ -230,7 +230,7 @@ void GraphicsWindow::drawPicture(Picture *src, int x0, int y0, int width, int h
w = sx1 - sx0;
h = sy1 - sy0;
- _surface->blitFrom(*src, Rect(sx0, sy0, sx0 + w, sy0 + h), Point(0, 0));
+ _surface->transBlitFrom(*src, Rect(sx0, sy0, sx0 + w, sy0 + h), Point(0, 0), src->getTransparentColor());
}
void GraphicsWindow::getSize(uint *width, uint *height) const {