From 8196258d2b06afcb06bd71b4b95d4db6e9be0208 Mon Sep 17 00:00:00 2001 From: petrie911 <69443847+petrie911@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:02:12 -0500 Subject: Add Vec3s factory, fix colpoly, add some support for palettes (#54) * tlut? * tlut --- src/factories/TextureFactory.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/factories/TextureFactory.cpp') diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp index 9d24c5c..2118e2e 100644 --- a/src/factories/TextureFactory.cpp +++ b/src/factories/TextureFactory.cpp @@ -3,6 +3,7 @@ #include "spdlog/spdlog.h" #include "Companion.h" #include +#include extern "C" { #include "n64graphics/n64graphics.h" @@ -153,7 +154,7 @@ ExportResult TextureCodeExporter::Export(std::ostream &write, std::shared_ptr(node, "ctype", "static const u8") << " " << name << "[][" << texture->mBuffer.size() << "] = {\n"; + write << GetSafeNode(node, "ctype", "static unsigned char") << " " << name << "[][" << texture->mBuffer.size() << "] = {\n"; } write << tab << "{\n"; @@ -283,7 +284,26 @@ std::optional> TextureFactory::parse(std::vector(node, "width"); height = GetSafeNode(node, "height"); } - + + if((format == "CI4" || format == "CI8") && node["tlut"] && node["colors"]) { + YAML::Node tlutNode; + const auto tlutOffset = GetSafeNode(node, "tlut"); + if(node["symbol"]) { + const auto symbol = GetSafeNode(node, "symbol"); + const auto tlutSymbol = GetSafeNode(node, "tlut_symbol", symbol + "_tlut"); + std::ostringstream offsetSeg; + offsetSeg << std::uppercase << std::hex << tlutOffset; + tlutNode["symbol"] = std::regex_replace(tlutSymbol, std::regex(R"(OFFSET)"), offsetSeg.str()); + } + tlutNode["type"] = "TEXTURE"; + tlutNode["format"] = "TLUT"; + tlutNode["offset"] = tlutOffset; + tlutNode["colors"] = GetSafeNode(node, "colors"); + if(node["tlut_ctype"]) { + tlutNode["ctype"] = GetSafeNode(node, "tlut_ctype"); + } + Companion::Instance->AddAsset(tlutNode); + } size = GetSafeNode(node, "size", CalculateTextureSize(gTextureFormats.at(format).type, width, height)); auto [_, segment] = Decompressor::AutoDecode(node, buffer, size); std::vector result; @@ -369,6 +389,7 @@ std::optional> TextureFactory::parse_modding(std::v const auto imgi = png2ci(buffer.data(), buffer.size(), &width, &height); size = width * height * fmt.depth / 8; raw = new uint8_t[size]; + if(ci2raw_torch(raw, imgi, width, height, fmt.depth) <= 0){ throw std::runtime_error("Failed to convert PNG to texture"); } -- cgit v1.2.3