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)
43constexpr int PALETTE_SIZE = (256 * 3);
45extern const byte HGC_A_PALETTE[6];
46extern const byte HGC_G_PALETTE[6];
64 DisposeAfterUse::Flag _disposeAfterUse;
67 static const uint16 npos = 0xFFFF;
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;
Simple class for handling a palette data.
Definition: palette.h:61
uint find(byte r, byte g, byte b) const
Definition: palette.h:150
static const Palette createEGAPalette()
void set(const byte *colors, uint start, uint num)
bool empty() const
Definition: palette.h:121
void grab(byte *colors, uint start, uint num) const
byte findBestColor(byte r, byte g, byte b, ColorDistanceMethod method=kColorDistanceRedmean) const
void resize(uint newSize, bool preserve)
Palette(const byte *data, uint size)
Construct a new Palette object with a copy of the palette data.
Palette(uint size=0)
Construct a new Palette object.
Palette(byte *data, uint size, DisposeAfterUse::Flag disposeAfterUse)
Construct a new Palette object taking ownership of the palette data.
Definition: palette.h:195
byte findBestColor(byte r, byte g, byte b, ColorDistanceMethod method=kColorDistanceRedmean)
This method returns closest color from the palette and it uses cache for faster lookups.
bool setPalette(const byte *palette, uint len)
Pass palette to the look up. It also compares given palette with the current one and resets cache onl...
uint32 * createMap(const byte *srcPalette, uint len, ColorDistanceMethod method=kColorDistanceRedmean)
This method creates a map from the given palette that can be used by crossBlitMap().
PaletteLookup(const byte *palette, uint len)
Construct a new Palette Lookup object.
Definition: atari-screen.h:42
Definition: formatinfo.h:28
constexpr int PALETTE_COUNT
Definition: palette.h:42
ColorDistanceMethod
Definition: palette.h:33
@ kColorDistanceRedmean
Common low-cost approximation.
Definition: palette.h:36
@ kColorDistanceEuclidean
Non-Weighted distance.
Definition: palette.h:34
@ kColorDistanceNaive
Weighted red 30%, green 50%, blue 20%.
Definition: palette.h:35