[nostalgia/core] Fix NostalgiaGraphic::setPixel
This commit is contained in:
parent
627fb387e6
commit
bb0592ade8
@ -47,9 +47,8 @@ struct NostalgiaGraphic {
|
||||
ox::Vector<uint8_t> pixels;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto getPixel4Bpp(const geo::Point &pt) const noexcept {
|
||||
constexpr auto getPixel4Bpp(std::size_t idx) const noexcept {
|
||||
oxAssert(bpp == 4, "NostalgiaGraphic::getPixel4Bpp: wrong bpp");
|
||||
const auto idx = ptToIdx(pt, this->columns);
|
||||
if (idx & 1) {
|
||||
return this->pixels[idx / 2];
|
||||
} else {
|
||||
@ -57,31 +56,51 @@ struct NostalgiaGraphic {
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto getPixel8Bpp(std::size_t idx) const noexcept {
|
||||
oxAssert(bpp == 8, "NostalgiaGraphic::getPixel8Bpp: wrong bpp");
|
||||
return this->pixels[idx];
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto getPixel(std::size_t idx) const noexcept {
|
||||
if (this->bpp == 4) {
|
||||
return getPixel4Bpp(idx);
|
||||
} else {
|
||||
return getPixel8Bpp(idx);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto getPixel4Bpp(const geo::Point &pt) const noexcept {
|
||||
oxAssert(bpp == 4, "NostalgiaGraphic::getPixel4Bpp: wrong bpp");
|
||||
const auto idx = ptToIdx(pt, this->columns);
|
||||
return getPixel4Bpp(idx);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto getPixel8Bpp(const geo::Point &pt) const noexcept {
|
||||
oxAssert(bpp == 8, "NostalgiaGraphic::getPixel8Bpp: wrong bpp");
|
||||
const auto idx = ptToIdx(pt, this->columns);
|
||||
return this->pixels[idx];
|
||||
return getPixel8Bpp(idx);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto getPixel(const geo::Point &pt) const noexcept {
|
||||
if (this->bpp == 4) {
|
||||
return getPixel4Bpp(pt);
|
||||
} else {
|
||||
return getPixel8Bpp(pt);
|
||||
}
|
||||
const auto idx = ptToIdx(pt, this->columns);
|
||||
return getPixel(idx);
|
||||
}
|
||||
|
||||
constexpr void setPixel(uint64_t idx, uint8_t palIdx) noexcept {
|
||||
auto &pixel = this->pixels[idx / 2];
|
||||
if (bpp == 4) {
|
||||
if (idx & 1) {
|
||||
pixels[idx / 2] &= 0b0000'1111 | (palIdx << 4);
|
||||
pixel = (pixel & 0b0000'1111) | (palIdx << 4);
|
||||
} else {
|
||||
pixels[idx / 2] &= 0b1111'0000 | (palIdx);
|
||||
pixel = (pixel & 0b1111'0000) | (palIdx);
|
||||
}
|
||||
} else {
|
||||
this->pixels[idx] = palIdx;
|
||||
pixel = palIdx;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user