ScummVM API documentation
palette.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SCI_GRAPHICS_PALETTE_H
23 #define SCI_GRAPHICS_PALETTE_H
24 
25 #include "common/array.h"
26 #include "sci/graphics/helpers.h"
27 #include "sci/util.h"
28 
29 namespace Sci {
30 
31 class ResourceManager;
32 class GfxScreen;
33 
34 // Special flag implemented by us for optimization in palette merge
35 #define SCI_PALETTE_MATCH_PERFECT 0x8000
36 #define SCI_PALETTE_MATCH_COLORMASK 0xFF
37 
42 public:
43  GfxPalette(ResourceManager *resMan, GfxScreen *screen);
44  ~GfxPalette() override;
45 
46  bool isMerging();
47  bool isUsing16bitColorMatch();
48 
49  void setDefault();
50  void createFromData(const SciSpan<const byte> &data, Palette *paletteOut) const;
51  bool setAmiga();
52  void modifyAmigaPalette(const SciSpan<const byte> &data);
53  void setEGA();
54  void set(Palette *sciPal, bool force, bool forceRealMerge = false, bool includeFirstColor = true);
55  bool insert(Palette *newPalette, Palette *destPalette, bool includeFirstColor = false);
56  bool merge(Palette *pFrom, bool force, bool forceRealMerge);
57  uint16 matchColor(byte r, byte g, byte b, bool force16BitColorMatch = false);
58  uint16 getTotalColorCount() const { return _totalScreenColors; }
59 
60  // Set palette on screen. If update is false, try not to change the palette
61  // on already painted areas, but this may be impossible.
62  void setOnScreen(bool update=true);
63  void copySysPaletteToScreen(bool update);
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, bool force16BitColorMatch = false);
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) override;
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 // SCI_GRAPHICS_PALETTE_H
Definition: array.h:52
Definition: serializer.h:79
Definition: resource.h:327
Definition: palette.h:41
Definition: console.h:28
Definition: serializer.h:308
Definition: screen.h:68
Definition: helpers.h:246
Definition: vm_types.h:39