av1_txfm_test.cc 4.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 *  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 <stdio.h>
12
#include "test/av1_txfm_test.h"
13

14
namespace libaom_test {
15

clang-format's avatar
clang-format committed
16
int get_txfm1d_size(TX_SIZE tx_size) { return 1 << (tx_size + 2); }
17

clang-format's avatar
clang-format committed
18
void get_txfm1d_type(TX_TYPE txfm2d_type, TYPE_TXFM *type0, TYPE_TXFM *type1) {
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  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;
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#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
58 59 60 61 62 63 64 65 66 67
    default:
      *type0 = TYPE_DCT;
      *type1 = TYPE_DCT;
      assert(0);
      break;
  }
}

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

clang-format's avatar
clang-format committed
68
void reference_dct_1d(const double *in, double *out, int size) {
69 70 71 72 73 74 75 76 77
  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
78
void reference_adst_1d(const double *in, double *out, int size) {
79 80 81 82 83 84 85 86
  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
87
void reference_hybrid_1d(double *in, double *out, int size, int type) {
88 89 90 91 92 93
  if (type == TYPE_DCT)
    reference_dct_1d(in, out, size);
  else
    reference_adst_1d(in, out, size);
}

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

  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;
}
122

clang-format's avatar
clang-format committed
123
template <typename Type>
124 125 126 127 128 129 130 131 132 133 134
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
135
template <typename Type>
136 137 138 139 140 141 142 143 144 145 146
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
147
template <typename Type>
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
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);

163
}  // namespace libaom_test