[nostalgia/gfx/studio/tilesheet] Fix Insert tile command

This commit is contained in:
Gary Talent 2025-05-09 20:34:42 -05:00
parent 209658549c
commit d585794cbe

View File

@ -9,20 +9,19 @@ namespace nostalgia::gfx {
InsertTilesCommand::InsertTilesCommand( InsertTilesCommand::InsertTilesCommand(
TileSheet &img, TileSheet &img,
TileSheet::SubSheetIdx idx, TileSheet::SubSheetIdx idx,
std::size_t tileIdx, std::size_t const tileIdx,
std::size_t tileCnt) noexcept: std::size_t const tileCnt) noexcept:
m_img(img), m_img{img},
m_idx(std::move(idx)) { m_idx{std::move(idx)} {
const unsigned bytesPerTile = m_img.bpp == 4 ? PixelsPerTile / 2 : PixelsPerTile; m_insertPos = tileIdx * PixelsPerTile;
m_insertPos = tileIdx * bytesPerTile; m_insertCnt = tileCnt * PixelsPerTile;
m_insertCnt = tileCnt * bytesPerTile;
m_deletedPixels.resize(m_insertCnt); m_deletedPixels.resize(m_insertCnt);
// copy pixels to be erased // copy pixels to be erased
{ {
auto &s = getSubSheet(m_img, m_idx); auto &s = getSubSheet(m_img, m_idx);
auto &p = s.pixels; auto &p = s.pixels;
auto dst = m_deletedPixels.begin(); auto const dst = m_deletedPixels.begin();
auto src = p.begin() + p.size() - m_insertCnt; auto const src = p.begin() + p.size() - m_insertCnt;
ox::copy_n(src, m_insertCnt, dst); ox::copy_n(src, m_insertCnt, dst);
} }
} }
@ -32,7 +31,7 @@ OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::Error InsertTilesCommand::redo() noexcept { ox::Error InsertTilesCommand::redo() noexcept {
auto &s = getSubSheet(m_img, m_idx); auto &s = getSubSheet(m_img, m_idx);
auto &p = s.pixels; auto &p = s.pixels;
auto dstPos = m_insertPos + m_insertCnt; auto const dstPos = m_insertPos + m_insertCnt;
auto const src = &p[m_insertPos]; auto const src = &p[m_insertPos];
if (dstPos < p.size()) { if (dstPos < p.size()) {
auto const dst = &p[dstPos]; auto const dst = &p[dstPos];