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 GRAPHICS_PALETTE_H
23 #define GRAPHICS_PALETTE_H
24 
25 #include "common/hashmap.h"
26 
27 namespace Graphics {
28 
39 class Palette {
40  byte *_data;
41  uint16 _size;
42 
43 public:
44  static const uint16 npos = 0xFFFF;
45 
51  Palette(uint size);
52 
59  Palette(const byte *data, uint size);
60 
61  Palette(const Palette &p);
62 
63  ~Palette();
64 
65  Palette &operator=(const Palette &rhs);
66  bool operator==(const Palette &rhs) const { return equals(rhs); }
67  bool operator!=(const Palette &rhs) const { return !equals(rhs); }
68 
69  bool equals(const Palette &p) const;
70 
71  bool contains(const Palette &p) const;
72 
73  const byte *data() const { return _data; }
74  uint size() const { return _size; }
75 
76  void set(uint entry, byte r, byte g, byte b) {
77  assert(entry < _size);
78  _data[entry * 3 + 0] = r;
79  _data[entry * 3 + 1] = g;
80  _data[entry * 3 + 2] = b;
81  }
82 
83  void get(uint entry, byte &r, byte &g, byte &b) const {
84  assert(entry < _size);
85  r = _data[entry * 3 + 0];
86  g = _data[entry * 3 + 1];
87  b = _data[entry * 3 + 2];
88  }
89 
95  uint find(byte r, byte g, byte b) const {
96  for (uint i = 0; i < _size; i++) {
97  if (_data[i * 3 + 0] == r && _data[i * 3 + 1] == g && _data[i * 3 + 2] == b)
98  return i;
99  }
100  return npos;
101  }
102 
110  byte findBestColor(byte r, byte g, byte b, bool useNaiveAlg = false) const;
111 
112  void clear();
113 
125  void set(const byte *colors, uint start, uint num);
126  void set(const Palette &p, uint start, uint num);
127 
138  void grab(byte *colors, uint start, uint num) const;
139  void grab(Palette &p, uint start, uint num) const;
140 };
141 
143 public:
144  PaletteLookup();
151  PaletteLookup(const byte *palette, uint len);
152 
162  bool setPalette(const byte *palette, uint len);
163 
172  byte findBestColor(byte r, byte g, byte b, bool useNaiveAlg = false);
173 
184  uint32 *createMap(const byte *srcPalette, uint len, bool useNaiveAlg = false);
185 
186 private:
187  Palette _palette;
188  uint _paletteSize;
189  Common::HashMap<int, byte> _colorHash;
190 };
191 
192 } // // end of namespace Graphics
193 #endif
byte findBestColor(byte r, byte g, byte b, bool useNaiveAlg=false) const
Palette(uint size)
Construct a new Palette object.
Definition: palette.h:142
Definition: formatinfo.h:28
uint find(byte r, byte g, byte b) const
Definition: palette.h:95
Simple class for handling a palette data.
Definition: palette.h:39
void grab(byte *colors, uint start, uint num) const