xref: /aosp_15_r20/external/libaom/test/av1_fwd_txfm1d_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #include <memory>
13*77c1e3ccSAndroid Build Coastguard Worker #include <new>
14*77c1e3ccSAndroid Build Coastguard Worker 
15*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/av1_fwd_txfm1d.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "test/av1_txfm_test.h"
17*77c1e3ccSAndroid Build Coastguard Worker 
18*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::ACMRandom;
19*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::input_base;
20*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::reference_hybrid_1d;
21*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::TYPE_ADST;
22*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::TYPE_DCT;
23*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::TYPE_IDTX;
24*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::TYPE_TXFM;
25*77c1e3ccSAndroid Build Coastguard Worker 
26*77c1e3ccSAndroid Build Coastguard Worker namespace {
27*77c1e3ccSAndroid Build Coastguard Worker const int txfm_type_num = 3;
28*77c1e3ccSAndroid Build Coastguard Worker const TYPE_TXFM txfm_type_ls[txfm_type_num] = { TYPE_DCT, TYPE_ADST,
29*77c1e3ccSAndroid Build Coastguard Worker                                                 TYPE_IDTX };
30*77c1e3ccSAndroid Build Coastguard Worker 
31*77c1e3ccSAndroid Build Coastguard Worker const int txfm_size_num = 5;
32*77c1e3ccSAndroid Build Coastguard Worker 
33*77c1e3ccSAndroid Build Coastguard Worker const int txfm_size_ls[] = { 4, 8, 16, 32, 64 };
34*77c1e3ccSAndroid Build Coastguard Worker 
35*77c1e3ccSAndroid Build Coastguard Worker const TxfmFunc fwd_txfm_func_ls[][txfm_type_num] = {
36*77c1e3ccSAndroid Build Coastguard Worker   { av1_fdct4, av1_fadst4, av1_fidentity4_c },
37*77c1e3ccSAndroid Build Coastguard Worker   { av1_fdct8, av1_fadst8, av1_fidentity8_c },
38*77c1e3ccSAndroid Build Coastguard Worker   { av1_fdct16, av1_fadst16, av1_fidentity16_c },
39*77c1e3ccSAndroid Build Coastguard Worker   { av1_fdct32, nullptr, av1_fidentity32_c },
40*77c1e3ccSAndroid Build Coastguard Worker   { av1_fdct64, nullptr, nullptr },
41*77c1e3ccSAndroid Build Coastguard Worker };
42*77c1e3ccSAndroid Build Coastguard Worker 
43*77c1e3ccSAndroid Build Coastguard Worker // the maximum stage number of fwd/inv 1d dct/adst txfm is 12
44*77c1e3ccSAndroid Build Coastguard Worker const int8_t cos_bit = 13;
45*77c1e3ccSAndroid Build Coastguard Worker const int8_t range_bit[12] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 };
46*77c1e3ccSAndroid Build Coastguard Worker 
TEST(av1_fwd_txfm1d,round_shift)47*77c1e3ccSAndroid Build Coastguard Worker TEST(av1_fwd_txfm1d, round_shift) {
48*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(round_shift(7, 1), 4);
49*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(round_shift(-7, 1), -3);
50*77c1e3ccSAndroid Build Coastguard Worker 
51*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(round_shift(7, 2), 2);
52*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(round_shift(-7, 2), -2);
53*77c1e3ccSAndroid Build Coastguard Worker 
54*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(round_shift(8, 2), 2);
55*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(round_shift(-8, 2), -2);
56*77c1e3ccSAndroid Build Coastguard Worker }
57*77c1e3ccSAndroid Build Coastguard Worker 
TEST(av1_fwd_txfm1d,av1_cospi_arr_data)58*77c1e3ccSAndroid Build Coastguard Worker TEST(av1_fwd_txfm1d, av1_cospi_arr_data) {
59*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < 4; i++) {
60*77c1e3ccSAndroid Build Coastguard Worker     for (int j = 0; j < 64; j++) {
61*77c1e3ccSAndroid Build Coastguard Worker       EXPECT_EQ(av1_cospi_arr_data[i][j],
62*77c1e3ccSAndroid Build Coastguard Worker                 (int32_t)round(cos(PI * j / 128) * (1 << (cos_bit_min + i))));
63*77c1e3ccSAndroid Build Coastguard Worker     }
64*77c1e3ccSAndroid Build Coastguard Worker   }
65*77c1e3ccSAndroid Build Coastguard Worker }
66*77c1e3ccSAndroid Build Coastguard Worker 
TEST(av1_fwd_txfm1d,accuracy)67*77c1e3ccSAndroid Build Coastguard Worker TEST(av1_fwd_txfm1d, accuracy) {
68*77c1e3ccSAndroid Build Coastguard Worker   ACMRandom rnd(ACMRandom::DeterministicSeed());
69*77c1e3ccSAndroid Build Coastguard Worker   for (int si = 0; si < txfm_size_num; ++si) {
70*77c1e3ccSAndroid Build Coastguard Worker     int txfm_size = txfm_size_ls[si];
71*77c1e3ccSAndroid Build Coastguard Worker     std::unique_ptr<int32_t[]> input(new (std::nothrow) int32_t[txfm_size]);
72*77c1e3ccSAndroid Build Coastguard Worker     std::unique_ptr<int32_t[]> output(new (std::nothrow) int32_t[txfm_size]);
73*77c1e3ccSAndroid Build Coastguard Worker     std::unique_ptr<double[]> ref_input(new (std::nothrow) double[txfm_size]);
74*77c1e3ccSAndroid Build Coastguard Worker     std::unique_ptr<double[]> ref_output(new (std::nothrow) double[txfm_size]);
75*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(input, nullptr);
76*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(output, nullptr);
77*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(ref_input, nullptr);
78*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(ref_output, nullptr);
79*77c1e3ccSAndroid Build Coastguard Worker 
80*77c1e3ccSAndroid Build Coastguard Worker     for (int ti = 0; ti < txfm_type_num; ++ti) {
81*77c1e3ccSAndroid Build Coastguard Worker       TYPE_TXFM txfm_type = txfm_type_ls[ti];
82*77c1e3ccSAndroid Build Coastguard Worker       TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[si][ti];
83*77c1e3ccSAndroid Build Coastguard Worker       int max_error = 7;
84*77c1e3ccSAndroid Build Coastguard Worker 
85*77c1e3ccSAndroid Build Coastguard Worker       const int count_test_block = 5000;
86*77c1e3ccSAndroid Build Coastguard Worker       if (fwd_txfm_func != nullptr) {
87*77c1e3ccSAndroid Build Coastguard Worker         for (int i = 0; i < count_test_block; ++i) {
88*77c1e3ccSAndroid Build Coastguard Worker           for (int ni = 0; ni < txfm_size; ++ni) {
89*77c1e3ccSAndroid Build Coastguard Worker             input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base;
90*77c1e3ccSAndroid Build Coastguard Worker             ref_input[ni] = static_cast<double>(input[ni]);
91*77c1e3ccSAndroid Build Coastguard Worker           }
92*77c1e3ccSAndroid Build Coastguard Worker 
93*77c1e3ccSAndroid Build Coastguard Worker           fwd_txfm_func(input.get(), output.get(), cos_bit, range_bit);
94*77c1e3ccSAndroid Build Coastguard Worker           reference_hybrid_1d(ref_input.get(), ref_output.get(), txfm_size,
95*77c1e3ccSAndroid Build Coastguard Worker                               txfm_type);
96*77c1e3ccSAndroid Build Coastguard Worker 
97*77c1e3ccSAndroid Build Coastguard Worker           for (int ni = 0; ni < txfm_size; ++ni) {
98*77c1e3ccSAndroid Build Coastguard Worker             ASSERT_LE(
99*77c1e3ccSAndroid Build Coastguard Worker                 abs(output[ni] - static_cast<int32_t>(round(ref_output[ni]))),
100*77c1e3ccSAndroid Build Coastguard Worker                 max_error)
101*77c1e3ccSAndroid Build Coastguard Worker                 << "tx size = " << txfm_size << ", tx type = " << txfm_type;
102*77c1e3ccSAndroid Build Coastguard Worker           }
103*77c1e3ccSAndroid Build Coastguard Worker         }
104*77c1e3ccSAndroid Build Coastguard Worker       }
105*77c1e3ccSAndroid Build Coastguard Worker     }
106*77c1e3ccSAndroid Build Coastguard Worker   }
107*77c1e3ccSAndroid Build Coastguard Worker }
108*77c1e3ccSAndroid Build Coastguard Worker }  // namespace
109