[nostalgia/core] Fix subsheet resize not to read garbage
This commit is contained in:
parent
67cf3ae837
commit
e4c3866017
@ -134,16 +134,20 @@ void setPixel(TileSheet::SubSheet &ss, int8_t pBpp, ox::Point const&pt, uint8_t
|
||||
}
|
||||
|
||||
static ox::Error setPixelCount(ox::Vector<uint8_t> &pixels, int8_t pBpp, std::size_t cnt) noexcept {
|
||||
size_t sz{};
|
||||
switch (pBpp) {
|
||||
case 4:
|
||||
pixels.resize(cnt / 2);
|
||||
return OxError(0);
|
||||
sz = cnt / 2;
|
||||
break;
|
||||
case 8:
|
||||
pixels.resize(cnt);
|
||||
return OxError(0);
|
||||
sz = cnt;
|
||||
break;
|
||||
default:
|
||||
return OxError(1, "Invalid pBpp used for TileSheet::SubSheet::setPixelCount");
|
||||
}
|
||||
pixels.reserve(sz);
|
||||
pixels.resize(sz);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error setPixelCount(TileSheet::SubSheet &ss, int8_t pBpp, std::size_t cnt) noexcept {
|
||||
@ -158,8 +162,8 @@ unsigned pixelCnt(TileSheet::SubSheet const&ss, int8_t pBpp) noexcept {
|
||||
ox::Error resizeSubsheet(TileSheet::SubSheet &ss, int8_t pBpp, ox::Size const&sz) noexcept {
|
||||
ox::Vector<uint8_t> out;
|
||||
oxReturnError(setPixelCount(out, pBpp, static_cast<size_t>(sz.width * sz.height) * PixelsPerTile));
|
||||
auto const w = sz.width * TileWidth;
|
||||
auto const h = sz.height * TileHeight;
|
||||
auto const w = ss.columns * TileWidth;
|
||||
auto const h = ss.rows * TileHeight;
|
||||
for (auto x = 0; x < w; ++x) {
|
||||
for (auto y = 0; y < h; ++y) {
|
||||
auto const palIdx = getPixel(ss, pBpp, {x, y});
|
||||
|
Loading…
x
Reference in New Issue
Block a user