aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2009-05-29 14:16:51 +0000
committerFilippos Karapetis2009-05-29 14:16:51 +0000
commit7d0c8615068c999ab465475c088f777d18ae3adf (patch)
treed2efe69201d26c1acccda816313ad4f57c81c68b
parent74e87bf05d584b922546b08cc1930c9af3586186 (diff)
downloadscummvm-rg350-7d0c8615068c999ab465475c088f777d18ae3adf.tar.gz
scummvm-rg350-7d0c8615068c999ab465475c088f777d18ae3adf.tar.bz2
scummvm-rg350-7d0c8615068c999ab465475c088f777d18ae3adf.zip
Merged res_view0.cpp and res_view1.cpp
svn-id: r40997
-rw-r--r--engines/sci/gfx/res_view.cpp (renamed from engines/sci/gfx/res_view1.cpp)149
-rw-r--r--engines/sci/gfx/res_view0.cpp182
-rw-r--r--engines/sci/module.mk3
3 files changed, 148 insertions, 186 deletions
diff --git a/engines/sci/gfx/res_view1.cpp b/engines/sci/gfx/res_view.cpp
index 0dcd75675f..f5f151cd3c 100644
--- a/engines/sci/gfx/res_view1.cpp
+++ b/engines/sci/gfx/res_view.cpp
@@ -33,6 +33,10 @@
namespace Sci {
+#define V0_LOOPS_NR_OFFSET 0
+#define V0_FIRST_LOOP_OFFSET 8
+#define V0_MIRROR_LIST_OFFSET 2
+
#define V1_LOOPS_NR_OFFSET 0
#define V1_MIRROR_MASK 2
#define V1_PALETTE_OFFSET 6
@@ -49,6 +53,147 @@ namespace Sci {
#define V2_CELS_NUM 4
#define V2_LOOP_OFFSET 14
+gfx_pixmap_t *gfxr_draw_cel0(int id, int loop, int cel, byte *resource, int size, gfxr_view_t *view, int mirrored) {
+ int xl = READ_LE_UINT16(resource);
+ int yl = READ_LE_UINT16(resource + 2);
+ int pixmap_size = xl * yl;
+ int xdisplace = ((signed char *)resource)[4];
+ int ydisplace = ((signed char *)resource)[5];
+ int color_key = resource[6];
+ int pos = 7;
+ int writepos = mirrored ? xl : 0;
+ int line_base = 0;
+ gfx_pixmap_t *retval = gfx_pixmap_alloc_index_data(gfx_new_pixmap(xl, yl, id, loop, cel));
+ byte *dest = retval->index_data;
+
+ retval->color_key = 255; // Pick something larger than 15
+
+ retval->xoffset = mirrored ? xdisplace : -xdisplace;
+ retval->yoffset = -ydisplace;
+
+ retval->palette = (view && view->palette) ? view->palette->getref() :
+ gfx_sci0_image_pal[sci0_palette]->getref();
+
+ if (xl <= 0 || yl <= 0) {
+ gfx_free_pixmap(retval);
+ GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl);
+ return NULL;
+ }
+
+ if (mirrored) {
+ while (yl && pos < size) {
+ int op = resource[pos++];
+ int count = op >> 4;
+ int color = op & 0xf;
+
+ if (view->flags & GFX_PIXMAP_FLAG_PALETTIZED)
+ color = view->translation[color];
+
+ if (color == color_key)
+ color = retval->color_key;
+
+ while (count) {
+ int pixels = writepos - line_base;
+
+ if (pixels > count)
+ pixels = count;
+
+ writepos -= pixels;
+ memset(dest + writepos, color, pixels);
+ count -= pixels;
+
+ if (writepos == line_base) {
+ yl--;
+ writepos += (xl << 1);
+ line_base += xl;
+ }
+ }
+ }
+ } else {
+
+ while (writepos < pixmap_size && pos < size) {
+ int op = resource[pos++];
+ int count = op >> 4;
+ int color = op & 0xf;
+
+ if (view && (view->flags & GFX_PIXMAP_FLAG_PALETTIZED))
+ color = view->translation[color];
+
+ if (color == color_key)
+ color = retval->color_key;
+
+ if (writepos + count > pixmap_size) {
+ GFXERROR("View %02x:(%d/%d) writes RLE data over its designated end at rel. offset 0x%04x\n", id, loop, cel, pos);
+ return NULL;
+ }
+
+ memset(dest + writepos, color, count);
+ writepos += count;
+ }
+ }
+
+ return retval;
+}
+
+gfxr_view_t *gfxr_draw_view0(int id, byte *resource, int size, int palette) {
+ int i;
+ gfxr_view_t *view;
+ int mirror_bitpos = 1;
+ int mirror_bytepos = V0_MIRROR_LIST_OFFSET;
+ int palette_ofs = READ_LE_UINT16(resource + 6);
+
+ if (size < V0_FIRST_LOOP_OFFSET + 8) {
+ GFXERROR("Attempt to draw empty view %04x\n", id);
+ return NULL;
+ }
+
+ view = (gfxr_view_t *)malloc(sizeof(gfxr_view_t));
+ view->ID = id;
+
+ view->loops_nr = resource[V0_LOOPS_NR_OFFSET];
+
+ // Set palette
+ view->flags = 0;
+ view->palette = gfx_sci0_image_pal[sci0_palette]->getref();
+
+ if ((palette_ofs) && (palette >= 0)) {
+ byte *paldata = resource + palette_ofs + (palette * GFX_SCI0_IMAGE_COLORS_NR);
+
+ for (i = 0; i < GFX_SCI0_IMAGE_COLORS_NR; i++)
+ view->translation[i] = *(paldata++);
+
+ view->flags |= GFX_PIXMAP_FLAG_PALETTIZED;
+ }
+
+ if (view->loops_nr * 2 + V0_FIRST_LOOP_OFFSET > size) {
+ GFXERROR("View %04x: Not enough space in resource to accomodate for the claimed %d loops\n", id, view->loops_nr);
+ free(view);
+ return NULL;
+ }
+
+ view->loops = (gfxr_loop_t*)malloc(sizeof(gfxr_loop_t) * ((view->loops_nr) ? view->loops_nr : 1)); /* Alloc 1 if no loop */
+
+ for (i = 0; i < view->loops_nr; i++) {
+ int loop_offset = READ_LE_UINT16(resource + V0_FIRST_LOOP_OFFSET + (i << 1));
+ int mirrored = resource[mirror_bytepos] & mirror_bitpos;
+
+ if ((mirror_bitpos <<= 1) == 0x100) {
+ mirror_bytepos++;
+ mirror_bitpos = 1;
+ }
+
+ view->loops[i].cels_nr = READ_LE_UINT16(resource + loop_offset);
+ view->loops[i].cels = (gfx_pixmap_t**)calloc(view->loops[i].cels_nr, sizeof(gfx_pixmap_t *));
+
+ for (int j = 0; j < view->loops[i].cels_nr; j++) {
+ int cel_offset = READ_LE_UINT16(resource + loop_offset + 4 + (j << 1));
+ view->loops[i].cels[j] = gfxr_draw_cel0(id, i, j, resource + cel_offset, size - cel_offset, view, mirrored);
+ }
+ }
+
+ return view;
+}
+
#define NEXT_LITERAL_BYTE(n) \
if (literal_pos == runlength_pos) \
runlength_pos += n; \
@@ -186,7 +331,7 @@ gfx_pixmap_t *gfxr_draw_cel1(int id, int loop, int cel, int mirrored, byte *reso
int yl = READ_LE_UINT16(cel_base + 2);
int pixmap_size = xl * yl;
int xdisplace = isSci11 ? READ_LE_UINT16(cel_base + 4) : (int8) cel_base[4];
- int ydisplace = isSci11 ? READ_LE_UINT16(cel_base + 6) : (uint8) cel_base[5];
+ int ydisplace = isSci11 ? READ_LE_UINT16(cel_base + 6) : (int8) cel_base[5];
int runlength_offset = isSci11 ? READ_LE_UINT16(cel_base + 24) : 8;
int literal_offset = isSci11 ? READ_LE_UINT16(cel_base + 28) : 8;
gfx_pixmap_t *retval = gfx_pixmap_alloc_index_data(gfx_new_pixmap(xl, yl, id, loop, cel));
@@ -194,7 +339,7 @@ gfx_pixmap_t *gfxr_draw_cel1(int id, int loop, int cel, int mirrored, byte *reso
int decompress_failed;
retval->color_key = cel_base[isSci11 ? 8 : 6];
- retval->xoffset = (mirrored) ? xdisplace : -xdisplace;
+ retval->xoffset = mirrored ? xdisplace : -xdisplace;
retval->yoffset = -ydisplace;
// FIXME: In LSL5, it seems that the inventory has views without palettes (or we don't load palettes properly)
retval->palette = (view && view->palette) ? view->palette->getref() : NULL;
diff --git a/engines/sci/gfx/res_view0.cpp b/engines/sci/gfx/res_view0.cpp
deleted file mode 100644
index c2d26fa4e4..0000000000
--- a/engines/sci/gfx/res_view0.cpp
+++ /dev/null
@@ -1,182 +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.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include "common/endian.h"
-
-#include "sci/gfx/gfx_system.h"
-#include "sci/gfx/gfx_resource.h"
-#include "sci/gfx/gfx_tools.h"
-
-namespace Sci {
-
-gfx_pixmap_t *gfxr_draw_cel0(int id, int loop, int cel, byte *resource, int size, gfxr_view_t *view, int mirrored) {
- int xl = READ_LE_UINT16(resource);
- int yl = READ_LE_UINT16(resource + 2);
- int xhot = ((signed char *)resource)[4];
- int yhot = ((signed char *)resource)[5];
- int color_key = resource[6];
- int pos = 7;
- int writepos = mirrored ? xl : 0;
- int pixmap_size = xl * yl;
- int line_base = 0;
- gfx_pixmap_t *retval = gfx_pixmap_alloc_index_data(gfx_new_pixmap(xl, yl, id, loop, cel));
- byte *dest = retval->index_data;
-
- retval->color_key = 255; // Pick something larger than 15
-
- retval->xoffset = mirrored ? xhot : -xhot;
- retval->yoffset = -yhot;
-
- if (view) {
- retval->palette = view->palette->getref();
- } else {
- retval->palette = gfx_sci0_image_pal[sci0_palette]->getref();
- }
-
- if (xl <= 0 || yl <= 0) {
- gfx_free_pixmap(retval);
- GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl);
- return NULL;
- }
-
- if (mirrored) {
- while (yl && pos < size) {
- int op = resource[pos++];
- int count = op >> 4;
- int color = op & 0xf;
-
- if (view->flags & GFX_PIXMAP_FLAG_PALETTIZED)
- color = view->translation[color];
-
- if (color == color_key)
- color = retval->color_key;
-
- while (count) {
- int pixels = writepos - line_base;
-
- if (pixels > count)
- pixels = count;
-
- writepos -= pixels;
- memset(dest + writepos, color, pixels);
- count -= pixels;
-
- if (writepos == line_base) {
- yl--;
- writepos += (xl << 1);
- line_base += xl;
- }
- }
- }
- } else {
-
- while (writepos < pixmap_size && pos < size) {
- int op = resource[pos++];
- int count = op >> 4;
- int color = op & 0xf;
-
- if (view && (view->flags & GFX_PIXMAP_FLAG_PALETTIZED))
- color = view->translation[color];
-
- if (color == color_key)
- color = retval->color_key;
-
- if (writepos + count > pixmap_size) {
- GFXERROR("View %02x:(%d/%d) writes RLE data over its designated end at rel. offset 0x%04x\n", id, loop, cel, pos);
- return NULL;
- }
-
- memset(dest + writepos, color, count);
- writepos += count;
- }
- }
-
- return retval;
-}
-
-#define V0_LOOPS_NR_OFFSET 0
-#define V0_FIRST_LOOP_OFFSET 8
-#define V0_MIRROR_LIST_OFFSET 2
-
-gfxr_view_t *gfxr_draw_view0(int id, byte *resource, int size, int palette) {
- int i;
- gfxr_view_t *view;
- int mirror_bitpos = 1;
- int mirror_bytepos = V0_MIRROR_LIST_OFFSET;
- int palette_ofs = READ_LE_UINT16(resource + 6);
-
- if (size < V0_FIRST_LOOP_OFFSET + 8) {
- GFXERROR("Attempt to draw empty view %04x\n", id);
- return NULL;
- }
-
- view = (gfxr_view_t *)malloc(sizeof(gfxr_view_t));
- view->ID = id;
-
- view->loops_nr = resource[V0_LOOPS_NR_OFFSET];
-
- // Set palette
- view->flags = 0;
- view->palette = gfx_sci0_image_pal[sci0_palette]->getref();
-
- if ((palette_ofs) && (palette >= 0)) {
- byte *paldata = resource + palette_ofs + (palette * GFX_SCI0_IMAGE_COLORS_NR);
-
- for (i = 0; i < GFX_SCI0_IMAGE_COLORS_NR; i++)
- view->translation[i] = *(paldata++);
-
- view->flags |= GFX_PIXMAP_FLAG_PALETTIZED;
- }
-
- if (view->loops_nr * 2 + V0_FIRST_LOOP_OFFSET > size) {
- GFXERROR("View %04x: Not enough space in resource to accomodate for the claimed %d loops\n", id, view->loops_nr);
- free(view);
- return NULL;
- }
-
- view->loops = (gfxr_loop_t*)malloc(sizeof(gfxr_loop_t) * ((view->loops_nr) ? view->loops_nr : 1)); /* Alloc 1 if no loop */
-
- for (i = 0; i < view->loops_nr; i++) {
- int loop_offset = READ_LE_UINT16(resource + V0_FIRST_LOOP_OFFSET + (i << 1));
- int mirrored = resource[mirror_bytepos] & mirror_bitpos;
-
- if ((mirror_bitpos <<= 1) == 0x100) {
- mirror_bytepos++;
- mirror_bitpos = 1;
- }
-
- view->loops[i].cels_nr = READ_LE_UINT16(resource + loop_offset);
- view->loops[i].cels = (gfx_pixmap_t**)calloc(view->loops[i].cels_nr, sizeof(gfx_pixmap_t *));
-
- for (int j = 0; j < view->loops[i].cels_nr; j++) {
- int cel_offset = READ_LE_UINT16(resource + loop_offset + 4 + (j << 1));
- view->loops[i].cels[j] = gfxr_draw_cel0(id, i, j, resource + cel_offset, size - cel_offset, view, mirrored);
- }
- }
-
- return view;
-}
-
-} // End of namespace Sci
diff --git a/engines/sci/module.mk b/engines/sci/module.mk
index 6309f9bcb3..5d217e8a42 100644
--- a/engines/sci/module.mk
+++ b/engines/sci/module.mk
@@ -54,8 +54,7 @@ MODULE_OBJS = \
gfx/res_font.o \
gfx/res_pal.o \
gfx/res_pic.o \
- gfx/res_view0.o \
- gfx/res_view1.o \
+ gfx/res_view.o \
gfx/seq_decoder.o \
sfx/core.o \
sfx/iterator.o \