From 97887377f0784bab34f2cb69638174b3243d380c Mon Sep 17 00:00:00 2001 From: Kari Salminen Date: Mon, 16 Mar 2009 21:10:15 +0000 Subject: Cine::Palette: Make saturatedAddColor-methods more like their old counterparts transformPaletteRange and transformColor. svn-id: r39454 --- engines/cine/pal.cpp | 18 +++++++++++------- engines/cine/pal.h | 13 +++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/engines/cine/pal.cpp b/engines/cine/pal.cpp index 5d1637084e..244ff74981 100644 --- a/engines/cine/pal.cpp +++ b/engines/cine/pal.cpp @@ -236,23 +236,27 @@ void Palette::setEndianType(const EndianType endianType) { } // a.k.a. transformPaletteRange -Palette &Palette::saturatedAddColor(byte firstIndex, byte lastIndex, signed r, signed g, signed b) { +Palette &Palette::saturatedAddColor(Palette& output, byte firstIndex, byte lastIndex, signed r, signed g, signed b) { assert(firstIndex < colorCount() && lastIndex < colorCount()); + assert(firstIndex < output.colorCount() && lastIndex < output.colorCount()); + assert(output.colorFormat() == colorFormat()); for (uint i = firstIndex; i <= lastIndex; i++) - saturatedAddColor(i, r, g, b); + output._colors[i] = saturatedAddColor(_colors[i], r, g, b); - return *this; + return output; } // a.k.a. transformColor // Parameter color components (i.e. r, g and b) are in range [-7, 7] // e.g. r = 7 sets the resulting color's red component to maximum // e.g. r = -7 sets the resulting color's red component to minimum (i.e. zero) -void Palette::saturatedAddColor(byte index, signed r, signed g, signed b) { - _colors[index].r = CLIP(_colors[index].r + r, 0, _rMax); - _colors[index].g = CLIP(_colors[index].g + g, 0, _gMax); - _colors[index].b = CLIP(_colors[index].b + b, 0, _bMax); +Cine::Palette::Color Palette::saturatedAddColor(Cine::Palette::Color baseColor, signed r, signed g, signed b) const { + Cine::Palette::Color result; + result.r = CLIP(baseColor.r + r, 0, _rMax); + result.g = CLIP(baseColor.g + g, 0, _gMax); + result.b = CLIP(baseColor.b + b, 0, _bMax); + return result; } Palette &Palette::load(const byte *buf, const uint size, const Graphics::PixelFormat format, const uint numColors, const EndianType endianType) { diff --git a/engines/cine/pal.h b/engines/cine/pal.h index e32990a88d..50033be6e0 100644 --- a/engines/cine/pal.h +++ b/engines/cine/pal.h @@ -74,6 +74,11 @@ void transformPaletteRange(byte *srcPal, byte *dstPal, int startColor, int stopC // TODO: Make use of // TODO: Test class Palette { +private: + struct Color { + uint8 r, g, b; + }; + public: /*! \brief Load palette from buffer with given color format, endianness and number of colors. * \param buf Input buffer @@ -110,7 +115,7 @@ public: byte *save(byte *buf, const uint size, const Graphics::PixelFormat format, const uint numColors, const EndianType endianType, const byte firstIndex = 0) const; Palette &rotateRight(byte firstIndex, byte lastIndex); - Palette &saturatedAddColor(byte firstIndex, byte lastIndex, signed r, signed g, signed b); + Palette &saturatedAddColor(Palette& output, byte firstIndex, byte lastIndex, signed r, signed g, signed b); uint colorCount() const; /*! \brief The original endian type in which this palette was loaded. @@ -124,13 +129,9 @@ public: private: void setColorFormat(const Graphics::PixelFormat format); void setEndianType(const EndianType endianType); - void saturatedAddColor(byte index, signed r, signed g, signed b); + Cine::Palette::Color saturatedAddColor(Cine::Palette::Color baseColor, signed r, signed g, signed b) const; private: - struct Color { - uint8 r, g, b; - }; - // The used source format, its endianness etc. Graphics::PixelFormat _format; uint _rBits, _gBits, _bBits; -- cgit v1.2.3