summaryrefslogtreecommitdiff
path: root/src/factories/TextureFactory.cpp
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2024-04-13 00:26:45 -0600
committerKiritoDv <kiritodev01@gmail.com>2024-04-13 00:26:45 -0600
commit884de3c8836368cb3592ed9dec2e117be1fbc744 (patch)
tree78b9db1b8b9e8dd14a798d883784083b40f50cdd /src/factories/TextureFactory.cpp
parent4513708c95af671028b11f19ae12e963a0989bd4 (diff)
Fully implemented tlut load by addr or symbol
Diffstat (limited to 'src/factories/TextureFactory.cpp')
-rw-r--r--src/factories/TextureFactory.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp
index d2166d4..2734244 100644
--- a/src/factories/TextureFactory.cpp
+++ b/src/factories/TextureFactory.cpp
@@ -255,19 +255,32 @@ ExportResult TextureModdingExporter::Export(std::ostream&write, std::shared_ptr<
case TextureType::Palette4bpp: {
// This check needed until sf64 has tluts fixed.
if (node["tlut_symbol"]) {
- auto tlut = GetSafeNode<std::string>(node,"tlut_symbol");
- auto tlutTextureMap = Companion::Instance->GetTlutTextureMap();
- auto palettePtr = tlutTextureMap[tlut];
-
- if (palettePtr) {
- convert_raw_to_ci8(&raw, &size, texture->mBuffer.data(), (uint8_t *)palettePtr->mBuffer.data(), 0, texture->mWidth, texture->mHeight, texture->mFormat.depth, palettePtr->mFormat.depth);
+ auto tlut = GetSafeNode<std::string>(node,"tlut_symbol");
+ auto palette = Companion::Instance->GetParseDataBySymbol(tlut);
+ if (palette.has_value()) {
+ auto palTexture = std::static_pointer_cast<TextureData>(palette.value().data.value());
+ convert_raw_to_ci8(&raw, &size, texture->mBuffer.data(), (uint8_t *)palTexture->mBuffer.data(), 0, texture->mWidth, texture->mHeight, texture->mFormat.depth, palTexture->mFormat.depth);
} else {
auto symbol = GetSafeNode<std::string>(node, "symbol");
throw std::runtime_error("Could not convert ci8 '"+symbol+"' the tlut symbol name is probably wrong for tlut_symbol node");
}
break;
}
+
+ if (node["tlut"]) {
+ auto tlut = GetSafeNode<uint32_t>(node,"tlut");
+ auto palette = Companion::Instance->GetParseDataByAddr(tlut);
+
+ if (palette.has_value()) {
+ auto palTexture = std::static_pointer_cast<TextureData>(palette.value().data.value());
+ convert_raw_to_ci8(&raw, &size, texture->mBuffer.data(), (uint8_t *)palTexture->mBuffer.data(), 0, texture->mWidth, texture->mHeight, texture->mFormat.depth, palTexture->mFormat.depth);
+ } else {
+ auto symbol = GetSafeNode<std::string>(node, "symbol");
+ throw std::runtime_error("Could not convert ci8 '"+symbol+"' the address is probably wrong for tlut address node");
+ }
+ break;
+ }
}
case TextureType::Grayscale8bpp:
case TextureType::Grayscale4bpp: {
@@ -351,7 +364,7 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui
SPDLOG_INFO("Width: {}", width);
SPDLOG_INFO("Height: {}", height);
}
- SPDLOG_INFO("Size: {}", size);
+ SPDLOG_INFO("Size: {}", size);
SPDLOG_INFO("Offset: 0x{:X}", offset);
if(result.size() == 0){
@@ -362,12 +375,6 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui
return std::nullopt;
}
- if (fmt.type == TextureType::TLUT) {
- auto textureData = std::make_shared<TextureData>(fmt, width, height, result);
- Companion::Instance->AddTlutTextureMap(symbol, textureData);
- return textureData;
- }
-
return std::make_shared<TextureData>(fmt, width, height, result);
}
@@ -432,7 +439,7 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse_modding(std::v
// todo: Add wheel palette input
// Implement so that it works.
- // auto tlut = GetSafeNode<std::string>(node,"tlut_symbol");
+ // auto tlut = GetSafeNode<std::string>(node,"tlut_symbol");
// auto tlutTextureMap = Companion::Instance->GetTlutTextureMap();
// auto palettePtr = tlutTextureMap[tlut];