aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/gfx/res_pal.cpp
diff options
context:
space:
mode:
authorFilippos Karapetis2009-03-18 13:24:47 +0000
committerFilippos Karapetis2009-03-18 13:24:47 +0000
commitbc37ec4ce13e2742b3fcaa2d8cd2b3a6224c0c72 (patch)
tree53327cac2a06f3809e0d50b240f70548f241b6ca /engines/sci/gfx/res_pal.cpp
parentabc842b677fcc6f34e87af5aca3fc626f1552d16 (diff)
downloadscummvm-rg350-bc37ec4ce13e2742b3fcaa2d8cd2b3a6224c0c72.tar.gz
scummvm-rg350-bc37ec4ce13e2742b3fcaa2d8cd2b3a6224c0c72.tar.bz2
scummvm-rg350-bc37ec4ce13e2742b3fcaa2d8cd2b3a6224c0c72.zip
Renamed resmgr.cpp -> gfx_resmgr.cpp
Moved all files from gfx/resource/* to gfx/* svn-id: r39515
Diffstat (limited to 'engines/sci/gfx/res_pal.cpp')
-rw-r--r--engines/sci/gfx/res_pal.cpp147
1 files changed, 147 insertions, 0 deletions
diff --git a/engines/sci/gfx/res_pal.cpp b/engines/sci/gfx/res_pal.cpp
new file mode 100644
index 0000000000..74fb8629b7
--- /dev/null
+++ b/engines/sci/gfx/res_pal.cpp
@@ -0,0 +1,147 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+/* SCI1 palette resource defrobnicator */
+
+#include "common/file.h"
+#include "sci/sci_memory.h"
+#include "sci/gfx/gfx_system.h"
+#include "sci/gfx/gfx_resource.h"
+
+namespace Sci {
+
+#define MAX_COLORS 256
+#define PALETTE_START 260
+#define COLOR_OK 0x01
+
+#define SCI_PAL_FORMAT_VARIABLE_FLAGS 0
+#define SCI_PAL_FORMAT_CONSTANT_FLAGS 1
+
+Palette *gfxr_read_pal11(int id, byte *resource, int size) {
+ int start_color = resource[25];
+ int format = resource[32];
+ int entry_size = 0;
+ Palette *retval;
+ byte *pal_data = resource + 37;
+ int _colors_nr = READ_LE_UINT16(resource + 29);
+ int i;
+
+ switch (format) {
+ case SCI_PAL_FORMAT_VARIABLE_FLAGS :
+ entry_size = 4;
+ break;
+ case SCI_PAL_FORMAT_CONSTANT_FLAGS :
+ entry_size = 3;
+ break;
+ }
+
+ retval = new Palette(_colors_nr + start_color);
+ char buf[100];
+ sprintf(buf, "read_pal11 (id %d)", id);
+ retval->name = buf;
+
+ for (i = 0; i < start_color; i ++) {
+ retval->setColor(i, 0, 0, 0);
+ }
+ for (i = start_color; i < start_color + _colors_nr; i ++) {
+ switch (format) {
+ case SCI_PAL_FORMAT_CONSTANT_FLAGS:
+ retval->setColor(i, pal_data[0], pal_data[1], pal_data[2]);
+ break;
+ case SCI_PAL_FORMAT_VARIABLE_FLAGS:
+ retval->setColor(i, pal_data[1], pal_data[2], pal_data[3]);
+ break;
+ }
+ pal_data += entry_size;
+ }
+
+ return retval;
+}
+
+Palette *gfxr_read_pal1(int id, byte *resource, int size) {
+ int counter = 0;
+ int pos;
+ unsigned int colors[MAX_COLORS] = {0};
+
+ if (size < PALETTE_START + 4) {
+ GFXERROR("Palette resource too small in %04x\n", id);
+ return NULL;
+ }
+
+ pos = PALETTE_START;
+
+ while (pos < size/* && resource[pos] == COLOR_OK && counter < MAX_COLORS*/) {
+ int color = resource[pos] | (resource[pos + 1] << 8) | (resource[pos + 2] << 16) | (resource[pos + 3] << 24);
+
+ pos += 4;
+
+ colors[counter++] = color;
+ }
+
+ if (counter < MAX_COLORS && resource[pos] != COLOR_OK) {
+ GFXERROR("Palette %04x uses unknown palette color prefix 0x%02x at offset 0x%04x\n", id, resource[pos], pos);
+ return NULL;
+ }
+
+ if (counter < MAX_COLORS) {
+ GFXERROR("Palette %04x ends prematurely\n", id);
+ return NULL;
+ }
+
+ Palette *retval = new Palette(counter);
+ char buf[100];
+ sprintf(buf, "read_pal1 (id %d)", id);
+ retval->name = buf;
+
+ for (pos = 0; pos < counter; pos++) {
+ unsigned int color = colors[pos];
+ retval->setColor(pos, (color >> 8) & 0xff, (color >> 16) & 0xff, (color >> 24) & 0xff);
+ }
+
+ return retval;
+}
+
+Palette *gfxr_read_pal1_amiga(Common::File &file) {
+ int i;
+ Palette *retval = new Palette(32);
+
+ for (i = 0; i < 32; i++) {
+ int b1, b2;
+
+ b1 = file.readByte();
+ b2 = file.readByte();
+
+ if (b1 == EOF || b2 == EOF) {
+ GFXERROR("Palette file ends prematurely\n");
+ return NULL;
+ }
+
+ retval->setColor(i, (b1 & 0xf) * 0x11, ((b2 & 0xf0) >> 4) * 0x11, (b2 & 0xf) * 0x11);
+ }
+
+ return retval;
+}
+
+} // End of namespace Sci