Skip to content

Commit

Permalink
Make blendPixel function general
Browse files Browse the repository at this point in the history
Moves the blendPixel function from the SSSE3 file and use it more
generally, also adds a const_alpha version.

Change-Id: Ia29d1ab3879a845d5b65e0610b7836507e33c7ed
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
carewolf authored and Allan Sandfeld Jensen committed Sep 9, 2016
1 parent fe82f50 commit 806b45e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
16 changes: 16 additions & 0 deletions src/gui/painting/qdrawhelper_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,22 @@ static Q_ALWAYS_INLINE uint BYTE_MUL(uint x, uint a) {
}
#endif

static Q_ALWAYS_INLINE void blend_pixel(quint32 &dst, const quint32 src)
{
if (src >= 0xff000000)
dst = src;
else if (src != 0)
dst = src + BYTE_MUL(dst, qAlpha(~src));
}

static Q_ALWAYS_INLINE void blend_pixel(quint32 &dst, const quint32 src, const int const_alpha)
{
if (src != 0) {
const quint32 s = BYTE_MUL(src, const_alpha);
dst = s + BYTE_MUL(dst, qAlpha(~s));
}
}

#if defined(__SSE2__)
static Q_ALWAYS_INLINE uint interpolate_4_pixels_sse2(__m128i vt, __m128i vb, uint distx, uint disty)
{
Expand Down
9 changes: 0 additions & 9 deletions src/gui/painting/qdrawhelper_ssse3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@

QT_BEGIN_NAMESPACE

inline static void blend_pixel(quint32 &dst, const quint32 src)
{
if (src >= 0xff000000)
dst = src;
else if (src != 0)
dst = src + BYTE_MUL(dst, qAlpha(~src));
}


/* The instruction palignr uses direct arguments, so we have to generate the code fo the different
shift (4, 8, 12). Checking the alignment inside the loop is unfortunatelly way too slow.
*/
Expand Down
24 changes: 4 additions & 20 deletions src/gui/painting/qdrawingprimitive_sse2_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,15 @@ QT_BEGIN_NAMESPACE
\
/* First, get dst aligned. */ \
ALIGNMENT_PROLOGUE_16BYTES(dst, x, length) { \
uint s = src[x]; \
if (s >= 0xff000000) \
dst[x] = s; \
else if (s != 0) \
dst[x] = s + BYTE_MUL(dst[x], qAlpha(~s)); \
blend_pixel(dst[x], src[x]); \
} \
\
for (; x < length-3; x += 4) { \
const __m128i srcVector = _mm_loadu_si128((const __m128i *)&src[x]); \
BLEND_SOURCE_OVER_ARGB32_SSE2_helper(dst, srcVector, nullVector, half, one, colorMask, alphaMask) \
} \
for (; x < length; ++x) { \
uint s = src[x]; \
if (s >= 0xff000000) \
dst[x] = s; \
else if (s != 0) \
dst[x] = s + BYTE_MUL(dst[x], qAlpha(~s)); \
blend_pixel(dst[x], src[x]); \
} \
}

Expand All @@ -207,11 +199,7 @@ QT_BEGIN_NAMESPACE
int x = 0; \
\
ALIGNMENT_PROLOGUE_16BYTES(dst, x, length) { \
quint32 s = src[x]; \
if (s != 0) { \
s = BYTE_MUL(s, const_alpha); \
dst[x] = s + BYTE_MUL(dst[x], qAlpha(~s)); \
} \
blend_pixel(dst[x], src[x], const_alpha); \
} \
\
for (; x < length-3; x += 4) { \
Expand All @@ -232,11 +220,7 @@ QT_BEGIN_NAMESPACE
} \
} \
for (; x < length; ++x) { \
quint32 s = src[x]; \
if (s != 0) { \
s = BYTE_MUL(s, const_alpha); \
dst[x] = s + BYTE_MUL(dst[x], qAlpha(~s)); \
} \
blend_pixel(dst[x], src[x], const_alpha); \
} \
}

Expand Down

0 comments on commit 806b45e

Please sign in to comment.