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() override; 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 = true); 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, bool force16BitColorMatch = false); 59 void getSys(Palette *pal); getTotalColorCount()60 uint16 getTotalColorCount() const { return _totalScreenColors; } 61 62 // Set palette on screen. If update is false, try not to change the palette 63 // on already painted areas, but this may be impossible. 64 void setOnScreen(bool update=true); 65 void copySysPaletteToScreen(bool update); 66 67 void drewPicture(GuiResourceId pictureId); 68 69 bool kernelSetFromResource(GuiResourceId resourceId, bool force); 70 void kernelSetFlag(uint16 fromColor, uint16 toColor, uint16 flag); 71 void kernelUnsetFlag(uint16 fromColor, uint16 toColor, uint16 flag); 72 void kernelSetIntensity(uint16 fromColor, uint16 toColor, uint16 intensity, bool setPalette); 73 int16 kernelFindColor(uint16 r, uint16 g, uint16 b, bool force16BitColorMatch = false); 74 bool kernelAnimate(byte fromColor, byte toColor, int speed); 75 void kernelAnimateSet(); 76 reg_t kernelSave(); 77 void kernelRestore(reg_t memoryHandle); 78 void kernelAssertPalette(GuiResourceId resourceId); 79 80 void kernelSyncScreenPalette(); 81 82 bool kernelPalVaryInit(GuiResourceId resourceId, uint16 ticks, uint16 stepStop, uint16 direction); 83 int16 kernelPalVaryReverse(int16 ticks, uint16 stepStop, int16 direction); 84 int16 kernelPalVaryGetCurrentStep(); 85 int16 kernelPalVaryChangeTarget(GuiResourceId resourceId); 86 void kernelPalVaryChangeTicks(uint16 ticks); 87 void kernelPalVaryPause(bool pause); 88 void kernelPalVaryDeinit(); 89 void palVaryUpdate(); 90 void palVaryPrepareForTransition(); 91 void palVaryProcess(int signal, bool setPalette); 92 93 void delayForPalVaryWorkaround(); 94 95 Palette _sysPalette; 96 97 void saveLoadWithSerializer(Common::Serializer &s) override; 98 void palVarySaveLoadPalette(Common::Serializer &s, Palette *palette); 99 100 byte findMacIconBarColor(byte r, byte g, byte b); 101 bool colorIsFromMacClut(byte index); 102 103 protected: 104 void palVaryInit(); 105 void palVaryInstallTimer(); 106 void palVaryRemoveTimer(); 107 bool palVaryLoadTargetPalette(GuiResourceId resourceId); 108 static void palVaryCallback(void *refCon); 109 void palVaryIncreaseSignal(); 110 111 GfxScreen *_screen; 112 ResourceManager *_resMan; 113 114 bool _sysPaletteChanged; 115 bool _useMerging; 116 bool _use16bitColorMatch; 117 118 Common::Array<PalSchedule> _schedules; 119 120 GuiResourceId _palVaryResourceId; 121 Palette _palVaryOriginPalette; 122 Palette _palVaryTargetPalette; 123 int16 _palVaryStep; 124 int16 _palVaryStepStop; 125 int16 _palVaryDirection; 126 uint16 _palVaryTicks; 127 int _palVaryPaused; 128 int _palVarySignal; 129 bool _palVaryZeroTick; 130 uint16 _totalScreenColors; 131 132 void loadMacIconBarPalette(); 133 byte *_macClut; 134 }; 135 136 } // End of namespace Sci 137 138 #endif 139