mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-06 16:56:55 +08:00
inline version of alpha blend
BUG=none TEST=none Review URL: https://webrtc-codereview.appspot.com/446006 git-svn-id: http://libyuv.googlecode.com/svn/trunk@216 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
parent
f620d2ae71
commit
91ab139558
@ -1,6 +1,6 @@
|
|||||||
Name: libyuv
|
Name: libyuv
|
||||||
URL: http://code.google.com/p/libyuv/
|
URL: http://code.google.com/p/libyuv/
|
||||||
Version: 214
|
Version: 216
|
||||||
License: BSD
|
License: BSD
|
||||||
License File: LICENSE
|
License File: LICENSE
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
#ifndef INCLUDE_LIBYUV_VERSION_H_
|
#ifndef INCLUDE_LIBYUV_VERSION_H_
|
||||||
#define INCLUDE_LIBYUV_VERSION_H_
|
#define INCLUDE_LIBYUV_VERSION_H_
|
||||||
|
|
||||||
#define LIBYUV_VERSION 214
|
#define LIBYUV_VERSION 216
|
||||||
|
|
||||||
#endif // INCLUDE_LIBYUV_VERSION_H_
|
#endif // INCLUDE_LIBYUV_VERSION_H_
|
||||||
|
|
||||||
|
|||||||
@ -170,6 +170,10 @@ int ARGBBlend(const uint8* src_argb, int src_stride_argb,
|
|||||||
#if defined(HAS_ARGBBLENDROW_SSE2)
|
#if defined(HAS_ARGBBLENDROW_SSE2)
|
||||||
if (TestCpuFlag(kCpuHasSSE2)) {
|
if (TestCpuFlag(kCpuHasSSE2)) {
|
||||||
ARGBBlendRow = ARGBBlendRow_SSE2;
|
ARGBBlendRow = ARGBBlendRow_SSE2;
|
||||||
|
if (IS_ALIGNED(width, 4) &&
|
||||||
|
IS_ALIGNED(dst_argb, 16) && IS_ALIGNED(dst_stride_argb, 16)) {
|
||||||
|
ARGBBlendRow = ARGBBlendRow_Aligned_SSE2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -240,10 +240,13 @@ void YToARGBRow_SSE2(const uint8* y_buf,
|
|||||||
uint8* rgb_buf,
|
uint8* rgb_buf,
|
||||||
int width);
|
int width);
|
||||||
|
|
||||||
|
// ARGB preattenuated alpha blend.
|
||||||
|
void ARGBBlendRow_Aligned_SSE2(const uint8* src_argb, uint8* dst_argb,
|
||||||
|
int width);
|
||||||
void ARGBBlendRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width);
|
void ARGBBlendRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width);
|
||||||
void ARGBBlendRow_C(const uint8* src_argb, uint8* dst_argb, int width);
|
void ARGBBlendRow_C(const uint8* src_argb, uint8* dst_argb, int width);
|
||||||
|
|
||||||
// 'Any' wrappers use memcpy()
|
// 'Any' functions handle any size and alignment.
|
||||||
void I420ToARGBRow_Any_SSSE3(const uint8* y_buf,
|
void I420ToARGBRow_Any_SSSE3(const uint8* y_buf,
|
||||||
const uint8* u_buf,
|
const uint8* u_buf,
|
||||||
const uint8* v_buf,
|
const uint8* v_buf,
|
||||||
|
|||||||
@ -452,7 +452,7 @@ void UYVYToYRow_C(const uint8* src_yuy2, uint8* dst_y, int width) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BLENDER(f, b, a) (f * a + b * (a ^ 0xff) + 0x80) >> 8
|
#define BLENDER(f, b, a) (((256 - a) * b) >> 8) + f
|
||||||
void ARGBBlendRow_C(const uint8* src_argb, uint8* dst_argb, int width) {
|
void ARGBBlendRow_C(const uint8* src_argb, uint8* dst_argb, int width) {
|
||||||
for (int x = 0; x < width - 1; x += 2) {
|
for (int x = 0; x < width - 1; x += 2) {
|
||||||
uint32 a = src_argb[3];
|
uint32 a = src_argb[3];
|
||||||
|
|||||||
@ -1925,106 +1925,151 @@ void UYVYToUVRow_Unaligned_SSE2(const uint8* src_uyvy, int stride_uyvy,
|
|||||||
#endif // HAS_YUY2TOYROW_SSE2
|
#endif // HAS_YUY2TOYROW_SSE2
|
||||||
|
|
||||||
#ifdef HAS_ARGBBLENDROW_SSE2
|
#ifdef HAS_ARGBBLENDROW_SSE2
|
||||||
void ARGBBlendRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width) {
|
// Blend 8 pixels at a time
|
||||||
uint32 pixel = 0;
|
// Destination aligned to 16 bytes, multiple of 4 pixels
|
||||||
|
void ARGBBlendRow_Aligned_SSE2(const uint8* src_argb, uint8* dst_argb,
|
||||||
|
int width) {
|
||||||
asm volatile (
|
asm volatile (
|
||||||
"pcmpeqb %%xmm4,%%xmm4 \n"
|
"pcmpeqb %%xmm7,%%xmm7 \n"
|
||||||
|
"psrlw $0xf,%%xmm7 \n"
|
||||||
|
"pcmpeqb %%xmm6,%%xmm6 \n"
|
||||||
|
"psrlw $0x8,%%xmm6 \n"
|
||||||
"pcmpeqb %%xmm5,%%xmm5 \n"
|
"pcmpeqb %%xmm5,%%xmm5 \n"
|
||||||
"pslld $24,%%xmm5 \n"
|
"psllw $0x8,%%xmm5 \n"
|
||||||
"sub %0,%1 \n"
|
"pcmpeqb %%xmm4,%%xmm4 \n"
|
||||||
"mov (%0),%3 \n"
|
"pslld $0x18,%%xmm4 \n"
|
||||||
"sub $0x1,%2 \n"
|
|
||||||
"jle 8f \n" // last1
|
|
||||||
"cmp $0xff000000,%3 \n"
|
|
||||||
"jae 2f \n" // opaqueloop
|
|
||||||
"cmp $0xffffff,%3 \n"
|
|
||||||
"ja 3f \n" // translucentloop
|
|
||||||
|
|
||||||
// transparentloop
|
// 8 pixel loop
|
||||||
"1: \n"
|
"1: \n"
|
||||||
"sub $0x1,%2 \n"
|
"movdqu (%0),%%xmm3 \n" // first 4 pixels
|
||||||
"lea 0x4(%0),%0 \n"
|
"movdqa %%xmm3,%%xmm0 \n"
|
||||||
"jle 8f \n" // last1
|
|
||||||
"mov (%0),%3 \n"
|
|
||||||
"cmp $0xffffff,%3 \n"
|
|
||||||
"jbe 1b \n" // transparentloop
|
|
||||||
"cmp $0xff000000,%3 \n"
|
|
||||||
"jb 3f \n" // translucentloop
|
|
||||||
|
|
||||||
// opaqueloop
|
|
||||||
"2: \n"
|
|
||||||
"mov %3,(%0,%1,1) \n"
|
|
||||||
"lea 0x4(%0),%0 \n"
|
|
||||||
"sub $0x1,%2 \n"
|
|
||||||
"jle 8f \n" // last1
|
|
||||||
"mov (%0),%3 \n"
|
|
||||||
"cmp $0xff000000,%3 \n"
|
|
||||||
"jae 2b \n" // opaqueloop
|
|
||||||
"cmp $0xffffff,%3 \n"
|
|
||||||
"jbe 1b \n" // transparentloop
|
|
||||||
|
|
||||||
// translucentloop
|
|
||||||
"3: \n"
|
|
||||||
"movq (%0),%%xmm0 \n"
|
|
||||||
"movq (%0,%1,1),%%xmm1 \n"
|
|
||||||
"punpcklbw %%xmm0,%%xmm0 \n"
|
|
||||||
"punpcklbw %%xmm1,%%xmm1 \n"
|
|
||||||
"pshuflw $0xff,%%xmm0,%%xmm2 \n"
|
|
||||||
"pshufhw $0xff,%%xmm2,%%xmm2 \n"
|
|
||||||
"movdqa %%xmm2,%%xmm3 \n"
|
|
||||||
"pxor %%xmm4,%%xmm3 \n"
|
"pxor %%xmm4,%%xmm3 \n"
|
||||||
"pmulhuw %%xmm2,%%xmm0 \n"
|
"movdqa (%1),%%xmm2 \n"
|
||||||
"pmulhuw %%xmm3,%%xmm1 \n"
|
"psrlw $0x8,%%xmm3 \n"
|
||||||
"paddusw %%xmm1,%%xmm0 \n"
|
"pshufhw $0xf5,%%xmm3,%%xmm3 \n"
|
||||||
"psrlw $0x8,%%xmm0 \n"
|
"pshuflw $0xf5,%%xmm3,%%xmm3 \n"
|
||||||
"packuswb %%xmm0,%%xmm0 \n"
|
"pand %%xmm6,%%xmm2 \n"
|
||||||
"por %%xmm5,%%xmm0 \n"
|
"paddw %%xmm7,%%xmm3 \n"
|
||||||
"movq %%xmm0,(%0,%1,1) \n"
|
"pmullw %%xmm3,%%xmm2 \n"
|
||||||
"lea 0x8(%0),%0 \n"
|
"movdqa (%1),%%xmm1 \n"
|
||||||
"sub $0x2,%2 \n"
|
"psrlw $0x8,%%xmm1 \n"
|
||||||
"jle 8f \n" // last1
|
"por %%xmm4,%%xmm0 \n"
|
||||||
"mov (%0),%3 \n"
|
"pmullw %%xmm3,%%xmm1 \n"
|
||||||
"cmp $0xffffff,%3 \n"
|
"movdqu 0x10(%0),%%xmm3 \n"
|
||||||
"jbe 1b \n" // transparentloop
|
"lea 0x20(%0),%0 \n"
|
||||||
"cmp $0xff000000,%3 \n"
|
"psrlw $0x8,%%xmm2 \n"
|
||||||
"jb 3b \n" // translucentloop
|
"paddusb %%xmm2,%%xmm0 \n"
|
||||||
"jmp 2b \n" // opaqueloop
|
"pand %%xmm5,%%xmm1 \n"
|
||||||
|
"paddusb %%xmm1,%%xmm0 \n"
|
||||||
// last1
|
"sub $0x4,%2 \n"
|
||||||
"8: \n"
|
"movdqa %%xmm0,(%1) \n"
|
||||||
"add $0x1,%2 \n" // 1 pixel left?
|
"jle 9f \n"
|
||||||
"cmp $0x1,%2 \n"
|
"movdqa %%xmm3,%%xmm0 \n" // next 4 pixels
|
||||||
"jl 9f \n" // done
|
|
||||||
"mov (%0),%3 \n"
|
|
||||||
"movd %3,%%xmm0 \n"
|
|
||||||
"mov (%0,%1,1),%3 \n"
|
|
||||||
"movd %3,%%xmm1 \n"
|
|
||||||
"punpcklbw %%xmm0,%%xmm0 \n"
|
|
||||||
"punpcklbw %%xmm1,%%xmm1 \n"
|
|
||||||
"pshuflw $0xff,%%xmm0,%%xmm2 \n"
|
|
||||||
"movdqa %%xmm2,%%xmm3 \n"
|
|
||||||
"pxor %%xmm4,%%xmm3 \n"
|
"pxor %%xmm4,%%xmm3 \n"
|
||||||
"pmulhuw %%xmm2,%%xmm0 \n"
|
"movdqa 0x10(%1),%%xmm2 \n"
|
||||||
"pmulhuw %%xmm3,%%xmm1 \n"
|
"psrlw $0x8,%%xmm3 \n"
|
||||||
"paddusw %%xmm1,%%xmm0 \n"
|
"pshufhw $0xf5,%%xmm3,%%xmm3 \n"
|
||||||
"psrlw $0x8,%%xmm0 \n"
|
"pshuflw $0xf5,%%xmm3,%%xmm3 \n"
|
||||||
"packuswb %%xmm0,%%xmm0 \n"
|
"pand %%xmm6,%%xmm2 \n"
|
||||||
"movd %%xmm0,%3 \n"
|
"paddw %%xmm7,%%xmm3 \n"
|
||||||
"mov %3,(%0,%1,1) \n"
|
"pmullw %%xmm3,%%xmm2 \n"
|
||||||
|
"movdqa 0x10(%1),%%xmm1 \n"
|
||||||
// done
|
"psrlw $0x8,%%xmm1 \n"
|
||||||
|
"por %%xmm4,%%xmm0 \n"
|
||||||
|
"pmullw %%xmm3,%%xmm1 \n"
|
||||||
|
"psrlw $0x8,%%xmm2 \n"
|
||||||
|
"paddusb %%xmm2,%%xmm0 \n"
|
||||||
|
"pand %%xmm5,%%xmm1 \n"
|
||||||
|
"paddusb %%xmm1,%%xmm0 \n"
|
||||||
|
"sub $0x4,%2 \n"
|
||||||
|
"movdqa %%xmm0,0x10(%1) \n"
|
||||||
|
"lea 0x20(%1),%1 \n"
|
||||||
|
"jg 1b \n"
|
||||||
"9: \n"
|
"9: \n"
|
||||||
: "+r"(src_argb), // %0
|
: "+r"(src_argb), // %0
|
||||||
"+r"(dst_argb), // %1
|
"+r"(dst_argb), // %1
|
||||||
"+r"(width), // %2
|
"+r"(width) // %2
|
||||||
"+r"(pixel) // %3
|
|
||||||
:
|
:
|
||||||
: "memory", "cc"
|
: "memory", "cc"
|
||||||
#if defined(__SSE2__)
|
#if defined(__SSE2__)
|
||||||
, "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
|
, "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Blend 1 pixel at a time, unaligned
|
||||||
|
void ARGBBlendRow1_SSE2(const uint8* src_argb, uint8* dst_argb, int width) {
|
||||||
|
asm volatile (
|
||||||
|
"pcmpeqb %%xmm7,%%xmm7 \n"
|
||||||
|
"psrlw $0xf,%%xmm7 \n"
|
||||||
|
"pcmpeqb %%xmm6,%%xmm6 \n"
|
||||||
|
"psrlw $0x8,%%xmm6 \n"
|
||||||
|
"pcmpeqb %%xmm5,%%xmm5 \n"
|
||||||
|
"psllw $0x8,%%xmm5 \n"
|
||||||
|
"pcmpeqb %%xmm4,%%xmm4 \n"
|
||||||
|
"pslld $0x18,%%xmm4 \n"
|
||||||
|
|
||||||
|
// 1 pixel loop
|
||||||
|
"1: \n"
|
||||||
|
"movd (%0),%%xmm3 \n"
|
||||||
|
"lea 0x4(%0),%0 \n"
|
||||||
|
"movdqa %%xmm3,%%xmm0 \n"
|
||||||
|
"pxor %%xmm4,%%xmm3 \n"
|
||||||
|
"movd (%1),%%xmm2 \n"
|
||||||
|
"psrlw $0x8,%%xmm3 \n"
|
||||||
|
"pshufhw $0xf5,%%xmm3,%%xmm3 \n"
|
||||||
|
"pshuflw $0xf5,%%xmm3,%%xmm3 \n"
|
||||||
|
"pand %%xmm6,%%xmm2 \n"
|
||||||
|
"paddw %%xmm7,%%xmm3 \n"
|
||||||
|
"pmullw %%xmm3,%%xmm2 \n"
|
||||||
|
"movd (%1),%%xmm1 \n"
|
||||||
|
"psrlw $0x8,%%xmm1 \n"
|
||||||
|
"por %%xmm4,%%xmm0 \n"
|
||||||
|
"pmullw %%xmm3,%%xmm1 \n"
|
||||||
|
"psrlw $0x8,%%xmm2 \n"
|
||||||
|
"paddusb %%xmm2,%%xmm0 \n"
|
||||||
|
"pand %%xmm5,%%xmm1 \n"
|
||||||
|
"paddusb %%xmm1,%%xmm0 \n"
|
||||||
|
"sub $0x1,%2 \n"
|
||||||
|
"movd %%xmm0,(%1) \n"
|
||||||
|
"lea 0x4(%1),%1 \n"
|
||||||
|
"jg 1b \n"
|
||||||
|
: "+r"(src_argb), // %0
|
||||||
|
"+r"(dst_argb), // %1
|
||||||
|
"+r"(width) // %2
|
||||||
|
:
|
||||||
|
: "memory", "cc"
|
||||||
|
#if defined(__SSE2__)
|
||||||
|
, "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARGBBlendRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width) {
|
||||||
|
// Do 1 to 3 pixels to get destination aligned.
|
||||||
|
if ((uintptr_t)(dst_argb) & 15) {
|
||||||
|
int count = width;
|
||||||
|
if (((intptr_t)(dst_argb) & 3) == 0) {
|
||||||
|
count = (-(intptr_t)(dst_argb) >> 2) & 3;
|
||||||
|
}
|
||||||
|
ARGBBlendRow1_SSE2(src_argb, dst_argb, count);
|
||||||
|
src_argb += count * 4;
|
||||||
|
dst_argb += count * 4;
|
||||||
|
width -= count;
|
||||||
|
}
|
||||||
|
// Do multiple of 4 pixels
|
||||||
|
if (width & ~3) {
|
||||||
|
ARGBBlendRow_Aligned_SSE2(src_argb, dst_argb, width & ~3);
|
||||||
|
}
|
||||||
|
// Do remaining 1 to 3 pixels
|
||||||
|
if (width & 3) {
|
||||||
|
src_argb += (width & ~3) * 4;
|
||||||
|
dst_argb += (width & ~3) * 4;
|
||||||
|
width &= 3;
|
||||||
|
ARGBBlendRow1_SSE2(src_argb, dst_argb, width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // HAS_ARGBBLENDROW_SSE2
|
#endif // HAS_ARGBBLENDROW_SSE2
|
||||||
|
|
||||||
#endif // defined(__x86_64__) || defined(__i386__)
|
#endif // defined(__x86_64__) || defined(__i386__)
|
||||||
|
|||||||
@ -1959,279 +1959,146 @@ void UYVYToUVRow_Unaligned_SSE2(const uint8* src_uyvy, int stride_uyvy,
|
|||||||
#endif // HAS_YUY2TOYROW_SSE2
|
#endif // HAS_YUY2TOYROW_SSE2
|
||||||
|
|
||||||
#ifdef HAS_ARGBBLENDROW_SSE2
|
#ifdef HAS_ARGBBLENDROW_SSE2
|
||||||
// TODO(fbarchard): Single multiply method b+a(f-b)
|
// Blend 8 pixels at a time
|
||||||
// TODO(fbarchard): Unroll and pair
|
// Destination aligned to 16 bytes, multiple of 4 pixels
|
||||||
// TODO(fbarchard): branch hints __emit 0x3E taken, 0x2E not taken
|
// TODO(fbarchard): SSSE3 version with pshufb for alpha and maybe pmaddubsw
|
||||||
__declspec(naked)
|
__declspec(naked) __declspec(align(16))
|
||||||
void OrigARGBBlendRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width) {
|
void ARGBBlendRow_Aligned_SSE2(const uint8* src_argb, uint8* dst_argb,
|
||||||
|
int width) {
|
||||||
__asm {
|
__asm {
|
||||||
push esi
|
mov eax, [esp + 4] // src_argb
|
||||||
mov esi, [esp + 4 + 4] // src_argb
|
mov edx, [esp + 8] // dst_argb
|
||||||
mov edx, [esp + 4 + 8] // dst_argb
|
mov ecx, [esp + 12] // width
|
||||||
mov ecx, [esp + 4 + 12] // width
|
pcmpeqb xmm7, xmm7 // generate constant 1
|
||||||
pcmpeqb xmm4, xmm4 // generate 0xffffffff do negative alpha
|
psrlw xmm7, 15
|
||||||
pcmpeqb xmm5, xmm5 // generate 0xff000000 for alpha
|
pcmpeqb xmm6, xmm6 // generate mask 0x00ff00ff
|
||||||
pslld xmm5, 24
|
psrlw xmm6, 8
|
||||||
sub edx, esi
|
pcmpeqb xmm5, xmm5 // generate mask 0xff00ff00
|
||||||
mov eax, [esi] // get first pixel
|
psllw xmm5, 8
|
||||||
sub ecx, 1 // ensure there are at least 2 pixels
|
pcmpeqb xmm4, xmm4 // generate mask 0xff000000
|
||||||
jle last1 // last pixel?
|
pslld xmm4, 24
|
||||||
cmp eax, 0xFF000000 // opaque?
|
|
||||||
jae opaqueloop
|
|
||||||
cmp eax, 0x00FFFFFF // translucent?
|
|
||||||
ja translucentloop
|
|
||||||
|
|
||||||
align 16
|
align 16
|
||||||
transparentloop:
|
convertloop:
|
||||||
sub ecx, 1
|
movdqu xmm3, [eax]
|
||||||
lea esi, [esi + 4]
|
movdqa xmm0, xmm3 // src argb
|
||||||
jle last1
|
pxor xmm3, xmm4 // ~alpha
|
||||||
mov eax, [esi] // get next pixel
|
movdqa xmm2, [edx] // _r_b
|
||||||
cmp eax, 0x00FFFFFF // transparent?
|
psrlw xmm3, 8 // alpha
|
||||||
jbe transparentloop
|
pshufhw xmm3, xmm3,0F5h // 8 alpha words
|
||||||
cmp eax, 0xFF000000 // translucent?
|
pshuflw xmm3, xmm3,0F5h
|
||||||
jb translucentloop
|
pand xmm2, xmm6 // _r_b
|
||||||
|
paddw xmm3, xmm7 // 256-alpha
|
||||||
|
pmullw xmm2, xmm3 // _r_b * alpha
|
||||||
|
movdqa xmm1, [edx] // _a_g
|
||||||
|
psrlw xmm1, 8 // _a_g
|
||||||
|
por xmm0, xmm4 // set alpha to 255
|
||||||
|
pmullw xmm1, xmm3 // _a_g * alpha
|
||||||
|
movdqu xmm3, [eax + 16]
|
||||||
|
lea eax, [eax + 32]
|
||||||
|
psrlw xmm2, 8 // _r_b convert to 8 bits again
|
||||||
|
paddusb xmm0, xmm2 // + src argb
|
||||||
|
pand xmm1, xmm5 // a_g_ convert to 8 bits again
|
||||||
|
paddusb xmm0, xmm1 // + src argb
|
||||||
|
sub ecx, 4
|
||||||
|
movdqa [edx], xmm0
|
||||||
|
jle done
|
||||||
|
|
||||||
align 16
|
movdqa xmm0, xmm3 // src argb
|
||||||
opaqueloop:
|
pxor xmm3, xmm4 // ~alpha
|
||||||
mov dword ptr [esi + edx], eax
|
movdqa xmm2, [edx + 16] // _r_b
|
||||||
lea esi, [esi + 4]
|
psrlw xmm3, 8 // alpha
|
||||||
sub ecx, 1
|
pshufhw xmm3, xmm3,0F5h // 8 alpha words
|
||||||
jle last1
|
pshuflw xmm3, xmm3,0F5h
|
||||||
mov eax, [esi] // get next pixel
|
pand xmm2, xmm6 // _r_b
|
||||||
cmp eax, 0xFF000000 // opaque?
|
paddw xmm3, xmm7 // 256-alpha
|
||||||
jae opaqueloop
|
pmullw xmm2, xmm3 // _r_b * alpha
|
||||||
cmp eax, 0x00FFFFFF // transparent?
|
movdqa xmm1, [edx + 16] // _a_g
|
||||||
jbe transparentloop
|
psrlw xmm1, 8 // _a_g
|
||||||
|
por xmm0, xmm4 // set alpha to 255
|
||||||
align 16
|
pmullw xmm1, xmm3 // _a_g * alpha
|
||||||
translucentloop:
|
psrlw xmm2, 8 // _r_b convert to 8 bits again
|
||||||
movq xmm0, qword ptr [esi] // fetch 2 pixels
|
paddusb xmm0, xmm2 // + src argb
|
||||||
movq xmm1, qword ptr [esi + edx]
|
pand xmm1, xmm5 // a_g_ convert to 8 bits again
|
||||||
punpcklbw xmm0, xmm0 // src 16 bits
|
paddusb xmm0, xmm1 // + src argb
|
||||||
punpcklbw xmm1, xmm1 // dst 16 bits
|
sub ecx, 4
|
||||||
pshuflw xmm2, xmm0, 0xff // src alpha
|
movdqa [edx + 16], xmm0
|
||||||
pshufhw xmm2, xmm2, 0xff
|
lea edx, [edx + 32]
|
||||||
movdqa xmm3, xmm2 // dst alpha
|
jg convertloop
|
||||||
pxor xmm3, xmm4
|
|
||||||
pmulhuw xmm0, xmm2 // src * a
|
|
||||||
pmulhuw xmm1, xmm3 // dst * (a ^ 0xffff)
|
|
||||||
paddusw xmm0, xmm1
|
|
||||||
psrlw xmm0, 8
|
|
||||||
packuswb xmm0, xmm0 // pack 2 pixels
|
|
||||||
por xmm0, xmm5 // set alpha
|
|
||||||
movq qword ptr [esi + edx], xmm0
|
|
||||||
lea esi, [esi + 8]
|
|
||||||
sub ecx, 2
|
|
||||||
jle last1
|
|
||||||
mov eax, [esi]
|
|
||||||
cmp eax, 0x00FFFFFF // transparent?
|
|
||||||
jbe transparentloop
|
|
||||||
cmp eax, 0xFF000000 // translucent?
|
|
||||||
jb translucentloop
|
|
||||||
jmp opaqueloop
|
|
||||||
|
|
||||||
align 16
|
|
||||||
last1:
|
|
||||||
add ecx, 1
|
|
||||||
cmp ecx, 1 // 1 left?
|
|
||||||
jl done
|
|
||||||
|
|
||||||
mov eax, [esi] // get next pixel
|
|
||||||
movd xmm0, eax
|
|
||||||
mov eax, [esi + edx]
|
|
||||||
movd xmm1, eax
|
|
||||||
punpcklbw xmm0, xmm0 // src 16 bits
|
|
||||||
punpcklbw xmm1, xmm1 // dst 16 bits
|
|
||||||
pshuflw xmm2, xmm0, 0xff // src alpha
|
|
||||||
movdqa xmm3, xmm2 // dst alpha
|
|
||||||
pxor xmm3, xmm4
|
|
||||||
pmulhuw xmm0, xmm2 // src * a
|
|
||||||
pmulhuw xmm1, xmm3 // dst * (a ^ 0xffff)
|
|
||||||
paddusw xmm0, xmm1
|
|
||||||
psrlw xmm0, 8
|
|
||||||
packuswb xmm0, xmm0 // pack to bytes
|
|
||||||
por xmm0, xmm5 // set alpha
|
|
||||||
movd eax, xmm0
|
|
||||||
mov dword ptr [esi + edx], eax
|
|
||||||
|
|
||||||
done:
|
done:
|
||||||
pop esi
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UNATTENUATED 1
|
// Blend 1 pixel at a time, unaligned
|
||||||
#define ALIGNED 1
|
__declspec(naked) __declspec(align(16))
|
||||||
#define SETALPHA 1
|
void ARGBBlendRow1_SSE2(const uint8* src_argb, uint8* dst_argb, int width) {
|
||||||
|
__asm {
|
||||||
|
mov eax, [esp + 4] // src_argb
|
||||||
|
mov edx, [esp + 8] // dst_argb
|
||||||
|
mov ecx, [esp + 12] // width
|
||||||
|
pcmpeqb xmm7, xmm7 // generate constant 1
|
||||||
|
psrlw xmm7, 15
|
||||||
|
pcmpeqb xmm6, xmm6 // generate mask 0x00ff00ff
|
||||||
|
psrlw xmm6, 8
|
||||||
|
pcmpeqb xmm5, xmm5 // generate mask 0xff00ff00
|
||||||
|
psllw xmm5, 8
|
||||||
|
pcmpeqb xmm4, xmm4 // generate mask 0xff000000
|
||||||
|
pslld xmm4, 24
|
||||||
|
|
||||||
void ARGBBlendPixel_SSE2(const uint8* src_argb, uint8* dst_argb) {
|
align 16
|
||||||
const uint32* s = reinterpret_cast<const uint32*>(src_argb);
|
convertloop:
|
||||||
uint32* d = reinterpret_cast<uint32*>(dst_argb);
|
movd xmm3, [eax]
|
||||||
__m128i rb_mask = _mm_set1_epi32(0x00FF00FF);
|
lea eax, [eax + 4]
|
||||||
#if SETALPHA
|
movdqa xmm0, xmm3 // src argb
|
||||||
__m128i alpha_255 = _mm_set1_epi32(0xFF000000);
|
pxor xmm3, xmm4 // ~alpha
|
||||||
#endif
|
movd xmm2, [edx] // _r_b
|
||||||
__m128i c_256 = _mm_set1_epi16(0x0100); // 8 copies of 256 (16-bit)
|
psrlw xmm3, 8 // alpha
|
||||||
|
pshufhw xmm3, xmm3,0F5h // 8 alpha words
|
||||||
{
|
pshuflw xmm3, xmm3,0F5h
|
||||||
// Load 4 pixels
|
pand xmm2, xmm6 // _r_b
|
||||||
__m128i src_pixel = _mm_cvtsi32_si128(*s);
|
paddw xmm3, xmm7 // 256-alpha
|
||||||
__m128i dst_pixel = _mm_cvtsi32_si128(*d);
|
pmullw xmm2, xmm3 // _r_b * alpha
|
||||||
|
movd xmm1, [edx] // _a_g
|
||||||
// (a0, g0, a1, g1, a2, g2, a3, g3) (low byte of each word)
|
psrlw xmm1, 8 // _a_g
|
||||||
__m128i src_alpha = _mm_srli_epi16(src_pixel, 8);
|
por xmm0, xmm4 // set alpha to 255
|
||||||
|
pmullw xmm1, xmm3 // _a_g * alpha
|
||||||
// (a0, a0, a1, a1, a2, g2, a3, g3)
|
psrlw xmm2, 8 // _r_b convert to 8 bits again
|
||||||
src_alpha = _mm_shufflehi_epi16(src_alpha, 0xF5);
|
paddusb xmm0, xmm2 // + src argb
|
||||||
|
pand xmm1, xmm5 // a_g_ convert to 8 bits again
|
||||||
// (a0, a0, a1, a1, a2, a2, a3, a3)
|
paddusb xmm0, xmm1 // + src argb
|
||||||
src_alpha = _mm_shufflelo_epi16(src_alpha, 0xF5);
|
sub ecx, 1
|
||||||
|
movd [edx], xmm0
|
||||||
#if UNATTENUATED
|
lea edx, [edx + 4]
|
||||||
__m128i src_rb = _mm_and_si128(rb_mask, src_pixel);
|
jg convertloop
|
||||||
__m128i src_ag = _mm_srli_epi16(src_pixel, 8);
|
ret
|
||||||
|
|
||||||
// Multiply by red and blue by src alpha.
|
|
||||||
src_rb = _mm_mullo_epi16(src_rb, src_alpha);
|
|
||||||
// Multiply by alpha and green by src alpha.
|
|
||||||
src_ag = _mm_mullo_epi16(src_ag, src_alpha);
|
|
||||||
|
|
||||||
// Divide by 256.
|
|
||||||
src_rb = _mm_srli_epi16(src_rb, 8);
|
|
||||||
|
|
||||||
// Mask out high bits (already in the right place)
|
|
||||||
src_ag = _mm_andnot_si128(rb_mask, src_ag);
|
|
||||||
|
|
||||||
// Combine back into RGBA.
|
|
||||||
src_pixel = _mm_or_si128(src_rb, src_ag);
|
|
||||||
#endif
|
|
||||||
// Subtract alphas from 256, to get 1..256
|
|
||||||
__m128i dst_alpha = _mm_sub_epi16(c_256, src_alpha);
|
|
||||||
//__m128i dst_alpha = _mm_xor_si128(src_alpha, rb_mask);
|
|
||||||
|
|
||||||
__m128i dst_rb = _mm_and_si128(rb_mask, dst_pixel);
|
|
||||||
__m128i dst_ag = _mm_srli_epi16(dst_pixel, 8);
|
|
||||||
|
|
||||||
// Multiply by red and blue by src alpha.
|
|
||||||
dst_rb = _mm_mullo_epi16(dst_rb, dst_alpha);
|
|
||||||
// Multiply by alpha and green by src alpha.
|
|
||||||
dst_ag = _mm_mullo_epi16(dst_ag, dst_alpha);
|
|
||||||
|
|
||||||
// Divide by 256.
|
|
||||||
dst_rb = _mm_srli_epi16(dst_rb, 8);
|
|
||||||
|
|
||||||
// Mask out high bits (already in the right place)
|
|
||||||
dst_ag = _mm_andnot_si128(rb_mask, dst_ag);
|
|
||||||
|
|
||||||
// Combine back into RGBA.
|
|
||||||
dst_pixel = _mm_or_si128(dst_rb, dst_ag);
|
|
||||||
|
|
||||||
// Add result
|
|
||||||
dst_pixel = _mm_adds_epu8(src_pixel, dst_pixel);
|
|
||||||
#if SETALPHA
|
|
||||||
dst_pixel = _mm_adds_epu8(alpha_255, dst_pixel);
|
|
||||||
#endif
|
|
||||||
*d = _mm_cvtsi128_si32(dst_pixel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARGBBlendRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width) {
|
void ARGBBlendRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width) {
|
||||||
#if ALIGNED
|
// Do 1 to 3 pixels to get destination aligned.
|
||||||
while (width >= 1 && ((uintptr_t)(dst_argb) & 15)) {
|
if ((uintptr_t)(dst_argb) & 15) {
|
||||||
ARGBBlendPixel_SSE2(src_argb, dst_argb);
|
int count = width;
|
||||||
src_argb += 4;
|
if (((intptr_t)(dst_argb) & 3) == 0) {
|
||||||
dst_argb += 4;
|
count = (-(intptr_t)(dst_argb) >> 2) & 3;
|
||||||
--width;
|
}
|
||||||
|
ARGBBlendRow1_SSE2(src_argb, dst_argb, count);
|
||||||
|
src_argb += count * 4;
|
||||||
|
dst_argb += count * 4;
|
||||||
|
width -= count;
|
||||||
}
|
}
|
||||||
#endif
|
// Do multiple of 4 pixels
|
||||||
const __m128i *s = reinterpret_cast<const __m128i*>(src_argb);
|
if (width & ~3) {
|
||||||
__m128i *d = reinterpret_cast<__m128i*>(dst_argb);
|
ARGBBlendRow_Aligned_SSE2(src_argb, dst_argb, width & ~3);
|
||||||
__m128i rb_mask = _mm_set1_epi32(0x00FF00FF);
|
|
||||||
#if SETALPHA
|
|
||||||
__m128i alpha_255 = _mm_set1_epi32(0xFF000000);
|
|
||||||
#endif
|
|
||||||
__m128i c_256 = _mm_set1_epi16(0x0100); // 8 copies of 256 (16-bit)
|
|
||||||
|
|
||||||
while (width >= 4) {
|
|
||||||
// Load 4 pixels
|
|
||||||
__m128i src_pixel = _mm_loadu_si128(s);
|
|
||||||
#if ALIGNED
|
|
||||||
__m128i dst_pixel = _mm_load_si128(d);
|
|
||||||
#else
|
|
||||||
__m128i dst_pixel = _mm_loadu_si128(d);
|
|
||||||
#endif
|
|
||||||
// (a0, g0, a1, g1, a2, g2, a3, g3) (low byte of each word)
|
|
||||||
__m128i src_alpha = _mm_srli_epi16(src_pixel, 8);
|
|
||||||
|
|
||||||
// (a0, a0, a1, a1, a2, g2, a3, g3)
|
|
||||||
src_alpha = _mm_shufflehi_epi16(src_alpha, 0xF5);
|
|
||||||
|
|
||||||
// (a0, a0, a1, a1, a2, a2, a3, a3)
|
|
||||||
src_alpha = _mm_shufflelo_epi16(src_alpha, 0xF5);
|
|
||||||
|
|
||||||
#if UNATTENUATED
|
|
||||||
__m128i src_rb = _mm_and_si128(rb_mask, src_pixel);
|
|
||||||
__m128i src_ag = _mm_srli_epi16(src_pixel, 8);
|
|
||||||
|
|
||||||
// Multiply by red and blue by src alpha.
|
|
||||||
src_rb = _mm_mullo_epi16(src_rb, src_alpha);
|
|
||||||
// Multiply by alpha and green by src alpha.
|
|
||||||
src_ag = _mm_mullo_epi16(src_ag, src_alpha);
|
|
||||||
|
|
||||||
// Divide by 256.
|
|
||||||
src_rb = _mm_srli_epi16(src_rb, 8);
|
|
||||||
|
|
||||||
// Mask out high bits (already in the right place)
|
|
||||||
src_ag = _mm_andnot_si128(rb_mask, src_ag);
|
|
||||||
|
|
||||||
// Combine back into RGBA.
|
|
||||||
src_pixel = _mm_or_si128(src_rb, src_ag);
|
|
||||||
#endif
|
|
||||||
// Subtract alphas from 256, to get 1..256
|
|
||||||
__m128i dst_alpha = _mm_sub_epi16(c_256, src_alpha);
|
|
||||||
//__m128i dst_alpha = _mm_xor_si128(src_alpha, rb_mask);
|
|
||||||
|
|
||||||
__m128i dst_rb = _mm_and_si128(rb_mask, dst_pixel);
|
|
||||||
__m128i dst_ag = _mm_srli_epi16(dst_pixel, 8);
|
|
||||||
|
|
||||||
// Multiply by red and blue by src alpha.
|
|
||||||
dst_rb = _mm_mullo_epi16(dst_rb, dst_alpha);
|
|
||||||
// Multiply by alpha and green by src alpha.
|
|
||||||
dst_ag = _mm_mullo_epi16(dst_ag, dst_alpha);
|
|
||||||
|
|
||||||
// Divide by 256.
|
|
||||||
dst_rb = _mm_srli_epi16(dst_rb, 8);
|
|
||||||
|
|
||||||
// Mask out high bits (already in the right place)
|
|
||||||
dst_ag = _mm_andnot_si128(rb_mask, dst_ag);
|
|
||||||
|
|
||||||
// Combine back into RGBA.
|
|
||||||
dst_pixel = _mm_or_si128(dst_rb, dst_ag);
|
|
||||||
|
|
||||||
// Add result
|
|
||||||
dst_pixel = _mm_adds_epu8(src_pixel, dst_pixel);
|
|
||||||
#if SETALPHA
|
|
||||||
dst_pixel = _mm_adds_epu8(alpha_255, dst_pixel);
|
|
||||||
#endif
|
|
||||||
#if ALIGNED
|
|
||||||
_mm_store_si128(d, dst_pixel);
|
|
||||||
#else
|
|
||||||
_mm_storeu_si128(d, dst_pixel);
|
|
||||||
#endif
|
|
||||||
s++;
|
|
||||||
d++;
|
|
||||||
width -= 4;
|
|
||||||
}
|
}
|
||||||
src_argb = reinterpret_cast<const uint8*>(s);
|
// Do remaining 1 to 3 pixels
|
||||||
dst_argb = reinterpret_cast<uint8*>(d);
|
if (width & 3) {
|
||||||
while (width >= 1) {
|
src_argb += (width & ~3) * 4;
|
||||||
ARGBBlendPixel_SSE2(src_argb, dst_argb);
|
dst_argb += (width & ~3) * 4;
|
||||||
src_argb += 4;
|
width &= 3;
|
||||||
dst_argb += 4;
|
ARGBBlendRow1_SSE2(src_argb, dst_argb, width);
|
||||||
--width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAS_ARGBBLENDROW_SSE2
|
#endif // HAS_ARGBBLENDROW_SSE2
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user