aboutsummaryrefslogtreecommitdiff
path: root/engines/sludge
diff options
context:
space:
mode:
authoryinsimei2017-05-31 01:11:28 +0200
committerEugene Sandulenko2017-07-13 18:27:45 +0200
commit786e4c3dc3ce834002253f8c280826108f9a3225 (patch)
tree4e1e51e428e039b161bd4db45e0fe2a4dfda9185 /engines/sludge
parent8c59f8deac6da7fd3b46234b70ca1cea428ca1f5 (diff)
downloadscummvm-rg350-786e4c3dc3ce834002253f8c280826108f9a3225.tar.gz
scummvm-rg350-786e4c3dc3ce834002253f8c280826108f9a3225.tar.bz2
scummvm-rg350-786e4c3dc3ce834002253f8c280826108f9a3225.zip
SLUDGE: Refactor image loading function and apply in backdrop
Diffstat (limited to 'engines/sludge')
-rw-r--r--engines/sludge/backdrop.cpp600
-rw-r--r--engines/sludge/backdrop.h5
-rw-r--r--engines/sludge/builtin.cpp2
-rw-r--r--engines/sludge/bytearray.cpp90
-rw-r--r--engines/sludge/freeze.cpp2
-rw-r--r--engines/sludge/graphics.h4
-rw-r--r--engines/sludge/imgloader.cpp138
-rw-r--r--engines/sludge/imgloader.h (renamed from engines/sludge/bytearray.h)26
-rw-r--r--engines/sludge/main_loop.cpp2
-rw-r--r--engines/sludge/module.mk2
10 files changed, 223 insertions, 648 deletions
diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index 07f4d35618..35159d07dd 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -60,7 +60,7 @@
#include "graphics/surface.h"
#include "graphics/palette.h"
#include "sludge.h"
-#include "bytearray.h"
+#include "imgloader.h"
namespace Sludge {
@@ -76,11 +76,10 @@ bool backdropExists = false;
GLfloat backdropTexW = 1.0;
GLfloat backdropTexH = 1.0;
-texture lightMap;
-
GLuint snapshotTextureName = 0;
#endif
+texture lightMap;
Graphics::Surface backdropSurface;
float snapTexW = 1.0;
@@ -226,6 +225,8 @@ bool restoreSnapshot(Common::SeekableReadStream *stream) {
}
void killBackDrop() {
+ if (backdropSurface.getPixels())
+ backdropSurface.free();
#if 0
deleteTextures(1, &backdropTextureName);
backdropTextureName = 0;
@@ -234,31 +235,31 @@ void killBackDrop() {
}
void killLightMap() {
+ if (lightMap.surface.getPixels()) {
+ lightMap.surface.free();
+ }
+ lightMapNumber = 0;
#if 0
deleteTextures(1, &lightMap.name);
lightMap.name = 0;
- if (lightMap.data) {
- delete lightMap.data;
- lightMap.data = NULL;
- }
- lightMapNumber = 0;
#endif
}
void killParallax() {
-#if 0
+
while (parallaxStuff) {
parallaxLayer *k = parallaxStuff;
parallaxStuff = k->next;
-
+#if 0
// Now kill the image
deleteTextures(1, &k->textureName);
- delete k->texture;
+#endif
+ k->surface.free();
delete k;
k = NULL;
}
-#endif
+
}
bool reserveBackdrop() {
@@ -302,16 +303,24 @@ bool reserveBackdrop() {
return true;
}
-bool resizeBackdrop(int x, int y) {
+void killAllBackDrop() {
killLightMap();
killBackDrop();
killParallax();
killZBuffer();
+}
+
+bool resizeBackdrop(int x, int y) {
sceneWidth = x;
sceneHeight = y;
return reserveBackdrop();
}
+bool killResizeBackdrop(int x, int y) {
+ killAllBackDrop();
+ return resizeBackdrop(x, y);
+}
+
void loadBackDrop(int fileNum, int x, int y) {
debug(kSludgeDebugGraphics, "Load back drop");
setResourceForFatal(fileNum);
@@ -333,7 +342,6 @@ void loadBackDrop(int fileNum, int x, int y) {
}
void mixBackDrop(int fileNum, int x, int y) {
-#if 0
setResourceForFatal(fileNum);
if (!openFileFromNum(fileNum)) {
fatal("Can't load overlay image");
@@ -345,7 +353,6 @@ void mixBackDrop(int fileNum, int x, int y) {
}
finishAccess();
-#endif
setResourceForFatal(-1);
}
@@ -629,83 +636,25 @@ void drawBackDrop() {
}
bool loadLightMap(int v) {
- int newPicWidth, newPicHeight;
-#if 0
setResourceForFatal(v);
if (!openFileFromNum(v)) return fatal("Can't open light map.");
- long file_pointer = ftell(bigDataFile);
-
- png_structp png_ptr;
- png_infop info_ptr, end_info;
-
- int fileIsPNG = true;
- // Is this a PNG file?
-
- char tmp[10];
- size_t bytes_read = fread(tmp, 1, 8, bigDataFile);
- if (bytes_read != 8 && ferror(bigDataFile)) {
- debugOut("Reading error in loadLightMap.\n");
- }
-
- if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
- // No, it's old-school HSI
- fileIsPNG = false;
- fseek(bigDataFile, file_pointer, SEEK_SET);
-
- newPicWidth = lightMap.w = bigDataFile->readUint16BE();
- newPicHeight = lightMap.h = bigDataFile->readUint16BE();
- } else {
- // Read the PNG header
-
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr) {
- return false;
- }
-
- info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr) {
- png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
- return false;
- }
-
- end_info = png_create_info_struct(png_ptr);
- if (!end_info) {
- png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
- return false;
- }
- png_init_io(png_ptr, bigDataFile); // Tell libpng which file to read
- png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
-
- png_read_info(png_ptr, info_ptr);
-
- png_uint_32 width, height;
- int bit_depth, color_type, interlace_type, compression_type, filter_method;
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
-
- newPicWidth = lightMap.w = width;
- newPicHeight = lightMap.h = height;
-
- if (bit_depth < 8) png_set_packing(png_ptr);
- png_set_expand(png_ptr);
- if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
- if (bit_depth == 16) png_set_strip_16(png_ptr);
-
- png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
-
- png_read_update_info(png_ptr, info_ptr);
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+ killLightMap();
+ lightMapNumber = v;
- //int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+ if (!ImgLoader::loadImage(bigDataFile, &lightMap.surface))
+ return false;
- }
+ int newPicWidth = lightMap.surface.w;
+ int newPicHeight = lightMap.surface.h;
if (lightMapMode == LIGHTMAPMODE_HOTSPOT) {
- if (lightMap.w != sceneWidth || lightMap.h != sceneHeight) {
+ if (lightMap.surface.w != sceneWidth || lightMap.surface.h != sceneHeight) {
return fatal("Light map width and height don't match scene width and height. That is required for lightmaps in HOTSPOT mode.");
}
}
+#if 0
if (!NPOT_textures) {
newPicWidth = getNextPOT(lightMap.w);
newPicHeight = getNextPOT(lightMap.h);
@@ -715,54 +664,11 @@ bool loadLightMap(int v) {
lightMap.texW = 1.0;
lightMap.texH = 1.0;
}
+#endif
- killLightMap();
- lightMapNumber = v;
#if 0
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
#endif
- if (lightMap.data) delete [] lightMap.data;
-
- lightMap.data = new GLubyte [newPicWidth * newPicHeight * 4];
- if (!lightMap.data) {
- return fatal("Out of memory loading light map.");
- }
-
- int t1, t2, n;
- unsigned short c;
- GLubyte *target;
-
- if (fileIsPNG) {
- unsigned char *row_pointers[lightMap.h];
- for (int i = 0; i < lightMap.h; i++)
- row_pointers[i] = lightMap.data + 4 * i * newPicWidth;
-
- png_read_image(png_ptr, (png_byte **) row_pointers);
- png_read_end(png_ptr, NULL);
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
- } else {
-
- for (t2 = 0; t2 < lightMap.h; t2 ++) {
- t1 = 0;
- while (t1 < lightMap.w) {
- c = (unsigned short)bigDataFile->readUint16BE();
- if (c & 32) {
- n = fgetc(bigDataFile) + 1;
- c -= 32;
- } else {
- n = 1;
- }
- while (n --) {
- target = lightMap.data + 4 * newPicWidth * t2 + t1 * 4;
- target[0] = (GLubyte) redValue(c);
- target[1] = (GLubyte) greenValue(c);
- target[2] = (GLubyte) blueValue(c);
- target[3] = (GLubyte) 255;
- t1++;
- }
- }
- }
- }
#if 0
if (!lightMap.name) glGenTextures(1, &lightMap.name);
glBindTexture(GL_TEXTURE_2D, lightMap.name);
@@ -775,7 +681,6 @@ bool loadLightMap(int v) {
#endif
finishAccess();
-#endif
setResourceForFatal(-1);
return true;
@@ -820,10 +725,7 @@ void reloadParallaxTextures() {
#endif
}
-bool loadParallax(unsigned short v, unsigned short fracX,
- unsigned short fracY) {
-
-#if 0
+bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY) {
setResourceForFatal(v);
if (!openFileFromNum(v)) return fatal("Can't open parallax image");
@@ -840,71 +742,8 @@ bool loadParallax(unsigned short v, unsigned short fracX,
int picWidth;
int picHeight;
- long file_pointer = ftell(bigDataFile);
-
- png_structp png_ptr;
- png_infop info_ptr, end_info;
-
- int fileIsPNG = true;
-
- // Is this a PNG file?
-
- char tmp[10];
- size_t bytes_read = fread(tmp, 1, 8, bigDataFile);
- if (bytes_read != 8 && ferror(bigDataFile)) {
- debugOut("Reading error in loadParallax.\n");
- }
- if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
- // No, it's old-school HSI
- fileIsPNG = false;
- fseek(bigDataFile, file_pointer, SEEK_SET);
-
- picWidth = nP->width = bigDataFile->readUint16BE();
- picHeight = nP->height = bigDataFile->readUint16BE();
- } else {
- // Read the PNG header
-
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr) {
- return false;
- }
-
- info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr) {
- png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
- return false;
- }
-
- end_info = png_create_info_struct(png_ptr);
- if (!end_info) {
- png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
- return false;
- }
- png_init_io(png_ptr, bigDataFile); // Tell libpng which file to read
- png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
-
- png_read_info(png_ptr, info_ptr);
-
- png_uint_32 width, height;
- int bit_depth, color_type, interlace_type, compression_type, filter_method;
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
-
- picWidth = nP->width = width;
- picHeight = nP->height = height;
-
- if (bit_depth < 8) png_set_packing(png_ptr);
- png_set_expand(png_ptr);
- if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
- if (bit_depth == 16) png_set_strip_16(png_ptr);
-
- png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
-
- png_read_update_info(png_ptr, info_ptr);
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
-
- //int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
-
- }
+ if (!ImgLoader::loadImage(bigDataFile, &nP->surface, false))
+ return false;
if (!NPOT_textures) {
picWidth = getNextPOT(picWidth);
@@ -935,52 +774,7 @@ bool loadParallax(unsigned short v, unsigned short fracX,
nP->wrapT = true;
}
- nP->texture = new GLubyte [picHeight * picWidth * 4];
- if (!checkNew(nP->texture)) return false;
-
- if (fileIsPNG) {
- unsigned char *row_pointers[nP->height];
- for (int i = 0; i < nP->height; i++)
- row_pointers[i] = nP->texture + 4 * i * picWidth;
-
- png_read_image(png_ptr, (png_byte **) row_pointers);
- png_read_end(png_ptr, NULL);
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
- } else {
-
- int t1, t2, n;
- unsigned short c;
- GLubyte *target;
-
- for (t2 = 0; t2 < nP->height; t2 ++) {
- t1 = 0;
- while (t1 < nP->width) {
- c = (unsigned short)bigDataFile->readUint16BE();
- if (c & 32) {
- n = fgetc(bigDataFile) + 1;
- c -= 32;
- } else {
- n = 1;
- }
- while (n--) {
- target = nP->texture + 4 * picWidth * t2 + t1 * 4;
- if (c == 63519 || c == 2015) {
- target[0] = (GLubyte) 0;
- target[1] = (GLubyte) 0;
- target[2] = (GLubyte) 0;
- target[3] = (GLubyte) 0;
- } else {
- target[0] = (GLubyte) redValue(c);
- target[1] = (GLubyte) greenValue(c);
- target[2] = (GLubyte) blueValue(c);
- target[3] = (GLubyte) 255;
- }
- t1 ++;
- }
- }
- }
- }
-
+#if 0
glGenTextures(1, &nP->textureName);
glBindTexture(GL_TEXTURE_2D, nP->textureName);
if (nP->wrapS)
@@ -1001,176 +795,14 @@ bool loadParallax(unsigned short v, unsigned short fracX,
}
texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nP->texture, nP->textureName);
-
- finishAccess();
#endif
+ finishAccess();
setResourceForFatal(-1);
return true;
}
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 at file position: %i", stream->pos());
- ::Image::PNGDecoder png;
- if (!png.loadStream(*stream)) {
- debug(kSludgeDebugGraphics, "Back drop is not a png");
- return false;
- }
- 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;
-#if 0
- long file_pointer = stream->pos();
- png_structp png_ptr;
- png_infop info_ptr, end_info;
-
- char tmp[10];
- size_t bytes_read = stream->read(tmp, 8);
-
- if (bytes_read != 8 && stream->err()) {
- stream->seek(file_pointer, SEEK_SET);
- return false;
- }
-
- if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
- stream->seek(file_pointer, SEEK_SET);
- return false;
- }
-
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr) {
- return false;
- }
-
- info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr) {
- png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
- return false;
- }
-
- end_info = png_create_info_struct(png_ptr);
- if (!end_info) {
- png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
- return false;
- }
- png_init_io(png_ptr, stream); // Tell libpng which file to read
- png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
-
- png_read_info(png_ptr, info_ptr);
-
- png_uint_32 width, height;
- int bit_depth, color_type, interlace_type, compression_type, filter_method;
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
-
- picWidth = realPicWidth = width;
- picHeight = realPicHeight = height;
-
- if (bit_depth < 8) png_set_packing(png_ptr);
- png_set_expand(png_ptr);
- if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
- if (bit_depth == 16) png_set_strip_16(png_ptr);
-
- png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
-
- png_read_update_info(png_ptr, info_ptr);
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
-
- if (reserve) {
- if (!resizeBackdrop(realPicWidth, realPicHeight)) return false;
- }
-
- unsigned char *row_pointers[realPicHeight];
-
- for (int i = 0; i < realPicHeight; i++)
- row_pointers[i] = loadhere + 4 * i * picWidth;
-
- png_read_image(png_ptr, (png_byte **) row_pointers);
- png_read_end(png_ptr, NULL);
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
-#endif
-}
-
-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;
- unsigned short c;
- picWidth = realPicWidth = stream->readUint16BE();
- picHeight = realPicHeight = stream->readUint16BE();
-
- if (reserve) {
- if (!resizeBackdrop(realPicWidth, realPicHeight)) return false;
- }
-
- for (t2 = 0; t2 < realPicHeight; t2 ++) {
- t1 = 0;
- while (t1 < realPicWidth) {
- c = (unsigned short)stream->readUint16BE();
- if (c & 32) {
- n = stream->readByte() + 1;
- c -= 32;
- } else {
- n = 1;
- }
- while (n --) {
- GLubyte *target = loadhere + 4 * picWidth * t2 + t1 * 4;
- if (c == transCol || c == 2015) {
- target[0] = (GLubyte)0;
- target[1] = (GLubyte)0;
- target[2] = (GLubyte)0;
- target[3] = (GLubyte)0;
- } else {
- target[0] = (GLubyte)redValue(c);
- target[1] = (GLubyte)greenValue(c);
- target[2] = (GLubyte)blueValue(c);
- target[3] = (GLubyte)255;
- }
- t1++;
- }
- }
- }
-#endif
-}
-
-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());
- 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;
- }
- }
-
- if (x == IN_THE_CENTRE)
- x = (sceneWidth - realPicWidth) >> 1;
- if (y == IN_THE_CENTRE)
- y = (sceneHeight - realPicHeight) >> 1;
- if (x < 0 || x + realPicWidth > sceneWidth || y < 0
- || y + realPicHeight > sceneHeight) {
- debug(kSludgeDebugGraphics, "Illegal back drop size");
- return false;
- }
- return true;
-}
-
#if 0
void makeGlArray(GLuint &tmpTex, const GLubyte *texture, int picWidth, int picHeight) {
glGenTextures(1, &tmpTex);
@@ -1294,12 +926,29 @@ void renderToTexture(GLuint tmpTex, int x, int y, int picWidth, int picHeight, i
#endif
bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
debug(kSludgeDebugGraphics, "Load HSI");
- int picWidth, picHeight;
- int realPicWidth, realPicHeight;
+ if (reserve) {
+ killAllBackDrop(); // kill all
+ }
+
+ if (!ImgLoader::loadImage(stream, &backdropSurface, reserve))
+ return false;
+
+ int realPicWidth = backdropSurface.w;
+ int realPicHeight = backdropSurface.h;
+
+ if (reserve) { // resize backdrop
+ if (!resizeBackdrop(realPicWidth, realPicHeight)) return false;
+ }
- if (!loadImage(picWidth, picHeight, realPicWidth, realPicHeight, stream, x,
- y, reserve))
+ if (x == IN_THE_CENTRE)
+ x = (sceneWidth - realPicWidth) >> 1;
+ if (y == IN_THE_CENTRE)
+ y = (sceneHeight - realPicHeight) >> 1;
+ if (x < 0 || x + realPicWidth > sceneWidth || y < 0
+ || y + realPicHeight > sceneHeight) {
+ debug(kSludgeDebugGraphics, "Illegal back drop size");
return false;
+ }
#if 0
GLuint tmpTex;
makeGlArray(tmpTex, backdropTexture, picWidth, picHeight);
@@ -1314,80 +963,17 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
}
bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
-#if 0
- int realPicWidth, realPicHeight;
- int picWidth;
- int picHeight;
-
- long file_pointer = stream->pos();
-
- png_structp png_ptr;
- png_infop info_ptr, end_info;
-
- int fileIsPNG = true;
-
- // Is this a PNG file?
- char tmp[10];
- size_t bytes_read = stream->read(tmp, 8);
- if (bytes_read != 8 && stream->err()) {
- debugOut("Reading error in mixHSI.\n");
- }
- if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
- // No, it's old-school HSI
- fileIsPNG = false;
- stream->seek(file_pointer, SEEK_SET);
-
- picWidth = realPicWidth = stream->readUint16BE();
- picHeight = realPicHeight = stream->readUint16BE();
- } else {
- // Read the PNG header
-
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr) {
- return false;
- }
-
- info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr) {
- png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
- return false;
- }
-
- end_info = png_create_info_struct(png_ptr);
- if (!end_info) {
- png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
- return false;
- }
- png_init_io(png_ptr, stream); // Tell libpng which file to read
- png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
-
- png_read_info(png_ptr, info_ptr);
-
- png_uint_32 width, height;
- int bit_depth, color_type, interlace_type, compression_type, filter_method;
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
-
- picWidth = realPicWidth = width;
- picHeight = realPicHeight = height;
-
- if (bit_depth < 8) png_set_packing(png_ptr);
- png_set_expand(png_ptr);
- if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
- if (bit_depth == 16) png_set_strip_16(png_ptr);
-
- png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
-
- png_read_update_info(png_ptr, info_ptr);
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
-
- //int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+ debug(kSludgeDebugGraphics, "Load mixHSI");
+ if (!ImgLoader::loadImage(stream, &backdropSurface, false))
+ return false;
- }
+ int realPicWidth = backdropSurface.w;
+ int realPicHeight = backdropSurface.h;
if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1;
if (y == IN_THE_CENTRE) y = (sceneHeight - realPicHeight) >> 1;
if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) return false;
-
+#if 0
float btx1, tx1;
float btx2, tx2;
float bty1, ty1;
@@ -1429,66 +1015,8 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
btx2, bty2
};
- int t1, t2, n;
- unsigned short c;
- GLubyte *target;
- int32_t transCol = 63519;
-
- if (fileIsPNG) {
- unsigned char *row_pointers[realPicHeight];
- for (int i = 0; i < realPicHeight; i++)
- row_pointers[i] = backdropTexture + 4 * i * picWidth;
-
- png_read_image(png_ptr, (png_byte **) row_pointers);
- png_read_end(png_ptr, NULL);
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
- } else {
- for (t2 = 0; t2 < realPicHeight; t2 ++) {
- t1 = 0;
- while (t1 < realPicWidth) {
- c = (unsigned short)stream->readUint16BE();
- if (c & 32) {
- n = stream->readByte() + 1;
- c -= 32;
- } else {
- n = 1;
- }
- while (n --) {
- target = backdropTexture + 4 * picWidth * t2 + t1 * 4;
- if (c == transCol || c == 2015) {
- target[0] = (GLubyte) 0;
- target[1] = (GLubyte) 0;
- target[2] = (GLubyte) 0;
- target[3] = (GLubyte) 0;
- } else {
- target[0] = (GLubyte) redValue(c);
- target[1] = (GLubyte) greenValue(c);
- target[2] = (GLubyte) blueValue(c);
- target[3] = (GLubyte) 255;
- }
- t1++;
- }
- }
- }
- }
-
GLuint tmpTex;
-
- glGenTextures(1, &tmpTex);
- glBindTexture(GL_TEXTURE_2D, tmpTex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- if (gameSettings.antiAlias < 0) {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- } else {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- }
-
- texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, backdropTexture, tmpTex);
-
- //glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ makeGlArray(tmpTex, backdropTexture, picWidth, picHeight);
setPixelCoords(true);
diff --git a/engines/sludge/backdrop.h b/engines/sludge/backdrop.h
index 9b0832a023..3a88d33ddd 100644
--- a/engines/sludge/backdrop.h
+++ b/engines/sludge/backdrop.h
@@ -51,6 +51,7 @@ struct parallaxLayer {
GLubyte *texture;
GLuint textureName;
#endif
+ Graphics::Surface surface;
int width, height, speedX, speedY;
bool wrapS, wrapT;
unsigned short fileNum, fractionX, fractionY;
@@ -59,7 +60,9 @@ struct parallaxLayer {
parallaxLayer *prev;
};
+void killAllBackDrop();
bool resizeBackdrop(int x, int y);
+bool killResizeBackdrop(int x, int y);
void killBackDrop();
void loadBackDrop(int fileNum, int x, int y);
void mixBackDrop(int fileNum, int x, int y);
@@ -82,9 +85,7 @@ bool getRGBIntoStack(unsigned int x, unsigned int y, stackHandler *sH);
void killLightMap();
bool loadLightMap(int v);
-#if 0
extern texture lightMap;
-#endif
// And background parallax scrolling
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index f35a2bd2e8..5eb52f9d07 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -441,7 +441,7 @@ builtIn(setSceneDimensions) {
trimStack(fun->stack);
if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
trimStack(fun->stack);
- if (resizeBackdrop(x, y)) {
+ if (killResizeBackdrop(x, y)) {
blankScreen(0, 0, x, y);
return BR_CONTINUE;
}
diff --git a/engines/sludge/bytearray.cpp b/engines/sludge/bytearray.cpp
deleted file mode 100644
index 0b28a02f3d..0000000000
--- a/engines/sludge/bytearray.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/* 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/freeze.cpp b/engines/sludge/freeze.cpp
index 7057f6e925..0d797b27d9 100644
--- a/engines/sludge/freeze.cpp
+++ b/engines/sludge/freeze.cpp
@@ -191,7 +191,7 @@ bool freeze() {
zBuffer.tex = NULL;
#endif
// resizeBackdrop kills parallax stuff, light map, z-buffer...
- if (!resizeBackdrop(winWidth, winHeight))
+ if (!killResizeBackdrop(winWidth, winHeight))
return fatal("Can't create new temporary backdrop buffer");
if (!NPOT_textures) {
diff --git a/engines/sludge/graphics.h b/engines/sludge/graphics.h
index 493e6f1454..ba23d72c46 100644
--- a/engines/sludge/graphics.h
+++ b/engines/sludge/graphics.h
@@ -31,6 +31,8 @@
#endif
#endif
+#include "graphics/surface.h"
+
namespace Sludge {
struct texture {
@@ -38,7 +40,7 @@ struct texture {
GLubyte *data;
GLuint name;
#endif
- int w, h;
+ Graphics::Surface surface;
double texW, texH;
};
diff --git a/engines/sludge/imgloader.cpp b/engines/sludge/imgloader.cpp
new file mode 100644
index 0000000000..48617f1ffa
--- /dev/null
+++ b/engines/sludge/imgloader.cpp
@@ -0,0 +1,138 @@
+/* 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 "image/png.h"
+#include "graphics/surface.h"
+
+#include "allfiles.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());
+ 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)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool ImgLoader::loadPNGImage(Common::SeekableReadStream *stream, Graphics::Surface *dest) {
+ ::Image::PNGDecoder png;
+ if (!png.loadStream(*stream))
+ return false;
+ const Graphics::Surface *sourceSurface = png.getSurface();
+ Graphics::Surface *pngSurface = sourceSurface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), png.getPalette());
+ dest->copyFrom(*pngSurface);
+ pngSurface->free();
+ delete pngSurface;
+ 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++;
+ }
+ }
+ }
+ return true;
+}
+
+} // End of namespace Sludge
diff --git a/engines/sludge/bytearray.h b/engines/sludge/imgloader.h
index 22bcc76bc0..2f4d9eea7b 100644
--- a/engines/sludge/bytearray.h
+++ b/engines/sludge/imgloader.h
@@ -20,27 +20,23 @@
*
*/
-#ifndef PRINCE_MHWANH_H
-#define PRINCE_MHWANH_H
+#ifndef SLUDGE_IMGLOADER_H
+#define SLUDGE_IMGLOADER_H
-#include "image/image_decoder.h"
-#include "graphics/surface.h"
+#include "common/file.h"
namespace Sludge {
-class ByteArrayDecoder : public Image::ImageDecoder {
+class ImgLoader {
+protected:
+ ImgLoader() {}
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;
+ static bool loadImage(Common::SeekableReadStream *stream, Graphics::Surface *dest);
+ static bool loadImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, bool reserve);
+ 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);
};
} // End of namespace Sludge
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index cf0c7f315f..2c4648b26c 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -432,7 +432,7 @@ int main_loop(char *filename)
registerWindowForFatal();
- if (!resizeBackdrop(winWidth, winHeight))
+ if (!killResizeBackdrop(winWidth, winHeight))
return fatal("Couldn't allocate memory for backdrop");
blankScreen(0, 0, winWidth, winHeight);
diff --git a/engines/sludge/module.mk b/engines/sludge/module.mk
index 5e62f5af2d..0bba16f7b7 100644
--- a/engines/sludge/module.mk
+++ b/engines/sludge/module.mk
@@ -4,7 +4,6 @@ MODULE_OBJS := \
backdrop.o \
bg_effects.o \
builtin.o \
- bytearray.o \
console.o \
cursors.o \
debug.o \
@@ -15,6 +14,7 @@ MODULE_OBJS := \
fonttext.o \
graphics.o \
helpers.o \
+ imgloader.o \
language.o \
line.o \
loadsave.o \