blob: be8089987b4de1dd5f5678a04ef45828db4dc739 [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;
Yaowu Xud3d41592018-02-14 13:26:52 -080024const int txfm_size_ls[] = { 4, 8, 16, 32, 64 };
Angie Chiang444acd72015-10-27 16:59:02 -070025
Debargha Mukherjeeaa84f3e2018-01-04 12:45:10 -080026const TxfmFunc fwd_txfm_func_ls[][txfm_type_num] = {
Sebastien Alaiwan13f77be2017-03-08 15:25:10 +010027 { av1_fdct4_new, av1_fadst4_new },
28 { av1_fdct8_new, av1_fadst8_new },
29 { av1_fdct16_new, av1_fadst16_new },
30 { av1_fdct32_new, av1_fadst32_new },
Sebastien Alaiwan13f77be2017-03-08 15:25:10 +010031 { av1_fdct64_new, NULL },
clang-format3a826f12016-08-11 17:46:05 -070032};
Angie Chiang444acd72015-10-27 16:59:02 -070033
Debargha Mukherjeeaa84f3e2018-01-04 12:45:10 -080034const TxfmFunc inv_txfm_func_ls[][txfm_type_num] = {
Sebastien Alaiwan13f77be2017-03-08 15:25:10 +010035 { av1_idct4_new, av1_iadst4_new },
36 { av1_idct8_new, av1_iadst8_new },
37 { av1_idct16_new, av1_iadst16_new },
38 { av1_idct32_new, av1_iadst32_new },
Sebastien Alaiwan13f77be2017-03-08 15:25:10 +010039 { av1_idct64_new, NULL },
clang-format3a826f12016-08-11 17:46:05 -070040};
Angie Chiang444acd72015-10-27 16:59:02 -070041
42// the maximum stage number of fwd/inv 1d dct/adst txfm is 12
Angie Chiangd4327bc2018-01-22 20:54:04 -080043const int8_t cos_bit = 13;
Angie Chianga87dc762018-02-06 17:16:48 -080044const int8_t range_bit[12] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 };
Angie Chiang444acd72015-10-27 16:59:02 -070045
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020046void reference_idct_1d_int(const int32_t *in, int32_t *out, int size) {
47 double input[64];
48 for (int i = 0; i < size; ++i) input[i] = in[i];
49
50 double output[64];
51 libaom_test::reference_idct_1d(input, output, size);
52
Urvang Joshiab2b36e2017-10-03 11:01:06 -070053 for (int i = 0; i < size; ++i) {
54 ASSERT_GE(output[i], INT32_MIN);
55 ASSERT_LE(output[i], INT32_MAX);
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020056 out[i] = static_cast<int32_t>(round(output[i]));
Urvang Joshiab2b36e2017-10-03 11:01:06 -070057 }
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020058}
59
60void random_matrix(int32_t *dst, int len, ACMRandom *rnd) {
61 const int bits = 16;
62 const int maxVal = (1 << (bits - 1)) - 1;
63 const int minVal = -(1 << (bits - 1));
64 for (int i = 0; i < len; ++i) {
65 if (rnd->Rand8() % 10)
66 dst[i] = minVal + rnd->Rand16() % (1 << bits);
67 else
68 dst[i] = rnd->Rand8() % 2 ? minVal : maxVal;
69 }
70}
71
72TEST(av1_inv_txfm1d, InvAccuracyCheck) {
73 ACMRandom rnd(ACMRandom::DeterministicSeed());
74 const int count_test_block = 20000;
Yaowu Xud3d41592018-02-14 13:26:52 -080075 const int max_error[] = { 6, 10, 19, 31, 40 };
Urvang Joshiab2b36e2017-10-03 11:01:06 -070076 ASSERT_EQ(NELEMENTS(max_error), TX_SIZES);
77 ASSERT_EQ(NELEMENTS(inv_txfm_func_ls), TX_SIZES);
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020078 for (int k = 0; k < count_test_block; ++k) {
79 // choose a random transform to test
Urvang Joshiab2b36e2017-10-03 11:01:06 -070080 const TX_SIZE tx_size = static_cast<TX_SIZE>(rnd.Rand8() % TX_SIZES);
81 const int tx_size_pix = txfm_size_ls[tx_size];
82 const TxfmFunc inv_txfm_func = inv_txfm_func_ls[tx_size][0];
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020083
84 int32_t input[64];
Urvang Joshiab2b36e2017-10-03 11:01:06 -070085 random_matrix(input, tx_size_pix, &rnd);
86
Urvang Joshiab2b36e2017-10-03 11:01:06 -070087 // 64x64 transform assumes last 32 values are zero.
88 memset(input + 32, 0, 32 * sizeof(input[0]));
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020089
90 int32_t ref_output[64];
Urvang Joshiab2b36e2017-10-03 11:01:06 -070091 reference_idct_1d_int(input, ref_output, tx_size_pix);
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020092
93 int32_t output[64];
Urvang Joshiab2b36e2017-10-03 11:01:06 -070094 inv_txfm_func(input, output, cos_bit, range_bit);
Sebastien Alaiwand02642f2017-07-10 11:41:44 +020095
Urvang Joshiab2b36e2017-10-03 11:01:06 -070096 for (int i = 0; i < tx_size_pix; ++i) {
97 EXPECT_LE(abs(output[i] - ref_output[i]), max_error[tx_size])
98 << "tx_size = " << tx_size << ", i = " << i
99 << ", output[i] = " << output[i]
100 << ", ref_output[i] = " << ref_output[i];
Sebastien Alaiwand02642f2017-07-10 11:41:44 +0200101 }
102 }
103}
104
Sebastien Alaiwan36967372017-09-27 17:02:20 +0200105static INLINE int get_max_bit(int x) {
106 int max_bit = -1;
107 while (x) {
108 x = x >> 1;
109 max_bit++;
110 }
111 return max_bit;
112}
113
114TEST(av1_inv_txfm1d, get_max_bit) {
115 int max_bit = get_max_bit(8);
116 EXPECT_EQ(max_bit, 3);
117}
118
Yaowu Xuf883b422016-08-30 14:01:10 -0700119TEST(av1_inv_txfm1d, round_trip) {
Angie Chiang444acd72015-10-27 16:59:02 -0700120 ACMRandom rnd(ACMRandom::DeterministicSeed());
Sebastien Alaiwaned9e0d02017-07-13 10:44:58 +0200121 for (int si = 0; si < NELEMENTS(fwd_txfm_func_ls); ++si) {
Angie Chiang444acd72015-10-27 16:59:02 -0700122 int txfm_size = txfm_size_ls[si];
Angie Chiang444acd72015-10-27 16:59:02 -0700123
124 for (int ti = 0; ti < txfm_type_num; ++ti) {
Sebastien Alaiwan13f77be2017-03-08 15:25:10 +0100125 TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[si][ti];
126 TxfmFunc inv_txfm_func = inv_txfm_func_ls[si][ti];
Angie Chiang444acd72015-10-27 16:59:02 -0700127 int max_error = 2;
128
Sebastien Alaiwan7889e5f2017-03-08 15:26:27 +0100129 if (!fwd_txfm_func) continue;
Angie Chiang444acd72015-10-27 16:59:02 -0700130
Sebastien Alaiwan7889e5f2017-03-08 15:26:27 +0100131 const int count_test_block = 5000;
132 for (int ci = 0; ci < count_test_block; ++ci) {
Sebastien Alaiwan1f40e222017-03-08 15:27:20 +0100133 int32_t input[64];
134 int32_t output[64];
135 int32_t round_trip_output[64];
136
Sebastien Alaiwan8b730a52017-07-14 08:12:54 +0200137 ASSERT_LE(txfm_size, NELEMENTS(input));
Sebastien Alaiwan1f40e222017-03-08 15:27:20 +0100138
Sebastien Alaiwan7889e5f2017-03-08 15:26:27 +0100139 for (int ni = 0; ni < txfm_size; ++ni) {
140 input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base;
141 }
Angie Chiang444acd72015-10-27 16:59:02 -0700142
Sebastien Alaiwan7889e5f2017-03-08 15:26:27 +0100143 fwd_txfm_func(input, output, cos_bit, range_bit);
144 inv_txfm_func(output, round_trip_output, cos_bit, range_bit);
145
146 for (int ni = 0; ni < txfm_size; ++ni) {
147 int node_err =
148 abs(input[ni] - round_shift(round_trip_output[ni],
149 get_max_bit(txfm_size) - 1));
150 EXPECT_LE(node_err, max_error);
Angie Chiang444acd72015-10-27 16:59:02 -0700151 }
152 }
153 }
Angie Chiang444acd72015-10-27 16:59:02 -0700154 }
155}
156
157} // namespace