Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 The WebM project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <math.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <new> |
| 14 | |
| 15 | #include "third_party/googletest/src/include/gtest/gtest.h" |
| 16 | #include "test/acm_random.h" |
| 17 | #include "test/util.h" |
| 18 | #include "./vpx_config.h" |
| 19 | #include "vpx_ports/msvc.h" |
| 20 | |
| 21 | #undef CONFIG_COEFFICIENT_RANGE_CHECKING |
| 22 | #define CONFIG_COEFFICIENT_RANGE_CHECKING 1 |
| 23 | #include "vp10/encoder/dct.c" |
| 24 | |
| 25 | using libvpx_test::ACMRandom; |
| 26 | |
| 27 | namespace { |
| 28 | void reference_dct_1d(const double *in, double *out, int size) { |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 29 | const double kInvSqrt2 = 0.707106781186547524400844362104; |
| 30 | for (int k = 0; k < size; ++k) { |
| 31 | out[k] = 0; |
| 32 | for (int n = 0; n < size; ++n) { |
| 33 | out[k] += in[n] * cos(PI * (2 * n + 1) * k / (2 * size)); |
| 34 | } |
| 35 | if (k == 0) |
| 36 | out[k] = out[k] * kInvSqrt2; |
| 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() { |
| 51 | tran_low_t *input = new tran_low_t[txfm_size_]; |
| 52 | tran_low_t *output = new tran_low_t[txfm_size_]; |
| 53 | double *ref_input = new double[txfm_size_]; |
| 54 | double *ref_output = new double[txfm_size_]; |
| 55 | |
| 56 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 57 | const int count_test_block = 5000; |
| 58 | for (int ti = 0; ti < count_test_block; ++ti) { |
| 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; |
| 87 | class Vp10FwdTxfm |
| 88 | : public TransTestBase, |
| 89 | public ::testing::TestWithParam<FdctParam> { |
| 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 | |
| 100 | TEST_P(Vp10FwdTxfm, RunFwdAccuracyCheck) { |
| 101 | RunFwdAccuracyCheck(); |
| 102 | } |
| 103 | |
| 104 | INSTANTIATE_TEST_CASE_P( |
| 105 | C, Vp10FwdTxfm, |
| 106 | ::testing::Values( |
| 107 | FdctParam(&fdct4, &reference_dct_1d, 4, 1), |
| 108 | FdctParam(&fdct8, &reference_dct_1d, 8, 1), |
Yaowu Xu | 7c514e2 | 2015-09-28 15:55:46 -0700 | [diff] [blame] | 109 | FdctParam(&fdct16, &reference_dct_1d, 16, 2))); |
Angie Chiang | fe776ce | 2015-08-28 20:39:10 -0700 | [diff] [blame] | 110 | } // namespace |