ScummVM API documentation
remap32.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_REMAP32_H
23#define SCI_GRAPHICS_REMAP32_H
24
25#include "common/algorithm.h"
26#include "common/array.h"
27#include "common/scummsys.h"
28#include "sci/graphics/helpers.h"
29
30namespace Sci {
31class GfxPalette32;
32
33enum RemapType {
34 kRemapNone = 0,
35 kRemapByRange = 1,
36 kRemapByPercent = 2,
37 kRemapToGray = 3,
38 kRemapToPercentGray = 4
39};
40
41#pragma mark -
42#pragma mark SingleRemap
43
48public:
49 SingleRemap() : _type(kRemapNone) {}
50
54 RemapType _type;
55
59 uint8 _from;
60
64 uint8 _to;
65
70 int16 _delta;
71
79 int16 _percent;
80
85 uint8 _gray;
86
107 uint8 _remapColors[237];
108
112 void reset();
113
117 bool update();
118
119private:
124 int16 _lastPercent;
125
130 uint8 _lastGray;
131
136 Color _originalColors[237];
137
143 bool _originalColorsChanged[237];
144
148 Color _idealColors[237];
149
155 bool _idealColorsChanged[237];
156
165 int _matchDistances[237];
166
173 bool updateRange();
174
181 bool updateBrightness();
182
189 bool updateSaturation();
190
197 bool updateSaturationAndBrightness();
198
207 bool apply();
208
215 int colorDistance(const Color &a, const Color &b) const;
216
225 int16 matchColor(const Color &color, const int minimumDistance, int &outDistance, const bool *const blockedIndexes) const;
226};
227
228#pragma mark -
229#pragma mark GfxRemap32
230
235public:
236 GfxRemap32();
237
238 void saveLoadWithSerializer(Common::Serializer &s) override;
239
240 inline uint8 getRemapCount() const { return _numActiveRemaps; }
241 inline uint8 getStartColor() const { return _remapStartColor; }
242 inline uint8 getEndColor() const { return _remapEndColor; }
243 inline uint8 getBlockedRangeStart() const { return _blockedRangeStart; }
244 inline int16 getBlockedRangeCount() const { return _blockedRangeCount; }
245
250 void remapOff(const uint8 color);
251
256
262 void remapByRange(const uint8 color, const int16 from, const int16 to, const int16 delta);
263
268 void remapByPercent(const uint8 color, const int16 percent);
269
274 void remapToGray(const uint8 color, const int8 gray);
275
281 void remapToPercentGray(const uint8 color, const int16 gray, const int16 percent);
282
289 void blockRange(const uint8 from, const int16 count);
290
301 inline bool remapEnabled(uint8 color) const {
302 const uint8 index = _remapEndColor - color;
303 // At least KQ7 DOS uses remap colors that are outside the valid remap
304 // range; in these cases, just treat those pixels as skip pixels (which
305 // is how they would be treated in SSCI)
306 if (index >= _remaps.size()) {
307 return false;
308 }
309 return (_remaps[index]._type != kRemapNone);
310 }
311
317 inline uint8 remapColor(const uint8 sourceColor, const uint8 targetColor) const {
318 const uint8 index = _remapEndColor - sourceColor;
319 assert(index < _remaps.size());
320 const SingleRemap &singleRemap = _remaps[index];
321 assert(singleRemap._type != kRemapNone);
322 // SSCI never really properly handled attempts to draw to a target with
323 // pixels above the remap color maximum. In RAMA, the cursor views have
324 // a remap color outlining the cursor, and so get drawn into a target
325 // surface filled with a skip color of 255. In SSCI, this causes the
326 // remapped color to be read from some statically allocated, never
327 // written memory and so always ends up being 0 (black).
328 if (targetColor >= _remapStartColor) {
329 return 0;
330 }
331 return singleRemap._remapColors[targetColor];
332 }
333
341 bool remapAllTables(const bool paletteUpdated);
342
343private:
345
349 uint8 _remapStartColor;
350
354 uint8 _remapEndColor;
355
359 uint8 _numActiveRemaps;
360
364 SingleRemapsList _remaps;
365
370 bool _needsUpdate;
371
375 uint8 _blockedRangeStart;
376
381 int16 _blockedRangeCount;
382};
383
384} // End of namespace Sci
385
386#endif // SCI_GRAPHICS_REMAP32_H
size_type size() const
Definition: array.h:316
Definition: serializer.h:352
Definition: serializer.h:80
Definition: remap32.h:234
void remapToPercentGray(const uint8 color, const int16 gray, const int16 percent)
void remapByRange(const uint8 color, const int16 from, const int16 to, const int16 delta)
void remapToGray(const uint8 color, const int8 gray)
bool remapAllTables(const bool paletteUpdated)
bool remapEnabled(uint8 color) const
Definition: remap32.h:301
void remapByPercent(const uint8 color, const int16 percent)
void remapOff(const uint8 color)
uint8 remapColor(const uint8 sourceColor, const uint8 targetColor) const
Definition: remap32.h:317
void blockRange(const uint8 from, const int16 count)
Definition: remap32.h:47
int16 _percent
Definition: remap32.h:79
RemapType _type
Definition: remap32.h:54
uint8 _to
Definition: remap32.h:64
uint8 _from
Definition: remap32.h:59
uint8 _gray
Definition: remap32.h:85
int16 _delta
Definition: remap32.h:70
uint8 _remapColors[237]
Definition: remap32.h:107
Definition: console.h:28
Definition: helpers.h:233