2 * Copyright (c) 2017 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "third_party/googletest/src/include/gtest/gtest.h"
13 #include "./vpx_dsp_rtcd.h"
15 #include "test/acm_random.h"
16 #include "test/buffer.h"
17 #include "test/register_state_check.h"
18 #include "vpx_ports/vpx_timer.h"
22 using ::libvpx_test::ACMRandom;
23 using ::libvpx_test::Buffer;
25 typedef void (*AvgPredFunc)(uint8_t *a, const uint8_t *b, int w, int h,
26 const uint8_t *c, int c_stride);
28 uint8_t avg_with_rounding(uint8_t a, uint8_t b) { return (a + b + 1) >> 1; }
30 void reference_pred(const Buffer<uint8_t> &pred, const Buffer<uint8_t> &ref,
31 int width, int height, Buffer<uint8_t> *avg) {
32 ASSERT_TRUE(avg->TopLeftPixel() != NULL);
33 ASSERT_TRUE(pred.TopLeftPixel() != NULL);
34 ASSERT_TRUE(ref.TopLeftPixel() != NULL);
36 for (int y = 0; y < height; ++y) {
37 for (int x = 0; x < width; ++x) {
38 avg->TopLeftPixel()[y * avg->stride() + x] =
39 avg_with_rounding(pred.TopLeftPixel()[y * pred.stride() + x],
40 ref.TopLeftPixel()[y * ref.stride() + x]);
45 class AvgPredTest : public ::testing::TestWithParam<AvgPredFunc> {
47 virtual void SetUp() {
48 avg_pred_func_ = GetParam();
49 rnd_.Reset(ACMRandom::DeterministicSeed());
53 AvgPredFunc avg_pred_func_;
57 TEST_P(AvgPredTest, SizeCombinations) {
58 // This is called as part of the sub pixel variance. As such it must be one of
59 // the variance block sizes.
61 for (int width_pow = 2; width_pow <= 6; ++width_pow) {
62 for (int height_pow = width_pow - 1; height_pow <= width_pow + 1;
64 // Don't test 4x2 or 64x128
65 if (height_pow == 1 || height_pow == 7) continue;
67 // The sse2 special-cases when ref width == stride, so make sure to test
69 for (int ref_padding = 0; ref_padding < 2; ref_padding++) {
70 const int width = 1 << width_pow;
71 const int height = 1 << height_pow;
72 // Only the reference buffer may have a stride not equal to width.
74 Buffer<uint8_t>(width, height, ref_padding ? 8 : 0);
75 ASSERT_TRUE(ref.Init());
76 Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
77 ASSERT_TRUE(pred.Init());
78 Buffer<uint8_t> avg_ref = Buffer<uint8_t>(width, height, 0, 16);
79 ASSERT_TRUE(avg_ref.Init());
80 Buffer<uint8_t> avg_chk = Buffer<uint8_t>(width, height, 0, 16);
81 ASSERT_TRUE(avg_chk.Init());
83 ref.Set(&rnd_, &ACMRandom::Rand8);
84 pred.Set(&rnd_, &ACMRandom::Rand8);
86 reference_pred(pred, ref, width, height, &avg_ref);
87 ASM_REGISTER_STATE_CHECK(
88 avg_pred_func_(avg_chk.TopLeftPixel(), pred.TopLeftPixel(), width,
89 height, ref.TopLeftPixel(), ref.stride()));
91 EXPECT_TRUE(avg_chk.CheckValues(avg_ref));
93 printf("Width: %d Height: %d\n", width, height);
94 avg_chk.PrintDifference(avg_ref);
102 TEST_P(AvgPredTest, CompareReferenceRandom) {
103 const int width = 64;
104 const int height = 32;
105 Buffer<uint8_t> ref = Buffer<uint8_t>(width, height, 8);
106 ASSERT_TRUE(ref.Init());
107 Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
108 ASSERT_TRUE(pred.Init());
109 Buffer<uint8_t> avg_ref = Buffer<uint8_t>(width, height, 0, 16);
110 ASSERT_TRUE(avg_ref.Init());
111 Buffer<uint8_t> avg_chk = Buffer<uint8_t>(width, height, 0, 16);
112 ASSERT_TRUE(avg_chk.Init());
114 for (int i = 0; i < 500; ++i) {
115 ref.Set(&rnd_, &ACMRandom::Rand8);
116 pred.Set(&rnd_, &ACMRandom::Rand8);
118 reference_pred(pred, ref, width, height, &avg_ref);
119 ASM_REGISTER_STATE_CHECK(avg_pred_func_(avg_chk.TopLeftPixel(),
120 pred.TopLeftPixel(), width, height,
121 ref.TopLeftPixel(), ref.stride()));
122 EXPECT_TRUE(avg_chk.CheckValues(avg_ref));
124 printf("Width: %d Height: %d\n", width, height);
125 avg_chk.PrintDifference(avg_ref);
131 TEST_P(AvgPredTest, DISABLED_Speed) {
132 for (int width_pow = 2; width_pow <= 6; ++width_pow) {
133 for (int height_pow = width_pow - 1; height_pow <= width_pow + 1;
135 // Don't test 4x2 or 64x128
136 if (height_pow == 1 || height_pow == 7) continue;
138 for (int ref_padding = 0; ref_padding < 2; ref_padding++) {
139 const int width = 1 << width_pow;
140 const int height = 1 << height_pow;
141 Buffer<uint8_t> ref =
142 Buffer<uint8_t>(width, height, ref_padding ? 8 : 0);
143 ASSERT_TRUE(ref.Init());
144 Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
145 ASSERT_TRUE(pred.Init());
146 Buffer<uint8_t> avg = Buffer<uint8_t>(width, height, 0, 16);
147 ASSERT_TRUE(avg.Init());
149 ref.Set(&rnd_, &ACMRandom::Rand8);
150 pred.Set(&rnd_, &ACMRandom::Rand8);
152 vpx_usec_timer timer;
153 vpx_usec_timer_start(&timer);
154 for (int i = 0; i < 10000000 / (width * height); ++i) {
155 avg_pred_func_(avg.TopLeftPixel(), pred.TopLeftPixel(), width, height,
156 ref.TopLeftPixel(), ref.stride());
158 vpx_usec_timer_mark(&timer);
160 const int elapsed_time =
161 static_cast<int>(vpx_usec_timer_elapsed(&timer));
162 printf("Average Test (ref_padding: %d) %dx%d time: %5d us\n",
163 ref_padding, width, height, elapsed_time);
169 INSTANTIATE_TEST_CASE_P(C, AvgPredTest,
170 ::testing::Values(&vpx_comp_avg_pred_c));
173 INSTANTIATE_TEST_CASE_P(SSE2, AvgPredTest,
174 ::testing::Values(&vpx_comp_avg_pred_sse2));
178 INSTANTIATE_TEST_CASE_P(NEON, AvgPredTest,
179 ::testing::Values(&vpx_comp_avg_pred_neon));
183 INSTANTIATE_TEST_CASE_P(VSX, AvgPredTest,
184 ::testing::Values(&vpx_comp_avg_pred_vsx));