Angie Chiang | 444acd7 | 2015-10-27 16:59:02 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2015 The WebM project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "test/vp10_txfm_test.h" |
| 12 | #include "vp10/common/vp10_fwd_txfm1d.h" |
| 13 | #include "vp10/common/vp10_inv_txfm1d.h" |
| 14 | |
| 15 | using libvpx_test::ACMRandom; |
| 16 | |
| 17 | namespace { |
| 18 | static int txfm_type_num = 2; |
| 19 | static int txfm_size_num = 4; |
| 20 | static int txfm_size_ls[4] = {4, 8, 16, 32}; |
| 21 | |
| 22 | static TxfmFunc fwd_txfm_func_ls[2][4] = { |
| 23 | {vp10_fdct4_new, vp10_fdct8_new, vp10_fdct16_new, vp10_fdct32_new}, |
| 24 | {vp10_fadst4_new, vp10_fadst8_new, vp10_fadst16_new, vp10_fadst32_new}}; |
| 25 | |
| 26 | static TxfmFunc inv_txfm_func_ls[2][4] = { |
| 27 | {vp10_idct4_new, vp10_idct8_new, vp10_idct16_new, vp10_idct32_new}, |
| 28 | {vp10_iadst4_new, vp10_iadst8_new, vp10_iadst16_new, vp10_iadst32_new}}; |
| 29 | |
| 30 | // the maximum stage number of fwd/inv 1d dct/adst txfm is 12 |
| 31 | static int8_t cos_bit[12] = {14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14}; |
| 32 | static int8_t range_bit[12] = {32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; |
| 33 | |
| 34 | TEST(vp10_inv_txfm1d, round_trip) { |
| 35 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 36 | for (int si = 0; si < txfm_size_num; ++si) { |
| 37 | int txfm_size = txfm_size_ls[si]; |
| 38 | int32_t *input = new int32_t[txfm_size]; |
| 39 | int32_t *output = new int32_t[txfm_size]; |
| 40 | int32_t *round_trip_output = new int32_t[txfm_size]; |
| 41 | |
| 42 | for (int ti = 0; ti < txfm_type_num; ++ti) { |
| 43 | TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[ti][si]; |
| 44 | TxfmFunc inv_txfm_func = inv_txfm_func_ls[ti][si]; |
| 45 | int max_error = 2; |
| 46 | |
| 47 | const int count_test_block = 5000; |
| 48 | for (int ci = 0; ci < count_test_block; ++ci) { |
| 49 | for (int ni = 0; ni < txfm_size; ++ni) { |
| 50 | input[ni] = rnd.Rand16() % base - rnd.Rand16() % base; |
| 51 | } |
| 52 | |
| 53 | fwd_txfm_func(input, output, cos_bit, range_bit); |
| 54 | inv_txfm_func(output, round_trip_output, cos_bit, range_bit); |
| 55 | |
| 56 | for (int ni = 0; ni < txfm_size; ++ni) { |
| 57 | EXPECT_LE(abs(input[ni] - round_shift(round_trip_output[ni], |
| 58 | get_max_bit(txfm_size) - 1)), |
| 59 | max_error); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | delete[] input; |
| 64 | delete[] output; |
| 65 | delete[] round_trip_output; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | } // namespace |