aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2018-11-23 15:35:13 -0800
committerPaul Gilbert2018-12-08 19:05:59 -0800
commit6f508124937df1b0cda5a2732039a82c4ec16b85 (patch)
tree568b8d485e76866b829ecbea1e4f97da11fa3f06
parent3e8ed4eafcfe3fd8198c65b0838022c1dd32eea8 (diff)
downloadscummvm-rg350-6f508124937df1b0cda5a2732039a82c4ec16b85.tar.gz
scummvm-rg350-6f508124937df1b0cda5a2732039a82c4ec16b85.tar.bz2
scummvm-rg350-6f508124937df1b0cda5a2732039a82c4ec16b85.zip
GLK: Added RawDecoder class for new raw picture data format
-rw-r--r--engines/glk/glk_api.cpp4
-rw-r--r--engines/glk/glk_api.h4
-rw-r--r--engines/glk/module.mk1
-rw-r--r--engines/glk/picture.cpp13
-rw-r--r--engines/glk/raw_decoder.cpp61
-rw-r--r--engines/glk/raw_decoder.h61
6 files changed, 140 insertions, 4 deletions
diff --git a/engines/glk/glk_api.cpp b/engines/glk/glk_api.cpp
index 981c41ef54..2a5fd11958 100644
--- a/engines/glk/glk_api.cpp
+++ b/engines/glk/glk_api.cpp
@@ -887,7 +887,7 @@ glui32 GlkAPI::glk_buffer_canon_normalize_uni(glui32 *buf, glui32 len, glui32 nu
return 0;
}
-glui32 GlkAPI::glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2) {
+bool GlkAPI::glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2) {
if (!win) {
warning("image_draw: invalid ref");
} else if (g_conf->_graphics) {
@@ -903,7 +903,7 @@ glui32 GlkAPI::glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val
return false;
}
-glui32 GlkAPI::glk_image_draw_scaled(winid_t win, glui32 image, glsi32 val1, glsi32 val2,
+bool GlkAPI::glk_image_draw_scaled(winid_t win, glui32 image, glsi32 val1, glsi32 val2,
glui32 width, glui32 height) {
if (!win) {
warning("image_draw_scaled: invalid ref");
diff --git a/engines/glk/glk_api.h b/engines/glk/glk_api.h
index 5c19e09cb5..fe25930cc2 100644
--- a/engines/glk/glk_api.h
+++ b/engines/glk/glk_api.h
@@ -190,8 +190,8 @@ public:
#ifdef GLK_MODULE_IMAGE
- glui32 glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2);
- glui32 glk_image_draw_scaled(winid_t win, glui32 image,
+ bool glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2);
+ bool glk_image_draw_scaled(winid_t win, glui32 image,
glsi32 val1, glsi32 val2, glui32 width, glui32 height);
bool glk_image_get_info(glui32 image, glui32 *width, glui32 *height);
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index d1d9100f32..a4344dfa6c 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -9,6 +9,7 @@ MODULE_OBJS := \
glk.o \
glk_api.o \
picture.o \
+ raw_decoder.o \
screen.o \
selection.o \
streams.o \
diff --git a/engines/glk/picture.cpp b/engines/glk/picture.cpp
index 122d9c3f30..7770bb892b 100644
--- a/engines/glk/picture.cpp
+++ b/engines/glk/picture.cpp
@@ -22,6 +22,7 @@
#include "glk/picture.h"
#include "glk/glk.h"
+#include "glk/raw_decoder.h"
#include "glk/screen.h"
#include "common/file.h"
#include "image/jpeg.h"
@@ -102,7 +103,9 @@ Picture *Pictures::retrieve(uint id, bool scaled) {
Picture *Pictures::load(uint32 id) {
::Image::PNGDecoder png;
::Image::JPEGDecoder jpg;
+ RawDecoder raw;
const Graphics::Surface *img;
+ const byte *palette = nullptr;
Picture *pic;
// Check if the picture is already in the store
@@ -114,15 +117,25 @@ Picture *Pictures::load(uint32 id) {
if (f.open(Common::String::format("PIC%lu.png", id))) {
png.loadStream(f);
img = png.getSurface();
+ palette = png.getPalette();
} else if (f.open(Common::String::format("PIC%lu.jpg", id))) {
jpg.loadStream(f);
img = jpg.getSurface();
+ } else if (f.open(Common::String::format("PIC%lu.raw", id))) {
+ raw.loadStream(f);
+ img = raw.getSurface();
+ palette = raw.getPalette();
}
pic = new Picture();
pic->_refCount = 1;
pic->_id = id;
pic->_scaled = false;
+ pic->create(img->w, img->h, g_system->getScreenFormat());
+ pic->blitFrom(*img);
+
+ if (palette)
+ pic->convertToInPlace(g_system->getScreenFormat(), palette);
store(pic);
return pic;
diff --git a/engines/glk/raw_decoder.cpp b/engines/glk/raw_decoder.cpp
new file mode 100644
index 0000000000..a5cd593338
--- /dev/null
+++ b/engines/glk/raw_decoder.cpp
@@ -0,0 +1,61 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software{} you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation{} either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY{} without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program{} if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "glk/raw_decoder.h"
+#include "common/stream.h"
+
+namespace Glk {
+
+RawDecoder::RawDecoder() : Image::ImageDecoder(), _palette(nullptr), _paletteColorCount(0) {
+}
+
+RawDecoder::~RawDecoder() {
+ destroy();
+}
+
+void RawDecoder::destroy() {
+ _surface.free();
+ delete[] _palette;
+ _palette = nullptr;
+}
+
+bool RawDecoder::loadStream(Common::SeekableReadStream &stream) {
+ // Reset member variables from previous decodings
+ destroy();
+
+ uint width = stream.readUint16LE();
+ uint height = stream.readUint16LE();
+ _paletteColorCount = stream.readByte();
+ assert(_paletteColorCount > 0);
+
+ // Read in the palette
+ _palette = new byte[_paletteColorCount * 3];
+ stream.read(_palette, _paletteColorCount * 3);
+
+ // Set up the surface and read it in
+ _surface.create(width, height, Graphics::PixelFormat::createFormatCLUT8());
+ stream.read(_surface.getPixels(), width * height);
+
+ return true;
+}
+
+} // End of namespace Glk
diff --git a/engines/glk/raw_decoder.h b/engines/glk/raw_decoder.h
new file mode 100644
index 0000000000..96f25c2512
--- /dev/null
+++ b/engines/glk/raw_decoder.h
@@ -0,0 +1,61 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef GLK_RAW_DECODER_H
+#define GLK_RAW_DECODER_H
+
+#include "graphics/surface.h"
+#include "image/image_decoder.h"
+
+namespace Glk {
+
+/**
+ * This image decoder class implements loading of a simplified image format.
+ * It's used for sub-engines like Frotz with custom picture formats. They can
+ * expose their picture archives using Common::Archive, and have the individual
+ * picture files stored in the format for this decoder to load
+ * Format:
+ * width 2 bytes
+ * height 2 bytes
+ * pal size 1 byte
+ * palette 3 bytes * pal size
+ * pixels width * height pixels
+ */
+class RawDecoder : public Image::ImageDecoder {
+private:
+ Graphics::Surface _surface;
+ byte *_palette;
+ uint16 _paletteColorCount;
+public:
+ RawDecoder();
+ ~RawDecoder();
+
+ virtual bool loadStream(Common::SeekableReadStream &stream) override;
+ virtual void destroy() override;
+ virtual const Graphics::Surface *getSurface() const override { return &_surface; }
+ virtual const byte *getPalette() const override { return _palette; }
+ virtual uint16 getPaletteColorCount() const override { return _paletteColorCount; }
+};
+
+} // End of namespace Glk
+
+#endif