blob: a9b3f8e4064d0cfaa9e0404ab08544d8a1748b96 [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
Yaowu Xuf883b422016-08-30 14:01:10 -070012#include "av1/common/av1_fwd_txfm1d.h"
13#include "test/av1_txfm_test.h"
Angie Chiangb9341482015-10-27 16:41:38 -070014
Yaowu Xuc27fc142016-08-22 16:08:15 -070015using libaom_test::ACMRandom;
16using libaom_test::input_base;
17using libaom_test::reference_hybrid_1d;
18using libaom_test::TYPE_TXFM;
19using libaom_test::TYPE_DCT;
20using libaom_test::TYPE_ADST;
Angie Chiangb9341482015-10-27 16:41:38 -070021
22namespace {
Angie Chiang29a06a12016-03-29 14:27:50 -070023const int txfm_type_num = 2;
clang-format3a826f12016-08-11 17:46:05 -070024const TYPE_TXFM txfm_type_ls[2] = { TYPE_DCT, TYPE_ADST };
Angie Chiangb9341482015-10-27 16:41:38 -070025
Angie Chiang29a06a12016-03-29 14:27:50 -070026const int txfm_size_num = 5;
Angie Chiang792519b2016-10-18 12:24:20 -070027const int txfm_size_ls[5] = { 4, 8, 16, 32, 64 };
Angie Chiangb9341482015-10-27 16:41:38 -070028
Angie Chiang29a06a12016-03-29 14:27:50 -070029const TxfmFunc fwd_txfm_func_ls[2][5] = {
Angie Chiang792519b2016-10-18 12:24:20 -070030#if CONFIG_TX64X64
31 { av1_fdct4_new, av1_fdct8_new, av1_fdct16_new, av1_fdct32_new,
32 av1_fdct64_new },
33#else
Yaowu Xuf883b422016-08-30 14:01:10 -070034 { av1_fdct4_new, av1_fdct8_new, av1_fdct16_new, av1_fdct32_new, NULL },
Angie Chiang792519b2016-10-18 12:24:20 -070035#endif
Yaowu Xuf883b422016-08-30 14:01:10 -070036 { av1_fadst4_new, av1_fadst8_new, av1_fadst16_new, av1_fadst32_new, NULL }
clang-format3a826f12016-08-11 17:46:05 -070037};
Angie Chiangb9341482015-10-27 16:41:38 -070038
39// the maximum stage number of fwd/inv 1d dct/adst txfm is 12
clang-format3a826f12016-08-11 17:46:05 -070040const int8_t cos_bit[12] = { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 };
41const int8_t range_bit[12] = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
Angie Chiangb9341482015-10-27 16:41:38 -070042
Yaowu Xuf883b422016-08-30 14:01:10 -070043TEST(av1_fwd_txfm1d, round_shift) {
Angie Chiangf2b311f2016-03-23 10:59:32 -070044 EXPECT_EQ(round_shift(7, 1), 4);
Angie Chiangb9341482015-10-27 16:41:38 -070045 EXPECT_EQ(round_shift(-7, 1), -3);
46
47 EXPECT_EQ(round_shift(7, 2), 2);
48 EXPECT_EQ(round_shift(-7, 2), -2);
49
50 EXPECT_EQ(round_shift(8, 2), 2);
51 EXPECT_EQ(round_shift(-8, 2), -2);
52}
53
Yaowu Xuf883b422016-08-30 14:01:10 -070054TEST(av1_fwd_txfm1d, get_max_bit) {
Angie Chiangb9341482015-10-27 16:41:38 -070055 int max_bit = get_max_bit(8);
56 EXPECT_EQ(max_bit, 3);
57}
58
Yaowu Xuf883b422016-08-30 14:01:10 -070059TEST(av1_fwd_txfm1d, cospi_arr) {
Angie Chiangb9341482015-10-27 16:41:38 -070060 for (int i = 0; i < 7; i++) {
61 for (int j = 0; j < 64; j++) {
62 EXPECT_EQ(cospi_arr[i][j],
63 (int32_t)round(cos(M_PI * j / 128) * (1 << (cos_bit_min + i))));
64 }
65 }
66}
67
Yaowu Xuf883b422016-08-30 14:01:10 -070068TEST(av1_fwd_txfm1d, clamp_block) {
clang-format3a826f12016-08-11 17:46:05 -070069 int16_t block[5][5] = { { 7, -5, 6, -3, 9 },
70 { 7, -5, 6, -3, 9 },
71 { 7, -5, 6, -3, 9 },
72 { 7, -5, 6, -3, 9 },
73 { 7, -5, 6, -3, 9 } };
Angie Chiangb9341482015-10-27 16:41:38 -070074
clang-format3a826f12016-08-11 17:46:05 -070075 int16_t ref_block[5][5] = { { 7, -5, 6, -3, 9 },
76 { 7, -5, 6, -3, 9 },
77 { 7, -4, 2, -3, 9 },
78 { 7, -4, 2, -3, 9 },
79 { 7, -4, 2, -3, 9 } };
Angie Chiangb9341482015-10-27 16:41:38 -070080
81 int row = 2;
82 int col = 1;
83 int block_size = 3;
84 int stride = 5;
85 clamp_block(block[row] + col, block_size, stride, -4, 2);
86 for (int r = 0; r < stride; r++) {
87 for (int c = 0; c < stride; c++) {
88 EXPECT_EQ(block[r][c], ref_block[r][c]);
89 }
90 }
91}
92
Yaowu Xuf883b422016-08-30 14:01:10 -070093TEST(av1_fwd_txfm1d, accuracy) {
Angie Chiangb9341482015-10-27 16:41:38 -070094 ACMRandom rnd(ACMRandom::DeterministicSeed());
95 for (int si = 0; si < txfm_size_num; ++si) {
96 int txfm_size = txfm_size_ls[si];
97 int32_t *input = new int32_t[txfm_size];
98 int32_t *output = new int32_t[txfm_size];
99 double *ref_input = new double[txfm_size];
100 double *ref_output = new double[txfm_size];
101
102 for (int ti = 0; ti < txfm_type_num; ++ti) {
103 TYPE_TXFM txfm_type = txfm_type_ls[ti];
104 TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[ti][si];
105 int max_error = 7;
106
107 const int count_test_block = 5000;
Angie Chianged2514a2016-03-14 12:02:27 -0700108 if (fwd_txfm_func != NULL) {
109 for (int ti = 0; ti < count_test_block; ++ti) {
110 for (int ni = 0; ni < txfm_size; ++ni) {
Angie Chiang218dfbd2016-04-19 11:59:00 -0700111 input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base;
Angie Chianged2514a2016-03-14 12:02:27 -0700112 ref_input[ni] = static_cast<double>(input[ni]);
113 }
Angie Chiangb9341482015-10-27 16:41:38 -0700114
Angie Chianged2514a2016-03-14 12:02:27 -0700115 fwd_txfm_func(input, output, cos_bit, range_bit);
116 reference_hybrid_1d(ref_input, ref_output, txfm_size, txfm_type);
Angie Chiangb9341482015-10-27 16:41:38 -0700117
Angie Chianged2514a2016-03-14 12:02:27 -0700118 for (int ni = 0; ni < txfm_size; ++ni) {
119 EXPECT_LE(
120 abs(output[ni] - static_cast<int32_t>(round(ref_output[ni]))),
121 max_error);
122 }
Angie Chiangb9341482015-10-27 16:41:38 -0700123 }
124 }
125 }
126
127 delete[] input;
128 delete[] output;
129 delete[] ref_input;
130 delete[] ref_output;
131 }
132}
133} // namespace