22 #ifndef GRAPHICS_PALETTE_H 23 #define GRAPHICS_PALETTE_H 25 #include "common/hashmap.h" 26 #include "common/types.h" 28 #define PALETTE_6BIT_TO_8BIT(x) ((x) * 255 / 63) 29 #define PALETTE_8BIT_TO_6BIT(x) ((x) * 63 / 255) 33 enum ColorDistanceMethod {
34 kColorDistanceEuclidean,
36 kColorDistanceRedmean,
42 constexpr
int PALETTE_COUNT = 256;
43 constexpr
int PALETTE_SIZE = (256 * 3);
58 DisposeAfterUse::Flag _disposeAfterUse;
61 static const uint16 npos = 0xFFFF;
76 Palette(
const byte *data, uint size);
85 Palette(byte *data, uint size, DisposeAfterUse::Flag disposeAfterUse);
97 bool operator==(
const Palette &rhs)
const {
return equals(rhs); }
98 bool operator!=(
const Palette &rhs)
const {
return !equals(rhs); }
100 bool equals(
const Palette &p)
const;
102 bool contains(
const Palette &p)
const;
104 const byte *data()
const {
return _data; }
105 uint size()
const {
return _size; }
115 bool empty()
const {
return _size == 0; }
123 void resize(uint newSize,
bool preserve);
125 void set(uint entry, byte r, byte g, byte b) {
126 assert(entry < _size);
127 _data[entry * 3 + 0] = r;
128 _data[entry * 3 + 1] = g;
129 _data[entry * 3 + 2] = b;
132 void get(uint entry, byte &r, byte &g, byte &b)
const {
133 assert(entry < _size);
134 r = _data[entry * 3 + 0];
135 g = _data[entry * 3 + 1];
136 b = _data[entry * 3 + 2];
144 uint
find(byte r, byte g, byte b)
const {
145 for (uint i = 0; i < _size; i++) {
146 if (_data[i * 3 + 0] == r && _data[i * 3 + 1] == g && _data[i * 3 + 2] == b)
159 byte
findBestColor(byte r, byte g, byte b, ColorDistanceMethod method = kColorDistanceRedmean)
const;
172 void set(
const byte *colors, uint start, uint num);
173 void set(
const Palette &p, uint start, uint num);
185 void grab(byte *colors, uint start, uint num)
const;
209 bool setPalette(
const byte *palette, uint len);
219 byte
findBestColor(byte r, byte g, byte b, ColorDistanceMethod method = kColorDistanceRedmean);
231 uint32 *createMap(
const byte *srcPalette, uint len, ColorDistanceMethod method = kColorDistanceRedmean);
bool empty() const
Definition: palette.h:115
Palette(uint size)
Construct a new Palette object.
byte findBestColor(byte r, byte g, byte b, ColorDistanceMethod method=kColorDistanceRedmean) const
Definition: palette.h:189
Definition: formatinfo.h:28
uint find(byte r, byte g, byte b) const
Definition: palette.h:144
Simple class for handling a palette data.
Definition: palette.h:55
void grab(byte *colors, uint start, uint num) const
static const Palette createEGAPalette()
void resize(uint newSize, bool preserve)