1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef SCI_GRAPHICS_PALETTE_H 24 #define SCI_GRAPHICS_PALETTE_H 25 26 #include "common/array.h" 27 #include "sci/graphics/helpers.h" 28 #include "sci/util.h" 29 30 namespace Sci { 31 32 class ResourceManager; 33 class GfxScreen; 34 35 // Special flag implemented by us for optimization in palette merge 36 #define SCI_PALETTE_MATCH_PERFECT 0x8000 37 #define SCI_PALETTE_MATCH_COLORMASK 0xFF 38 39 /** 40 * Palette class, handles palette operations like changing intensity, setting up the palette, merging different palettes 41 */ 42 class GfxPalette : public Common::Serializable { 43 public: 44 GfxPalette(ResourceManager *resMan, GfxScreen *screen); 45 ~GfxPalette(); 46 47 bool isMerging(); 48 bool isUsing16bitColorMatch(); 49 50 void setDefault(); 51 void createFromData(const SciSpan<const byte> &data, Palette *paletteOut) const; 52 bool setAmiga(); 53 void modifyAmigaPalette(const SciSpan<const byte> &data); 54 void setEGA(); 55 void set(Palette *sciPal, bool force, bool forceRealMerge = false, bool includeFirstColor = false); 56 bool insert(Palette *newPalette, Palette *destPalette, bool includeFirstColor = false); 57 bool merge(Palette *pFrom, bool force, bool forceRealMerge); 58 uint16 matchColor(byte r, byte g, byte b); 59 void getSys(Palette *pal); getTotalColorCount()60 uint16 getTotalColorCount() const { return _totalScreenColors; } 61 62 void setOnScreen(); 63 void copySysPaletteToScreen(); 64 65 void drewPicture(GuiResourceId pictureId); 66 67 bool kernelSetFromResource(GuiResourceId resourceId, bool force); 68 void kernelSetFlag(uint16 fromColor, uint16 toColor, uint16 flag); 69 void kernelUnsetFlag(uint16 fromColor, uint16 toColor, uint16 flag); 70 void kernelSetIntensity(uint16 fromColor, uint16 toColor, uint16 intensity, bool setPalette); 71 int16 kernelFindColor(uint16 r, uint16 g, uint16 b); 72 bool kernelAnimate(byte fromColor, byte toColor, int speed); 73 void kernelAnimateSet(); 74 reg_t kernelSave(); 75 void kernelRestore(reg_t memoryHandle); 76 void kernelAssertPalette(GuiResourceId resourceId); 77 78 void kernelSyncScreenPalette(); 79 80 bool kernelPalVaryInit(GuiResourceId resourceId, uint16 ticks, uint16 stepStop, uint16 direction); 81 int16 kernelPalVaryReverse(int16 ticks, uint16 stepStop, int16 direction); 82 int16 kernelPalVaryGetCurrentStep(); 83 int16 kernelPalVaryChangeTarget(GuiResourceId resourceId); 84 void kernelPalVaryChangeTicks(uint16 ticks); 85 void kernelPalVaryPause(bool pause); 86 void kernelPalVaryDeinit(); 87 void palVaryUpdate(); 88 void palVaryPrepareForTransition(); 89 void palVaryProcess(int signal, bool setPalette); 90 91 void delayForPalVaryWorkaround(); 92 93 Palette _sysPalette; 94 95 void saveLoadWithSerializer(Common::Serializer &s); 96 void palVarySaveLoadPalette(Common::Serializer &s, Palette *palette); 97 98 byte findMacIconBarColor(byte r, byte g, byte b); 99 bool colorIsFromMacClut(byte index); 100 101 protected: 102 void palVaryInit(); 103 void palVaryInstallTimer(); 104 void palVaryRemoveTimer(); 105 bool palVaryLoadTargetPalette(GuiResourceId resourceId); 106 static void palVaryCallback(void *refCon); 107 void palVaryIncreaseSignal(); 108 109 GfxScreen *_screen; 110 ResourceManager *_resMan; 111 112 bool _sysPaletteChanged; 113 bool _useMerging; 114 bool _use16bitColorMatch; 115 116 Common::Array<PalSchedule> _schedules; 117 118 GuiResourceId _palVaryResourceId; 119 Palette _palVaryOriginPalette; 120 Palette _palVaryTargetPalette; 121 int16 _palVaryStep; 122 int16 _palVaryStepStop; 123 int16 _palVaryDirection; 124 uint16 _palVaryTicks; 125 int _palVaryPaused; 126 int _palVarySignal; 127 bool _palVaryZeroTick; 128 uint16 _totalScreenColors; 129 130 void loadMacIconBarPalette(); 131 byte *_macClut; 132 }; 133 134 } // End of namespace Sci 135 136 #endif 137