|
|
|
@ -30,7 +30,7 @@ struct TileSheetV1 {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr bool valid(TileSheetV1 const&ts) noexcept {
|
|
|
|
|
constexpr bool valid(TileSheetV1 const &ts) noexcept {
|
|
|
|
|
auto const bytes = static_cast<size_t>(ts.columns * ts.rows * PixelsPerTile) / (ts.bpp == 4 ? 2 : 1);
|
|
|
|
|
return (ts.bpp == 4 || ts.bpp == 8) && ts.pixels.size() == bytes;
|
|
|
|
|
}
|
|
|
|
@ -71,16 +71,16 @@ struct TileSheetV2 {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr bool valid(TileSheetV2::SubSheet const&ss, int bpp) noexcept {
|
|
|
|
|
constexpr bool valid(TileSheetV2::SubSheet const &ss, int bpp) noexcept {
|
|
|
|
|
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
|
|
|
|
return ox::all_of(ss.subsheets.begin(), ss.subsheets.end(),
|
|
|
|
|
[bpp, bytes](TileSheetV2::SubSheet const&s) {
|
|
|
|
|
[bpp, bytes](TileSheetV2::SubSheet const &s) {
|
|
|
|
|
return bytes == s.pixels.size() && valid(s, bpp);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr bool valid(TileSheetV2 const&ts) noexcept {
|
|
|
|
|
constexpr bool valid(TileSheetV2 const &ts) noexcept {
|
|
|
|
|
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -141,16 +141,16 @@ struct TileSheetV3 {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr bool valid(TileSheetV3::SubSheet const&ss, int bpp) noexcept {
|
|
|
|
|
constexpr bool valid(TileSheetV3::SubSheet const &ss, int bpp) noexcept {
|
|
|
|
|
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
|
|
|
|
return ox::all_of(ss.subsheets.begin(), ss.subsheets.end(),
|
|
|
|
|
[bpp, bytes](TileSheetV3::SubSheet const&s) {
|
|
|
|
|
[bpp, bytes](TileSheetV3::SubSheet const &s) {
|
|
|
|
|
return bytes == s.pixels.size() && valid(s, bpp);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr bool valid(TileSheetV3 const&ts) noexcept {
|
|
|
|
|
constexpr bool valid(TileSheetV3 const &ts) noexcept {
|
|
|
|
|
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -233,18 +233,18 @@ struct TileSheetV4 {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr bool valid(TileSheetV4::SubSheet const&ss, int bpp) noexcept {
|
|
|
|
|
constexpr bool valid(TileSheetV4::SubSheet const &ss, int bpp) noexcept {
|
|
|
|
|
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
|
|
|
|
return
|
|
|
|
|
(ss.pixels.empty() || ss.subsheets.empty()) &&
|
|
|
|
|
ox::all_of(ss.subsheets.begin(), ss.subsheets.end(),
|
|
|
|
|
[bpp, bytes](TileSheetV4::SubSheet const&s) {
|
|
|
|
|
[bpp, bytes](TileSheetV4::SubSheet const &s) {
|
|
|
|
|
return bytes == s.pixels.size() && valid(s, bpp);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr bool valid(TileSheetV4 const&ts) noexcept {
|
|
|
|
|
constexpr bool valid(TileSheetV4 const &ts) noexcept {
|
|
|
|
|
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -334,19 +334,19 @@ struct TileSheetV5 {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr bool valid(TileSheetV5::SubSheet const&ss) noexcept {
|
|
|
|
|
constexpr bool valid(TileSheetV5::SubSheet const &ss) noexcept {
|
|
|
|
|
if (ss.subsheets.empty()) {
|
|
|
|
|
return std::cmp_equal(ss.columns * ss.rows * PixelsPerTile, ss.pixels.size());
|
|
|
|
|
} else {
|
|
|
|
|
return ss.pixels.empty() && ox::all_of(ss.subsheets.begin(), ss.subsheets.end(),
|
|
|
|
|
[](TileSheetV5::SubSheet const&s) {
|
|
|
|
|
[](TileSheetV5::SubSheet const &s) {
|
|
|
|
|
return valid(s);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr bool valid(TileSheetV5 const&ts) noexcept {
|
|
|
|
|
constexpr bool valid(TileSheetV5 const &ts) noexcept {
|
|
|
|
|
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -376,24 +376,24 @@ constexpr ox::Error repair(TileSheetV5 &ts) noexcept {
|
|
|
|
|
using TileSheet = TileSheetV5;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept;
|
|
|
|
|
std::size_t idx(TileSheet::SubSheet const &ss, ox::Point const &pt) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
size_t getTileCnt(TileSheet const&ts) noexcept;
|
|
|
|
|
size_t getTileCnt(TileSheet const &ts) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId id) noexcept;
|
|
|
|
|
TileSheet::SubSheet const*getSubsheet(TileSheet const &ts, SubSheetId id) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
ox::Optional<size_t> getTileIdx(TileSheet const&ts, SubSheetId id) noexcept;
|
|
|
|
|
ox::Optional<size_t> getTileIdx(TileSheet const &ts, SubSheetId id) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
uint8_t getPixel(TileSheet::SubSheet const&ss, std::size_t idx) noexcept;
|
|
|
|
|
uint8_t getPixel(TileSheet::SubSheet const &ss, std::size_t idx) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
uint8_t getPixel(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept;
|
|
|
|
|
uint8_t getPixel(TileSheet::SubSheet const &ss, ox::Point const &pt) noexcept;
|
|
|
|
|
|
|
|
|
|
void setPixel(TileSheet::SubSheet &ss, ox::Point const&pt, uint8_t palIdx) noexcept;
|
|
|
|
|
void setPixel(TileSheet::SubSheet &ss, ox::Point const &pt, uint8_t palIdx) noexcept;
|
|
|
|
|
|
|
|
|
|
ox::Error setPixelCount(TileSheet::SubSheet &ss, std::size_t cnt) noexcept;
|
|
|
|
|
|
|
|
|
@ -406,14 +406,14 @@ void flipY(TileSheet::SubSheet &ss, ox::Point const &a, ox::Point const &b) noex
|
|
|
|
|
* @return a count of the pixels in this sheet
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
unsigned pixelCnt(TileSheet::SubSheet const&ss) noexcept;
|
|
|
|
|
unsigned pixelCnt(TileSheet::SubSheet const &ss) noexcept;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param ss
|
|
|
|
|
* @param sz size of Subsheet in tiles (not pixels)
|
|
|
|
|
*/
|
|
|
|
|
ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const&sz) noexcept;
|
|
|
|
|
ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const &sz) noexcept;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* validateSubSheetIdx takes a SubSheetIdx and moves the index to the
|
|
|
|
@ -424,7 +424,7 @@ ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const&sz) noexcept;
|
|
|
|
|
* @return a valid version of idx
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubSheetIdx idx) noexcept;
|
|
|
|
|
TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const &ts, TileSheet::SubSheetIdx idx) noexcept;
|
|
|
|
|
|
|
|
|
|
ox::Result<TileSheet::SubSheetIdx> getSubSheetIdx(TileSheet const &ts, SubSheetId pId) noexcept;
|
|
|
|
|
|
|
|
|
@ -438,7 +438,7 @@ ox::Result<TileSheet::SubSheet const*> getSubSheet(
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
TileSheet::SubSheet &getSubSheet(
|
|
|
|
|
ox::SpanView<uint32_t> const&idx,
|
|
|
|
|
ox::SpanView<uint32_t> const &idx,
|
|
|
|
|
std::size_t idxIt,
|
|
|
|
|
TileSheet::SubSheet &pSubsheet) noexcept;
|
|
|
|
|
|
|
|
|
@ -447,7 +447,7 @@ TileSheet::SubSheet &getSubSheet(
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wdangling-reference"
|
|
|
|
|
#endif
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
TileSheet::SubSheet const&getSubSheet(TileSheet const&ts, ox::SpanView<uint32_t> const &idx) noexcept;
|
|
|
|
|
TileSheet::SubSheet const &getSubSheet(TileSheet const &ts, ox::SpanView<uint32_t> const &idx) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
TileSheet::SubSheet &getSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const &idx) noexcept;
|
|
|
|
@ -461,27 +461,29 @@ ox::Error insertSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const &idx, TileS
|
|
|
|
|
|
|
|
|
|
ox::Error rmSubSheet(
|
|
|
|
|
TileSheet &ts,
|
|
|
|
|
TileSheet::SubSheetIdx const&idx,
|
|
|
|
|
TileSheet::SubSheetIdx const &idx,
|
|
|
|
|
std::size_t idxIt,
|
|
|
|
|
TileSheet::SubSheet &pSubsheet) noexcept;
|
|
|
|
|
|
|
|
|
|
ox::Error rmSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const&idx) noexcept;
|
|
|
|
|
ox::Error rmSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const &idx) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
uint8_t getPixel(
|
|
|
|
|
TileSheet const&ts,
|
|
|
|
|
ox::Point const&pt,
|
|
|
|
|
TileSheet::SubSheetIdx const&subsheetIdx) noexcept;
|
|
|
|
|
TileSheet const &ts,
|
|
|
|
|
ox::Point const &pt,
|
|
|
|
|
TileSheet::SubSheetIdx const &subsheetIdx) noexcept;
|
|
|
|
|
|
|
|
|
|
ox::Result<SubSheetId> getIdFor(TileSheet const&ts, ox::StringViewCR path) noexcept;
|
|
|
|
|
ox::Result<SubSheetId> getIdFor(TileSheet const &ts, ox::StringViewCR path) noexcept;
|
|
|
|
|
|
|
|
|
|
ox::Result<unsigned> getTileOffset(TileSheet const&ts, ox::StringViewCR pNamePath) noexcept;
|
|
|
|
|
ox::Result<unsigned> getTileOffset(TileSheet const &ts, ox::StringViewCR pNamePath) noexcept;
|
|
|
|
|
|
|
|
|
|
ox::Result<uint32_t> getTileOffset(TileSheet const&ts, SubSheetId pId) noexcept;
|
|
|
|
|
ox::Result<uint32_t> getTileOffset(TileSheet const &ts, SubSheetId pId) noexcept;
|
|
|
|
|
|
|
|
|
|
ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const&ss, SubSheetId pId) noexcept;
|
|
|
|
|
ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const &ss, SubSheetId pId) noexcept;
|
|
|
|
|
|
|
|
|
|
ox::Result<ox::StringView> getNameFor(TileSheet const&ts, SubSheetId pId) noexcept;
|
|
|
|
|
ox::Result<ox::StringView> getNameFor(TileSheet &ts, SubSheetId pId) noexcept;
|
|
|
|
|
|
|
|
|
|
ox::Result<ox::StringView> getNameFor(TileSheet const &ts, SubSheetId pId) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
ox::Vector<uint8_t> pixels(TileSheet &ts) noexcept;
|
|
|
|
@ -497,7 +499,7 @@ struct CompactTileSheetV1 {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr bool valid(CompactTileSheetV1 const&ts) noexcept {
|
|
|
|
|
constexpr bool valid(CompactTileSheetV1 const &ts) noexcept {
|
|
|
|
|
return ts.bpp == 4 || ts.bpp == 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -506,22 +508,22 @@ using CompactTileSheet = CompactTileSheetV1;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
uint8_t getPixel4Bpp(
|
|
|
|
|
CompactTileSheet const&ts,
|
|
|
|
|
CompactTileSheet const &ts,
|
|
|
|
|
size_t idx) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
uint8_t getPixel8Bpp(
|
|
|
|
|
CompactTileSheet const&ts,
|
|
|
|
|
CompactTileSheet const &ts,
|
|
|
|
|
size_t idx) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
ox::Pair<uint8_t> get2Pixels4Bpp(
|
|
|
|
|
CompactTileSheet const&ts,
|
|
|
|
|
CompactTileSheet const &ts,
|
|
|
|
|
size_t idx) noexcept;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
ox::Pair<uint8_t> get2Pixels8Bpp(
|
|
|
|
|
CompactTileSheet const&ts,
|
|
|
|
|
CompactTileSheet const &ts,
|
|
|
|
|
size_t idx) noexcept;
|
|
|
|
|
|
|
|
|
|
OX_MODEL_BEGIN(TileSheetV1)
|
|
|
|
@ -601,8 +603,8 @@ OX_MODEL_BEGIN(CompactTileSheetV1)
|
|
|
|
|
OX_MODEL_END()
|
|
|
|
|
|
|
|
|
|
ox::Vector<uint32_t> resizeTileSheetData(
|
|
|
|
|
ox::Vector<uint32_t> const&srcPixels,
|
|
|
|
|
ox::Size const&srcSize,
|
|
|
|
|
ox::Vector<uint32_t> const &srcPixels,
|
|
|
|
|
ox::Size const &srcSize,
|
|
|
|
|
int scale = 2) noexcept;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|