aboutsummaryrefslogtreecommitdiff
path: root/scumm/gfx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scumm/gfx.cpp')
-rw-r--r--scumm/gfx.cpp319
1 files changed, 1 insertions, 318 deletions
diff --git a/scumm/gfx.cpp b/scumm/gfx.cpp
index 921587609e..7481cbf30a 100644
--- a/scumm/gfx.cpp
+++ b/scumm/gfx.cpp
@@ -22,6 +22,7 @@
#include "stdafx.h"
#include "scumm.h"
#include "actor.h"
+#include "bomp.h"
#include "charset.h"
#include "resource.h"
#include "usage_bits.h"
@@ -3243,324 +3244,6 @@ void Scumm::makeCursorColorTransparent(int a) {
updateCursor();
}
-#pragma mark -
-#pragma mark --- Bomp ---
-#pragma mark -
-
-int32 Scumm::bompDecodeLineMode0(const byte *src, byte *line_buffer, int32 size) {
- if (size <= 0)
- return size;
-
- memcpy(line_buffer, src, size);
- return size;
-}
-
-int32 Scumm::bompDecodeLineMode1(const byte *src, byte *line_buffer, int32 size) {
- int32 t_size = READ_LE_UINT16(src) + 2;
- if (size <= 0)
- return t_size;
-
- int len, num;
- byte code, color;
-
- len = size;
- src += 2;
- while (len) {
- code = *src++;
- num = (code >> 1) + 1;
- if (num > len)
- num = len;
- len -= num;
- if (code & 1) {
- color = *src++;
- memset(line_buffer, color, num);
- } else {
- memcpy(line_buffer, src, num);
- src += num;
- }
- line_buffer += num;
- }
- return t_size;
-}
-
-int32 Scumm::bompDecodeLineMode3(const byte *src, byte *line_buffer, int32 size) {
- int32 t_size = READ_LE_UINT16(src) + 2;
- line_buffer += size;
- if (size <= 0)
- return t_size;
-
- int len, num;
- byte code, color;
-
- len = size;
- src += 2;
- while (len) {
- code = *src++;
- num = (code >> 1) + 1;
- if (num > len)
- num = len;
- len -= num;
- line_buffer -= num;
- if (code & 1) {
- color = *src++;
- memset(line_buffer, color, num);
- } else {
- memcpy(line_buffer, src, num);
- src += num;
- }
- }
- return t_size;
-}
-
-void Scumm::bompApplyMask(byte *line_buffer, byte *mask_src, byte bits, int32 size) {
- while(1) {
- byte tmp = *(mask_src++);
- do {
- if (size-- == 0)
- return;
- if (tmp & bits) {
- *(line_buffer) = 255;
- }
- line_buffer++;
- bits >>= 1;
- } while (bits);
- bits = 128;
- }
-}
-
-void Scumm::bompApplyShadow(int shadowMode, const byte *line_buffer, byte *dst, int32 size, byte transparency) const {
- assert(size > 0);
- switch(shadowMode) {
- case 0:
- bompApplyShadow0(line_buffer, dst, size, transparency);
- break;
- case 1:
- bompApplyShadow1(line_buffer, dst, size, transparency);
- break;
- case 3:
- bompApplyShadow3(line_buffer, dst, size, transparency);
- break;
- default:
- error("Unknown shadow mode %d", shadowMode);
- }
-}
-void Scumm::bompApplyShadow0(const byte *line_buffer, byte *dst, int32 size, byte transparency) const {
- while(size-- > 0) {
- byte tmp = *line_buffer++;
- if (tmp != transparency) {
- *dst = tmp;
- }
- dst++;
- }
-}
-
-void Scumm::bompApplyShadow1(const byte *line_buffer, byte *dst, int32 size, byte transparency) const {
- while(size-- > 0) {
- byte tmp = *line_buffer++;
- if (tmp != transparency) {
- if (tmp == 13) {
- tmp = _shadowPalette[*(dst)];
- }
- *dst = tmp;
- }
- dst++;
- }
-}
-
-void Scumm::bompApplyShadow3(const byte *line_buffer, byte *dst, int32 size, byte transparency) const {
- while(size-- > 0) {
- byte tmp = *line_buffer++;
- if (tmp != transparency) {
- if (tmp < 8) {
- tmp = _shadowPalette[*dst + (tmp << 8)];
- }
- *dst = tmp;
- }
- dst++;
- }
-}
-
-void Scumm::bompApplyActorPalette(byte *line_buffer, int32 size) const {
- if (_bompActorPalettePtr != 0) {
- *(_bompActorPalettePtr + 255) = 255;
- while(1) {
- if (size-- == 0)
- break;
- *line_buffer = *(_bompActorPalettePtr + *line_buffer);
- line_buffer++;
- }
- }
-}
-
-void Scumm::bompScaleFuncX(byte *line_buffer, byte *scaling_x_ptr, byte skip, int32 size) {
- byte * line_ptr1 = line_buffer;
- byte * line_ptr2 = line_buffer;
-
- byte tmp = *(scaling_x_ptr++);
-
- while (size--) {
- if ((skip & tmp) == 0) {
- *(line_ptr1++) = *(line_ptr2);
- }
- line_ptr2++;
- skip >>= 1;
- if (skip == 0) {
- skip = 128;
- tmp = *(scaling_x_ptr++);
- }
- }
-}
-
-void Scumm::decompressBomp(byte *dst, const byte *src, int w, int h) {
- int len, num;
- byte code, color;
-
- do {
- len = w;
- src += 2;
- while (len) {
- code = *src++;
- num = (code >> 1) + 1;
- if (num > len)
- num = len;
- len -= num;
- if (code & 1) {
- color = *src++;
- memset(dst, color, num);
- } else {
- memcpy(dst, src, num);
- src += num;
- }
- dst += num;
- }
- } while (--h);
-}
-
-void Scumm::drawBomp(const BompDrawData &bd, int decode_mode, int mask) {
- byte skip_y = 128;
- byte skip_y_new = 0;
- byte bits;
- byte *mask_out = 0;
- byte *charset_mask;
- byte tmp;
- int32 clip_left, clip_right, clip_top, clip_bottom, tmp_x, tmp_y, mask_offset, mask_pitch;
- byte *scalingYPtr = bd.scalingYPtr;
-
- if (bd.x < 0) {
- clip_left = -bd.x;
- } else {
- clip_left = 0;
- }
-
- if (bd.y < 0) {
- clip_top = -bd.y;
- } else {
- clip_top = 0;
- }
-
- clip_right = bd.srcwidth - clip_left;
- tmp_x = bd.x + bd.srcwidth;
- if (tmp_x > bd.outwidth) {
- clip_right -= tmp_x - bd.outwidth;
- }
-
- clip_bottom = bd.srcheight;
- tmp_y = bd.y + bd.srcheight;
- if (tmp_y > bd.outheight) {
- clip_bottom -= tmp_y - bd.outheight;
- }
-
- const byte *src = bd.dataptr;
- byte *dst = bd.out + bd.y * bd.outwidth + bd.x + clip_left;
-
- mask_pitch = _screenWidth / 8;
- mask_offset = _screenStartStrip + (bd.y * mask_pitch) + ((bd.x + clip_left) >> 3);
-
- charset_mask = getResourceAddress(rtBuffer, 9) + mask_offset;
- bits = 128 >> ((bd.x + clip_left) & 7);
-
- if (mask == 1) {
- mask_out = bd.maskPtr + mask_offset;
- }
-
- if (mask == 3) {
- if (scalingYPtr != NULL) {
- skip_y_new = *(scalingYPtr++);
- }
-
- if ((clip_right + clip_left) > bd.scaleRight) {
- clip_right = bd.scaleRight - clip_left;
- }
-
- if (clip_bottom > bd.scaleBottom) {
- clip_bottom = bd.scaleBottom;
- }
- }
-
- if ((clip_right <= 0) || (clip_bottom <= 0))
- return;
-
- int32 pos_y = 0;
-
- byte line_buffer[1024];
-
- byte *line_ptr = line_buffer + clip_left;
-
- while(1) {
- switch(decode_mode) {
- case 0:
- src += bompDecodeLineMode0(src, line_buffer, bd.srcwidth);
- break;
- case 1:
- src += bompDecodeLineMode1(src, line_buffer, bd.srcwidth);
- break;
- case 3:
- src += bompDecodeLineMode3(src, line_buffer, bd.srcwidth);
- break;
- default:
- error("Unknown bomp decode_mode %d", decode_mode);
- }
-
- if (mask == 3) {
- if (bd.scale_y != 255) {
- tmp = skip_y_new & skip_y;
- skip_y >>= 1;
- if (skip_y == 0) {
- skip_y = 128;
- skip_y_new = *(scalingYPtr++);
- }
-
- if (tmp != 0)
- continue;
- }
-
- if (bd.scale_x != 255) {
- bompScaleFuncX(line_buffer, bd.scalingXPtr, 128, bd.srcwidth);
- }
- }
-
- if (clip_top > 0) {
- clip_top--;
- } else {
-
- if (mask == 1) {
- bompApplyMask(line_ptr, mask_out, bits, clip_right);
- }
-
- bompApplyMask(line_ptr, charset_mask, bits, clip_right);
- bompApplyActorPalette(line_ptr, clip_right);
- bompApplyShadow(bd.shadowMode, line_ptr, dst, clip_right, 255);
- }
-
- mask_out += mask_pitch;
- charset_mask += mask_pitch;
- pos_y++;
- dst += bd.outwidth;
- if (pos_y >= clip_bottom)
- break;
- }
-}
-
#ifdef __PALM_OS__
#include "scumm_globals.h" // init globals