diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index 882d6299..8256ef52 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -47,9 +47,8 @@ struct NostalgiaGraphic { ox::Vector 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 { @@ -58,30 +57,50 @@ struct NostalgiaGraphic { } [[nodiscard]] - constexpr auto getPixel8Bpp(const geo::Point &pt) const noexcept { + constexpr auto getPixel8Bpp(std::size_t idx) const noexcept { oxAssert(bpp == 8, "NostalgiaGraphic::getPixel8Bpp: wrong bpp"); - const auto idx = ptToIdx(pt, this->columns); return this->pixels[idx]; } [[nodiscard]] - constexpr auto getPixel(const geo::Point &pt) const noexcept { + constexpr auto getPixel(std::size_t idx) const noexcept { if (this->bpp == 4) { - return getPixel4Bpp(pt); + return getPixel4Bpp(idx); } else { - return getPixel8Bpp(pt); + 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 getPixel8Bpp(idx); + } + + [[nodiscard]] + constexpr auto getPixel(const geo::Point &pt) const noexcept { + 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; } }