av1_inv_txfm2d_test.cc 5.17 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 13 14 15
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

Yaowu Xu's avatar
Yaowu Xu committed
16
#include "./av1_rtcd.h"
Angie Chiang's avatar
Angie Chiang committed
17
#include "test/acm_random.h"
18
#include "test/util.h"
Yaowu Xu's avatar
Yaowu Xu committed
19
#include "test/av1_txfm_test.h"
20
#include "av1/common/av1_inv_txfm1d_cfg.h"
Angie Chiang's avatar
Angie Chiang committed
21

22 23 24 25 26 27
using libaom_test::ACMRandom;
using libaom_test::input_base;
using libaom_test::bd;
using libaom_test::compute_avg_abs_error;
using libaom_test::Fwd_Txfm2d_Func;
using libaom_test::Inv_Txfm2d_Func;
Angie Chiang's avatar
Angie Chiang committed
28 29 30

namespace {

31
#if CONFIG_HIGHBITDEPTH
Yaowu Xu's avatar
Yaowu Xu committed
32
// AV1InvTxfm2dParam argument list:
33
// tx_type_, tx_size_, max_error_, max_avg_error_
Yaowu Xu's avatar
Yaowu Xu committed
34
typedef std::tr1::tuple<TX_TYPE, TX_SIZE, int, double> AV1InvTxfm2dParam;
35

Yaowu Xu's avatar
Yaowu Xu committed
36
class AV1InvTxfm2d : public ::testing::TestWithParam<AV1InvTxfm2dParam> {
37 38 39 40 41 42
 public:
  virtual void SetUp() {
    tx_type_ = GET_PARAM(0);
    tx_size_ = GET_PARAM(1);
    max_error_ = GET_PARAM(2);
    max_avg_error_ = GET_PARAM(3);
43
    txfm1d_size_ = libaom_test::get_txfm1d_size(tx_size_);
44 45 46 47 48
    txfm2d_size_ = txfm1d_size_ * txfm1d_size_;
  }

  void RunRoundtripCheck() {
    const Fwd_Txfm2d_Func fwd_txfm_func =
49
        libaom_test::fwd_txfm_func_ls[tx_size_];
50
    const Inv_Txfm2d_Func inv_txfm_func =
51
        libaom_test::inv_txfm_func_ls[tx_size_];
52 53
    double avg_abs_error = 0;
    ACMRandom rnd(ACMRandom::DeterministicSeed());
Sebastien Alaiwan's avatar
Sebastien Alaiwan committed
54 55 56

    const int count_ = 500;

57
    for (int ci = 0; ci < count_; ci++) {
58 59 60
      int16_t expected[64 * 64] = { 0 };
      assert(txfm2d_size_ < ARRAY_SIZE(expected));

61 62 63
      for (int ni = 0; ni < txfm2d_size_; ++ni) {
        if (ci == 0) {
          int extreme_input = input_base - 1;
64
          expected[ni] = extreme_input;  // extreme case
65
        } else {
66
          expected[ni] = rnd.Rand16() % input_base;
Angie Chiang's avatar
Angie Chiang committed
67
        }
68 69
      }

70 71 72 73 74 75 76
      int32_t coeffs[64 * 64] = { 0 };
      assert(txfm2d_size_ < ARRAY_SIZE(coeffs));
      fwd_txfm_func(expected, coeffs, txfm1d_size_, tx_type_, bd);

      uint16_t actual[64 * 64] = { 0 };
      assert(txfm2d_size_ < ARRAY_SIZE(actual));
      inv_txfm_func(coeffs, actual, txfm1d_size_, tx_type_, bd);
Angie Chiang's avatar
Angie Chiang committed
77

78
      for (int ni = 0; ni < txfm2d_size_; ++ni) {
79
        EXPECT_GE(max_error_, abs(expected[ni] - actual[ni]));
Angie Chiang's avatar
Angie Chiang committed
80
      }
81
      avg_abs_error += compute_avg_abs_error<int16_t, uint16_t>(
82
          expected, actual, txfm2d_size_);
Angie Chiang's avatar
Angie Chiang committed
83 84
    }

85 86 87 88 89
    avg_abs_error /= count_;
    // max_abs_avg_error comes from upper bound of
    // printf("txfm1d_size: %d accuracy_avg_abs_error: %f\n",
    // txfm1d_size_, avg_abs_error);
    EXPECT_GE(max_avg_error_, avg_abs_error);
Angie Chiang's avatar
Angie Chiang committed
90
  }
91 92 93 94 95 96 97 98 99 100

 private:
  int max_error_;
  double max_avg_error_;
  TX_TYPE tx_type_;
  TX_SIZE tx_size_;
  int txfm1d_size_;
  int txfm2d_size_;
};

Yaowu Xu's avatar
Yaowu Xu committed
101
TEST_P(AV1InvTxfm2d, RunRoundtripCheck) { RunRoundtripCheck(); }
102

Yaowu Xu's avatar
Yaowu Xu committed
103
const AV1InvTxfm2dParam av1_inv_txfm2d_param[] = {
104
#if CONFIG_EXT_TX
Yaowu Xu's avatar
Yaowu Xu committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
  AV1InvTxfm2dParam(FLIPADST_DCT, TX_4X4, 2, 0.002),
  AV1InvTxfm2dParam(DCT_FLIPADST, TX_4X4, 2, 0.002),
  AV1InvTxfm2dParam(FLIPADST_FLIPADST, TX_4X4, 2, 0.002),
  AV1InvTxfm2dParam(ADST_FLIPADST, TX_4X4, 2, 0.002),
  AV1InvTxfm2dParam(FLIPADST_ADST, TX_4X4, 2, 0.002),
  AV1InvTxfm2dParam(FLIPADST_DCT, TX_8X8, 2, 0.02),
  AV1InvTxfm2dParam(DCT_FLIPADST, TX_8X8, 2, 0.02),
  AV1InvTxfm2dParam(FLIPADST_FLIPADST, TX_8X8, 2, 0.02),
  AV1InvTxfm2dParam(ADST_FLIPADST, TX_8X8, 2, 0.02),
  AV1InvTxfm2dParam(FLIPADST_ADST, TX_8X8, 2, 0.02),
  AV1InvTxfm2dParam(FLIPADST_DCT, TX_16X16, 2, 0.04),
  AV1InvTxfm2dParam(DCT_FLIPADST, TX_16X16, 2, 0.04),
  AV1InvTxfm2dParam(FLIPADST_FLIPADST, TX_16X16, 11, 0.04),
  AV1InvTxfm2dParam(ADST_FLIPADST, TX_16X16, 2, 0.04),
  AV1InvTxfm2dParam(FLIPADST_ADST, TX_16X16, 2, 0.04),
  AV1InvTxfm2dParam(FLIPADST_DCT, TX_32X32, 4, 0.4),
  AV1InvTxfm2dParam(DCT_FLIPADST, TX_32X32, 4, 0.4),
  AV1InvTxfm2dParam(FLIPADST_FLIPADST, TX_32X32, 4, 0.4),
  AV1InvTxfm2dParam(ADST_FLIPADST, TX_32X32, 4, 0.4),
  AV1InvTxfm2dParam(FLIPADST_ADST, TX_32X32, 4, 0.4),
125
#endif
Yaowu Xu's avatar
Yaowu Xu committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
  AV1InvTxfm2dParam(DCT_DCT, TX_4X4, 2, 0.002),
  AV1InvTxfm2dParam(ADST_DCT, TX_4X4, 2, 0.002),
  AV1InvTxfm2dParam(DCT_ADST, TX_4X4, 2, 0.002),
  AV1InvTxfm2dParam(ADST_ADST, TX_4X4, 2, 0.002),
  AV1InvTxfm2dParam(DCT_DCT, TX_8X8, 2, 0.02),
  AV1InvTxfm2dParam(ADST_DCT, TX_8X8, 2, 0.02),
  AV1InvTxfm2dParam(DCT_ADST, TX_8X8, 2, 0.02),
  AV1InvTxfm2dParam(ADST_ADST, TX_8X8, 2, 0.02),
  AV1InvTxfm2dParam(DCT_DCT, TX_16X16, 2, 0.04),
  AV1InvTxfm2dParam(ADST_DCT, TX_16X16, 2, 0.04),
  AV1InvTxfm2dParam(DCT_ADST, TX_16X16, 2, 0.04),
  AV1InvTxfm2dParam(ADST_ADST, TX_16X16, 2, 0.04),
  AV1InvTxfm2dParam(DCT_DCT, TX_32X32, 4, 0.4),
  AV1InvTxfm2dParam(ADST_DCT, TX_32X32, 4, 0.4),
  AV1InvTxfm2dParam(DCT_ADST, TX_32X32, 4, 0.4),
  AV1InvTxfm2dParam(ADST_ADST, TX_32X32, 4, 0.4)
142 143
};

Yaowu Xu's avatar
Yaowu Xu committed
144 145
INSTANTIATE_TEST_CASE_P(C, AV1InvTxfm2d,
                        ::testing::ValuesIn(av1_inv_txfm2d_param));
146

147
#endif  // CONFIG_HIGHBITDEPTH
Angie Chiang's avatar
Angie Chiang committed
148

149
}  // namespace