blob: b24f14056c01c5387687e233f6a462cb254c2488 [file] [log] [blame]
David Barkeree674322017-05-10 15:43:02 +01001/*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
13#include "test/acm_random.h"
14#include "test/util.h"
15#include "./av1_rtcd.h"
16#include "test/clear_system_state.h"
17#include "test/register_state_check.h"
18
19#include "av1/encoder/corner_match.h"
20
21namespace test_libaom {
22
23namespace AV1CornerMatch {
24
25using libaom_test::ACMRandom;
26
David Barkeree674322017-05-10 15:43:02 +010027using std::tr1::make_tuple;
Johann123e8a62017-12-28 14:40:49 -080028using std::tr1::tuple;
David Barkeree674322017-05-10 15:43:02 +010029typedef tuple<int> CornerMatchParam;
30
31class AV1CornerMatchTest : public ::testing::TestWithParam<CornerMatchParam> {
32 public:
33 virtual ~AV1CornerMatchTest();
34 virtual void SetUp();
35
36 virtual void TearDown();
37
38 protected:
39 void RunCheckOutput();
40
41 libaom_test::ACMRandom rnd_;
42};
43
44AV1CornerMatchTest::~AV1CornerMatchTest() {}
45void AV1CornerMatchTest::SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
46void AV1CornerMatchTest::TearDown() { libaom_test::ClearSystemState(); }
47
48void AV1CornerMatchTest::RunCheckOutput() {
49 const int w = 128, h = 128;
50 const int num_iters = 10000;
51 int i, j;
52
53 uint8_t *input1 = new uint8_t[w * h];
54 uint8_t *input2 = new uint8_t[w * h];
55
56 // Test the two extreme cases:
57 // i) Random data, should have correlation close to 0
58 // ii) Linearly related data + noise, should have correlation close to 1
59 int mode = GET_PARAM(0);
60 if (mode == 0) {
61 for (i = 0; i < h; ++i)
62 for (j = 0; j < w; ++j) {
63 input1[i * w + j] = rnd_.Rand8();
64 input2[i * w + j] = rnd_.Rand8();
65 }
66 } else if (mode == 1) {
67 for (i = 0; i < h; ++i)
68 for (j = 0; j < w; ++j) {
69 int v = rnd_.Rand8();
70 input1[i * w + j] = v;
71 input2[i * w + j] = (v / 2) + (rnd_.Rand8() & 15);
72 }
73 }
74
75 for (i = 0; i < num_iters; ++i) {
76 int x1 = MATCH_SZ_BY2 + rnd_.PseudoUniform(w - 2 * MATCH_SZ_BY2);
77 int y1 = MATCH_SZ_BY2 + rnd_.PseudoUniform(h - 2 * MATCH_SZ_BY2);
78 int x2 = MATCH_SZ_BY2 + rnd_.PseudoUniform(w - 2 * MATCH_SZ_BY2);
79 int y2 = MATCH_SZ_BY2 + rnd_.PseudoUniform(h - 2 * MATCH_SZ_BY2);
80
81 double res_c =
82 compute_cross_correlation_c(input1, w, x1, y1, input2, w, x2, y2);
83 double res_sse4 =
84 compute_cross_correlation_sse4_1(input1, w, x1, y1, input2, w, x2, y2);
85
86 ASSERT_EQ(res_sse4, res_c);
87 }
88
89 delete[] input1;
90 delete[] input2;
91}
92
93TEST_P(AV1CornerMatchTest, CheckOutput) { RunCheckOutput(); }
94
95INSTANTIATE_TEST_CASE_P(SSE4_1, AV1CornerMatchTest,
96 ::testing::Values(make_tuple(0), make_tuple(1)));
97
98} // namespace AV1CornerMatch
99
100} // namespace test_libaom