blob: d5c23f6ce67dc4ffe1a01e85aed218e21fae4997 [file] [log] [blame]
Angie Chiangfe776ce2015-08-28 20:39:10 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Angie Chiangfe776ce2015-08-28 20:39:10 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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*/
Angie Chiangfe776ce2015-08-28 20:39:10 -070011
12#include <math.h>
13#include <stdlib.h>
14#include <new>
15
16#include "third_party/googletest/src/include/gtest/gtest.h"
17#include "test/acm_random.h"
18#include "test/util.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070019#include "./aom_config.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070020#include "aom_ports/msvc.h"
Angie Chiangfe776ce2015-08-28 20:39:10 -070021
22#undef CONFIG_COEFFICIENT_RANGE_CHECKING
23#define CONFIG_COEFFICIENT_RANGE_CHECKING 1
Yaowu Xuc27fc142016-08-22 16:08:15 -070024#include "av1/encoder/dct.c"
Angie Chiangfe776ce2015-08-28 20:39:10 -070025
Yaowu Xuc27fc142016-08-22 16:08:15 -070026using libaom_test::ACMRandom;
Angie Chiangfe776ce2015-08-28 20:39:10 -070027
28namespace {
29void reference_dct_1d(const double *in, double *out, int size) {
Angie Chiangfe776ce2015-08-28 20:39:10 -070030 const double kInvSqrt2 = 0.707106781186547524400844362104;
31 for (int k = 0; k < size; ++k) {
32 out[k] = 0;
33 for (int n = 0; n < size; ++n) {
34 out[k] += in[n] * cos(PI * (2 * n + 1) * k / (2 * size));
35 }
clang-format3a826f12016-08-11 17:46:05 -070036 if (k == 0) out[k] = out[k] * kInvSqrt2;
Angie Chiangfe776ce2015-08-28 20:39:10 -070037 }
38}
39
40typedef void (*FdctFuncRef)(const double *in, double *out, int size);
41typedef void (*IdctFuncRef)(const double *in, double *out, int size);
42typedef void (*FdctFunc)(const tran_low_t *in, tran_low_t *out);
43typedef void (*IdctFunc)(const tran_low_t *in, tran_low_t *out);
44
45class TransTestBase {
46 public:
47 virtual ~TransTestBase() {}
48
49 protected:
50 void RunFwdAccuracyCheck() {
clang-format3a826f12016-08-11 17:46:05 -070051 tran_low_t *input = new tran_low_t[txfm_size_];
Angie Chiangfe776ce2015-08-28 20:39:10 -070052 tran_low_t *output = new tran_low_t[txfm_size_];
clang-format3a826f12016-08-11 17:46:05 -070053 double *ref_input = new double[txfm_size_];
Angie Chiangfe776ce2015-08-28 20:39:10 -070054 double *ref_output = new double[txfm_size_];
55
56 ACMRandom rnd(ACMRandom::DeterministicSeed());
57 const int count_test_block = 5000;
clang-format3a826f12016-08-11 17:46:05 -070058 for (int ti = 0; ti < count_test_block; ++ti) {
Angie Chiangfe776ce2015-08-28 20:39:10 -070059 for (int ni = 0; ni < txfm_size_; ++ni) {
60 input[ni] = rnd.Rand8() - rnd.Rand8();
61 ref_input[ni] = static_cast<double>(input[ni]);
62 }
63
64 fwd_txfm_(input, output);
65 fwd_txfm_ref_(ref_input, ref_output, txfm_size_);
66
67 for (int ni = 0; ni < txfm_size_; ++ni) {
68 EXPECT_LE(
69 abs(output[ni] - static_cast<tran_low_t>(round(ref_output[ni]))),
70 max_error_);
71 }
72 }
73
74 delete[] input;
75 delete[] output;
76 delete[] ref_input;
77 delete[] ref_output;
78 }
79
80 double max_error_;
81 int txfm_size_;
82 FdctFunc fwd_txfm_;
83 FdctFuncRef fwd_txfm_ref_;
84};
85
86typedef std::tr1::tuple<FdctFunc, FdctFuncRef, int, int> FdctParam;
Yaowu Xuf883b422016-08-30 14:01:10 -070087class AV1FwdTxfm : public TransTestBase,
88 public ::testing::TestWithParam<FdctParam> {
Angie Chiangfe776ce2015-08-28 20:39:10 -070089 public:
90 virtual void SetUp() {
91 fwd_txfm_ = GET_PARAM(0);
92 fwd_txfm_ref_ = GET_PARAM(1);
93 txfm_size_ = GET_PARAM(2);
94 max_error_ = GET_PARAM(3);
95 }
96 virtual void TearDown() {}
97};
98
Yaowu Xuf883b422016-08-30 14:01:10 -070099TEST_P(AV1FwdTxfm, RunFwdAccuracyCheck) { RunFwdAccuracyCheck(); }
Angie Chiangfe776ce2015-08-28 20:39:10 -0700100
101INSTANTIATE_TEST_CASE_P(
Yaowu Xuf883b422016-08-30 14:01:10 -0700102 C, AV1FwdTxfm,
clang-format3a826f12016-08-11 17:46:05 -0700103 ::testing::Values(FdctParam(&fdct4, &reference_dct_1d, 4, 1),
104 FdctParam(&fdct8, &reference_dct_1d, 8, 1),
Yi Luo157e45a2016-10-17 11:18:50 -0700105 FdctParam(&fdct16, &reference_dct_1d, 16, 2),
106 FdctParam(&fdct32, &reference_dct_1d, 32, 3)));
Angie Chiangfe776ce2015-08-28 20:39:10 -0700107} // namespace