2009-10-06 16:14:40 +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.
|
|
|
|
*
|
|
|
|
* 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$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-02-17 23:38:43 +00:00
|
|
|
#include "common/file.h"
|
2009-10-06 16:14:40 +00:00
|
|
|
#include "common/timer.h"
|
|
|
|
#include "common/util.h"
|
2010-02-17 23:37:32 +00:00
|
|
|
#include "common/system.h"
|
2009-10-06 16:14:40 +00:00
|
|
|
|
|
|
|
#include "sci/sci.h"
|
|
|
|
#include "sci/engine/state.h"
|
2010-05-24 17:21:11 +00:00
|
|
|
#include "sci/graphics/maciconbar.h"
|
2010-01-05 01:37:57 +00:00
|
|
|
#include "sci/graphics/palette.h"
|
2010-05-24 17:21:11 +00:00
|
|
|
#include "sci/graphics/screen.h"
|
2009-10-06 16:14:40 +00:00
|
|
|
|
|
|
|
namespace Sci {
|
|
|
|
|
2010-06-08 22:00:59 +00:00
|
|
|
GfxPalette::GfxPalette(ResourceManager *resMan, GfxScreen *screen)
|
2009-10-08 08:00:30 +00:00
|
|
|
: _resMan(resMan), _screen(screen) {
|
2009-10-08 20:13:52 +00:00
|
|
|
int16 color;
|
|
|
|
|
|
|
|
_sysPalette.timestamp = 0;
|
|
|
|
for (color = 0; color < 256; color++) {
|
|
|
|
_sysPalette.colors[color].used = 0;
|
|
|
|
_sysPalette.colors[color].r = 0;
|
|
|
|
_sysPalette.colors[color].g = 0;
|
|
|
|
_sysPalette.colors[color].b = 0;
|
|
|
|
_sysPalette.intensity[color] = 100;
|
|
|
|
_sysPalette.mapping[color] = color;
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
2009-10-08 20:13:52 +00:00
|
|
|
// Black and white are hardcoded
|
2009-10-06 16:14:40 +00:00
|
|
|
_sysPalette.colors[0].used = 1;
|
|
|
|
_sysPalette.colors[255].used = 1;
|
|
|
|
_sysPalette.colors[255].r = 255;
|
|
|
|
_sysPalette.colors[255].g = 255;
|
|
|
|
_sysPalette.colors[255].b = 255;
|
|
|
|
|
2010-06-04 20:06:59 +00:00
|
|
|
_sysPaletteChanged = false;
|
2010-06-17 16:06:01 +00:00
|
|
|
_alwaysForceRealMerge = false;
|
|
|
|
|
|
|
|
// Pseudo-WORKAROUND
|
2010-06-17 16:09:06 +00:00
|
|
|
// Laura Bow 2 demo uses an inbetween interpreter, some parts are SCI1.1, some parts are SCI1
|
2010-06-17 16:06:01 +00:00
|
|
|
// It's not using the SCI1.1 palette merging (copying over all the colors) but the real merging
|
|
|
|
// If we use the copying over, we will get issues because some views have marked all colors as being used
|
|
|
|
// and those will overwrite the current palette in that case
|
2010-06-17 16:36:01 +00:00
|
|
|
// Quest for Glory 3 demo and police quest 1 vga behave the same interpreter wise and all have glitches, if we don't
|
|
|
|
// switch back
|
2010-06-17 23:14:34 +00:00
|
|
|
if (g_sci->getGameId() == "laurabow2" && (g_sci->isDemo()))
|
2010-06-17 16:06:01 +00:00
|
|
|
_alwaysForceRealMerge = true;
|
2010-06-17 23:14:34 +00:00
|
|
|
else if (g_sci->getGameId() == "qfg3" && (g_sci->isDemo()))
|
2010-06-17 16:36:01 +00:00
|
|
|
_alwaysForceRealMerge = true;
|
2010-06-17 23:14:34 +00:00
|
|
|
else if (g_sci->getGameId() == "pq1sci")
|
2010-06-17 16:36:01 +00:00
|
|
|
_alwaysForceRealMerge = true;
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 16:21:11 +00:00
|
|
|
GfxPalette::~GfxPalette() {
|
2009-10-08 08:00:30 +00:00
|
|
|
}
|
|
|
|
|
2010-06-08 22:00:59 +00:00
|
|
|
// meant to get called only once during init of engine
|
|
|
|
void GfxPalette::setDefault() {
|
|
|
|
if (_resMan->getViewType() == kViewEga)
|
|
|
|
setEGA();
|
|
|
|
else if (_resMan->isAmiga32color())
|
|
|
|
setAmiga();
|
|
|
|
else
|
|
|
|
kernelSetFromResource(999, true);
|
|
|
|
}
|
|
|
|
|
2009-10-06 16:14:40 +00:00
|
|
|
#define SCI_PAL_FORMAT_CONSTANT 1
|
|
|
|
#define SCI_PAL_FORMAT_VARIABLE 0
|
|
|
|
|
2010-01-31 16:21:11 +00:00
|
|
|
void GfxPalette::createFromData(byte *data, Palette *paletteOut) {
|
2009-10-06 16:14:40 +00:00
|
|
|
int palFormat = 0;
|
|
|
|
int palOffset = 0;
|
|
|
|
int palColorStart = 0;
|
|
|
|
int palColorCount = 0;
|
|
|
|
int colorNo = 0;
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
memset(paletteOut, 0, sizeof(Palette));
|
2009-10-06 16:14:40 +00:00
|
|
|
// Setup default mapping
|
|
|
|
for (colorNo = 0; colorNo < 256; colorNo++) {
|
|
|
|
paletteOut->mapping[colorNo] = colorNo;
|
|
|
|
}
|
2009-10-15 10:12:14 +00:00
|
|
|
if ((data[0] == 0 && data[1] == 1) || (data[0] == 0 && data[1] == 0 && READ_LE_UINT16(data + 29) == 0)) {
|
2009-10-06 16:14:40 +00:00
|
|
|
// SCI0/SCI1 palette
|
|
|
|
palFormat = SCI_PAL_FORMAT_VARIABLE; // CONSTANT;
|
|
|
|
palOffset = 260;
|
|
|
|
palColorStart = 0; palColorCount = 256;
|
|
|
|
//memcpy(&paletteOut->mapping, data, 256);
|
|
|
|
} else {
|
|
|
|
// SCI1.1 palette
|
|
|
|
palFormat = data[32];
|
|
|
|
palOffset = 37;
|
|
|
|
palColorStart = READ_LE_UINT16(data + 25); palColorCount = READ_LE_UINT16(data + 29);
|
|
|
|
}
|
|
|
|
switch (palFormat) {
|
|
|
|
case SCI_PAL_FORMAT_CONSTANT:
|
|
|
|
for (colorNo = palColorStart; colorNo < palColorStart + palColorCount; colorNo++) {
|
|
|
|
paletteOut->colors[colorNo].used = 1;
|
|
|
|
paletteOut->colors[colorNo].r = data[palOffset++];
|
|
|
|
paletteOut->colors[colorNo].g = data[palOffset++];
|
|
|
|
paletteOut->colors[colorNo].b = data[palOffset++];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCI_PAL_FORMAT_VARIABLE:
|
|
|
|
for (colorNo = palColorStart; colorNo < palColorStart + palColorCount; colorNo++) {
|
|
|
|
paletteOut->colors[colorNo].used = data[palOffset++];
|
|
|
|
paletteOut->colors[colorNo].r = data[palOffset++];
|
|
|
|
paletteOut->colors[colorNo].g = data[palOffset++];
|
|
|
|
paletteOut->colors[colorNo].b = data[palOffset++];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Will try to set amiga palette by using "spal" file. If not found, we return false
|
2010-01-31 16:21:11 +00:00
|
|
|
bool GfxPalette::setAmiga() {
|
2009-10-06 16:14:40 +00:00
|
|
|
Common::File file;
|
|
|
|
int curColor, byte1, byte2;
|
|
|
|
|
|
|
|
if (file.open("spal")) {
|
|
|
|
for (curColor = 0; curColor < 32; curColor++) {
|
|
|
|
byte1 = file.readByte();
|
|
|
|
byte2 = file.readByte();
|
|
|
|
if ((byte1 == EOF) || (byte2 == EOF))
|
|
|
|
error("Amiga palette file ends prematurely");
|
|
|
|
_sysPalette.colors[curColor].used = 1;
|
|
|
|
_sysPalette.colors[curColor].r = (byte1 & 0x0F) * 0x11;
|
|
|
|
_sysPalette.colors[curColor].g = ((byte2 & 0xF0) >> 4) * 0x11;
|
|
|
|
_sysPalette.colors[curColor].b = (byte2 & 0x0F) * 0x11;
|
|
|
|
}
|
|
|
|
file.close();
|
2010-01-24 21:11:26 +00:00
|
|
|
// Directly set the palette, because setOnScreen() wont do a thing for amiga
|
|
|
|
_screen->setPalette(&_sysPalette);
|
2009-10-06 16:14:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-25 11:15:40 +00:00
|
|
|
// Called from picture class, some amiga sci1 games set half of the palette
|
2010-01-31 16:21:11 +00:00
|
|
|
void GfxPalette::modifyAmigaPalette(byte *data) {
|
2010-01-25 11:15:40 +00:00
|
|
|
int16 curColor, curPos = 0;
|
|
|
|
byte byte1, byte2;
|
|
|
|
for (curColor = 0; curColor < 16; curColor++) {
|
|
|
|
byte1 = data[curPos++];
|
|
|
|
byte2 = data[curPos++];
|
|
|
|
_sysPalette.colors[curColor].r = (byte1 & 0x0F) * 0x11;
|
|
|
|
_sysPalette.colors[curColor].g = ((byte2 & 0xF0) >> 4) * 0x11;
|
|
|
|
_sysPalette.colors[curColor].b = (byte2 & 0x0F) * 0x11;
|
|
|
|
}
|
|
|
|
_screen->setPalette(&_sysPalette);
|
|
|
|
}
|
|
|
|
|
2010-01-31 16:21:11 +00:00
|
|
|
void GfxPalette::setEGA() {
|
2010-01-24 20:31:01 +00:00
|
|
|
int curColor;
|
2009-10-09 20:21:21 +00:00
|
|
|
byte color1, color2;
|
2010-01-26 11:40:54 +00:00
|
|
|
|
|
|
|
_sysPalette.colors[1].r = 0x000; _sysPalette.colors[1].g = 0x000; _sysPalette.colors[1].b = 0x0AA;
|
|
|
|
_sysPalette.colors[2].r = 0x000; _sysPalette.colors[2].g = 0x0AA; _sysPalette.colors[2].b = 0x000;
|
|
|
|
_sysPalette.colors[3].r = 0x000; _sysPalette.colors[3].g = 0x0AA; _sysPalette.colors[3].b = 0x0AA;
|
|
|
|
_sysPalette.colors[4].r = 0x0AA; _sysPalette.colors[4].g = 0x000; _sysPalette.colors[4].b = 0x000;
|
|
|
|
_sysPalette.colors[5].r = 0x0AA; _sysPalette.colors[5].g = 0x000; _sysPalette.colors[5].b = 0x0AA;
|
|
|
|
_sysPalette.colors[6].r = 0x0AA; _sysPalette.colors[6].g = 0x055; _sysPalette.colors[6].b = 0x000;
|
|
|
|
_sysPalette.colors[7].r = 0x0AA; _sysPalette.colors[7].g = 0x0AA; _sysPalette.colors[7].b = 0x0AA;
|
|
|
|
_sysPalette.colors[8].r = 0x055; _sysPalette.colors[8].g = 0x055; _sysPalette.colors[8].b = 0x055;
|
|
|
|
_sysPalette.colors[9].r = 0x055; _sysPalette.colors[9].g = 0x055; _sysPalette.colors[9].b = 0x0FF;
|
|
|
|
_sysPalette.colors[10].r = 0x055; _sysPalette.colors[10].g = 0x0FF; _sysPalette.colors[10].b = 0x055;
|
|
|
|
_sysPalette.colors[11].r = 0x055; _sysPalette.colors[11].g = 0x0FF; _sysPalette.colors[11].b = 0x0FF;
|
|
|
|
_sysPalette.colors[12].r = 0x0FF; _sysPalette.colors[12].g = 0x055; _sysPalette.colors[12].b = 0x055;
|
|
|
|
_sysPalette.colors[13].r = 0x0FF; _sysPalette.colors[13].g = 0x055; _sysPalette.colors[13].b = 0x0FF;
|
|
|
|
_sysPalette.colors[14].r = 0x0FF; _sysPalette.colors[14].g = 0x0FF; _sysPalette.colors[14].b = 0x055;
|
|
|
|
_sysPalette.colors[15].r = 0x0FF; _sysPalette.colors[15].g = 0x0FF; _sysPalette.colors[15].b = 0x0FF;
|
2010-01-24 20:31:01 +00:00
|
|
|
for (curColor = 0; curColor <= 15; curColor++) {
|
|
|
|
_sysPalette.colors[curColor].used = 1;
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
2009-10-07 18:00:49 +00:00
|
|
|
// Now setting colors 16-254 to the correct mix colors that occur when not doing a dithering run on
|
|
|
|
// finished pictures
|
2010-01-24 20:31:01 +00:00
|
|
|
for (curColor = 0x10; curColor <= 0xFE; curColor++) {
|
2010-06-18 17:20:09 +00:00
|
|
|
_sysPalette.colors[curColor].used = 1;
|
2010-01-24 20:31:01 +00:00
|
|
|
color1 = curColor & 0x0F; color2 = curColor >> 4;
|
|
|
|
_sysPalette.colors[curColor].r = (_sysPalette.colors[color1].r >> 1) + (_sysPalette.colors[color2].r >> 1);
|
|
|
|
_sysPalette.colors[curColor].g = (_sysPalette.colors[color1].g >> 1) + (_sysPalette.colors[color2].g >> 1);
|
|
|
|
_sysPalette.colors[curColor].b = (_sysPalette.colors[color1].b >> 1) + (_sysPalette.colors[color2].b >> 1);
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
2010-06-18 17:40:13 +00:00
|
|
|
_sysPalette.timestamp = 1;
|
2009-10-06 16:14:40 +00:00
|
|
|
setOnScreen();
|
|
|
|
}
|
|
|
|
|
2010-06-20 13:15:45 +00:00
|
|
|
void GfxPalette::set(Palette *newPalette, bool force, bool forceRealMerge) {
|
2009-10-06 16:14:40 +00:00
|
|
|
uint32 systime = _sysPalette.timestamp;
|
2010-02-07 12:13:34 +00:00
|
|
|
|
2010-06-20 13:15:45 +00:00
|
|
|
if (force || newPalette->timestamp != systime) {
|
|
|
|
_sysPaletteChanged |= merge(newPalette, force, forceRealMerge);
|
|
|
|
newPalette->timestamp = _sysPalette.timestamp;
|
2010-04-02 18:48:17 +00:00
|
|
|
if (_sysPaletteChanged && _screen->_picNotValid == 0) { // && systime != _sysPalette.timestamp) {
|
|
|
|
// Removed timestamp checking, because this shouldnt be needed anymore. I'm leaving it commented just in
|
|
|
|
// case this causes regressions
|
2009-10-06 16:14:40 +00:00
|
|
|
setOnScreen();
|
2010-04-02 18:48:17 +00:00
|
|
|
_sysPaletteChanged = false;
|
|
|
|
}
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-20 13:15:45 +00:00
|
|
|
bool GfxPalette::merge(Palette *pFrom, bool force, bool forceRealMerge) {
|
2009-10-06 16:14:40 +00:00
|
|
|
uint16 res;
|
|
|
|
int i,j;
|
2010-02-07 12:13:34 +00:00
|
|
|
bool paletteChanged = false;
|
2010-01-26 21:12:13 +00:00
|
|
|
|
2010-06-17 16:06:01 +00:00
|
|
|
// for Laura Bow 2 demo
|
|
|
|
forceRealMerge |= _alwaysForceRealMerge;
|
|
|
|
|
2010-01-26 22:34:17 +00:00
|
|
|
if ((!forceRealMerge) && (getSciVersion() >= SCI_VERSION_1_1)) {
|
2010-01-26 21:12:13 +00:00
|
|
|
// SCI1.1+ doesnt do real merging anymore, but simply copying over the used colors from other palettes
|
|
|
|
for (i = 1; i < 255; i++) {
|
|
|
|
if (pFrom->colors[i].used) {
|
2010-06-20 13:15:45 +00:00
|
|
|
if ((pFrom->colors[i].r != _sysPalette.colors[i].r) || (pFrom->colors[i].g != _sysPalette.colors[i].g) || (pFrom->colors[i].b != _sysPalette.colors[i].b)) {
|
|
|
|
_sysPalette.colors[i].r = pFrom->colors[i].r;
|
|
|
|
_sysPalette.colors[i].g = pFrom->colors[i].g;
|
|
|
|
_sysPalette.colors[i].b = pFrom->colors[i].b;
|
2010-02-07 12:13:34 +00:00
|
|
|
paletteChanged = true;
|
|
|
|
}
|
2010-06-20 13:15:45 +00:00
|
|
|
_sysPalette.colors[i].used = pFrom->colors[i].used;
|
2010-01-26 21:12:13 +00:00
|
|
|
pFrom->mapping[i] = i;
|
|
|
|
}
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
2010-01-26 21:12:13 +00:00
|
|
|
} else {
|
|
|
|
// colors 0 (black) and 255 (white) are not affected by merging
|
|
|
|
for (i = 1 ; i < 255; i++) {
|
|
|
|
if (!pFrom->colors[i].used)// color is not used - so skip it
|
|
|
|
continue;
|
2010-01-29 16:26:40 +00:00
|
|
|
// forced palette merging or dest color is not used yet
|
2010-06-20 13:15:45 +00:00
|
|
|
if (force || (!_sysPalette.colors[i].used)) {
|
|
|
|
_sysPalette.colors[i].used = pFrom->colors[i].used;
|
|
|
|
if ((pFrom->colors[i].r != _sysPalette.colors[i].r) || (pFrom->colors[i].g != _sysPalette.colors[i].g) || (pFrom->colors[i].b != _sysPalette.colors[i].b)) {
|
|
|
|
_sysPalette.colors[i].r = pFrom->colors[i].r;
|
|
|
|
_sysPalette.colors[i].g = pFrom->colors[i].g;
|
|
|
|
_sysPalette.colors[i].b = pFrom->colors[i].b;
|
2010-02-07 12:13:34 +00:00
|
|
|
paletteChanged = true;
|
|
|
|
}
|
2010-01-26 21:12:13 +00:00
|
|
|
pFrom->mapping[i] = i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// is the same color already at the same position? -> match it directly w/o lookup
|
|
|
|
// this fixes games like lsl1demo/sq5 where the same rgb color exists multiple times and where we would
|
|
|
|
// otherwise match the wrong one (which would result into the pixels affected (or not) by palette changes)
|
2010-06-20 13:15:45 +00:00
|
|
|
if ((_sysPalette.colors[i].r == pFrom->colors[i].r) && (_sysPalette.colors[i].g == pFrom->colors[i].g) && (_sysPalette.colors[i].b == pFrom->colors[i].b)) {
|
2010-01-26 21:12:13 +00:00
|
|
|
pFrom->mapping[i] = i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// check if exact color could be matched
|
2010-06-20 13:15:45 +00:00
|
|
|
res = matchColor(pFrom->colors[i].r, pFrom->colors[i].g, pFrom->colors[i].b);
|
2010-01-26 21:12:13 +00:00
|
|
|
if (res & 0x8000) { // exact match was found
|
|
|
|
pFrom->mapping[i] = res & 0xFF;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// no exact match - see if there is an unused color
|
|
|
|
for (j = 1; j < 256; j++)
|
2010-06-20 13:15:45 +00:00
|
|
|
if (!_sysPalette.colors[j].used) {
|
|
|
|
_sysPalette.colors[j].used = pFrom->colors[i].used;
|
|
|
|
_sysPalette.colors[j].r = pFrom->colors[i].r;
|
|
|
|
_sysPalette.colors[j].g = pFrom->colors[i].g;
|
|
|
|
_sysPalette.colors[j].b = pFrom->colors[i].b;
|
2010-01-26 21:12:13 +00:00
|
|
|
pFrom->mapping[i] = j;
|
2010-02-07 12:13:34 +00:00
|
|
|
paletteChanged = true;
|
2010-01-26 21:12:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// if still no luck - set an approximate color
|
|
|
|
if (j == 256) {
|
|
|
|
pFrom->mapping[i] = res & 0xFF;
|
2010-06-20 13:15:45 +00:00
|
|
|
_sysPalette.colors[res & 0xFF].used |= 0x10;
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-20 13:25:08 +00:00
|
|
|
|
|
|
|
// We don't update the timestamp here for SCI1.1, it's only updated on kDrawPic calls
|
|
|
|
if (getSciVersion() < SCI_VERSION_1_1)
|
|
|
|
_sysPalette.timestamp = g_system->getMillis() * 60 / 1000;
|
2010-02-07 12:13:34 +00:00
|
|
|
return paletteChanged;
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
|
2010-06-20 13:25:08 +00:00
|
|
|
// This is used for SCI1.1 and called from kDrawPic. We only update sysPalette timestamp this way for SCI1.1
|
|
|
|
void GfxPalette::increaseSysTimestamp() {
|
|
|
|
_sysPalette.timestamp++;
|
|
|
|
}
|
|
|
|
|
2010-06-20 13:15:45 +00:00
|
|
|
uint16 GfxPalette::matchColor(byte r, byte g, byte b) {
|
2009-10-06 16:14:40 +00:00
|
|
|
byte found = 0xFF;
|
|
|
|
int diff = 0x2FFFF, cdiff;
|
|
|
|
int16 dr,dg,db;
|
|
|
|
|
2009-12-30 21:43:57 +00:00
|
|
|
for (int i = 1; i < 255; i++) {
|
2010-06-20 13:15:45 +00:00
|
|
|
if ((!_sysPalette.colors[i].used))
|
2009-10-06 16:14:40 +00:00
|
|
|
continue;
|
2010-06-20 13:15:45 +00:00
|
|
|
dr = _sysPalette.colors[i].r - r;
|
|
|
|
dg = _sysPalette.colors[i].g - g;
|
|
|
|
db = _sysPalette.colors[i].b - b;
|
2009-10-06 16:14:40 +00:00
|
|
|
// minimum squares match
|
2009-10-15 09:54:45 +00:00
|
|
|
cdiff = (dr*dr) + (dg*dg) + (db*db);
|
2009-10-06 16:14:40 +00:00
|
|
|
// minimum sum match (Sierra's)
|
|
|
|
// cdiff = ABS(dr) + ABS(dg) + ABS(db);
|
|
|
|
if (cdiff < diff) {
|
|
|
|
if (cdiff == 0)
|
|
|
|
return i | 0x8000; // setting this flag to indicate exact match
|
|
|
|
found = i;
|
|
|
|
diff = cdiff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2010-01-31 16:21:11 +00:00
|
|
|
void GfxPalette::getSys(Palette *pal) {
|
2009-10-06 16:14:40 +00:00
|
|
|
if (pal != &_sysPalette)
|
2010-01-05 01:37:57 +00:00
|
|
|
memcpy(pal, &_sysPalette,sizeof(Palette));
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 16:21:11 +00:00
|
|
|
void GfxPalette::setOnScreen() {
|
2009-10-06 16:14:40 +00:00
|
|
|
// if (pal != &_sysPalette)
|
2010-01-05 01:37:57 +00:00
|
|
|
// memcpy(&_sysPalette,pal,sizeof(Palette));
|
2010-01-24 21:11:26 +00:00
|
|
|
// We dont change palette at all times for amiga
|
2010-01-25 12:34:40 +00:00
|
|
|
if (_resMan->isAmiga32color())
|
2010-01-24 21:11:26 +00:00
|
|
|
return;
|
2009-10-06 16:14:40 +00:00
|
|
|
_screen->setPalette(&_sysPalette);
|
2010-05-24 17:21:11 +00:00
|
|
|
|
|
|
|
// Redraw the Mac SCI1.1 Icon bar every palette change
|
2010-05-24 21:47:06 +00:00
|
|
|
if (g_sci->_gfxMacIconBar)
|
|
|
|
g_sci->_gfxMacIconBar->drawIcons();
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 16:21:11 +00:00
|
|
|
bool GfxPalette::kernelSetFromResource(GuiResourceId resourceId, bool force) {
|
|
|
|
Resource *palResource = _resMan->findResource(ResourceId(kResourceTypePalette, resourceId), 0);
|
|
|
|
Palette palette;
|
|
|
|
|
|
|
|
if (palResource) {
|
|
|
|
createFromData(palResource->data, &palette);
|
2010-02-07 14:47:40 +00:00
|
|
|
set(&palette, force);
|
2010-01-31 16:21:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxPalette::kernelSetFlag(uint16 fromColor, uint16 toColor, uint16 flag) {
|
2009-10-20 18:45:46 +00:00
|
|
|
uint16 colorNr;
|
|
|
|
for (colorNr = fromColor; colorNr < toColor; colorNr++) {
|
|
|
|
_sysPalette.colors[colorNr].used |= flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-31 16:21:11 +00:00
|
|
|
void GfxPalette::kernelUnsetFlag(uint16 fromColor, uint16 toColor, uint16 flag) {
|
2009-10-20 18:45:46 +00:00
|
|
|
uint16 colorNr;
|
|
|
|
for (colorNr = fromColor; colorNr < toColor; colorNr++) {
|
|
|
|
_sysPalette.colors[colorNr].used &= ~flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-31 16:21:11 +00:00
|
|
|
void GfxPalette::kernelSetIntensity(uint16 fromColor, uint16 toColor, uint16 intensity, bool setPalette) {
|
2009-10-14 19:39:07 +00:00
|
|
|
memset(&_sysPalette.intensity[0] + fromColor, intensity, toColor - fromColor);
|
|
|
|
if (setPalette)
|
|
|
|
setOnScreen();
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 16:26:15 +00:00
|
|
|
int16 GfxPalette::kernelFindColor(uint16 r, uint16 g, uint16 b) {
|
2010-06-20 13:15:45 +00:00
|
|
|
return matchColor(r, g, b) & 0xFF;
|
2010-01-31 16:21:11 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 16:44:58 +00:00
|
|
|
// Returns true, if palette got changed
|
2010-01-31 16:21:11 +00:00
|
|
|
bool GfxPalette::kernelAnimate(byte fromColor, byte toColor, int speed) {
|
2010-01-05 01:37:57 +00:00
|
|
|
Color col;
|
2010-01-04 18:33:31 +00:00
|
|
|
//byte colorNr;
|
2010-01-04 16:44:58 +00:00
|
|
|
int16 colorCount;
|
2009-12-01 19:19:58 +00:00
|
|
|
uint32 now = g_system->getMillis() * 60 / 1000;
|
2009-10-17 17:35:41 +00:00
|
|
|
|
2009-10-06 16:14:40 +00:00
|
|
|
// search for sheduled animations with the same 'from' value
|
2010-01-04 16:44:58 +00:00
|
|
|
// schedule animation...
|
|
|
|
int scheduleCount = _schedules.size();
|
|
|
|
int scheduleNr;
|
|
|
|
for (scheduleNr = 0; scheduleNr < scheduleCount; scheduleNr++) {
|
|
|
|
if (_schedules[scheduleNr].from == fromColor)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (scheduleNr == scheduleCount) {
|
|
|
|
// adding a new schedule
|
2010-01-05 01:37:57 +00:00
|
|
|
PalSchedule newSchedule;
|
2010-01-04 16:44:58 +00:00
|
|
|
newSchedule.from = fromColor;
|
|
|
|
newSchedule.schedule = now + ABS(speed);
|
|
|
|
_schedules.push_back(newSchedule);
|
|
|
|
scheduleCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (scheduleNr = 0; scheduleNr < scheduleCount; scheduleNr++) {
|
|
|
|
if (_schedules[scheduleNr].from == fromColor) {
|
|
|
|
if (_schedules[scheduleNr].schedule <= now) {
|
2009-10-06 16:14:40 +00:00
|
|
|
if (speed > 0) {
|
2010-01-04 16:44:58 +00:00
|
|
|
// TODO: Not really sure about this, sierra sci seems to do exactly this here
|
2009-10-06 16:14:40 +00:00
|
|
|
col = _sysPalette.colors[fromColor];
|
2010-01-04 16:44:58 +00:00
|
|
|
if (fromColor < toColor) {
|
|
|
|
colorCount = toColor - fromColor - 1;
|
2010-01-05 01:37:57 +00:00
|
|
|
memmove(&_sysPalette.colors[fromColor], &_sysPalette.colors[fromColor + 1], colorCount * sizeof(Color));
|
2010-01-04 16:44:58 +00:00
|
|
|
}
|
2009-10-06 16:14:40 +00:00
|
|
|
_sysPalette.colors[toColor - 1] = col;
|
|
|
|
} else {
|
|
|
|
col = _sysPalette.colors[toColor - 1];
|
2010-01-04 16:44:58 +00:00
|
|
|
if (fromColor < toColor) {
|
|
|
|
colorCount = toColor - fromColor - 1;
|
2010-01-05 01:37:57 +00:00
|
|
|
memmove(&_sysPalette.colors[fromColor + 1], &_sysPalette.colors[fromColor], colorCount * sizeof(Color));
|
2010-01-04 16:44:58 +00:00
|
|
|
}
|
2009-10-06 16:14:40 +00:00
|
|
|
_sysPalette.colors[fromColor] = col;
|
|
|
|
}
|
|
|
|
// removing schedule
|
2010-01-04 16:44:58 +00:00
|
|
|
_schedules[scheduleNr].schedule = now + ABS(speed);
|
|
|
|
// TODO: Not sure when sierra actually removes a schedule
|
|
|
|
//_schedules.remove_at(scheduleNr);
|
|
|
|
return true;
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
2010-01-04 16:44:58 +00:00
|
|
|
return false;
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-04 16:44:58 +00:00
|
|
|
return false;
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 16:21:11 +00:00
|
|
|
void GfxPalette::kernelAnimateSet() {
|
|
|
|
setOnScreen();
|
|
|
|
}
|
|
|
|
|
2010-02-07 12:00:06 +00:00
|
|
|
void GfxPalette::kernelAssertPalette(GuiResourceId resourceId) {
|
|
|
|
warning("kAssertPalette %d", resourceId);
|
|
|
|
}
|
|
|
|
|
2009-10-20 21:25:50 +00:00
|
|
|
// palVary
|
|
|
|
// init - only does, if palVaryOn == false
|
|
|
|
// target, start, new palette allocation
|
|
|
|
// palVaryOn = true
|
|
|
|
// palDirection = 1
|
|
|
|
// palStop = 64
|
|
|
|
// palTime = from caller
|
|
|
|
// copy resource palette to target
|
|
|
|
// init target palette (used = 1 on all colors, color 0 = RGB 0, 0, 0 color 255 = RGB 0xFF, 0xFF, 0xFF
|
|
|
|
// copy sysPalette to startPalette
|
|
|
|
// init new palette like target palette
|
|
|
|
// palPercent = 1
|
|
|
|
// do various things
|
|
|
|
// return 1
|
|
|
|
// deinit - unloads target palette, kills timer hook, disables palVaryOn
|
|
|
|
// pause - counts up or down, if counter != 0 -> signal wont get counted up by timer
|
|
|
|
// will only count down to 0
|
|
|
|
//
|
|
|
|
// Restarting game
|
|
|
|
// palVary = false
|
|
|
|
// palPercent = 0
|
|
|
|
// call palVary deinit
|
|
|
|
//
|
|
|
|
// Saving/restoring
|
|
|
|
// need to save start and target-palette, when palVaryOn = true
|
|
|
|
|
2010-06-20 12:21:57 +00:00
|
|
|
void GfxPalette::startPalVary(GuiResourceId resourceId, uint16 ticks) {
|
|
|
|
kernelSetFromResource(resourceId, true);
|
2010-02-07 12:00:06 +00:00
|
|
|
return;
|
|
|
|
|
2010-06-20 12:21:57 +00:00
|
|
|
if (_palVaryResourceId >= 0) // another palvary is taking place, return
|
2010-02-04 23:17:33 +00:00
|
|
|
return;
|
|
|
|
|
2010-06-20 12:21:57 +00:00
|
|
|
_palVaryResourceId = resourceId;
|
2010-02-04 23:17:33 +00:00
|
|
|
_palVaryStart = g_system->getMillis();
|
|
|
|
_palVaryEnd = _palVaryStart + ticks * 1000 / 60;
|
2010-06-15 10:51:10 +00:00
|
|
|
g_sci->getTimerManager()->installTimerProc(&palVaryCallback, 1000000 / 60, this);
|
2010-02-04 23:17:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GfxPalette::togglePalVary(bool pause) {
|
|
|
|
// this call is actually counting states, so calling this 3 times with true will require calling it later
|
|
|
|
// 3 times with false to actually remove pause
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxPalette::stopPalVary() {
|
2010-02-13 17:42:49 +00:00
|
|
|
g_sci->getTimerManager()->removeTimerProc(&palVaryCallback);
|
2010-02-04 23:17:33 +00:00
|
|
|
|
|
|
|
// HACK: just set the target palette
|
2010-06-20 12:21:57 +00:00
|
|
|
kernelSetFromResource(_palVaryResourceId, true);
|
|
|
|
|
|
|
|
_palVaryResourceId = -1; // invalidate the target palette
|
2010-02-04 23:17:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GfxPalette::palVaryCallback(void *refCon) {
|
|
|
|
((GfxPalette *)refCon)->doPalVary();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxPalette::doPalVary() {
|
|
|
|
// TODO: do palette transition here...
|
|
|
|
}
|
|
|
|
|
2009-10-06 16:14:40 +00:00
|
|
|
} // End of namespace Sci
|