2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2003-07-28 01:47:41 +00:00
|
|
|
*
|
2007-05-31 20:28:29 +00:00
|
|
|
* Additional copyright for this file:
|
|
|
|
* Copyright (C) 1994-1998 Revolution Software Ltd.
|
|
|
|
*
|
2003-07-28 01:47:41 +00:00
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-07-28 01:47:41 +00:00
|
|
|
*/
|
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
#include "common/endian.h"
|
2005-02-27 16:11:19 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "sword2/sword2.h"
|
2005-02-27 16:11:19 +00:00
|
|
|
#include "sword2/defs.h"
|
2006-02-12 19:33:45 +00:00
|
|
|
#include "sword2/screen.h"
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* This function takes a sprite and creates a mirror image of it.
|
|
|
|
* @param dst destination buffer
|
|
|
|
* @param src source buffer
|
|
|
|
* @param w width of the sprite
|
|
|
|
* @param h height of the sprite
|
|
|
|
*/
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
void Screen::mirrorSprite(byte *dst, byte *src, int16 w, int16 h) {
|
2003-10-15 06:40:31 +00:00
|
|
|
for (int y = 0; y < h; y++) {
|
|
|
|
for (int x = 0; x < w; x++) {
|
2003-09-23 17:24:45 +00:00
|
|
|
*dst++ = *(src + w - x - 1);
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
src += w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
2011-04-14 12:12:27 +00:00
|
|
|
* This function takes a compressed frame of a sprite with up to 256 colors
|
2003-09-28 14:13:57 +00:00
|
|
|
* and decompresses it.
|
2005-02-19 14:02:16 +00:00
|
|
|
* @param dst destination buffer
|
|
|
|
* @param src source buffer
|
2003-09-28 14:13:57 +00:00
|
|
|
* @param decompSize the expected size of the decompressed sprite
|
|
|
|
*/
|
2003-09-23 17:24:45 +00:00
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
int32 Screen::decompressRLE256(byte *dst, byte *src, int32 decompSize) {
|
2003-07-28 01:47:41 +00:00
|
|
|
// PARAMETERS:
|
2003-09-23 17:24:45 +00:00
|
|
|
// source points to the start of the sprite data for input
|
2003-07-28 01:47:41 +00:00
|
|
|
// decompSize gives size of decompressed data in bytes
|
2003-09-23 17:24:45 +00:00
|
|
|
// dest points to start of destination buffer for decompressed
|
2008-01-28 00:14:17 +00:00
|
|
|
// data
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
byte headerByte; // block header byte
|
2005-02-19 14:02:16 +00:00
|
|
|
byte *endDest = dst + decompSize; // pointer to byte after end of decomp buffer
|
2003-07-28 01:47:41 +00:00
|
|
|
int32 rv;
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
while (1) {
|
2003-07-28 01:47:41 +00:00
|
|
|
// FLAT block
|
2003-09-23 17:24:45 +00:00
|
|
|
// read FLAT block header & increment 'scan' to first pixel
|
|
|
|
// of block
|
2005-02-19 14:02:16 +00:00
|
|
|
headerByte = *src++;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// if this isn't a zero-length block
|
|
|
|
if (headerByte) {
|
2005-02-19 14:02:16 +00:00
|
|
|
if (dst + headerByte > endDest) {
|
2003-07-28 01:47:41 +00:00
|
|
|
rv = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-14 12:12:27 +00:00
|
|
|
// set the next 'headerByte' pixels to the next color
|
2003-09-23 17:24:45 +00:00
|
|
|
// at 'source'
|
2005-02-19 14:02:16 +00:00
|
|
|
memset(dst, *src, headerByte);
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// increment destination pointer to just after this
|
|
|
|
// block
|
2005-02-19 14:02:16 +00:00
|
|
|
dst += headerByte;
|
2003-09-23 17:24:45 +00:00
|
|
|
|
2011-04-14 12:12:27 +00:00
|
|
|
// increment source pointer to just after this color
|
2005-02-19 14:02:16 +00:00
|
|
|
src++;
|
2003-09-23 17:24:45 +00:00
|
|
|
|
|
|
|
// if we've decompressed all of the data
|
2005-02-19 14:02:16 +00:00
|
|
|
if (dst == endDest) {
|
2003-09-23 17:24:45 +00:00
|
|
|
rv = 0; // return "OK"
|
2003-07-28 01:47:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-09-23 17:24:45 +00:00
|
|
|
|
2003-07-28 01:47:41 +00:00
|
|
|
// RAW block
|
2003-09-23 17:24:45 +00:00
|
|
|
// read RAW block header & increment 'scan' to first pixel of
|
|
|
|
// block
|
2005-02-19 14:02:16 +00:00
|
|
|
headerByte = *src++;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// if this isn't a zero-length block
|
|
|
|
if (headerByte) {
|
2005-02-19 14:02:16 +00:00
|
|
|
if (dst + headerByte > endDest) {
|
2003-07-28 01:47:41 +00:00
|
|
|
rv = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// copy the next 'headerByte' pixels from source to
|
|
|
|
// destination
|
2005-02-19 14:02:16 +00:00
|
|
|
memcpy(dst, src, headerByte);
|
2003-09-23 17:24:45 +00:00
|
|
|
|
|
|
|
// increment destination pointer to just after this
|
|
|
|
// block
|
2005-02-19 14:02:16 +00:00
|
|
|
dst += headerByte;
|
2003-09-23 17:24:45 +00:00
|
|
|
|
|
|
|
// increment source pointer to just after this block
|
2005-02-19 14:02:16 +00:00
|
|
|
src += headerByte;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// if we've decompressed all of the data
|
2005-02-19 14:02:16 +00:00
|
|
|
if (dst == endDest) {
|
2003-09-23 17:24:45 +00:00
|
|
|
rv = 0; // return "OK"
|
2003-07-28 01:47:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
return rv;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
2011-04-14 12:12:27 +00:00
|
|
|
* Unwinds a run of 16-color data into 256-color palette data.
|
2003-09-28 14:13:57 +00:00
|
|
|
*/
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
void Screen::unwindRaw16(byte *dst, byte *src, uint16 blockSize, byte *colTable) {
|
2003-09-23 17:24:45 +00:00
|
|
|
// for each pair of pixels
|
|
|
|
while (blockSize > 1) {
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
if (Sword2Engine::isPsx()) {
|
2011-04-14 12:12:27 +00:00
|
|
|
// 1st color = number in table at position given by upper
|
2009-04-07 19:52:46 +00:00
|
|
|
// nibble of source byte
|
|
|
|
*dst++ = colTable[(*src) & 0x0f];
|
|
|
|
|
2011-04-14 12:12:27 +00:00
|
|
|
// 2nd color = number in table at position given by lower
|
2009-04-07 19:52:46 +00:00
|
|
|
// nibble of source byte
|
|
|
|
*dst++ = colTable[(*src) >> 4];
|
|
|
|
} else {
|
|
|
|
*dst++ = colTable[(*src) >> 4];
|
|
|
|
*dst++ = colTable[(*src) & 0x0f];
|
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
|
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// point to next source byte
|
2005-02-19 14:02:16 +00:00
|
|
|
src++;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// decrement count of how many pixels left to read
|
|
|
|
blockSize -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there's a final odd pixel
|
|
|
|
if (blockSize) {
|
2011-04-14 12:12:27 +00:00
|
|
|
// color = number in table at position given by upper nibble
|
2003-09-23 17:24:45 +00:00
|
|
|
// of source byte
|
2005-02-19 14:02:16 +00:00
|
|
|
*dst++ = colTable[(*src) >> 4];
|
2003-09-23 17:24:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
2011-04-14 12:12:27 +00:00
|
|
|
* This function takes a compressed frame of a sprite (with up to 16 colors)
|
2003-09-28 14:13:57 +00:00
|
|
|
* and decompresses it.
|
2005-02-19 14:02:16 +00:00
|
|
|
* @param dst destination buffer
|
|
|
|
* @param src source buffer
|
2003-09-28 14:13:57 +00:00
|
|
|
* @param decompSize the expected size of the uncompressed sprite
|
2011-04-14 12:12:27 +00:00
|
|
|
* @param colTable mapping from the 16 encoded colors to the current palette
|
2003-09-28 14:13:57 +00:00
|
|
|
*/
|
2003-09-23 17:24:45 +00:00
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
int32 Screen::decompressRLE16(byte *dst, byte *src, int32 decompSize, byte *colTable) {
|
2004-04-23 07:02:11 +00:00
|
|
|
byte headerByte; // block header byte
|
2005-02-19 14:02:16 +00:00
|
|
|
byte *endDest = dst + decompSize; // pointer to byte after end of decomp buffer
|
2003-07-28 01:47:41 +00:00
|
|
|
int32 rv;
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
while (1) {
|
2003-07-28 01:47:41 +00:00
|
|
|
// FLAT block
|
2003-09-23 17:24:45 +00:00
|
|
|
// read FLAT block header & increment 'scan' to first pixel
|
|
|
|
// of block
|
2005-02-19 14:02:16 +00:00
|
|
|
headerByte = *src++;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// if this isn't a zero-length block
|
|
|
|
if (headerByte) {
|
2005-02-19 14:02:16 +00:00
|
|
|
if (dst + headerByte > endDest) {
|
2003-07-28 01:47:41 +00:00
|
|
|
rv = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// set the next 'headerByte' pixels to the next
|
2011-04-14 12:12:27 +00:00
|
|
|
// color at 'source'
|
2005-02-19 14:02:16 +00:00
|
|
|
memset(dst, *src, headerByte);
|
2003-09-23 17:24:45 +00:00
|
|
|
|
|
|
|
// increment destination pointer to just after this
|
|
|
|
// block
|
2005-02-19 14:02:16 +00:00
|
|
|
dst += headerByte;
|
2003-09-23 17:24:45 +00:00
|
|
|
|
2011-04-14 12:12:27 +00:00
|
|
|
// increment source pointer to just after this color
|
2005-02-19 14:02:16 +00:00
|
|
|
src++;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// if we've decompressed all of the data
|
2005-07-30 21:11:48 +00:00
|
|
|
if (dst == endDest) {
|
2003-09-23 17:24:45 +00:00
|
|
|
rv = 0; // return "OK"
|
2003-07-28 01:47:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-09-23 17:24:45 +00:00
|
|
|
|
2003-07-28 01:47:41 +00:00
|
|
|
// RAW block
|
2003-09-23 17:24:45 +00:00
|
|
|
// read RAW block header & increment 'scan' to first pixel of
|
|
|
|
// block
|
2005-02-19 14:02:16 +00:00
|
|
|
headerByte = *src++;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// if this isn't a zero-length block
|
|
|
|
if (headerByte) {
|
2005-02-19 14:02:16 +00:00
|
|
|
if (dst + headerByte > endDest) {
|
2003-07-28 01:47:41 +00:00
|
|
|
rv = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// copy the next 'headerByte' pixels from source to
|
|
|
|
// destination (NB. 2 pixels per byte)
|
2005-02-19 14:02:16 +00:00
|
|
|
unwindRaw16(dst, src, headerByte, colTable);
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// increment destination pointer to just after this
|
|
|
|
// block
|
2005-02-19 14:02:16 +00:00
|
|
|
dst += headerByte;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// increment source pointer to just after this block
|
|
|
|
// (NB. headerByte gives pixels, so /2 for bytes)
|
2005-02-19 14:02:16 +00:00
|
|
|
src += (headerByte + 1) / 2;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// if we've decompressed all of the data
|
2005-02-19 14:02:16 +00:00
|
|
|
if (dst >= endDest) {
|
2003-09-23 17:24:45 +00:00
|
|
|
rv = 0; // return "OK"
|
|
|
|
break;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
return rv;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
/**
|
|
|
|
* This function takes a compressed HIF image and decompresses it.
|
|
|
|
* Used for PSX version sprites.
|
|
|
|
* @param dst destination buffer
|
|
|
|
* @param src source buffer
|
|
|
|
* @param skipData if pointer != NULL, value of pointed var
|
|
|
|
* is set to number of bytes composing the compressed data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32 Screen::decompressHIF(byte *src, byte *dst, uint32 *skipData) {
|
|
|
|
uint32 decompSize = 0;
|
|
|
|
uint32 readByte = 0;
|
|
|
|
|
|
|
|
for (;;) { // Main loop
|
|
|
|
byte control_byte = *src++;
|
|
|
|
readByte++;
|
|
|
|
uint32 byte_count = 0;
|
|
|
|
while (byte_count < 8) {
|
|
|
|
if (control_byte & 0x80) {
|
|
|
|
uint16 info_word = READ_BE_UINT16(src); // Read the info word
|
|
|
|
src += 2;
|
|
|
|
readByte += 2;
|
|
|
|
if (info_word == 0xFFFF) { // Got 0xFFFF code, finished.
|
|
|
|
if (skipData != NULL) *(skipData) = readByte;
|
|
|
|
return decompSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 repeat_count = (info_word >> 12) + 2; // How many time data needs to be refetched
|
2009-09-30 16:16:53 +00:00
|
|
|
while (repeat_count >= 0) {
|
2009-04-07 19:52:46 +00:00
|
|
|
uint16 refetchData = (info_word & 0xFFF) + 1;
|
|
|
|
if (refetchData > decompSize) return 0; // We have a problem here...
|
2009-05-24 15:17:42 +00:00
|
|
|
uint8 *old_data_src = dst - refetchData;
|
2009-04-07 19:52:46 +00:00
|
|
|
*dst++ = *old_data_src;
|
|
|
|
decompSize++;
|
|
|
|
repeat_count--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*dst++ = *src++;
|
|
|
|
readByte++;
|
|
|
|
decompSize++;
|
|
|
|
}
|
|
|
|
byte_count++;
|
|
|
|
control_byte <<= 1; // Shifting left the control code one bit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-24 15:17:42 +00:00
|
|
|
// Double line image to keep aspect ratio.
|
2009-04-07 19:52:46 +00:00
|
|
|
// Used in PSX version.
|
|
|
|
void Screen::resizePsxSprite(byte *dst, byte *src, uint16 destW, uint16 destH) {
|
|
|
|
for (int i = 0; i < destH / 2; i++) {
|
|
|
|
memcpy(dst + i * destW * 2, src + i * destW, destW);
|
|
|
|
memcpy(dst + i * destW * 2 + destW, src + i * destW, destW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sprites wider than 254px in PSX version are divided
|
|
|
|
// into slices, this recomposes the image.
|
|
|
|
void Screen::recomposePsxSprite(SpriteInfo *s) {
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint16 noStripes = (s->w / 254) + ((s->w % 254) ? 1 : 0);
|
|
|
|
uint16 lastStripeSize = (s->w % 254) ? s->w % 254 : 254;
|
|
|
|
byte *buffer = (byte *)malloc(s->w * s->h / 2);
|
|
|
|
|
|
|
|
memset(buffer, 0, s->w * s->h / 2);
|
|
|
|
|
|
|
|
for (int idx = 0; idx < noStripes; idx++) {
|
|
|
|
uint16 stripeSize = (idx == noStripes - 1) ? lastStripeSize : 254;
|
|
|
|
for (int line = 0; line < s->h / 2; line++) {
|
|
|
|
memcpy(buffer + idx * 254 + line * s->w, s->data, stripeSize);
|
|
|
|
s->data += stripeSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s->data = buffer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recomposes sprites wider than 254 pixels but also
|
|
|
|
// compressed with HIF.
|
|
|
|
// Used in PSX version.
|
|
|
|
void Screen::recomposeCompPsxSprite(SpriteInfo *s) {
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint16 noStripes = (s->w / 254) + ((s->w % 254) ? 1 : 0);
|
|
|
|
uint16 lastStripeSize = (s->w % 254) ? s->w % 254 : 254;
|
|
|
|
byte *buffer = (byte *)malloc(s->w * s->h / 2);
|
2009-08-14 23:20:46 +00:00
|
|
|
byte *stripeBuffer = (byte *)malloc(254 * s->h);
|
2009-04-07 19:52:46 +00:00
|
|
|
|
|
|
|
memset(buffer, 0, s->w * s->h / 2);
|
|
|
|
uint32 skipData = 0;
|
|
|
|
uint32 compBytes = 0;
|
|
|
|
|
|
|
|
for (int idx = 0; idx < noStripes; idx++) {
|
|
|
|
uint16 stripeSize = (idx == noStripes - 1) ? lastStripeSize : 254;
|
|
|
|
|
|
|
|
decompressHIF((s->data) + skipData, stripeBuffer, &compBytes);
|
|
|
|
skipData += compBytes;
|
|
|
|
|
|
|
|
for (int line = 0; line < s->h / 2; line++) {
|
|
|
|
memcpy(buffer + idx * 254 + line * s->w, stripeBuffer + line * stripeSize, stripeSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(stripeBuffer);
|
|
|
|
s->data = buffer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* Creates a sprite surface. Sprite surfaces are used by the in-game dialogs
|
|
|
|
* and for displaying cutscene subtitles, which makes them much easier to draw
|
|
|
|
* than standard sprites.
|
|
|
|
* @param s information about how to decode the sprite
|
|
|
|
* @param sprite the buffer that will be created to store the surface
|
|
|
|
* @return RD_OK, or an error code
|
|
|
|
*/
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
int32 Screen::createSurface(SpriteInfo *s, byte **sprite) {
|
2005-05-12 13:12:15 +00:00
|
|
|
*sprite = (byte *)malloc(s->w * s->h);
|
2003-08-23 13:02:21 +00:00
|
|
|
if (!*sprite)
|
|
|
|
return RDERR_OUTOFMEMORY;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-12-10 08:01:58 +00:00
|
|
|
// Surfaces are either uncompressed or RLE256-compressed. No need to
|
|
|
|
// test for anything else.
|
|
|
|
|
2003-08-23 13:02:21 +00:00
|
|
|
if (s->type & RDSPR_NOCOMPRESSION) {
|
|
|
|
memcpy(*sprite, s->data, s->w * s->h);
|
2003-12-10 08:01:58 +00:00
|
|
|
} else if (decompressRLE256(*sprite, s->data, s->w * s->h)) {
|
|
|
|
free(*sprite);
|
|
|
|
return RDERR_DECOMPRESSION;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
2003-09-08 06:38:16 +00:00
|
|
|
|
2003-08-23 13:02:21 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* Draws the sprite surface created earlier.
|
|
|
|
* @param s information about how to place the sprite
|
|
|
|
* @param surface pointer to the surface created earlier
|
|
|
|
* @param clipRect the clipping rectangle
|
|
|
|
*/
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
void Screen::drawSurface(SpriteInfo *s, byte *surface, Common::Rect *clipRect) {
|
2003-10-02 17:43:02 +00:00
|
|
|
Common::Rect rd, rs;
|
2003-12-10 08:01:58 +00:00
|
|
|
uint16 x, y;
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *src, *dst;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
|
|
|
rs.left = 0;
|
|
|
|
rs.right = s->w;
|
|
|
|
rs.top = 0;
|
|
|
|
rs.bottom = s->h;
|
2003-08-23 13:02:21 +00:00
|
|
|
|
2003-12-10 08:01:58 +00:00
|
|
|
rd.left = s->x;
|
2003-08-23 13:02:21 +00:00
|
|
|
rd.right = rd.left + rs.right;
|
2003-12-10 08:01:58 +00:00
|
|
|
rd.top = s->y;
|
2003-08-23 13:02:21 +00:00
|
|
|
rd.bottom = rd.top + rs.bottom;
|
|
|
|
|
2005-12-20 08:56:48 +00:00
|
|
|
Common::Rect defClipRect(0, 0, _screenWide, _screenDeep);
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2005-12-20 08:56:48 +00:00
|
|
|
if (!clipRect) {
|
|
|
|
clipRect = &defClipRect;
|
|
|
|
}
|
2003-08-23 13:02:21 +00:00
|
|
|
|
2005-12-20 08:56:48 +00:00
|
|
|
if (clipRect->left > rd.left) {
|
|
|
|
rs.left += (clipRect->left - rd.left);
|
|
|
|
rd.left = clipRect->left;
|
|
|
|
}
|
2003-08-23 13:02:21 +00:00
|
|
|
|
2005-12-20 08:56:48 +00:00
|
|
|
if (clipRect->top > rd.top) {
|
|
|
|
rs.top += (clipRect->top - rd.top);
|
|
|
|
rd.top = clipRect->top;
|
|
|
|
}
|
2003-09-08 06:38:16 +00:00
|
|
|
|
2005-12-20 08:56:48 +00:00
|
|
|
if (clipRect->right < rd.right) {
|
|
|
|
rd.right = clipRect->right;
|
2003-09-08 06:38:16 +00:00
|
|
|
}
|
|
|
|
|
2005-12-20 08:56:48 +00:00
|
|
|
if (clipRect->bottom < rd.bottom) {
|
|
|
|
rd.bottom = clipRect->bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rd.width() <= 0 || rd.height() <= 0)
|
|
|
|
return;
|
|
|
|
|
2003-12-10 08:01:58 +00:00
|
|
|
src = surface + rs.top * s->w + rs.left;
|
2003-10-15 06:40:31 +00:00
|
|
|
dst = _buffer + _screenWide * rd.top + rd.left;
|
2003-08-23 13:02:21 +00:00
|
|
|
|
2003-09-08 06:38:16 +00:00
|
|
|
// Surfaces are always transparent.
|
|
|
|
|
|
|
|
for (y = 0; y < rd.height(); y++) {
|
|
|
|
for (x = 0; x < rd.width(); x++) {
|
|
|
|
if (src[x])
|
|
|
|
dst[x] = src[x];
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
2003-12-10 08:01:58 +00:00
|
|
|
src += s->w;
|
2003-10-15 06:40:31 +00:00
|
|
|
dst += _screenWide;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
updateRect(&rd);
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* Destroys a surface.
|
|
|
|
*/
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
void Screen::deleteSurface(byte *surface) {
|
2003-08-23 13:02:21 +00:00
|
|
|
free(surface);
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* Draws a sprite onto the screen. The type of the sprite can be a combination
|
|
|
|
* of the following flags, some of which are mutually exclusive:
|
|
|
|
* RDSPR_DISPLAYALIGN The sprite is drawn relative to the top left corner
|
|
|
|
* of the screen
|
|
|
|
* RDSPR_FLIP The sprite is mirrored
|
2011-04-14 12:12:27 +00:00
|
|
|
* RDSPR_TRANS The sprite has a transparent color zero
|
2003-09-28 14:13:57 +00:00
|
|
|
* RDSPR_BLEND The sprite is translucent
|
|
|
|
* RDSPR_SHADOW The sprite is affected by the light mask. (Scaled
|
|
|
|
* sprites always are.)
|
|
|
|
* RDSPR_NOCOMPRESSION The sprite data is not compressed
|
2011-04-14 12:12:27 +00:00
|
|
|
* RDSPR_RLE16 The sprite data is a 16-color compressed sprite
|
|
|
|
* RDSPR_RLE256 The sprite data is a 256-color compressed sprite
|
2003-09-28 14:13:57 +00:00
|
|
|
* @param s all the information needed to draw the sprite
|
|
|
|
* @warning Sprites will only be drawn onto the background, not over menubar
|
|
|
|
* areas.
|
|
|
|
*/
|
|
|
|
|
2003-09-23 17:24:45 +00:00
|
|
|
// FIXME: I'm sure this could be optimized. There's plenty of data copying and
|
|
|
|
// mallocing here.
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
int32 Screen::drawSprite(SpriteInfo *s) {
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *src, *dst;
|
|
|
|
byte *sprite, *newSprite;
|
2003-08-20 06:51:35 +00:00
|
|
|
uint16 scale;
|
2003-08-19 08:47:09 +00:00
|
|
|
int16 i, j;
|
2003-08-20 06:51:35 +00:00
|
|
|
uint16 srcPitch;
|
|
|
|
bool freeSprite = false;
|
2003-10-02 17:43:02 +00:00
|
|
|
Common::Rect rd, rs;
|
2003-08-19 08:47:09 +00:00
|
|
|
|
2003-08-20 06:51:35 +00:00
|
|
|
// -----------------------------------------------------------------
|
|
|
|
// Decompression and mirroring
|
|
|
|
// -----------------------------------------------------------------
|
2009-04-07 19:52:46 +00:00
|
|
|
if (s->type & RDSPR_NOCOMPRESSION) {
|
2009-09-30 16:16:53 +00:00
|
|
|
if (Sword2Engine::isPsx()) { // PSX Uncompressed sprites
|
2009-04-07 19:52:46 +00:00
|
|
|
if (s->w > 254 && !s->isText) { // We need to recompose these frames
|
|
|
|
recomposePsxSprite(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
freeSprite = true;
|
|
|
|
byte *tempBuf = (byte *)malloc(s->w * s->h * 2);
|
|
|
|
memset(tempBuf, 0, s->w * s->h * 2);
|
|
|
|
resizePsxSprite(tempBuf, s->data, s->w, s->h);
|
|
|
|
|
|
|
|
if (s->w > 254 && !s->isText) {
|
|
|
|
free(s->data);
|
|
|
|
}
|
2003-08-19 08:47:09 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
sprite = tempBuf;
|
|
|
|
} else { // PC Uncompressed sprites
|
|
|
|
sprite = s->data;
|
|
|
|
}
|
|
|
|
} else {
|
2003-08-20 06:51:35 +00:00
|
|
|
freeSprite = true;
|
2009-04-07 19:52:46 +00:00
|
|
|
|
2003-12-10 08:01:58 +00:00
|
|
|
if ((s->type & 0xff00) == RDSPR_RLE16) {
|
2009-04-07 19:52:46 +00:00
|
|
|
if (Sword2Engine::isPsx()) { // PSX HIF16 sprites
|
|
|
|
uint32 decompData;
|
|
|
|
byte *tempBuf = (byte *)malloc(s->w * s->h);
|
|
|
|
memset(tempBuf, 0, s->w * s->h);
|
|
|
|
|
|
|
|
decompData = decompressHIF(s->data, tempBuf);
|
|
|
|
|
2009-04-18 08:37:22 +00:00
|
|
|
// Check that we correctly decompressed data
|
2010-09-18 12:42:23 +00:00
|
|
|
if (!decompData) {
|
|
|
|
free(tempBuf);
|
|
|
|
|
2009-04-18 08:37:22 +00:00
|
|
|
return RDERR_DECOMPRESSION;
|
2010-09-18 12:42:23 +00:00
|
|
|
}
|
2009-04-18 08:37:22 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
s->w = (decompData / (s->h / 2)) * 2;
|
|
|
|
byte *tempBuf2 = (byte *)malloc(s->w * s->h * 10);
|
|
|
|
memset(tempBuf2, 0, s->w * s->h * 2);
|
|
|
|
|
2011-04-14 12:12:27 +00:00
|
|
|
unwindRaw16(tempBuf2, tempBuf, (s->w * (s->h / 2)), s->colorTable);
|
2009-04-07 19:52:46 +00:00
|
|
|
sprite = (byte *)malloc(s->w * s->h);
|
|
|
|
|
2010-01-21 23:05:33 +00:00
|
|
|
if (!sprite) {
|
|
|
|
free(tempBuf2);
|
|
|
|
free(tempBuf);
|
2009-04-07 19:52:46 +00:00
|
|
|
return RDERR_OUTOFMEMORY;
|
2010-01-21 23:05:33 +00:00
|
|
|
}
|
2009-04-07 19:52:46 +00:00
|
|
|
|
|
|
|
resizePsxSprite(sprite, tempBuf2, s->w, s->h);
|
|
|
|
|
|
|
|
free(tempBuf2);
|
|
|
|
free(tempBuf);
|
|
|
|
} else { // PC RLE16 sprites
|
|
|
|
sprite = (byte *)malloc(s->w * s->h);
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
if (!sprite)
|
|
|
|
return RDERR_OUTOFMEMORY;
|
|
|
|
|
2011-04-14 12:12:27 +00:00
|
|
|
if (decompressRLE16(sprite, s->data, s->w * s->h, s->colorTable)) {
|
2009-04-07 19:52:46 +00:00
|
|
|
free(sprite);
|
|
|
|
return RDERR_DECOMPRESSION;
|
|
|
|
}
|
2003-08-20 06:51:35 +00:00
|
|
|
}
|
2003-08-19 08:47:09 +00:00
|
|
|
} else {
|
2009-04-07 19:52:46 +00:00
|
|
|
if (Sword2Engine::isPsx()) { // PSX HIF256 sprites
|
|
|
|
if (s->w > 255) {
|
|
|
|
sprite = (byte *)malloc(s->w * s->h);
|
|
|
|
recomposeCompPsxSprite(s);
|
|
|
|
resizePsxSprite(sprite, s->data, s->w, s->h);
|
|
|
|
free(s->data);
|
|
|
|
} else {
|
|
|
|
byte *tempBuf = (byte *)malloc(s->w * s->h);
|
|
|
|
uint32 decompData = decompressHIF(s->data, tempBuf);
|
2009-04-18 08:37:22 +00:00
|
|
|
|
|
|
|
// Check that we correctly decompressed data
|
2010-09-18 12:42:23 +00:00
|
|
|
if (!decompData) {
|
|
|
|
free(tempBuf);
|
|
|
|
|
2009-04-18 08:37:22 +00:00
|
|
|
return RDERR_DECOMPRESSION;
|
2010-09-18 12:42:23 +00:00
|
|
|
}
|
2009-04-18 08:37:22 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
s->w = (decompData / (s->h / 2));
|
|
|
|
sprite = (byte *)malloc(s->w * s->h);
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
if (!sprite)
|
|
|
|
return RDERR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
resizePsxSprite(sprite, tempBuf, s->w, s->h);
|
|
|
|
free(tempBuf);
|
|
|
|
}
|
|
|
|
} else { // PC RLE256 sprites
|
|
|
|
sprite = (byte *)malloc(s->w * s->h);
|
|
|
|
|
|
|
|
if (!sprite)
|
|
|
|
return RDERR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if (decompressRLE256(sprite, s->data, s->w * s->h)) {
|
|
|
|
free(sprite);
|
|
|
|
return RDERR_DECOMPRESSION;
|
|
|
|
}
|
2003-08-20 06:51:35 +00:00
|
|
|
}
|
2003-08-19 08:47:09 +00:00
|
|
|
}
|
2003-08-20 06:51:35 +00:00
|
|
|
}
|
2003-08-19 08:47:09 +00:00
|
|
|
|
2003-08-20 06:51:35 +00:00
|
|
|
if (s->type & RDSPR_FLIP) {
|
2005-05-12 13:12:15 +00:00
|
|
|
newSprite = (byte *)malloc(s->w * s->h);
|
2003-08-20 06:51:35 +00:00
|
|
|
if (newSprite == NULL) {
|
|
|
|
if (freeSprite)
|
2003-08-19 08:47:09 +00:00
|
|
|
free(sprite);
|
2003-08-20 06:51:35 +00:00
|
|
|
return RDERR_OUTOFMEMORY;
|
2003-08-19 08:47:09 +00:00
|
|
|
}
|
2003-10-15 06:40:31 +00:00
|
|
|
mirrorSprite(newSprite, sprite, s->w, s->h);
|
2003-08-20 06:51:35 +00:00
|
|
|
if (freeSprite)
|
|
|
|
free(sprite);
|
|
|
|
sprite = newSprite;
|
|
|
|
freeSprite = true;
|
2003-08-19 08:47:09 +00:00
|
|
|
}
|
|
|
|
|
2003-08-20 06:51:35 +00:00
|
|
|
// -----------------------------------------------------------------
|
|
|
|
// Positioning and clipping.
|
|
|
|
// -----------------------------------------------------------------
|
2003-08-19 08:47:09 +00:00
|
|
|
|
2005-05-02 09:20:27 +00:00
|
|
|
int16 spriteX = s->x;
|
|
|
|
int16 spriteY = s->y;
|
|
|
|
|
2003-08-20 06:51:35 +00:00
|
|
|
if (!(s->type & RDSPR_DISPLAYALIGN)) {
|
2005-05-02 09:20:27 +00:00
|
|
|
spriteX += _parallaxScrollX;
|
|
|
|
spriteY += _parallaxScrollY;
|
2003-08-20 06:51:35 +00:00
|
|
|
}
|
2003-08-19 08:47:09 +00:00
|
|
|
|
2005-05-02 09:20:27 +00:00
|
|
|
spriteY += MENUDEEP;
|
2003-08-20 06:51:35 +00:00
|
|
|
|
|
|
|
// A scale factor 0 or 256 means don't scale. Why do they use two
|
|
|
|
// different values to mean the same thing? Normalize it here for
|
|
|
|
// convenience.
|
|
|
|
|
|
|
|
scale = (s->scale == 0) ? 256 : s->scale;
|
|
|
|
|
|
|
|
rs.top = 0;
|
|
|
|
rs.left = 0;
|
|
|
|
|
|
|
|
if (scale != 256) {
|
|
|
|
rs.right = s->scaledWidth;
|
|
|
|
rs.bottom = s->scaledHeight;
|
|
|
|
srcPitch = s->scaledWidth;
|
|
|
|
} else {
|
2003-08-19 08:47:09 +00:00
|
|
|
rs.right = s->w;
|
2003-08-20 06:51:35 +00:00
|
|
|
rs.bottom = s->h;
|
|
|
|
srcPitch = s->w;
|
|
|
|
}
|
2003-08-19 08:47:09 +00:00
|
|
|
|
2005-05-02 09:20:27 +00:00
|
|
|
rd.top = spriteY;
|
|
|
|
rd.left = spriteX;
|
2003-08-20 06:51:35 +00:00
|
|
|
|
|
|
|
if (!(s->type & RDSPR_DISPLAYALIGN)) {
|
2003-10-15 06:40:31 +00:00
|
|
|
rd.top -= _scrollY;
|
|
|
|
rd.left -= _scrollX;
|
2003-08-20 06:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rd.right = rd.left + rs.right;
|
|
|
|
rd.bottom = rd.top + rs.bottom;
|
|
|
|
|
2003-08-30 10:23:40 +00:00
|
|
|
// Check if the sprite would end up completely outside the screen.
|
|
|
|
|
2005-05-02 09:20:27 +00:00
|
|
|
if (rd.left > RENDERWIDE || rd.top > RENDERDEEP + MENUDEEP || rd.right < 0 || rd.bottom < MENUDEEP) {
|
2003-08-30 10:23:40 +00:00
|
|
|
if (freeSprite)
|
|
|
|
free(sprite);
|
|
|
|
return RD_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-02 09:20:27 +00:00
|
|
|
if (rd.top < MENUDEEP) {
|
|
|
|
rs.top = MENUDEEP - rd.top;
|
|
|
|
rd.top = MENUDEEP;
|
2003-08-20 06:51:35 +00:00
|
|
|
}
|
2005-05-02 09:20:27 +00:00
|
|
|
if (rd.bottom > RENDERDEEP + MENUDEEP) {
|
|
|
|
rd.bottom = RENDERDEEP + MENUDEEP;
|
2003-08-30 10:23:40 +00:00
|
|
|
rs.bottom = rs.top + (rd.bottom - rd.top);
|
2003-08-20 06:51:35 +00:00
|
|
|
}
|
|
|
|
if (rd.left < 0) {
|
2003-08-30 10:23:40 +00:00
|
|
|
rs.left = -rd.left;
|
2003-08-20 06:51:35 +00:00
|
|
|
rd.left = 0;
|
|
|
|
}
|
2005-05-02 09:20:27 +00:00
|
|
|
if (rd.right > RENDERWIDE) {
|
|
|
|
rd.right = RENDERWIDE;
|
2003-08-30 10:23:40 +00:00
|
|
|
rs.right = rs.left + (rd.right - rd.left);
|
2003-08-20 06:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------
|
|
|
|
// Scaling
|
|
|
|
// -----------------------------------------------------------------
|
|
|
|
|
|
|
|
if (scale != 256) {
|
|
|
|
if (s->scaledWidth > SCALE_MAXWIDTH || s->scaledHeight > SCALE_MAXHEIGHT) {
|
|
|
|
if (freeSprite)
|
|
|
|
free(sprite);
|
|
|
|
return RDERR_NOTIMPLEMENTED;
|
2003-08-19 08:47:09 +00:00
|
|
|
}
|
2003-08-20 06:51:35 +00:00
|
|
|
|
2005-05-12 13:12:15 +00:00
|
|
|
newSprite = (byte *)malloc(s->scaledWidth * s->scaledHeight);
|
2003-08-20 06:51:35 +00:00
|
|
|
if (newSprite == NULL) {
|
|
|
|
if (freeSprite)
|
|
|
|
free(sprite);
|
|
|
|
return RDERR_OUTOFMEMORY;
|
2003-08-19 08:47:09 +00:00
|
|
|
}
|
2003-08-20 06:51:35 +00:00
|
|
|
|
2009-05-24 15:17:42 +00:00
|
|
|
// We cannot use good scaling for PSX version, as we are missing
|
2009-04-07 19:52:46 +00:00
|
|
|
// some required data.
|
|
|
|
if (_renderCaps & RDBLTFX_EDGEBLEND && !Sword2Engine::isPsx())
|
2010-04-17 17:23:30 +00:00
|
|
|
scaleImageGood(newSprite, s->scaledWidth, s->scaledWidth, s->scaledHeight, sprite, s->w, s->w, s->h, _buffer, rd.left, rd.top);
|
2004-06-06 15:40:31 +00:00
|
|
|
else
|
|
|
|
scaleImageFast(newSprite, s->scaledWidth, s->scaledWidth, s->scaledHeight, sprite, s->w, s->w, s->h);
|
2003-08-19 08:47:09 +00:00
|
|
|
|
2003-08-20 06:51:35 +00:00
|
|
|
if (freeSprite)
|
|
|
|
free(sprite);
|
|
|
|
sprite = newSprite;
|
|
|
|
freeSprite = true;
|
|
|
|
}
|
|
|
|
|
2003-08-22 07:04:50 +00:00
|
|
|
// -----------------------------------------------------------------
|
|
|
|
// Light masking
|
|
|
|
// -----------------------------------------------------------------
|
|
|
|
|
|
|
|
// The light mask is an optional layer that covers the entire room
|
2003-08-30 10:23:40 +00:00
|
|
|
// and which is used to simulate light and shadows. Scaled sprites
|
|
|
|
// (actors, presumably) are always affected.
|
2009-04-07 19:52:46 +00:00
|
|
|
// Light masking makes use of palette match table, so it's unavailable
|
|
|
|
// in PSX version.
|
2003-08-22 07:04:50 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
if ((_renderCaps & RDBLTFX_SHADOWBLEND) && _lightMask && (scale != 256 || ((s->type & RDSPR_SHADOW) && !Sword2Engine::isPsx()) )) {
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *lightMap;
|
2003-08-22 07:04:50 +00:00
|
|
|
|
2004-06-07 05:57:00 +00:00
|
|
|
// Make sure that we never apply the shadow to the original
|
|
|
|
// resource data. This could only ever happen in the
|
|
|
|
// RDSPR_NOCOMPRESSION case.
|
|
|
|
|
2003-08-22 07:04:50 +00:00
|
|
|
if (!freeSprite) {
|
2005-05-12 13:12:15 +00:00
|
|
|
newSprite = (byte *)malloc(s->w * s->h);
|
2003-08-22 07:04:50 +00:00
|
|
|
memcpy(newSprite, sprite, s->w * s->h);
|
|
|
|
sprite = newSprite;
|
|
|
|
freeSprite = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
src = sprite + rs.top * srcPitch + rs.left;
|
2005-05-02 09:20:27 +00:00
|
|
|
lightMap = _lightMask + (rd.top + _scrollY - MENUDEEP) * _locationWide + rd.left + _scrollX;
|
2003-08-22 07:04:50 +00:00
|
|
|
|
2003-09-08 06:38:16 +00:00
|
|
|
for (i = 0; i < rs.height(); i++) {
|
|
|
|
for (j = 0; j < rs.width(); j++) {
|
2003-08-22 07:04:50 +00:00
|
|
|
if (src[j] && lightMap[j]) {
|
2011-02-15 21:52:15 +00:00
|
|
|
uint8 r = ((32 - lightMap[j]) * _palette[src[j] * 3 + 0]) >> 5;
|
|
|
|
uint8 g = ((32 - lightMap[j]) * _palette[src[j] * 3 + 1]) >> 5;
|
|
|
|
uint8 b = ((32 - lightMap[j]) * _palette[src[j] * 3 + 2]) >> 5;
|
2003-10-15 06:40:31 +00:00
|
|
|
src[j] = quickMatch(r, g, b);
|
2003-08-22 07:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
src += srcPitch;
|
2003-10-15 06:40:31 +00:00
|
|
|
lightMap += _locationWide;
|
2003-08-22 07:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-20 06:51:35 +00:00
|
|
|
// -----------------------------------------------------------------
|
|
|
|
// Drawing
|
|
|
|
// -----------------------------------------------------------------
|
|
|
|
|
2003-08-22 07:04:50 +00:00
|
|
|
src = sprite + rs.top * srcPitch + rs.left;
|
2003-10-15 06:40:31 +00:00
|
|
|
dst = _buffer + _screenWide * rd.top + rd.left;
|
2003-08-20 06:51:35 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
if (s->type & RDSPR_BLEND && !Sword2Engine::isPsx()) { // Blending is unavailable in PSX version
|
2003-12-09 08:09:18 +00:00
|
|
|
// The original code had two different blending cases. One for
|
|
|
|
// s->blend & 0x01 and one for s->blend & 0x02. However, the
|
|
|
|
// only values that actually appear in the cluster files are
|
|
|
|
// 0, 513 and 1025 so the s->blend & 0x02 case was never used.
|
|
|
|
// Which is just as well since that code made no sense to me.
|
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
if (!(_renderCaps & RDBLTFX_SPRITEBLEND)) {
|
2003-09-08 06:38:16 +00:00
|
|
|
for (i = 0; i < rs.height(); i++) {
|
|
|
|
for (j = 0; j < rs.width(); j++) {
|
2003-08-26 06:53:00 +00:00
|
|
|
if (src[j] && ((i & 1) == (j & 1)))
|
|
|
|
dst[j] = src[j];
|
2003-08-19 08:47:09 +00:00
|
|
|
}
|
2003-08-20 06:51:35 +00:00
|
|
|
src += srcPitch;
|
2003-10-15 06:40:31 +00:00
|
|
|
dst += _screenWide;
|
2003-08-19 08:47:09 +00:00
|
|
|
}
|
2003-08-26 06:53:00 +00:00
|
|
|
} else {
|
2003-12-09 08:09:18 +00:00
|
|
|
uint8 n = s->blend >> 8;
|
|
|
|
|
|
|
|
for (i = 0; i < rs.height(); i++) {
|
|
|
|
for (j = 0; j < rs.width(); j++) {
|
|
|
|
if (src[j]) {
|
2011-02-15 21:52:15 +00:00
|
|
|
uint8 r1 = _palette[src[j] * 3 + 0];
|
|
|
|
uint8 g1 = _palette[src[j] * 3 + 1];
|
|
|
|
uint8 b1 = _palette[src[j] * 3 + 2];
|
|
|
|
uint8 r2 = _palette[dst[j] * 3 + 0];
|
|
|
|
uint8 g2 = _palette[dst[j] * 3 + 1];
|
|
|
|
uint8 b2 = _palette[dst[j] * 3 + 2];
|
2003-12-09 08:09:18 +00:00
|
|
|
|
|
|
|
uint8 r = (r1 * n + r2 * (8 - n)) >> 3;
|
|
|
|
uint8 g = (g1 * n + g2 * (8 - n)) >> 3;
|
|
|
|
uint8 b = (b1 * n + b2 * (8 - n)) >> 3;
|
|
|
|
dst[j] = quickMatch(r, g, b);
|
2003-08-26 06:53:00 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-09 08:09:18 +00:00
|
|
|
src += srcPitch;
|
|
|
|
dst += _screenWide;
|
2003-08-19 08:47:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (s->type & RDSPR_TRANS) {
|
2003-09-08 06:38:16 +00:00
|
|
|
for (i = 0; i < rs.height(); i++) {
|
|
|
|
for (j = 0; j < rs.width(); j++) {
|
2003-08-19 08:47:09 +00:00
|
|
|
if (src[j])
|
|
|
|
dst[j] = src[j];
|
|
|
|
}
|
2003-08-20 06:51:35 +00:00
|
|
|
src += srcPitch;
|
2003-10-15 06:40:31 +00:00
|
|
|
dst += _screenWide;
|
2003-08-19 08:47:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-09-08 06:38:16 +00:00
|
|
|
for (i = 0; i < rs.height(); i++) {
|
|
|
|
memcpy(dst, src, rs.width());
|
2003-08-20 06:51:35 +00:00
|
|
|
src += srcPitch;
|
2003-10-15 06:40:31 +00:00
|
|
|
dst += _screenWide;
|
2003-08-19 08:47:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-20 06:51:35 +00:00
|
|
|
if (freeSprite)
|
|
|
|
free(sprite);
|
|
|
|
|
2004-05-09 13:24:07 +00:00
|
|
|
markAsDirty(rd.left, rd.top, rd.right - 1, rd.bottom - 1);
|
2003-09-23 17:24:45 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* Opens the light masking sprite for a room.
|
|
|
|
*/
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
int32 Screen::openLightMask(SpriteInfo *s) {
|
2003-08-26 06:53:00 +00:00
|
|
|
// FIXME: The light mask is only needed on higher graphics detail
|
|
|
|
// settings, so to save memory we could simply ignore it on lower
|
|
|
|
// settings. But then we need to figure out how to ensure that it
|
|
|
|
// is properly loaded if the user changes the settings in mid-game.
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
if (_lightMask)
|
2003-08-26 06:53:00 +00:00
|
|
|
return RDERR_NOTCLOSED;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2005-05-12 13:12:15 +00:00
|
|
|
_lightMask = (byte *)malloc(s->w * s->h);
|
2003-10-15 06:40:31 +00:00
|
|
|
if (!_lightMask)
|
2003-08-26 06:53:00 +00:00
|
|
|
return RDERR_OUTOFMEMORY;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
if (s->data == NULL) // Check, as there's no mask in psx version
|
|
|
|
return RDERR_NOTOPEN;
|
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
if (decompressRLE256(_lightMask, s->data, s->w * s->h))
|
2003-08-26 06:53:00 +00:00
|
|
|
return RDERR_DECOMPRESSION;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-08-26 06:53:00 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* Closes the light masking sprite for a room.
|
|
|
|
*/
|
|
|
|
|
2005-05-02 05:41:01 +00:00
|
|
|
int32 Screen::closeLightMask() {
|
2003-10-15 06:40:31 +00:00
|
|
|
if (!_lightMask)
|
2003-08-26 06:53:00 +00:00
|
|
|
return RDERR_NOTOPEN;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
free(_lightMask);
|
|
|
|
_lightMask = NULL;
|
2003-08-26 06:53:00 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword2
|