Commit 12d04833 authored by fbarchard@google.com's avatar fbarchard@google.com

I420Mirror rewrite, I420Copy movdqa, I444To420, I420To422

Review URL: http://webrtc-codereview.appspot.com/267025

git-svn-id: http://libyuv.googlecode.com/svn/trunk@89 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent 1616c315
Name: libyuv
URL: http://code.google.com/p/libyuv/
Version: 86
Version: 89
License: BSD
License File: LICENSE
......
......@@ -46,6 +46,12 @@ int I420ToYUY2(const uint8* src_y, int src_stride_y,
uint8* dst_frame, int dst_stride_frame,
int width, int height);
int I422ToYUY2(const uint8* src_y, int src_stride_y,
const uint8* src_u, int src_stride_u,
const uint8* src_v, int src_stride_v,
uint8* dst_frame, int dst_stride_frame,
int width, int height);
int I420ToUYVY(const uint8* src_y, int src_stride_y,
const uint8* src_u, int src_stride_u,
const uint8* src_v, int src_stride_v,
......
......@@ -50,6 +50,24 @@ int I422ToI420(const uint8* src_y, int src_stride_y,
uint8* dst_v, int dst_stride_v,
int width, int height);
// Convert I422 to I420.
int I420ToI422(const uint8* src_y, int src_stride_y,
const uint8* src_u, int src_stride_u,
const uint8* src_v, int src_stride_v,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v,
int width, int height);
// Convert I444 to I420.
int I444ToI420(const uint8* src_y, int src_stride_y,
const uint8* src_u, int src_stride_u,
const uint8* src_v, int src_stride_v,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v,
int width, int height);
// Convert NV12 to I420. Also used for NV21.
int NV12ToI420(const uint8* src_y, int src_stride_y,
const uint8* src_uv, int src_stride_uv,
......
......@@ -1057,22 +1057,13 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
case FOURCC_RGGB:
case FOURCC_GRBG:
case FOURCC_GBRG:
// TODO(fbarchard): We could support cropping by odd numbers by
// adjusting fourcc.
// TODO(fbarchard): Support cropping by odd numbers by adjusting fourcc.
src = sample + (src_width * crop_y + crop_x);
BayerRGBToI420(src, src_width, format,
y, y_stride, u, u_stride, v, v_stride,
dst_width, inv_dst_height);
break;
// Biplanar formats
case FOURCC_M420:
src = sample + (src_width * crop_y) * 12 / 8 + crop_x;
M420ToI420(src, src_width,
y, y_stride,
u, u_stride,
v, v_stride,
dst_width, inv_dst_height);
break;
case FOURCC_NV12:
src = sample + (src_width * crop_y + crop_x);
src_uv = sample + aligned_src_width * (src_height + crop_y / 2) + crop_x;
......@@ -1094,6 +1085,14 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
v, v_stride,
dst_width, inv_dst_height, rotation);
break;
case FOURCC_M420:
src = sample + (src_width * crop_y) * 12 / 8 + crop_x;
M420ToI420(src, src_width,
y, y_stride,
u, u_stride,
v, v_stride,
dst_width, inv_dst_height);
break;
case FOURCC_Q420:
src = sample + (src_width + aligned_src_width * 2) * crop_y + crop_x;
src_uv = sample + (src_width + aligned_src_width * 2) * crop_y +
......@@ -1133,6 +1132,33 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
dst_width, inv_dst_height, rotation);
break;
}
// Triplanar formats
case FOURCC_I422:
case FOURCC_YV16: {
const uint8* src_y = sample + (src_width * crop_y + crop_x);
const uint8* src_u;
const uint8* src_v;
int halfwidth = (src_width + 1) / 2;
if (format == FOURCC_I422) {
src_u = sample + src_width * abs_src_height +
halfwidth * crop_y + crop_x / 2;
src_v = sample + src_width * abs_src_height +
halfwidth * (abs_src_height + crop_y) + crop_x / 2;
} else {
src_v = sample + src_width * abs_src_height +
halfwidth * crop_y + crop_x / 2;
src_u = sample + src_width * abs_src_height +
halfwidth * (abs_src_height + crop_y) + crop_x / 2;
}
I422ToI420(src_y, src_width,
src_u, halfwidth,
src_v, halfwidth,
y, y_stride,
u, u_stride,
v, v_stride,
dst_width, inv_dst_height);
break;
}
// Formats not supported
case FOURCC_MJPG:
default:
......
This diff is collapsed.
......@@ -20,10 +20,6 @@ namespace libyuv {
#if (defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)) && \
!defined(YUV_DISABLE_ASM)
// Note static const preferred, but gives internal compiler error on gcc 4.2
// Shuffle table for reversing the bytes.
uvec8 kShuffleReverse = {
15u, 14u, 13u, 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u
};
// Shuffle table for reversing the bytes of UV channels.
uvec8 kShuffleReverseUV = {
14u, 12u, 10u, 8u, 6u, 4u, 2u, 0u, 15u, 13u, 11u, 9u, 7u, 5u, 3u, 1u
......@@ -31,7 +27,6 @@ uvec8 kShuffleReverseUV = {
#endif
typedef void (*reverse_uv_func)(const uint8*, uint8*, uint8*, int);
typedef void (*reverse_func)(const uint8*, uint8*, int);
typedef void (*rotate_uv_wx8_func)(const uint8*, int,
uint8*, int,
uint8*, int, int);
......@@ -844,71 +839,10 @@ void RotatePlane270(const uint8* src, int src_stride,
TransposePlane(src, src_stride, dst, dst_stride, width, height);
}
static void ReverseRow_C(const uint8* src, uint8* dst, int width) {
int i;
src += width - 1;
for (i = 0; i < width; ++i) {
dst[i] = src[0];
--src;
}
}
#if defined(_M_IX86) && !defined(YUV_DISABLE_ASM)
#define HAS_REVERSE_ROW_SSSE3
__declspec(naked)
static void ReverseRow_SSSE3(const uint8* src, uint8* dst, int width) {
__asm {
mov eax, [esp + 4] // src
mov edx, [esp + 8] // dst
mov ecx, [esp + 12] // width
movdqa xmm5, kShuffleReverse
lea eax, [eax + ecx - 16]
convertloop:
movdqa xmm0, [eax]
lea eax, [eax - 16]
pshufb xmm0, xmm5
movdqa [edx], xmm0
lea edx, [edx + 16]
sub ecx, 16
ja convertloop
ret
}
}
#elif (defined(__i386__) || defined(__x86_64__)) && \
!defined(YUV_DISABLE_ASM)
#define HAS_REVERSE_ROW_SSSE3
static void ReverseRow_SSSE3(const uint8* src, uint8* dst, int width) {
intptr_t temp_width = static_cast<intptr_t>(width);
asm volatile (
"movdqa %3,%%xmm5 \n"
"lea -0x10(%0,%2,1),%0 \n"
"1: \n"
"movdqa (%0),%%xmm0 \n"
"lea -0x10(%0),%0 \n"
"pshufb %%xmm5,%%xmm0 \n"
"movdqa %%xmm0,(%1) \n"
"lea 0x10(%1),%1 \n"
"sub $0x10,%2 \n"
"ja 1b \n"
: "+r"(src), // %0
"+r"(dst), // %1
"+r"(temp_width) // %2
: "m"(kShuffleReverse) // %3
: "memory", "cc"
#if defined(__SSE2__)
, "xmm0", "xmm5"
#endif
);
}
#endif
void RotatePlane180(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height) {
int i;
reverse_func ReverseRow;
void (*ReverseRow)(const uint8* src, uint8* dst, int width);
#if defined(HAS_REVERSE_ROW_NEON)
if (TestCpuFlag(kCpuHasNEON)) {
ReverseRow = ReverseRow_NEON;
......@@ -925,10 +859,11 @@ void RotatePlane180(const uint8* src, int src_stride,
{
ReverseRow = ReverseRow_C;
}
// Rotate by 180 is a mirror and vertical flip
src += src_stride * (height - 1);
for (i = 0; i < height; ++i) {
for (int y = 0; y < height; ++y) {
ReverseRow(src, dst, width);
src -= src_stride;
dst += dst_stride;
......
......@@ -63,6 +63,12 @@ void FastConvertYUVToABGRRow_NEON(const uint8* y_buf,
#define HAS_FASTCONVERTYUVTOBGRAROW_SSSE3
#define HAS_FASTCONVERTYUVTOABGRROW_SSSE3
#define HAS_FASTCONVERTYUV444TOARGBROW_SSSE3
#define HAS_REVERSE_ROW_SSSE3
#endif
// The following are available on Neon platforms
#if defined(__ARM_NEON__) && !defined(YUV_DISABLE_ASM)
#define HAS_REVERSE_ROW_NEON
#endif
extern "C" {
......@@ -89,6 +95,14 @@ void RGB24ToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
void RAWToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
uint8* dst_u, uint8* dst_v, int width);
#endif
#ifdef HAS_REVERSE_ROW_SSSE3
void ReverseRow_SSSE3(const uint8* src, uint8* dst, int width);
#endif
#ifdef HAS_REVERSE_ROW_NEON
void ReverseRow_NEON(const uint8* src, uint8* dst, int width);
#endif
void ReverseRow_C(const uint8* src, uint8* dst, int width);
void ARGBToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
void BGRAToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
void ABGRToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
......
......@@ -335,4 +335,12 @@ void FastConvertYToARGBRow_C(const uint8* y_buf,
}
}
void ReverseRow_C(const uint8* src, uint8* dst, int width) {
src += width - 1;
for (int i = 0; i < width; ++i) {
dst[i] = src[0];
--src;
}
}
} // extern "C"
......@@ -634,4 +634,36 @@ void BGRAToUVRow_SSSE3(const uint8* src_argb, int src_stride_argb,
}
#endif
#ifdef HAS_REVERSE_ROW_SSSE3
// Shuffle table for reversing the bytes.
static const uvec8 kShuffleReverse = {
15u, 14u, 13u, 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u
};
void ReverseRow_SSSE3(const uint8* src, uint8* dst, int width) {
intptr_t temp_width = static_cast<intptr_t>(width);
asm volatile (
"movdqa %3,%%xmm5 \n"
"lea -0x10(%0,%2,1),%0 \n"
"1: \n"
"movdqa (%0),%%xmm0 \n"
"lea -0x10(%0),%0 \n"
"pshufb %%xmm5,%%xmm0 \n"
"movdqa %%xmm0,(%1) \n"
"lea 0x10(%1),%1 \n"
"sub $0x10,%2 \n"
"ja 1b \n"
: "+r"(src), // %0
"+r"(dst), // %1
"+r"(temp_width) // %2
: "m"(kShuffleReverse) // %3
: "memory", "cc"
#if defined(__SSE2__)
, "xmm0", "xmm5"
#endif
);
}
#endif
} // extern "C"
......@@ -814,7 +814,34 @@ void FastConvertYToARGBRow_SSE2(const uint8* y_buf,
}
}
#endif
#endif
#ifdef HAS_REVERSE_ROW_SSSE3
// Shuffle table for reversing the bytes.
static const uvec8 kShuffleReverse = {
15u, 14u, 13u, 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u
};
__declspec(naked)
void ReverseRow_SSSE3(const uint8* src, uint8* dst, int width) {
__asm {
mov eax, [esp + 4] // src
mov edx, [esp + 8] // dst
mov ecx, [esp + 12] // width
movdqa xmm5, kShuffleReverse
lea eax, [eax + ecx - 16]
convertloop:
movdqa xmm0, [eax]
lea eax, [eax - 16]
pshufb xmm0, xmm5
movdqa [edx], xmm0
lea edx, [edx + 16]
sub ecx, 16
ja convertloop
ret
}
}
#endif
} // extern "C"
......
......@@ -42,6 +42,8 @@ void SetUseReferenceImpl(bool use) {
use_reference_impl_ = use;
}
// ScaleRowDown2Int also used by planar functions
/**
* NEON downscalers with interpolation.
*
......@@ -624,8 +626,8 @@ static void ScaleRowDown2_SSE2(const uint8* src_ptr, int src_stride,
// Blends 32x2 rectangle to 16x1.
// Alignment requirement: src_ptr 16 byte aligned, dst_ptr 16 byte aligned.
__declspec(naked)
static void ScaleRowDown2Int_SSE2(const uint8* src_ptr, int src_stride,
uint8* dst_ptr, int dst_width) {
void ScaleRowDown2Int_SSE2(const uint8* src_ptr, int src_stride,
uint8* dst_ptr, int dst_width) {
__asm {
push esi
mov eax, [esp + 4 + 4] // src_ptr
......@@ -2778,8 +2780,8 @@ static void ScaleRowDown2_C(const uint8* src_ptr, int,
}
}
static void ScaleRowDown2Int_C(const uint8* src_ptr, int src_stride,
uint8* dst, int dst_width) {
void ScaleRowDown2Int_C(const uint8* src_ptr, int src_stride,
uint8* dst, int dst_width) {
for (int x = 0; x < dst_width; ++x) {
*dst++ = (src_ptr[0] + src_ptr[1] +
src_ptr[src_stride] + src_ptr[src_stride + 1] + 2) >> 2;
......@@ -3068,8 +3070,9 @@ static void ScalePlaneDown2(int src_width, int src_height,
#endif
#if defined(HAS_SCALEROWDOWN2_SSE2)
if (TestCpuFlag(kCpuHasSSE2) &&
(dst_width % 16 == 0) && IS_ALIGNED(src_ptr, 16) &&
IS_ALIGNED(dst_ptr, 16)) {
(dst_width % 16 == 0) &&
IS_ALIGNED(src_ptr, 16) && (src_stride % 16 == 0) &&
IS_ALIGNED(dst_ptr, 16) && (dst_stride % 16 == 0)) {
ScaleRowDown2 = filtering ? ScaleRowDown2Int_SSE2 : ScaleRowDown2_SSE2;
} else
#endif
......
......@@ -38,7 +38,9 @@ namespace libyuv {
enum FourCC {
// Canonical fourcc codes used in our code.
FOURCC_I420 = FOURCC('I', '4', '2', '0'),
FOURCC_I422 = FOURCC('I', '4', '2', '2'),
FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'),
FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'),
FOURCC_YUY2 = FOURCC('Y', 'U', 'Y', '2'),
FOURCC_UYVY = FOURCC('U', 'Y', 'V', 'Y'),
FOURCC_M420 = FOURCC('M', '4', '2', '0'),
......@@ -62,6 +64,7 @@ enum FourCC {
// equivalents by CanonicalFourCC().
FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'), // Alias for I420
FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Alias for I420
FOURCC_YU16 = FOURCC('Y', 'U', '1', '6'), // Alias for I422
FOURCC_YUYV = FOURCC('Y', 'U', 'Y', 'V'), // Alias for YUY2
FOURCC_YUVS = FOURCC('y', 'u', 'v', 's'), // Alias for YUY2 on Mac
FOURCC_HDYC = FOURCC('H', 'D', 'Y', 'C'), // Alias for UYVY
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment