adspartan: improve alphamap loading and conversion to big alpha format
This commit is contained in:
@@ -95,16 +95,26 @@ void Alphamap::readBigAlpha(BlizzardArchive::ClientFile *f)
|
|||||||
f->seekRelative(0x1000);
|
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)
|
void Alphamap::readNotCompressed(BlizzardArchive::ClientFile *f, bool do_not_fix_alpha_map)
|
||||||
{
|
{
|
||||||
char const* abuf = f->getPointer();
|
alpha_4_4 const* abuf = reinterpret_cast<alpha_4_4 const*>(f->getPointer());
|
||||||
|
|
||||||
for (std::size_t x(0); x < 64; ++x)
|
for (std::size_t x(0); x < 64; ++x)
|
||||||
{
|
{
|
||||||
for (std::size_t y(0); y < 64; y += 2)
|
for (std::size_t y(0); y < 64; y += 2)
|
||||||
{
|
{
|
||||||
amap[x * 64 + y + 0] = ((*abuf & 0x0f) << 4) | (*abuf & 0x0f);
|
amap[x * 64 + y + 0] = abuf->lower | abuf->lower << 4;
|
||||||
amap[x * 64 + y + 1] = ((*abuf & 0xf0) >> 4) | (*abuf & 0xf0);
|
amap[x * 64 + y + 1] = abuf->upper | abuf->upper << 4;
|
||||||
++abuf;
|
++abuf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1133,9 +1133,12 @@ void TextureSet::alphas_to_big_alpha(uint8_t* dest)
|
|||||||
|
|
||||||
for (int k = static_cast<int>(nTextures - 2); k >= 0; --k)
|
for (int k = static_cast<int>(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;
|
a -= val;
|
||||||
*alpha(k, i) = val;
|
// *alpha(k, i) = val;
|
||||||
|
*value_ptr = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1148,14 +1151,14 @@ void TextureSet::convertToBigAlpha()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t tab[4096 * 3];
|
std::array<std::uint8_t, 4096 * 3> tab;
|
||||||
|
|
||||||
apply_alpha_changes();
|
apply_alpha_changes();
|
||||||
alphas_to_big_alpha(tab);
|
alphas_to_big_alpha(tab.data());
|
||||||
|
|
||||||
for (size_t k = 0; k < nTextures - 1; k++)
|
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<std::uint16_t, 8> TextureSet::lod_texture_map()
|
|||||||
|
|
||||||
return _doodadMapping;
|
return _doodadMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::array<std::uint8_t, 256 * 256> TextureSet::alpha_convertion_lookup = TextureSet::make_alpha_lookup_array();
|
||||||
@@ -166,5 +166,19 @@ private:
|
|||||||
|
|
||||||
bool _do_not_convert_alphamaps;
|
bool _do_not_convert_alphamaps;
|
||||||
|
|
||||||
|
static constexpr std::array<std::uint8_t, 256 * 256> make_alpha_lookup_array()
|
||||||
|
{
|
||||||
|
std::array<std::uint8_t, 256 * 256> array{};
|
||||||
|
|
||||||
|
for (int i = 0; i < 256 * 256; ++i)
|
||||||
|
{
|
||||||
|
array[i] = i / 255 + (i % 255 <= 127 ? 0 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::array<std::uint8_t, 256 * 256> alpha_convertion_lookup;
|
||||||
|
|
||||||
Noggit::NoggitRenderContext _context;
|
Noggit::NoggitRenderContext _context;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user