Commit 58cb5349 authored by Frank Barchard's avatar Frank Barchard

Fix memory overwrite in YUY2ToNV12 odd wdiths

When width was odd Y channel wrote an extra pixel.
This change splits the Y from UV into a temporary
buffer and memcpy's to the destination.  Performance
is slower.

Was
YUY2ToNV12_Any (307 ms)
YUY2ToNV12_Unaligned (213 ms)
TestYUY2ToNV12 (181 ms)
YUY2ToNV12_Opt (177 ms)
YUY2ToNV12_Invert (177 ms)

Npw
YUY2ToNV12_Any (300 ms)
YUY2ToNV12_Unaligned (226 ms)
YUY2ToNV12_Invert (206 ms)
TestYUY2ToNV12 (184 ms)
YUY2ToNV12_Opt (181 ms)
TBR=harryjin@google.com
BUG=libyuv:545

Review URL: https://codereview.chromium.org/1593833002 .
parent 8377c798
Name: libyuv
URL: http://code.google.com/p/libyuv/
Version: 1566
Version: 1567
License: BSD
License File: LICENSE
......
......@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 1566
#define LIBYUV_VERSION 1567
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
......@@ -2424,6 +2424,9 @@ int ARGBCopyYToAlpha(const uint8* src_y, int src_stride_y,
return 0;
}
// TODO(fbarchard): Consider if width is even Y channel can be split
// directly. A SplitUVRow_Odd function could copy the remaining chroma.
LIBYUV_API
int YUY2ToNV12(const uint8* src_yuy2, int src_stride_yuy2,
uint8* dst_y, int dst_stride_y,
......@@ -2498,22 +2501,24 @@ int YUY2ToNV12(const uint8* src_yuy2, int src_stride_yuy2,
{
int awidth = halfwidth * 2;
// 2 rows of uv
align_buffer_64(rows, awidth * 2);
// row of y and 2 rows of uv
align_buffer_64(rows, awidth * 3);
for (y = 0; y < height - 1; y += 2) {
// Split Y from UV.
SplitUVRow(src_yuy2, dst_y, rows, awidth);
SplitUVRow(src_yuy2 + src_stride_yuy2, dst_y + dst_stride_y,
rows + awidth, awidth);
InterpolateRow(dst_uv, rows, awidth, awidth, 128);
SplitUVRow(src_yuy2, rows, rows + awidth, awidth);
memcpy(dst_y, rows, width);
SplitUVRow(src_yuy2 + src_stride_yuy2, rows, rows + awidth * 2, awidth);
memcpy(dst_y + dst_stride_y, rows, width);
InterpolateRow(dst_uv, rows + awidth, awidth, awidth, 128);
src_yuy2 += src_stride_yuy2 * 2;
dst_y += dst_stride_y * 2;
dst_uv += dst_stride_uv;
}
if (height & 1) {
// Split Y from UV.
SplitUVRow(src_yuy2, dst_y, dst_uv, awidth);
SplitUVRow(src_yuy2, rows, dst_uv, awidth);
memcpy(dst_y, rows, width);
}
free_aligned_buffer_64(rows);
}
......@@ -2594,22 +2599,24 @@ int UYVYToNV12(const uint8* src_uyvy, int src_stride_uyvy,
{
int awidth = halfwidth * 2;
// 2 rows of uv
align_buffer_64(rows, awidth * 2);
// row of y and 2 rows of uv
align_buffer_64(rows, awidth * 3);
for (y = 0; y < height - 1; y += 2) {
// Split Y from UV.
SplitUVRow(src_uyvy, rows, dst_y, awidth);
SplitUVRow(src_uyvy + src_stride_uyvy, rows + awidth,
dst_y + dst_stride_y, awidth);
InterpolateRow(dst_uv, rows, awidth, awidth, 128);
SplitUVRow(src_uyvy, rows + awidth, rows, awidth);
memcpy(dst_y, rows, width);
SplitUVRow(src_uyvy + src_stride_uyvy, rows + awidth * 2, rows, awidth);
memcpy(dst_y + dst_stride_y, rows, width);
InterpolateRow(dst_uv, rows + awidth, awidth, awidth, 128);
src_uyvy += src_stride_uyvy * 2;
dst_y += dst_stride_y * 2;
dst_uv += dst_stride_uv;
}
if (height & 1) {
// Split Y from UV.
SplitUVRow(src_uyvy, dst_uv, dst_y, awidth);
SplitUVRow(src_uyvy, dst_uv, rows, awidth);
memcpy(dst_y, rows, width);
}
free_aligned_buffer_64(rows);
}
......
......@@ -790,12 +790,12 @@ TESTATOPLANAR(UYVY, 2, 1, I422, 2, 1, 2)
TESTATOPLANAR(I400, 1, 1, I420, 2, 2, 2)
TESTATOPLANAR(J400, 1, 1, J420, 2, 2, 2)
#define TESTATOBIPLANARI(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
W1280, N, NEG, OFF) \
#define TESTATOBIPLANARI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y,\
W1280, N, NEG, OFF) \
TEST_F(LibYUVConvertTest, FMT_A##To##FMT_PLANAR##N) { \
const int kWidth = ((W1280) > 0) ? (W1280) : 1; \
const int kHeight = benchmark_height_; \
const int kStride = (kWidth * 8 * BPP_A + 7) / 8; \
const int kStride = SUBSAMPLE(kWidth, SUB_A) * BPP_A; \
const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \
align_buffer_64(src_argb, kStride * kHeight + OFF); \
align_buffer_64(dst_y_c, kWidth * kHeight); \
......@@ -849,20 +849,20 @@ TEST_F(LibYUVConvertTest, FMT_A##To##FMT_PLANAR##N) { \
free_aligned_buffer_64(src_argb); \
}
#define TESTATOBIPLANAR(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \
TESTATOBIPLANARI(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
#define TESTATOBIPLANAR(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \
TESTATOBIPLANARI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
benchmark_width_ - 4, _Any, +, 0) \
TESTATOBIPLANARI(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
TESTATOBIPLANARI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
benchmark_width_, _Unaligned, +, 1) \
TESTATOBIPLANARI(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
TESTATOBIPLANARI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
benchmark_width_, _Invert, -, 0) \
TESTATOBIPLANARI(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
TESTATOBIPLANARI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
benchmark_width_, _Opt, +, 0)
TESTATOBIPLANAR(ARGB, 4, NV12, 2, 2)
TESTATOBIPLANAR(ARGB, 4, NV21, 2, 2)
TESTATOBIPLANAR(YUY2, 2, NV12, 2, 2)
TESTATOBIPLANAR(UYVY, 2, NV12, 2, 2)
TESTATOBIPLANAR(ARGB, 1, 4, NV12, 2, 2)
TESTATOBIPLANAR(ARGB, 1, 4, NV21, 2, 2)
TESTATOBIPLANAR(YUY2, 2, 4, NV12, 2, 2)
TESTATOBIPLANAR(UYVY, 2, 4, NV12, 2, 2)
#define TESTATOBI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, \
FMT_B, BPP_B, STRIDE_B, HEIGHT_B, \
......
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