diff options
-rw-r--r-- | sword2/anims.cpp | 6 | ||||
-rw-r--r-- | sword2/build_display.cpp | 19 | ||||
-rw-r--r-- | sword2/driver/animation.cpp | 12 | ||||
-rw-r--r-- | sword2/driver/d_draw.h | 4 | ||||
-rw-r--r-- | sword2/driver/palette.cpp | 109 | ||||
-rw-r--r-- | sword2/driver/render.cpp | 24 | ||||
-rw-r--r-- | sword2/driver/sprite.cpp | 18 | ||||
-rw-r--r-- | sword2/function.cpp | 2 | ||||
-rw-r--r-- | sword2/header.h | 9 |
9 files changed, 69 insertions, 134 deletions
diff --git a/sword2/anims.cpp b/sword2/anims.cpp index 52b4a2c258..685d922a02 100644 --- a/sword2/anims.cpp +++ b/sword2/anims.cpp @@ -588,10 +588,10 @@ int32 Logic::fnPlaySequence(int32 *params) { // zero the entire palette in case we're about to fade up! - PalEntry pal[256]; + byte pal[4 * 256]; - memset(pal, 0, 256 * sizeof(PalEntry)); - _vm->_graphics->setPalette(0, 256, (byte *) pal, RDPAL_INSTANT); + memset(pal, 0, sizeof(pal)); + _vm->_graphics->setPalette(0, 256, pal, RDPAL_INSTANT); debug(5, "fnPlaySequence FINISHED"); return IR_CONT; diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp index 9f424b9bce..f03c475c8d 100644 --- a/sword2/build_display.cpp +++ b/sword2/build_display.cpp @@ -119,8 +119,8 @@ void Sword2Engine::buildDisplay(void) { */ void Sword2Engine::displayMsg(byte *text, int time) { - PalEntry pal[256]; - PalEntry oldPal[256]; + byte pal[256 * 4]; + byte oldPal[256 * 4]; debug(2, "DisplayMsg: %s", text); @@ -159,14 +159,14 @@ void Sword2Engine::displayMsg(byte *text, int time) { if (rv) error("Driver Error %.8x (in DisplayMsg)", rv); - memcpy((char *) oldPal, (char *) _graphics->_palCopy, 256 * sizeof(PalEntry)); + memcpy(oldPal, _graphics->_palette, sizeof(oldPal)); + memset(pal, 0, sizeof(pal)); - memset(pal, 0, 256 * sizeof(PalEntry)); - pal[187].red = 255; - pal[187].green = 255; - pal[187].blue = 255; + pal[187 * 4 + 0] = 255; + pal[187 * 4 + 1] = 255; + pal[187 * 4 + 2] = 255; - _graphics->setPalette(0, 256, (byte *) pal, RDPAL_FADE); + _graphics->setPalette(0, 256, pal, RDPAL_FADE); _graphics->fadeUp(); free(text_spr); _graphics->waitForFade(); @@ -174,7 +174,8 @@ void Sword2Engine::displayMsg(byte *text, int time) { uint32 targetTime = _system->get_msecs() + (time * 1000); sleepUntil(targetTime); - _graphics->setPalette(0, 256, (byte *) oldPal, RDPAL_FADE); + _graphics->setPalette(0, 256, oldPal, RDPAL_FADE); + _graphics->fadeUp(); } /** diff --git a/sword2/driver/animation.cpp b/sword2/driver/animation.cpp index f975b4be7d..3fe259c7cf 100644 --- a/sword2/driver/animation.cpp +++ b/sword2/driver/animation.cpp @@ -178,8 +178,8 @@ int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], byte *mus uint32 flags = SoundMixer::FLAG_16BITS; bool startNextText = false; - byte oldPal[1024]; - memcpy(oldPal, _vm->_graphics->_palCopy, 1024); + byte oldPal[256 * 4]; + memcpy(oldPal, _vm->_graphics->_palette, sizeof(oldPal)); AnimationState *anim = new AnimationState(_vm); @@ -345,8 +345,8 @@ int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], byte *mus int32 MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], byte *musicOut) { int frameCounter = 0, textCounter = 0; if (text) { - byte oldPal[1024]; - byte tmpPal[1024]; + byte oldPal[256 * 4]; + byte tmpPal[256 * 4]; _vm->_graphics->clearScene(); @@ -384,8 +384,8 @@ int32 MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], byte // In the opening cutscene it seems to use colours 1 (black?) // and 255 (white?). - memcpy(oldPal, _vm->_graphics->_palCopy, 1024); - memset(tmpPal, 0, 1024); + memcpy(oldPal, _vm->_graphics->_palette, sizeof(oldPal)); + memset(tmpPal, 0, sizeof(tmpPal)); tmpPal[255 * 4 + 0] = 255; tmpPal[255 * 4 + 1] = 255; tmpPal[255 * 4 + 2] = 255; diff --git a/sword2/driver/d_draw.h b/sword2/driver/d_draw.h index 2d8eb83412..7b4b0f448c 100644 --- a/sword2/driver/d_draw.h +++ b/sword2/driver/d_draw.h @@ -93,7 +93,6 @@ private: byte _paletteMatch[PALTABLESIZE]; - byte _fadePalette[256][4]; uint8 _fadeStatus; int32 _fadeStartTime; @@ -150,7 +149,6 @@ private: void decompressMouse(byte *decomp, byte *comp, int width, int height, int pitch, int xOff = 0, int yOff = 0); - uint8 getMatch(uint8 r, uint8 g, uint8 b); void fadeServer(void); void scaleImageFast(byte *dst, uint16 dstPitch, uint16 dstWidth, @@ -178,7 +176,7 @@ public: int16 _screenWide; int16 _screenDeep; - byte _palCopy[256][4]; + byte _palette[256 * 4]; byte *getScreen(void) { return _buffer; } diff --git a/sword2/driver/palette.cpp b/sword2/driver/palette.cpp index 1c5096c11b..c63f8a1439 100644 --- a/sword2/driver/palette.cpp +++ b/sword2/driver/palette.cpp @@ -23,68 +23,15 @@ namespace Sword2 { -uint8 Graphics::getMatch(uint8 r, uint8 g, uint8 b) { - int32 diff; - int32 min; - int16 diffred, diffgreen, diffblue; - int16 i; - uint8 minIndex; - - diffred = _palCopy[0][0] - r; - diffgreen = _palCopy[0][1] - g; - diffblue = _palCopy[0][2] - b; - - diff = diffred * diffred + diffgreen * diffgreen + diffblue * diffblue; - min = diff; - minIndex = 0; - if (diff > 0) { - for (i = 1; i < 256; i++) { - diffred = _palCopy[i][0] - r; - diffgreen = _palCopy[i][1] - g; - diffblue = _palCopy[i][2] - b; - - diff = diffred * diffred + diffgreen * diffgreen + diffblue * diffblue; - if (diff < min) { - min = diff; - minIndex = (uint8) i; - if (min == 0) - break; - } - } - } - - // Here, minIndex is the index of the matchpalette which is closest. - return minIndex; -} - /** - * Sets or creates a table of palette indices which will be searched later for - * a quick palette match. - * @param data either the palette match table, or NULL to create a new table - * from the current palCopy + * Sets a table of palette indices which will be searched later for a quick + * palette match. + * @param data the palette match table */ void Graphics::updatePaletteMatchTable(byte *data) { - if (!data) { - int16 red, green, blue; - byte *p; - - // Create palette match table - - // FIXME: Does this case ever happen? - - p = &_paletteMatch[0]; - for (red = 0; red < 256; red += 4) { - for (green = 0; green < 256; green += 4) { - for (blue = 0; blue < 256; blue += 4) { - *p++ = getMatch((uint8) red, (uint8) green, (uint8) blue); - } - } - } - } else { - // The provided data is the new palette match table - memcpy(_paletteMatch, data, PALTABLESIZE); - } + assert(data); + memcpy(_paletteMatch, data, PALTABLESIZE); } /** @@ -110,23 +57,24 @@ uint8 Graphics::quickMatch(uint8 r, uint8 g, uint8 b) { */ void Graphics::setPalette(int16 startEntry, int16 noEntries, byte *colourTable, uint8 fadeNow) { - if (noEntries) { - memcpy(&_palCopy[startEntry][0], colourTable, noEntries * 4); - if (fadeNow == RDPAL_INSTANT) { - _vm->_system->setPalette((const byte *) _palCopy, startEntry, noEntries); - setNeedFullRedraw(); - } - } else { - _vm->_system->setPalette((const byte *) _palCopy, 0, 256); + assert(noEntries > 0); + + memcpy(&_palette[4 * startEntry], colourTable, noEntries * 4); + + if (fadeNow == RDPAL_INSTANT) { + _vm->_system->setPalette(_palette, startEntry, noEntries); setNeedFullRedraw(); } } void Graphics::dimPalette(void) { - byte *p = (byte *) _palCopy; + byte *p = _palette; - for (int i = 0; i < 256 * 4; i++) - p[i] /= 2; + for (int i = 0; i < 256; i++) { + p[i * 4 + 0] /= 2; + p[i * 4 + 1] /= 2; + p[i * 4 + 2] /= 2; + } _vm->_system->setPalette(p, 0, 256); setNeedFullRedraw(); @@ -183,15 +131,12 @@ void Graphics::waitForFade(void) { void Graphics::fadeServer(void) { static int32 previousTime = 0; - const byte *newPalette = (const byte *) _fadePalette; + byte fadePalette[256 * 4]; + byte *newPalette = fadePalette; int32 currentTime; int16 fadeMultiplier; int16 i; - // This used to be called through a timer, but is now called from - // ServiceWindows() instead, since that's the only place where we - // actually update the screen. - // If we're not in the process of fading, do nothing. if (getFadeStatus() != RDFADE_UP && getFadeStatus() != RDFADE_DOWN) return; @@ -207,25 +152,25 @@ void Graphics::fadeServer(void) { if (getFadeStatus() == RDFADE_UP) { if (currentTime >= _fadeStartTime + _fadeTotalTime) { _fadeStatus = RDFADE_NONE; - newPalette = (const byte *) _palCopy; + newPalette = _palette; } else { fadeMultiplier = (int16) (((int32) (currentTime - _fadeStartTime) * 256) / _fadeTotalTime); for (i = 0; i < 256; i++) { - _fadePalette[i][0] = (_palCopy[i][0] * fadeMultiplier) >> 8; - _fadePalette[i][1] = (_palCopy[i][1] * fadeMultiplier) >> 8; - _fadePalette[i][2] = (_palCopy[i][2] * fadeMultiplier) >> 8; + newPalette[i * 4 + 0] = (_palette[i * 4 + 0] * fadeMultiplier) >> 8; + newPalette[i * 4 + 1] = (_palette[i * 4 + 1] * fadeMultiplier) >> 8; + newPalette[i * 4 + 2] = (_palette[i * 4 + 2] * fadeMultiplier) >> 8; } } } else { if (currentTime >= _fadeStartTime + _fadeTotalTime) { _fadeStatus = RDFADE_BLACK; - memset(_fadePalette, 0, sizeof(_fadePalette)); + memset(newPalette, 0, sizeof(fadePalette)); } else { fadeMultiplier = (int16) (((int32) (_fadeTotalTime - (currentTime - _fadeStartTime)) * 256) / _fadeTotalTime); for (i = 0; i < 256; i++) { - _fadePalette[i][0] = (_palCopy[i][0] * fadeMultiplier) >> 8; - _fadePalette[i][1] = (_palCopy[i][1] * fadeMultiplier) >> 8; - _fadePalette[i][2] = (_palCopy[i][2] * fadeMultiplier) >> 8; + newPalette[i * 4 + 0] = (_palette[i * 4 + 0] * fadeMultiplier) >> 8; + newPalette[i * 4 + 1] = (_palette[i * 4 + 1] * fadeMultiplier) >> 8; + newPalette[i * 4 + 2] = (_palette[i * 4 + 2] * fadeMultiplier) >> 8; } } } diff --git a/sword2/driver/render.cpp b/sword2/driver/render.cpp index c6e9f745b2..edf91cd22c 100644 --- a/sword2/driver/render.cpp +++ b/sword2/driver/render.cpp @@ -152,21 +152,21 @@ void Graphics::scaleImageGood(byte *dst, uint16 dstPitch, uint16 dstWidth, uint1 c4 = c3; if (!transparent) { - uint32 r1 = _palCopy[c1][0]; - uint32 g1 = _palCopy[c1][1]; - uint32 b1 = _palCopy[c1][2]; + uint32 r1 = _palette[c1 * 4 + 0]; + uint32 g1 = _palette[c1 * 4 + 1]; + uint32 b1 = _palette[c1 * 4 + 2]; - uint32 r2 = _palCopy[c2][0]; - uint32 g2 = _palCopy[c2][1]; - uint32 b2 = _palCopy[c2][2]; + uint32 r2 = _palette[c2 * 4 + 0]; + uint32 g2 = _palette[c2 * 4 + 1]; + uint32 b2 = _palette[c2 * 4 + 2]; - uint32 r3 = _palCopy[c3][0]; - uint32 g3 = _palCopy[c3][1]; - uint32 b3 = _palCopy[c3][2]; + uint32 r3 = _palette[c3 * 4 + 0]; + uint32 g3 = _palette[c3 * 4 + 1]; + uint32 b3 = _palette[c3 * 4 + 2]; - uint32 r4 = _palCopy[c4][0]; - uint32 g4 = _palCopy[c4][1]; - uint32 b4 = _palCopy[c4][2]; + uint32 r4 = _palette[c4 * 4 + 0]; + uint32 g4 = _palette[c4 * 4 + 1]; + uint32 b4 = _palette[c4 * 4 + 2]; uint32 r5 = (r1 * xFrac + r2 * (dstWidth - xFrac)) / dstWidth; uint32 g5 = (g1 * xFrac + g2 * (dstWidth - xFrac)) / dstWidth; diff --git a/sword2/driver/sprite.cpp b/sword2/driver/sprite.cpp index a886899c55..4afc292bde 100644 --- a/sword2/driver/sprite.cpp +++ b/sword2/driver/sprite.cpp @@ -522,9 +522,9 @@ int32 Graphics::drawSprite(SpriteInfo *s) { for (i = 0; i < rs.height(); i++) { for (j = 0; j < rs.width(); j++) { if (src[j] && lightMap[j]) { - uint8 r = ((32 - lightMap[j]) * _palCopy[src[j]][0]) >> 5; - uint8 g = ((32 - lightMap[j]) * _palCopy[src[j]][1]) >> 5; - uint8 b = ((32 - lightMap[j]) * _palCopy[src[j]][2]) >> 5; + uint8 r = ((32 - lightMap[j]) * _palette[src[j] * 4 + 0]) >> 5; + uint8 g = ((32 - lightMap[j]) * _palette[src[j] * 4 + 1]) >> 5; + uint8 b = ((32 - lightMap[j]) * _palette[src[j] * 4 + 2]) >> 5; src[j] = quickMatch(r, g, b); } } @@ -562,12 +562,12 @@ int32 Graphics::drawSprite(SpriteInfo *s) { for (i = 0; i < rs.height(); i++) { for (j = 0; j < rs.width(); j++) { if (src[j]) { - uint8 r1 = _palCopy[src[j]][0]; - uint8 g1 = _palCopy[src[j]][1]; - uint8 b1 = _palCopy[src[j]][2]; - uint8 r2 = _palCopy[dst[j]][0]; - uint8 g2 = _palCopy[dst[j]][1]; - uint8 b2 = _palCopy[dst[j]][2]; + uint8 r1 = _palette[src[j] * 4 + 0]; + uint8 g1 = _palette[src[j] * 4 + 1]; + uint8 b1 = _palette[src[j] * 4 + 2]; + uint8 r2 = _palette[dst[j] * 4 + 0]; + uint8 g2 = _palette[dst[j] * 4 + 1]; + uint8 b2 = _palette[dst[j] * 4 + 2]; uint8 r = (r1 * n + r2 * (8 - n)) >> 3; uint8 g = (g1 * n + g2 * (8 - n)) >> 3; diff --git a/sword2/function.cpp b/sword2/function.cpp index 4fd756d529..9feca89f3e 100644 --- a/sword2/function.cpp +++ b/sword2/function.cpp @@ -433,7 +433,7 @@ int32 Logic::fnPlayCredits(int32 *params) { uint16 logoWidth = 0; uint16 logoHeight = 0; byte *logoData = NULL; - byte palette[1024]; + byte palette[256 * 4]; if (f.open("credits.bmp")) { logoWidth = f.readUint16LE(); diff --git a/sword2/header.h b/sword2/header.h index b88e7c71c7..68be38ebeb 100644 --- a/sword2/header.h +++ b/sword2/header.h @@ -194,15 +194,6 @@ struct MultiScreenHeader { uint32 maskOffset; } GCC_PACK; -// Palette Data - -struct PalEntry { - uint8 red; - uint8 green; - uint8 blue; - uint8 alpha; -} GCC_PACK; - // Screen Header struct ScreenHeader { |