Angie Chiang | b934148 | 2015-10-27 16:41:38 -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 | b934148 | 2015-10-27 16:41:38 -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 | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
James Zern | 1633b59 | 2021-11-22 15:48:34 -0800 | [diff] [blame] | 12 | #include <memory> |
| 13 | #include <new> |
| 14 | |
Urvang Joshi | 2314566 | 2017-12-13 12:25:46 -0800 | [diff] [blame] | 15 | #include "av1/encoder/av1_fwd_txfm1d.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "test/av1_txfm_test.h" |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 17 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | using libaom_test::ACMRandom; |
Johann | 54fa62e | 2018-09-25 14:09:31 -0700 | [diff] [blame] | 19 | using libaom_test::input_base; |
| 20 | using libaom_test::reference_hybrid_1d; |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 21 | using libaom_test::TYPE_ADST; |
| 22 | using libaom_test::TYPE_DCT; |
| 23 | using libaom_test::TYPE_IDTX; |
| 24 | using libaom_test::TYPE_TXFM; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 25 | |
| 26 | namespace { |
Debargha Mukherjee | aa84f3e | 2018-01-04 12:45:10 -0800 | [diff] [blame] | 27 | const int txfm_type_num = 3; |
| 28 | const TYPE_TXFM txfm_type_ls[txfm_type_num] = { TYPE_DCT, TYPE_ADST, |
| 29 | TYPE_IDTX }; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 30 | |
Angie Chiang | 29a06a1 | 2016-03-29 14:27:50 -0700 | [diff] [blame] | 31 | const int txfm_size_num = 5; |
Urvang Joshi | 22fba1f | 2017-12-22 15:51:36 -0800 | [diff] [blame] | 32 | |
Yaowu Xu | d3d4159 | 2018-02-14 13:26:52 -0800 | [diff] [blame] | 33 | const int txfm_size_ls[] = { 4, 8, 16, 32, 64 }; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 34 | |
Debargha Mukherjee | aa84f3e | 2018-01-04 12:45:10 -0800 | [diff] [blame] | 35 | const TxfmFunc fwd_txfm_func_ls[][txfm_type_num] = { |
Yaowu Xu | eb5e4e2 | 2020-04-06 14:17:55 -0700 | [diff] [blame] | 36 | { av1_fdct4, av1_fadst4, av1_fidentity4_c }, |
| 37 | { av1_fdct8, av1_fadst8, av1_fidentity8_c }, |
| 38 | { av1_fdct16, av1_fadst16, av1_fidentity16_c }, |
James Zern | 664f04d | 2022-05-24 17:30:58 -0700 | [diff] [blame^] | 39 | { av1_fdct32, nullptr, av1_fidentity32_c }, |
| 40 | { av1_fdct64, nullptr, nullptr }, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 41 | }; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 42 | |
| 43 | // 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] | 44 | const int8_t cos_bit = 14; |
Angie Chiang | a87dc76 | 2018-02-06 17:16:48 -0800 | [diff] [blame] | 45 | const int8_t range_bit[12] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 }; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 46 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 47 | TEST(av1_fwd_txfm1d, round_shift) { |
Angie Chiang | f2b311f | 2016-03-23 10:59:32 -0700 | [diff] [blame] | 48 | EXPECT_EQ(round_shift(7, 1), 4); |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 49 | EXPECT_EQ(round_shift(-7, 1), -3); |
| 50 | |
| 51 | EXPECT_EQ(round_shift(7, 2), 2); |
| 52 | EXPECT_EQ(round_shift(-7, 2), -2); |
| 53 | |
| 54 | EXPECT_EQ(round_shift(8, 2), 2); |
| 55 | EXPECT_EQ(round_shift(-8, 2), -2); |
| 56 | } |
| 57 | |
Yue Chen | 5b53ea1 | 2018-03-09 11:26:43 -0800 | [diff] [blame] | 58 | TEST(av1_fwd_txfm1d, av1_cospi_arr_data) { |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 59 | for (int i = 0; i < 7; i++) { |
| 60 | for (int j = 0; j < 64; j++) { |
Yue Chen | 5b53ea1 | 2018-03-09 11:26:43 -0800 | [diff] [blame] | 61 | EXPECT_EQ(av1_cospi_arr_data[i][j], |
David Turner | f2ea6e1 | 2018-10-19 11:04:25 +0100 | [diff] [blame] | 62 | (int32_t)round(cos(PI * j / 128) * (1 << (cos_bit_min + i)))); |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 67 | TEST(av1_fwd_txfm1d, accuracy) { |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 68 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 69 | for (int si = 0; si < txfm_size_num; ++si) { |
| 70 | int txfm_size = txfm_size_ls[si]; |
James Zern | 1633b59 | 2021-11-22 15:48:34 -0800 | [diff] [blame] | 71 | std::unique_ptr<int32_t[]> input(new (std::nothrow) int32_t[txfm_size]); |
| 72 | std::unique_ptr<int32_t[]> output(new (std::nothrow) int32_t[txfm_size]); |
| 73 | std::unique_ptr<double[]> ref_input(new (std::nothrow) double[txfm_size]); |
| 74 | std::unique_ptr<double[]> ref_output(new (std::nothrow) double[txfm_size]); |
| 75 | ASSERT_NE(input, nullptr); |
| 76 | ASSERT_NE(output, nullptr); |
| 77 | ASSERT_NE(ref_input, nullptr); |
| 78 | ASSERT_NE(ref_output, nullptr); |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 79 | |
| 80 | for (int ti = 0; ti < txfm_type_num; ++ti) { |
| 81 | TYPE_TXFM txfm_type = txfm_type_ls[ti]; |
Sebastien Alaiwan | f263044 | 2017-12-19 12:39:41 +0100 | [diff] [blame] | 82 | TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[si][ti]; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 83 | int max_error = 7; |
| 84 | |
| 85 | const int count_test_block = 5000; |
James Zern | 664f04d | 2022-05-24 17:30:58 -0700 | [diff] [blame^] | 86 | if (fwd_txfm_func != nullptr) { |
Angie Chiang | ed2514a | 2016-03-14 12:02:27 -0700 | [diff] [blame] | 87 | for (int ti = 0; ti < count_test_block; ++ti) { |
| 88 | for (int ni = 0; ni < txfm_size; ++ni) { |
Angie Chiang | 218dfbd | 2016-04-19 11:59:00 -0700 | [diff] [blame] | 89 | input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base; |
Angie Chiang | ed2514a | 2016-03-14 12:02:27 -0700 | [diff] [blame] | 90 | ref_input[ni] = static_cast<double>(input[ni]); |
| 91 | } |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 92 | |
James Zern | 1633b59 | 2021-11-22 15:48:34 -0800 | [diff] [blame] | 93 | fwd_txfm_func(input.get(), output.get(), cos_bit, range_bit); |
| 94 | reference_hybrid_1d(ref_input.get(), ref_output.get(), txfm_size, |
| 95 | txfm_type); |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 96 | |
Angie Chiang | ed2514a | 2016-03-14 12:02:27 -0700 | [diff] [blame] | 97 | for (int ni = 0; ni < txfm_size; ++ni) { |
Sarah Parker | 95f5260 | 2017-10-04 12:45:14 -0700 | [diff] [blame] | 98 | ASSERT_LE( |
Angie Chiang | ed2514a | 2016-03-14 12:02:27 -0700 | [diff] [blame] | 99 | abs(output[ni] - static_cast<int32_t>(round(ref_output[ni]))), |
Sarah Parker | 95f5260 | 2017-10-04 12:45:14 -0700 | [diff] [blame] | 100 | max_error) |
| 101 | << "tx size = " << txfm_size << ", tx type = " << txfm_type; |
Angie Chiang | ed2514a | 2016-03-14 12:02:27 -0700 | [diff] [blame] | 102 | } |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | } |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | } // namespace |