diff --git a/src/noggit/Alphamap.cpp b/src/noggit/Alphamap.cpp index eaa47a4d..abf07773 100755 --- a/src/noggit/Alphamap.cpp +++ b/src/noggit/Alphamap.cpp @@ -95,16 +95,26 @@ void Alphamap::readBigAlpha(BlizzardArchive::ClientFile *f) f->seekRelative(0x1000); } +namespace +{ + struct alpha_4_4 + { + std::uint8_t lower : 4; + std::uint8_t upper : 4; + }; +} + + void Alphamap::readNotCompressed(BlizzardArchive::ClientFile *f, bool do_not_fix_alpha_map) { - char const* abuf = f->getPointer(); + alpha_4_4 const* abuf = reinterpret_cast(f->getPointer()); for (std::size_t x(0); x < 64; ++x) { for (std::size_t y(0); y < 64; y += 2) { - amap[x * 64 + y + 0] = ((*abuf & 0x0f) << 4) | (*abuf & 0x0f); - amap[x * 64 + y + 1] = ((*abuf & 0xf0) >> 4) | (*abuf & 0xf0); + amap[x * 64 + y + 0] = abuf->lower | abuf->lower << 4; + amap[x * 64 + y + 1] = abuf->upper | abuf->upper << 4; ++abuf; } } diff --git a/src/noggit/texture_set.cpp b/src/noggit/texture_set.cpp index dd873c84..464d60ff 100755 --- a/src/noggit/texture_set.cpp +++ b/src/noggit/texture_set.cpp @@ -1133,9 +1133,12 @@ void TextureSet::alphas_to_big_alpha(uint8_t* dest) for (int k = static_cast(nTextures - 2); k >= 0; --k) { - uint8_t val = misc::rounded_255_int_div(*alpha(k, i) * a); + // uint8_t val = misc::rounded_255_int_div(*alpha(k, i) * a); + uint8_t* value_ptr = alpha(k, i); + uint8_t val = alpha_convertion_lookup[*value_ptr * a]; a -= val; - *alpha(k, i) = val; + // *alpha(k, i) = val; + *value_ptr = val; } } } @@ -1148,14 +1151,14 @@ void TextureSet::convertToBigAlpha() return; } - uint8_t tab[4096 * 3]; + std::array tab; apply_alpha_changes(); - alphas_to_big_alpha(tab); + alphas_to_big_alpha(tab.data()); for (size_t k = 0; k < nTextures - 1; k++) { - alphamaps[k]->setAlpha(tab + 4096 * k); + alphamaps[k]->setAlpha(tab.data() + 4096 * k); } } @@ -1639,3 +1642,5 @@ std::array TextureSet::lod_texture_map() return _doodadMapping; } + +std::array TextureSet::alpha_convertion_lookup = TextureSet::make_alpha_lookup_array(); \ No newline at end of file diff --git a/src/noggit/texture_set.hpp b/src/noggit/texture_set.hpp index edb68a9b..d1549700 100755 --- a/src/noggit/texture_set.hpp +++ b/src/noggit/texture_set.hpp @@ -166,5 +166,19 @@ private: bool _do_not_convert_alphamaps; + static constexpr std::array make_alpha_lookup_array() + { + std::array array{}; + + for (int i = 0; i < 256 * 256; ++i) + { + array[i] = i / 255 + (i % 255 <= 127 ? 0 : 1); + } + + return array; + } + + static std::array alpha_convertion_lookup; + Noggit::NoggitRenderContext _context; };