2011-06-27 11:06: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "neverhood/palette.h"
|
|
|
|
#include "neverhood/resource.h"
|
2011-07-04 10:52:07 +00:00
|
|
|
#include "neverhood/screen.h"
|
2011-06-27 11:06:40 +00:00
|
|
|
|
|
|
|
namespace Neverhood {
|
|
|
|
|
2011-07-04 10:52:07 +00:00
|
|
|
// Palette
|
|
|
|
|
2011-06-27 11:06:40 +00:00
|
|
|
Palette::Palette(NeverhoodEngine *vm) : Entity(vm, 0) {
|
|
|
|
_status = 0;
|
|
|
|
_palette = new byte[1024];
|
|
|
|
memset(_palette, 0, 1024);
|
|
|
|
SetUpdateHandler(&Palette::update);
|
|
|
|
}
|
|
|
|
|
2011-06-27 13:39:29 +00:00
|
|
|
Palette::Palette(NeverhoodEngine *vm, byte *palette) : Entity(vm, 0) {
|
|
|
|
_status = 0;
|
|
|
|
_palette = new byte[1024];
|
|
|
|
memcpy(_palette, palette, 1024);
|
|
|
|
SetUpdateHandler(&Palette::update);
|
|
|
|
}
|
|
|
|
|
|
|
|
Palette::Palette(NeverhoodEngine *vm, const char *filename) : Entity(vm, 0) {
|
|
|
|
PaletteResource paletteResource(_vm);
|
|
|
|
_status = 0;
|
|
|
|
_palette = new byte[1024];
|
|
|
|
// TODO: paletteResource.load(calcHash(filename));
|
|
|
|
// paletteResource.copyPalette(_palette);
|
|
|
|
SetUpdateHandler(&Palette::update);
|
|
|
|
}
|
|
|
|
|
|
|
|
Palette::Palette(NeverhoodEngine *vm, uint32 fileHash) : Entity(vm, 0) {
|
|
|
|
PaletteResource paletteResource(_vm);
|
|
|
|
_status = 0;
|
|
|
|
_palette = new byte[1024];
|
|
|
|
paletteResource.load(fileHash);
|
|
|
|
paletteResource.copyPalette(_palette);
|
|
|
|
SetUpdateHandler(&Palette::update);
|
|
|
|
}
|
|
|
|
|
2011-06-27 11:06:40 +00:00
|
|
|
Palette::~Palette() {
|
2011-07-04 10:52:07 +00:00
|
|
|
_vm->_screen->unsetPaletteData(_palette);
|
2011-06-27 11:06:40 +00:00
|
|
|
delete[] _palette;
|
|
|
|
}
|
|
|
|
|
2011-06-27 13:39:29 +00:00
|
|
|
void Palette::usePalette() {
|
2011-07-04 10:52:07 +00:00
|
|
|
_vm->_screen->setPaletteData(_palette);
|
2011-06-27 13:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Palette::addPalette(const char *filename, int toIndex, int count, int fromIndex) {
|
2011-09-19 08:00:56 +00:00
|
|
|
addPalette(calcHash(filename), toIndex, count, fromIndex);
|
2011-06-27 13:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Palette::addPalette(uint32 fileHash, int toIndex, int count, int fromIndex) {
|
|
|
|
PaletteResource paletteResource(_vm);
|
|
|
|
if (toIndex + count > 256)
|
|
|
|
count = 256 - toIndex;
|
|
|
|
paletteResource.load(fileHash);
|
|
|
|
memcpy(_palette + toIndex * 4, paletteResource.palette() + fromIndex * 4, count * 4);
|
2011-07-04 10:52:07 +00:00
|
|
|
_vm->_screen->testPalette(_palette);
|
2011-06-27 13:39:29 +00:00
|
|
|
}
|
|
|
|
|
2011-07-04 17:58:38 +00:00
|
|
|
void Palette::copyPalette(const byte *palette, int toIndex, int count, int fromIndex) {
|
|
|
|
if (toIndex + count > 256)
|
|
|
|
count = 256 - toIndex;
|
|
|
|
memcpy(_palette + toIndex * 4, palette + fromIndex * 4, count * 4);
|
|
|
|
_vm->_screen->testPalette(_palette);
|
|
|
|
}
|
|
|
|
|
2011-06-27 13:39:29 +00:00
|
|
|
void Palette::startFadeToBlack(int counter) {
|
2011-07-04 10:52:07 +00:00
|
|
|
debug("Palette::startFadeToBlack(%d)", counter);
|
2011-06-27 13:39:29 +00:00
|
|
|
if (counter == 0)
|
|
|
|
counter = 1;
|
|
|
|
_fadeToR = 0;
|
|
|
|
_fadeToG = 0;
|
|
|
|
_fadeToB = 0;
|
|
|
|
_palCounter = counter;
|
|
|
|
_fadeStep = 255 / counter;
|
|
|
|
_status = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Palette::startFadeToWhite(int counter) {
|
2011-07-04 10:52:07 +00:00
|
|
|
debug("Palette::startFadeToWhite(%d)", counter);
|
2011-06-27 13:39:29 +00:00
|
|
|
if (counter == 0)
|
|
|
|
counter = 1;
|
|
|
|
_fadeToR = 255;
|
|
|
|
_fadeToG = 255;
|
|
|
|
_fadeToB = 255;
|
|
|
|
_palCounter = counter;
|
|
|
|
_fadeStep = 255 / counter;
|
|
|
|
_status = 1;
|
|
|
|
}
|
|
|
|
|
2011-06-27 11:06:40 +00:00
|
|
|
void Palette::update() {
|
2011-09-08 15:07:07 +00:00
|
|
|
debug(2, "Palette::update() _status = %d", _status);
|
2011-06-27 13:39:29 +00:00
|
|
|
if (_status == 1) {
|
2011-07-04 10:52:07 +00:00
|
|
|
if (_palCounter > 1) {
|
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
fadeColor(_palette + i * 4, _fadeToR, _fadeToG, _fadeToB);
|
|
|
|
}
|
|
|
|
_vm->_screen->testPalette(_palette);
|
|
|
|
_palCounter--;
|
|
|
|
} else {
|
|
|
|
memset(_palette, 0, 1024);
|
|
|
|
_status = 0;
|
2011-06-27 13:39:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Palette::fadeColor(byte *rgb, byte toR, byte toG, byte toB) {
|
|
|
|
#define FADE(color, toColor) color += _fadeStep < toColor - color ? _fadeStep : (-_fadeStep <= toColor - color ? toColor - color : -_fadeStep)
|
|
|
|
FADE(rgb[0], toR);
|
|
|
|
FADE(rgb[1], toG);
|
|
|
|
FADE(rgb[2], toB);
|
|
|
|
#undef FADE
|
2011-06-27 11:06:40 +00:00
|
|
|
}
|
|
|
|
|
2011-07-04 10:52:07 +00:00
|
|
|
// Palette2
|
|
|
|
|
|
|
|
Palette2::Palette2(NeverhoodEngine *vm)
|
|
|
|
: Palette(vm) {
|
|
|
|
_basePalette = new byte[1024];
|
|
|
|
SetUpdateHandler(&Palette2::update);
|
|
|
|
}
|
|
|
|
|
|
|
|
Palette2::Palette2(NeverhoodEngine *vm, uint32 fileHash)
|
|
|
|
: Palette(vm, fileHash) {
|
|
|
|
_basePalette = new byte[1024];
|
|
|
|
SetUpdateHandler(&Palette2::update);
|
|
|
|
}
|
|
|
|
|
|
|
|
Palette2::~Palette2() {
|
|
|
|
delete _basePalette;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Palette2::update() {
|
|
|
|
debug("Palette2::update() _status = %d", _status);
|
|
|
|
if (_status == 1) {
|
|
|
|
Palette::update();
|
|
|
|
} else if (_status == 2) {
|
|
|
|
if (_palCounter > 1) {
|
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
fadeColor(_palette + i * 4, _basePalette[i * 4 + 0], _basePalette[i * 4 + 1], _basePalette[i * 4 + 2]);
|
|
|
|
}
|
|
|
|
_vm->_screen->testPalette(_palette);
|
|
|
|
_palCounter--;
|
|
|
|
} else {
|
|
|
|
memcpy(_palette, _basePalette, 256 * 4);
|
|
|
|
_status = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-26 08:38:19 +00:00
|
|
|
void Palette2::copyBasePalette(int toIndex, int count, int fromIndex) {
|
|
|
|
if (toIndex + count > 256)
|
|
|
|
count = 256 - toIndex;
|
|
|
|
memcpy(_basePalette + toIndex * 4, _palette + fromIndex * 4, count * 4);
|
|
|
|
}
|
|
|
|
|
2011-09-19 08:00:56 +00:00
|
|
|
void Palette2::addBasePalette(uint32 fileHash, int toIndex, int count, int fromIndex) {
|
2011-07-04 10:52:07 +00:00
|
|
|
PaletteResource paletteResource(_vm);
|
|
|
|
if (toIndex + count > 256)
|
|
|
|
count = 256 - toIndex;
|
|
|
|
paletteResource.load(fileHash);
|
|
|
|
memcpy(_basePalette + toIndex * 4, paletteResource.palette() + fromIndex * 4, count * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Palette2::startFadeToPalette(int counter) {
|
|
|
|
debug("Palette2::startFadeToPalette(%d)", counter);
|
|
|
|
if (counter == 0)
|
|
|
|
counter = 1;
|
|
|
|
_palCounter = counter;
|
|
|
|
_fadeStep = 255 / counter;
|
|
|
|
_status = 2;
|
|
|
|
}
|
|
|
|
|
2011-06-27 11:06:40 +00:00
|
|
|
} // End of namespace Neverhood
|