Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 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. |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #include "av1/common/av1_fwd_txfm1d.h" |
| 13 | #include "test/av1_txfm_test.h" |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 14 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 15 | using libaom_test::ACMRandom; |
| 16 | using libaom_test::input_base; |
| 17 | using libaom_test::reference_hybrid_1d; |
| 18 | using libaom_test::TYPE_TXFM; |
| 19 | using libaom_test::TYPE_DCT; |
| 20 | using libaom_test::TYPE_ADST; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 21 | |
| 22 | namespace { |
Angie Chiang | 29a06a1 | 2016-03-29 14:27:50 -0700 | [diff] [blame] | 23 | const int txfm_type_num = 2; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 24 | const TYPE_TXFM txfm_type_ls[2] = { TYPE_DCT, TYPE_ADST }; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 25 | |
Angie Chiang | 29a06a1 | 2016-03-29 14:27:50 -0700 | [diff] [blame] | 26 | const int txfm_size_num = 5; |
Angie Chiang | 792519b | 2016-10-18 12:24:20 -0700 | [diff] [blame] | 27 | const int txfm_size_ls[5] = { 4, 8, 16, 32, 64 }; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 28 | |
Angie Chiang | 29a06a1 | 2016-03-29 14:27:50 -0700 | [diff] [blame] | 29 | const TxfmFunc fwd_txfm_func_ls[2][5] = { |
Angie Chiang | 792519b | 2016-10-18 12:24:20 -0700 | [diff] [blame] | 30 | #if CONFIG_TX64X64 |
| 31 | { av1_fdct4_new, av1_fdct8_new, av1_fdct16_new, av1_fdct32_new, |
| 32 | av1_fdct64_new }, |
| 33 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 34 | { av1_fdct4_new, av1_fdct8_new, av1_fdct16_new, av1_fdct32_new, NULL }, |
Angie Chiang | 792519b | 2016-10-18 12:24:20 -0700 | [diff] [blame] | 35 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 36 | { av1_fadst4_new, av1_fadst8_new, av1_fadst16_new, av1_fadst32_new, NULL } |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 37 | }; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 38 | |
| 39 | // the maximum stage number of fwd/inv 1d dct/adst txfm is 12 |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 40 | const int8_t cos_bit[12] = { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 }; |
| 41 | const int8_t range_bit[12] = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 }; |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 42 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 43 | TEST(av1_fwd_txfm1d, round_shift) { |
Angie Chiang | f2b311f | 2016-03-23 10:59:32 -0700 | [diff] [blame] | 44 | EXPECT_EQ(round_shift(7, 1), 4); |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 45 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 54 | TEST(av1_fwd_txfm1d, get_max_bit) { |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 55 | int max_bit = get_max_bit(8); |
| 56 | EXPECT_EQ(max_bit, 3); |
| 57 | } |
| 58 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 59 | TEST(av1_fwd_txfm1d, cospi_arr) { |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 60 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 68 | TEST(av1_fwd_txfm1d, clamp_block) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 69 | 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 Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 74 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 75 | 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 Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 80 | |
| 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 93 | TEST(av1_fwd_txfm1d, accuracy) { |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 94 | 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 Chiang | ed2514a | 2016-03-14 12:02:27 -0700 | [diff] [blame] | 108 | 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 Chiang | 218dfbd | 2016-04-19 11:59:00 -0700 | [diff] [blame] | 111 | input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base; |
Angie Chiang | ed2514a | 2016-03-14 12:02:27 -0700 | [diff] [blame] | 112 | ref_input[ni] = static_cast<double>(input[ni]); |
| 113 | } |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 114 | |
Angie Chiang | ed2514a | 2016-03-14 12:02:27 -0700 | [diff] [blame] | 115 | fwd_txfm_func(input, output, cos_bit, range_bit); |
| 116 | reference_hybrid_1d(ref_input, ref_output, txfm_size, txfm_type); |
Angie Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 117 | |
Angie Chiang | ed2514a | 2016-03-14 12:02:27 -0700 | [diff] [blame] | 118 | 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 Chiang | b934148 | 2015-10-27 16:41:38 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | delete[] input; |
| 128 | delete[] output; |
| 129 | delete[] ref_input; |
| 130 | delete[] ref_output; |
| 131 | } |
| 132 | } |
| 133 | } // namespace |