From e72a032a114c7710112534157abad8fa300c2f7d Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 19 Jun 2016 23:12:10 +0200 Subject: [PATCH] Fixed alpha channel issue with textures --- src/textures/pngtexture.cpp | 10 ++++++++-- src/textures/texture.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index 206797a34..408cf1e2f 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -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; diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 0030719cb..da5dd8ad7 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -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();