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.
14 #include "test/av1_txfm_test.h"
15 #include "test/util.h"
16 #include "av1/common/av1_inv_txfm1d.h"
17 #include "av1/encoder/av1_fwd_txfm1d.h"
19 using libaom_test::ACMRandom
;
20 using libaom_test::input_base
;
23 const int txfm_type_num
= 2;
24 const int txfm_size_ls
[] = { 4, 8, 16, 32, 64 };
26 const TxfmFunc fwd_txfm_func_ls
[][txfm_type_num
] = {
27 { av1_fdct4_new
, av1_fadst4_new
},
28 { av1_fdct8_new
, av1_fadst8_new
},
29 { av1_fdct16_new
, av1_fadst16_new
},
30 { av1_fdct32_new
, NULL
},
31 { av1_fdct64_new
, NULL
},
34 const TxfmFunc inv_txfm_func_ls
[][txfm_type_num
] = {
35 { av1_idct4_new
, av1_iadst4_new
},
36 { av1_idct8_new
, av1_iadst8_new
},
37 { av1_idct16_new
, av1_iadst16_new
},
38 { av1_idct32_new
, NULL
},
39 { av1_idct64_new
, NULL
},
42 // the maximum stage number of fwd/inv 1d dct/adst txfm is 12
43 const int8_t cos_bit
= 13;
44 const int8_t range_bit
[12] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 };
46 void reference_idct_1d_int(const int32_t *in
, int32_t *out
, int size
) {
48 for (int i
= 0; i
< size
; ++i
) input
[i
] = in
[i
];
51 libaom_test::reference_idct_1d(input
, output
, size
);
53 for (int i
= 0; i
< size
; ++i
) {
54 ASSERT_GE(output
[i
], INT32_MIN
);
55 ASSERT_LE(output
[i
], INT32_MAX
);
56 out
[i
] = static_cast<int32_t>(round(output
[i
]));
60 void random_matrix(int32_t *dst
, int len
, ACMRandom
*rnd
) {
62 const int maxVal
= (1 << (bits
- 1)) - 1;
63 const int minVal
= -(1 << (bits
- 1));
64 for (int i
= 0; i
< len
; ++i
) {
65 if (rnd
->Rand8() % 10)
66 dst
[i
] = minVal
+ rnd
->Rand16() % (1 << bits
);
68 dst
[i
] = rnd
->Rand8() % 2 ? minVal
: maxVal
;
72 TEST(av1_inv_txfm1d
, InvAccuracyCheck
) {
73 ACMRandom
rnd(ACMRandom::DeterministicSeed());
74 const int count_test_block
= 20000;
75 const int max_error
[] = { 6, 10, 19, 31, 40 };
76 ASSERT_EQ(NELEMENTS(max_error
), TX_SIZES
);
77 ASSERT_EQ(NELEMENTS(inv_txfm_func_ls
), TX_SIZES
);
78 for (int k
= 0; k
< count_test_block
; ++k
) {
79 // choose a random transform to test
80 const TX_SIZE tx_size
= static_cast<TX_SIZE
>(rnd
.Rand8() % TX_SIZES
);
81 const int tx_size_pix
= txfm_size_ls
[tx_size
];
82 const TxfmFunc inv_txfm_func
= inv_txfm_func_ls
[tx_size
][0];
85 random_matrix(input
, tx_size_pix
, &rnd
);
87 // 64x64 transform assumes last 32 values are zero.
88 memset(input
+ 32, 0, 32 * sizeof(input
[0]));
90 int32_t ref_output
[64];
91 reference_idct_1d_int(input
, ref_output
, tx_size_pix
);
94 inv_txfm_func(input
, output
, cos_bit
, range_bit
);
96 for (int i
= 0; i
< tx_size_pix
; ++i
) {
97 EXPECT_LE(abs(output
[i
] - ref_output
[i
]), max_error
[tx_size
])
98 << "tx_size = " << tx_size
<< ", i = " << i
99 << ", output[i] = " << output
[i
]
100 << ", ref_output[i] = " << ref_output
[i
];
105 static INLINE
int get_max_bit(int x
) {
114 TEST(av1_inv_txfm1d
, get_max_bit
) {
115 int max_bit
= get_max_bit(8);
116 EXPECT_EQ(max_bit
, 3);
119 TEST(av1_inv_txfm1d
, round_trip
) {
120 ACMRandom
rnd(ACMRandom::DeterministicSeed());
121 for (int si
= 0; si
< NELEMENTS(fwd_txfm_func_ls
); ++si
) {
122 int txfm_size
= txfm_size_ls
[si
];
124 for (int ti
= 0; ti
< txfm_type_num
; ++ti
) {
125 TxfmFunc fwd_txfm_func
= fwd_txfm_func_ls
[si
][ti
];
126 TxfmFunc inv_txfm_func
= inv_txfm_func_ls
[si
][ti
];
129 if (!fwd_txfm_func
) continue;
131 const int count_test_block
= 5000;
132 for (int ci
= 0; ci
< count_test_block
; ++ci
) {
135 int32_t round_trip_output
[64];
137 ASSERT_LE(txfm_size
, NELEMENTS(input
));
139 for (int ni
= 0; ni
< txfm_size
; ++ni
) {
140 input
[ni
] = rnd
.Rand16() % input_base
- rnd
.Rand16() % input_base
;
143 fwd_txfm_func(input
, output
, cos_bit
, range_bit
);
144 inv_txfm_func(output
, round_trip_output
, cos_bit
, range_bit
);
146 for (int ni
= 0; ni
< txfm_size
; ++ni
) {
148 abs(input
[ni
] - round_shift(round_trip_output
[ni
],
149 get_max_bit(txfm_size
) - 1));
150 EXPECT_LE(node_err
, max_error
);