Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 10 | */ |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 11 | |
| 12 | #include <math.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <new> |
| 15 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 16 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 17 | #include "test/acm_random.h" |
| 18 | #include "test/util.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 19 | #include "./aom_config.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | #include "aom_ports/msvc.h" |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 21 | |
| 22 | #undef CONFIG_COEFFICIENT_RANGE_CHECKING |
| 23 | #define CONFIG_COEFFICIENT_RANGE_CHECKING 1 |
James Zern | e2a703e | 2017-01-24 21:05:23 -0800 | [diff] [blame] | 24 | #define AV1_DCT_GTEST |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | #include "av1/encoder/dct.c" |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 26 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | using libaom_test::ACMRandom; |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 28 | |
| 29 | namespace { |
| 30 | void reference_dct_1d(const double *in, double *out, int size) { |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 31 | 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-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 37 | if (k == 0) out[k] = out[k] * kInvSqrt2; |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
| 41 | typedef void (*FdctFuncRef)(const double *in, double *out, int size); |
| 42 | typedef void (*IdctFuncRef)(const double *in, double *out, int size); |
| 43 | typedef void (*FdctFunc)(const tran_low_t *in, tran_low_t *out); |
| 44 | typedef void (*IdctFunc)(const tran_low_t *in, tran_low_t *out); |
| 45 | |
| 46 | class TransTestBase { |
| 47 | public: |
| 48 | virtual ~TransTestBase() {} |
| 49 | |
| 50 | protected: |
| 51 | void RunFwdAccuracyCheck() { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 52 | tran_low_t *input = new tran_low_t[txfm_size_]; |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 53 | tran_low_t *output = new tran_low_t[txfm_size_]; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 54 | double *ref_input = new double[txfm_size_]; |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 55 | double *ref_output = new double[txfm_size_]; |
| 56 | |
| 57 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 58 | const int count_test_block = 5000; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 59 | for (int ti = 0; ti < count_test_block; ++ti) { |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 60 | 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 | |
| 87 | typedef std::tr1::tuple<FdctFunc, FdctFuncRef, int, int> FdctParam; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 88 | class AV1FwdTxfm : public TransTestBase, |
| 89 | public ::testing::TestWithParam<FdctParam> { |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 90 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 100 | TEST_P(AV1FwdTxfm, RunFwdAccuracyCheck) { RunFwdAccuracyCheck(); } |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 101 | |
| 102 | INSTANTIATE_TEST_CASE_P( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 103 | C, AV1FwdTxfm, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 104 | ::testing::Values(FdctParam(&fdct4, &reference_dct_1d, 4, 1), |
| 105 | FdctParam(&fdct8, &reference_dct_1d, 8, 1), |
Yi Luo | 157e45a | 2016-10-17 11:18:50 -0700 | [diff] [blame] | 106 | FdctParam(&fdct16, &reference_dct_1d, 16, 2), |
| 107 | FdctParam(&fdct32, &reference_dct_1d, 32, 3))); |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 108 | } // namespace |