From 51751cd0691b25bcdb882b72ab8c8347d8b3cfbb Mon Sep 17 00:00:00 2001 From: Kari Salminen Date: Tue, 24 Mar 2009 21:45:35 +0000 Subject: [PATCH] Cine::Palette: Add fillWithBlack and saturatedAddNormalizedGray-methods. svn-id: r39676 --- engines/cine/pal.cpp | 20 ++++++++++++++++++++ engines/cine/pal.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/engines/cine/pal.cpp b/engines/cine/pal.cpp index 2d8774f59a1..b2ce45ded8b 100644 --- a/engines/cine/pal.cpp +++ b/engines/cine/pal.cpp @@ -211,6 +211,16 @@ uint Palette::colorCount() const { return _colors.size(); } +Palette &Palette::fillWithBlack() { + for (uint i = 0; i < _colors.size(); i++) { + _colors[i].r = 0; + _colors[i].g = 0; + _colors[i].b = 0; + } + + return *this; +} + EndianType Palette::endianType() const { return (_bigEndian ? CINE_BIG_ENDIAN : CINE_LITTLE_ENDIAN); } @@ -247,6 +257,16 @@ Palette &Palette::saturatedAddColor(Palette& output, byte firstIndex, byte lastI return output; } +Palette &Palette::saturatedAddNormalizedGray(Palette& output, byte firstIndex, byte lastIndex, double normalizedGray) { + // Calculate the gray value rounded up away from zero + const double signedHalf = ((normalizedGray >= 0) ? +0.5 : -0.5); + const signed r = (signed)(_rMax * normalizedGray + signedHalf); + const signed g = (signed)(_gMax * normalizedGray + signedHalf); + const signed b = (signed)(_bMax * normalizedGray + signedHalf); + + return saturatedAddColor(output, firstIndex, lastIndex, r, g, b); +} + // 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 diff --git a/engines/cine/pal.h b/engines/cine/pal.h index afb86c871c1..2bb93245cf1 100644 --- a/engines/cine/pal.h +++ b/engines/cine/pal.h @@ -116,8 +116,11 @@ public: Palette &rotateRight(byte firstIndex, byte lastIndex); Palette &saturatedAddColor(Palette& output, byte firstIndex, byte lastIndex, signed r, signed g, signed b); + Palette &saturatedAddNormalizedGray(Palette& output, byte firstIndex, byte lastIndex, double normalizedGray); uint colorCount() const; + Palette &fillWithBlack(); + /*! \brief The original endian type in which this palette was loaded. * \note This will always return either CINE_BIG_ENDIAN or CINE_LITTLE_ENDIAN (So no CINE_NATIVE_ENDIAN). */