diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2023-10-19 11:12:24 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2023-10-19 11:12:24 -0600 |
| commit | a66b259d7c10c3367a04819c6b55d47fb9a99f5e (patch) | |
| tree | 43327783ffef57bcc9bf686631ac175629bb0579 | |
| parent | 5025c4bebecd6d96abaacfedbde0a6607df15c41 (diff) | |
Added ia1 conversion
| -rw-r--r-- | src/factories/TextureFactory.cpp | 38 | ||||
| -rw-r--r-- | src/factories/TextureFactory.h | 1 |
2 files changed, 36 insertions, 3 deletions
diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp index c92c8a5..d929d7c 100644 --- a/src/factories/TextureFactory.cpp +++ b/src/factories/TextureFactory.cpp @@ -8,12 +8,36 @@ namespace fs = std::filesystem; static const std::unordered_map <std::string, TextureType> gTextureTypes = { { "RGBA16", TextureType::RGBA16bpp }, { "RGBA32", TextureType::RGBA32bpp }, - { "IA1", TextureType::GrayscaleAlpha4bpp }, + { "IA1", TextureType::GrayscaleAlpha1bpp }, { "IA4", TextureType::GrayscaleAlpha4bpp }, { "IA8", TextureType::GrayscaleAlpha8bpp }, { "IA16", TextureType::GrayscaleAlpha16bpp }, }; +uint8_t* alloc_ia8_text_from_i1(uint16_t *in, int16_t width, int16_t height) { + int32_t inPos; + uint16_t bitMask; + int16_t outPos = 0; + uint8_t* out = new uint8_t[width * height]; + + for (inPos = 0; inPos < (width * height) / 16; inPos++) { + bitMask = 0x8000; + + while (bitMask != 0) { + if (BSWAP16(in[inPos]) & bitMask) { + out[outPos] = 0xFF; + } else { + out[outPos] = 0x00; + } + + bitMask /= 2; + outPos++; + } + } + + return out; +} + bool TextureFactory::process(LUS::BinaryWriter* writer, YAML::Node& data, std::vector<uint8_t>& buffer) { auto format = data["format"].as<std::string>(); @@ -37,8 +61,16 @@ bool TextureFactory::process(LUS::BinaryWriter* writer, YAML::Node& data, std::v if(data["mio0"]){ auto mio0 = data["mio0"].as<size_t>(); auto decoded = MIO0Decoder::Decode(buffer, offset); - WRITE_U32(size); - WRITE_ARRAY(decoded.data() + mio0, size); + auto data = decoded.data() + mio0; + if(type == TextureType::GrayscaleAlpha1bpp){ + auto ia8 = alloc_ia8_text_from_i1((uint16_t*)data, 8, 16); + WRITE_U32(8 * 16); + WRITE_ARRAY(ia8, 8 * 16); + delete[] ia8; + } else { + WRITE_U32(size); + WRITE_ARRAY(data, size); + } } else { WRITE_U32(size); WRITE_ARRAY(buffer.data() + offset, size); diff --git a/src/factories/TextureFactory.h b/src/factories/TextureFactory.h index c0349d6..e153e07 100644 --- a/src/factories/TextureFactory.h +++ b/src/factories/TextureFactory.h @@ -10,6 +10,7 @@ enum class TextureType { Palette8bpp, Grayscale4bpp, Grayscale8bpp, + GrayscaleAlpha1bpp, GrayscaleAlpha4bpp, GrayscaleAlpha8bpp, GrayscaleAlpha16bpp, |
