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