Fixed alpha channel issue with textures

This commit is contained in:
Magnus Norddahl 2016-06-19 23:12:10 +02:00
parent 38aba81dcc
commit e72a032a11
2 changed files with 9 additions and 3 deletions

View file

@ -724,8 +724,9 @@ void FPNGTexture::MakeTextureBgra ()
{
for (y = Height; y > 0; --y)
{
// output as premultiplied alpha
uint32_t alpha = in[1];
uint32_t gray = in[0];
uint32_t gray = (in[0] * alpha + 127) / 255;
*out++ = (alpha << 24) | (gray << 16) | (gray << 8) | gray;
in += pitch;
}
@ -740,7 +741,12 @@ void FPNGTexture::MakeTextureBgra ()
{
for (y = Height; y > 0; --y)
{
*out++ = (((uint32_t)in[3]) << 24) | (((uint32_t)in[0]) << 16) | (((uint32_t)in[1]) << 8) | ((uint32_t)in[2]);
// output as premultiplied alpha
uint32_t alpha = in[3];
uint32_t red = (in[0] * alpha + 127) / 255;
uint32_t green = (in[1] * alpha + 127) / 255;
uint32_t blue = (in[2] * alpha + 127) / 255;
*out++ = (alpha << 24) | (red << 16) | (green << 8) | blue;
in += pitch;
}
in -= backstep;

View file

@ -203,7 +203,7 @@ const uint32_t *FTexture::GetPixelsBgra()
PixelsBgra.resize(Width * Height);
for (int i = 0; i < Width * Height; i++)
{
PixelsBgra[i] = GPalette.BaseColors[indices[i]].d;
PixelsBgra[i] = 0xff000000 | GPalette.BaseColors[indices[i]].d;
}
}
return PixelsBgra.data();