mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2026-01-01 03:12:16 +08:00
Randomize function for filling a buffer with random values.
BUG=244 TEST=*ScaleFrom1366x768_Box R=mflodman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1644004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@720 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
parent
884a939665
commit
ae67c900f4
@ -1,6 +1,6 @@
|
||||
Name: libyuv
|
||||
URL: http://code.google.com/p/libyuv/
|
||||
Version: 719
|
||||
Version: 720
|
||||
License: BSD
|
||||
License File: LICENSE
|
||||
|
||||
|
||||
@ -11,6 +11,6 @@
|
||||
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
|
||||
#define INCLUDE_LIBYUV_VERSION_H_
|
||||
|
||||
#define LIBYUV_VERSION 719
|
||||
#define LIBYUV_VERSION 720
|
||||
|
||||
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
|
||||
|
||||
@ -26,25 +26,18 @@ static int ARGBTestFilter(int src_width, int src_height,
|
||||
int dst_width, int dst_height,
|
||||
FilterMode f, int benchmark_iterations) {
|
||||
const int b = 128;
|
||||
int i, j;
|
||||
int src_argb_plane_size = (Abs(src_width) + b * 2) *
|
||||
(Abs(src_height) + b * 2) * 4;
|
||||
int src_stride_argb = (b * 2 + Abs(src_width)) * 4;
|
||||
|
||||
align_buffer_64(src_argb, src_argb_plane_size)
|
||||
memset(src_argb, 1, src_argb_plane_size);
|
||||
srandom(time(NULL));
|
||||
MemRandomize(src_argb, src_argb_plane_size);
|
||||
|
||||
int dst_argb_plane_size = (dst_width + b * 2) * (dst_height + b * 2) * 4;
|
||||
int dst_stride_argb = (b * 2 + dst_width) * 4;
|
||||
|
||||
srandom(time(NULL));
|
||||
|
||||
int i, j;
|
||||
for (i = b; i < (Abs(src_height) + b); ++i) {
|
||||
for (j = b; j < (Abs(src_width) + b) * 4; ++j) {
|
||||
src_argb[(i * src_stride_argb) + j] = (random() & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
align_buffer_64(dst_argb_c, dst_argb_plane_size)
|
||||
align_buffer_64(dst_argb_opt, dst_argb_plane_size)
|
||||
memset(dst_argb_c, 2, dst_argb_plane_size);
|
||||
|
||||
@ -25,6 +25,7 @@ static __inline int Abs(int v) {
|
||||
static int TestFilter(int src_width, int src_height,
|
||||
int dst_width, int dst_height,
|
||||
FilterMode f, int benchmark_iterations) {
|
||||
int i, j;
|
||||
const int b = 128;
|
||||
int src_width_uv = (Abs(src_width) + 1) >> 1;
|
||||
int src_height_uv = (Abs(src_height) + 1) >> 1;
|
||||
@ -38,6 +39,10 @@ static int TestFilter(int src_width, int src_height,
|
||||
align_buffer_page_end(src_y, src_y_plane_size)
|
||||
align_buffer_page_end(src_u, src_uv_plane_size)
|
||||
align_buffer_page_end(src_v, src_uv_plane_size)
|
||||
srandom(time(NULL));
|
||||
MemRandomize(src_y, src_y_plane_size);
|
||||
MemRandomize(src_u, src_uv_plane_size);
|
||||
MemRandomize(src_v, src_uv_plane_size);
|
||||
|
||||
int dst_width_uv = (dst_width + 1) >> 1;
|
||||
int dst_height_uv = (dst_height + 1) >> 1;
|
||||
@ -48,22 +53,6 @@ static int TestFilter(int src_width, int src_height,
|
||||
int dst_stride_y = b * 2 + dst_width;
|
||||
int dst_stride_uv = b * 2 + dst_width_uv;
|
||||
|
||||
srandom(time(NULL));
|
||||
|
||||
int i, j;
|
||||
for (i = b; i < (Abs(src_height) + b); ++i) {
|
||||
for (j = b; j < (Abs(src_width) + b); ++j) {
|
||||
src_y[(i * src_stride_y) + j] = (random() & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = b; i < (src_height_uv + b); ++i) {
|
||||
for (j = b; j < (src_width_uv + b); ++j) {
|
||||
src_u[(i * src_stride_uv) + j] = (random() & 0xff);
|
||||
src_v[(i * src_stride_uv) + j] = (random() & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
align_buffer_page_end(dst_y_c, dst_y_plane_size)
|
||||
align_buffer_page_end(dst_u_c, dst_uv_plane_size)
|
||||
align_buffer_page_end(dst_v_c, dst_uv_plane_size)
|
||||
@ -71,25 +60,6 @@ static int TestFilter(int src_width, int src_height,
|
||||
align_buffer_page_end(dst_u_opt, dst_uv_plane_size)
|
||||
align_buffer_page_end(dst_v_opt, dst_uv_plane_size)
|
||||
|
||||
// Warm up both versions for consistent benchmarks.
|
||||
MaskCpuFlags(0); // Disable all CPU optimization.
|
||||
I420Scale(src_y + (src_stride_y * b) + b, src_stride_y,
|
||||
src_u + (src_stride_uv * b) + b, src_stride_uv,
|
||||
src_v + (src_stride_uv * b) + b, src_stride_uv,
|
||||
src_width, src_height,
|
||||
dst_y_c + (dst_stride_y * b) + b, dst_stride_y,
|
||||
dst_u_c + (dst_stride_uv * b) + b, dst_stride_uv,
|
||||
dst_v_c + (dst_stride_uv * b) + b, dst_stride_uv,
|
||||
dst_width, dst_height, f);
|
||||
MaskCpuFlags(-1); // Enable all CPU optimization.
|
||||
I420Scale(src_y + (src_stride_y * b) + b, src_stride_y,
|
||||
src_u + (src_stride_uv * b) + b, src_stride_uv,
|
||||
src_v + (src_stride_uv * b) + b, src_stride_uv,
|
||||
src_width, src_height,
|
||||
dst_y_opt + (dst_stride_y * b) + b, dst_stride_y,
|
||||
dst_u_opt + (dst_stride_uv * b) + b, dst_stride_uv,
|
||||
dst_v_opt + (dst_stride_uv * b) + b, dst_stride_uv,
|
||||
dst_width, dst_height, f);
|
||||
|
||||
MaskCpuFlags(0); // Disable all CPU optimization.
|
||||
double c_time = get_time();
|
||||
@ -101,7 +71,6 @@ static int TestFilter(int src_width, int src_height,
|
||||
dst_u_c + (dst_stride_uv * b) + b, dst_stride_uv,
|
||||
dst_v_c + (dst_stride_uv * b) + b, dst_stride_uv,
|
||||
dst_width, dst_height, f);
|
||||
|
||||
c_time = (get_time() - c_time);
|
||||
|
||||
MaskCpuFlags(-1); // Enable all CPU optimization.
|
||||
@ -117,10 +86,11 @@ static int TestFilter(int src_width, int src_height,
|
||||
dst_width, dst_height, f);
|
||||
}
|
||||
opt_time = (get_time() - opt_time) / benchmark_iterations;
|
||||
|
||||
// Report performance of C vs OPT
|
||||
printf("filter %d - %8d us C - %8d us OPT\n",
|
||||
f, static_cast<int>(c_time * 1e6), static_cast<int>(opt_time * 1e6));
|
||||
f,
|
||||
static_cast<int>(c_time * 1e6),
|
||||
static_cast<int>(opt_time * 1e6));
|
||||
|
||||
// C version may be a little off from the optimized. Order of
|
||||
// operations may introduce rounding somewhere. So do a difference
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "libyuv/basic_types.h"
|
||||
|
||||
#define align_buffer_64(var, size) \
|
||||
uint8* var; \
|
||||
uint8* var##_mem; \
|
||||
@ -59,6 +61,17 @@ static inline double get_time() {
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void MemRandomize(uint8* dst, int len) {
|
||||
int i;
|
||||
for (i = 0; i < len - 3; i += 4) {
|
||||
*reinterpret_cast<uint32*>(dst) = random();
|
||||
dst += 4;
|
||||
}
|
||||
for (; i < len; ++i) {
|
||||
*dst++ = random();
|
||||
}
|
||||
}
|
||||
|
||||
class libyuvTest : public ::testing::Test {
|
||||
protected:
|
||||
libyuvTest();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user