diff options
| author | petrie911 <69443847+petrie911@users.noreply.github.com> | 2024-03-26 18:02:12 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-26 17:02:12 -0600 |
| commit | 8196258d2b06afcb06bd71b4b95d4db6e9be0208 (patch) | |
| tree | b14cbdd8265ad5d45dbf3c908d1278c693537026 /src/factories/TextureFactory.cpp | |
| parent | b101ad14bf80730a30d67cfed974f77113a41ab6 (diff) | |
Add Vec3s factory, fix colpoly, add some support for palettes (#54)
* tlut?
* tlut
Diffstat (limited to 'src/factories/TextureFactory.cpp')
| -rw-r--r-- | src/factories/TextureFactory.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
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 <iomanip> +#include <regex> extern "C" { #include "n64graphics/n64graphics.h" @@ -153,7 +154,7 @@ ExportResult TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IP } if(start == offset){ - write << GetSafeNode<std::string>(node, "ctype", "static const u8") << " " << name << "[][" << texture->mBuffer.size() << "] = {\n"; + write << GetSafeNode<std::string>(node, "ctype", "static unsigned char") << " " << name << "[][" << texture->mBuffer.size() << "] = {\n"; } write << tab << "{\n"; @@ -283,7 +284,26 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui width = GetSafeNode<uint32_t>(node, "width"); height = GetSafeNode<uint32_t>(node, "height"); } - + + if((format == "CI4" || format == "CI8") && node["tlut"] && node["colors"]) { + YAML::Node tlutNode; + const auto tlutOffset = GetSafeNode<uint32_t>(node, "tlut"); + if(node["symbol"]) { + const auto symbol = GetSafeNode<std::string>(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<uint32_t>(node, "colors"); + if(node["tlut_ctype"]) { + tlutNode["ctype"] = GetSafeNode<std::string>(node, "tlut_ctype"); + } + Companion::Instance->AddAsset(tlutNode); + } size = GetSafeNode<uint32_t>(node, "size", CalculateTextureSize(gTextureFormats.at(format).type, width, height)); auto [_, segment] = Decompressor::AutoDecode(node, buffer, size); std::vector<uint8_t> result; @@ -369,6 +389,7 @@ std::optional<std::shared_ptr<IParsedData>> 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"); } |
