blob: 33cc61ca12c204cdab08a398854216c5e3c1d946 [file] [log] [blame]
Angie Chiang444acd72015-10-27 16:59:02 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Angie Chiang444acd72015-10-27 16:59:02 -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.
Angie Chiang444acd72015-10-27 16:59:02 -070010 */
11
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020012#include <math.h>
13
Yaowu Xuf883b422016-08-30 14:01:10 -070014#include "test/av1_txfm_test.h"
Sebastien Alaiwanb5138be2017-07-04 12:03:01 +020015#include "test/util.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "av1/common/av1_inv_txfm1d.h"
Urvang Joshi23145662017-12-13 12:25:46 -080017#include "av1/encoder/av1_fwd_txfm1d.h"
Angie Chiang444acd72015-10-27 16:59:02 -070018
Yaowu Xuc27fc142016-08-22 16:08:15 -070019using libaom_test::ACMRandom;
20using libaom_test::input_base;
Angie Chiang444acd72015-10-27 16:59:02 -070021
22namespace {
Angie Chiang29a06a12016-03-29 14:27:50 -070023const int txfm_type_num = 2;
Urvang Joshiab2b36e2017-10-03 11:01:06 -070024const int txfm_size_ls[] = {
25 4, 8, 16, 32,
26#if CONFIG_TX64X64
27 64,
28#endif // CONFIG_TX64X64
29};
Angie Chiang444acd72015-10-27 16:59:02 -070030
Debargha Mukherjeeaa84f3e2018-01-04 12:45:10 -080031const TxfmFunc fwd_txfm_func_ls[][txfm_type_num] = {
Sebastien Alaiwan13f77be2017-03-08 15:25:10 +010032 { av1_fdct4_new, av1_fadst4_new },
33 { av1_fdct8_new, av1_fadst8_new },
34 { av1_fdct16_new, av1_fadst16_new },
35 { av1_fdct32_new, av1_fadst32_new },
Angie Chiang792519b2016-10-18 12:24:20 -070036#if CONFIG_TX64X64
Sebastien Alaiwan13f77be2017-03-08 15:25:10 +010037 { av1_fdct64_new, NULL },
Angie Chiang792519b2016-10-18 12:24:20 -070038#endif
clang-format3a826f12016-08-11 17:46:05 -070039};
Angie Chiang444acd72015-10-27 16:59:02 -070040
Debargha Mukherjeeaa84f3e2018-01-04 12:45:10 -080041const TxfmFunc inv_txfm_func_ls[][txfm_type_num] = {
Sebastien Alaiwan13f77be2017-03-08 15:25:10 +010042 { av1_idct4_new, av1_iadst4_new },
43 { av1_idct8_new, av1_iadst8_new },
44 { av1_idct16_new, av1_iadst16_new },
45 { av1_idct32_new, av1_iadst32_new },
Angie Chiang792519b2016-10-18 12:24:20 -070046#if CONFIG_TX64X64
Sebastien Alaiwan13f77be2017-03-08 15:25:10 +010047 { av1_idct64_new, NULL },
Angie Chiang792519b2016-10-18 12:24:20 -070048#endif
clang-format3a826f12016-08-11 17:46:05 -070049};
Angie Chiang444acd72015-10-27 16:59:02 -070050
51// the maximum stage number of fwd/inv 1d dct/adst txfm is 12
Sebastien Alaiwane0f3a752017-07-10 12:27:15 +020052const int8_t cos_bit[12] = { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13 };
clang-format3a826f12016-08-11 17:46:05 -070053const int8_t range_bit[12] = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
Angie Chiang444acd72015-10-27 16:59:02 -070054
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020055void reference_idct_1d_int(const int32_t *in, int32_t *out, int size) {
56 double input[64];
57 for (int i = 0; i < size; ++i) input[i] = in[i];
58
59 double output[64];
60 libaom_test::reference_idct_1d(input, output, size);
61
Urvang Joshiab2b36e2017-10-03 11:01:06 -070062 for (int i = 0; i < size; ++i) {
63 ASSERT_GE(output[i], INT32_MIN);
64 ASSERT_LE(output[i], INT32_MAX);
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020065 out[i] = static_cast<int32_t>(round(output[i]));
Urvang Joshiab2b36e2017-10-03 11:01:06 -070066 }
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020067}
68
69void random_matrix(int32_t *dst, int len, ACMRandom *rnd) {
70 const int bits = 16;
71 const int maxVal = (1 << (bits - 1)) - 1;
72 const int minVal = -(1 << (bits - 1));
73 for (int i = 0; i < len; ++i) {
74 if (rnd->Rand8() % 10)
75 dst[i] = minVal + rnd->Rand16() % (1 << bits);
76 else
77 dst[i] = rnd->Rand8() % 2 ? minVal : maxVal;
78 }
79}
80
81TEST(av1_inv_txfm1d, InvAccuracyCheck) {
82 ACMRandom rnd(ACMRandom::DeterministicSeed());
83 const int count_test_block = 20000;
Urvang Joshiab2b36e2017-10-03 11:01:06 -070084 const int max_error[] = {
85 6,
86 10,
87 19,
88 31,
89#if CONFIG_TX64X64
90 40,
91#endif // CONFIG_TX64X64
92 };
93 ASSERT_EQ(NELEMENTS(max_error), TX_SIZES);
94 ASSERT_EQ(NELEMENTS(inv_txfm_func_ls), TX_SIZES);
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020095 for (int k = 0; k < count_test_block; ++k) {
96 // choose a random transform to test
Urvang Joshiab2b36e2017-10-03 11:01:06 -070097 const TX_SIZE tx_size = static_cast<TX_SIZE>(rnd.Rand8() % TX_SIZES);
98 const int tx_size_pix = txfm_size_ls[tx_size];
99 const TxfmFunc inv_txfm_func = inv_txfm_func_ls[tx_size][0];
Sebastien Alaiwand02642f2017-07-10 11:41:44 +0200100
101 int32_t input[64];
Urvang Joshiab2b36e2017-10-03 11:01:06 -0700102 random_matrix(input, tx_size_pix, &rnd);
103
104#if CONFIG_TX64X64
105 // 64x64 transform assumes last 32 values are zero.
106 memset(input + 32, 0, 32 * sizeof(input[0]));
107#endif // CONFIG_TX64X64
Sebastien Alaiwand02642f2017-07-10 11:41:44 +0200108
109 int32_t ref_output[64];
Urvang Joshiab2b36e2017-10-03 11:01:06 -0700110 reference_idct_1d_int(input, ref_output, tx_size_pix);
Sebastien Alaiwand02642f2017-07-10 11:41:44 +0200111
112 int32_t output[64];
Urvang Joshiab2b36e2017-10-03 11:01:06 -0700113 inv_txfm_func(input, output, cos_bit, range_bit);
Sebastien Alaiwand02642f2017-07-10 11:41:44 +0200114
Urvang Joshiab2b36e2017-10-03 11:01:06 -0700115 for (int i = 0; i < tx_size_pix; ++i) {
116 EXPECT_LE(abs(output[i] - ref_output[i]), max_error[tx_size])
117 << "tx_size = " << tx_size << ", i = " << i
118 << ", output[i] = " << output[i]
119 << ", ref_output[i] = " << ref_output[i];
Sebastien Alaiwand02642f2017-07-10 11:41:44 +0200120 }
121 }
122}
123
Sebastien Alaiwan36967372017-09-27 17:02:20 +0200124static INLINE int get_max_bit(int x) {
125 int max_bit = -1;
126 while (x) {
127 x = x >> 1;
128 max_bit++;
129 }
130 return max_bit;
131}
132
133TEST(av1_inv_txfm1d, get_max_bit) {
134 int max_bit = get_max_bit(8);
135 EXPECT_EQ(max_bit, 3);
136}
137
Yaowu Xuf883b422016-08-30 14:01:10 -0700138TEST(av1_inv_txfm1d, round_trip) {
Angie Chiang444acd72015-10-27 16:59:02 -0700139 ACMRandom rnd(ACMRandom::DeterministicSeed());
Sebastien Alaiwaned9e0d02017-07-13 10:44:58 +0200140 for (int si = 0; si < NELEMENTS(fwd_txfm_func_ls); ++si) {
Angie Chiang444acd72015-10-27 16:59:02 -0700141 int txfm_size = txfm_size_ls[si];
Angie Chiang444acd72015-10-27 16:59:02 -0700142
143 for (int ti = 0; ti < txfm_type_num; ++ti) {
Sebastien Alaiwan13f77be2017-03-08 15:25:10 +0100144 TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[si][ti];
145 TxfmFunc inv_txfm_func = inv_txfm_func_ls[si][ti];
Angie Chiang444acd72015-10-27 16:59:02 -0700146 int max_error = 2;
147
Sebastien Alaiwan7889e5f2017-03-08 15:26:27 +0100148 if (!fwd_txfm_func) continue;
Angie Chiang444acd72015-10-27 16:59:02 -0700149
Sebastien Alaiwan7889e5f2017-03-08 15:26:27 +0100150 const int count_test_block = 5000;
151 for (int ci = 0; ci < count_test_block; ++ci) {
Sebastien Alaiwan1f40e222017-03-08 15:27:20 +0100152 int32_t input[64];
153 int32_t output[64];
154 int32_t round_trip_output[64];
155
Sebastien Alaiwan8b730a52017-07-14 08:12:54 +0200156 ASSERT_LE(txfm_size, NELEMENTS(input));
Sebastien Alaiwan1f40e222017-03-08 15:27:20 +0100157
Sebastien Alaiwan7889e5f2017-03-08 15:26:27 +0100158 for (int ni = 0; ni < txfm_size; ++ni) {
159 input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base;
160 }
Angie Chiang444acd72015-10-27 16:59:02 -0700161
Sebastien Alaiwan7889e5f2017-03-08 15:26:27 +0100162 fwd_txfm_func(input, output, cos_bit, range_bit);
163 inv_txfm_func(output, round_trip_output, cos_bit, range_bit);
164
165 for (int ni = 0; ni < txfm_size; ++ni) {
166 int node_err =
167 abs(input[ni] - round_shift(round_trip_output[ni],
168 get_max_bit(txfm_size) - 1));
169 EXPECT_LE(node_err, max_error);
Angie Chiang444acd72015-10-27 16:59:02 -0700170 }
171 }
172 }
Angie Chiang444acd72015-10-27 16:59:02 -0700173 }
174}
175
176} // namespace