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) 43 constexpr
int PALETTE_SIZE = (256 * 3);
45 extern const byte HGC_A_PALETTE[6];
46 extern const byte HGC_G_PALETTE[6];
64 DisposeAfterUse::Flag _disposeAfterUse;
67 static const uint16 npos = 0xFFFF;
82 Palette(
const byte *data, uint size);
91 Palette(byte *data, uint size, DisposeAfterUse::Flag disposeAfterUse);
103 bool operator==(
const Palette &rhs)
const {
return equals(rhs); }
104 bool operator!=(
const Palette &rhs)
const {
return !equals(rhs); }
106 bool equals(
const Palette &p)
const;
108 bool contains(
const Palette &p)
const;
110 const byte *data()
const {
return _data; }
111 uint size()
const {
return _size; }
121 bool empty()
const {
return _size == 0; }
129 void resize(uint newSize,
bool preserve);
131 void set(uint entry, byte r, byte g, byte b) {
132 assert(entry < _size);
133 _data[entry * 3 + 0] = r;
134 _data[entry * 3 + 1] = g;
135 _data[entry * 3 + 2] = b;
138 void get(uint entry, byte &r, byte &g, byte &b)
const {
139 assert(entry < _size);
140 r = _data[entry * 3 + 0];
141 g = _data[entry * 3 + 1];
142 b = _data[entry * 3 + 2];
150 uint
find(byte r, byte g, byte b)
const {
151 for (uint i = 0; i < _size; i++) {
152 if (_data[i * 3 + 0] == r && _data[i * 3 + 1] == g && _data[i * 3 + 2] == b)
178 void set(
const byte *colors, uint start, uint num);
179 void set(
const Palette &p, uint start, uint num);
191 void grab(byte *colors, uint start, uint num)
const;
215 bool setPalette(
const byte *palette, uint len);
bool empty() const
Definition: palette.h:121
byte findBestColor(byte r, byte g, byte b, ColorDistanceMethod method=kColorDistanceRedmean) const
ColorDistanceMethod
Definition: palette.h:33
Definition: palette.h:195
constexpr int PALETTE_COUNT
Definition: palette.h:42
Definition: formatinfo.h:28
uint find(byte r, byte g, byte b) const
Definition: palette.h:150
Non-Weighted distance.
Definition: palette.h:34
Weighted red 30%, green 50%, blue 20%.
Definition: palette.h:35
Palette(uint size=0)
Construct a new Palette object.
Simple class for handling a palette data.
Definition: palette.h:61
Common low-cost approximation.
Definition: palette.h:36
void grab(byte *colors, uint start, uint num) const
static const Palette createEGAPalette()
void resize(uint newSize, bool preserve)