| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include "src/dsp/dsp.h" |
| 15 |
|
| 16 |
#if defined(WEBP_USE_SSE41) |
| 17 |
|
| 18 |
#include <smmintrin.h> |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
static int ExtractAlpha_SSE41(const uint8_t* WEBP_RESTRICT argb, |
| 23 |
int argb_stride, int width, int height, |
| 24 |
uint8_t* WEBP_RESTRICT alpha, int alpha_stride) { |
| 25 |
|
| 26 |
|
| 27 |
uint32_t alpha_and = 0xff; |
| 28 |
int i, j; |
| 29 |
const __m128i all_0xff = _mm_set1_epi32(~0); |
| 30 |
__m128i all_alphas = all_0xff; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
const int limit = (width - 1) & ~15; |
| 36 |
const __m128i kCstAlpha0 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, |
| 37 |
-1, -1, -1, -1, 12, 8, 4, 0); |
| 38 |
const __m128i kCstAlpha1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, |
| 39 |
12, 8, 4, 0, -1, -1, -1, -1); |
| 40 |
const __m128i kCstAlpha2 = _mm_set_epi8(-1, -1, -1, -1, 12, 8, 4, 0, |
| 41 |
-1, -1, -1, -1, -1, -1, -1, -1); |
| 42 |
const __m128i kCstAlpha3 = _mm_set_epi8(12, 8, 4, 0, -1, -1, -1, -1, |
| 43 |
-1, -1, -1, -1, -1, -1, -1, -1); |
| 44 |
for (j = 0; j < height; ++j) { |
| 45 |
const __m128i* src = (const __m128i*)argb; |
| 46 |
for (i = 0; i < limit; i += 16) { |
| 47 |
|
| 48 |
const __m128i a0 = _mm_loadu_si128(src + 0); |
| 49 |
const __m128i a1 = _mm_loadu_si128(src + 1); |
| 50 |
const __m128i a2 = _mm_loadu_si128(src + 2); |
| 51 |
const __m128i a3 = _mm_loadu_si128(src + 3); |
| 52 |
const __m128i b0 = _mm_shuffle_epi8(a0, kCstAlpha0); |
| 53 |
const __m128i b1 = _mm_shuffle_epi8(a1, kCstAlpha1); |
| 54 |
const __m128i b2 = _mm_shuffle_epi8(a2, kCstAlpha2); |
| 55 |
const __m128i b3 = _mm_shuffle_epi8(a3, kCstAlpha3); |
| 56 |
const __m128i c0 = _mm_or_si128(b0, b1); |
| 57 |
const __m128i c1 = _mm_or_si128(b2, b3); |
| 58 |
const __m128i d0 = _mm_or_si128(c0, c1); |
| 59 |
|
| 60 |
_mm_storeu_si128((__m128i*)&alpha[i], d0); |
| 61 |
|
| 62 |
all_alphas = _mm_and_si128(all_alphas, d0); |
| 63 |
src += 4; |
| 64 |
} |
| 65 |
for (; i < width; ++i) { |
| 66 |
const uint32_t alpha_value = argb[4 * i]; |
| 67 |
alpha[i] = alpha_value; |
| 68 |
alpha_and &= alpha_value; |
| 69 |
} |
| 70 |
argb += argb_stride; |
| 71 |
alpha += alpha_stride; |
| 72 |
} |
| 73 |
|
| 74 |
alpha_and |= 0xff00u; |
| 75 |
alpha_and &= _mm_movemask_epi8(_mm_cmpeq_epi8(all_alphas, all_0xff)); |
| 76 |
return (alpha_and == 0xffffu); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
extern void WebPInitAlphaProcessingSSE41(void); |
| 83 |
|
| 84 |
WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessingSSE41(void) { |
| 85 |
WebPExtractAlpha = ExtractAlpha_SSE41; |
| 86 |
} |
| 87 |
|
| 88 |
#else |
| 89 |
|
| 90 |
WEBP_DSP_INIT_STUB(WebPInitAlphaProcessingSSE41) |
| 91 |
|
| 92 |
#endif |