intrapred_test.cc 9.34 KB
Newer Older
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
4
5
6
7
8
9
10
11
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/

12
13
14
15
#include <string>

#include "third_party/googletest/src/include/gtest/gtest.h"

Adrian Grange's avatar
Adrian Grange committed
16
17
#include "./aom_config.h"
#include "./aom_dsp_rtcd.h"
18
19
20
21
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
Yaowu Xu's avatar
Yaowu Xu committed
22
23
#include "av1/common/blockd.h"
#include "av1/common/pred_common.h"
Adrian Grange's avatar
Adrian Grange committed
24
#include "aom_mem/aom_mem.h"
25
26
27

namespace {

Yaowu Xu's avatar
Yaowu Xu committed
28
using libaom_test::ACMRandom;
29
30
31

const int count_test_block = 100000;

Adrian Grange's avatar
Adrian Grange committed
32
33
// Base class for AV1 intra prediction tests.
class AV1IntraPredBase {
34
 public:
Adrian Grange's avatar
Adrian Grange committed
35
  virtual ~AV1IntraPredBase() { libaom_test::ClearSystemState(); }
36
37

 protected:
38
  virtual void Predict() = 0;
39
40
41
42
43
44
45
46

  void CheckPrediction(int test_case_number, int *error_count) const {
    // For each pixel ensure that the calculated value is the same as reference.
    for (int y = 0; y < block_size_; y++) {
      for (int x = 0; x < block_size_; x++) {
        *error_count += ref_dst_[x + y * stride_] != dst_[x + y * stride_];
        if (*error_count == 1) {
          ASSERT_EQ(ref_dst_[x + y * stride_], dst_[x + y * stride_])
clang-format's avatar
clang-format committed
47
              << " Failed on Test Case Number " << test_case_number;
48
49
50
51
52
        }
      }
    }
  }

clang-format's avatar
clang-format committed
53
54
  void RunTest(uint16_t *left_col, uint16_t *above_data, uint16_t *dst,
               uint16_t *ref_dst) {
55
56
57
58
59
60
61
62
    ACMRandom rnd(ACMRandom::DeterministicSeed());
    left_col_ = left_col;
    dst_ = dst;
    ref_dst_ = ref_dst;
    above_row_ = above_data + 16;
    int error_count = 0;
    for (int i = 0; i < count_test_block; ++i) {
      // Fill edges with random data, try first with saturated values.
clang-format's avatar
clang-format committed
63
      for (int x = -1; x <= block_size_ * 2; x++) {
64
65
66
67
68
69
70
71
72
73
74
75
76
        if (i == 0) {
          above_row_[x] = mask_;
        } else {
          above_row_[x] = rnd.Rand16() & mask_;
        }
      }
      for (int y = 0; y < block_size_; y++) {
        if (i == 0) {
          left_col_[y] = mask_;
        } else {
          left_col_[y] = rnd.Rand16() & mask_;
        }
      }
77
      Predict();
78
79
80
81
82
83
84
85
86
87
88
89
90
91
      CheckPrediction(i, &error_count);
    }
    ASSERT_EQ(0, error_count);
  }

  int block_size_;
  uint16_t *above_row_;
  uint16_t *left_col_;
  uint16_t *dst_;
  uint16_t *ref_dst_;
  ptrdiff_t stride_;
  int mask_;
};

clang-format's avatar
clang-format committed
92
93
94
95
96
typedef void (*intra_pred_fn_t)(uint16_t *dst, ptrdiff_t stride,
                                const uint16_t *above, const uint16_t *left,
                                int bps);
typedef std::tr1::tuple<intra_pred_fn_t, intra_pred_fn_t, int, int>
    intra_pred_params_t;
Adrian Grange's avatar
Adrian Grange committed
97
class AV1IntraPredTest : public AV1IntraPredBase,
clang-format's avatar
clang-format committed
98
                         public ::testing::TestWithParam<intra_pred_params_t> {
99
  virtual void SetUp() {
clang-format's avatar
clang-format committed
100
101
    pred_fn_ = GET_PARAM(0);
    ref_fn_ = GET_PARAM(1);
102
    block_size_ = GET_PARAM(2);
clang-format's avatar
clang-format committed
103
104
105
    bit_depth_ = GET_PARAM(3);
    stride_ = block_size_ * 3;
    mask_ = (1 << bit_depth_) - 1;
106
107
  }

108
  virtual void Predict() {
109
110
111
    const uint16_t *const_above_row = above_row_;
    const uint16_t *const_left_col = left_col_;
    ref_fn_(ref_dst_, stride_, const_above_row, const_left_col, bit_depth_);
clang-format's avatar
clang-format committed
112
113
    ASM_REGISTER_STATE_CHECK(
        pred_fn_(dst_, stride_, const_above_row, const_left_col, bit_depth_));
114
115
116
117
118
119
  }
  intra_pred_fn_t pred_fn_;
  intra_pred_fn_t ref_fn_;
  int bit_depth_;
};

Adrian Grange's avatar
Adrian Grange committed
120
TEST_P(AV1IntraPredTest, IntraPredTests) {
121
  // max block size is 32
clang-format's avatar
clang-format committed
122
123
  DECLARE_ALIGNED(16, uint16_t, left_col[2 * 32]);
  DECLARE_ALIGNED(16, uint16_t, above_data[2 * 32 + 32]);
124
125
  DECLARE_ALIGNED(16, uint16_t, dst[3 * 32 * 32]);
  DECLARE_ALIGNED(16, uint16_t, ref_dst[3 * 32 * 32]);
126
127
128
129
130
131
  RunTest(left_col, above_data, dst, ref_dst);
}

using std::tr1::make_tuple;

#if HAVE_SSE2
132
#if CONFIG_AOM_HIGHBITDEPTH
133
#if CONFIG_USE_X86INC
clang-format's avatar
clang-format committed
134
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
135
    SSE2_TO_C_8, AV1IntraPredTest,
Adrian Grange's avatar
Adrian Grange committed
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    ::testing::Values(make_tuple(&aom_highbd_dc_predictor_32x32_sse2,
                                 &aom_highbd_dc_predictor_32x32_c, 32, 8),
                      make_tuple(&aom_highbd_tm_predictor_16x16_sse2,
                                 &aom_highbd_tm_predictor_16x16_c, 16, 8),
                      make_tuple(&aom_highbd_tm_predictor_32x32_sse2,
                                 &aom_highbd_tm_predictor_32x32_c, 32, 8),
                      make_tuple(&aom_highbd_dc_predictor_4x4_sse2,
                                 &aom_highbd_dc_predictor_4x4_c, 4, 8),
                      make_tuple(&aom_highbd_dc_predictor_8x8_sse2,
                                 &aom_highbd_dc_predictor_8x8_c, 8, 8),
                      make_tuple(&aom_highbd_dc_predictor_16x16_sse2,
                                 &aom_highbd_dc_predictor_16x16_c, 16, 8),
                      make_tuple(&aom_highbd_v_predictor_4x4_sse2,
                                 &aom_highbd_v_predictor_4x4_c, 4, 8),
                      make_tuple(&aom_highbd_v_predictor_8x8_sse2,
                                 &aom_highbd_v_predictor_8x8_c, 8, 8),
                      make_tuple(&aom_highbd_v_predictor_16x16_sse2,
                                 &aom_highbd_v_predictor_16x16_c, 16, 8),
                      make_tuple(&aom_highbd_v_predictor_32x32_sse2,
                                 &aom_highbd_v_predictor_32x32_c, 32, 8),
                      make_tuple(&aom_highbd_tm_predictor_4x4_sse2,
                                 &aom_highbd_tm_predictor_4x4_c, 4, 8),
                      make_tuple(&aom_highbd_tm_predictor_8x8_sse2,
                                 &aom_highbd_tm_predictor_8x8_c, 8, 8)));
clang-format's avatar
clang-format committed
160
161

INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
162
    SSE2_TO_C_10, AV1IntraPredTest,
Adrian Grange's avatar
Adrian Grange committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
    ::testing::Values(make_tuple(&aom_highbd_dc_predictor_32x32_sse2,
                                 &aom_highbd_dc_predictor_32x32_c, 32, 10),
                      make_tuple(&aom_highbd_tm_predictor_16x16_sse2,
                                 &aom_highbd_tm_predictor_16x16_c, 16, 10),
                      make_tuple(&aom_highbd_tm_predictor_32x32_sse2,
                                 &aom_highbd_tm_predictor_32x32_c, 32, 10),
                      make_tuple(&aom_highbd_dc_predictor_4x4_sse2,
                                 &aom_highbd_dc_predictor_4x4_c, 4, 10),
                      make_tuple(&aom_highbd_dc_predictor_8x8_sse2,
                                 &aom_highbd_dc_predictor_8x8_c, 8, 10),
                      make_tuple(&aom_highbd_dc_predictor_16x16_sse2,
                                 &aom_highbd_dc_predictor_16x16_c, 16, 10),
                      make_tuple(&aom_highbd_v_predictor_4x4_sse2,
                                 &aom_highbd_v_predictor_4x4_c, 4, 10),
                      make_tuple(&aom_highbd_v_predictor_8x8_sse2,
                                 &aom_highbd_v_predictor_8x8_c, 8, 10),
                      make_tuple(&aom_highbd_v_predictor_16x16_sse2,
                                 &aom_highbd_v_predictor_16x16_c, 16, 10),
                      make_tuple(&aom_highbd_v_predictor_32x32_sse2,
                                 &aom_highbd_v_predictor_32x32_c, 32, 10),
                      make_tuple(&aom_highbd_tm_predictor_4x4_sse2,
                                 &aom_highbd_tm_predictor_4x4_c, 4, 10),
                      make_tuple(&aom_highbd_tm_predictor_8x8_sse2,
                                 &aom_highbd_tm_predictor_8x8_c, 8, 10)));
clang-format's avatar
clang-format committed
187
188

INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
189
    SSE2_TO_C_12, AV1IntraPredTest,
Adrian Grange's avatar
Adrian Grange committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
    ::testing::Values(make_tuple(&aom_highbd_dc_predictor_32x32_sse2,
                                 &aom_highbd_dc_predictor_32x32_c, 32, 12),
                      make_tuple(&aom_highbd_tm_predictor_16x16_sse2,
                                 &aom_highbd_tm_predictor_16x16_c, 16, 12),
                      make_tuple(&aom_highbd_tm_predictor_32x32_sse2,
                                 &aom_highbd_tm_predictor_32x32_c, 32, 12),
                      make_tuple(&aom_highbd_dc_predictor_4x4_sse2,
                                 &aom_highbd_dc_predictor_4x4_c, 4, 12),
                      make_tuple(&aom_highbd_dc_predictor_8x8_sse2,
                                 &aom_highbd_dc_predictor_8x8_c, 8, 12),
                      make_tuple(&aom_highbd_dc_predictor_16x16_sse2,
                                 &aom_highbd_dc_predictor_16x16_c, 16, 12),
                      make_tuple(&aom_highbd_v_predictor_4x4_sse2,
                                 &aom_highbd_v_predictor_4x4_c, 4, 12),
                      make_tuple(&aom_highbd_v_predictor_8x8_sse2,
                                 &aom_highbd_v_predictor_8x8_c, 8, 12),
                      make_tuple(&aom_highbd_v_predictor_16x16_sse2,
                                 &aom_highbd_v_predictor_16x16_c, 16, 12),
                      make_tuple(&aom_highbd_v_predictor_32x32_sse2,
                                 &aom_highbd_v_predictor_32x32_c, 32, 12),
                      make_tuple(&aom_highbd_tm_predictor_4x4_sse2,
                                 &aom_highbd_tm_predictor_4x4_c, 4, 12),
                      make_tuple(&aom_highbd_tm_predictor_8x8_sse2,
                                 &aom_highbd_tm_predictor_8x8_c, 8, 12)));
214

215
#endif  // CONFIG_USE_X86INC
216
#endif  // CONFIG_AOM_HIGHBITDEPTH
217
218
#endif  // HAVE_SSE2
}  // namespace