blob: fd68a54ef7b7767a3e3eb14621c5417f0cdc15be [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.
Johann123e8a62017-12-28 14:40:49 -080010 */
Angie Chiangfe776ce2015-08-28 20:39:10 -070011
12#include <math.h>
13#include <stdlib.h>
14#include <new>
15
Tom Finegan7a07ece2017-02-07 17:14:05 -080016#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Angie Chiangfe776ce2015-08-28 20:39:10 -070017#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
James Zerne2a703e2017-01-24 21:05:23 -080024#define AV1_DCT_GTEST
Yaowu Xuc27fc142016-08-22 16:08:15 -070025#include "av1/encoder/dct.c"
Angie Chiangfe776ce2015-08-28 20:39:10 -070026
Yaowu Xuc27fc142016-08-22 16:08:15 -070027using libaom_test::ACMRandom;
Angie Chiangfe776ce2015-08-28 20:39:10 -070028
29namespace {
30void reference_dct_1d(const double *in, double *out, int size) {
Angie Chiangfe776ce2015-08-28 20:39:10 -070031 const double kInvSqrt2 = 0.707106781186547524400844362104;
32 for (int k = 0; k < size; ++k) {
33 out[k] = 0;
34 for (int n = 0; n < size; ++n) {
35 out[k] += in[n] * cos(PI * (2 * n + 1) * k / (2 * size));
36 }
clang-format3a826f12016-08-11 17:46:05 -070037 if (k == 0) out[k] = out[k] * kInvSqrt2;
Angie Chiangfe776ce2015-08-28 20:39:10 -070038 }
39}
40
41typedef void (*FdctFuncRef)(const double *in, double *out, int size);
42typedef void (*IdctFuncRef)(const double *in, double *out, int size);
43typedef void (*FdctFunc)(const tran_low_t *in, tran_low_t *out);
44typedef void (*IdctFunc)(const tran_low_t *in, tran_low_t *out);
45
46class TransTestBase {
47 public:
48 virtual ~TransTestBase() {}
49
50 protected:
51 void RunFwdAccuracyCheck() {
clang-format3a826f12016-08-11 17:46:05 -070052 tran_low_t *input = new tran_low_t[txfm_size_];
Angie Chiangfe776ce2015-08-28 20:39:10 -070053 tran_low_t *output = new tran_low_t[txfm_size_];
clang-format3a826f12016-08-11 17:46:05 -070054 double *ref_input = new double[txfm_size_];
Angie Chiangfe776ce2015-08-28 20:39:10 -070055 double *ref_output = new double[txfm_size_];
56
57 ACMRandom rnd(ACMRandom::DeterministicSeed());
58 const int count_test_block = 5000;
clang-format3a826f12016-08-11 17:46:05 -070059 for (int ti = 0; ti < count_test_block; ++ti) {
Angie Chiangfe776ce2015-08-28 20:39:10 -070060 for (int ni = 0; ni < txfm_size_; ++ni) {
61 input[ni] = rnd.Rand8() - rnd.Rand8();
62 ref_input[ni] = static_cast<double>(input[ni]);
63 }
64
65 fwd_txfm_(input, output);
66 fwd_txfm_ref_(ref_input, ref_output, txfm_size_);
67
68 for (int ni = 0; ni < txfm_size_; ++ni) {
69 EXPECT_LE(
70 abs(output[ni] - static_cast<tran_low_t>(round(ref_output[ni]))),
71 max_error_);
72 }
73 }
74
75 delete[] input;
76 delete[] output;
77 delete[] ref_input;
78 delete[] ref_output;
79 }
80
81 double max_error_;
82 int txfm_size_;
83 FdctFunc fwd_txfm_;
84 FdctFuncRef fwd_txfm_ref_;
85};
86
87typedef std::tr1::tuple<FdctFunc, FdctFuncRef, int, int> FdctParam;
Yaowu Xuf883b422016-08-30 14:01:10 -070088class AV1FwdTxfm : public TransTestBase,
89 public ::testing::TestWithParam<FdctParam> {
Angie Chiangfe776ce2015-08-28 20:39:10 -070090 public:
91 virtual void SetUp() {
92 fwd_txfm_ = GET_PARAM(0);
93 fwd_txfm_ref_ = GET_PARAM(1);
94 txfm_size_ = GET_PARAM(2);
95 max_error_ = GET_PARAM(3);
96 }
97 virtual void TearDown() {}
98};
99
Yaowu Xuf883b422016-08-30 14:01:10 -0700100TEST_P(AV1FwdTxfm, RunFwdAccuracyCheck) { RunFwdAccuracyCheck(); }
Angie Chiangfe776ce2015-08-28 20:39:10 -0700101
102INSTANTIATE_TEST_CASE_P(
Yaowu Xuf883b422016-08-30 14:01:10 -0700103 C, AV1FwdTxfm,
clang-format3a826f12016-08-11 17:46:05 -0700104 ::testing::Values(FdctParam(&fdct4, &reference_dct_1d, 4, 1),
105 FdctParam(&fdct8, &reference_dct_1d, 8, 1),
Yi Luo157e45a2016-10-17 11:18:50 -0700106 FdctParam(&fdct16, &reference_dct_1d, 16, 2),
107 FdctParam(&fdct32, &reference_dct_1d, 32, 3)));
Angie Chiangfe776ce2015-08-28 20:39:10 -0700108} // namespace