From c4a70492c0f2f5b8da259046b951ae0a141bc60e Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Wed, 14 Aug 2013 16:16:39 +0000 Subject: [PATCH] blur unittest and fix for negative height BUG=256 TEST=*Blur* R=ryanpetrie@google.com Review URL: https://webrtc-codereview.appspot.com/2027005 git-svn-id: http://libyuv.googlecode.com/svn/trunk@757 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- README.chromium | 2 +- include/libyuv/row.h | 11 +++--- include/libyuv/version.h | 2 +- source/planar_functions.cc | 15 +++++--- source/row_posix.cc | 2 +- unit_test/planar_test.cc | 72 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 14 deletions(-) diff --git a/README.chromium b/README.chromium index be320d70e..bdcd05bf7 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 754 +Version: 757 License: BSD License File: LICENSE diff --git a/include/libyuv/row.h b/include/libyuv/row.h index e0211992f..a782c1001 100644 --- a/include/libyuv/row.h +++ b/include/libyuv/row.h @@ -54,13 +54,13 @@ extern "C" { #define HAS_CUMULATIVESUMTOAVERAGEROW_SSE2 // Conversions: -#define HAS_ARGBTOBAYERROW_SSSE3 #define HAS_ARGBSHUFFLEROW_SSSE3 -#define HAS_COPYROW_X86 -#define HAS_COPYROW_ERMS -#define HAS_FIXEDDIV_X86 -#define HAS_ARGBTOYROW_SSSE3 +#define HAS_ARGBTOBAYERROW_SSSE3 #define HAS_ARGBTOYJROW_SSSE3 +#define HAS_ARGBTOYROW_SSSE3 +#define HAS_COPYROW_ERMS +#define HAS_COPYROW_X86 +#define HAS_FIXEDDIV_X86 #define HAS_I400TOARGBROW_SSE2 #define HAS_SETROW_X86 #endif @@ -129,7 +129,6 @@ extern "C" { // Effects: #define HAS_ARGBAFFINEROW_SSE2 #define HAS_ARGBUNATTENUATEROW_SSE2 -#define HAS_CUMULATIVESUMTOAVERAGEROW_SSE2 #define HAS_INTERPOLATEROW_SSE2 #define HAS_INTERPOLATEROW_SSSE3 #define HAS_SOBELROW_SSE2 diff --git a/include/libyuv/version.h b/include/libyuv/version.h index de3df3fc4..598d1a07e 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 754 +#define LIBYUV_VERSION 757 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/source/planar_functions.cc b/source/planar_functions.cc index 93a1603ed..8456c5043 100644 --- a/source/planar_functions.cc +++ b/source/planar_functions.cc @@ -1528,14 +1528,19 @@ int ARGBBlur(const uint8* src_argb, int src_stride_argb, if (!src_argb || !dst_argb || width <= 0 || height == 0) { return -1; } + if (height < 0) { + height = -height; + src_argb = src_argb + (height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } void (*ComputeCumulativeSumRow)(const uint8* row, int32* cumsum, const int32* previous_cumsum, int width) = ComputeCumulativeSumRow_C; - void (*CUMULATIVESUMTOAVERAGEROW)(const int32* topleft, const int32* botleft, + void (*CumulativeSumToAverageRow)(const int32* topleft, const int32* botleft, int width, int area, uint8* dst, int count) = CumulativeSumToAverageRow_C; #if defined(HAS_CUMULATIVESUMTOAVERAGEROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { ComputeCumulativeSumRow = ComputeCumulativeSumRow_SSE2; - CUMULATIVESUMTOAVERAGEROW = CumulativeSumToAverageRow_SSE2; + CumulativeSumToAverageRow = CumulativeSumToAverageRow_SSE2; } #endif // Compute enough CumulativeSum for first row to be blurred. After this @@ -1580,7 +1585,7 @@ int ARGBBlur(const uint8* src_argb, int src_stride_argb, int boxwidth = radius * 4; int x; for (x = 0; x < radius + 1; ++x) { - CUMULATIVESUMTOAVERAGEROW(cumsum_top_row, cumsum_bot_row, + CumulativeSumToAverageRow(cumsum_top_row, cumsum_bot_row, boxwidth, area, &dst_argb[x * 4], 1); area += (bot_y - top_y); boxwidth += 4; @@ -1588,14 +1593,14 @@ int ARGBBlur(const uint8* src_argb, int src_stride_argb, // Middle unclipped. int n = (width - 1) - radius - x + 1; - CUMULATIVESUMTOAVERAGEROW(cumsum_top_row, cumsum_bot_row, + CumulativeSumToAverageRow(cumsum_top_row, cumsum_bot_row, boxwidth, area, &dst_argb[x * 4], n); // Right clipped. for (x += n; x <= width - 1; ++x) { area -= (bot_y - top_y); boxwidth -= 4; - CUMULATIVESUMTOAVERAGEROW(cumsum_top_row + (x - radius - 1) * 4, + CumulativeSumToAverageRow(cumsum_top_row + (x - radius - 1) * 4, cumsum_bot_row + (x - radius - 1) * 4, boxwidth, area, &dst_argb[x * 4], 1); } diff --git a/source/row_posix.cc b/source/row_posix.cc index 03c7b268c..27802296f 100644 --- a/source/row_posix.cc +++ b/source/row_posix.cc @@ -4668,7 +4668,7 @@ void CumulativeSumToAverageRow_SSE2(const int32* topleft, const int32* botleft, MEMOPREG(paddd,0x10,1,4,4,xmm1) // paddd 0x10(%1,%4,4),%%xmm1 MEMOPREG(paddd,0x20,1,4,4,xmm2) // paddd 0x20(%1,%4,4),%%xmm2 MEMOPREG(paddd,0x30,1,4,4,xmm3) // paddd 0x30(%1,%4,4),%%xmm3 - "lea "MEMLEA(0x40,0)",%0 \n" + "lea "MEMLEA(0x40,1)",%1 \n" "cvtdq2ps %%xmm0,%%xmm0 \n" "cvtdq2ps %%xmm1,%%xmm1 \n" "mulps %%xmm4,%%xmm0 \n" diff --git a/unit_test/planar_test.cc b/unit_test/planar_test.cc index a1da459c4..b3984dbd4 100644 --- a/unit_test/planar_test.cc +++ b/unit_test/planar_test.cc @@ -1584,4 +1584,76 @@ TEST_F(libyuvTest, ARGBSobelXY_Opt) { EXPECT_EQ(0, max_diff); } +static int TestBlur(int width, int height, int benchmark_iterations, + int invert, int off, int radius) { + if (width < 1) { + width = 1; + } + const int kBpp = 4; + const int kStride = (width * kBpp + 15) & ~15; + align_buffer_64(src_argb_a, kStride * height + off); + align_buffer_64(dst_cumsum, width * height * 16); + align_buffer_64(dst_argb_c, kStride * height); + align_buffer_64(dst_argb_opt, kStride * height); + srandom(time(NULL)); + for (int i = 0; i < kStride * height; ++i) { + src_argb_a[i + off] = (random() & 0xff); + } + memset(dst_cumsum, 0, width * height * 16); + memset(dst_argb_c, 0, kStride * height); + memset(dst_argb_opt, 0, kStride * height); + + MaskCpuFlags(0); + ARGBBlur(src_argb_a + off, kStride, + dst_argb_c, kStride, + reinterpret_cast(dst_cumsum), width * 4, + width, invert * height, radius); + MaskCpuFlags(-1); + for (int i = 0; i < benchmark_iterations; ++i) { + ARGBBlur(src_argb_a + off, kStride, + dst_argb_opt, kStride, + reinterpret_cast(dst_cumsum), width * 4, + width, invert * height, radius); + } + int max_diff = 0; + for (int i = 0; i < kStride * height; ++i) { + int abs_diff = + abs(static_cast(dst_argb_c[i]) - + static_cast(dst_argb_opt[i])); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + free_aligned_buffer_64(src_argb_a) + free_aligned_buffer_64(dst_cumsum) + free_aligned_buffer_64(dst_argb_c) + free_aligned_buffer_64(dst_argb_opt) + return max_diff; +} + +static const int kBlurSize = 13; +TEST_F(libyuvTest, ARGBBlur_Any) { + int max_diff = TestBlur(benchmark_width_ - 1, benchmark_height_, + benchmark_iterations_, +1, 0, kBlurSize); + EXPECT_LE(max_diff, 1); +} + +TEST_F(libyuvTest, ARGBBlur_Unaligned) { + int max_diff = TestBlur(benchmark_width_, benchmark_height_, + benchmark_iterations_, +1, 1, kBlurSize); + EXPECT_LE(max_diff, 1); +} + +TEST_F(libyuvTest, ARGBBlur_Invert) { + int max_diff = TestBlur(benchmark_width_, benchmark_height_, + benchmark_iterations_, -1, 0, kBlurSize); + EXPECT_LE(max_diff, 1); +} + +TEST_F(libyuvTest, ARGBBlur_Opt) { + int max_diff = TestBlur(benchmark_width_, benchmark_height_, + benchmark_iterations_, +1, 0, kBlurSize); + EXPECT_LE(max_diff, 1); +} + } // namespace libyuv