diff options
-rw-r--r-- | engines/sludge/backdrop.cpp | 40 | ||||
-rw-r--r-- | engines/sludge/bytearray.cpp | 90 | ||||
-rw-r--r-- | engines/sludge/bytearray.h | 48 | ||||
-rw-r--r-- | engines/sludge/main_loop.cpp | 2 | ||||
-rw-r--r-- | engines/sludge/module.mk | 1 | ||||
-rw-r--r-- | engines/sludge/sludge.cpp | 3 |
6 files changed, 166 insertions, 18 deletions
diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp index ff24e1ba78..da71289464 100644 --- a/engines/sludge/backdrop.cpp +++ b/engines/sludge/backdrop.cpp @@ -60,6 +60,7 @@ #include "graphics/surface.h" #include "graphics/palette.h" #include "sludge.h" +#include "bytearray.h" namespace Sludge { @@ -82,7 +83,6 @@ GLuint snapshotTextureName = 0; Graphics::Surface backdropSurface; - float snapTexW = 1.0; float snapTexH = 1.0; @@ -1010,17 +1010,18 @@ bool loadParallax(unsigned short v, unsigned short fracX, extern int viewportOffsetX, viewportOffsetY; -bool loadPng(int &picWidth, int &picHeight, int &realPicWidth, - int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) { - debug(kSludgeDebugGraphics, "Loading back drop png."); +bool loadPng(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) { + debug(kSludgeDebugGraphics, "Loading back drop png at file position: %i", stream->pos()); ::Image::PNGDecoder png; if (!png.loadStream(*stream)) { debug(kSludgeDebugGraphics, "Back drop is not a png"); return false; } - backdropSurface.copyFrom(*(png.getSurface())); - const byte *palette = png.getPalette(); - g_system->getPaletteManager()->setPalette(palette, 0, 256); + const Graphics::Surface *sourceSurface = png.getSurface(); + Graphics::Surface *pngSurface = sourceSurface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), png.getPalette()); + backdropSurface.copyFrom(*pngSurface); + pngSurface->free(); + delete pngSurface; picWidth = realPicWidth = backdropSurface.w; picHeight = realPicHeight = backdropSurface.h; return true; @@ -1095,8 +1096,17 @@ bool loadPng(int &picWidth, int &picHeight, int &realPicWidth, #endif } -bool loadByteArray(int &picWidth, int &picHeight, int &realPicWidth, - int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) { +bool loadByteArray(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) { + debug(kSludgeDebugGraphics, "Loading back drop as a byte array at file position: %i", stream->pos()); + ByteArrayDecoder byteDecoder; + if (!byteDecoder.loadStream(*stream)) { + debug(kSludgeDebugGraphics, "Back drop is not a byte array"); + return false; + } + backdropSurface.copyFrom(*(byteDecoder.getSurface())); + picWidth = realPicWidth = backdropSurface.w; + picHeight = realPicHeight = backdropSurface.h; + return true; #if 0 int32_t transCol = reserve ? -1 : 63519; int t1, t2, n; @@ -1138,14 +1148,12 @@ bool loadByteArray(int &picWidth, int &picHeight, int &realPicWidth, #endif } -bool loadImage(int &picWidth, int &picHeight, int &realPicWidth, - int &realPicHeight, Common::SeekableReadStream *stream, int x, int y, - bool reserve) { +bool loadImage(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, int x, int y, bool reserve) { debug(kSludgeDebugGraphics, "Loading back drop image at file position: %i", stream->pos()); - if (!loadPng(picWidth, picHeight, realPicWidth, realPicHeight, stream, - reserve)) { - if (!loadByteArray(picWidth, picHeight, realPicWidth, realPicHeight, - stream, reserve)) { + int32 start_ptr = stream->pos(); + if (!loadPng(picWidth, picHeight, realPicWidth, realPicHeight, stream, reserve)) { + stream->seek(start_ptr); + if (!loadByteArray(picWidth, picHeight, realPicWidth, realPicHeight, stream, reserve)) { debug(kSludgeDebugGraphics, "Back drop loading failed"); return false; } diff --git a/engines/sludge/bytearray.cpp b/engines/sludge/bytearray.cpp new file mode 100644 index 0000000000..0b28a02f3d --- /dev/null +++ b/engines/sludge/bytearray.cpp @@ -0,0 +1,90 @@ +/* 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 "common/stream.h" +#include "common/debug.h" +#include "graphics/surface.h" + +#include "allfiles.h" +#include "bytearray.h" +#include "colours.h" +#include "sludge.h" + +namespace Sludge { + +ByteArrayDecoder::ByteArrayDecoder() : _surface(nullptr) { +} + +ByteArrayDecoder::~ByteArrayDecoder() { + destroy(); +} + +void ByteArrayDecoder::destroy() { + if (_surface != nullptr) { + _surface->free(); + delete _surface; + _surface = nullptr; + } +} + +bool ByteArrayDecoder::loadStream(Common::SeekableReadStream &stream) { + destroy(); + int32_t transCol = /*reserve ? -1 : */63519; + int n; + uint16 width = stream.readUint16BE(); + debug(kSludgeDebugGraphics, "picWidth : %i", width); + uint16 height = stream.readUint16BE(); + debug(kSludgeDebugGraphics, "picHeight : %i", height); + + _surface = new Graphics::Surface(); + _surface->create(width, height, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)); + for (uint16 y = 0; y < height; y++) { + uint16 x = 0; + while (x < width) { + unsigned short c = (unsigned short)stream.readUint16BE(); + if (c & 32) { + n = stream.readByte() + 1; + c -= 32; + } else { + n = 1; + } + while (n--) { + byte *target = (byte *)_surface->getBasePtr(x, y); + if (c == transCol || c == 2015) { + target[0] = (byte)0; + target[1] = (byte)0; + target[2] = (byte)0; + target[3] = (byte)0; + } else { + target[0] = (byte)255; + target[1] = (byte)blueValue(c); + target[2] = (byte)greenValue(c); + target[3] = (byte)redValue(c); + } + x++; + } + } + } + return true; +} + +} // End of namespace Sludge diff --git a/engines/sludge/bytearray.h b/engines/sludge/bytearray.h new file mode 100644 index 0000000000..22bcc76bc0 --- /dev/null +++ b/engines/sludge/bytearray.h @@ -0,0 +1,48 @@ +/* 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 PRINCE_MHWANH_H +#define PRINCE_MHWANH_H + +#include "image/image_decoder.h" +#include "graphics/surface.h" + +namespace Sludge { + +class ByteArrayDecoder : public Image::ImageDecoder { + +public: + ByteArrayDecoder(); + virtual ~ByteArrayDecoder(); + + // ImageDecoder API + void destroy(); + virtual bool loadStream(Common::SeekableReadStream &stream); + virtual Graphics::Surface *getSurface() const { return _surface; } + +private: + Graphics::Surface *_surface; +}; + +} // End of namespace Sludge + +#endif diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp index 5e9a0f11ae..cf0c7f315f 100644 --- a/engines/sludge/main_loop.cpp +++ b/engines/sludge/main_loop.cpp @@ -75,6 +75,7 @@ #include "helpers.h" #include "graphics/surface.h" #include "common/debug.h" +#include "sludge.h" namespace Sludge { @@ -481,7 +482,6 @@ int main_loop(char *filename) g_system->copyRectToScreen(backdropSurface.getPixels(), backdropSurface.pitch, 0, 0, backdropSurface.w, backdropSurface.h); - //g_system->getPaletteManager()->setPalette(_image->getPalette(), 0, 256); g_system->updateScreen(); g_system->delayMillis(100); #if 0 diff --git a/engines/sludge/module.mk b/engines/sludge/module.mk index bad7f3589c..5e62f5af2d 100644 --- a/engines/sludge/module.mk +++ b/engines/sludge/module.mk @@ -4,6 +4,7 @@ MODULE_OBJS := \ backdrop.o \ bg_effects.o \ builtin.o \ + bytearray.o \ console.o \ cursors.o \ debug.o \ diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp index ea9dc57afc..86c4980b71 100644 --- a/engines/sludge/sludge.cpp +++ b/engines/sludge/sludge.cpp @@ -64,7 +64,8 @@ SludgeEngine::~SludgeEngine() { Common::Error SludgeEngine::run() { // init graphics - initGraphics(640, 480, false); + Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); + initGraphics(640, 480, false, &format); // create console _console = new SludgeConsole(this); |