SLUDGE: Add the slusge specific image decoder

This commit is contained in:
yinsimei 2017-05-30 01:30:51 +02:00 committed by Eugene Sandulenko
parent 3ae270f709
commit b920f61a11
6 changed files with 166 additions and 18 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -4,6 +4,7 @@ MODULE_OBJS := \
backdrop.o \
bg_effects.o \
builtin.o \
bytearray.o \
console.o \
cursors.o \
debug.o \

View File

@ -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);