2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
12 #include "av1/encoder/av1_fwd_txfm1d.h"
13 #include "test/av1_txfm_test.h"
15 using libaom_test::ACMRandom
;
16 using libaom_test::TYPE_ADST
;
17 using libaom_test::TYPE_DCT
;
18 using libaom_test::TYPE_IDTX
;
19 using libaom_test::TYPE_TXFM
;
20 using libaom_test::input_base
;
21 using libaom_test::reference_hybrid_1d
;
24 const int txfm_type_num
= 3;
25 const TYPE_TXFM txfm_type_ls
[txfm_type_num
] = { TYPE_DCT
, TYPE_ADST
,
28 const int txfm_size_num
= 5;
30 const int txfm_size_ls
[] = { 4, 8, 16, 32, 64 };
32 const TxfmFunc fwd_txfm_func_ls
[][txfm_type_num
] = {
33 { av1_fdct4_new
, av1_fadst4_new
, av1_fidentity4_c
},
34 { av1_fdct8_new
, av1_fadst8_new
, av1_fidentity8_c
},
35 { av1_fdct16_new
, av1_fadst16_new
, av1_fidentity16_c
},
36 { av1_fdct32_new
, av1_fadst32_new
, av1_fidentity32_c
},
37 { av1_fdct64_new
, NULL
, NULL
},
40 // the maximum stage number of fwd/inv 1d dct/adst txfm is 12
41 const int8_t cos_bit
= 14;
42 const int8_t range_bit
[12] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 };
44 TEST(av1_fwd_txfm1d
, round_shift
) {
45 EXPECT_EQ(round_shift(7, 1), 4);
46 EXPECT_EQ(round_shift(-7, 1), -3);
48 EXPECT_EQ(round_shift(7, 2), 2);
49 EXPECT_EQ(round_shift(-7, 2), -2);
51 EXPECT_EQ(round_shift(8, 2), 2);
52 EXPECT_EQ(round_shift(-8, 2), -2);
55 TEST(av1_fwd_txfm1d
, av1_cospi_arr_data
) {
56 for (int i
= 0; i
< 7; i
++) {
57 for (int j
= 0; j
< 64; j
++) {
58 EXPECT_EQ(av1_cospi_arr_data
[i
][j
],
59 (int32_t)round(cos(M_PI
* j
/ 128) * (1 << (cos_bit_min
+ i
))));
64 TEST(av1_fwd_txfm1d
, accuracy
) {
65 ACMRandom
rnd(ACMRandom::DeterministicSeed());
66 for (int si
= 0; si
< txfm_size_num
; ++si
) {
67 int txfm_size
= txfm_size_ls
[si
];
68 int32_t *input
= new int32_t[txfm_size
];
69 int32_t *output
= new int32_t[txfm_size
];
70 double *ref_input
= new double[txfm_size
];
71 double *ref_output
= new double[txfm_size
];
73 for (int ti
= 0; ti
< txfm_type_num
; ++ti
) {
74 TYPE_TXFM txfm_type
= txfm_type_ls
[ti
];
75 TxfmFunc fwd_txfm_func
= fwd_txfm_func_ls
[si
][ti
];
78 const int count_test_block
= 5000;
79 if (fwd_txfm_func
!= NULL
) {
80 for (int ti
= 0; ti
< count_test_block
; ++ti
) {
81 for (int ni
= 0; ni
< txfm_size
; ++ni
) {
82 input
[ni
] = rnd
.Rand16() % input_base
- rnd
.Rand16() % input_base
;
83 ref_input
[ni
] = static_cast<double>(input
[ni
]);
86 fwd_txfm_func(input
, output
, cos_bit
, range_bit
);
87 reference_hybrid_1d(ref_input
, ref_output
, txfm_size
, txfm_type
);
89 for (int ni
= 0; ni
< txfm_size
; ++ni
) {
91 abs(output
[ni
] - static_cast<int32_t>(round(ref_output
[ni
]))),
93 << "tx size = " << txfm_size
<< ", tx type = " << txfm_type
;