blob: df504ea4d525cc904513eed4a7c18a742ec961c6 [file] [log] [blame]
Angie Chiangb9341482015-10-27 16:41:38 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Angie Chiangb9341482015-10-27 16:41:38 -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 Chiangb9341482015-10-27 16:41:38 -070010 */
11
James Zern1633b592021-11-22 15:48:34 -080012#include <memory>
13#include <new>
14
Urvang Joshi23145662017-12-13 12:25:46 -080015#include "av1/encoder/av1_fwd_txfm1d.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "test/av1_txfm_test.h"
Angie Chiangb9341482015-10-27 16:41:38 -070017
Yaowu Xuc27fc142016-08-22 16:08:15 -070018using libaom_test::ACMRandom;
Johann54fa62e2018-09-25 14:09:31 -070019using libaom_test::input_base;
20using libaom_test::reference_hybrid_1d;
Johann123e8a62017-12-28 14:40:49 -080021using libaom_test::TYPE_ADST;
22using libaom_test::TYPE_DCT;
23using libaom_test::TYPE_IDTX;
24using libaom_test::TYPE_TXFM;
Angie Chiangb9341482015-10-27 16:41:38 -070025
26namespace {
Debargha Mukherjeeaa84f3e2018-01-04 12:45:10 -080027const int txfm_type_num = 3;
28const TYPE_TXFM txfm_type_ls[txfm_type_num] = { TYPE_DCT, TYPE_ADST,
29 TYPE_IDTX };
Angie Chiangb9341482015-10-27 16:41:38 -070030
Angie Chiang29a06a12016-03-29 14:27:50 -070031const int txfm_size_num = 5;
Urvang Joshi22fba1f2017-12-22 15:51:36 -080032
Yaowu Xud3d41592018-02-14 13:26:52 -080033const int txfm_size_ls[] = { 4, 8, 16, 32, 64 };
Angie Chiangb9341482015-10-27 16:41:38 -070034
Debargha Mukherjeeaa84f3e2018-01-04 12:45:10 -080035const TxfmFunc fwd_txfm_func_ls[][txfm_type_num] = {
Yaowu Xueb5e4e22020-04-06 14:17:55 -070036 { av1_fdct4, av1_fadst4, av1_fidentity4_c },
37 { av1_fdct8, av1_fadst8, av1_fidentity8_c },
38 { av1_fdct16, av1_fadst16, av1_fidentity16_c },
James Zern664f04d2022-05-24 17:30:58 -070039 { av1_fdct32, nullptr, av1_fidentity32_c },
40 { av1_fdct64, nullptr, nullptr },
clang-format3a826f12016-08-11 17:46:05 -070041};
Angie Chiangb9341482015-10-27 16:41:38 -070042
43// the maximum stage number of fwd/inv 1d dct/adst txfm is 12
Angie Chiangd4327bc2018-01-22 20:54:04 -080044const int8_t cos_bit = 14;
Angie Chianga87dc762018-02-06 17:16:48 -080045const int8_t range_bit[12] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 };
Angie Chiangb9341482015-10-27 16:41:38 -070046
Yaowu Xuf883b422016-08-30 14:01:10 -070047TEST(av1_fwd_txfm1d, round_shift) {
Angie Chiangf2b311f2016-03-23 10:59:32 -070048 EXPECT_EQ(round_shift(7, 1), 4);
Angie Chiangb9341482015-10-27 16:41:38 -070049 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 Chen5b53ea12018-03-09 11:26:43 -080058TEST(av1_fwd_txfm1d, av1_cospi_arr_data) {
Angie Chiangb9341482015-10-27 16:41:38 -070059 for (int i = 0; i < 7; i++) {
60 for (int j = 0; j < 64; j++) {
Yue Chen5b53ea12018-03-09 11:26:43 -080061 EXPECT_EQ(av1_cospi_arr_data[i][j],
David Turnerf2ea6e12018-10-19 11:04:25 +010062 (int32_t)round(cos(PI * j / 128) * (1 << (cos_bit_min + i))));
Angie Chiangb9341482015-10-27 16:41:38 -070063 }
64 }
65}
66
Yaowu Xuf883b422016-08-30 14:01:10 -070067TEST(av1_fwd_txfm1d, accuracy) {
Angie Chiangb9341482015-10-27 16:41:38 -070068 ACMRandom rnd(ACMRandom::DeterministicSeed());
69 for (int si = 0; si < txfm_size_num; ++si) {
70 int txfm_size = txfm_size_ls[si];
James Zern1633b592021-11-22 15:48:34 -080071 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 Chiangb9341482015-10-27 16:41:38 -070079
80 for (int ti = 0; ti < txfm_type_num; ++ti) {
81 TYPE_TXFM txfm_type = txfm_type_ls[ti];
Sebastien Alaiwanf2630442017-12-19 12:39:41 +010082 TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[si][ti];
Angie Chiangb9341482015-10-27 16:41:38 -070083 int max_error = 7;
84
85 const int count_test_block = 5000;
James Zern664f04d2022-05-24 17:30:58 -070086 if (fwd_txfm_func != nullptr) {
Angie Chianged2514a2016-03-14 12:02:27 -070087 for (int ti = 0; ti < count_test_block; ++ti) {
88 for (int ni = 0; ni < txfm_size; ++ni) {
Angie Chiang218dfbd2016-04-19 11:59:00 -070089 input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base;
Angie Chianged2514a2016-03-14 12:02:27 -070090 ref_input[ni] = static_cast<double>(input[ni]);
91 }
Angie Chiangb9341482015-10-27 16:41:38 -070092
James Zern1633b592021-11-22 15:48:34 -080093 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 Chiangb9341482015-10-27 16:41:38 -070096
Angie Chianged2514a2016-03-14 12:02:27 -070097 for (int ni = 0; ni < txfm_size; ++ni) {
Sarah Parker95f52602017-10-04 12:45:14 -070098 ASSERT_LE(
Angie Chianged2514a2016-03-14 12:02:27 -070099 abs(output[ni] - static_cast<int32_t>(round(ref_output[ni]))),
Sarah Parker95f52602017-10-04 12:45:14 -0700100 max_error)
101 << "tx size = " << txfm_size << ", tx type = " << txfm_type;
Angie Chianged2514a2016-03-14 12:02:27 -0700102 }
Angie Chiangb9341482015-10-27 16:41:38 -0700103 }
104 }
105 }
Angie Chiangb9341482015-10-27 16:41:38 -0700106 }
107}
108} // namespace