summaryrefslogtreecommitdiff
path: root/src/factories/TextureFactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/factories/TextureFactory.cpp')
-rw-r--r--src/factories/TextureFactory.cpp25
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");
}