blob: fc1787f765eee645cfbefcf9524c0de2b254c19d [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>
Urvang Joshi5fb50f82017-12-12 18:48:55 -080015#include <vector>
Yaowu Xuf883b422016-08-30 14:01:10 -070016
17#include "test/acm_random.h"
18#include "test/util.h"
19#include "test/av1_txfm_test.h"
20#include "av1/common/av1_txfm.h"
21#include "./av1_rtcd.h"
22
23using libaom_test::ACMRandom;
Yaowu Xuf883b422016-08-30 14:01:10 -070024using libaom_test::Fwd_Txfm2d_Func;
25using libaom_test::TYPE_TXFM;
Johann123e8a62017-12-28 14:40:49 -080026using libaom_test::bd;
27using libaom_test::compute_avg_abs_error;
28using libaom_test::input_base;
Yaowu Xuf883b422016-08-30 14:01:10 -070029
Urvang Joshi5fb50f82017-12-12 18:48:55 -080030using std::vector;
31
Yaowu Xuf883b422016-08-30 14:01:10 -070032namespace {
Yaowu Xuf883b422016-08-30 14:01:10 -070033// tx_type_, tx_size_, max_error_, max_avg_error_
34typedef std::tr1::tuple<TX_TYPE, TX_SIZE, double, double> AV1FwdTxfm2dParam;
35
36class AV1FwdTxfm2d : public ::testing::TestWithParam<AV1FwdTxfm2dParam> {
37 public:
38 virtual void SetUp() {
39 tx_type_ = GET_PARAM(0);
40 tx_size_ = GET_PARAM(1);
41 max_error_ = GET_PARAM(2);
42 max_avg_error_ = GET_PARAM(3);
43 count_ = 500;
Urvang Joshic5022162017-11-21 15:57:42 -080044 TXFM_2D_FLIP_CFG fwd_txfm_flip_cfg;
45 av1_get_fwd_txfm_cfg(tx_type_, tx_size_, &fwd_txfm_flip_cfg);
Urvang Joshiec6acb22017-12-13 18:54:51 -080046 amplify_factor_ = libaom_test::get_amplification_factor(tx_type_, tx_size_);
Urvang Joshi5fb50f82017-12-12 18:48:55 -080047 tx_width_ = fwd_txfm_flip_cfg.row_cfg->txfm_size;
48 tx_height_ = fwd_txfm_flip_cfg.col_cfg->txfm_size;
Yaowu Xuf883b422016-08-30 14:01:10 -070049 ud_flip_ = fwd_txfm_flip_cfg.ud_flip;
50 lr_flip_ = fwd_txfm_flip_cfg.lr_flip;
Urvang Joshi5fb50f82017-12-12 18:48:55 -080051
Yaowu Xuf883b422016-08-30 14:01:10 -070052 fwd_txfm_ = libaom_test::fwd_txfm_func_ls[tx_size_];
Urvang Joshi5fb50f82017-12-12 18:48:55 -080053 txfm2d_size_ = tx_width_ * tx_height_;
Yaowu Xuf883b422016-08-30 14:01:10 -070054 input_ = reinterpret_cast<int16_t *>(
55 aom_memalign(16, sizeof(input_[0]) * txfm2d_size_));
56 output_ = reinterpret_cast<int32_t *>(
57 aom_memalign(16, sizeof(output_[0]) * txfm2d_size_));
58 ref_input_ = reinterpret_cast<double *>(
59 aom_memalign(16, sizeof(ref_input_[0]) * txfm2d_size_));
60 ref_output_ = reinterpret_cast<double *>(
61 aom_memalign(16, sizeof(ref_output_[0]) * txfm2d_size_));
62 }
63
64 void RunFwdAccuracyCheck() {
65 ACMRandom rnd(ACMRandom::DeterministicSeed());
66 double avg_abs_error = 0;
67 for (int ci = 0; ci < count_; ci++) {
68 for (int ni = 0; ni < txfm2d_size_; ++ni) {
69 input_[ni] = rnd.Rand16() % input_base;
70 ref_input_[ni] = static_cast<double>(input_[ni]);
71 output_[ni] = 0;
72 ref_output_[ni] = 0;
73 }
74
Urvang Joshi5fb50f82017-12-12 18:48:55 -080075 fwd_txfm_(input_, output_, tx_width_, tx_type_, bd);
Yaowu Xuf883b422016-08-30 14:01:10 -070076
Urvang Joshi5fb50f82017-12-12 18:48:55 -080077 if (lr_flip_ && ud_flip_) {
78 libaom_test::fliplrud(ref_input_, tx_width_, tx_height_, tx_width_);
79 } else if (lr_flip_) {
80 libaom_test::fliplr(ref_input_, tx_width_, tx_height_, tx_width_);
81 } else if (ud_flip_) {
82 libaom_test::flipud(ref_input_, tx_width_, tx_height_, tx_width_);
83 }
Yaowu Xuf883b422016-08-30 14:01:10 -070084
Urvang Joshiec6acb22017-12-13 18:54:51 -080085 libaom_test::reference_hybrid_2d(ref_input_, ref_output_, tx_type_,
86 tx_size_);
Yaowu Xuf883b422016-08-30 14:01:10 -070087
Urvang Joshi5fb50f82017-12-12 18:48:55 -080088 double actual_max_error = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070089 for (int ni = 0; ni < txfm2d_size_; ++ni) {
Urvang Joshiec6acb22017-12-13 18:54:51 -080090 ref_output_[ni] = round(ref_output_[ni]);
Urvang Joshi5fb50f82017-12-12 18:48:55 -080091 const double this_error =
92 fabs(output_[ni] - ref_output_[ni]) / amplify_factor_;
93 actual_max_error = AOMMAX(actual_max_error, this_error);
Yaowu Xuf883b422016-08-30 14:01:10 -070094 }
Urvang Joshi5fb50f82017-12-12 18:48:55 -080095 EXPECT_GE(max_error_, actual_max_error)
96 << "tx_size = " << tx_size_ << ", tx_type = " << tx_type_;
97 if (actual_max_error > max_error_) { // exit early.
98 break;
99 }
100
Yaowu Xuf883b422016-08-30 14:01:10 -0700101 avg_abs_error += compute_avg_abs_error<int32_t, double>(
102 output_, ref_output_, txfm2d_size_);
103 }
104
105 avg_abs_error /= amplify_factor_;
106 avg_abs_error /= count_;
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800107 EXPECT_GE(max_avg_error_, avg_abs_error)
108 << "tx_size = " << tx_size_ << ", tx_type = " << tx_type_;
Yaowu Xuf883b422016-08-30 14:01:10 -0700109 }
110
111 virtual void TearDown() {
112 aom_free(input_);
113 aom_free(output_);
114 aom_free(ref_input_);
115 aom_free(ref_output_);
116 }
117
118 private:
119 double max_error_;
120 double max_avg_error_;
121 int count_;
122 double amplify_factor_;
123 TX_TYPE tx_type_;
124 TX_SIZE tx_size_;
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800125 int tx_width_;
126 int tx_height_;
Yaowu Xuf883b422016-08-30 14:01:10 -0700127 int txfm2d_size_;
128 Fwd_Txfm2d_Func fwd_txfm_;
Yaowu Xuf883b422016-08-30 14:01:10 -0700129 int16_t *input_;
130 int32_t *output_;
131 double *ref_input_;
132 double *ref_output_;
133 int ud_flip_; // flip upside down
134 int lr_flip_; // flip left to right
135};
136
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800137vector<AV1FwdTxfm2dParam> GetTxfm2dParamList() {
138 vector<AV1FwdTxfm2dParam> param_list;
Debargha Mukherjeeaa84f3e2018-01-04 12:45:10 -0800139 for (int t = 0; t < TX_TYPES; ++t) {
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800140 const TX_TYPE tx_type = static_cast<TX_TYPE>(t);
Angie Chiang82517362018-01-17 17:31:54 -0800141 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_4X4, 3, 0.5));
Angie Chianga0d27592018-01-15 21:40:16 -0800142 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_8X8, 5, 0.5));
143 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_16X16, 11, 1.2));
144 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_32X32, 70, 6.1));
Yue Chenc1d9aef2017-12-28 16:13:13 -0800145#if CONFIG_TX64X64
146 if (tx_type == DCT_DCT) { // Other types not supported by these tx sizes.
Angie Chianga0d27592018-01-15 21:40:16 -0800147 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_64X64, 64, 3.4));
Yue Chenc1d9aef2017-12-28 16:13:13 -0800148 }
149#endif // CONFIG_TX64X64
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800150
Angie Chiang82517362018-01-17 17:31:54 -0800151 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_4X8, 3.2, 0.52));
152 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_8X4, 3.6, 0.64));
Angie Chianga0d27592018-01-15 21:40:16 -0800153 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_8X16, 8, 0.8));
154 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_16X8, 8, 1.1));
155 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_16X32, 29, 3.9));
156 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_32X16, 37, 5.9));
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800157
Angie Chiang82517362018-01-17 17:31:54 -0800158 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_4X16, 5, 0.6));
159 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_16X4, 6, 0.9));
Angie Chianga0d27592018-01-15 21:40:16 -0800160 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_8X32, 21, 1.2));
161 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_32X8, 13, 1.7));
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800162
Urvang Joshi72359922017-12-11 17:17:40 -0800163#if CONFIG_TX64X64
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800164 if (tx_type == DCT_DCT) { // Other types not supported by these tx sizes.
Angie Chianga0d27592018-01-15 21:40:16 -0800165 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_32X64, 136, 2.9));
166 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_64X32, 136, 4.9));
167 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_16X64, 30, 2.0));
168 param_list.push_back(AV1FwdTxfm2dParam(tx_type, TX_64X16, 36, 4.7));
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800169 }
Urvang Joshi72359922017-12-11 17:17:40 -0800170#endif // CONFIG_TX64X64
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800171 }
172 return param_list;
173}
Yaowu Xuf883b422016-08-30 14:01:10 -0700174
175INSTANTIATE_TEST_CASE_P(C, AV1FwdTxfm2d,
Urvang Joshi5fb50f82017-12-12 18:48:55 -0800176 ::testing::ValuesIn(GetTxfm2dParamList()));
177
178TEST_P(AV1FwdTxfm2d, RunFwdAccuracyCheck) { RunFwdAccuracyCheck(); }
Yaowu Xuf883b422016-08-30 14:01:10 -0700179
Angie Chiang9c7089a2017-08-08 16:21:11 -0700180TEST(AV1FwdTxfm2d, CfgTest) {
181 for (int bd_idx = 0; bd_idx < BD_NUM; ++bd_idx) {
182 int bd = libaom_test::bd_arr[bd_idx];
183 int8_t low_range = libaom_test::low_range_arr[bd_idx];
184 int8_t high_range = libaom_test::high_range_arr[bd_idx];
Urvang Joshi88710442017-12-11 16:41:26 -0800185 for (int tx_size = 0; tx_size < TX_SIZES_ALL; ++tx_size) {
Angie Chiang9c7089a2017-08-08 16:21:11 -0700186 for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) {
Urvang Joshiab2b36e2017-10-03 11:01:06 -0700187#if CONFIG_TX64X64
Urvang Joshi88710442017-12-11 16:41:26 -0800188 if ((tx_size_wide[tx_size] == 64 || tx_size_high[tx_size] == 64) &&
189 tx_type != DCT_DCT) {
190 continue;
191 }
Urvang Joshiab2b36e2017-10-03 11:01:06 -0700192#endif // CONFIG_TX64X64
Urvang Joshic5022162017-11-21 15:57:42 -0800193 TXFM_2D_FLIP_CFG cfg;
194 av1_get_fwd_txfm_cfg(static_cast<TX_TYPE>(tx_type),
195 static_cast<TX_SIZE>(tx_size), &cfg);
Angie Chiang9c7089a2017-08-08 16:21:11 -0700196 int8_t stage_range_col[MAX_TXFM_STAGE_NUM];
197 int8_t stage_range_row[MAX_TXFM_STAGE_NUM];
198 av1_gen_fwd_stage_range(stage_range_col, stage_range_row, &cfg, bd);
199 const TXFM_1D_CFG *col_cfg = cfg.col_cfg;
200 const TXFM_1D_CFG *row_cfg = cfg.row_cfg;
201 libaom_test::txfm_stage_range_check(stage_range_col, col_cfg->stage_num,
Angie Chiangd4327bc2018-01-22 20:54:04 -0800202 cfg.cos_bit_col, low_range,
Angie Chiang9c7089a2017-08-08 16:21:11 -0700203 high_range);
204 libaom_test::txfm_stage_range_check(stage_range_row, row_cfg->stage_num,
Angie Chiangd4327bc2018-01-22 20:54:04 -0800205 cfg.cos_bit_row, low_range,
Angie Chiang9c7089a2017-08-08 16:21:11 -0700206 high_range);
207 }
208 }
209 }
210}
211
Yaowu Xuf883b422016-08-30 14:01:10 -0700212} // namespace