aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorjohndoe1232011-06-24 23:25:01 +0000
committerWillem Jan Palenstijn2013-05-08 20:30:57 +0200
commit7d5d5f139f5d2ac747f1440171f4cc42735541a7 (patch)
treea709d6c5ab93ed510e3084e6d011a64788668aa3 /engines
parent70d20096c16b983d254366b82e725ce14e5b195c (diff)
downloadscummvm-rg350-7d5d5f139f5d2ac747f1440171f4cc42735541a7.tar.gz
scummvm-rg350-7d5d5f139f5d2ac747f1440171f4cc42735541a7.tar.bz2
scummvm-rg350-7d5d5f139f5d2ac747f1440171f4cc42735541a7.zip
NEVERHOOD: Start with graphics code (bitmap parsing and rle decompression)
Diffstat (limited to 'engines')
-rw-r--r--engines/neverhood/graphics.cpp108
-rw-r--r--engines/neverhood/graphics.h45
-rw-r--r--engines/neverhood/module.mk1
-rw-r--r--engines/neverhood/neverhood.cpp49
-rw-r--r--engines/neverhood/neverhood.h4
5 files changed, 195 insertions, 12 deletions
diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp
new file mode 100644
index 0000000000..8f8849be41
--- /dev/null
+++ b/engines/neverhood/graphics.cpp
@@ -0,0 +1,108 @@
+/* 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 "neverhood/graphics.h"
+
+namespace Neverhood {
+
+void parseBitmapResource(byte *sprite, bool *rle, NDimensions *dimensions, NUnknown *unknown, byte **palette, byte **pixels) {
+
+ uint16 flags;
+
+ flags = READ_LE_UINT16(sprite);
+ sprite += 2;
+
+ if (rle)
+ *rle = flags & 1;
+
+ if (flags & 2) {
+ if (dimensions) {
+ dimensions->width = READ_LE_UINT16(sprite);
+ dimensions->height = READ_LE_UINT16(sprite + 2);
+ }
+ sprite += 4;
+ } else if (dimensions) {
+ dimensions->width = 1;
+ dimensions->height = 1;
+ }
+
+ if (flags & 4) {
+ if (unknown) {
+ unknown->unk1 = READ_LE_UINT16(sprite);
+ unknown->unk2 = READ_LE_UINT16(sprite + 2);
+ }
+ sprite += 4;
+ } else if (unknown) {
+ unknown->unk1 = 0;
+ unknown->unk2 = 0;
+ }
+
+ if (flags & 8) {
+ if (palette)
+ *palette = sprite;
+ sprite += 1024;
+ } else if (palette)
+ *palette = NULL;
+
+ if (flags & 0x10) {
+ if (pixels)
+ *pixels = sprite;
+ } else if (pixels)
+ *pixels = NULL;
+
+}
+
+void unpackSpriteRle(byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY) {
+
+ // TODO: Flip
+
+ int16 rows, chunks;
+ int16 skip, copy;
+
+ rows = READ_LE_UINT16(source);
+ chunks = READ_LE_UINT16(source + 2);
+ source += 4;
+
+ do {
+ if (chunks == 0) {
+ dest += rows * destPitch;
+ } else {
+ while (rows-- > 0) {
+ uint16 rowChunks = chunks;
+ while (rowChunks-- > 0) {
+ skip = READ_LE_UINT16(source);
+ copy = READ_LE_UINT16(source + 2);
+ source += 4;
+ memcpy(dest + skip, source, copy);
+ source += copy;
+ }
+ dest += destPitch;
+ }
+ }
+ rows = READ_LE_UINT16(source);
+ chunks = READ_LE_UINT16(source + 2);
+ source += 4;
+ } while (rows > 0);
+
+}
+
+} // End of namespace Neverhood
diff --git a/engines/neverhood/graphics.h b/engines/neverhood/graphics.h
new file mode 100644
index 0000000000..8cac5a5af0
--- /dev/null
+++ b/engines/neverhood/graphics.h
@@ -0,0 +1,45 @@
+/* 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 NEVERHOOD_GRAPHICS_H
+#define NEVERHOOD_GRAPHICS_H
+
+#include "common/array.h"
+#include "common/file.h"
+#include "neverhood/neverhood.h"
+
+namespace Neverhood {
+
+struct NDimensions {
+ int16 width, height;
+};
+
+struct NUnknown {
+ int16 unk1, unk2;
+};
+
+void parseBitmapResource(byte *sprite, bool *rle, NDimensions *dimensions, NUnknown *unknown, byte **palette, byte **pixels);
+void unpackSpriteRle(byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY);
+
+} // End of namespace Neverhood
+
+#endif /* NEVERHOOD_GRAPHICS_H */
diff --git a/engines/neverhood/module.mk b/engines/neverhood/module.mk
index bdb6d8684e..57491e6b72 100644
--- a/engines/neverhood/module.mk
+++ b/engines/neverhood/module.mk
@@ -3,6 +3,7 @@ MODULE := engines/neverhood
MODULE_OBJS = \
blbarchive.o \
detection.o \
+ graphics.o \
neverhood.o \
resourceman.o
diff --git a/engines/neverhood/neverhood.cpp b/engines/neverhood/neverhood.cpp
index 9254f886c0..fa781fba1e 100644
--- a/engines/neverhood/neverhood.cpp
+++ b/engines/neverhood/neverhood.cpp
@@ -38,6 +38,7 @@
#include "neverhood/neverhood.h"
#include "neverhood/blbarchive.h"
+#include "neverhood/graphics.h"
#include "neverhood/resourceman.h"
namespace Neverhood {
@@ -68,26 +69,50 @@ Common::Error NeverhoodEngine::run() {
_isSaveAllowed = false;
+ _res = new ResourceMan();
+ _res->addArchive("a.blb");
+ _res->addArchive("c.blb");
+ _res->addArchive("hd.blb");
+ _res->addArchive("i.blb");
+ _res->addArchive("m.blb");
+ _res->addArchive("s.blb");
+ _res->addArchive("t.blb");
+
#if 0
BlbArchive *blb = new BlbArchive();
blb->open("m.blb");
delete blb;
#endif
-#if 1
- ResourceMan *res = new ResourceMan();
- res->addArchive("a.blb");
- res->addArchive("c.blb");
- res->addArchive("hd.blb");
- res->addArchive("i.blb");
- res->addArchive("m.blb");
- res->addArchive("s.blb");
- res->addArchive("t.blb");
-
- ResourceFileEntry *r = res->findEntry(0x50A80517);
-
+#if 0
+ ResourceFileEntry *r = _res->findEntry(0x50A80517);
#endif
+#if 0
+ int resourceHandle = _res->useResource(0x0CA04202);
+ debug("resourceHandle = %d", resourceHandle);
+ byte *data = _res->loadResource(resourceHandle);
+ bool rle;
+ NDimensions dimensions;
+ NUnknown unknown;
+ byte *palette, *pixels;
+ parseBitmapResource(data, &rle, &dimensions, &unknown, &palette, &pixels);
+ debug("%d, %d", dimensions.width, dimensions.height);
+ byte *rawpixels = new byte[dimensions.width * dimensions.height];
+ memset(rawpixels, 0, dimensions.width * dimensions.height);
+ debug("rle = %d", rle);
+ unpackSpriteRle(pixels, dimensions.width, dimensions.height, rawpixels, dimensions.width, false, false);
+ Common::DumpFile d;
+ d.open("dump.0");
+ d.write(rawpixels, dimensions.width * dimensions.height);
+ d.close();
+ delete[] rawpixels;
+ _res->unloadResource(resourceHandle);
+ _res->unuseResource(resourceHandle);
+#endif
+
+ delete _res;
+
return Common::kNoError;
}
diff --git a/engines/neverhood/neverhood.h b/engines/neverhood/neverhood.h
index 63862dde54..956880fcca 100644
--- a/engines/neverhood/neverhood.h
+++ b/engines/neverhood/neverhood.h
@@ -43,6 +43,8 @@ enum NeverhoodGameFeatures {
struct NeverhoodGameDescription;
+class ResourceMan;
+
class NeverhoodEngine : public ::Engine {
protected:
@@ -66,6 +68,8 @@ public:
Common::KeyCode _keyState;
uint16 _buttonState;
+ ResourceMan *_res;
+
void updateEvents();
public: