diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2024-02-17 12:06:08 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2024-02-17 12:06:08 -0600 |
| commit | 102ab4862f360651f02ec1af904298984699a3d4 (patch) | |
| tree | b6aff75f537e2d4ebb32646b0747a6131a001f78 | |
| parent | 5b1e5d632b44cd13282ce98d8dd3c11a5c86d598 (diff) | |
Added tlut support
| -rw-r--r-- | src/factories/TextureFactory.cpp | 27 | ||||
| -rw-r--r-- | 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 <std::string, TextureType> 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<IParsedD std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { auto format = GetSafeNode<std::string>(node, "format"); - auto width = GetSafeNode<uint32_t>(node, "width"); - auto height = GetSafeNode<uint32_t>(node, "height"); - auto size = GetSafeNode<uint32_t>(node, "size", CalculateTextureSize(gTextureTypes.at(format), width, height)); + uint32_t width; + uint32_t height; + uint32_t size; auto offset = Decompressor::TranslateAddr(GetSafeNode<uint32_t>(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<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui TextureType type = gTextureTypes.at(format); + if(type == TextureType::TLUT){ + width = GetSafeNode<uint32_t>(node, "colors"); + height = 1; + } else { + width = GetSafeNode<uint32_t>(node, "width"); + height = GetSafeNode<uint32_t>(node, "height"); + } + + size = GetSafeNode<uint32_t>(node, "size", CalculateTextureSize(gTextureTypes.at(format), width, height)); auto [_, segment] = Decompressor::AutoDecode(node, buffer, size); std::vector<uint8_t> result; @@ -166,8 +177,12 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui } SPDLOG_INFO("Texture: {}", format); - SPDLOG_INFO("Width: {}", width); - SPDLOG_INFO("Height: {}", height); + if(type == TextureType::TLUT){ + SPDLOG_INFO("Colors: {}", width); + } else { + SPDLOG_INFO("Width: {}", width); + SPDLOG_INFO("Height: {}", height); + } SPDLOG_INFO("Size: {}", size); SPDLOG_INFO("Offset: 0x{:X}", offset); SPDLOG_INFO("Is Compressed: {}", Decompressor::IsCompressed(node) ? "true" : "false"); diff --git a/src/factories/TextureFactory.h b/src/factories/TextureFactory.h index 5f5fcc8..2bffc9a 100644 --- a/src/factories/TextureFactory.h +++ b/src/factories/TextureFactory.h @@ -14,6 +14,7 @@ enum class TextureType { GrayscaleAlpha4bpp, GrayscaleAlpha8bpp, GrayscaleAlpha16bpp, + TLUT }; class TextureData : public IParsedData { |
