mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-17 06:19:54 +02:00
10% faster table-less SSE2/NEON version of YUV->RGB conversion
* Precision is slightly different * also implemented in SSE2 the missing WebPUpsamplers for MODE_ARGB, MODE_Argb, MODE_RGB565, etc. * removing yuv_tables_sse2.h saved ~8k of binary size * the mips32/mips_dsp_r2 code is disabled for now, since it has drifted away * the NEON code is somewhat tricky Change-Id: Icf205faa62cf46c2825d79f3af6725dc1ec7f052
This commit is contained in:
committed by
James Zern
parent
bd91af200a
commit
ac761a3738
@ -18,170 +18,183 @@
|
||||
#include <emmintrin.h>
|
||||
#include <string.h> // for memcpy
|
||||
|
||||
typedef union { // handy struct for converting SSE2 registers
|
||||
int32_t i32[4];
|
||||
uint8_t u8[16];
|
||||
__m128i m;
|
||||
} VP8kCstSSE2;
|
||||
|
||||
#if defined(WEBP_YUV_USE_SSE2_TABLES)
|
||||
|
||||
#include "./yuv_tables_sse2.h"
|
||||
|
||||
WEBP_TSAN_IGNORE_FUNCTION void VP8YUVInitSSE2(void) {}
|
||||
|
||||
#else
|
||||
|
||||
static int done_sse2 = 0;
|
||||
static VP8kCstSSE2 VP8kUtoRGBA[256], VP8kVtoRGBA[256], VP8kYtoRGBA[256];
|
||||
|
||||
WEBP_TSAN_IGNORE_FUNCTION void VP8YUVInitSSE2(void) {
|
||||
if (!done_sse2) {
|
||||
int i;
|
||||
for (i = 0; i < 256; ++i) {
|
||||
VP8kYtoRGBA[i].i32[0] =
|
||||
VP8kYtoRGBA[i].i32[1] =
|
||||
VP8kYtoRGBA[i].i32[2] = (i - 16) * kYScale + YUV_HALF2;
|
||||
VP8kYtoRGBA[i].i32[3] = 0xff << YUV_FIX2;
|
||||
|
||||
VP8kUtoRGBA[i].i32[0] = 0;
|
||||
VP8kUtoRGBA[i].i32[1] = -kUToG * (i - 128);
|
||||
VP8kUtoRGBA[i].i32[2] = kUToB * (i - 128);
|
||||
VP8kUtoRGBA[i].i32[3] = 0;
|
||||
|
||||
VP8kVtoRGBA[i].i32[0] = kVToR * (i - 128);
|
||||
VP8kVtoRGBA[i].i32[1] = -kVToG * (i - 128);
|
||||
VP8kVtoRGBA[i].i32[2] = 0;
|
||||
VP8kVtoRGBA[i].i32[3] = 0;
|
||||
}
|
||||
done_sse2 = 1;
|
||||
|
||||
#if 0 // code used to generate 'yuv_tables_sse2.h'
|
||||
printf("static const VP8kCstSSE2 VP8kYtoRGBA[256] = {\n");
|
||||
for (i = 0; i < 256; ++i) {
|
||||
printf(" {{0x%.8x, 0x%.8x, 0x%.8x, 0x%.8x}},\n",
|
||||
VP8kYtoRGBA[i].i32[0], VP8kYtoRGBA[i].i32[1],
|
||||
VP8kYtoRGBA[i].i32[2], VP8kYtoRGBA[i].i32[3]);
|
||||
}
|
||||
printf("};\n\n");
|
||||
printf("static const VP8kCstSSE2 VP8kUtoRGBA[256] = {\n");
|
||||
for (i = 0; i < 256; ++i) {
|
||||
printf(" {{0, 0x%.8x, 0x%.8x, 0}},\n",
|
||||
VP8kUtoRGBA[i].i32[1], VP8kUtoRGBA[i].i32[2]);
|
||||
}
|
||||
printf("};\n\n");
|
||||
printf("static VP8kCstSSE2 VP8kVtoRGBA[256] = {\n");
|
||||
for (i = 0; i < 256; ++i) {
|
||||
printf(" {{0x%.8x, 0x%.8x, 0, 0}},\n",
|
||||
VP8kVtoRGBA[i].i32[0], VP8kVtoRGBA[i].i32[1]);
|
||||
}
|
||||
printf("};\n\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif // WEBP_YUV_USE_SSE2_TABLES
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static WEBP_INLINE __m128i LoadUVPart(int u, int v) {
|
||||
const __m128i u_part = _mm_loadu_si128(&VP8kUtoRGBA[u].m);
|
||||
const __m128i v_part = _mm_loadu_si128(&VP8kVtoRGBA[v].m);
|
||||
const __m128i uv_part = _mm_add_epi32(u_part, v_part);
|
||||
return uv_part;
|
||||
}
|
||||
|
||||
static WEBP_INLINE __m128i GetRGBA32bWithUV(int y, const __m128i uv_part) {
|
||||
const __m128i y_part = _mm_loadu_si128(&VP8kYtoRGBA[y].m);
|
||||
const __m128i rgba1 = _mm_add_epi32(y_part, uv_part);
|
||||
const __m128i rgba2 = _mm_srai_epi32(rgba1, YUV_FIX2);
|
||||
return rgba2;
|
||||
}
|
||||
|
||||
static WEBP_INLINE __m128i GetRGBA32b(int y, int u, int v) {
|
||||
const __m128i uv_part = LoadUVPart(u, v);
|
||||
return GetRGBA32bWithUV(y, uv_part);
|
||||
}
|
||||
|
||||
static WEBP_INLINE void YuvToRgbSSE2(uint8_t y, uint8_t u, uint8_t v,
|
||||
uint8_t* const rgb) {
|
||||
const __m128i tmp0 = GetRGBA32b(y, u, v);
|
||||
const __m128i tmp1 = _mm_packs_epi32(tmp0, tmp0);
|
||||
const __m128i tmp2 = _mm_packus_epi16(tmp1, tmp1);
|
||||
// Note: we store 8 bytes at a time, not 3 bytes! -> memory stomp
|
||||
_mm_storel_epi64((__m128i*)rgb, tmp2);
|
||||
}
|
||||
|
||||
static WEBP_INLINE void YuvToBgrSSE2(uint8_t y, uint8_t u, uint8_t v,
|
||||
uint8_t* const bgr) {
|
||||
const __m128i tmp0 = GetRGBA32b(y, u, v);
|
||||
const __m128i tmp1 = _mm_shuffle_epi32(tmp0, _MM_SHUFFLE(3, 0, 1, 2));
|
||||
const __m128i tmp2 = _mm_packs_epi32(tmp1, tmp1);
|
||||
const __m128i tmp3 = _mm_packus_epi16(tmp2, tmp2);
|
||||
// Note: we store 8 bytes at a time, not 3 bytes! -> memory stomp
|
||||
_mm_storel_epi64((__m128i*)bgr, tmp3);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Convert spans of 32 pixels to various RGB formats for the fancy upsampler.
|
||||
|
||||
// These constants are 14b fixed-point version of ITU-R BT.601 constants.
|
||||
// R = (19077 * y + 26149 * v - 14234) >> 6
|
||||
// G = (19077 * y - 6419 * u - 13320 * v + 8708) >> 6
|
||||
// B = (19077 * y + 33050 * u - 17685) >> 6
|
||||
static void ConvertYUV444ToRGB(const __m128i* const Y0,
|
||||
const __m128i* const U0,
|
||||
const __m128i* const V0,
|
||||
__m128i* const R,
|
||||
__m128i* const G,
|
||||
__m128i* const B) {
|
||||
const __m128i k19077 = _mm_set1_epi16(19077);
|
||||
const __m128i k26149 = _mm_set1_epi16(26149);
|
||||
const __m128i k14234 = _mm_set1_epi16(14234);
|
||||
const __m128i k33050 = _mm_set1_epi16(33050);
|
||||
const __m128i k17685 = _mm_set1_epi16(17685);
|
||||
const __m128i k6419 = _mm_set1_epi16(6419);
|
||||
const __m128i k13320 = _mm_set1_epi16(13320);
|
||||
const __m128i k8708 = _mm_set1_epi16(8708);
|
||||
|
||||
const __m128i Y1 = _mm_mulhi_epu16(*Y0, k19077);
|
||||
|
||||
const __m128i R0 = _mm_mulhi_epu16(*V0, k26149);
|
||||
const __m128i R1 = _mm_sub_epi16(Y1, k14234);
|
||||
const __m128i R2 = _mm_add_epi16(R1, R0);
|
||||
|
||||
const __m128i G0 = _mm_mulhi_epu16(*U0, k6419);
|
||||
const __m128i G1 = _mm_mulhi_epu16(*V0, k13320);
|
||||
const __m128i G2 = _mm_add_epi16(Y1, k8708);
|
||||
const __m128i G3 = _mm_add_epi16(G0, G1);
|
||||
const __m128i G4 = _mm_sub_epi16(G2, G3);
|
||||
|
||||
// be careful with the saturated *unsigned* arithmetic here!
|
||||
const __m128i B0 = _mm_mulhi_epu16(*U0, k33050);
|
||||
const __m128i B1 = _mm_adds_epu16(B0, Y1);
|
||||
const __m128i B2 = _mm_subs_epu16(B1, k17685);
|
||||
|
||||
// use logical shift for B2, which can be larger than 32767
|
||||
*R = _mm_srai_epi16(R2, 6); // range: [-14234, 30815]
|
||||
*G = _mm_srai_epi16(G4, 6); // range: [-10953, 27710]
|
||||
*B = _mm_srli_epi16(B2, 6); // range: [0, 34238]
|
||||
}
|
||||
|
||||
// Load the bytes into the *upper* part of 16b words. That's "<< 8", basically.
|
||||
static WEBP_INLINE __m128i Load_HI_16(const uint8_t* src) {
|
||||
const __m128i zero = _mm_setzero_si128();
|
||||
return _mm_unpacklo_epi8(zero, _mm_loadl_epi64((const __m128i*)src));
|
||||
}
|
||||
|
||||
// Load and replicate the U/V samples
|
||||
static WEBP_INLINE __m128i Load_UV_HI_8(const uint8_t* src) {
|
||||
const __m128i zero = _mm_setzero_si128();
|
||||
const __m128i tmp0 = _mm_cvtsi32_si128(*(const uint32_t*)src);
|
||||
const __m128i tmp1 = _mm_unpacklo_epi8(zero, tmp0);
|
||||
return _mm_unpacklo_epi16(tmp1, tmp1); // replicate samples
|
||||
}
|
||||
|
||||
// Convert 32 samples of YUV444 to R/G/B
|
||||
static void YUV444ToRGB(const uint8_t* const y,
|
||||
const uint8_t* const u,
|
||||
const uint8_t* const v,
|
||||
__m128i* const R, __m128i* const G, __m128i* const B) {
|
||||
const __m128i Y0 = Load_HI_16(y), U0 = Load_HI_16(u), V0 = Load_HI_16(v);
|
||||
ConvertYUV444ToRGB(&Y0, &U0, &V0, R, G, B);
|
||||
}
|
||||
|
||||
// Convert 32 samples of YUV420 to R/G/B
|
||||
static void YUV420ToRGB(const uint8_t* const y,
|
||||
const uint8_t* const u,
|
||||
const uint8_t* const v,
|
||||
__m128i* const R, __m128i* const G, __m128i* const B) {
|
||||
const __m128i Y0 = Load_HI_16(y), U0 = Load_UV_HI_8(u), V0 = Load_UV_HI_8(v);
|
||||
ConvertYUV444ToRGB(&Y0, &U0, &V0, R, G, B);
|
||||
}
|
||||
|
||||
// Pack R/G/B/A results into 32b output.
|
||||
static WEBP_INLINE void PackAndStore4(const __m128i* const R,
|
||||
const __m128i* const G,
|
||||
const __m128i* const B,
|
||||
const __m128i* const A,
|
||||
uint8_t* const dst) {
|
||||
const __m128i rb = _mm_packus_epi16(*R, *B);
|
||||
const __m128i ga = _mm_packus_epi16(*G, *A);
|
||||
const __m128i rg = _mm_unpacklo_epi8(rb, ga);
|
||||
const __m128i ba = _mm_unpackhi_epi8(rb, ga);
|
||||
const __m128i RGBA_lo = _mm_unpacklo_epi16(rg, ba);
|
||||
const __m128i RGBA_hi = _mm_unpackhi_epi16(rg, ba);
|
||||
_mm_storeu_si128((__m128i*)(dst + 0), RGBA_lo);
|
||||
_mm_storeu_si128((__m128i*)(dst + 16), RGBA_hi);
|
||||
}
|
||||
|
||||
// Pack R/G/B results into 24b output.
|
||||
static WEBP_INLINE void PackAndStore3(const __m128i* const R,
|
||||
const __m128i* const G,
|
||||
const __m128i* const B,
|
||||
uint8_t* const dst) {
|
||||
const __m128i tmp0 = _mm_packus_epi16(*R, *R);
|
||||
const __m128i tmp1 = _mm_packus_epi16(*G, *G);
|
||||
const __m128i tmp2 = _mm_packus_epi16(*B, *B);
|
||||
_mm_storel_epi64((__m128i*)(dst + 0 * 32), tmp0);
|
||||
_mm_storel_epi64((__m128i*)(dst + 1 * 32), tmp1);
|
||||
_mm_storel_epi64((__m128i*)(dst + 2 * 32), tmp2);
|
||||
}
|
||||
|
||||
// Converts 32 samples in src[3][32] to interleaved RGB24 in dst[]
|
||||
static WEBP_INLINE void PlanarTo24b(const uint8_t* src, uint8_t* dst) {
|
||||
#if 1
|
||||
// This code is faster than the version below (left there for reference).
|
||||
// It's also endian-dependent but we're only targeting x86.
|
||||
const uint8_t* const end = src + 32;
|
||||
for (; src < end; src += 4, dst += 12) {
|
||||
const uint32_t A = (src[0 + 0 * 32] << 0) | (src[0 + 1 * 32] << 8)
|
||||
| (src[0 + 2 * 32] << 16) | (src[1 + 0 * 32] << 24);
|
||||
const uint32_t B = (src[1 + 1 * 32] << 0) | (src[1 + 2 * 32] << 8)
|
||||
| (src[2 + 0 * 32] << 16) | (src[2 + 1 * 32] << 24);
|
||||
const uint32_t C = (src[2 + 2 * 32] << 0) | (src[3 + 0 * 32] << 8)
|
||||
| (src[3 + 1 * 32] << 16) | (src[3 + 2 * 32] << 24);
|
||||
*(uint32_t*)(dst + 0) = A;
|
||||
*(uint32_t*)(dst + 4) = B;
|
||||
*(uint32_t*)(dst + 8) = C;
|
||||
}
|
||||
#else
|
||||
int n;
|
||||
for (n = 0; n < 32; ++n) {
|
||||
*dst++ = src[0 * 32 + n];
|
||||
*dst++ = src[1 * 32 + n];
|
||||
*dst++ = src[2 * 32 + n];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void VP8YuvToRgba32(const uint8_t* y, const uint8_t* u, const uint8_t* v,
|
||||
uint8_t* dst) {
|
||||
const __m128i kAlpha = _mm_set1_epi16(255);
|
||||
int n;
|
||||
for (n = 0; n < 32; n += 4) {
|
||||
const __m128i tmp0_1 = GetRGBA32b(y[n + 0], u[n + 0], v[n + 0]);
|
||||
const __m128i tmp0_2 = GetRGBA32b(y[n + 1], u[n + 1], v[n + 1]);
|
||||
const __m128i tmp0_3 = GetRGBA32b(y[n + 2], u[n + 2], v[n + 2]);
|
||||
const __m128i tmp0_4 = GetRGBA32b(y[n + 3], u[n + 3], v[n + 3]);
|
||||
const __m128i tmp1_1 = _mm_packs_epi32(tmp0_1, tmp0_2);
|
||||
const __m128i tmp1_2 = _mm_packs_epi32(tmp0_3, tmp0_4);
|
||||
const __m128i tmp2 = _mm_packus_epi16(tmp1_1, tmp1_2);
|
||||
_mm_storeu_si128((__m128i*)dst, tmp2);
|
||||
dst += 4 * 4;
|
||||
for (n = 0; n < 32; n += 8, dst += 32) {
|
||||
__m128i R, G, B;
|
||||
YUV444ToRGB(y + n, u + n, v + n, &R, &G, &B);
|
||||
PackAndStore4(&R, &G, &B, &kAlpha, dst);
|
||||
}
|
||||
}
|
||||
|
||||
void VP8YuvToBgra32(const uint8_t* y, const uint8_t* u, const uint8_t* v,
|
||||
uint8_t* dst) {
|
||||
const __m128i kAlpha = _mm_set1_epi16(255);
|
||||
int n;
|
||||
for (n = 0; n < 32; n += 2) {
|
||||
const __m128i tmp0_1 = GetRGBA32b(y[n + 0], u[n + 0], v[n + 0]);
|
||||
const __m128i tmp0_2 = GetRGBA32b(y[n + 1], u[n + 1], v[n + 1]);
|
||||
const __m128i tmp1_1 = _mm_shuffle_epi32(tmp0_1, _MM_SHUFFLE(3, 0, 1, 2));
|
||||
const __m128i tmp1_2 = _mm_shuffle_epi32(tmp0_2, _MM_SHUFFLE(3, 0, 1, 2));
|
||||
const __m128i tmp2_1 = _mm_packs_epi32(tmp1_1, tmp1_2);
|
||||
const __m128i tmp3 = _mm_packus_epi16(tmp2_1, tmp2_1);
|
||||
_mm_storel_epi64((__m128i*)dst, tmp3);
|
||||
dst += 4 * 2;
|
||||
for (n = 0; n < 32; n += 8, dst += 32) {
|
||||
__m128i R, G, B;
|
||||
YUV444ToRGB(y + n, u + n, v + n, &R, &G, &B);
|
||||
PackAndStore4(&B, &G, &R, &kAlpha, dst);
|
||||
}
|
||||
}
|
||||
|
||||
void VP8YuvToRgb32(const uint8_t* y, const uint8_t* u, const uint8_t* v,
|
||||
uint8_t* dst) {
|
||||
int n;
|
||||
uint8_t tmp0[2 * 3 + 5 + 15];
|
||||
uint8_t* const tmp = (uint8_t*)((uintptr_t)(tmp0 + 15) & ~15); // align
|
||||
for (n = 0; n < 30; ++n) { // we directly stomp the *dst memory
|
||||
YuvToRgbSSE2(y[n], u[n], v[n], dst + n * 3);
|
||||
uint8_t tmp[32 * 3];
|
||||
for (n = 0; n < 32; n += 8) {
|
||||
__m128i R, G, B;
|
||||
YUV444ToRGB(y + n, u + n, v + n, &R, &G, &B);
|
||||
PackAndStore3(&R, &G, &B, tmp + n);
|
||||
}
|
||||
// Last two pixels are special: we write in a tmp buffer before sending
|
||||
// to dst.
|
||||
YuvToRgbSSE2(y[n + 0], u[n + 0], v[n + 0], tmp + 0);
|
||||
YuvToRgbSSE2(y[n + 1], u[n + 1], v[n + 1], tmp + 3);
|
||||
memcpy(dst + n * 3, tmp, 2 * 3);
|
||||
PlanarTo24b(tmp, dst);
|
||||
}
|
||||
|
||||
void VP8YuvToBgr32(const uint8_t* y, const uint8_t* u, const uint8_t* v,
|
||||
uint8_t* dst) {
|
||||
int n;
|
||||
uint8_t tmp0[2 * 3 + 5 + 15];
|
||||
uint8_t* const tmp = (uint8_t*)((uintptr_t)(tmp0 + 15) & ~15); // align
|
||||
for (n = 0; n < 30; ++n) {
|
||||
YuvToBgrSSE2(y[n], u[n], v[n], dst + n * 3);
|
||||
uint8_t tmp[32 * 3];
|
||||
for (n = 0; n < 32; n += 8) {
|
||||
__m128i R, G, B;
|
||||
YUV444ToRGB(y + n, u + n, v + n, &R, &G, &B);
|
||||
PackAndStore3(&B, &G, &R, tmp + n);
|
||||
}
|
||||
YuvToBgrSSE2(y[n + 0], u[n + 0], v[n + 0], tmp + 0);
|
||||
YuvToBgrSSE2(y[n + 1], u[n + 1], v[n + 1], tmp + 3);
|
||||
memcpy(dst + n * 3, tmp, 2 * 3);
|
||||
PlanarTo24b(tmp, dst);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -189,110 +202,121 @@ void VP8YuvToBgr32(const uint8_t* y, const uint8_t* u, const uint8_t* v,
|
||||
|
||||
static void YuvToRgbaRow(const uint8_t* y, const uint8_t* u, const uint8_t* v,
|
||||
uint8_t* dst, int len) {
|
||||
const __m128i kAlpha = _mm_set1_epi16(255);
|
||||
int n;
|
||||
for (n = 0; n + 4 <= len; n += 4) {
|
||||
const __m128i uv_0 = LoadUVPart(u[0], v[0]);
|
||||
const __m128i uv_1 = LoadUVPart(u[1], v[1]);
|
||||
const __m128i tmp0_1 = GetRGBA32bWithUV(y[0], uv_0);
|
||||
const __m128i tmp0_2 = GetRGBA32bWithUV(y[1], uv_0);
|
||||
const __m128i tmp0_3 = GetRGBA32bWithUV(y[2], uv_1);
|
||||
const __m128i tmp0_4 = GetRGBA32bWithUV(y[3], uv_1);
|
||||
const __m128i tmp1_1 = _mm_packs_epi32(tmp0_1, tmp0_2);
|
||||
const __m128i tmp1_2 = _mm_packs_epi32(tmp0_3, tmp0_4);
|
||||
const __m128i tmp2 = _mm_packus_epi16(tmp1_1, tmp1_2);
|
||||
_mm_storeu_si128((__m128i*)dst, tmp2);
|
||||
dst += 4 * 4;
|
||||
y += 4;
|
||||
u += 2;
|
||||
v += 2;
|
||||
for (n = 0; n + 8 <= len; n += 8, dst += 32) {
|
||||
__m128i R, G, B;
|
||||
YUV420ToRGB(y, u, v, &R, &G, &B);
|
||||
PackAndStore4(&R, &G, &B, &kAlpha, dst);
|
||||
y += 8;
|
||||
u += 4;
|
||||
v += 4;
|
||||
}
|
||||
// Finish off
|
||||
while (n < len) {
|
||||
for (; n < len; ++n) { // Finish off
|
||||
VP8YuvToRgba(y[0], u[0], v[0], dst);
|
||||
dst += 4;
|
||||
++y;
|
||||
y += 1;
|
||||
u += (n & 1);
|
||||
v += (n & 1);
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
static void YuvToBgraRow(const uint8_t* y, const uint8_t* u, const uint8_t* v,
|
||||
uint8_t* dst, int len) {
|
||||
const __m128i kAlpha = _mm_set1_epi16(255);
|
||||
int n;
|
||||
for (n = 0; n + 2 <= len; n += 2) {
|
||||
const __m128i uv_0 = LoadUVPart(u[0], v[0]);
|
||||
const __m128i tmp0_1 = GetRGBA32bWithUV(y[0], uv_0);
|
||||
const __m128i tmp0_2 = GetRGBA32bWithUV(y[1], uv_0);
|
||||
const __m128i tmp1_1 = _mm_shuffle_epi32(tmp0_1, _MM_SHUFFLE(3, 0, 1, 2));
|
||||
const __m128i tmp1_2 = _mm_shuffle_epi32(tmp0_2, _MM_SHUFFLE(3, 0, 1, 2));
|
||||
const __m128i tmp2_1 = _mm_packs_epi32(tmp1_1, tmp1_2);
|
||||
const __m128i tmp3 = _mm_packus_epi16(tmp2_1, tmp2_1);
|
||||
_mm_storel_epi64((__m128i*)dst, tmp3);
|
||||
dst += 4 * 2;
|
||||
y += 2;
|
||||
++u;
|
||||
++v;
|
||||
for (n = 0; n + 8 <= len; n += 8, dst += 32) {
|
||||
__m128i R, G, B;
|
||||
YUV420ToRGB(y, u, v, &R, &G, &B);
|
||||
PackAndStore4(&B, &G, &R, &kAlpha, dst);
|
||||
y += 8;
|
||||
u += 4;
|
||||
v += 4;
|
||||
}
|
||||
// Finish off
|
||||
if (len & 1) {
|
||||
for (; n < len; ++n) { // Finish off
|
||||
VP8YuvToBgra(y[0], u[0], v[0], dst);
|
||||
dst += 4;
|
||||
y += 1;
|
||||
u += (n & 1);
|
||||
v += (n & 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void YuvToArgbRow(const uint8_t* y, const uint8_t* u, const uint8_t* v,
|
||||
uint8_t* dst, int len) {
|
||||
const __m128i kAlpha = _mm_set1_epi16(255);
|
||||
int n;
|
||||
for (n = 0; n + 2 <= len; n += 2) {
|
||||
const __m128i uv_0 = LoadUVPart(u[0], v[0]);
|
||||
const __m128i tmp0_1 = GetRGBA32bWithUV(y[0], uv_0);
|
||||
const __m128i tmp0_2 = GetRGBA32bWithUV(y[1], uv_0);
|
||||
const __m128i tmp1_1 = _mm_shuffle_epi32(tmp0_1, _MM_SHUFFLE(2, 1, 0, 3));
|
||||
const __m128i tmp1_2 = _mm_shuffle_epi32(tmp0_2, _MM_SHUFFLE(2, 1, 0, 3));
|
||||
const __m128i tmp2_1 = _mm_packs_epi32(tmp1_1, tmp1_2);
|
||||
const __m128i tmp3 = _mm_packus_epi16(tmp2_1, tmp2_1);
|
||||
_mm_storel_epi64((__m128i*)dst, tmp3);
|
||||
dst += 4 * 2;
|
||||
y += 2;
|
||||
++u;
|
||||
++v;
|
||||
for (n = 0; n + 8 <= len; n += 8, dst += 32) {
|
||||
__m128i R, G, B;
|
||||
YUV420ToRGB(y, u, v, &R, &G, &B);
|
||||
PackAndStore4(&kAlpha, &R, &G, &B, dst);
|
||||
y += 8;
|
||||
u += 4;
|
||||
v += 4;
|
||||
}
|
||||
// Finish off
|
||||
if (len & 1) {
|
||||
for (; n < len; ++n) { // Finish off
|
||||
VP8YuvToArgb(y[0], u[0], v[0], dst);
|
||||
dst += 4;
|
||||
y += 1;
|
||||
u += (n & 1);
|
||||
v += (n & 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void YuvToRgbRow(const uint8_t* y, const uint8_t* u, const uint8_t* v,
|
||||
uint8_t* dst, int len) {
|
||||
int n;
|
||||
for (n = 0; n + 2 < len; ++n) { // we directly stomp the *dst memory
|
||||
YuvToRgbSSE2(y[0], u[0], v[0], dst); // stomps 8 bytes
|
||||
for (n = 0; n + 32 <= len; n += 32, dst += 32 * 3) {
|
||||
uint8_t tmp[32 * 3];
|
||||
__m128i R, G, B;
|
||||
YUV420ToRGB(y + 0, u + 0, v + 0, &R, &G, &B);
|
||||
PackAndStore3(&R, &G, &B, tmp + 0);
|
||||
YUV420ToRGB(y + 8, u + 4, v + 4, &R, &G, &B);
|
||||
PackAndStore3(&R, &G, &B, tmp + 8);
|
||||
YUV420ToRGB(y + 16, u + 8, v + 8, &R, &G, &B);
|
||||
PackAndStore3(&R, &G, &B, tmp + 16);
|
||||
YUV420ToRGB(y + 24, u + 12, v + 12, &R, &G, &B);
|
||||
PackAndStore3(&R, &G, &B, tmp + 24);
|
||||
PlanarTo24b(tmp, dst);
|
||||
y += 32;
|
||||
u += 16;
|
||||
v += 16;
|
||||
}
|
||||
for (; n < len; ++n) { // Finish off
|
||||
VP8YuvToRgb(y[0], u[0], v[0], dst);
|
||||
dst += 3;
|
||||
++y;
|
||||
y += 1;
|
||||
u += (n & 1);
|
||||
v += (n & 1);
|
||||
}
|
||||
VP8YuvToRgb(y[0], u[0], v[0], dst);
|
||||
if (len > 1) {
|
||||
VP8YuvToRgb(y[1], u[n & 1], v[n & 1], dst + 3);
|
||||
}
|
||||
}
|
||||
|
||||
static void YuvToBgrRow(const uint8_t* y, const uint8_t* u, const uint8_t* v,
|
||||
uint8_t* dst, int len) {
|
||||
int n;
|
||||
for (n = 0; n + 2 < len; ++n) { // we directly stomp the *dst memory
|
||||
YuvToBgrSSE2(y[0], u[0], v[0], dst); // stomps 8 bytes
|
||||
for (n = 0; n + 32 <= len; n += 32, dst += 32 * 3) {
|
||||
uint8_t tmp[32 * 3];
|
||||
__m128i R, G, B;
|
||||
YUV420ToRGB(y + 0, u + 0, v + 0, &R, &G, &B);
|
||||
PackAndStore3(&B, &G, &R, tmp + 0);
|
||||
YUV420ToRGB(y + 8, u + 4, v + 4, &R, &G, &B);
|
||||
PackAndStore3(&B, &G, &R, tmp + 8);
|
||||
YUV420ToRGB(y + 16, u + 8, v + 8, &R, &G, &B);
|
||||
PackAndStore3(&B, &G, &R, tmp + 16);
|
||||
YUV420ToRGB(y + 24, u + 12, v + 12, &R, &G, &B);
|
||||
PackAndStore3(&B, &G, &R, tmp + 24);
|
||||
PlanarTo24b(tmp, dst);
|
||||
y += 32;
|
||||
u += 16;
|
||||
v += 16;
|
||||
}
|
||||
for (; n < len; ++n) { // Finish off
|
||||
VP8YuvToBgr(y[0], u[0], v[0], dst);
|
||||
dst += 3;
|
||||
++y;
|
||||
y += 1;
|
||||
u += (n & 1);
|
||||
v += (n & 1);
|
||||
}
|
||||
VP8YuvToBgr(y[0], u[0], v[0], dst + 0);
|
||||
if (len > 1) {
|
||||
VP8YuvToBgr(y[1], u[n & 1], v[n & 1], dst + 3);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user