OSUOSL/Nero are experiencing Internet connectivity problems. This affects us as we're hosted with OSUOSL. We apologize for the inconvenience.

av1_txfm_test.cc 4.94 KB
Newer Older
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
10 11 12
 */

#include <stdio.h>
13
#include "test/av1_txfm_test.h"
14

15
namespace libaom_test {
16

17
int get_txfm1d_size(TX_SIZE tx_size) { return tx_size_wide[tx_size]; }
18

clang-format's avatar
clang-format committed
19
void get_txfm1d_type(TX_TYPE txfm2d_type, TYPE_TXFM *type0, TYPE_TXFM *type1) {
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  switch (txfm2d_type) {
    case DCT_DCT:
      *type0 = TYPE_DCT;
      *type1 = TYPE_DCT;
      break;
    case ADST_DCT:
      *type0 = TYPE_ADST;
      *type1 = TYPE_DCT;
      break;
    case DCT_ADST:
      *type0 = TYPE_DCT;
      *type1 = TYPE_ADST;
      break;
    case ADST_ADST:
      *type0 = TYPE_ADST;
      *type1 = TYPE_ADST;
      break;
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#if CONFIG_EXT_TX
    case FLIPADST_DCT:
      *type0 = TYPE_ADST;
      *type1 = TYPE_DCT;
      break;
    case DCT_FLIPADST:
      *type0 = TYPE_DCT;
      *type1 = TYPE_ADST;
      break;
    case FLIPADST_FLIPADST:
      *type0 = TYPE_ADST;
      *type1 = TYPE_ADST;
      break;
    case ADST_FLIPADST:
      *type0 = TYPE_ADST;
      *type1 = TYPE_ADST;
      break;
    case FLIPADST_ADST:
      *type0 = TYPE_ADST;
      *type1 = TYPE_ADST;
      break;
#endif  // CONFIG_EXT_TX
59 60 61 62 63 64 65 66 67 68
    default:
      *type0 = TYPE_DCT;
      *type1 = TYPE_DCT;
      assert(0);
      break;
  }
}

double invSqrt2 = 1 / pow(2, 0.5);

clang-format's avatar
clang-format committed
69
void reference_dct_1d(const double *in, double *out, int size) {
70 71 72 73 74 75 76 77 78
  for (int k = 0; k < size; ++k) {
    out[k] = 0;
    for (int n = 0; n < size; ++n) {
      out[k] += in[n] * cos(M_PI * (2 * n + 1) * k / (2 * size));
    }
    if (k == 0) out[k] = out[k] * invSqrt2;
  }
}

clang-format's avatar
clang-format committed
79
void reference_adst_1d(const double *in, double *out, int size) {
80 81 82 83 84 85 86 87
  for (int k = 0; k < size; ++k) {
    out[k] = 0;
    for (int n = 0; n < size; ++n) {
      out[k] += in[n] * sin(M_PI * (2 * n + 1) * (2 * k + 1) / (4 * size));
    }
  }
}

clang-format's avatar
clang-format committed
88
void reference_hybrid_1d(double *in, double *out, int size, int type) {
89 90 91 92 93 94
  if (type == TYPE_DCT)
    reference_dct_1d(in, out, size);
  else
    reference_adst_1d(in, out, size);
}

clang-format's avatar
clang-format committed
95 96 97
void reference_hybrid_2d(double *in, double *out, int size, int type0,
                         int type1) {
  double *tempOut = new double[size * size];
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

  for (int r = 0; r < size; r++) {
    // out ->tempOut
    for (int c = 0; c < size; c++) {
      tempOut[r * size + c] = in[c * size + r];
    }
  }

  // dct each row: in -> out
  for (int r = 0; r < size; r++) {
    reference_hybrid_1d(tempOut + r * size, out + r * size, size, type0);
  }

  for (int r = 0; r < size; r++) {
    // out ->tempOut
    for (int c = 0; c < size; c++) {
      tempOut[r * size + c] = out[c * size + r];
    }
  }

  for (int r = 0; r < size; r++) {
    reference_hybrid_1d(tempOut + r * size, out + r * size, size, type1);
  }
  delete[] tempOut;
}
123

clang-format's avatar
clang-format committed
124
template <typename Type>
125 126 127 128 129 130 131 132 133 134 135
void fliplr(Type *dest, int stride, int length) {
  int i, j;
  for (i = 0; i < length; ++i) {
    for (j = 0; j < length / 2; ++j) {
      const Type tmp = dest[i * stride + j];
      dest[i * stride + j] = dest[i * stride + length - 1 - j];
      dest[i * stride + length - 1 - j] = tmp;
    }
  }
}

clang-format's avatar
clang-format committed
136
template <typename Type>
137 138 139 140 141 142 143 144 145 146 147
void flipud(Type *dest, int stride, int length) {
  int i, j;
  for (j = 0; j < length; ++j) {
    for (i = 0; i < length / 2; ++i) {
      const Type tmp = dest[i * stride + j];
      dest[i * stride + j] = dest[(length - 1 - i) * stride + j];
      dest[(length - 1 - i) * stride + j] = tmp;
    }
  }
}

clang-format's avatar
clang-format committed
148
template <typename Type>
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
void fliplrud(Type *dest, int stride, int length) {
  int i, j;
  for (i = 0; i < length / 2; ++i) {
    for (j = 0; j < length; ++j) {
      const Type tmp = dest[i * stride + j];
      dest[i * stride + j] = dest[(length - 1 - i) * stride + length - 1 - j];
      dest[(length - 1 - i) * stride + length - 1 - j] = tmp;
    }
  }
}

template void fliplr<double>(double *dest, int stride, int length);
template void flipud<double>(double *dest, int stride, int length);
template void fliplrud<double>(double *dest, int stride, int length);

Angie Chiang's avatar
Angie Chiang committed
164 165 166 167 168 169 170 171 172 173 174 175
int bd_arr[BD_NUM] = { 8, 10, 12 };
int8_t low_range_arr[BD_NUM] = { 16, 32, 32 };
int8_t high_range_arr[BD_NUM] = { 32, 32, 32 };

void txfm_stage_range_check(const int8_t *stage_range, int stage_num,
                            const int8_t *cos_bit, int low_range,
                            int high_range) {
  for (int i = 0; i < stage_num; ++i) {
    EXPECT_LE(stage_range[i], low_range);
  }
  for (int i = 0; i < stage_num - 1; ++i) {
    // make sure there is no overflow while doing half_btf()
176
    EXPECT_LE(stage_range[i] + cos_bit[i], high_range);
Angie Chiang's avatar
Angie Chiang committed
177 178 179
    EXPECT_LE(stage_range[i + 1] + cos_bit[i], high_range);
  }
}
180
}  // namespace libaom_test