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 MADS_PALETTE_H
23 #define MADS_PALETTE_H
24 
25 #include "common/scummsys.h"
26 #include "common/stream.h"
27 
28 namespace MADS {
29 
30 class MADSEngine;
31 
32 #define PALETTE_USAGE_COUNT 4
33 
34 #define PALETTE_RESERVED_LOW_COUNT 18
35 #define PALETTE_RESERVED_HIGH_COUNT 10
36 
37 #define PALETTE_COUNT 256
38 #define RGB_SIZE 3
39 #define PALETTE_SIZE (256 * 3)
40 
44 enum {
45  PALFLAG_BACKGROUND = 0x8000, // Loading initial background
46  PALFLAG_RESERVED = 0x4000, // Enable mapping reserved colors
47  PALFLAG_ANY_TO_CLOSEST = 0x2000, // Any color can map to closest
48  PALFLAG_ALL_TO_CLOSEST = 0x1000, // Any colors that can map must map
49  PALFLAG_TOP_COLORS = 0x0800, // Allow mapping to high four colors
50  PALFLAG_DEFINE_RESERVED = 0x0400, // Define initial reserved color
51  PALFLAG_MASK = 0xfc00 // Mask for all the palette flags
52 };
53 
54 struct PaletteCycle {
55  byte _colorCount;
56  byte _firstListColor;
57  byte _firstColorIndex;
58  byte _ticks;
59 
60  PaletteCycle() { _colorCount = _firstListColor = _firstColorIndex = _ticks = 0; }
61 };
62 
63 struct RGB6 {
64  byte r;
65  byte g;
66  byte b;
67  byte _palIndex;
68  byte _u2;
69  byte _flags;
70 
74  void load(Common::SeekableReadStream *f);
75 };
76 
77 class PaletteUsage {
78 public:
79  struct UsageEntry {
80  uint16 _palIndex;
81  int _sortValue;
82 
83  UsageEntry(int palIndex) { _palIndex = palIndex; _sortValue = -1; }
84  UsageEntry() { _palIndex = 0; _sortValue = 0; }
85  };
86  struct UsageRange {
87  byte _v1, _v2;
88 
89  UsageRange(byte v1, byte v2) { _v1 = v1; _v2 = v2; }
90  };
91 private:
92  MADSEngine *_vm;
94 
95  int getGamePalFreeIndex(int *palIndex);
96 
97  int rgbFactor(byte *palEntry, RGB6 &pal6);
98 
99  Common::Array<UsageEntry> _nullUsage;
100 public:
105 
106  void load(Common::Array<UsageEntry> *data);
107 
111  bool empty() const { return _data == nullptr; }
112 
113  uint16 &operator[](int index) { return (*_data)[index]._palIndex; }
114 
118  void setEmpty() { _data = &_nullUsage; }
119 
124  void getKeyEntries(Common::Array<RGB6> &palette);
125 
130  void prioritize(Common::Array<RGB6> &palette);
131 
132  int process(Common::Array<RGB6> &palette, uint flags);
133 
134  void transform(Common::Array<RGB6> &palette);
135 
136  void updateUsage(Common::Array<int> &usageList, int sceneUsageIndex);
137 
138  void resetPalFlags(int idx);
139 
140  int checkRGB(const byte *rgb, int palStart, bool flag, int *palIndex);
141 };
142 
143 class RGBList {
144 private:
145  bool _data[32];
146 public:
147  RGBList() { clear(); }
148 
149  void clear();
150 
151  void reset();
152 
156  void copy(RGBList &src);
157 
161  int scan();
162 
163  bool &operator[](int idx) { return _data[idx]; }
164 };
165 
166 class Fader {
167 public:
168  struct GreyEntry {
169  byte _intensity;
170  byte _mapColor;
171  uint16 _accum[3];
172  };
173 private:
174  void mapToGreyRamp(byte palette[PALETTE_SIZE], int baseColor, int numColors,
175  int baseGrey, int numGreys, GreyEntry *map);
176 
177  void getGreyValues(const byte palette[PALETTE_SIZE], byte greyList[PALETTE_COUNT],
178  int baseColor, int numColors);
179 
184  void greyPopularity(const byte greyList[PALETTE_COUNT], byte greyTable[64], int numColors);
185 
189  void insertionSort(int size, byte *id, byte *value);
190 protected:
191  MADSEngine *_vm;
192  byte _rgb64Map[PALETTE_COUNT];
193 public:
194  bool _colorFlags[4];
195  int _colorValues[4];
196 public:
200  Fader(MADSEngine *vm);
201 
205  void setPalette(const byte *colors, uint start, uint num);
206 
210  void grabPalette(byte *colors, uint start, uint num);
211 
215  void getFullPalette(byte palette[PALETTE_SIZE]);
216 
220  void setFullPalette(byte palette[PALETTE_SIZE]);
221 
225  int rgbMerge(byte r, byte g, byte b);
226 
230  int rgbMerge(RGB6 &palEntry);
231 
235  void fadeOut(byte palette[PALETTE_SIZE], byte *paletteMap,
236  int baseColor, int numColors, int baseGrey, int numGreys,
237  int tickDelay, int steps);
238 
242  void fadeIn(byte palette[PALETTE_SIZE], byte destPalette[PALETTE_SIZE],
243  int baseColor, int numColors, int baseGrey, int numGreys,
244  int tickDelay, int steps);
245 };
246 
247 class Palette : public Fader {
248 private:
253  void initVGAPalette(byte *palette);
254 public:
255  byte _mainPalette[PALETTE_SIZE];
256  byte _cyclingPalette[PALETTE_SIZE];
257  uint32 _palFlags[PALETTE_COUNT];
258  PaletteUsage _paletteUsage;
259  RGBList _rgbList;
260  bool _lockFl;
261  int _lowRange;
262  int _highRange;
263 public:
267  Palette(MADSEngine *vm);
268 
272  virtual ~Palette() {}
273 
277  void setEntry(byte palIndex, byte r, byte g, byte b);
278 
283  uint8 palIndexFromRgb(byte r, byte g, byte b, byte *paletteData = nullptr);
284 
288  void setSystemPalette();
289 
293  static void setGradient(byte *palette, int start, int count, int rgbValue1, int rgbValue2);
294 
298  void resetGamePalette(int lowRange, int highRange);
299 
303  void initPalette();
304 
308  void setLowRange();
309 
310  void setColorFlags(byte r, byte g, byte b);
311  void setColorValues(byte r, byte g, byte b);
312 
313  void lock();
314  void unlock();
315 
316  void refreshSceneColors();
317 
318  static int closestColor(const byte *matchColor, const byte *refPalette,
319  int paletteInc, int count);
320 };
321 
322 } // End of namespace MADS
323 
324 #endif /* MADS_PALETTE_H */
Definition: array.h:52
void setEmpty()
Definition: palette.h:118
Definition: palette.h:79
Definition: stream.h:745
Definition: palette.h:143
Out copy(In first, In last, Out dst)
Definition: algorithm.h:52
Definition: palette.h:54
Definition: mads.h:87
Definition: action.h:28
Definition: palette.h:63
virtual ~Palette()
Definition: palette.h:272
Definition: palette.h:86
Definition: palette.h:166
Definition: palette.h:168
bool empty() const
Definition: palette.h:111
Definition: palette.h:247
Definition: palette.h:77