Bug 1882465 - Update .hg-annotate-ignore-revs and .git-blame-ignore-revs to reflect...
[gecko.git] / third_party / aom / test / av1_fwd_txfm1d_test.cc
blob6bae9f8364dd7769efe281f1f6ba6198f30d9d6d
1 /*
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 <memory>
13 #include <new>
15 #include "av1/encoder/av1_fwd_txfm1d.h"
16 #include "test/av1_txfm_test.h"
18 using libaom_test::ACMRandom;
19 using libaom_test::input_base;
20 using libaom_test::reference_hybrid_1d;
21 using libaom_test::TYPE_ADST;
22 using libaom_test::TYPE_DCT;
23 using libaom_test::TYPE_IDTX;
24 using libaom_test::TYPE_TXFM;
26 namespace {
27 const int txfm_type_num = 3;
28 const TYPE_TXFM txfm_type_ls[txfm_type_num] = { TYPE_DCT, TYPE_ADST,
29 TYPE_IDTX };
31 const int txfm_size_num = 5;
33 const int txfm_size_ls[] = { 4, 8, 16, 32, 64 };
35 const TxfmFunc fwd_txfm_func_ls[][txfm_type_num] = {
36 { av1_fdct4, av1_fadst4, av1_fidentity4_c },
37 { av1_fdct8, av1_fadst8, av1_fidentity8_c },
38 { av1_fdct16, av1_fadst16, av1_fidentity16_c },
39 { av1_fdct32, nullptr, av1_fidentity32_c },
40 { av1_fdct64, nullptr, nullptr },
43 // the maximum stage number of fwd/inv 1d dct/adst txfm is 12
44 const int8_t cos_bit = 13;
45 const int8_t range_bit[12] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 };
47 TEST(av1_fwd_txfm1d, round_shift) {
48 EXPECT_EQ(round_shift(7, 1), 4);
49 EXPECT_EQ(round_shift(-7, 1), -3);
51 EXPECT_EQ(round_shift(7, 2), 2);
52 EXPECT_EQ(round_shift(-7, 2), -2);
54 EXPECT_EQ(round_shift(8, 2), 2);
55 EXPECT_EQ(round_shift(-8, 2), -2);
58 TEST(av1_fwd_txfm1d, av1_cospi_arr_data) {
59 for (int i = 0; i < 4; i++) {
60 for (int j = 0; j < 64; j++) {
61 EXPECT_EQ(av1_cospi_arr_data[i][j],
62 (int32_t)round(cos(PI * j / 128) * (1 << (cos_bit_min + i))));
67 TEST(av1_fwd_txfm1d, accuracy) {
68 ACMRandom rnd(ACMRandom::DeterministicSeed());
69 for (int si = 0; si < txfm_size_num; ++si) {
70 int txfm_size = txfm_size_ls[si];
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);
80 for (int ti = 0; ti < txfm_type_num; ++ti) {
81 TYPE_TXFM txfm_type = txfm_type_ls[ti];
82 TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[si][ti];
83 int max_error = 7;
85 const int count_test_block = 5000;
86 if (fwd_txfm_func != nullptr) {
87 for (int i = 0; i < count_test_block; ++i) {
88 for (int ni = 0; ni < txfm_size; ++ni) {
89 input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base;
90 ref_input[ni] = static_cast<double>(input[ni]);
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);
97 for (int ni = 0; ni < txfm_size; ++ni) {
98 ASSERT_LE(
99 abs(output[ni] - static_cast<int32_t>(round(ref_output[ni]))),
100 max_error)
101 << "tx size = " << txfm_size << ", tx type = " << txfm_type;
108 } // namespace