From 738dfa0307cc158b5e10c58ecab335069bd8b0e6 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Tue, 10 Feb 2015 02:18:38 +0000 Subject: [PATCH] Support odd widths for NV12 format when cropping vertically. BUG=400 TESTED=CropNV12 R=harryjin@google.com Review URL: https://webrtc-codereview.appspot.com/39009004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@1272 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- README.chromium | 2 +- include/libyuv/version.h | 2 +- source/convert_to_i420.cc | 6 ++++-- unit_test/convert_test.cc | 9 +++++---- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.chromium b/README.chromium index a67b10d8b..4debabb72 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 1271 +Version: 1272 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 7bb68e17a..e4314a6e6 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1271 +#define LIBYUV_VERSION 1272 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/source/convert_to_i420.cc b/source/convert_to_i420.cc index 1f6a92e09..ab25f5abf 100644 --- a/source/convert_to_i420.cc +++ b/source/convert_to_i420.cc @@ -183,7 +183,8 @@ int ConvertToI420(const uint8* sample, // Biplanar formats case FOURCC_NV12: src = sample + (src_width * crop_y + crop_x); - src_uv = sample + aligned_src_width * (src_height + crop_y / 2) + crop_x; + src_uv = sample + (src_width * src_height) + + ((crop_y / 2) * aligned_src_width) + ((crop_x / 2) * 2); r = NV12ToI420Rotate(src, src_width, src_uv, aligned_src_width, y, y_stride, @@ -193,7 +194,8 @@ int ConvertToI420(const uint8* sample, break; case FOURCC_NV21: src = sample + (src_width * crop_y + crop_x); - src_uv = sample + aligned_src_width * (src_height + crop_y / 2) + crop_x; + src_uv = sample + (src_width * src_height) + + ((crop_y / 2) * aligned_src_width) + ((crop_x / 2) * 2); // Call NV12 but with u and v parameters swapped. r = NV12ToI420Rotate(src, src_width, src_uv, aligned_src_width, diff --git a/unit_test/convert_test.cc b/unit_test/convert_test.cc index 42bd7a371..71cdb8de6 100644 --- a/unit_test/convert_test.cc +++ b/unit_test/convert_test.cc @@ -1135,7 +1135,7 @@ TEST_F(libyuvTest, CropNV12) { const int crop_y = ((benchmark_height_ - (benchmark_height_ * 360 / 480)) / 2 + 1) & ~1; const int kDestWidth = benchmark_width_; - const int kDestHeight = benchmark_height_ - crop_y * 2;; + const int kDestHeight = benchmark_height_ - crop_y * 2; const int sample_size = kWidth * kHeight + SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y) * 2; @@ -1162,8 +1162,8 @@ TEST_F(libyuvTest, CropNV12) { for (int i = 0; i < kHeight * kWidth; ++i) { src_y[i] = (random() & 0xff); } - for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y) * - SUBSAMPLE(kWidth, SUBSAMP_X) * 2; ++i) { + for (int i = 0; i < (SUBSAMPLE(kHeight, SUBSAMP_Y) * + SUBSAMPLE(kWidth, SUBSAMP_X)) * 2; ++i) { src_uv[i] = (random() & 0xff); } memset(dst_y, 1, kDestWidth * kDestHeight); @@ -1187,7 +1187,8 @@ TEST_F(libyuvTest, CropNV12) { libyuv::kRotate0, libyuv::FOURCC_NV12); NV12ToI420(src_y + crop_y * kWidth, kWidth, - src_uv + (crop_y / 2) * kWidth, kWidth, + src_uv + (crop_y / 2) * SUBSAMPLE(kWidth, SUBSAMP_X) * 2, + SUBSAMPLE(kWidth, SUBSAMP_X) * 2, dst_y, kDestWidth, dst_u, SUBSAMPLE(kDestWidth, SUBSAMP_X), dst_v, SUBSAMPLE(kDestWidth, SUBSAMP_X),