[nostalgia/core/studio] Fix Subsheet width to update properly
All checks were successful
Build / build (push) Successful in 2m30s
All checks were successful
Build / build (push) Successful in 2m30s
This commit is contained in:
parent
9105b1ece6
commit
37e65ab0a6
@ -222,6 +222,14 @@ ox::Error setPixelCount(TileSheet::SubSheet &ss, int8_t pBpp, std::size_t cnt) n
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
unsigned pixelCnt(TileSheet::SubSheet const&ss, int8_t pBpp) noexcept;
|
unsigned pixelCnt(TileSheet::SubSheet const&ss, int8_t pBpp) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param ss
|
||||||
|
* @param pBpp
|
||||||
|
* @param sz size of Subsheet in tiles (not pixels)
|
||||||
|
*/
|
||||||
|
ox::Error resizeSubsheet(TileSheet::SubSheet &ss, int8_t pBpp, ox::Size const&sz) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* validateSubSheetIdx takes a SubSheetIdx and moves the index to the
|
* validateSubSheetIdx takes a SubSheetIdx and moves the index to the
|
||||||
* preceding or parent sheet if the current corresponding sheet does
|
* preceding or parent sheet if the current corresponding sheet does
|
||||||
|
@ -23,9 +23,7 @@ core::UpdateSubSheetCommand::UpdateSubSheetCommand(
|
|||||||
void UpdateSubSheetCommand::redo() noexcept {
|
void UpdateSubSheetCommand::redo() noexcept {
|
||||||
auto &sheet = getSubSheet(m_img, m_idx);
|
auto &sheet = getSubSheet(m_img, m_idx);
|
||||||
sheet.name = m_newName;
|
sheet.name = m_newName;
|
||||||
sheet.columns = m_newCols;
|
oxLogError(resizeSubsheet(sheet, m_img.bpp, {m_newCols, m_newRows}));
|
||||||
sheet.rows = m_newRows;
|
|
||||||
oxLogError(setPixelCount(sheet, m_img.bpp, static_cast<std::size_t>(PixelsPerTile * m_newCols * m_newRows)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateSubSheetCommand::undo() noexcept {
|
void UpdateSubSheetCommand::undo() noexcept {
|
||||||
|
@ -106,8 +106,8 @@ uint8_t getPixel(TileSheet::SubSheet const&ss, int8_t pBpp, ox::Point const&pt)
|
|||||||
return getPixel(ss, pBpp, idx);
|
return getPixel(ss, pBpp, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPixel(TileSheet::SubSheet &ss, int8_t pBpp, uint64_t idx, uint8_t palIdx) noexcept {
|
static void setPixel(ox::Vector<uint8_t> &pixels, int8_t pBpp, uint64_t idx, uint8_t palIdx) noexcept {
|
||||||
auto &pixel = ss.pixels[static_cast<std::size_t>(idx / 2)];
|
auto &pixel = pixels[static_cast<std::size_t>(idx / 2)];
|
||||||
if (pBpp == 4) {
|
if (pBpp == 4) {
|
||||||
if (idx & 1) {
|
if (idx & 1) {
|
||||||
pixel = static_cast<uint8_t>((pixel & 0b0000'1111) | (palIdx << 4));
|
pixel = static_cast<uint8_t>((pixel & 0b0000'1111) | (palIdx << 4));
|
||||||
@ -119,29 +119,59 @@ void setPixel(TileSheet::SubSheet &ss, int8_t pBpp, uint64_t idx, uint8_t palIdx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPixel(TileSheet::SubSheet &ss, int8_t pBpp, uint64_t idx, uint8_t palIdx) noexcept {
|
||||||
|
setPixel(ss.pixels, pBpp, idx, palIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setPixel(ox::Vector<uint8_t> &pixels, int columns, int8_t pBpp, ox::Point const &pt, uint8_t palIdx) noexcept {
|
||||||
|
const auto idx = ptToIdx(pt, columns);
|
||||||
|
setPixel(pixels, pBpp, idx, palIdx);
|
||||||
|
}
|
||||||
|
|
||||||
void setPixel(TileSheet::SubSheet &ss, int8_t pBpp, ox::Point const &pt, uint8_t palIdx) noexcept {
|
void setPixel(TileSheet::SubSheet &ss, int8_t pBpp, ox::Point const &pt, uint8_t palIdx) noexcept {
|
||||||
const auto idx = ptToIdx(pt, ss.columns);
|
const auto idx = ptToIdx(pt, ss.columns);
|
||||||
setPixel(ss, pBpp, idx, palIdx);
|
setPixel(ss, pBpp, idx, palIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error setPixelCount(TileSheet::SubSheet &ss, int8_t pBpp, std::size_t cnt) noexcept {
|
static ox::Error setPixelCount(ox::Vector<uint8_t> &pixels, int8_t pBpp, std::size_t cnt) noexcept {
|
||||||
switch (pBpp) {
|
switch (pBpp) {
|
||||||
case 4:
|
case 4:
|
||||||
ss.pixels.resize(cnt / 2);
|
pixels.resize(cnt / 2);
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
case 8:
|
case 8:
|
||||||
ss.pixels.resize(cnt);
|
pixels.resize(cnt);
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
default:
|
default:
|
||||||
return OxError(1, "Invalid pBpp used for TileSheet::SubSheet::setPixelCount");
|
return OxError(1, "Invalid pBpp used for TileSheet::SubSheet::setPixelCount");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ox::Error setPixelCount(TileSheet::SubSheet &ss, int8_t pBpp, std::size_t cnt) noexcept {
|
||||||
|
return setPixelCount(ss.pixels, pBpp, cnt);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned pixelCnt(TileSheet::SubSheet const&ss, int8_t pBpp) noexcept {
|
unsigned pixelCnt(TileSheet::SubSheet const&ss, int8_t pBpp) noexcept {
|
||||||
const auto pixelsSize = static_cast<unsigned>(ss.pixels.size());
|
const auto pixelsSize = static_cast<unsigned>(ss.pixels.size());
|
||||||
return pBpp == 4 ? pixelsSize * 2 : pixelsSize;
|
return pBpp == 4 ? pixelsSize * 2 : pixelsSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
for (auto x = 0; x < w; ++x) {
|
||||||
|
for (auto y = 0; y < h; ++y) {
|
||||||
|
auto const palIdx = getPixel(ss, pBpp, {x, y});
|
||||||
|
setPixel(out, sz.width, pBpp, {x, y}, palIdx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ss.columns = sz.width;
|
||||||
|
ss.rows = sz.height;
|
||||||
|
ss.pixels = std::move(out);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const&ss, SubSheetId pId) noexcept {
|
ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const&ss, SubSheetId pId) noexcept {
|
||||||
if (ss.id == pId) {
|
if (ss.id == pId) {
|
||||||
return ox::StringView(ss.name);
|
return ox::StringView(ss.name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user