summaryrefslogtreecommitdiff
path: root/src/blitter/32bpp_sse2.hpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-01-13 17:58:58 +0000
committerrubidium <rubidium@openttd.org>2014-01-13 17:58:58 +0000
commit6e34672c6ca636b38ed3711f3f2be444ae12bfdf (patch)
treecf1f9d787a3d1a3fbd222f96bd2e2cc2c26d69b6 /src/blitter/32bpp_sse2.hpp
parent76661f2c56e6542fe3023cf22814237a25a4a7bd (diff)
downloadopenttd-6e34672c6ca636b38ed3711f3f2be444ae12bfdf.tar.xz
(svn r26250) -Codechange: deduplicate darkening (e.g. shadow) code (MJP)
Diffstat (limited to 'src/blitter/32bpp_sse2.hpp')
-rw-r--r--src/blitter/32bpp_sse2.hpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/blitter/32bpp_sse2.hpp b/src/blitter/32bpp_sse2.hpp
index 98acb8cd1..386b5d3e3 100644
--- a/src/blitter/32bpp_sse2.hpp
+++ b/src/blitter/32bpp_sse2.hpp
@@ -81,6 +81,19 @@ typedef union ALIGN(16) um128i {
PACK_AB_WITHOUT_SATURATION(srcAB, srcABCD); \
}
+/* Darken 2 pixels.
+ * rgb = rgb * ((256/4) * 4 - (alpha/4)) / ((256/4) * 4)
+ */
+#define DARKEN_2() \
+ __m128i srcAB = _mm_unpacklo_epi8(srcABCD, _mm_setzero_si128()); \
+ __m128i dstAB = _mm_unpacklo_epi8(dstABCD, _mm_setzero_si128()); \
+ __m128i PUT_ALPHA_IN_FRONT_OF_RGB(srcAB, alphaAB); \
+ alphaAB = _mm_srli_epi16(alphaAB, 2); /* Reduce to 64 levels of shades so the max value fits in 16 bits. */ \
+ __m128i nom = _mm_sub_epi16(tr_nom_base, alphaAB); \
+ dstAB = _mm_mullo_epi16(dstAB, nom); \
+ dstAB = _mm_srli_epi16(dstAB, 8); \
+ dstAB = _mm_packus_epi16(dstAB, dstAB);
+
/** Base methods for 32bpp SSE blitters. */
class Blitter_32bppSSE_Base {
public: