bmxconverter/palette.cpp

41 lines
998 B
C++
Raw Permalink Normal View History

2023-11-17 12:30:24 -08:00
#include "palette.h"
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;
}
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;
}
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);
}
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;
}