av1_dct_test.cc 3.28 KB
Newer Older
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
10
 * 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.
*/
11
12
13
14
15
16
17
18

#include <math.h>
#include <stdlib.h>
#include <new>

#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/acm_random.h"
#include "test/util.h"
Yaowu Xu's avatar
Yaowu Xu committed
19
#include "./aom_config.h"
20
#include "aom_ports/msvc.h"
21
22
23

#undef CONFIG_COEFFICIENT_RANGE_CHECKING
#define CONFIG_COEFFICIENT_RANGE_CHECKING 1
24
#include "av1/encoder/dct.c"
25

26
using libaom_test::ACMRandom;
27
28
29
30
31
32
33
34
35

namespace {
void reference_dct_1d(const double *in, double *out, int size) {
  const double kInvSqrt2 = 0.707106781186547524400844362104;
  for (int k = 0; k < size; ++k) {
    out[k] = 0;
    for (int n = 0; n < size; ++n) {
      out[k] += in[n] * cos(PI * (2 * n + 1) * k / (2 * size));
    }
clang-format's avatar
clang-format committed
36
    if (k == 0) out[k] = out[k] * kInvSqrt2;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  }
}

typedef void (*FdctFuncRef)(const double *in, double *out, int size);
typedef void (*IdctFuncRef)(const double *in, double *out, int size);
typedef void (*FdctFunc)(const tran_low_t *in, tran_low_t *out);
typedef void (*IdctFunc)(const tran_low_t *in, tran_low_t *out);

class TransTestBase {
 public:
  virtual ~TransTestBase() {}

 protected:
  void RunFwdAccuracyCheck() {
clang-format's avatar
clang-format committed
51
    tran_low_t *input = new tran_low_t[txfm_size_];
52
    tran_low_t *output = new tran_low_t[txfm_size_];
clang-format's avatar
clang-format committed
53
    double *ref_input = new double[txfm_size_];
54
55
56
57
    double *ref_output = new double[txfm_size_];

    ACMRandom rnd(ACMRandom::DeterministicSeed());
    const int count_test_block = 5000;
clang-format's avatar
clang-format committed
58
    for (int ti = 0; ti < count_test_block; ++ti) {
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
      for (int ni = 0; ni < txfm_size_; ++ni) {
        input[ni] = rnd.Rand8() - rnd.Rand8();
        ref_input[ni] = static_cast<double>(input[ni]);
      }

      fwd_txfm_(input, output);
      fwd_txfm_ref_(ref_input, ref_output, txfm_size_);

      for (int ni = 0; ni < txfm_size_; ++ni) {
        EXPECT_LE(
            abs(output[ni] - static_cast<tran_low_t>(round(ref_output[ni]))),
            max_error_);
      }
    }

    delete[] input;
    delete[] output;
    delete[] ref_input;
    delete[] ref_output;
  }

  double max_error_;
  int txfm_size_;
  FdctFunc fwd_txfm_;
  FdctFuncRef fwd_txfm_ref_;
};

typedef std::tr1::tuple<FdctFunc, FdctFuncRef, int, int> FdctParam;
Yaowu Xu's avatar
Yaowu Xu committed
87
88
class AV1FwdTxfm : public TransTestBase,
                   public ::testing::TestWithParam<FdctParam> {
89
90
91
92
93
94
95
96
97
98
 public:
  virtual void SetUp() {
    fwd_txfm_ = GET_PARAM(0);
    fwd_txfm_ref_ = GET_PARAM(1);
    txfm_size_ = GET_PARAM(2);
    max_error_ = GET_PARAM(3);
  }
  virtual void TearDown() {}
};

Yaowu Xu's avatar
Yaowu Xu committed
99
TEST_P(AV1FwdTxfm, RunFwdAccuracyCheck) { RunFwdAccuracyCheck(); }
100
101

INSTANTIATE_TEST_CASE_P(
Yaowu Xu's avatar
Yaowu Xu committed
102
    C, AV1FwdTxfm,
clang-format's avatar
clang-format committed
103
104
    ::testing::Values(FdctParam(&fdct4, &reference_dct_1d, 4, 1),
                      FdctParam(&fdct8, &reference_dct_1d, 8, 1),
105
106
                      FdctParam(&fdct16, &reference_dct_1d, 16, 2),
                      FdctParam(&fdct32, &reference_dct_1d, 32, 3)));
107
}  // namespace