[nostalgia/core] Add custom TypeStore with type desc loader
This commit is contained in:
@@ -12,25 +12,32 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
static ox::Error toPngFile(const ox::String &path, const TileSheet::SubSheet &s, const Palette &pal, int8_t bpp) noexcept {
|
||||
template<bool alpha = false>
|
||||
ox::Error toPngFile(const ox::String &path, const TileSheet::SubSheet &s, const Palette &pal, int8_t bpp) noexcept {
|
||||
ox::Vector<uint8_t> pixels;
|
||||
s.readPixelsTo(&pixels, bpp);
|
||||
const unsigned rows = s.rows == -1 ? pixels.size() / PixelsPerTile : static_cast<unsigned>(s.rows);
|
||||
const unsigned cols = s.columns == -1 ? 1 : static_cast<unsigned>(s.columns);
|
||||
const auto width = cols * TileWidth;
|
||||
const auto height = rows * TileHeight;
|
||||
ox::Vector<unsigned char> outData(pixels.size() * 3);
|
||||
constexpr auto bytesPerPixel = alpha ? 4 : 3;
|
||||
ox::Vector<unsigned char> outData(pixels.size() * bytesPerPixel);
|
||||
for (auto idx = 0; const auto colorIdx : pixels) {
|
||||
const auto pt = idxToPt(idx, static_cast<int>(cols));
|
||||
const auto i = static_cast<unsigned>(pt.y * static_cast<int>(width) + pt.x) * 3;
|
||||
const auto i = static_cast<unsigned>(pt.y * static_cast<int>(width) + pt.x) * bytesPerPixel;
|
||||
const auto c = pal.colors[colorIdx];
|
||||
outData[i + 0] = (red32(c));
|
||||
outData[i + 1] = (green32(c));
|
||||
outData[i + 2] = (blue32(c));
|
||||
outData[i + 0] = red32(c);
|
||||
outData[i + 1] = green32(c);
|
||||
outData[i + 2] = blue32(c);
|
||||
if constexpr(alpha) {
|
||||
outData[i + 3] = colorIdx ? 255 : 0;
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
return OxError(lodepng_encode24_file(path.c_str(), outData.data(), width, height));
|
||||
constexpr auto fmt = alpha ? LCT_RGBA : LCT_RGB;
|
||||
return OxError(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8));
|
||||
}
|
||||
|
||||
TileSheetEditorImGui::TileSheetEditorImGui(Context *ctx, const ox::String &path): m_tileSheetEditor(ctx, path) {
|
||||
m_ctx = ctx;
|
||||
m_itemPath = path;
|
||||
|
||||
Reference in New Issue
Block a user