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. |
| 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 | |
| 16 | #include "third_party/googletest/src/include/gtest/gtest.h" |
| 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 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | #include "av1/encoder/dct.c" |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 25 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 26 | using libaom_test::ACMRandom; |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 27 | |
| 28 | namespace { |
| 29 | void reference_dct_1d(const double *in, double *out, int size) { |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 30 | 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-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 36 | if (k == 0) out[k] = out[k] * kInvSqrt2; |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
| 40 | typedef void (*FdctFuncRef)(const double *in, double *out, int size); |
| 41 | typedef void (*IdctFuncRef)(const double *in, double *out, int size); |
| 42 | typedef void (*FdctFunc)(const tran_low_t *in, tran_low_t *out); |
| 43 | typedef void (*IdctFunc)(const tran_low_t *in, tran_low_t *out); |
| 44 | |
| 45 | class TransTestBase { |
| 46 | public: |
| 47 | virtual ~TransTestBase() {} |
| 48 | |
| 49 | protected: |
| 50 | void RunFwdAccuracyCheck() { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 51 | tran_low_t *input = new tran_low_t[txfm_size_]; |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 52 | tran_low_t *output = new tran_low_t[txfm_size_]; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 53 | double *ref_input = new double[txfm_size_]; |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 54 | double *ref_output = new double[txfm_size_]; |
| 55 | |
| 56 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 57 | const int count_test_block = 5000; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 58 | for (int ti = 0; ti < count_test_block; ++ti) { |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 59 | 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 | |
| 86 | typedef std::tr1::tuple<FdctFunc, FdctFuncRef, int, int> FdctParam; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 87 | class AV1FwdTxfm : public TransTestBase, |
| 88 | public ::testing::TestWithParam<FdctParam> { |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 89 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 99 | TEST_P(AV1FwdTxfm, RunFwdAccuracyCheck) { RunFwdAccuracyCheck(); } |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 100 | |
| 101 | INSTANTIATE_TEST_CASE_P( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 102 | C, AV1FwdTxfm, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 103 | ::testing::Values(FdctParam(&fdct4, &reference_dct_1d, 4, 1), |
| 104 | FdctParam(&fdct8, &reference_dct_1d, 8, 1), |
Yi Luo | 157e45a | 2016-10-17 11:18:50 -0700 | [diff] [blame] | 105 | FdctParam(&fdct16, &reference_dct_1d, 16, 2), |
| 106 | FdctParam(&fdct32, &reference_dct_1d, 32, 3))); |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 107 | } // namespace |