22 #ifndef GRAPHICS_PALETTE_H 23 #define GRAPHICS_PALETTE_H 25 #include "common/hashmap.h" 29 enum ColorDistanceMethod {
30 kColorDistanceEuclidean,
32 kColorDistanceRedmean,
38 constexpr
int PALETTE_COUNT = 256;
39 constexpr
int PALETTE_SIZE = (256 * 3);
56 static const uint16 npos = 0xFFFF;
71 Palette(
const byte *data, uint size);
83 bool operator==(
const Palette &rhs)
const {
return equals(rhs); }
84 bool operator!=(
const Palette &rhs)
const {
return !equals(rhs); }
86 bool equals(
const Palette &p)
const;
88 bool contains(
const Palette &p)
const;
90 const byte *data()
const {
return _data; }
91 uint size()
const {
return _size; }
104 void resize(uint newSize,
bool preserve);
106 void set(uint entry, byte r, byte g, byte b) {
107 assert(entry < _size);
108 _data[entry * 3 + 0] = r;
109 _data[entry * 3 + 1] = g;
110 _data[entry * 3 + 2] = b;
113 void get(uint entry, byte &r, byte &g, byte &b)
const {
114 assert(entry < _size);
115 r = _data[entry * 3 + 0];
116 g = _data[entry * 3 + 1];
117 b = _data[entry * 3 + 2];
125 uint
find(byte r, byte g, byte b)
const {
126 for (uint i = 0; i < _size; i++) {
127 if (_data[i * 3 + 0] == r && _data[i * 3 + 1] == g && _data[i * 3 + 2] == b)
140 byte
findBestColor(byte r, byte g, byte b, ColorDistanceMethod method = kColorDistanceRedmean)
const;
153 void set(
const byte *colors, uint start, uint num);
154 void set(
const Palette &p, uint start, uint num);
166 void grab(byte *colors, uint start, uint num)
const;
190 bool setPalette(
const byte *palette, uint len);
200 byte
findBestColor(byte r, byte g, byte b, ColorDistanceMethod method = kColorDistanceRedmean);
212 uint32 *createMap(
const byte *srcPalette, uint len, ColorDistanceMethod method = kColorDistanceRedmean);
Palette(uint size)
Construct a new Palette object.
byte findBestColor(byte r, byte g, byte b, ColorDistanceMethod method=kColorDistanceRedmean) const
Definition: palette.h:170
Definition: formatinfo.h:28
uint find(byte r, byte g, byte b) const
Definition: palette.h:125
Simple class for handling a palette data.
Definition: palette.h:51
static Palette createEGAPalette()
void grab(byte *colors, uint start, uint num) const
void resize(uint newSize, bool preserve)