diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2024-12-25 00:43:20 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2024-12-25 00:43:20 -0600 |
| commit | 64266cbac2f51e50380ea0d7191b97e63e64ddfa (patch) | |
| tree | f774cdbecb283295fe283244b6c370b33d9a2b69 /src/utils | |
| parent | 0efd51b717fe7ffef8a8c93a4c25efcb8ef3f919 (diff) | |
| parent | abb74ef940afe35ddf7bea5ea2e03c45484a95a3 (diff) | |
Merge branch 'main' into audio_extraction
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/Decompressor.cpp | 6 | ||||
| -rw-r--r-- | src/utils/Decompressor.h | 2 | ||||
| -rw-r--r-- | src/utils/TextureUtils.cpp | 57 | ||||
| -rw-r--r-- | src/utils/TextureUtils.h | 31 |
4 files changed, 92 insertions, 4 deletions
diff --git a/src/utils/Decompressor.cpp b/src/utils/Decompressor.cpp index 95af7b1..1fee382 100644 --- a/src/utils/Decompressor.cpp +++ b/src/utils/Decompressor.cpp @@ -12,9 +12,9 @@ extern "C" { std::unordered_map<uint32_t, DataChunk*> gCachedChunks; -DataChunk* Decompressor::Decode(const std::vector<uint8_t>& buffer, const uint32_t offset, const CompressionType type) { +DataChunk* Decompressor::Decode(const std::vector<uint8_t>& buffer, const uint32_t offset, const CompressionType type, bool ignoreCache) { - if(gCachedChunks.contains(offset)){ + if(!ignoreCache && gCachedChunks.contains(offset)){ return gCachedChunks[offset]; } @@ -208,4 +208,4 @@ void Decompressor::ClearCache() { delete value->data; } gCachedChunks.clear(); -} +}
\ No newline at end of file diff --git a/src/utils/Decompressor.h b/src/utils/Decompressor.h index 4d2056a..4aff942 100644 --- a/src/utils/Decompressor.h +++ b/src/utils/Decompressor.h @@ -32,7 +32,7 @@ struct DecompressedData { class Decompressor { public: - static DataChunk* Decode(const std::vector<uint8_t>& buffer, uint32_t offset, CompressionType type); + static DataChunk* Decode(const std::vector<uint8_t>& buffer, uint32_t offset, CompressionType type, bool ignoreCache = false); static DataChunk* DecodeTKMK00(const std::vector<uint8_t>& buffer, const uint32_t offset, const uint32_t size, const uint32_t alpha); static DecompressedData AutoDecode(YAML::Node& node, std::vector<uint8_t>& buffer, std::optional<size_t> size = std::nullopt); static DecompressedData AutoDecode(uint32_t offset, std::optional<size_t> size, std::vector<uint8_t>& buffer); diff --git a/src/utils/TextureUtils.cpp b/src/utils/TextureUtils.cpp new file mode 100644 index 0000000..7b70f19 --- /dev/null +++ b/src/utils/TextureUtils.cpp @@ -0,0 +1,57 @@ +#include "TextureUtils.h" +#include <vector> +#include <binarytools/endianness.h> + +size_t TextureUtils::CalculateTextureSize(TextureType type, uint32_t width, uint32_t height) { + switch (type) { + // 4 bytes per pixel + case TextureType::RGBA32bpp: + return width * height * 4; + // 2 bytes per pixel + case TextureType::TLUT: + case TextureType::RGBA16bpp: + case TextureType::GrayscaleAlpha16bpp: + return width * height * 2; + // 1 byte per pixel + case TextureType::Grayscale8bpp: + case TextureType::Palette8bpp: + case TextureType::GrayscaleAlpha8bpp: + // TODO: We need to validate this MegaMech + case TextureType::GrayscaleAlpha1bpp: + return width * height; + // 1/2 byte per pixel + case TextureType::Palette4bpp: + case TextureType::Grayscale4bpp: + case TextureType::GrayscaleAlpha4bpp: + return (width * height) / 2; + default: + return 0; + } +} + +std::vector<uint8_t> TextureUtils::alloc_ia8_text_from_i1(uint16_t *in, int16_t width, int16_t height) { + int32_t inPos; + uint16_t bitMask; + int16_t outPos = 0; + const auto out = new uint8_t[width * height]; + + for (int32_t inPos = 0; inPos < (width * height) / 16; inPos++) { + uint16_t bitMask = 0x8000; + + while (bitMask != 0) { + if (BSWAP16(in[inPos]) & bitMask) { + out[outPos] = 0xFF; + } else { + out[outPos] = 0x00; + } + + bitMask /= 2; + outPos++; + } + } + + auto result = std::vector(out, out + width * height); + delete[] out; + + return result; +}
\ No newline at end of file diff --git a/src/utils/TextureUtils.h b/src/utils/TextureUtils.h new file mode 100644 index 0000000..90501c6 --- /dev/null +++ b/src/utils/TextureUtils.h @@ -0,0 +1,31 @@ +#pragma once + +#include <cstdint> +#include <vector> +#include <cstddef> + +enum class TextureType { + Error, + RGBA32bpp, + RGBA16bpp, + Palette4bpp, + Palette8bpp, + Grayscale4bpp, + Grayscale8bpp, + GrayscaleAlpha4bpp, + GrayscaleAlpha8bpp, + GrayscaleAlpha16bpp, + GrayscaleAlpha1bpp, + TLUT +}; + +struct TextureFormat { + TextureType type; + uint32_t depth; +}; + +class TextureUtils { + public: + static size_t CalculateTextureSize(TextureType type, uint32_t width, uint32_t height); + static std::vector<uint8_t> alloc_ia8_text_from_i1(uint16_t *in, int16_t width, int16_t height); +}; |
