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 
32 #define PALETTE_COUNT 256
33 #define PALETTE_SIZE (256 * 3)
34 
45 class Palette {
46  byte *_data;
47  uint16 _size;
48 
49 public:
50  static const uint16 npos = 0xFFFF;
51 
57  Palette(uint size);
58 
65  Palette(const byte *data, uint size);
66 
67  Palette(const Palette &p);
68 
69  ~Palette();
70 
74  static Palette createEGAPalette();
75 
76  Palette &operator=(const Palette &rhs);
77  bool operator==(const Palette &rhs) const { return equals(rhs); }
78  bool operator!=(const Palette &rhs) const { return !equals(rhs); }
79 
80  bool equals(const Palette &p) const;
81 
82  bool contains(const Palette &p) const;
83 
84  const byte *data() const { return _data; }
85  uint size() const { return _size; }
86 
87  void set(uint entry, byte r, byte g, byte b) {
88  assert(entry < _size);
89  _data[entry * 3 + 0] = r;
90  _data[entry * 3 + 1] = g;
91  _data[entry * 3 + 2] = b;
92  }
93 
94  void get(uint entry, byte &r, byte &g, byte &b) const {
95  assert(entry < _size);
96  r = _data[entry * 3 + 0];
97  g = _data[entry * 3 + 1];
98  b = _data[entry * 3 + 2];
99  }
100 
106  uint find(byte r, byte g, byte b) const {
107  for (uint i = 0; i < _size; i++) {
108  if (_data[i * 3 + 0] == r && _data[i * 3 + 1] == g && _data[i * 3 + 2] == b)
109  return i;
110  }
111  return npos;
112  }
113 
121  byte findBestColor(byte r, byte g, byte b, bool useNaiveAlg = false) const;
122 
123  void clear();
124 
136  void set(const byte *colors, uint start, uint num);
137  void set(const Palette &p, uint start, uint num);
138 
149  void grab(byte *colors, uint start, uint num) const;
150  void grab(Palette &p, uint start, uint num) const;
151 };
152 
154 public:
155  PaletteLookup();
162  PaletteLookup(const byte *palette, uint len);
163 
173  bool setPalette(const byte *palette, uint len);
174 
183  byte findBestColor(byte r, byte g, byte b, bool useNaiveAlg = false);
184 
195  uint32 *createMap(const byte *srcPalette, uint len, bool useNaiveAlg = false);
196 
197 private:
198  Palette _palette;
199  uint _paletteSize;
200  Common::HashMap<int, byte> _colorHash;
201 };
202 
203 } // // end of namespace Graphics
204 #endif
byte findBestColor(byte r, byte g, byte b, bool useNaiveAlg=false) const
Palette(uint size)
Construct a new Palette object.
Definition: palette.h:153
Definition: formatinfo.h:28
uint find(byte r, byte g, byte b) const
Definition: palette.h:106
Simple class for handling a palette data.
Definition: palette.h:45
static Palette createEGAPalette()
void grab(byte *colors, uint start, uint num) const