av1_inv_txfm1d_test.cc 2.82 KB
Newer Older
Angie Chiang's avatar
Angie Chiang committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Angie Chiang's avatar
Angie Chiang committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Angie Chiang's avatar
Angie Chiang committed
10 11
 */

Yaowu Xu's avatar
Yaowu Xu committed
12 13 14
#include "test/av1_txfm_test.h"
#include "av1/common/av1_fwd_txfm1d.h"
#include "av1/common/av1_inv_txfm1d.h"
Angie Chiang's avatar
Angie Chiang committed
15

16 17
using libaom_test::ACMRandom;
using libaom_test::input_base;
Angie Chiang's avatar
Angie Chiang committed
18 19

namespace {
20 21
const int txfm_type_num = 2;
const int txfm_size_num = 5;
22
const int txfm_size_ls[5] = { 4, 8, 16, 32, 64 };
Angie Chiang's avatar
Angie Chiang committed
23

24
const TxfmFunc fwd_txfm_func_ls[2][5] = {
25 26
  {
      av1_fdct4_new, av1_fdct8_new, av1_fdct16_new, av1_fdct32_new,
27
#if CONFIG_TX64X64
28
      av1_fdct64_new,
29
#else
30
      NULL,
31
#endif
32
  },
Yaowu Xu's avatar
Yaowu Xu committed
33
  { av1_fadst4_new, av1_fadst8_new, av1_fadst16_new, av1_fadst32_new, NULL }
clang-format's avatar
clang-format committed
34
};
Angie Chiang's avatar
Angie Chiang committed
35

36
const TxfmFunc inv_txfm_func_ls[2][5] = {
37 38
  {
      av1_idct4_new, av1_idct8_new, av1_idct16_new, av1_idct32_new,
39
#if CONFIG_TX64X64
40
      av1_idct64_new,
41
#else
42
      NULL,
43
#endif
44
  },
Yaowu Xu's avatar
Yaowu Xu committed
45
  { av1_iadst4_new, av1_iadst8_new, av1_iadst16_new, av1_iadst32_new, NULL }
clang-format's avatar
clang-format committed
46
};
Angie Chiang's avatar
Angie Chiang committed
47 48

// the maximum stage number of fwd/inv 1d dct/adst txfm is 12
clang-format's avatar
clang-format committed
49 50
const int8_t cos_bit[12] = { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 };
const int8_t range_bit[12] = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
Angie Chiang's avatar
Angie Chiang committed
51

Yaowu Xu's avatar
Yaowu Xu committed
52
TEST(av1_inv_txfm1d, round_trip) {
Angie Chiang's avatar
Angie Chiang committed
53 54 55 56 57 58 59 60 61 62 63 64
  ACMRandom rnd(ACMRandom::DeterministicSeed());
  for (int si = 0; si < txfm_size_num; ++si) {
    int txfm_size = txfm_size_ls[si];
    int32_t *input = new int32_t[txfm_size];
    int32_t *output = new int32_t[txfm_size];
    int32_t *round_trip_output = new int32_t[txfm_size];

    for (int ti = 0; ti < txfm_type_num; ++ti) {
      TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[ti][si];
      TxfmFunc inv_txfm_func = inv_txfm_func_ls[ti][si];
      int max_error = 2;

Angie Chiang's avatar
Angie Chiang committed
65 66 67 68
      if (fwd_txfm_func != NULL) {
        const int count_test_block = 5000;
        for (int ci = 0; ci < count_test_block; ++ci) {
          for (int ni = 0; ni < txfm_size; ++ni) {
69
            input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base;
Angie Chiang's avatar
Angie Chiang committed
70
          }
Angie Chiang's avatar
Angie Chiang committed
71

Angie Chiang's avatar
Angie Chiang committed
72 73
          fwd_txfm_func(input, output, cos_bit, range_bit);
          inv_txfm_func(output, round_trip_output, cos_bit, range_bit);
Angie Chiang's avatar
Angie Chiang committed
74

Angie Chiang's avatar
Angie Chiang committed
75 76 77 78 79 80
          for (int ni = 0; ni < txfm_size; ++ni) {
            int node_err =
                abs(input[ni] - round_shift(round_trip_output[ni],
                                            get_max_bit(txfm_size) - 1));
            EXPECT_LE(node_err, max_error);
          }
Angie Chiang's avatar
Angie Chiang committed
81 82 83 84 85 86 87 88 89 90
        }
      }
    }
    delete[] input;
    delete[] output;
    delete[] round_trip_output;
  }
}

}  // namespace