Introduce LookUpColor4

This commit is contained in:
2023-12-21 12:50:42 -05:00
parent 6f1980393d
commit 239a7ceb3f
2 changed files with 23 additions and 14 deletions

View File

@@ -167,7 +167,25 @@ namespace JabyEngine {
constexpr void set_lu_id(uint8_t new_lu_id, size_t at) {
this->lu_id[at] = new_lu_id;
}
};
struct LookUpColor4 {
uint8_t lu_id[2];
static constexpr LookUpColor4 from_id(uint8_t px0, uint8_t px1, uint8_t px2, uint8_t px3) {
return {{static_cast<uint8_t>((px0 << 4) | px1), static_cast<uint8_t>((px2 << 4) | px3)}};
}
constexpr uint8_t get_lu_id(size_t at) const {
const auto value = this->lu_id[at >> 1];
return (value & 0x1) ? value & 0xF : value >> 4;
}
constexpr void set_lu_id(uint8_t new_lu_id, size_t at) {
this->lu_id[at >> 1] = bit::value::set_normalized(this->lu_id[at >> 1], BitRange(4*(at&0x1), 4).with(new_lu_id));
}
uint16_t force_read() const {
return *const_cast<const volatile uint16_t*>(reinterpret_cast<const uint16_t*>(this->lu_id));
}