av1_fwd_txfm1d_test.cc 3.28 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
 */

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

15 16 17 18 19 20
using libaom_test::ACMRandom;
using libaom_test::input_base;
using libaom_test::reference_hybrid_1d;
using libaom_test::TYPE_TXFM;
using libaom_test::TYPE_DCT;
using libaom_test::TYPE_ADST;
Angie Chiang's avatar
Angie Chiang committed
21 22

namespace {
23
const int txfm_type_num = 2;
clang-format's avatar
clang-format committed
24
const TYPE_TXFM txfm_type_ls[2] = { TYPE_DCT, TYPE_ADST };
Angie Chiang's avatar
Angie Chiang committed
25

26
const int txfm_size_num = 5;
27
const int txfm_size_ls[5] = { 4, 8, 16, 32, 64 };
Angie Chiang's avatar
Angie Chiang committed
28

29 30 31 32 33
const TxfmFunc fwd_txfm_func_ls[][2] = {
  { av1_fdct4_new, av1_fadst4_new },
  { av1_fdct8_new, av1_fadst8_new },
  { av1_fdct16_new, av1_fadst16_new },
  { av1_fdct32_new, av1_fadst32_new },
34
#if CONFIG_TX64X64
35
  { av1_fdct64_new, NULL },
36
#endif
clang-format's avatar
clang-format committed
37
};
Angie Chiang's avatar
Angie Chiang committed
38 39

// the maximum stage number of fwd/inv 1d dct/adst txfm is 12
clang-format's avatar
clang-format committed
40 41
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
42

Yaowu Xu's avatar
Yaowu Xu committed
43
TEST(av1_fwd_txfm1d, round_shift) {
44
  EXPECT_EQ(round_shift(7, 1), 4);
Angie Chiang's avatar
Angie Chiang committed
45 46 47 48 49 50 51 52 53
  EXPECT_EQ(round_shift(-7, 1), -3);

  EXPECT_EQ(round_shift(7, 2), 2);
  EXPECT_EQ(round_shift(-7, 2), -2);

  EXPECT_EQ(round_shift(8, 2), 2);
  EXPECT_EQ(round_shift(-8, 2), -2);
}

54
TEST(av1_fwd_txfm1d, cospi_arr_data) {
Angie Chiang's avatar
Angie Chiang committed
55 56
  for (int i = 0; i < 7; i++) {
    for (int j = 0; j < 64; j++) {
57
      EXPECT_EQ(cospi_arr_data[i][j],
Angie Chiang's avatar
Angie Chiang committed
58 59 60 61 62
                (int32_t)round(cos(M_PI * j / 128) * (1 << (cos_bit_min + i))));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
63
TEST(av1_fwd_txfm1d, accuracy) {
Angie Chiang's avatar
Angie Chiang committed
64 65 66 67 68 69 70 71 72 73
  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];
    double *ref_input = new double[txfm_size];
    double *ref_output = new double[txfm_size];

    for (int ti = 0; ti < txfm_type_num; ++ti) {
      TYPE_TXFM txfm_type = txfm_type_ls[ti];
74
      TxfmFunc fwd_txfm_func = fwd_txfm_func_ls[si][ti];
Angie Chiang's avatar
Angie Chiang committed
75 76 77
      int max_error = 7;

      const int count_test_block = 5000;
Angie Chiang's avatar
Angie Chiang committed
78 79 80
      if (fwd_txfm_func != NULL) {
        for (int ti = 0; ti < count_test_block; ++ti) {
          for (int ni = 0; ni < txfm_size; ++ni) {
81
            input[ni] = rnd.Rand16() % input_base - rnd.Rand16() % input_base;
Angie Chiang's avatar
Angie Chiang committed
82 83 84 85 86 87 88
            ref_input[ni] = static_cast<double>(input[ni]);
          }

          fwd_txfm_func(input, output, cos_bit, range_bit);
          reference_hybrid_1d(ref_input, ref_output, txfm_size, txfm_type);

          for (int ni = 0; ni < txfm_size; ++ni) {
89
            ASSERT_LE(
Angie Chiang's avatar
Angie Chiang committed
90
                abs(output[ni] - static_cast<int32_t>(round(ref_output[ni]))),
91 92
                max_error)
                << "tx size = " << txfm_size << ", tx type = " << txfm_type;
Angie Chiang's avatar
Angie Chiang committed
93
          }
Angie Chiang's avatar
Angie Chiang committed
94 95 96 97 98 99 100 101 102 103 104
        }
      }
    }

    delete[] input;
    delete[] output;
    delete[] ref_input;
    delete[] ref_output;
  }
}
}  // namespace