mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-06 16:56:55 +08:00
add ARGBRect, fix for 444 support in ConvertToI420
BUG=none TEST=none Review URL: http://webrtc-codereview.appspot.com/289003 git-svn-id: http://libyuv.googlecode.com/svn/trunk@93 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
parent
10f5556a9f
commit
3e8a577bb3
@ -1,6 +1,6 @@
|
||||
Name: libyuv
|
||||
URL: http://code.google.com/p/libyuv/
|
||||
Version: 90
|
||||
Version: 93
|
||||
License: BSD
|
||||
License File: LICENSE
|
||||
|
||||
|
||||
@ -66,7 +66,6 @@ typedef char int8;
|
||||
#define CPU_X86 1
|
||||
#endif
|
||||
|
||||
#define IS_ALIGNED(p, a) (0==(reinterpret_cast<uintptr_t>(p) & ((a)-1)))
|
||||
#define ALIGNP(p, t) \
|
||||
(reinterpret_cast<uint8*>(((reinterpret_cast<uintptr_t>(p) + \
|
||||
((t)-1)) & ~((t)-1))))
|
||||
|
||||
@ -33,15 +33,7 @@ int I420Mirror(const uint8* src_y, int src_stride_y,
|
||||
uint8* dst_v, int dst_stride_v,
|
||||
int width, int height);
|
||||
|
||||
// Draw a rectangle into I420
|
||||
int I420Rect(uint8* dst_y, int dst_stride_y,
|
||||
uint8* dst_u, int dst_stride_u,
|
||||
uint8* dst_v, int dst_stride_v,
|
||||
int x, int y,
|
||||
int width, int height,
|
||||
int value_y, int value_u, int value_v);
|
||||
|
||||
// Convert I422 to I420. Used by MJPG.
|
||||
// Convert I422 to I420.
|
||||
int I422ToI420(const uint8* src_y, int src_stride_y,
|
||||
const uint8* src_u, int src_stride_u,
|
||||
const uint8* src_v, int src_stride_v,
|
||||
@ -183,6 +175,20 @@ int ARGBToI400(const uint8* src_argb, int src_stride_argb,
|
||||
uint8* dst_y, int dst_stride_y,
|
||||
int width, int height);
|
||||
|
||||
// Draw a rectangle into I420
|
||||
int I420Rect(uint8* dst_y, int dst_stride_y,
|
||||
uint8* dst_u, int dst_stride_u,
|
||||
uint8* dst_v, int dst_stride_v,
|
||||
int x, int y,
|
||||
int width, int height,
|
||||
int value_y, int value_u, int value_v);
|
||||
|
||||
// Draw a rectangle into ARGB
|
||||
int ARGBRect(uint8* dst_argb, int dst_stride_argb,
|
||||
int x, int y,
|
||||
int width, int height,
|
||||
uint32 value);
|
||||
|
||||
} // namespace libyuv
|
||||
|
||||
#endif // INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_
|
||||
|
||||
@ -1171,8 +1171,8 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
|
||||
src_u = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x;
|
||||
}
|
||||
I444ToI420(src_y, src_width,
|
||||
src_u, halfwidth,
|
||||
src_v, halfwidth,
|
||||
src_u, src_width,
|
||||
src_v, src_width,
|
||||
y, y_stride,
|
||||
u, u_stride,
|
||||
v, v_stride,
|
||||
|
||||
@ -304,138 +304,6 @@ int I420Mirror(const uint8* src_y, int src_stride_y,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// SetRows32 writes 'count' bytes using a 32 bit value repeated
|
||||
|
||||
#if defined(__ARM_NEON__) && !defined(YUV_DISABLE_ASM)
|
||||
#define HAS_SETROW_NEON
|
||||
static void SetRow32_NEON(uint8* dst, uint32 v32, int count) {
|
||||
asm volatile (
|
||||
"vdup.u32 q0, %2 \n" // duplicate 4 ints
|
||||
"1: \n"
|
||||
"vst1.u32 {q0}, [%0]! \n" // store
|
||||
"subs %1, %1, #16 \n" // 16 processed per loop
|
||||
"bhi 1b \n"
|
||||
: "+r"(dst), // %0
|
||||
"+r"(count) // %1
|
||||
: "r"(v32) // %2
|
||||
: "q0", "memory", "cc"
|
||||
);
|
||||
}
|
||||
|
||||
#elif defined(_M_IX86) && !defined(YUV_DISABLE_ASM)
|
||||
#define HAS_SETROW_SSE2
|
||||
__declspec(naked)
|
||||
static void SetRow32_SSE2(uint8* dst, uint32 v32, int count) {
|
||||
__asm {
|
||||
mov eax, [esp + 4] // dst
|
||||
movd xmm5, [esp + 8] // v32
|
||||
mov ecx, [esp + 12] // count
|
||||
pshufd xmm5, xmm5, 0
|
||||
|
||||
convertloop:
|
||||
movdqa [eax], xmm5
|
||||
lea eax, [eax + 16]
|
||||
sub ecx, 16
|
||||
ja convertloop
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#elif (defined(__x86_64__) || defined(__i386__)) && !defined(YUV_DISABLE_ASM)
|
||||
|
||||
#define HAS_SETROW_SSE2
|
||||
static void SetRow32_SSE2(uint8* dst, uint32 v32, int count) {
|
||||
asm volatile (
|
||||
"movd %2, %%xmm5 \n"
|
||||
"pshufd $0x0,%%xmm5,%%xmm5 \n"
|
||||
"1: \n"
|
||||
"movdqa %%xmm5,(%0) \n"
|
||||
"lea 0x10(%0),%0 \n"
|
||||
"sub $0x10,%1 \n"
|
||||
"ja 1b \n"
|
||||
: "+r"(dst), // %0
|
||||
"+r"(count) // %1
|
||||
: "r"(v32) // %2
|
||||
: "memory", "cc"
|
||||
#if defined(__SSE2__)
|
||||
, "xmm5"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void SetRow8_C(uint8* dst, uint32 v8, int count) {
|
||||
memset(dst, v8, count);
|
||||
}
|
||||
|
||||
static void I420SetPlane(uint8* dst_y, int dst_stride_y,
|
||||
int width, int height,
|
||||
int value) {
|
||||
void (*SetRow)(uint8* dst, uint32 value, int pix);
|
||||
#if defined(HAS_SETROW_NEON)
|
||||
if (TestCpuFlag(kCpuHasNEON) &&
|
||||
IS_ALIGNED(width, 16) &&
|
||||
IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) {
|
||||
SetRow = SetRow32_NEON;
|
||||
} else
|
||||
#elif defined(HAS_SETROW_SSE2)
|
||||
if (TestCpuFlag(kCpuHasSSE2) &&
|
||||
IS_ALIGNED(width, 16) &&
|
||||
IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) {
|
||||
SetRow = SetRow32_SSE2;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SetRow = SetRow8_C;
|
||||
}
|
||||
|
||||
uint32 v32 = value | (value << 8) | (value << 16) | (value << 24);
|
||||
// Set plane
|
||||
for (int y = 0; y < height; ++y) {
|
||||
SetRow(dst_y, v32, width);
|
||||
dst_y += dst_stride_y;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a rectangle into I420
|
||||
int I420Rect(uint8* dst_y, int dst_stride_y,
|
||||
uint8* dst_u, int dst_stride_u,
|
||||
uint8* dst_v, int dst_stride_v,
|
||||
int x, int y,
|
||||
int width, int height,
|
||||
int value_y, int value_u, int value_v) {
|
||||
if (!dst_y || !dst_u || !dst_v ||
|
||||
width <= 0 || height == 0 ||
|
||||
x < 0 || y < 0 ||
|
||||
value_y < 0 || value_y > 255 ||
|
||||
value_u < 0 || value_u > 255 ||
|
||||
value_v < 0 || value_v > 255) {
|
||||
return -1;
|
||||
}
|
||||
// Negative height means invert the image.
|
||||
if (height < 0) {
|
||||
height = -height;
|
||||
int halfheight = (height + 1) >> 1;
|
||||
dst_y = dst_y + (height - 1) * dst_stride_y;
|
||||
dst_u = dst_u + (halfheight - 1) * dst_stride_u;
|
||||
dst_v = dst_v + (halfheight - 1) * dst_stride_v;
|
||||
dst_stride_y = -dst_stride_y;
|
||||
dst_stride_u = -dst_stride_u;
|
||||
dst_stride_v = -dst_stride_v;
|
||||
}
|
||||
|
||||
int halfwidth = (width + 1) >> 1;
|
||||
int halfheight = (height + 1) >> 1;
|
||||
uint8* start_y = dst_y + y * dst_stride_y + x;
|
||||
uint8* start_u = dst_u + (y / 2) * dst_stride_u + (x / 2);
|
||||
uint8* start_v = dst_v + (y / 2) * dst_stride_v + (x / 2);
|
||||
|
||||
I420SetPlane(start_y, dst_stride_y, width, height, value_y);
|
||||
I420SetPlane(start_u, dst_stride_u, halfwidth, halfheight, value_u);
|
||||
I420SetPlane(start_v, dst_stride_v, halfwidth, halfheight, value_v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(_M_IX86) && !defined(YUV_DISABLE_ASM)
|
||||
#define HAS_HALFROW_SSE2
|
||||
__declspec(naked)
|
||||
@ -1785,5 +1653,169 @@ int BG24ToARGB(const uint8* src_bg24, int src_stride_bg24,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// SetRows32 writes 'count' bytes using a 32 bit value repeated
|
||||
|
||||
#if defined(__ARM_NEON__) && !defined(YUV_DISABLE_ASM)
|
||||
#define HAS_SETROW_NEON
|
||||
static void SetRow32_NEON(uint8* dst, uint32 v32, int count) {
|
||||
asm volatile (
|
||||
"vdup.u32 q0, %2 \n" // duplicate 4 ints
|
||||
"1: \n"
|
||||
"vst1.u32 {q0}, [%0]! \n" // store
|
||||
"subs %1, %1, #16 \n" // 16 processed per loop
|
||||
"bhi 1b \n"
|
||||
: "+r"(dst), // %0
|
||||
"+r"(count) // %1
|
||||
: "r"(v32) // %2
|
||||
: "q0", "memory", "cc"
|
||||
);
|
||||
}
|
||||
|
||||
#elif defined(_M_IX86) && !defined(YUV_DISABLE_ASM)
|
||||
#define HAS_SETROW_SSE2
|
||||
__declspec(naked)
|
||||
static void SetRow32_SSE2(uint8* dst, uint32 v32, int count) {
|
||||
__asm {
|
||||
mov eax, [esp + 4] // dst
|
||||
movd xmm5, [esp + 8] // v32
|
||||
mov ecx, [esp + 12] // count
|
||||
pshufd xmm5, xmm5, 0
|
||||
|
||||
convertloop:
|
||||
movdqa [eax], xmm5
|
||||
lea eax, [eax + 16]
|
||||
sub ecx, 16
|
||||
ja convertloop
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#elif (defined(__x86_64__) || defined(__i386__)) && !defined(YUV_DISABLE_ASM)
|
||||
|
||||
#define HAS_SETROW_SSE2
|
||||
static void SetRow32_SSE2(uint8* dst, uint32 v32, int count) {
|
||||
asm volatile (
|
||||
"movd %2, %%xmm5 \n"
|
||||
"pshufd $0x0,%%xmm5,%%xmm5 \n"
|
||||
"1: \n"
|
||||
"movdqa %%xmm5,(%0) \n"
|
||||
"lea 0x10(%0),%0 \n"
|
||||
"sub $0x10,%1 \n"
|
||||
"ja 1b \n"
|
||||
: "+r"(dst), // %0
|
||||
"+r"(count) // %1
|
||||
: "r"(v32) // %2
|
||||
: "memory", "cc"
|
||||
#if defined(__SSE2__)
|
||||
, "xmm5"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void SetRow8_C(uint8* dst, uint32 v8, int count) {
|
||||
memset(dst, v8, count);
|
||||
}
|
||||
|
||||
static void SetPlane(uint8* dst_y, int dst_stride_y,
|
||||
int width, int height,
|
||||
uint32 value) {
|
||||
void (*SetRow)(uint8* dst, uint32 value, int pix);
|
||||
#if defined(HAS_SETROW_NEON)
|
||||
if (TestCpuFlag(kCpuHasNEON) &&
|
||||
IS_ALIGNED(width, 16) &&
|
||||
IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) {
|
||||
SetRow = SetRow32_NEON;
|
||||
} else
|
||||
#elif defined(HAS_SETROW_SSE2)
|
||||
if (TestCpuFlag(kCpuHasSSE2) &&
|
||||
IS_ALIGNED(width, 16) &&
|
||||
IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) {
|
||||
SetRow = SetRow32_SSE2;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SetRow = SetRow8_C;
|
||||
}
|
||||
|
||||
uint32 v32 = value | (value << 8) | (value << 16) | (value << 24);
|
||||
// Set plane
|
||||
for (int y = 0; y < height; ++y) {
|
||||
SetRow(dst_y, v32, width);
|
||||
dst_y += dst_stride_y;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a rectangle into I420
|
||||
int I420Rect(uint8* dst_y, int dst_stride_y,
|
||||
uint8* dst_u, int dst_stride_u,
|
||||
uint8* dst_v, int dst_stride_v,
|
||||
int x, int y,
|
||||
int width, int height,
|
||||
int value_y, int value_u, int value_v) {
|
||||
if (!dst_y || !dst_u || !dst_v ||
|
||||
width <= 0 || height <= 0 ||
|
||||
x < 0 || y < 0 ||
|
||||
value_y < 0 || value_y > 255 ||
|
||||
value_u < 0 || value_u > 255 ||
|
||||
value_v < 0 || value_v > 255) {
|
||||
return -1;
|
||||
}
|
||||
int halfwidth = (width + 1) >> 1;
|
||||
int halfheight = (height + 1) >> 1;
|
||||
uint8* start_y = dst_y + y * dst_stride_y + x;
|
||||
uint8* start_u = dst_u + (y / 2) * dst_stride_u + (x / 2);
|
||||
uint8* start_v = dst_v + (y / 2) * dst_stride_v + (x / 2);
|
||||
|
||||
SetPlane(start_y, dst_stride_y, width, height, value_y);
|
||||
SetPlane(start_u, dst_stride_u, halfwidth, halfheight, value_u);
|
||||
SetPlane(start_v, dst_stride_v, halfwidth, halfheight, value_v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// count measured in bytes
|
||||
static void SetRow32_C(uint8* dst, uint32 v8, int count) {
|
||||
uint32* d = reinterpret_cast<uint32*>(dst);
|
||||
for (int x = 0; x < count; x += 4) {
|
||||
*d++ = v8;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a rectangle into ARGB
|
||||
int ARGBRect(uint8* dst_argb, int dst_stride_argb,
|
||||
int x, int y,
|
||||
int width, int height,
|
||||
uint32 value) {
|
||||
if (!dst_argb ||
|
||||
width <= 0 || height <= 0 ||
|
||||
x < 0 || y < 0) {
|
||||
return -1;
|
||||
}
|
||||
void (*SetRow)(uint8* dst, uint32 value, int count);
|
||||
#if defined(HAS_SETROW_NEON)
|
||||
if (TestCpuFlag(kCpuHasNEON) &&
|
||||
IS_ALIGNED(width, 16) &&
|
||||
IS_ALIGNED(dst_argb, 16) && IS_ALIGNED(dst_stride_argb, 16)) {
|
||||
SetRow = SetRow32_NEON;
|
||||
} else
|
||||
#elif defined(HAS_SETROW_SSE2)
|
||||
if (TestCpuFlag(kCpuHasSSE2) &&
|
||||
IS_ALIGNED(width, 16) &&
|
||||
IS_ALIGNED(dst_argb, 16) && IS_ALIGNED(dst_stride_argb, 16)) {
|
||||
SetRow = SetRow32_SSE2;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SetRow = SetRow32_C;
|
||||
}
|
||||
int w32 = width << 2;
|
||||
for (int y = 0; y < height; ++y) {
|
||||
SetRow(dst_argb, value, w32);
|
||||
dst_argb += dst_stride_argb;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace libyuv
|
||||
|
||||
|
||||
@ -3060,7 +3060,6 @@ static void ScalePlaneDown2(int src_width, int src_height,
|
||||
assert(IS_ALIGNED(src_height, 2));
|
||||
void (*ScaleRowDown2)(const uint8* src_ptr, int src_stride,
|
||||
uint8* dst_ptr, int dst_width);
|
||||
|
||||
#if defined(HAS_SCALEROWDOWN2_NEON)
|
||||
if (TestCpuFlag(kCpuHasNEON) &&
|
||||
IS_ALIGNED(dst_width, 16)) {
|
||||
@ -3078,7 +3077,6 @@ static void ScalePlaneDown2(int src_width, int src_height,
|
||||
{
|
||||
ScaleRowDown2 = filtering ? ScaleRowDown2Int_C : ScaleRowDown2_C;
|
||||
}
|
||||
|
||||
for (int y = 0; y < dst_height; ++y) {
|
||||
ScaleRowDown2(src_ptr, src_stride, dst_ptr, dst_width);
|
||||
src_ptr += (src_stride << 1);
|
||||
@ -3101,7 +3099,6 @@ static void ScalePlaneDown4(int src_width, int src_height,
|
||||
assert(IS_ALIGNED(src_height, 4));
|
||||
void (*ScaleRowDown4)(const uint8* src_ptr, int src_stride,
|
||||
uint8* dst_ptr, int dst_width);
|
||||
|
||||
#if defined(HAS_SCALEROWDOWN4_NEON)
|
||||
if (TestCpuFlag(kCpuHasNEON) &&
|
||||
IS_ALIGNED(dst_width, 4)) {
|
||||
@ -3119,7 +3116,6 @@ static void ScalePlaneDown4(int src_width, int src_height,
|
||||
{
|
||||
ScaleRowDown4 = filtering ? ScaleRowDown4Int_C : ScaleRowDown4_C;
|
||||
}
|
||||
|
||||
for (int y = 0; y < dst_height; ++y) {
|
||||
ScaleRowDown4(src_ptr, src_stride, dst_ptr, dst_width);
|
||||
src_ptr += (src_stride << 2);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user