av1_inv_txfm2d_test.cc 5.33 KB
Newer Older
Angie Chiang's avatar
Angie Chiang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 *  Copyright (c) 2015 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

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

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

21 22 23 24 25 26
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
27 28 29

namespace {

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

Yaowu Xu's avatar
Yaowu Xu committed
35
class AV1InvTxfm2d : public ::testing::TestWithParam<AV1InvTxfm2dParam> {
36 37 38 39 40 41
 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);
42
    txfm1d_size_ = libaom_test::get_txfm1d_size(tx_size_);
43 44 45
    txfm2d_size_ = txfm1d_size_ * txfm1d_size_;
    count_ = 500;

clang-format's avatar
clang-format committed
46
    input_ = reinterpret_cast<int16_t *>(
Yaowu Xu's avatar
Yaowu Xu committed
47
        aom_memalign(16, sizeof(int16_t) * txfm2d_size_));
clang-format's avatar
clang-format committed
48
    ref_input_ = reinterpret_cast<uint16_t *>(
Yaowu Xu's avatar
Yaowu Xu committed
49
        aom_memalign(16, sizeof(uint16_t) * txfm2d_size_));
clang-format's avatar
clang-format committed
50
    output_ = reinterpret_cast<int32_t *>(
Yaowu Xu's avatar
Yaowu Xu committed
51
        aom_memalign(16, sizeof(int32_t) * txfm2d_size_));
52 53 54 55
  }

  void RunRoundtripCheck() {
    const Fwd_Txfm2d_Func fwd_txfm_func =
56
        libaom_test::fwd_txfm_func_ls[tx_size_];
57
    const Inv_Txfm2d_Func inv_txfm_func =
58
        libaom_test::inv_txfm_func_ls[tx_size_];
59 60 61 62 63 64 65 66 67 68 69
    double avg_abs_error = 0;
    ACMRandom rnd(ACMRandom::DeterministicSeed());
    for (int ci = 0; ci < count_; ci++) {
      for (int ni = 0; ni < txfm2d_size_; ++ni) {
        if (ci == 0) {
          int extreme_input = input_base - 1;
          input_[ni] = extreme_input;  // extreme case
          ref_input_[ni] = 0;
        } else {
          input_[ni] = rnd.Rand16() % input_base;
          ref_input_[ni] = 0;
Angie Chiang's avatar
Angie Chiang committed
70
        }
71 72 73 74
      }

      fwd_txfm_func(input_, output_, txfm1d_size_, tx_type_, bd);
      inv_txfm_func(output_, ref_input_, txfm1d_size_, tx_type_, bd);
Angie Chiang's avatar
Angie Chiang committed
75

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

83 84 85 86 87
    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
88
  }
89 90

  virtual void TearDown() {
Yaowu Xu's avatar
Yaowu Xu committed
91 92 93
    aom_free(input_);
    aom_free(output_);
    aom_free(ref_input_);
94 95 96 97 98 99 100 101 102 103
  }

 private:
  int count_;
  int max_error_;
  double max_avg_error_;
  TX_TYPE tx_type_;
  TX_SIZE tx_size_;
  int txfm1d_size_;
  int txfm2d_size_;
clang-format's avatar
clang-format committed
104 105 106
  int16_t *input_;
  uint16_t *ref_input_;
  int32_t *output_;
107 108
};

Yaowu Xu's avatar
Yaowu Xu committed
109
TEST_P(AV1InvTxfm2d, RunRoundtripCheck) { RunRoundtripCheck(); }
110

Yaowu Xu's avatar
Yaowu Xu committed
111
const AV1InvTxfm2dParam av1_inv_txfm2d_param[] = {
112
#if CONFIG_EXT_TX
Yaowu Xu's avatar
Yaowu Xu committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
  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),
133
#endif
Yaowu Xu's avatar
Yaowu Xu committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
  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)
150 151
};

Yaowu Xu's avatar
Yaowu Xu committed
152 153
INSTANTIATE_TEST_CASE_P(C, AV1InvTxfm2d,
                        ::testing::ValuesIn(av1_inv_txfm2d_param));
154

Yaowu Xu's avatar
Yaowu Xu committed
155
#endif  // CONFIG_AOM_HIGHBITDEPTH
Angie Chiang's avatar
Angie Chiang committed
156

157
}  // namespace