Add ssse3 aom_smooth_h_predictor_4xh
[aom.git] / test / av1_dct_test.cc
blobfd68a54ef7b7767a3e3eb14621c5417f0cdc15be
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
12 #include <math.h>
13 #include <stdlib.h>
14 #include <new>
16 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
17 #include "test/acm_random.h"
18 #include "test/util.h"
19 #include "./aom_config.h"
20 #include "aom_ports/msvc.h"
22 #undef CONFIG_COEFFICIENT_RANGE_CHECKING
23 #define CONFIG_COEFFICIENT_RANGE_CHECKING 1
24 #define AV1_DCT_GTEST
25 #include "av1/encoder/dct.c"
27 using libaom_test::ACMRandom;
29 namespace {
30 void reference_dct_1d(const double *in, double *out, int size) {
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));
37 if (k == 0) out[k] = out[k] * kInvSqrt2;
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);
46 class TransTestBase {
47 public:
48 virtual ~TransTestBase() {}
50 protected:
51 void RunFwdAccuracyCheck() {
52 tran_low_t *input = new tran_low_t[txfm_size_];
53 tran_low_t *output = new tran_low_t[txfm_size_];
54 double *ref_input = new double[txfm_size_];
55 double *ref_output = new double[txfm_size_];
57 ACMRandom rnd(ACMRandom::DeterministicSeed());
58 const int count_test_block = 5000;
59 for (int ti = 0; ti < count_test_block; ++ti) {
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]);
65 fwd_txfm_(input, output);
66 fwd_txfm_ref_(ref_input, ref_output, txfm_size_);
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_);
75 delete[] input;
76 delete[] output;
77 delete[] ref_input;
78 delete[] ref_output;
81 double max_error_;
82 int txfm_size_;
83 FdctFunc fwd_txfm_;
84 FdctFuncRef fwd_txfm_ref_;
87 typedef std::tr1::tuple<FdctFunc, FdctFuncRef, int, int> FdctParam;
88 class AV1FwdTxfm : 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);
97 virtual void TearDown() {}
100 TEST_P(AV1FwdTxfm, RunFwdAccuracyCheck) { RunFwdAccuracyCheck(); }
102 INSTANTIATE_TEST_CASE_P(
103 C, AV1FwdTxfm,
104 ::testing::Values(FdctParam(&fdct4, &reference_dct_1d, 4, 1),
105 FdctParam(&fdct8, &reference_dct_1d, 8, 1),
106 FdctParam(&fdct16, &reference_dct_1d, 16, 2),
107 FdctParam(&fdct32, &reference_dct_1d, 32, 3)));
108 } // namespace