Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 4 | * 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 Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Sebastien Alaiwan | d02642f | 2017-07-10 11:41:44 +0200 | [diff] [blame] | 12 | #include <math.h> |
| 13 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 14 | #include "test/av1_txfm_test.h" |
Sebastien Alaiwan | b5138be | 2017-07-04 12:03:01 +0200 | [diff] [blame] | 15 | #include "test/util.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "av1/common/av1_inv_txfm1d.h" |
Urvang Joshi | 2314566 | 2017-12-13 12:25:46 -0800 | [diff] [blame] | 17 | #include "av1/encoder/av1_fwd_txfm1d.h" |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 18 | |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 19 | typedef TX_SIZE TxSize; |
| 20 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 21 | using libaom_test::ACMRandom; |
| 22 | using libaom_test::input_base; |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 23 | |
| 24 | namespace { |
Angie Chiang | 29a06a1 | 2016-03-29 14:27:50 -0700 | [diff] [blame] | 25 | const int txfm_type_num = 2; |
Yaowu Xu | d3d4159 | 2018-02-14 13:26:52 -0800 | [diff] [blame] | 26 | const int txfm_size_ls[] = { 4, 8, 16, 32, 64 }; |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 27 | |
Debargha Mukherjee | aa84f3e | 2018-01-04 12:45:10 -0800 | [diff] [blame] | 28 | const TxfmFunc fwd_txfm_func_ls[][txfm_type_num] = { |
Yaowu Xu | eb5e4e2 | 2020-04-06 14:17:55 -0700 | [diff] [blame] | 29 | { av1_fdct4, av1_fadst4 }, { av1_fdct8, av1_fadst8 }, |
James Zern | 664f04d | 2022-05-24 17:30:58 -0700 | [diff] [blame] | 30 | { av1_fdct16, av1_fadst16 }, { av1_fdct32, nullptr }, |
| 31 | { av1_fdct64, nullptr }, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 32 | }; |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 33 | |
Debargha Mukherjee | aa84f3e | 2018-01-04 12:45:10 -0800 | [diff] [blame] | 34 | const TxfmFunc inv_txfm_func_ls[][txfm_type_num] = { |
Yaowu Xu | eb5e4e2 | 2020-04-06 14:17:55 -0700 | [diff] [blame] | 35 | { av1_idct4, av1_iadst4 }, { av1_idct8, av1_iadst8 }, |
James Zern | 664f04d | 2022-05-24 17:30:58 -0700 | [diff] [blame] | 36 | { av1_idct16, av1_iadst16 }, { av1_idct32, nullptr }, |
| 37 | { av1_idct64, nullptr }, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 38 | }; |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 39 | |
| 40 | // the maximum stage number of fwd/inv 1d dct/adst txfm is 12 |
Angie Chiang | d4327bc | 2018-01-22 20:54:04 -0800 | [diff] [blame] | 41 | const int8_t cos_bit = 13; |
Angie Chiang | a87dc76 | 2018-02-06 17:16:48 -0800 | [diff] [blame] | 42 | const int8_t range_bit[12] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 }; |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 43 | |
Sebastien Alaiwan | d02642f | 2017-07-10 11:41:44 +0200 | [diff] [blame] | 44 | void reference_idct_1d_int(const int32_t *in, int32_t *out, int size) { |
| 45 | double input[64]; |
| 46 | for (int i = 0; i < size; ++i) input[i] = in[i]; |
| 47 | |
| 48 | double output[64]; |
| 49 | libaom_test::reference_idct_1d(input, output, size); |
| 50 | |
Urvang Joshi | ab2b36e | 2017-10-03 11:01:06 -0700 | [diff] [blame] | 51 | for (int i = 0; i < size; ++i) { |
| 52 | ASSERT_GE(output[i], INT32_MIN); |
| 53 | ASSERT_LE(output[i], INT32_MAX); |
Sebastien Alaiwan | d02642f | 2017-07-10 11:41:44 +0200 | [diff] [blame] | 54 | out[i] = static_cast<int32_t>(round(output[i])); |
Urvang Joshi | ab2b36e | 2017-10-03 11:01:06 -0700 | [diff] [blame] | 55 | } |
Sebastien Alaiwan | d02642f | 2017-07-10 11:41:44 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void random_matrix(int32_t *dst, int len, ACMRandom *rnd) { |
| 59 | const int bits = 16; |
| 60 | const int maxVal = (1 << (bits - 1)) - 1; |
| 61 | const int minVal = -(1 << (bits - 1)); |
| 62 | for (int i = 0; i < len; ++i) { |
| 63 | if (rnd->Rand8() % 10) |
| 64 | dst[i] = minVal + rnd->Rand16() % (1 << bits); |
| 65 | else |
| 66 | dst[i] = rnd->Rand8() % 2 ? minVal : maxVal; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | TEST(av1_inv_txfm1d, InvAccuracyCheck) { |
| 71 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 72 | const int count_test_block = 20000; |
Yaowu Xu | d3d4159 | 2018-02-14 13:26:52 -0800 | [diff] [blame] | 73 | const int max_error[] = { 6, 10, 19, 31, 40 }; |
Urvang Joshi | ab2b36e | 2017-10-03 11:01:06 -0700 | [diff] [blame] | 74 | ASSERT_EQ(NELEMENTS(max_error), TX_SIZES); |
| 75 | ASSERT_EQ(NELEMENTS(inv_txfm_func_ls), TX_SIZES); |
Sebastien Alaiwan | d02642f | 2017-07-10 11:41:44 +0200 | [diff] [blame] | 76 | for (int k = 0; k < count_test_block; ++k) { |
| 77 | // choose a random transform to test |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 78 | const TxSize tx_size = static_cast<TxSize>(rnd.Rand8() % TX_SIZES); |
Urvang Joshi | ab2b36e | 2017-10-03 11:01:06 -0700 | [diff] [blame] | 79 | const int tx_size_pix = txfm_size_ls[tx_size]; |
| 80 | const TxfmFunc inv_txfm_func = inv_txfm_func_ls[tx_size][0]; |
Sebastien Alaiwan | d02642f | 2017-07-10 11:41:44 +0200 | [diff] [blame] | 81 | |
| 82 | int32_t input[64]; |
Urvang Joshi | ab2b36e | 2017-10-03 11:01:06 -0700 | [diff] [blame] | 83 | random_matrix(input, tx_size_pix, &rnd); |
| 84 | |
Urvang Joshi | ab2b36e | 2017-10-03 11:01:06 -0700 | [diff] [blame] | 85 | // 64x64 transform assumes last 32 values are zero. |
| 86 | memset(input + 32, 0, 32 * sizeof(input[0])); |
Sebastien Alaiwan | d02642f | 2017-07-10 11:41:44 +0200 | [diff] [blame] | 87 | |
| 88 | int32_t ref_output[64]; |
kyslov | 6fdf934 | 2019-04-09 14:53:43 -0700 | [diff] [blame] | 89 | memset(ref_output, 0, sizeof(ref_output)); |
Urvang Joshi | ab2b36e | 2017-10-03 11:01:06 -0700 | [diff] [blame] | 90 | reference_idct_1d_int(input, ref_output, tx_size_pix); |
Sebastien Alaiwan | d02642f | 2017-07-10 11:41:44 +0200 | [diff] [blame] | 91 | |
| 92 | int32_t output[64]; |
kyslov | 6fdf934 | 2019-04-09 14:53:43 -0700 | [diff] [blame] | 93 | memset(output, 0, sizeof(output)); |
Urvang Joshi | ab2b36e | 2017-10-03 11:01:06 -0700 | [diff] [blame] | 94 | inv_txfm_func(input, output, cos_bit, range_bit); |
Sebastien Alaiwan | d02642f | 2017-07-10 11:41:44 +0200 | [diff] [blame] | 95 | |
Urvang Joshi | ab2b36e | 2017-10-03 11:01:06 -0700 | [diff] [blame] | 96 | 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 Alaiwan | d02642f | 2017-07-10 11:41:44 +0200 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
Sebastien Alaiwan | 3696737 | 2017-09-27 17:02:20 +0200 | [diff] [blame] | 105 | static 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 | |
| 114 | TEST(av1_inv_txfm1d, get_max_bit) { |
| 115 | int max_bit = get_max_bit(8); |
| 116 | EXPECT_EQ(max_bit, 3); |
| 117 | } |
| 118 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 119 | TEST(av1_inv_txfm1d, round_trip) { |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 120 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
Sebastien Alaiwan | ed9e0d0 | 2017-07-13 10:44:58 +0200 | [diff] [blame] | 121 | for (int si = 0; si < NELEMENTS(fwd_txfm_func_ls); ++si) { |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 122 | int txfm_size = txfm_size_ls[si]; |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 123 | |
| 124 | for (int ti = 0; ti < txfm_type_num; ++ti) { |
Sebastien Alaiwan | 13f77be | 2017-03-08 15:25:10 +0100 | [diff] [blame] | 125 | TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[si][ti]; |
| 126 | TxfmFunc inv_txfm_func = inv_txfm_func_ls[si][ti]; |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 127 | int max_error = 2; |
| 128 | |
Sebastien Alaiwan | 7889e5f | 2017-03-08 15:26:27 +0100 | [diff] [blame] | 129 | if (!fwd_txfm_func) continue; |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 130 | |
Sebastien Alaiwan | 7889e5f | 2017-03-08 15:26:27 +0100 | [diff] [blame] | 131 | const int count_test_block = 5000; |
| 132 | for (int ci = 0; ci < count_test_block; ++ci) { |
Sebastien Alaiwan | 1f40e22 | 2017-03-08 15:27:20 +0100 | [diff] [blame] | 133 | int32_t input[64]; |
| 134 | int32_t output[64]; |
| 135 | int32_t round_trip_output[64]; |
| 136 | |
Sebastien Alaiwan | 8b730a5 | 2017-07-14 08:12:54 +0200 | [diff] [blame] | 137 | ASSERT_LE(txfm_size, NELEMENTS(input)); |
Sebastien Alaiwan | 1f40e22 | 2017-03-08 15:27:20 +0100 | [diff] [blame] | 138 | |
Sebastien Alaiwan | 7889e5f | 2017-03-08 15:26:27 +0100 | [diff] [blame] | 139 | for (int ni = 0; ni < txfm_size; ++ni) { |
| 140 | input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base; |
| 141 | } |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 142 | |
Sebastien Alaiwan | 7889e5f | 2017-03-08 15:26:27 +0100 | [diff] [blame] | 143 | 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 Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | } |
Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
| 157 | } // namespace |