diff --git a/src/r_draw_rgba.cpp b/src/r_draw_rgba.cpp index 528c3c986f..fa632cb5d3 100644 --- a/src/r_draw_rgba.cpp +++ b/src/r_draw_rgba.cpp @@ -1511,8 +1511,6 @@ public: { // 64x64 is the most common case by far, so special case it. - uint32_t *palette = (uint32_t*)GPalette.BaseColors; - int sse_count = count / 4; count -= sse_count * 4; @@ -1545,7 +1543,7 @@ public: // Lookup pixel from flat texture tile, // re-index using light/colormap. - __m128i fg = _mm_set_epi32(palette[p3], palette[p2], palette[p1], palette[p0]); + __m128i fg = _mm_set_epi32(p3, p2, p1, p0); SSE_SHADE_SIMPLE(fg); _mm_storeu_si128((__m128i*)dest, fg); @@ -1582,7 +1580,7 @@ public: // Lookup pixel from flat texture tile, // re-index using light/colormap. - __m128i fg = _mm_set_epi32(palette[p3], palette[p2], palette[p1], palette[p0]); + __m128i fg = _mm_set_epi32(p3, p2, p1, p0); SSE_SHADE(fg, shade_constants); _mm_storeu_si128((__m128i*)dest, fg); diff --git a/src/r_main.h b/src/r_main.h index 6d0e2a21f2..d71d44fe1f 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -217,6 +217,27 @@ FORCEINLINE uint32_t shade_bgra(uint32_t color, uint32_t light, const ShadeConst return 0xff000000 | (red << 16) | (green << 8) | blue; } +FORCEINLINE uint32_t alpha_blend(uint32_t fg, uint32_t bg) +{ + uint32_t fg_alpha = (fg >> 24) & 0xff; + uint32_t fg_red = (fg >> 16) & 0xff; + uint32_t fg_green = (fg >> 8) & 0xff; + uint32_t fg_blue = fg & 0xff; + + uint32_t alpha = fg_alpha + (fg_alpha >> 7); // 255 -> 256 + uint32_t inv_alpha = 256 - alpha; + + uint32_t bg_red = (bg >> 16) & 0xff; + uint32_t bg_green = (bg >> 8) & 0xff; + uint32_t bg_blue = bg & 0xff; + + uint32_t red = ((fg_red * alpha) + (bg_red * inv_alpha)) / 256; + uint32_t green = ((fg_green * alpha) + (bg_green * inv_alpha)) / 256; + uint32_t blue = ((fg_blue * alpha) + (bg_blue * inv_alpha)) / 256; + + return 0xff000000 | (red << 16) | (green << 8) | blue; +} + // Calculate constants for a simple shade #define SSE_SHADE_SIMPLE_INIT(light) \ __m128i mlight_hi = _mm_set_epi16(256, light, light, light, 256, light, light, light); \