diff options
author | Torbjörn Andersson | 2004-06-09 06:33:29 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2004-06-09 06:33:29 +0000 |
commit | 0426d38aa599d554bd63c4053c6990356a62b71e (patch) | |
tree | b6a0362ef754b67e1c55df5da7e7acb7f5857469 /sword2/driver | |
parent | 51b373eb6fdcbc6af2bc606341c92cd645c56096 (diff) | |
download | scummvm-rg350-0426d38aa599d554bd63c4053c6990356a62b71e.tar.gz scummvm-rg350-0426d38aa599d554bd63c4053c6990356a62b71e.tar.bz2 scummvm-rg350-0426d38aa599d554bd63c4053c6990356a62b71e.zip |
Cleaned up the palette handling a bit. Renamed _palCopy to _palette since I
found the old name misleading (there is only one array that stores the
palette in the engine, though it could be argued that it's a copy of the
one used by the backend), and removed some code that I'm almost certain was
never used. (I've added assert()s to trigger in the cases where it would
have been used.)
svn-id: r13949
Diffstat (limited to 'sword2/driver')
-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 |
5 files changed, 55 insertions, 112 deletions
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; |