blob: 25cf5ad53b01319be534911e0db2fb8b99db6e05 [file] [log] [blame]
Yaowu Xuf883b422016-08-30 14:01:10 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuf883b422016-08-30 14:01:10 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * 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.
Yaowu Xuf883b422016-08-30 14:01:10 -070010 */
11
12#include <math.h>
13#include <stdio.h>
14#include <stdlib.h>
15
16#include "test/acm_random.h"
17#include "test/util.h"
18#include "test/av1_txfm_test.h"
19#include "av1/common/av1_txfm.h"
20#include "./av1_rtcd.h"
21
22using libaom_test::ACMRandom;
23using libaom_test::input_base;
24using libaom_test::bd;
25using libaom_test::compute_avg_abs_error;
26using libaom_test::Fwd_Txfm2d_Func;
27using libaom_test::TYPE_TXFM;
28
29namespace {
Sebastien Alaiwan71e87842017-04-12 16:03:28 +020030#if CONFIG_HIGHBITDEPTH
Yaowu Xuf883b422016-08-30 14:01:10 -070031// tx_type_, tx_size_, max_error_, max_avg_error_
32typedef std::tr1::tuple<TX_TYPE, TX_SIZE, double, double> AV1FwdTxfm2dParam;
33
34class AV1FwdTxfm2d : public ::testing::TestWithParam<AV1FwdTxfm2dParam> {
35 public:
36 virtual void SetUp() {
37 tx_type_ = GET_PARAM(0);
38 tx_size_ = GET_PARAM(1);
39 max_error_ = GET_PARAM(2);
40 max_avg_error_ = GET_PARAM(3);
41 count_ = 500;
42 TXFM_2D_FLIP_CFG fwd_txfm_flip_cfg =
43 av1_get_fwd_txfm_cfg(tx_type_, tx_size_);
44 const TXFM_2D_CFG *fwd_txfm_cfg = fwd_txfm_flip_cfg.cfg;
45 int amplify_bit = fwd_txfm_cfg->shift[0] + fwd_txfm_cfg->shift[1] +
46 fwd_txfm_cfg->shift[2];
47 ud_flip_ = fwd_txfm_flip_cfg.ud_flip;
48 lr_flip_ = fwd_txfm_flip_cfg.lr_flip;
49 amplify_factor_ =
50 amplify_bit >= 0 ? (1 << amplify_bit) : (1.0 / (1 << -amplify_bit));
51
52 fwd_txfm_ = libaom_test::fwd_txfm_func_ls[tx_size_];
53 txfm1d_size_ = libaom_test::get_txfm1d_size(tx_size_);
54 txfm2d_size_ = txfm1d_size_ * txfm1d_size_;
55 get_txfm1d_type(tx_type_, &type0_, &type1_);
56 input_ = reinterpret_cast<int16_t *>(
57 aom_memalign(16, sizeof(input_[0]) * txfm2d_size_));
58 output_ = reinterpret_cast<int32_t *>(
59 aom_memalign(16, sizeof(output_[0]) * txfm2d_size_));
60 ref_input_ = reinterpret_cast<double *>(
61 aom_memalign(16, sizeof(ref_input_[0]) * txfm2d_size_));
62 ref_output_ = reinterpret_cast<double *>(
63 aom_memalign(16, sizeof(ref_output_[0]) * txfm2d_size_));
64 }
65
66 void RunFwdAccuracyCheck() {
67 ACMRandom rnd(ACMRandom::DeterministicSeed());
68 double avg_abs_error = 0;
69 for (int ci = 0; ci < count_; ci++) {
70 for (int ni = 0; ni < txfm2d_size_; ++ni) {
71 input_[ni] = rnd.Rand16() % input_base;
72 ref_input_[ni] = static_cast<double>(input_[ni]);
73 output_[ni] = 0;
74 ref_output_[ni] = 0;
75 }
76
77 fwd_txfm_(input_, output_, txfm1d_size_, tx_type_, bd);
78
79 if (lr_flip_ && ud_flip_)
80 libaom_test::fliplrud(ref_input_, txfm1d_size_, txfm1d_size_);
81 else if (lr_flip_)
82 libaom_test::fliplr(ref_input_, txfm1d_size_, txfm1d_size_);
83 else if (ud_flip_)
84 libaom_test::flipud(ref_input_, txfm1d_size_, txfm1d_size_);
85
86 reference_hybrid_2d(ref_input_, ref_output_, txfm1d_size_, type0_,
87 type1_);
88
89 for (int ni = 0; ni < txfm2d_size_; ++ni) {
90 ref_output_[ni] = round(ref_output_[ni] * amplify_factor_);
91 EXPECT_GE(max_error_,
92 fabs(output_[ni] - ref_output_[ni]) / amplify_factor_);
93 }
94 avg_abs_error += compute_avg_abs_error<int32_t, double>(
95 output_, ref_output_, txfm2d_size_);
96 }
97
98 avg_abs_error /= amplify_factor_;
99 avg_abs_error /= count_;
100 // max_abs_avg_error comes from upper bound of avg_abs_error
101 // printf("type0: %d type1: %d txfm_size: %d accuracy_avg_abs_error:
102 // %f\n", type0_, type1_, txfm1d_size_, avg_abs_error);
103 EXPECT_GE(max_avg_error_, avg_abs_error);
104 }
105
106 virtual void TearDown() {
107 aom_free(input_);
108 aom_free(output_);
109 aom_free(ref_input_);
110 aom_free(ref_output_);
111 }
112
113 private:
114 double max_error_;
115 double max_avg_error_;
116 int count_;
117 double amplify_factor_;
118 TX_TYPE tx_type_;
119 TX_SIZE tx_size_;
120 int txfm1d_size_;
121 int txfm2d_size_;
122 Fwd_Txfm2d_Func fwd_txfm_;
123 TYPE_TXFM type0_;
124 TYPE_TXFM type1_;
125 int16_t *input_;
126 int32_t *output_;
127 double *ref_input_;
128 double *ref_output_;
129 int ud_flip_; // flip upside down
130 int lr_flip_; // flip left to right
131};
132
133TEST_P(AV1FwdTxfm2d, RunFwdAccuracyCheck) { RunFwdAccuracyCheck(); }
134const AV1FwdTxfm2dParam av1_fwd_txfm2d_param_c[] = {
135#if CONFIG_EXT_TX
136 AV1FwdTxfm2dParam(FLIPADST_DCT, TX_4X4, 2, 0.2),
137 AV1FwdTxfm2dParam(DCT_FLIPADST, TX_4X4, 2, 0.2),
138 AV1FwdTxfm2dParam(FLIPADST_FLIPADST, TX_4X4, 2, 0.2),
139 AV1FwdTxfm2dParam(ADST_FLIPADST, TX_4X4, 2, 0.2),
140 AV1FwdTxfm2dParam(FLIPADST_ADST, TX_4X4, 2, 0.2),
141 AV1FwdTxfm2dParam(FLIPADST_DCT, TX_8X8, 5, 0.6),
142 AV1FwdTxfm2dParam(DCT_FLIPADST, TX_8X8, 5, 0.6),
143 AV1FwdTxfm2dParam(FLIPADST_FLIPADST, TX_8X8, 5, 0.6),
144 AV1FwdTxfm2dParam(ADST_FLIPADST, TX_8X8, 5, 0.6),
145 AV1FwdTxfm2dParam(FLIPADST_ADST, TX_8X8, 5, 0.6),
146 AV1FwdTxfm2dParam(FLIPADST_DCT, TX_16X16, 11, 1.5),
147 AV1FwdTxfm2dParam(DCT_FLIPADST, TX_16X16, 11, 1.5),
148 AV1FwdTxfm2dParam(FLIPADST_FLIPADST, TX_16X16, 11, 1.5),
149 AV1FwdTxfm2dParam(ADST_FLIPADST, TX_16X16, 11, 1.5),
150 AV1FwdTxfm2dParam(FLIPADST_ADST, TX_16X16, 11, 1.5),
151 AV1FwdTxfm2dParam(FLIPADST_DCT, TX_32X32, 70, 7),
152 AV1FwdTxfm2dParam(DCT_FLIPADST, TX_32X32, 70, 7),
153 AV1FwdTxfm2dParam(FLIPADST_FLIPADST, TX_32X32, 70, 7),
154 AV1FwdTxfm2dParam(ADST_FLIPADST, TX_32X32, 70, 7),
155 AV1FwdTxfm2dParam(FLIPADST_ADST, TX_32X32, 70, 7),
156#endif
157 AV1FwdTxfm2dParam(DCT_DCT, TX_4X4, 2, 0.2),
158 AV1FwdTxfm2dParam(ADST_DCT, TX_4X4, 2, 0.2),
159 AV1FwdTxfm2dParam(DCT_ADST, TX_4X4, 2, 0.2),
160 AV1FwdTxfm2dParam(ADST_ADST, TX_4X4, 2, 0.2),
161 AV1FwdTxfm2dParam(DCT_DCT, TX_8X8, 5, 0.6),
162 AV1FwdTxfm2dParam(ADST_DCT, TX_8X8, 5, 0.6),
163 AV1FwdTxfm2dParam(DCT_ADST, TX_8X8, 5, 0.6),
164 AV1FwdTxfm2dParam(ADST_ADST, TX_8X8, 5, 0.6),
165 AV1FwdTxfm2dParam(DCT_DCT, TX_16X16, 11, 1.5),
166 AV1FwdTxfm2dParam(ADST_DCT, TX_16X16, 11, 1.5),
167 AV1FwdTxfm2dParam(DCT_ADST, TX_16X16, 11, 1.5),
168 AV1FwdTxfm2dParam(ADST_ADST, TX_16X16, 11, 1.5),
169 AV1FwdTxfm2dParam(DCT_DCT, TX_32X32, 70, 7),
170 AV1FwdTxfm2dParam(ADST_DCT, TX_32X32, 70, 7),
171 AV1FwdTxfm2dParam(DCT_ADST, TX_32X32, 70, 7),
172 AV1FwdTxfm2dParam(ADST_ADST, TX_32X32, 70, 7)
173};
174
175INSTANTIATE_TEST_CASE_P(C, AV1FwdTxfm2d,
176 ::testing::ValuesIn(av1_fwd_txfm2d_param_c));
177
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200178#endif // CONFIG_HIGHBITDEPTH
Yaowu Xuf883b422016-08-30 14:01:10 -0700179} // namespace