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 
27 namespace Sci {
28 
29 #pragma mark HunkPalette
30 
37 class HunkPalette {
38 public:
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 
67 private:
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 
182 enum PalCyclerDirection {
183  kPalCycleBackward = 0,
184  kPalCycleForward = 1
185 };
186 
190 struct PalCycler {
195  uint8 fromColor;
196 
201 
206 
210  PalCyclerDirection direction;
211 
216 
223  int16 delay;
224 
229 };
230 
231 #pragma mark -
232 #pragma mark GfxPalette32
233 
235 public:
236  GfxPalette32(ResourceManager *resMan);
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 
250 #ifdef USE_RGB_COLOR
251 
255  inline const uint8 *getHardwarePalette() const { return _hardwarePalette; };
256 #endif
257 
261  bool loadPalette(const GuiResourceId resourceId);
262 
267  int16 matchColor(const uint8 r, const uint8 g, const uint8 b);
268 
272  uint8 getPlatformBlack() const;
273 
277  uint8 getPlatformWhite() const;
278 
283  void submit(const Palette &palette);
284  void submit(const HunkPalette &palette);
285 
290  bool updateForFrame();
291 
297  void updateFFrame();
298 
303  void updateHardware();
304 
305 private:
306  ResourceManager *_resMan;
307 
312  uint32 _version;
313 
317  bool _needsUpdate;
318 
319 #ifdef USE_RGB_COLOR
320 
325  uint8 _hardwarePalette[256 * 3];
326 #endif
327 
331  Palette _currentPalette;
332 
338  Palette _sourcePalette;
339 
344  Palette _nextPalette;
345 
350  Palette getPaletteFromResource(const GuiResourceId paletteId) const;
351 
355  void mergePalette(Palette &to, const Palette &from);
356 
360  void applyAll();
361 
362 #pragma mark -
363 #pragma mark Varying
364 public:
376  void setVary(const Palette &target, const int16 percent, const int32 ticks, const int16 fromColor, const int16 toColor);
377 
381  inline int16 getVaryPercent() const { return ABS(_varyPercent); }
382 
387  void setVaryPercent(const int16 percent, const int32 time);
388 
393  void setVaryTime(const int32 ticks);
394 
398  void setVaryTime(const int16 percent, const int32 ticks);
399 
403  void varyOff();
404 
408  void varyPause();
409 
413  void varyOn();
414 
418  void setTarget(const Palette &palette);
419 
423  void setStart(const Palette &palette);
424 
428  void mergeStart(const Palette &palette);
429 
433  void mergeTarget(const Palette &palette);
434 
438  void applyVary();
439 
440  void kernelPalVarySet(const GuiResourceId paletteId, const int16 percent, const int32 ticks, const int16 fromColor, const int16 toColor);
441  void kernelPalVaryMergeTarget(const GuiResourceId paletteId);
442  void kernelPalVarySetTarget(const GuiResourceId paletteId);
443  void kernelPalVarySetStart(const GuiResourceId paletteId);
444  void kernelPalVaryMergeStart(const GuiResourceId paletteId);
445  void kernelPalVaryPause(const bool pause);
446 
447 private:
453  Common::ScopedPtr<Palette> _varyStartPalette;
454 
459  Common::ScopedPtr<Palette> _varyTargetPalette;
460 
464  uint8 _varyFromColor;
465 
469  uint8 _varyToColor;
470 
474  uint32 _varyLastTick;
475 
480  int32 _varyTime;
481 
485  int16 _varyDirection;
486 
491  int16 _varyPercent;
492 
497  int16 _varyTargetPercent;
498 
502  uint16 _varyNumTimesPaused;
503 
504 #pragma mark -
505 #pragma mark Cycling
506 public:
507  inline const bool *getCycleMap() const { return _cycleMap; }
508 
521  void setCycle(const uint8 fromColor, const uint8 toColor, const int16 direction, const int16 delay);
522 
529  void doCycle(const uint8 fromColor, const int16 speed);
530 
534  void cycleOn(const uint8 fromColor);
535 
539  void cyclePause(const uint8 fromColor);
540 
544  void cycleAllOn();
545 
549  void cycleAllPause();
550 
554  void cycleOff(const uint8 fromColor);
555 
559  void cycleAllOff();
560 
561 private:
562  enum {
563  kNumCyclers = 10
564  };
565 
567  PalCyclerOwner _cyclers[kNumCyclers];
568 
572  void updateCycler(PalCycler &cycler, const int16 speed);
573 
585  bool _cycleMap[256];
586 
591  void clearCycleMap(const uint16 fromColor, const uint16 numColorsToClear);
592 
597  void setCycleMap(const uint16 fromColor, const uint16 numColorsToClear);
598 
603  PalCycler *getCycler(const uint16 fromColor);
604 
609  void applyAllCycles();
610 
614  void applyCycles();
615 
616 #pragma mark -
617 #pragma mark Fading
618 public:
624  void setFade(const uint16 percent, const uint8 fromColor, const uint16 toColor);
625 
629  void fadeOff();
630 
634  void applyFade();
635 
636 private:
640  uint16 _fadeTable[256];
641 
642 #pragma mark -
643 #pragma mark Gamma correction
644 public:
645  enum {
649  numGammaTables = 6
650  };
651 
656  void setGamma(const int16 level) {
657  _gammaLevel = CLIP<int16>(level, 0, numGammaTables) - 1;
658  _gammaChanged = true;
659  }
660 
661 private:
665  int8 _gammaLevel;
666 
671  bool _gammaChanged;
672 };
673 
674 } // End of namespace Sci
675 
676 #endif // SCI_GRAPHICS_PALETTE32_H
int16 getVaryPercent() const
Definition: palette32.h:381
void setGamma(const int16 level)
Definition: palette32.h:656
const Palette & getNextPalette() const
Definition: palette32.h:243
uint16 numColorsToCycle
Definition: palette32.h:200
Definition: palette32.h:37
Definition: palette32.h:190
PalCyclerDirection direction
Definition: palette32.h:210
Definition: ptr.h:572
Definition: serializer.h:79
uint32 lastUpdateTick
Definition: palette32.h:215
void setVersion(const uint32 version) const
const Palette toPalette() const
Definition: resource.h:327
int16 delay
Definition: palette32.h:223
Definition: palette32.h:234
uint16 numTimesPaused
Definition: palette32.h:228
uint32 getVersion() const
Definition: palette32.h:55
uint8 fromColor
Definition: palette32.h:195
Definition: console.h:28
Definition: helpers.h:246
T ABS(T x)
Definition: util.h:56
uint8 currentCycle
Definition: palette32.h:205
const Palette & getCurrentPalette() const
Definition: palette32.h:248