diff options
author | yinsimei | 2017-06-01 00:50:06 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2017-07-13 18:27:45 +0200 |
commit | cfe2e637937321f2a634e1b016622a0fb8e2582d (patch) | |
tree | 01fbd1816816dceb81c8979cb607914a93e22526 | |
parent | 786e4c3dc3ce834002253f8c280826108f9a3225 (diff) | |
download | scummvm-rg350-cfe2e637937321f2a634e1b016622a0fb8e2582d.tar.gz scummvm-rg350-cfe2e637937321f2a634e1b016622a0fb8e2582d.tar.bz2 scummvm-rg350-cfe2e637937321f2a634e1b016622a0fb8e2582d.zip |
SLUDGE: refactor HSIDecoder out of Imgloader
-rw-r--r-- | engines/sludge/backdrop.cpp | 22 | ||||
-rw-r--r-- | engines/sludge/backdrop.h | 12 | ||||
-rw-r--r-- | engines/sludge/hsi.cpp | 90 | ||||
-rw-r--r-- | engines/sludge/hsi.h | 49 | ||||
-rw-r--r-- | engines/sludge/imgloader.cpp | 88 | ||||
-rw-r--r-- | engines/sludge/imgloader.h | 6 | ||||
-rw-r--r-- | engines/sludge/module.mk | 1 |
7 files changed, 155 insertions, 113 deletions
diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp index 35159d07dd..a6cf71f407 100644 --- a/engines/sludge/backdrop.cpp +++ b/engines/sludge/backdrop.cpp @@ -19,22 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ -#if 0 -#if defined __unix__ && !(defined __APPLE__) -#include <png.h> -#else -#include <libpng/png.h> -#endif - -#include <stdlib.h> -#include <stdint.h> - -#if !defined(HAVE_GLES2) -#include "GLee.h" -#else -#include <GLES2/gl2.h> -#endif -#endif #include "allfiles.h" #include "debug.h" @@ -742,7 +726,7 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY) int picWidth; int picHeight; - if (!ImgLoader::loadImage(bigDataFile, &nP->surface, false)) + if (!ImgLoader::loadImage(bigDataFile, &nP->surface, 0)) return false; if (!NPOT_textures) { @@ -930,7 +914,7 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) { killAllBackDrop(); // kill all } - if (!ImgLoader::loadImage(stream, &backdropSurface, reserve)) + if (!ImgLoader::loadImage(stream, &backdropSurface, (int)reserve)) return false; int realPicWidth = backdropSurface.w; @@ -964,7 +948,7 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) { bool mixHSI(Common::SeekableReadStream *stream, int x, int y) { debug(kSludgeDebugGraphics, "Load mixHSI"); - if (!ImgLoader::loadImage(stream, &backdropSurface, false)) + if (!ImgLoader::loadImage(stream, &backdropSurface, 0)) return false; int realPicWidth = backdropSurface.w; diff --git a/engines/sludge/backdrop.h b/engines/sludge/backdrop.h index 3a88d33ddd..01f21b09bd 100644 --- a/engines/sludge/backdrop.h +++ b/engines/sludge/backdrop.h @@ -23,14 +23,6 @@ #ifndef SLUDGE_BACKDROP_H #define SLUDGE_BACKDROP_H -#if 0 -#if !defined(HAVE_GLES2) -#include "GLee.h" -#else -#include <GLES2/gl2.h> -#endif -#endif - #include "variable.h" #include "graphics.h" @@ -47,10 +39,6 @@ extern unsigned int winWidth, winHeight, sceneWidth, sceneHeight; extern int lightMapMode; struct parallaxLayer { -#if 0 - GLubyte *texture; - GLuint textureName; -#endif Graphics::Surface surface; int width, height, speedX, speedY; bool wrapS, wrapT; diff --git a/engines/sludge/hsi.cpp b/engines/sludge/hsi.cpp new file mode 100644 index 0000000000..5281ff7e2c --- /dev/null +++ b/engines/sludge/hsi.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/debug.h" +#include "common/stream.h" + +#include "graphics/surface.h" + +#include "colours.h" +#include "hsi.h" +#include "sludge.h" + +namespace Sludge { + +HSIDecoder::HSIDecoder() : _surface(nullptr), _reserve(-1) { +} + +HSIDecoder::~HSIDecoder() { + destroy(); +} + +void HSIDecoder::destroy() { + if (_surface != nullptr) { + _surface->free(); + delete _surface; + _surface = nullptr; + } +} + +bool HSIDecoder::loadStream(Common::SeekableReadStream &stream) { + destroy(); + int32_t transCol = _reserve > 0 ? -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 (_reserve != -1 && (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/hsi.h b/engines/sludge/hsi.h new file mode 100644 index 0000000000..a1bef307bd --- /dev/null +++ b/engines/sludge/hsi.h @@ -0,0 +1,49 @@ +/* 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 SLUDGE_HSI_H +#define SLUDGE_HSI_H + +#include "image/image_decoder.h" + +#include "graphics/surface.h" + +namespace Sludge { + +class HSIDecoder : public Image::ImageDecoder { +public: + HSIDecoder(); + virtual ~HSIDecoder(); + + // ImageDecoder API + void destroy(); + virtual bool loadStream(Common::SeekableReadStream &stream); + virtual Graphics::Surface *getSurface() const { return _surface; } + void setReserve(bool reserve) { _reserve = reserve; } + +private: + Graphics::Surface *_surface; + int _reserve; +}; + +} // End of namespace Sludge + +#endif diff --git a/engines/sludge/imgloader.cpp b/engines/sludge/imgloader.cpp index 48617f1ffa..f76c7b6baa 100644 --- a/engines/sludge/imgloader.cpp +++ b/engines/sludge/imgloader.cpp @@ -26,30 +26,19 @@ #include "graphics/surface.h" #include "allfiles.h" +#include "hsi.h" #include "imgloader.h" #include "colours.h" #include "sludge.h" namespace Sludge { -bool ImgLoader::loadImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, bool reserve) { - debug("Loading image at position: %i", stream->pos()); +bool ImgLoader::loadImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, int reserve) { + debug(kSludgeDebugDataLoad, "Loading image at position: %i", stream->pos()); int32 start_ptr = stream->pos(); if (!loadPNGImage(stream, dest)) { stream->seek(start_ptr); - if (!loadReserveImage(stream, dest, reserve)) { - return false; - } - } - return true; -} - -bool ImgLoader::loadImage(Common::SeekableReadStream *stream, Graphics::Surface *dest) { - debug("Loading image at position: %i", stream->pos()); - int32 start_ptr = stream->pos(); - if (!loadPNGImage(stream, dest)) { - stream->seek(start_ptr); - if (!loadOtherImage(stream, dest)) { + if (!loadHSIImage(stream, dest, reserve)) { return false; } } @@ -68,70 +57,13 @@ bool ImgLoader::loadPNGImage(Common::SeekableReadStream *stream, Graphics::Surfa return true; } -bool ImgLoader::loadReserveImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, int reserve) { - debug("Loading image at position: %i", stream->pos()); - int32_t transCol = reserve ? -1 : 63519; - int n; - uint16 width = stream->readUint16BE(); - uint16 height = stream->readUint16BE(); - - dest->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 *)dest->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; -} - -bool ImgLoader::loadOtherImage(Common::SeekableReadStream *stream, Graphics::Surface *dest) { - int n; - uint16 width = stream->readUint16BE(); - uint16 height = stream->readUint16BE(); - - dest->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 *)dest->getBasePtr(x, y); - target[0] = (byte)255; - target[1] = (byte)blueValue(c); - target[2] = (byte)greenValue(c); - target[3] = (byte)redValue(c); - x++; - } - } +bool ImgLoader::loadHSIImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, int reserve) { + HSIDecoder hsiDecoder; + hsiDecoder.setReserve(reserve); + if (!hsiDecoder.loadStream(*stream)) { + return false; } + dest->copyFrom(*(hsiDecoder.getSurface())); return true; } diff --git a/engines/sludge/imgloader.h b/engines/sludge/imgloader.h index 2f4d9eea7b..35529f516c 100644 --- a/engines/sludge/imgloader.h +++ b/engines/sludge/imgloader.h @@ -32,11 +32,9 @@ protected: ImgLoader() {} public: - static bool loadImage(Common::SeekableReadStream *stream, Graphics::Surface *dest); - static bool loadImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, bool reserve); + static bool loadImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, int reserve = -1); static bool loadPNGImage(Common::SeekableReadStream *stream, Graphics::Surface *dest); - static bool loadReserveImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, int reserve); - static bool loadOtherImage(Common::SeekableReadStream *stream, Graphics::Surface *dest); + static bool loadHSIImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, int reserve = -1); }; } // End of namespace Sludge diff --git a/engines/sludge/module.mk b/engines/sludge/module.mk index 0bba16f7b7..726cd6b115 100644 --- a/engines/sludge/module.mk +++ b/engines/sludge/module.mk @@ -14,6 +14,7 @@ MODULE_OBJS := \ fonttext.o \ graphics.o \ helpers.o \ + hsi.o \ imgloader.o \ language.o \ line.o \ |