Commit ae9a1388 authored by fbarchard@google.com's avatar fbarchard@google.com

Use malloc for row buffers in rotate

BUG=296
TESTED=rotate_test
R=tpsiaki@google.com

Review URL: https://webrtc-codereview.appspot.com/6329004

git-svn-id: http://libyuv.googlecode.com/svn/trunk@922 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent cf17f0cd
Name: libyuv Name: libyuv
URL: http://code.google.com/p/libyuv/ URL: http://code.google.com/p/libyuv/
Version: 921 Version: 922
License: BSD License: BSD
License File: LICENSE License File: LICENSE
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "libyuv/basic_types.h" #include "libyuv/basic_types.h"
#include <stdlib.h> // For malloc.
#ifdef __cplusplus #ifdef __cplusplus
namespace libyuv { namespace libyuv {
extern "C" { extern "C" {
...@@ -26,6 +28,18 @@ extern "C" { ...@@ -26,6 +28,18 @@ extern "C" {
#endif #endif
#define IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a) - 1))) #define IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a) - 1)))
// TODO (fbarchard): Port to C.
#define align_buffer_64(var, size) \
uint8* var; \
uint8* var##_mem; \
var##_mem = reinterpret_cast<uint8*>(malloc((size) + 63)); \
var = reinterpret_cast<uint8*> \
((reinterpret_cast<intptr_t>(var##_mem) + 63) & ~63)
#define free_aligned_buffer_64(var) \
free(var##_mem); \
var = 0
#if defined(__CLR_VER) || defined(COVERAGE_ENABLED) || \ #if defined(__CLR_VER) || defined(COVERAGE_ENABLED) || \
defined(TARGET_IPHONE_SIMULATOR) defined(TARGET_IPHONE_SIMULATOR)
#define LIBYUV_DISABLE_X86 #define LIBYUV_DISABLE_X86
......
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 921 #define LIBYUV_VERSION 922
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
...@@ -931,11 +931,9 @@ void RotatePlane180(const uint8* src, int src_stride, ...@@ -931,11 +931,9 @@ void RotatePlane180(const uint8* src, int src_stride,
CopyRow = CopyRow_MIPS; CopyRow = CopyRow_MIPS;
} }
#endif #endif
if (width > kMaxStride) {
return;
}
// Swap first and last row and mirror the content. Uses a temporary row. // Swap first and last row and mirror the content. Uses a temporary row.
SIMD_ALIGNED(uint8 row[kMaxStride]); align_buffer_64(row, width);
const uint8* src_bot = src + src_stride * (height - 1); const uint8* src_bot = src + src_stride * (height - 1);
uint8* dst_bot = dst + dst_stride * (height - 1); uint8* dst_bot = dst + dst_stride * (height - 1);
int half_height = (height + 1) >> 1; int half_height = (height + 1) >> 1;
...@@ -949,6 +947,7 @@ void RotatePlane180(const uint8* src, int src_stride, ...@@ -949,6 +947,7 @@ void RotatePlane180(const uint8* src, int src_stride,
src_bot -= src_stride; src_bot -= src_stride;
dst_bot -= dst_stride; dst_bot -= dst_stride;
} }
free_aligned_buffer_64(row);
} }
static void TransposeUVWx8_C(const uint8* src, int src_stride, static void TransposeUVWx8_C(const uint8* src, int src_stride,
......
...@@ -140,30 +140,23 @@ void ARGBRotate180(const uint8* src, int src_stride, ...@@ -140,30 +140,23 @@ void ARGBRotate180(const uint8* src, int src_stride,
CopyRow = CopyRow_MIPS; CopyRow = CopyRow_MIPS;
} }
#endif #endif
bool direct = width * 4 > kMaxStride;
// Swap first and last row and mirror the content. Uses a temporary row. // Swap first and last row and mirror the content. Uses a temporary row.
SIMD_ALIGNED(uint8 row[kMaxStride]); align_buffer_64(row, width * 4);
const uint8* src_bot = src + src_stride * (height - 1); const uint8* src_bot = src + src_stride * (height - 1);
uint8* dst_bot = dst + dst_stride * (height - 1); uint8* dst_bot = dst + dst_stride * (height - 1);
int half_height = (height + 1) >> 1; int half_height = (height + 1) >> 1;
// Odd height will harmlessly mirror the middle row twice. // Odd height will harmlessly mirror the middle row twice.
for (int y = 0; y < half_height; ++y) { for (int y = 0; y < half_height; ++y) {
if (direct) { ARGBMirrorRow(src, row, width); // Mirror first row into a buffer
ARGBMirrorRow(src, dst_bot, width); // Mirror first row into a buffer ARGBMirrorRow(src_bot, dst, width); // Mirror last row into first row
if (src != src_bot) { CopyRow(row, dst_bot, width * 4); // Copy first mirrored row into last
ARGBMirrorRow(src_bot, dst, width); // Mirror last row into first row
}
} else {
ARGBMirrorRow(src, row, width); // Mirror first row into a buffer
ARGBMirrorRow(src_bot, dst, width); // Mirror last row into first row
CopyRow(row, dst_bot, width * 4); // Copy first mirrored row into last
}
src += src_stride; src += src_stride;
dst += dst_stride; dst += dst_stride;
src_bot -= src_stride; src_bot -= src_stride;
dst_bot -= dst_stride; dst_bot -= dst_stride;
} }
free_aligned_buffer_64(row);
} }
LIBYUV_API LIBYUV_API
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "libyuv/basic_types.h" #include "libyuv/basic_types.h"
#include "libyuv/compare.h" #include "libyuv/compare.h"
#include "libyuv/cpu_id.h" #include "libyuv/cpu_id.h"
#include "libyuv/row.h"
namespace libyuv { namespace libyuv {
...@@ -32,8 +33,8 @@ static uint32 ReferenceHashDjb2(const uint8* src, uint64 count, uint32 seed) { ...@@ -32,8 +33,8 @@ static uint32 ReferenceHashDjb2(const uint8* src, uint64 count, uint32 seed) {
TEST_F(libyuvTest, Djb2_Test) { TEST_F(libyuvTest, Djb2_Test) {
const int kMaxTest = benchmark_width_ * benchmark_height_; const int kMaxTest = benchmark_width_ * benchmark_height_;
align_buffer_64(src_a, kMaxTest) align_buffer_64(src_a, kMaxTest);
align_buffer_64(src_b, kMaxTest) align_buffer_64(src_b, kMaxTest);
const char* fox = "The quick brown fox jumps over the lazy dog" const char* fox = "The quick brown fox jumps over the lazy dog"
" and feels as if he were in the seventh heaven of typography" " and feels as if he were in the seventh heaven of typography"
...@@ -110,13 +111,13 @@ TEST_F(libyuvTest, Djb2_Test) { ...@@ -110,13 +111,13 @@ TEST_F(libyuvTest, Djb2_Test) {
h2 = HashDjb2(src_a, kMaxTest / 2, 0); h2 = HashDjb2(src_a, kMaxTest / 2, 0);
EXPECT_EQ(h1, h2); EXPECT_EQ(h1, h2);
free_aligned_buffer_64(src_a) free_aligned_buffer_64(src_a);
free_aligned_buffer_64(src_b) free_aligned_buffer_64(src_b);
} }
TEST_F(libyuvTest, BenchmarkDjb2_Opt) { TEST_F(libyuvTest, BenchmarkDjb2_Opt) {
const int kMaxTest = benchmark_width_ * benchmark_height_; const int kMaxTest = benchmark_width_ * benchmark_height_;
align_buffer_64(src_a, kMaxTest) align_buffer_64(src_a, kMaxTest);
for (int i = 0; i < kMaxTest; ++i) { for (int i = 0; i < kMaxTest; ++i) {
src_a[i] = i; src_a[i] = i;
...@@ -127,12 +128,12 @@ TEST_F(libyuvTest, BenchmarkDjb2_Opt) { ...@@ -127,12 +128,12 @@ TEST_F(libyuvTest, BenchmarkDjb2_Opt) {
h1 = HashDjb2(src_a, kMaxTest, 5381); h1 = HashDjb2(src_a, kMaxTest, 5381);
} }
EXPECT_EQ(h1, h2); EXPECT_EQ(h1, h2);
free_aligned_buffer_64(src_a) free_aligned_buffer_64(src_a);
} }
TEST_F(libyuvTest, BenchmarkDjb2_Unaligned) { TEST_F(libyuvTest, BenchmarkDjb2_Unaligned) {
const int kMaxTest = benchmark_width_ * benchmark_height_; const int kMaxTest = benchmark_width_ * benchmark_height_;
align_buffer_64(src_a, kMaxTest + 1) align_buffer_64(src_a, kMaxTest + 1);
for (int i = 0; i < kMaxTest; ++i) { for (int i = 0; i < kMaxTest; ++i) {
src_a[i + 1] = i; src_a[i + 1] = i;
} }
...@@ -142,13 +143,13 @@ TEST_F(libyuvTest, BenchmarkDjb2_Unaligned) { ...@@ -142,13 +143,13 @@ TEST_F(libyuvTest, BenchmarkDjb2_Unaligned) {
h1 = HashDjb2(src_a + 1, kMaxTest, 5381); h1 = HashDjb2(src_a + 1, kMaxTest, 5381);
} }
EXPECT_EQ(h1, h2); EXPECT_EQ(h1, h2);
free_aligned_buffer_64(src_a) free_aligned_buffer_64(src_a);
} }
TEST_F(libyuvTest, BenchmarkSumSquareError_Opt) { TEST_F(libyuvTest, BenchmarkSumSquareError_Opt) {
const int kMaxWidth = 4096 * 3; const int kMaxWidth = 4096 * 3;
align_buffer_64(src_a, kMaxWidth) align_buffer_64(src_a, kMaxWidth);
align_buffer_64(src_b, kMaxWidth) align_buffer_64(src_b, kMaxWidth);
memset(src_a, 0, kMaxWidth); memset(src_a, 0, kMaxWidth);
memset(src_b, 0, kMaxWidth); memset(src_b, 0, kMaxWidth);
...@@ -172,14 +173,14 @@ TEST_F(libyuvTest, BenchmarkSumSquareError_Opt) { ...@@ -172,14 +173,14 @@ TEST_F(libyuvTest, BenchmarkSumSquareError_Opt) {
EXPECT_EQ(0, h1); EXPECT_EQ(0, h1);
free_aligned_buffer_64(src_a) free_aligned_buffer_64(src_a);
free_aligned_buffer_64(src_b) free_aligned_buffer_64(src_b);
} }
TEST_F(libyuvTest, SumSquareError) { TEST_F(libyuvTest, SumSquareError) {
const int kMaxWidth = 4096 * 3; const int kMaxWidth = 4096 * 3;
align_buffer_64(src_a, kMaxWidth) align_buffer_64(src_a, kMaxWidth);
align_buffer_64(src_b, kMaxWidth) align_buffer_64(src_b, kMaxWidth);
memset(src_a, 0, kMaxWidth); memset(src_a, 0, kMaxWidth);
memset(src_b, 0, kMaxWidth); memset(src_b, 0, kMaxWidth);
...@@ -214,13 +215,13 @@ TEST_F(libyuvTest, SumSquareError) { ...@@ -214,13 +215,13 @@ TEST_F(libyuvTest, SumSquareError) {
EXPECT_EQ(c_err, opt_err); EXPECT_EQ(c_err, opt_err);
free_aligned_buffer_64(src_a) free_aligned_buffer_64(src_a);
free_aligned_buffer_64(src_b) free_aligned_buffer_64(src_b);
} }
TEST_F(libyuvTest, BenchmarkPsnr_Opt) { TEST_F(libyuvTest, BenchmarkPsnr_Opt) {
align_buffer_64(src_a, benchmark_width_ * benchmark_height_) align_buffer_64(src_a, benchmark_width_ * benchmark_height_);
align_buffer_64(src_b, benchmark_width_ * benchmark_height_) align_buffer_64(src_b, benchmark_width_ * benchmark_height_);
for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) {
src_a[i] = i; src_a[i] = i;
src_b[i] = i; src_b[i] = i;
...@@ -239,8 +240,8 @@ TEST_F(libyuvTest, BenchmarkPsnr_Opt) { ...@@ -239,8 +240,8 @@ TEST_F(libyuvTest, BenchmarkPsnr_Opt) {
EXPECT_EQ(0, 0); EXPECT_EQ(0, 0);
free_aligned_buffer_64(src_a) free_aligned_buffer_64(src_a);
free_aligned_buffer_64(src_b) free_aligned_buffer_64(src_b);
} }
TEST_F(libyuvTest, Psnr) { TEST_F(libyuvTest, Psnr) {
...@@ -249,8 +250,8 @@ TEST_F(libyuvTest, Psnr) { ...@@ -249,8 +250,8 @@ TEST_F(libyuvTest, Psnr) {
const int b = 128; const int b = 128;
const int kSrcPlaneSize = (kSrcWidth + b * 2) * (kSrcHeight + b * 2); const int kSrcPlaneSize = (kSrcWidth + b * 2) * (kSrcHeight + b * 2);
const int kSrcStride = 2 * b + kSrcWidth; const int kSrcStride = 2 * b + kSrcWidth;
align_buffer_64(src_a, kSrcPlaneSize) align_buffer_64(src_a, kSrcPlaneSize);
align_buffer_64(src_b, kSrcPlaneSize) align_buffer_64(src_b, kSrcPlaneSize);
memset(src_a, 0, kSrcPlaneSize); memset(src_a, 0, kSrcPlaneSize);
memset(src_b, 0, kSrcPlaneSize); memset(src_b, 0, kSrcPlaneSize);
...@@ -318,13 +319,13 @@ TEST_F(libyuvTest, Psnr) { ...@@ -318,13 +319,13 @@ TEST_F(libyuvTest, Psnr) {
EXPECT_EQ(opt_err, c_err); EXPECT_EQ(opt_err, c_err);
free_aligned_buffer_64(src_a) free_aligned_buffer_64(src_a);
free_aligned_buffer_64(src_b) free_aligned_buffer_64(src_b);
} }
TEST_F(libyuvTest, DISABLED_BenchmarkSsim_Opt) { TEST_F(libyuvTest, DISABLED_BenchmarkSsim_Opt) {
align_buffer_64(src_a, benchmark_width_ * benchmark_height_) align_buffer_64(src_a, benchmark_width_ * benchmark_height_);
align_buffer_64(src_b, benchmark_width_ * benchmark_height_) align_buffer_64(src_b, benchmark_width_ * benchmark_height_);
for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) {
src_a[i] = i; src_a[i] = i;
src_b[i] = i; src_b[i] = i;
...@@ -343,8 +344,8 @@ TEST_F(libyuvTest, DISABLED_BenchmarkSsim_Opt) { ...@@ -343,8 +344,8 @@ TEST_F(libyuvTest, DISABLED_BenchmarkSsim_Opt) {
EXPECT_EQ(0, 0); // Pass if we get this far. EXPECT_EQ(0, 0); // Pass if we get this far.
free_aligned_buffer_64(src_a) free_aligned_buffer_64(src_a);
free_aligned_buffer_64(src_b) free_aligned_buffer_64(src_b);
} }
TEST_F(libyuvTest, Ssim) { TEST_F(libyuvTest, Ssim) {
...@@ -353,8 +354,8 @@ TEST_F(libyuvTest, Ssim) { ...@@ -353,8 +354,8 @@ TEST_F(libyuvTest, Ssim) {
const int b = 128; const int b = 128;
const int kSrcPlaneSize = (kSrcWidth + b * 2) * (kSrcHeight + b * 2); const int kSrcPlaneSize = (kSrcWidth + b * 2) * (kSrcHeight + b * 2);
const int kSrcStride = 2 * b + kSrcWidth; const int kSrcStride = 2 * b + kSrcWidth;
align_buffer_64(src_a, kSrcPlaneSize) align_buffer_64(src_a, kSrcPlaneSize);
align_buffer_64(src_b, kSrcPlaneSize) align_buffer_64(src_b, kSrcPlaneSize);
memset(src_a, 0, kSrcPlaneSize); memset(src_a, 0, kSrcPlaneSize);
memset(src_b, 0, kSrcPlaneSize); memset(src_b, 0, kSrcPlaneSize);
...@@ -430,8 +431,8 @@ TEST_F(libyuvTest, Ssim) { ...@@ -430,8 +431,8 @@ TEST_F(libyuvTest, Ssim) {
EXPECT_EQ(opt_err, c_err); EXPECT_EQ(opt_err, c_err);
} }
free_aligned_buffer_64(src_a) free_aligned_buffer_64(src_a);
free_aligned_buffer_64(src_b) free_aligned_buffer_64(src_b);
} }
} // namespace libyuv } // namespace libyuv
This diff is collapsed.
...@@ -105,10 +105,10 @@ TEST_F(libyuvTest, TestAttenuate) { ...@@ -105,10 +105,10 @@ TEST_F(libyuvTest, TestAttenuate) {
EXPECT_NEAR(85, atten_pixels[255 * 4 + 2], 1); EXPECT_NEAR(85, atten_pixels[255 * 4 + 2], 1);
EXPECT_EQ(255, atten_pixels[255 * 4 + 3]); EXPECT_EQ(255, atten_pixels[255 * 4 + 3]);
free_aligned_buffer_64(atten2_pixels) free_aligned_buffer_64(atten2_pixels);
free_aligned_buffer_64(unatten_pixels) free_aligned_buffer_64(unatten_pixels);
free_aligned_buffer_64(atten_pixels) free_aligned_buffer_64(atten_pixels);
free_aligned_buffer_64(orig_pixels) free_aligned_buffer_64(orig_pixels);
} }
static int TestAttenuateI(int width, int height, int benchmark_iterations, static int TestAttenuateI(int width, int height, int benchmark_iterations,
...@@ -147,9 +147,9 @@ static int TestAttenuateI(int width, int height, int benchmark_iterations, ...@@ -147,9 +147,9 @@ static int TestAttenuateI(int width, int height, int benchmark_iterations,
max_diff = abs_diff; max_diff = abs_diff;
} }
} }
free_aligned_buffer_64(src_argb) free_aligned_buffer_64(src_argb);
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
return max_diff; return max_diff;
} }
...@@ -216,9 +216,9 @@ static int TestUnattenuateI(int width, int height, int benchmark_iterations, ...@@ -216,9 +216,9 @@ static int TestUnattenuateI(int width, int height, int benchmark_iterations,
max_diff = abs_diff; max_diff = abs_diff;
} }
} }
free_aligned_buffer_64(src_argb) free_aligned_buffer_64(src_argb);
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
return max_diff; return max_diff;
} }
...@@ -970,10 +970,10 @@ TEST_F(libyuvTest, ARGBInterpolate##TERP##N) { \ ...@@ -970,10 +970,10 @@ TEST_F(libyuvTest, ARGBInterpolate##TERP##N) { \
} \ } \
} \ } \
EXPECT_LE(max_diff, DIFF); \ EXPECT_LE(max_diff, DIFF); \
free_aligned_buffer_64(src_argb_a) \ free_aligned_buffer_64(src_argb_a); \
free_aligned_buffer_64(src_argb_b) \ free_aligned_buffer_64(src_argb_b); \
free_aligned_buffer_64(dst_argb_c) \ free_aligned_buffer_64(dst_argb_c); \
free_aligned_buffer_64(dst_argb_opt) \ free_aligned_buffer_64(dst_argb_opt); \
} }
#define TESTINTERPOLATE(TERP) \ #define TESTINTERPOLATE(TERP) \
...@@ -1038,10 +1038,10 @@ static int TestBlend(int width, int height, int benchmark_iterations, ...@@ -1038,10 +1038,10 @@ static int TestBlend(int width, int height, int benchmark_iterations,
max_diff = abs_diff; max_diff = abs_diff;
} }
} }
free_aligned_buffer_64(src_argb_a) free_aligned_buffer_64(src_argb_a);
free_aligned_buffer_64(src_argb_b) free_aligned_buffer_64(src_argb_b);
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
return max_diff; return max_diff;
} }
...@@ -1312,8 +1312,8 @@ TEST_F(libyuvTest, TestCopyPlane) { ...@@ -1312,8 +1312,8 @@ TEST_F(libyuvTest, TestCopyPlane) {
int y_plane_size = (yw + b * 2) * (yh + b * 2); int y_plane_size = (yw + b * 2) * (yh + b * 2);
srandom(time(NULL)); srandom(time(NULL));
align_buffer_64(orig_y, y_plane_size) align_buffer_64(orig_y, y_plane_size);
align_buffer_64(dst_c, y_plane_size) align_buffer_64(dst_c, y_plane_size);
align_buffer_64(dst_opt, y_plane_size); align_buffer_64(dst_opt, y_plane_size);
memset(orig_y, 0, y_plane_size); memset(orig_y, 0, y_plane_size);
...@@ -1360,9 +1360,9 @@ TEST_F(libyuvTest, TestCopyPlane) { ...@@ -1360,9 +1360,9 @@ TEST_F(libyuvTest, TestCopyPlane) {
++err; ++err;
} }
free_aligned_buffer_64(orig_y) free_aligned_buffer_64(orig_y);
free_aligned_buffer_64(dst_c) free_aligned_buffer_64(dst_c);
free_aligned_buffer_64(dst_opt) free_aligned_buffer_64(dst_opt);
EXPECT_EQ(0, err); EXPECT_EQ(0, err);
} }
...@@ -1407,10 +1407,10 @@ static int TestMultiply(int width, int height, int benchmark_iterations, ...@@ -1407,10 +1407,10 @@ static int TestMultiply(int width, int height, int benchmark_iterations,
max_diff = abs_diff; max_diff = abs_diff;
} }
} }
free_aligned_buffer_64(src_argb_a) free_aligned_buffer_64(src_argb_a);
free_aligned_buffer_64(src_argb_b) free_aligned_buffer_64(src_argb_b);
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
return max_diff; return max_diff;
} }
...@@ -1478,10 +1478,10 @@ static int TestAdd(int width, int height, int benchmark_iterations, ...@@ -1478,10 +1478,10 @@ static int TestAdd(int width, int height, int benchmark_iterations,
max_diff = abs_diff; max_diff = abs_diff;
} }
} }
free_aligned_buffer_64(src_argb_a) free_aligned_buffer_64(src_argb_a);
free_aligned_buffer_64(src_argb_b) free_aligned_buffer_64(src_argb_b);
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
return max_diff; return max_diff;
} }
...@@ -1549,10 +1549,10 @@ static int TestSubtract(int width, int height, int benchmark_iterations, ...@@ -1549,10 +1549,10 @@ static int TestSubtract(int width, int height, int benchmark_iterations,
max_diff = abs_diff; max_diff = abs_diff;
} }
} }
free_aligned_buffer_64(src_argb_a) free_aligned_buffer_64(src_argb_a);
free_aligned_buffer_64(src_argb_b) free_aligned_buffer_64(src_argb_b);
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
return max_diff; return max_diff;
} }
...@@ -1617,9 +1617,9 @@ static int TestSobel(int width, int height, int benchmark_iterations, ...@@ -1617,9 +1617,9 @@ static int TestSobel(int width, int height, int benchmark_iterations,
max_diff = abs_diff; max_diff = abs_diff;
} }
} }
free_aligned_buffer_64(src_argb_a) free_aligned_buffer_64(src_argb_a);
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
return max_diff; return max_diff;
} }
...@@ -1686,9 +1686,9 @@ static int TestSobelToPlane(int width, int height, int benchmark_iterations, ...@@ -1686,9 +1686,9 @@ static int TestSobelToPlane(int width, int height, int benchmark_iterations,
max_diff = abs_diff; max_diff = abs_diff;
} }
} }
free_aligned_buffer_64(src_argb_a) free_aligned_buffer_64(src_argb_a);
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
return max_diff; return max_diff;
} }
...@@ -1753,9 +1753,9 @@ static int TestSobelXY(int width, int height, int benchmark_iterations, ...@@ -1753,9 +1753,9 @@ static int TestSobelXY(int width, int height, int benchmark_iterations,
max_diff = abs_diff; max_diff = abs_diff;
} }
} }
free_aligned_buffer_64(src_argb_a) free_aligned_buffer_64(src_argb_a);
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
return max_diff; return max_diff;
} }
...@@ -1823,10 +1823,10 @@ static int TestBlur(int width, int height, int benchmark_iterations, ...@@ -1823,10 +1823,10 @@ static int TestBlur(int width, int height, int benchmark_iterations,
max_diff = abs_diff; max_diff = abs_diff;
} }
} }
free_aligned_buffer_64(src_argb_a) free_aligned_buffer_64(src_argb_a);
free_aligned_buffer_64(dst_cumsum) free_aligned_buffer_64(dst_cumsum);
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
return max_diff; return max_diff;
} }
...@@ -2070,9 +2070,9 @@ TEST_F(libyuvTest, TestARGBCopyAlpha) { ...@@ -2070,9 +2070,9 @@ TEST_F(libyuvTest, TestARGBCopyAlpha) {
EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
} }
free_aligned_buffer_64(dst_pixels_c) free_aligned_buffer_64(dst_pixels_c);
free_aligned_buffer_64(dst_pixels_opt) free_aligned_buffer_64(dst_pixels_opt);
free_aligned_buffer_64(orig_pixels) free_aligned_buffer_64(orig_pixels);
} }
TEST_F(libyuvTest, TestARGBCopyYToAlpha) { TEST_F(libyuvTest, TestARGBCopyYToAlpha) {
...@@ -2100,9 +2100,9 @@ TEST_F(libyuvTest, TestARGBCopyYToAlpha) { ...@@ -2100,9 +2100,9 @@ TEST_F(libyuvTest, TestARGBCopyYToAlpha) {
EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
} }
free_aligned_buffer_64(dst_pixels_c) free_aligned_buffer_64(dst_pixels_c);
free_aligned_buffer_64(dst_pixels_opt) free_aligned_buffer_64(dst_pixels_opt);
free_aligned_buffer_64(orig_pixels) free_aligned_buffer_64(orig_pixels);
} }
} // namespace libyuv } // namespace libyuv
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "libyuv/cpu_id.h" #include "libyuv/cpu_id.h"
#include "libyuv/rotate_argb.h" #include "libyuv/rotate_argb.h"
#include "libyuv/row.h"
#include "../unit_test/unit_test.h" #include "../unit_test/unit_test.h"
namespace libyuv { namespace libyuv {
...@@ -36,15 +37,15 @@ void TestRotateBpp(int src_width, int src_height, ...@@ -36,15 +37,15 @@ void TestRotateBpp(int src_width, int src_height,
} }
int src_stride_argb = src_width * kBpp; int src_stride_argb = src_width * kBpp;
int src_argb_plane_size = src_stride_argb * src_height; int src_argb_plane_size = src_stride_argb * src_height;
align_buffer_64(src_argb, src_argb_plane_size) align_buffer_64(src_argb, src_argb_plane_size);
for (int i = 0; i < src_argb_plane_size; ++i) { for (int i = 0; i < src_argb_plane_size; ++i) {
src_argb[i] = random() & 0xff; src_argb[i] = random() & 0xff;
} }
int dst_stride_argb = dst_width * kBpp; int dst_stride_argb = dst_width * kBpp;
int dst_argb_plane_size = dst_stride_argb * dst_height; int dst_argb_plane_size = dst_stride_argb * dst_height;
align_buffer_64(dst_argb_c, dst_argb_plane_size) align_buffer_64(dst_argb_c, dst_argb_plane_size);
align_buffer_64(dst_argb_opt, dst_argb_plane_size) align_buffer_64(dst_argb_opt, dst_argb_plane_size);
memset(dst_argb_c, 2, dst_argb_plane_size); memset(dst_argb_c, 2, dst_argb_plane_size);
memset(dst_argb_opt, 3, dst_argb_plane_size); memset(dst_argb_opt, 3, dst_argb_plane_size);
...@@ -79,9 +80,9 @@ void TestRotateBpp(int src_width, int src_height, ...@@ -79,9 +80,9 @@ void TestRotateBpp(int src_width, int src_height,
EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]); EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]);
} }
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
free_aligned_buffer_64(src_argb) free_aligned_buffer_64(src_argb);
} }
static void ARGBTestRotate(int src_width, int src_height, static void ARGBTestRotate(int src_width, int src_height,
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "libyuv/cpu_id.h" #include "libyuv/cpu_id.h"
#include "libyuv/rotate.h" #include "libyuv/rotate.h"
#include "libyuv/row.h"
#include "../unit_test/unit_test.h" #include "../unit_test/unit_test.h"
namespace libyuv { namespace libyuv {
...@@ -36,7 +37,7 @@ static void I420TestRotate(int src_width, int src_height, ...@@ -36,7 +37,7 @@ static void I420TestRotate(int src_width, int src_height,
int src_i420_y_size = src_width * src_height; int src_i420_y_size = src_width * src_height;
int src_i420_uv_size = ((src_width + 1) / 2) * ((src_height + 1) / 2); int src_i420_uv_size = ((src_width + 1) / 2) * ((src_height + 1) / 2);
int src_i420_size = src_i420_y_size + src_i420_uv_size * 2; int src_i420_size = src_i420_y_size + src_i420_uv_size * 2;
align_buffer_64(src_i420, src_i420_size) align_buffer_64(src_i420, src_i420_size);
for (int i = 0; i < src_i420_size; ++i) { for (int i = 0; i < src_i420_size; ++i) {
src_i420[i] = random() & 0xff; src_i420[i] = random() & 0xff;
} }
...@@ -44,8 +45,8 @@ static void I420TestRotate(int src_width, int src_height, ...@@ -44,8 +45,8 @@ static void I420TestRotate(int src_width, int src_height,
int dst_i420_y_size = dst_width * dst_height; int dst_i420_y_size = dst_width * dst_height;
int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2);
int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2; int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2;
align_buffer_64(dst_i420_c, dst_i420_size) align_buffer_64(dst_i420_c, dst_i420_size);
align_buffer_64(dst_i420_opt, dst_i420_size) align_buffer_64(dst_i420_opt, dst_i420_size);
memset(dst_i420_c, 2, dst_i420_size); memset(dst_i420_c, 2, dst_i420_size);
memset(dst_i420_opt, 3, dst_i420_size); memset(dst_i420_opt, 3, dst_i420_size);
...@@ -77,9 +78,9 @@ static void I420TestRotate(int src_width, int src_height, ...@@ -77,9 +78,9 @@ static void I420TestRotate(int src_width, int src_height,
EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]);
} }
free_aligned_buffer_64(dst_i420_c) free_aligned_buffer_64(dst_i420_c);
free_aligned_buffer_64(dst_i420_opt) free_aligned_buffer_64(dst_i420_opt);
free_aligned_buffer_64(src_i420) free_aligned_buffer_64(src_i420);
} }
TEST_F(libyuvTest, I420Rotate0) { TEST_F(libyuvTest, I420Rotate0) {
...@@ -149,7 +150,7 @@ static void NV12TestRotate(int src_width, int src_height, ...@@ -149,7 +150,7 @@ static void NV12TestRotate(int src_width, int src_height,
int src_nv12_y_size = src_width * src_height; int src_nv12_y_size = src_width * src_height;
int src_nv12_uv_size = ((src_width + 1) / 2) * ((src_height + 1) / 2) * 2; int src_nv12_uv_size = ((src_width + 1) / 2) * ((src_height + 1) / 2) * 2;
int src_nv12_size = src_nv12_y_size + src_nv12_uv_size; int src_nv12_size = src_nv12_y_size + src_nv12_uv_size;
align_buffer_64(src_nv12, src_nv12_size) align_buffer_64(src_nv12, src_nv12_size);
for (int i = 0; i < src_nv12_size; ++i) { for (int i = 0; i < src_nv12_size; ++i) {
src_nv12[i] = random() & 0xff; src_nv12[i] = random() & 0xff;
} }
...@@ -157,8 +158,8 @@ static void NV12TestRotate(int src_width, int src_height, ...@@ -157,8 +158,8 @@ static void NV12TestRotate(int src_width, int src_height,
int dst_i420_y_size = dst_width * dst_height; int dst_i420_y_size = dst_width * dst_height;
int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2);
int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2; int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2;
align_buffer_64(dst_i420_c, dst_i420_size) align_buffer_64(dst_i420_c, dst_i420_size);
align_buffer_64(dst_i420_opt, dst_i420_size) align_buffer_64(dst_i420_opt, dst_i420_size);
memset(dst_i420_c, 2, dst_i420_size); memset(dst_i420_c, 2, dst_i420_size);
memset(dst_i420_opt, 3, dst_i420_size); memset(dst_i420_opt, 3, dst_i420_size);
...@@ -187,9 +188,9 @@ static void NV12TestRotate(int src_width, int src_height, ...@@ -187,9 +188,9 @@ static void NV12TestRotate(int src_width, int src_height,
EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]);
} }
free_aligned_buffer_64(dst_i420_c) free_aligned_buffer_64(dst_i420_c);
free_aligned_buffer_64(dst_i420_opt) free_aligned_buffer_64(dst_i420_opt);
free_aligned_buffer_64(src_nv12) free_aligned_buffer_64(src_nv12);
} }
TEST_F(libyuvTest, NV12Rotate0) { TEST_F(libyuvTest, NV12Rotate0) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "libyuv/cpu_id.h" #include "libyuv/cpu_id.h"
#include "libyuv/scale_argb.h" #include "libyuv/scale_argb.h"
#include "libyuv/row.h"
#include "../unit_test/unit_test.h" #include "../unit_test/unit_test.h"
namespace libyuv { namespace libyuv {
...@@ -27,15 +28,15 @@ static int ARGBTestFilter(int src_width, int src_height, ...@@ -27,15 +28,15 @@ static int ARGBTestFilter(int src_width, int src_height,
(Abs(src_height) + b * 2) * 4; (Abs(src_height) + b * 2) * 4;
int src_stride_argb = (b * 2 + Abs(src_width)) * 4; int src_stride_argb = (b * 2 + Abs(src_width)) * 4;
align_buffer_64(src_argb, src_argb_plane_size) align_buffer_64(src_argb, src_argb_plane_size);
srandom(time(NULL)); srandom(time(NULL));
MemRandomize(src_argb, src_argb_plane_size); MemRandomize(src_argb, src_argb_plane_size);
int dst_argb_plane_size = (dst_width + b * 2) * (dst_height + b * 2) * 4; int dst_argb_plane_size = (dst_width + b * 2) * (dst_height + b * 2) * 4;
int dst_stride_argb = (b * 2 + dst_width) * 4; int dst_stride_argb = (b * 2 + dst_width) * 4;
align_buffer_64(dst_argb_c, dst_argb_plane_size) align_buffer_64(dst_argb_c, dst_argb_plane_size);
align_buffer_64(dst_argb_opt, dst_argb_plane_size) align_buffer_64(dst_argb_opt, dst_argb_plane_size);
memset(dst_argb_c, 2, dst_argb_plane_size); memset(dst_argb_c, 2, dst_argb_plane_size);
memset(dst_argb_opt, 3, dst_argb_plane_size); memset(dst_argb_opt, 3, dst_argb_plane_size);
...@@ -89,9 +90,9 @@ static int ARGBTestFilter(int src_width, int src_height, ...@@ -89,9 +90,9 @@ static int ARGBTestFilter(int src_width, int src_height,
} }
} }
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
free_aligned_buffer_64(src_argb) free_aligned_buffer_64(src_argb);
return max_diff; return max_diff;
} }
...@@ -134,7 +135,7 @@ static int ARGBClipTestFilter(int src_width, int src_height, ...@@ -134,7 +135,7 @@ static int ARGBClipTestFilter(int src_width, int src_height,
(Abs(src_height) + b * 2) * 4; (Abs(src_height) + b * 2) * 4;
int src_stride_argb = (b * 2 + Abs(src_width)) * 4; int src_stride_argb = (b * 2 + Abs(src_width)) * 4;
align_buffer_64(src_argb, src_argb_plane_size) align_buffer_64(src_argb, src_argb_plane_size);
memset(src_argb, 1, src_argb_plane_size); memset(src_argb, 1, src_argb_plane_size);
int dst_argb_plane_size = (dst_width + b * 2) * (dst_height + b * 2) * 4; int dst_argb_plane_size = (dst_width + b * 2) * (dst_height + b * 2) * 4;
...@@ -149,8 +150,8 @@ static int ARGBClipTestFilter(int src_width, int src_height, ...@@ -149,8 +150,8 @@ static int ARGBClipTestFilter(int src_width, int src_height,
} }
} }
align_buffer_64(dst_argb_c, dst_argb_plane_size) align_buffer_64(dst_argb_c, dst_argb_plane_size);
align_buffer_64(dst_argb_opt, dst_argb_plane_size) align_buffer_64(dst_argb_opt, dst_argb_plane_size);
memset(dst_argb_c, 2, dst_argb_plane_size); memset(dst_argb_c, 2, dst_argb_plane_size);
memset(dst_argb_opt, 3, dst_argb_plane_size); memset(dst_argb_opt, 3, dst_argb_plane_size);
...@@ -188,9 +189,9 @@ static int ARGBClipTestFilter(int src_width, int src_height, ...@@ -188,9 +189,9 @@ static int ARGBClipTestFilter(int src_width, int src_height,
} }
} }
free_aligned_buffer_64(dst_argb_c) free_aligned_buffer_64(dst_argb_c);
free_aligned_buffer_64(dst_argb_opt) free_aligned_buffer_64(dst_argb_opt);
free_aligned_buffer_64(src_argb) free_aligned_buffer_64(src_argb);
return max_diff; return max_diff;
} }
......
...@@ -26,18 +26,6 @@ static __inline int Abs(int v) { ...@@ -26,18 +26,6 @@ static __inline int Abs(int v) {
return v >= 0 ? v : -v; return v >= 0 ? v : -v;
} }
#define align_buffer_64(var, size) \
uint8* var; \
uint8* var##_mem; \
var##_mem = reinterpret_cast<uint8*>(malloc((size) + 63)); \
var = reinterpret_cast<uint8*> \
((reinterpret_cast<intptr_t>(var##_mem) + 63) & ~63);
#define free_aligned_buffer_64(var) \
free(var##_mem); \
var = 0;
#define align_buffer_page_end(var, size) \ #define align_buffer_page_end(var, size) \
uint8* var; \ uint8* var; \
uint8* var##_mem; \ uint8* var##_mem; \
......
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