1 /* GemRB - Infinity Engine Emulator 2 * Copyright (C) 2005-2006 The GemRB Project 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 * 18 */ 19 20 #ifndef PALETTE_H 21 #define PALETTE_H 22 23 #include "RGBAColor.h" 24 #include "exports.h" 25 #include "ie_types.h" 26 #include "Holder.h" 27 28 #include <algorithm> 29 #include <cassert> 30 #include <cstdint> 31 #include <cstring> 32 33 namespace GemRB { 34 35 struct RGBModifier { 36 Color rgb; 37 int speed; 38 int phase; 39 enum Type { 40 NONE, 41 ADD, 42 TINT, 43 BRIGHTEN 44 } type; 45 bool locked; 46 }; 47 48 class Palette; 49 using PaletteHolder = Holder<Palette>; 50 51 class GEM_EXPORT Palette : public Held<Palette> 52 { 53 private: 54 void CopyColorRangePrivate(const Color* srcBeg, const Color* srcEnd, Color* dst); 55 void UpdateAlpha(); 56 public: 57 Palette(const Color &color, const Color &back); 58 Palette(const Color * begin,const Color * end)59 Palette(const Color* begin, const Color* end) 60 : Palette() { 61 std::copy(begin, end, col); 62 UpdateAlpha(); 63 } 64 Palette()65 Palette() { 66 named = false; 67 version = 0; 68 } 69 70 Color col[256]; //< RGB or RGBA 8 bit palette 71 bool named; //< true if the palette comes from a bmp and cached 72 GetVersion()73 unsigned short GetVersion() const { return version; } 74 HasAlpha()75 bool HasAlpha() const { return alpha; } 76 void CreateShadedAlphaChannel(); 77 void Brighten(); 78 79 void SetupPaperdollColours(const ieDword* Colors, unsigned int type); 80 void SetupRGBModification(const PaletteHolder src, const RGBModifier* mods, 81 unsigned int type); 82 void SetupGlobalRGBModification(const PaletteHolder src, 83 const RGBModifier& mod); 84 85 PaletteHolder Copy() const; 86 87 void CopyColorRange(const Color* srcBeg, const Color* srcEnd, uint8_t dst); 88 bool operator==(const Palette&) const; 89 bool operator!=(const Palette&) const; 90 private: 91 unsigned short version; 92 bool alpha = false; // true if any colors in the palette have an alpha < 255 93 // FIXME: version is not enough since `col` is public 94 // must make it private to fully capture changes to it 95 }; 96 97 } 98 99 #endif 100