aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJohannes Schickel2009-06-22 02:34:35 +0000
committerJohannes Schickel2009-06-22 02:34:35 +0000
commitb448d506b89209d79bc153b6b0759ad926fa8794 (patch)
tree2424f442ef037a1a088c57d934b7b5a033efe890 /engines
parent3424dfda98c59543ec1bea464723dca2221a6965 (diff)
downloadscummvm-rg350-b448d506b89209d79bc153b6b0759ad926fa8794.tar.gz
scummvm-rg350-b448d506b89209d79bc153b6b0759ad926fa8794.tar.bz2
scummvm-rg350-b448d506b89209d79bc153b6b0759ad926fa8794.zip
Start refactoring palette handling into new class "Palette".
svn-id: r41739
Diffstat (limited to 'engines')
-rw-r--r--engines/kyra/screen.cpp136
-rw-r--r--engines/kyra/screen.h86
-rw-r--r--engines/kyra/screen_lol.cpp20
-rw-r--r--engines/kyra/screen_v2.cpp2
4 files changed, 202 insertions, 42 deletions
diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp
index 64236e833f..2442286bd2 100644
--- a/engines/kyra/screen.cpp
+++ b/engines/kyra/screen.cpp
@@ -52,14 +52,13 @@ Screen::~Screen() {
delete[] _sjisFontData;
delete[] _sjisTempPage;
- delete[] _currentPalette;
- delete[] _screenPalette;
+ delete _screenPalette;
delete[] _decodeShapeBuffer;
delete[] _animBlockPtr;
if (_vm->gameFlags().platform != Common::kPlatformAmiga) {
for (int i = 0; i < ARRAYSIZE(_palettes); ++i)
- delete[] _palettes[i];
+ delete _palettes[i];
}
CursorMan.popAllCursors();
@@ -124,29 +123,25 @@ bool Screen::init() {
memset(_shapePages, 0, sizeof(_shapePages));
memset(_palettes, 0, sizeof(_palettes));
- _screenPalette = new uint8[768];
+
+ _screenPalette = new Palette(768);
assert(_screenPalette);
- memset(_screenPalette, 0, 768);
if (_vm->gameFlags().platform == Common::kPlatformAmiga) {
- _currentPalette = new uint8[1248];
- assert(_currentPalette);
- memset(_currentPalette, 0, 1248);
-
- for (int i = 0; i < 6; ++i)
- _palettes[i] = _currentPalette + (i+1)*96;
+ for (int i = 0; i < 7; ++i) {
+ _palettes[i] = new Palette(32);
+ assert(_palettes[i]);
+ }
} else {
- _currentPalette = new uint8[768];
- assert(_currentPalette);
- memset(_currentPalette, 0, 768);
- for (int i = 0; i < 3; ++i) {
- _palettes[i] = new uint8[768];
+ for (int i = 0; i < 4; ++i) {
+ _palettes[i] = new Palette(768);
assert(_palettes[i]);
- memset(_palettes[i], 0, 768);
}
}
+ _currentPalette = _palettes[0]->getData();
setScreenPalette(_currentPalette);
+
_curDim = 0;
_charWidth = 0;
_charOffset = 0;
@@ -543,7 +538,7 @@ void Screen::getFadeParams(const uint8 *palette, int delay, int &delayInc, int &
const int colors = (_vm->gameFlags().platform == Common::kPlatformAmiga ? 32 : 256) * 3;
for (int i = 0; i < colors; ++i) {
- diff = ABS(palette[i] - _screenPalette[i]);
+ diff = ABS(palette[i] - (*_screenPalette)[i]);
maxDiff = MAX<uint8>(maxDiff, diff);
}
@@ -563,7 +558,7 @@ int Screen::fadePalStep(const uint8 *palette, int diff) {
const int colors = (_vm->gameFlags().platform == Common::kPlatformAmiga ? 32 : (_use16ColorMode ? 16 : 256)) * 3;
uint8 fadePal[768];
- memcpy(fadePal, _screenPalette, colors);
+ memcpy(fadePal, _screenPalette->getData(), colors);
bool needRefresh = false;
@@ -623,8 +618,7 @@ void Screen::setScreenPalette(const uint8 *palData) {
const int colors = (_vm->gameFlags().platform == Common::kPlatformAmiga ? 32 : 256);
uint8 screenPal[256 * 4];
- if (palData != _screenPalette)
- memcpy(_screenPalette, palData, colors*3);
+ _screenPalette->copy(palData, 0, colors);
if (_use16ColorMode && _vm->gameFlags().platform == Common::kPlatformPC98) {
for (int l = 0; l < 1024; l += 64) {
@@ -639,8 +633,6 @@ void Screen::setScreenPalette(const uint8 *palData) {
palData = tp;
}
} else {
- if (palData != _screenPalette)
- memcpy(_screenPalette, palData, colors*3);
for (int i = 0; i < colors; ++i) {
screenPal[4 * i + 0] = (palData[0] << 2) | (palData[0] & 3);
screenPal[4 * i + 1] = (palData[1] << 2) | (palData[1] & 3);
@@ -2671,11 +2663,8 @@ void Screen::setMouseCursor(int x, int y, const byte *shape) {
}
uint8 *Screen::getPalette(int num) {
- assert(num >= 0 && num < (_vm->gameFlags().platform == Common::kPlatformAmiga ? 6 : 4));
- if (num == 0)
- return _currentPalette;
-
- return _palettes[num-1];
+ assert(num >= 0 && num < (_vm->gameFlags().platform == Common::kPlatformAmiga ? 7 : 4));
+ return _palettes[num]->getData();
}
byte Screen::getShapeFlag1(int x, int y) {
@@ -3249,5 +3238,96 @@ void Screen::drawCharSJIS(uint16 c, int x, int y) {
#pragma mark -
+Palette::Palette(const int numColors) : _palData(0), _numColors(numColors) {
+ _palData = new uint8[numColors * 3];
+ assert(_palData);
+
+ memset(_palData, 0, numColors * 3);
+}
+
+Palette::~Palette() {
+ delete[] _palData;
+ _palData = 0;
+}
+
+void Palette::loadVGAPalette(Common::ReadStream &stream, int colors) {
+ if (colors == -1)
+ colors = _numColors;
+
+ assert(colors <= _numColors);
+
+ stream.read(_palData, colors * 3);
+ memset(_palData + colors * 3, 0, (_numColors - colors) * 3);
+}
+
+void Palette::loadAmigaPalette(Common::ReadStream &stream, int colors) {
+ if (colors == -1)
+ colors = _numColors;
+
+ assert(colors <= _numColors);
+
+ assert(colors % 2 == 0);
+ assert(colors / 2 <= 256);
+
+ for (int i = 0; i < (colors >> 1); ++i) {
+ uint16 col = stream.readUint16BE();
+ _palData[i * 3 + 2] = (col & 0xF) << 2; col >>= 4;
+ _palData[i * 3 + 1] = (col & 0xF) << 2; col >>= 4;
+ _palData[i * 3 + 0] = (col & 0xF) << 2; col >>= 4;
+ }
+
+ memset(_palData + colors * 3, 0, (_numColors - colors) * 3);
+}
+
+void Palette::clear() {
+ memset(_palData, 0, _numColors * 3);
+}
+
+void Palette::copy(const Palette &source, int firstCol, int numCols, int dstStart) {
+ if (numCols == -1)
+ numCols = MIN(source.getNumColors(), _numColors) - firstCol;
+ if (dstStart == -1)
+ dstStart = firstCol;
+
+ assert(numCols >= 0 && numCols < _numColors);
+ assert(firstCol >= 0 && firstCol < source.getNumColors());
+ assert(dstStart >= 0 && dstStart + numCols < _numColors);
+
+ memcpy(_palData + dstStart * 3, source._palData + firstCol * 3, numCols * 3);
+}
+
+void Palette::copy(const uint8 *source, int firstCol, int numCols, int dstStart) {
+ if (source == _palData)
+ return;
+
+ if (dstStart == -1)
+ dstStart = firstCol;
+
+ assert(numCols >= 0 && numCols < _numColors);
+ assert(firstCol >= 0);
+ assert(dstStart >= 0 && dstStart + numCols < _numColors);
+
+ memcpy(_palData + dstStart * 3, source + firstCol * 3, numCols * 3);
+}
+
+uint8 *Palette::fetchRealPalette() const {
+ uint8 *buffer = new uint8[_numColors * 3];
+ assert(buffer);
+
+ uint8 *dst = buffer;
+ const uint8 *palData = _palData;
+
+ for (int i = 0; i < _numColors; ++i) {
+ dst[0] = (palData[0] << 2) | (palData[0] & 3);
+ dst[1] = (palData[1] << 2) | (palData[1] & 3);
+ dst[2] = (palData[2] << 2) | (palData[2] & 3);
+
+ dst += 3;
+ palData += 3;
+ }
+
+ return buffer;
+}
+
} // End of namespace Kyra
diff --git a/engines/kyra/screen.h b/engines/kyra/screen.h
index 9eb17b1d39..aee8e955c3 100644
--- a/engines/kyra/screen.h
+++ b/engines/kyra/screen.h
@@ -30,6 +30,7 @@
#include "common/func.h"
#include "common/list.h"
#include "common/rect.h"
+#include "common/stream.h"
class OSystem;
@@ -61,6 +62,85 @@ struct Font {
uint8 lastGlyph;
};
+/**
+ * A class that manages KYRA palettes.
+ *
+ * This class stores the palette data as VGA RGB internally.
+ */
+class Palette {
+public:
+ Palette(const int numColors);
+ ~Palette();
+
+ /**
+ * Load a VGA palette from the given stream.
+ */
+ void loadVGAPalette(Common::ReadStream &stream, const int colors = -1);
+
+ /**
+ * Load a AMIGA palette from the given stream.
+ */
+ void loadAmigaPalette(Common::ReadStream &stream, const int colors = -1);
+
+ /**
+ * Return the number of colors this palette manages.
+ */
+ int getNumColors() const { return _numColors; }
+
+ /**
+ * Set all palette colors to black.
+ */
+ void clear();
+
+ /**
+ * Copy data from another palette.
+ *
+ * @param source palette to copy data from.
+ * @param firstCol the first color of the source which should be copied.
+ * @param numCols number of colors, which should be copied. -1 all remaining colors.
+ * @param dstStart the first color, which should be ovewritten. If -1 firstCol will be used as start.
+ */
+ void copy(const Palette &source, int firstCol = 0, int numCols = -1, int dstStart = -1);
+
+ /**
+ * Copy data from a raw VGA palette.
+ *
+ * @param source source buffer
+ * @param firstCol the first color of the source which should be copied.
+ * @param numCols number of colors, which should be copied.
+ * @param dstStart the first color, which should be ovewritten. If -1 firstCol will be used as start.
+ */
+ void copy(const uint8 *source, int firstCol, int numCols, int dstStart = -1);
+
+ /**
+ * Fetch a RGB palette.
+ *
+ * @return a pointer to the RGB palette data, the client must delete[] it.
+ */
+ uint8 *fetchRealPalette() const;
+
+ //XXX
+ uint8 &operator[](const int index) {
+ assert(index >= 0 && index <= _numColors * 3);
+ return _palData[index];
+ }
+
+ const uint8 &operator[](const int index) const {
+ assert(index >= 0 && index <= _numColors * 3);
+ return _palData[index];
+ }
+
+ /**
+ * Gets raw access to the palette.
+ *
+ * TODO: Get rid of this.
+ */
+ uint8 *getData() { return _palData; }
+private:
+ uint8 *_palData;
+ const int _numColors;
+};
+
class Screen {
public:
enum {
@@ -149,7 +229,7 @@ public:
void setPaletteIndex(uint8 index, uint8 red, uint8 green, uint8 blue);
void setScreenPalette(const uint8 *palData);
- const uint8 *getScreenPalette() const { return _screenPalette; }
+ const uint8 *getScreenPalette() const { return _screenPalette->getData(); }
void getRealPalette(int num, uint8 *dst);
uint8 *getPalette(int num);
@@ -280,8 +360,8 @@ protected:
uint8 *_sjisSourceChar;
uint8 _sjisInvisibleColor;
- uint8 *_screenPalette;
- uint8 *_palettes[6];
+ Palette *_screenPalette;
+ Palette *_palettes[7];
Font _fonts[FID_NUM];
uint8 _textColorsMap[16];
diff --git a/engines/kyra/screen_lol.cpp b/engines/kyra/screen_lol.cpp
index 2556464394..a7e3c3a1bb 100644
--- a/engines/kyra/screen_lol.cpp
+++ b/engines/kyra/screen_lol.cpp
@@ -838,18 +838,18 @@ void Screen_LoL::fadeToBlack(int delay, const UpdateFunctor *upFunc) {
}
void Screen_LoL::fadeToPalette1(int delay) {
- loadSpecialColors(_palettes[0]);
- fadePalette(_palettes[0], delay);
+ loadSpecialColors(getPalette(1));
+ fadePalette(getPalette(1), delay);
_fadeFlag = 0;
}
void Screen_LoL::loadSpecialColors(uint8 *destPalette) {
- memcpy(destPalette + 0x240, _screenPalette + 0x240, 12);
+ memcpy(destPalette + 0x240, _screenPalette->getData() + 0x240, 12);
}
void Screen_LoL::copyColor(int dstColorIndex, int srcColorIndex) {
- uint8 *s = _screenPalette + srcColorIndex * 3;
- uint8 *d = _screenPalette + dstColorIndex * 3;
+ uint8 *s = _screenPalette->getData() + srcColorIndex * 3;
+ uint8 *d = _screenPalette->getData() + dstColorIndex * 3;
memcpy(d, s, 3);
uint8 ci[4];
@@ -862,8 +862,8 @@ void Screen_LoL::copyColor(int dstColorIndex, int srcColorIndex) {
}
bool Screen_LoL::fadeColor(int dstColorIndex, int srcColorIndex, uint32 elapsedTime, uint32 targetTime) {
- uint8 *dst = _screenPalette + 3 * dstColorIndex;
- uint8 *src = _screenPalette + 3 * srcColorIndex;
+ uint8 *dst = _screenPalette->getData() + 3 * dstColorIndex;
+ uint8 *src = _screenPalette->getData() + 3 * srcColorIndex;
uint8 *p = getPalette(1) + 3 * dstColorIndex;
bool res = false;
@@ -898,7 +898,7 @@ bool Screen_LoL::fadeColor(int dstColorIndex, int srcColorIndex, uint32 elapsedT
}
uint8 tpal[768];
- memcpy(tpal, _screenPalette, 768);
+ memcpy(tpal, _screenPalette->getData(), 768);
memcpy(tpal + dstColorIndex * 3, tmpPalEntry, 3);
setScreenPalette(tpal);
updateScreen();
@@ -908,7 +908,7 @@ bool Screen_LoL::fadeColor(int dstColorIndex, int srcColorIndex, uint32 elapsedT
bool Screen_LoL::fadePaletteStep(uint8 *pal1, uint8 *pal2, uint32 elapsedTime, uint32 targetTime) {
uint8 tpal[768];
- uint8 *p1 = _palettes[0];
+ uint8 *p1 = getPalette(1);
bool res = false;
for (int i = 0; i < 768; i++) {
@@ -936,7 +936,7 @@ bool Screen_LoL::fadePaletteStep(uint8 *pal1, uint8 *pal2, uint32 elapsedTime, u
uint8 *Screen_LoL::generateFadeTable(uint8 *dst, uint8 *src1, uint8 *src2, int numTabs) {
if (!src1)
- src1 = _screenPalette;
+ src1 = _screenPalette->getData();
uint8 *p1 = dst;
uint8 *p2 = src1;
diff --git a/engines/kyra/screen_v2.cpp b/engines/kyra/screen_v2.cpp
index 454040d86e..9f72725d2d 100644
--- a/engines/kyra/screen_v2.cpp
+++ b/engines/kyra/screen_v2.cpp
@@ -119,7 +119,7 @@ void Screen_v2::getFadeParams(const uint8 *palette, int delay, int &delayInc, in
diff = 0;
int len = _use16ColorMode ? 48 : 768;
for (int i = 0; i < len; ++i) {
- diff = ABS(palette[i] - _screenPalette[i]);
+ diff = ABS(palette[i] - (*_screenPalette)[i]);
maxDiff = MAX(maxDiff, diff);
}