2023-11-17 12:30:24 -08:00
|
|
|
#include "palette.h"
|
2023-11-18 12:55:26 -08:00
|
|
|
ColorRGB PaletteEntry::toColor() const {
|
2023-11-17 12:30:24 -08:00
|
|
|
ColorRGB color;
|
|
|
|
color.red(((double)r) / 15.0);
|
|
|
|
color.green(((double)g) / 15.0);
|
|
|
|
color.blue(((double)b) / 15.0);
|
|
|
|
return color;
|
|
|
|
}
|
2023-11-18 12:55:26 -08:00
|
|
|
void PaletteEntry::write(uint8_t *ptr) const {
|
2023-11-17 12:30:24 -08:00
|
|
|
ptr[0] = ((g & 0b1111) << 4) | (b & 0b1111);
|
|
|
|
ptr[1] = r;
|
|
|
|
}
|
2023-11-18 12:55:26 -08:00
|
|
|
std::string PaletteEntry::to_string() const {
|
|
|
|
char buf[65];
|
|
|
|
snprintf(buf, 64, "#%0x%0x%0x", r, g, b);
|
|
|
|
std::string output(buf);
|
|
|
|
return output;
|
|
|
|
}
|
2023-11-17 12:30:24 -08:00
|
|
|
PaletteEntry::PaletteEntry(uint8_t *ptr) {
|
|
|
|
b = (ptr[0] & 0b1111);
|
|
|
|
g = ((ptr[0] >> 4) & 0b1111);
|
|
|
|
r = ptr[1] & 0b1111;
|
|
|
|
}
|
|
|
|
PaletteEntry::PaletteEntry(uint8_t r, uint8_t g, uint8_t b) {
|
|
|
|
this->r = r;
|
|
|
|
this->g = g;
|
|
|
|
this->b = b;
|
|
|
|
}
|
|
|
|
PaletteEntry::PaletteEntry(const ColorRGB &rgb) {
|
|
|
|
r = (uint8_t)((rgb.red()) * 15);
|
|
|
|
g = (uint8_t)((rgb.green()) * 15);
|
|
|
|
b = (uint8_t)((rgb.blue()) * 15);
|
|
|
|
}
|
2023-11-18 12:55:26 -08:00
|
|
|
uint16_t PaletteEntry::hash() const {
|
2023-11-17 12:30:24 -08:00
|
|
|
return ((r & 0b1111) << 8) | ((g & 0b1111) << 4) | (b & 0b1111);
|
|
|
|
}
|
|
|
|
PaletteEntry::PaletteEntry() {
|
|
|
|
r = 0;
|
|
|
|
g = 0;
|
|
|
|
b = 0;
|
|
|
|
}
|