From 0ec0b1d4981e227fddd03bf7d5be7077a445baae Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 25 Jun 2009 01:29:41 +0000 Subject: Implement palette fading for 16 color version of Kyrandia 1. svn-id: r41846 --- engines/kyra/screen.h | 4 +-- engines/kyra/screen_lok.cpp | 87 +++++++++++++++++++++++++++++++++++++++++---- engines/kyra/screen_lok.h | 6 ++++ 3 files changed, 88 insertions(+), 9 deletions(-) diff --git a/engines/kyra/screen.h b/engines/kyra/screen.h index 2246a84a53..9828704dd4 100644 --- a/engines/kyra/screen.h +++ b/engines/kyra/screen.h @@ -228,9 +228,9 @@ public: void fadeFromBlack(int delay=0x54, const UpdateFunctor *upFunc = 0); void fadeToBlack(int delay=0x54, const UpdateFunctor *upFunc = 0); - void fadePalette(const Palette &pal, int delay, const UpdateFunctor *upFunc = 0); + virtual void fadePalette(const Palette &pal, int delay, const UpdateFunctor *upFunc = 0); virtual void getFadeParams(const Palette &pal, int delay, int &delayInc, int &diff); - int fadePalStep(const Palette &pal, int diff); + virtual int fadePalStep(const Palette &pal, int diff); void setPaletteIndex(uint8 index, uint8 red, uint8 green, uint8 blue); virtual void setScreenPalette(const Palette &pal); diff --git a/engines/kyra/screen_lok.cpp b/engines/kyra/screen_lok.cpp index fe3e713e15..e96ca9b2ed 100644 --- a/engines/kyra/screen_lok.cpp +++ b/engines/kyra/screen_lok.cpp @@ -251,15 +251,76 @@ void Screen_LoK_16::setScreenPalette(const Palette &pal) { for (int i = 0; i < 256; ++i) paletteMap(i, pal[i * 3 + 0] << 2, pal[i * 3 + 1] << 2, pal[i * 3 + 2] << 2); - uint8 palette[16 * 4]; - for (int i = 0; i < 16; ++i) { - palette[i * 4 + 0] = (_palette16[i * 3 + 0] * 0xFF) / 0x0F; - palette[i * 4 + 1] = (_palette16[i * 3 + 1] * 0xFF) / 0x0F; - palette[i * 4 + 2] = (_palette16[i * 3 + 2] * 0xFF) / 0x0F; - palette[i * 4 + 3] = 0; + set16ColorPalette(_palette16); +} + +void Screen_LoK_16::fadePalette(const Palette &pal, int delay, const UpdateFunctor *upFunc) { + uint8 notBlackFlag = 0; + for (int i = 0; i < 768; ++i) { + if ((*_screenPalette)[i]) + notBlackFlag |= 1; + if (pal[i]) + notBlackFlag |= 2; } - _system->setPalette(palette, 0, 16); + if (notBlackFlag == 1 || notBlackFlag == 2) { + bool upFade = false; + + for (int i = 0; i < 768; ++i) { + if ((*_screenPalette)[i] < pal[i]) { + upFade = true; + break; + } + } + + if (upFade) { + for (int i = 0; i < 256; ++i) + paletteMap(i, pal[i * 3 + 0] << 2, pal[i * 3 + 1] << 2, pal[i * 3 + 2] << 2); + _forceFullUpdate = true; + } + + uint8 color16Palette[16 * 3]; + + if (upFade) + memset(color16Palette, 0, sizeof(color16Palette)); + else + memcpy(color16Palette, _palette16, sizeof(color16Palette)); + + set16ColorPalette(color16Palette); + updateScreen(); + + for (int i = 0; i < 16; ++i) { + set16ColorPalette(color16Palette); + + for (int k = 0; k < 48; ++k) { + if (upFade) { + if (color16Palette[k] < _palette16[k]) + ++color16Palette[k]; + } else { + if (color16Palette[k] > 0) + --color16Palette[k]; + } + } + + if (upFunc && upFunc->isValid()) + (*upFunc)(); + else + _system->updateScreen(); + + _vm->delay((delay >> 5) * _vm->tickLength()); + } + } + + setScreenPalette(pal); +} + +void Screen_LoK_16::getFadeParams(const Palette &pal, int delay, int &delayInc, int &diff) { + error("Screen_LoK_16::getFadeParams called"); +} + +int Screen_LoK_16::fadePalStep(const Palette &pal, int diff) { + error("Screen_LoK_16::fadePalStep called"); + return 0; } // TODO: This is currently nearly the same as Screen::setMouseCursor, only that @@ -403,4 +464,16 @@ void Screen_LoK_16::mergeOverlay(int x, int y, int w, int h) { convertTo16Colors(_sjisOverlayPtrs[0] + y * 640 + x, w, h, 640); } +void Screen_LoK_16::set16ColorPalette(const uint8 *pal) { + uint8 palette[16 * 4]; + for (int i = 0; i < 16; ++i) { + palette[i * 4 + 0] = (pal[i * 3 + 0] * 0xFF) / 0x0F; + palette[i * 4 + 1] = (pal[i * 3 + 1] * 0xFF) / 0x0F; + palette[i * 4 + 2] = (pal[i * 3 + 2] * 0xFF) / 0x0F; + palette[i * 4 + 3] = 0; + } + + _system->setPalette(palette, 0, 16); +} + } // end of namespace Kyra diff --git a/engines/kyra/screen_lok.h b/engines/kyra/screen_lok.h index 582830636b..098fd1e389 100644 --- a/engines/kyra/screen_lok.h +++ b/engines/kyra/screen_lok.h @@ -83,6 +83,10 @@ public: void setScreenPalette(const Palette &pal); + void fadePalette(const Palette &pal, int delay, const UpdateFunctor *upFunc = 0); + void getFadeParams(const Palette &pal, int delay, int &delayInc, int &diff); + int fadePalStep(const Palette &pal, int diff); + void setMouseCursor(int x, int y, const byte *shape); private: void updateDirtyRectsOvl(); @@ -90,6 +94,8 @@ private: void convertTo16Colors(uint8 *page, int w, int h, int pitch, int keyColor = -1); void mergeOverlay(int x, int y, int w, int h); + void set16ColorPalette(const uint8 *pal); + void paletteMap(uint8 idx, int r, int g, int b); uint8 _paletteMap[1024]; -- cgit v1.2.3