2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
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.
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"
21 #undef CONFIG_COEFFICIENT_RANGE_CHECKING
22 #define CONFIG_COEFFICIENT_RANGE_CHECKING 1
23 #include "vp10/encoder/dct.c"
25 using libvpx_test::ACMRandom
;
28 void reference_dct_1d(const double *in
, double *out
, int size
) {
29 const double PI
= 3.141592653589793238462643383279502884;
30 const double kInvSqrt2
= 0.707106781186547524400844362104;
31 for (int k
= 0; k
< size
; ++k
) {
33 for (int n
= 0; n
< size
; ++n
) {
34 out
[k
] += in
[n
] * cos(PI
* (2 * n
+ 1) * k
/ (2 * size
));
37 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
);
48 virtual ~TransTestBase() {}
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
) {
70 abs(output
[ni
] - static_cast<tran_low_t
>(round(ref_output
[ni
]))),
84 FdctFuncRef fwd_txfm_ref_
;
87 typedef std::tr1::tuple
<FdctFunc
, FdctFuncRef
, int, int> FdctParam
;
89 : public TransTestBase
,
90 public ::testing::TestWithParam
<FdctParam
> {
92 virtual void SetUp() {
93 fwd_txfm_
= GET_PARAM(0);
94 fwd_txfm_ref_
= GET_PARAM(1);
95 txfm_size_
= GET_PARAM(2);
96 max_error_
= GET_PARAM(3);
98 virtual void TearDown() {}
101 TEST_P(Vp10FwdTxfm
, RunFwdAccuracyCheck
) {
102 RunFwdAccuracyCheck();
105 INSTANTIATE_TEST_CASE_P(
108 FdctParam(&fdct4
, &reference_dct_1d
, 4, 1),
109 FdctParam(&fdct8
, &reference_dct_1d
, 8, 1),
110 FdctParam(&fdct16
, &reference_dct_1d
, 16, 2)));