From 102ab4862f360651f02ec1af904298984699a3d4 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Sat, 17 Feb 2024 12:06:08 -0600 Subject: Added tlut support --- src/factories/TextureFactory.cpp | 27 +++++++++++++++++++++------ src/factories/TextureFactory.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp index eb89480..420d8d8 100644 --- a/src/factories/TextureFactory.cpp +++ b/src/factories/TextureFactory.cpp @@ -15,6 +15,7 @@ static const std::unordered_map gTextureTypes = { { "IA4", TextureType::GrayscaleAlpha4bpp }, { "IA8", TextureType::GrayscaleAlpha8bpp }, { "IA16", TextureType::GrayscaleAlpha16bpp }, + { "TLUT", TextureType::TLUT }, }; size_t CalculateTextureSize(TextureType type, uint32_t width, uint32_t height) { @@ -23,6 +24,7 @@ size_t CalculateTextureSize(TextureType type, uint32_t width, uint32_t height) { case TextureType::RGBA32bpp: return width * height * 4; // 2 bytes per pixel + case TextureType::TLUT: case TextureType::RGBA16bpp: case TextureType::GrayscaleAlpha16bpp: return width * height * 2; @@ -138,15 +140,15 @@ void TextureBinaryExporter::Export(std::ostream &write, std::shared_ptr> TextureFactory::parse(std::vector& buffer, YAML::Node& node) { auto format = GetSafeNode(node, "format"); - auto width = GetSafeNode(node, "width"); - auto height = GetSafeNode(node, "height"); - auto size = GetSafeNode(node, "size", CalculateTextureSize(gTextureTypes.at(format), width, height)); + uint32_t width; + uint32_t height; + uint32_t size; auto offset = Decompressor::TranslateAddr(GetSafeNode(node, "offset")); if (format.empty()) { SPDLOG_ERROR("Texture entry at {:X} in yaml missing format node\n\ Please add one of the following formats\n\ - rgba16, rgba32, ia16, ia8, ia4, i8, i4, ci8, ci4, 1bpp", offset); + rgba16, rgba32, ia16, ia8, ia4, i8, i4, ci8, ci4, 1bpp, tlut", offset); return std::nullopt; } @@ -156,6 +158,15 @@ std::optional> TextureFactory::parse(std::vector(node, "colors"); + height = 1; + } else { + width = GetSafeNode(node, "width"); + height = GetSafeNode(node, "height"); + } + + size = GetSafeNode(node, "size", CalculateTextureSize(gTextureTypes.at(format), width, height)); auto [_, segment] = Decompressor::AutoDecode(node, buffer, size); std::vector result; @@ -166,8 +177,12 @@ std::optional> TextureFactory::parse(std::vector