ScummVM API documentation
palette32.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_PALETTE32_H
23#define SCI_GRAPHICS_PALETTE32_H
24
25#include "common/ptr.h"
26
27namespace Sci {
28
29#pragma mark HunkPalette
30
38public:
39 HunkPalette(const SciSpan<const byte> &rawPalette);
40
41 static void write(SciSpan<byte> &out, const Palette &palette);
42
43 static uint32 calculateHunkPaletteSize(const uint16 numIndexes = 256, const bool sharedUsed = true) {
44 const int numPalettes = 1;
45 return kHunkPaletteHeaderSize +
46 /* slack bytes between hunk header & palette offset table */ 2 +
47 /* palette offset table */ 2 * numPalettes +
48 /* palette data */ (kEntryHeaderSize + numIndexes * (/* RGB */ 3 + !sharedUsed)) * numPalettes;
49 }
50
55 uint32 getVersion() const { return _version; }
56
60 void setVersion(const uint32 version) const;
61
65 const Palette toPalette() const;
66
67private:
68 enum {
73 kNumPaletteEntriesOffset = 10,
74
78 kHunkPaletteHeaderSize = 13,
79
83 kEntryHeaderSize = 22
84 };
85
86 enum {
90 kEntryStartColorOffset = 10,
91
95 kEntryNumColorsOffset = 14,
96
101 kEntryUsedOffset = 16,
102
108 kEntrySharedUsedOffset = 17,
109
114 kEntryVersionOffset = 18
115 };
116
120 struct EntryHeader {
124 uint8 startColor;
125
129 uint16 numColors;
130
134 bool used;
135
140 bool sharedUsed;
141
145 uint32 version;
146 };
147
152 mutable uint32 _version;
153
158 uint8 _numPalettes;
159
163 SciSpan<const byte> _data;
164
169 const EntryHeader getEntryHeader() const;
170
174 SciSpan<const byte> getPalPointer() const {
175 return _data.subspan(kHunkPaletteHeaderSize + (2 * _numPalettes));
176 }
177};
178
179#pragma mark -
180#pragma mark PalCycler
181
182enum PalCyclerDirection {
183 kPalCycleBackward = 0,
184 kPalCycleForward = 1
185};
186
190struct PalCycler {
196
201
206
210 PalCyclerDirection direction;
211
216
223 int16 delay;
224
229};
230
231#pragma mark -
232#pragma mark GfxPalette32
233
235public:
237
238 void saveLoadWithSerializer(Common::Serializer &s);
239
243 inline const Palette &getNextPalette() const { return _nextPalette; };
244
248 inline const Palette &getCurrentPalette() const { return _currentPalette; };
249
254 inline const uint8 *getHardwarePalette() const { return _hardwarePalette; };
255
259 bool loadPalette(const GuiResourceId resourceId);
260
265 int16 matchColor(const uint8 r, const uint8 g, const uint8 b);
266
270 uint8 getPlatformBlack() const;
271
275 uint8 getPlatformWhite() const;
276
281 void submit(const Palette &palette);
282 void submit(const HunkPalette &palette);
283
289
296
302
303private:
304 ResourceManager *_resMan;
305
310 uint32 _version;
311
315 bool _needsUpdate;
316
322 uint8 _hardwarePalette[256 * 3];
323
327 Palette _currentPalette;
328
334 Palette _sourcePalette;
335
340 Palette _nextPalette;
341
346 Palette getPaletteFromResource(const GuiResourceId paletteId) const;
347
351 void mergePalette(Palette &to, const Palette &from);
352
356 void applyAll();
357
358#pragma mark -
359#pragma mark Varying
360public:
372 void setVary(const Palette &target, const int16 percent, const int32 ticks, const int16 fromColor, const int16 toColor);
373
377 inline int16 getVaryPercent() const { return ABS(_varyPercent); }
378
383 void setVaryPercent(const int16 percent, const int32 time);
384
389 void setVaryTime(const int32 ticks);
390
394 void setVaryTime(const int16 percent, const int32 ticks);
395
399 void varyOff();
400
404 void varyPause();
405
409 void varyOn();
410
414 void setTarget(const Palette &palette);
415
419 void setStart(const Palette &palette);
420
424 void mergeStart(const Palette &palette);
425
429 void mergeTarget(const Palette &palette);
430
434 void applyVary();
435
436 void kernelPalVarySet(const GuiResourceId paletteId, const int16 percent, const int32 ticks, const int16 fromColor, const int16 toColor);
437 void kernelPalVaryMergeTarget(const GuiResourceId paletteId);
438 void kernelPalVarySetTarget(const GuiResourceId paletteId);
439 void kernelPalVarySetStart(const GuiResourceId paletteId);
440 void kernelPalVaryMergeStart(const GuiResourceId paletteId);
441 void kernelPalVaryPause(const bool pause);
442
443private:
449 Common::ScopedPtr<Palette> _varyStartPalette;
450
455 Common::ScopedPtr<Palette> _varyTargetPalette;
456
460 uint8 _varyFromColor;
461
465 uint8 _varyToColor;
466
470 uint32 _varyLastTick;
471
476 int32 _varyTime;
477
481 int16 _varyDirection;
482
487 int16 _varyPercent;
488
493 int16 _varyTargetPercent;
494
498 uint16 _varyNumTimesPaused;
499
500#pragma mark -
501#pragma mark Cycling
502public:
503 inline const bool *getCycleMap() const { return _cycleMap; }
504
517 void setCycle(const uint8 fromColor, const uint8 toColor, const int16 direction, const int16 delay);
518
525 void doCycle(const uint8 fromColor, const int16 speed);
526
530 void cycleOn(const uint8 fromColor);
531
535 void cyclePause(const uint8 fromColor);
536
541
546
550 void cycleOff(const uint8 fromColor);
551
556
557private:
558 enum {
559 kNumCyclers = 10
560 };
561
562 typedef Common::ScopedPtr<PalCycler> PalCyclerOwner;
563 PalCyclerOwner _cyclers[kNumCyclers];
564
568 void updateCycler(PalCycler &cycler, const int16 speed);
569
581 bool _cycleMap[256];
582
587 void clearCycleMap(const uint16 fromColor, const uint16 numColorsToClear);
588
593 void setCycleMap(const uint16 fromColor, const uint16 numColorsToClear);
594
599 PalCycler *getCycler(const uint16 fromColor);
600
605 void applyAllCycles();
606
610 void applyCycles();
611
612#pragma mark -
613#pragma mark Fading
614public:
620 void setFade(const uint16 percent, const uint8 fromColor, const uint16 toColor);
621
625 void fadeOff();
626
630 void applyFade();
631
632private:
636 uint16 _fadeTable[256];
637
638#pragma mark -
639#pragma mark Gamma correction
640public:
641 enum {
646 };
647
652 void setGamma(const int16 level) {
653 _gammaLevel = CLIP<int16>(level, 0, numGammaTables) - 1;
654 _gammaChanged = true;
655 }
656
657private:
661 int8 _gammaLevel;
662
667 bool _gammaChanged;
668};
669
670} // End of namespace Sci
671
672#endif // SCI_GRAPHICS_PALETTE32_H
Definition: ptr.h:572
Definition: serializer.h:80
Definition: palette32.h:234
const uint8 * getHardwarePalette() const
Definition: palette32.h:254
void setVary(const Palette &target, const int16 percent, const int32 ticks, const int16 fromColor, const int16 toColor)
void setCycle(const uint8 fromColor, const uint8 toColor, const int16 direction, const int16 delay)
void setTarget(const Palette &palette)
void setVaryTime(const int32 ticks)
void cycleOn(const uint8 fromColor)
@ numGammaTables
Definition: palette32.h:645
void doCycle(const uint8 fromColor, const int16 speed)
bool loadPalette(const GuiResourceId resourceId)
void mergeTarget(const Palette &palette)
void setVaryTime(const int16 percent, const int32 ticks)
void setVaryPercent(const int16 percent, const int32 time)
int16 getVaryPercent() const
Definition: palette32.h:377
void setGamma(const int16 level)
Definition: palette32.h:652
void cyclePause(const uint8 fromColor)
void setFade(const uint16 percent, const uint8 fromColor, const uint16 toColor)
uint8 getPlatformBlack() const
void setStart(const Palette &palette)
int16 matchColor(const uint8 r, const uint8 g, const uint8 b)
const Palette & getCurrentPalette() const
Definition: palette32.h:248
const Palette & getNextPalette() const
Definition: palette32.h:243
void mergeStart(const Palette &palette)
uint8 getPlatformWhite() const
void cycleOff(const uint8 fromColor)
void submit(const Palette &palette)
Definition: palette32.h:37
uint32 getVersion() const
Definition: palette32.h:55
const Palette toPalette() const
void setVersion(const uint32 version) const
Definition: resource.h:327
Definition: util.h:251
T ABS(T x)
Definition: util.h:60
Definition: console.h:28
Definition: palette32.h:190
uint16 numTimesPaused
Definition: palette32.h:228
int16 delay
Definition: palette32.h:223
uint16 numColorsToCycle
Definition: palette32.h:200
uint8 fromColor
Definition: palette32.h:195
uint32 lastUpdateTick
Definition: palette32.h:215
PalCyclerDirection direction
Definition: palette32.h:210
uint8 currentCycle
Definition: palette32.h:205
Definition: helpers.h:247