idct.c 103 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
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.
Jingning Han's avatar
Jingning Han committed
10 11 12 13
 */

#include <math.h>

Yaowu Xu's avatar
Yaowu Xu committed
14
#include "./aom_dsp_rtcd.h"
Geza Lore's avatar
Geza Lore committed
15 16 17
#include "./av1_rtcd.h"
#include "aom_dsp/inv_txfm.h"
#include "aom_ports/mem.h"
18
#include "av1/common/av1_inv_txfm1d_cfg.h"
19 20 21
#include "av1/common/blockd.h"
#include "av1/common/enums.h"
#include "av1/common/idct.h"
Jingning Han's avatar
Jingning Han committed
22

23
int av1_get_tx_scale(const TX_SIZE tx_size) {
24 25 26 27 28 29 30
  if (txsize_sqr_up_map[tx_size] == TX_32X32) return 1;
#if CONFIG_TX64X64
  else if (txsize_sqr_up_map[tx_size] == TX_64X64)
    return 2;
#endif  // CONFIG_TX64X64
  else
    return 0;
31 32
}

33 34 35
// NOTE: The implementation of all inverses need to be aware of the fact
// that input and output could be the same buffer.

36
#if CONFIG_EXT_TX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
37 38 39 40 41 42 43 44
static void iidtx4_c(const tran_low_t *input, tran_low_t *output) {
  int i;
  for (i = 0; i < 4; ++i)
    output[i] = (tran_low_t)dct_const_round_shift(input[i] * Sqrt2);
}

static void iidtx8_c(const tran_low_t *input, tran_low_t *output) {
  int i;
clang-format's avatar
clang-format committed
45
  for (i = 0; i < 8; ++i) output[i] = input[i] * 2;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
46 47 48 49 50 51 52 53 54 55
}

static void iidtx16_c(const tran_low_t *input, tran_low_t *output) {
  int i;
  for (i = 0; i < 16; ++i)
    output[i] = (tran_low_t)dct_const_round_shift(input[i] * 2 * Sqrt2);
}

static void iidtx32_c(const tran_low_t *input, tran_low_t *output) {
  int i;
clang-format's avatar
clang-format committed
56
  for (i = 0; i < 32; ++i) output[i] = input[i] * 4;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
57
}
58 59 60 61 62 63 64 65

#if CONFIG_TX64X64
static void iidtx64_c(const tran_low_t *input, tran_low_t *output) {
  int i;
  for (i = 0; i < 64; ++i)
    output[i] = (tran_low_t)dct_const_round_shift(input[i] * 4 * Sqrt2);
}
#endif  // CONFIG_TX64X64
66
#endif  // CONFIG_EXT_TX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
67

68
// For use in lieu of ADST
69 70 71 72 73 74 75
static void ihalfright32_c(const tran_low_t *input, tran_low_t *output) {
  int i;
  tran_low_t inputhalf[16];
  // Multiply input by sqrt(2)
  for (i = 0; i < 16; ++i) {
    inputhalf[i] = (tran_low_t)dct_const_round_shift(input[i] * Sqrt2);
  }
76 77 78
  for (i = 0; i < 16; ++i) {
    output[i] = input[16 + i] * 4;
  }
Luca Barbato's avatar
Luca Barbato committed
79
  aom_idct16_c(inputhalf, output + 16);
80 81 82
  // Note overall scaling factor is 4 times orthogonal
}

83 84 85 86 87
#if CONFIG_TX64X64
static void idct64_col_c(const tran_low_t *input, tran_low_t *output) {
  int32_t in[64], out[64];
  int i;
  for (i = 0; i < 64; ++i) in[i] = (int32_t)input[i];
88
  av1_idct64_new(in, out, inv_cos_bit_col_dct_64, inv_stage_range_col_dct_64);
89 90 91 92 93 94 95
  for (i = 0; i < 64; ++i) output[i] = (tran_low_t)out[i];
}

static void idct64_row_c(const tran_low_t *input, tran_low_t *output) {
  int32_t in[64], out[64];
  int i;
  for (i = 0; i < 64; ++i) in[i] = (int32_t)input[i];
96
  av1_idct64_new(in, out, inv_cos_bit_row_dct_64, inv_stage_range_row_dct_64);
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  for (i = 0; i < 64; ++i) output[i] = (tran_low_t)out[i];
}

// For use in lieu of ADST
static void ihalfright64_c(const tran_low_t *input, tran_low_t *output) {
  int i;
  tran_low_t inputhalf[32];
  // Multiply input by sqrt(2)
  for (i = 0; i < 32; ++i) {
    inputhalf[i] = (tran_low_t)dct_const_round_shift(input[i] * Sqrt2);
  }
  for (i = 0; i < 32; ++i) {
    output[i] = (tran_low_t)dct_const_round_shift(input[32 + i] * 4 * Sqrt2);
  }
  aom_idct32_c(inputhalf, output + 32);
  // Note overall scaling factor is 4 * sqrt(2)  times orthogonal
}
#endif  // CONFIG_TX64X64

116
#if CONFIG_HIGHBITDEPTH
117
#if CONFIG_EXT_TX
118 119 120 121
// TODO(sarahparker) these functions will be removed once the highbitdepth
// codepath works properly for rectangular transforms. They have almost
// identical versions in av1_inv_txfm1d.c, but those are currently only
// being used for square transforms.
Debargha Mukherjee's avatar
Debargha Mukherjee committed
122 123 124 125
static void highbd_iidtx4_c(const tran_low_t *input, tran_low_t *output,
                            int bd) {
  int i;
  for (i = 0; i < 4; ++i)
126
    output[i] = HIGHBD_WRAPLOW(dct_const_round_shift(input[i] * Sqrt2), bd);
Debargha Mukherjee's avatar
Debargha Mukherjee committed
127 128 129 130 131
}

static void highbd_iidtx8_c(const tran_low_t *input, tran_low_t *output,
                            int bd) {
  int i;
clang-format's avatar
clang-format committed
132 133
  (void)bd;
  for (i = 0; i < 8; ++i) output[i] = input[i] * 2;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
134 135 136
}

static void highbd_iidtx16_c(const tran_low_t *input, tran_low_t *output,
clang-format's avatar
clang-format committed
137
                             int bd) {
Debargha Mukherjee's avatar
Debargha Mukherjee committed
138 139
  int i;
  for (i = 0; i < 16; ++i)
140
    output[i] = HIGHBD_WRAPLOW(dct_const_round_shift(input[i] * 2 * Sqrt2), bd);
Debargha Mukherjee's avatar
Debargha Mukherjee committed
141 142 143 144 145
}

static void highbd_iidtx32_c(const tran_low_t *input, tran_low_t *output,
                             int bd) {
  int i;
clang-format's avatar
clang-format committed
146 147
  (void)bd;
  for (i = 0; i < 32; ++i) output[i] = input[i] * 4;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
148
}
149
#endif  // CONFIG_EXT_TX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
150

151
static void highbd_ihalfright32_c(const tran_low_t *input, tran_low_t *output,
152
                                  int bd) {
153 154 155 156
  int i;
  tran_low_t inputhalf[16];
  // Multiply input by sqrt(2)
  for (i = 0; i < 16; ++i) {
157
    inputhalf[i] = HIGHBD_WRAPLOW(dct_const_round_shift(input[i] * Sqrt2), bd);
158
  }
159 160 161
  for (i = 0; i < 16; ++i) {
    output[i] = input[16 + i] * 4;
  }
162
  aom_highbd_idct16_c(inputhalf, output + 16, bd);
163 164
  // Note overall scaling factor is 4 times orthogonal
}
165

166
#if CONFIG_EXT_TX
167 168 169 170 171
#if CONFIG_TX64X64
static void highbd_iidtx64_c(const tran_low_t *input, tran_low_t *output,
                             int bd) {
  int i;
  for (i = 0; i < 64; ++i)
172
    output[i] = HIGHBD_WRAPLOW(dct_const_round_shift(input[i] * 4 * Sqrt2), bd);
173
}
174 175
#endif  // CONFIG_TX64X64
#endif  // CONFIG_EXT_TX
176

177
#if CONFIG_TX64X64
178 179
// For use in lieu of ADST
static void highbd_ihalfright64_c(const tran_low_t *input, tran_low_t *output,
180
                                  int bd) {
181 182 183 184
  int i;
  tran_low_t inputhalf[32];
  // Multiply input by sqrt(2)
  for (i = 0; i < 32; ++i) {
185
    inputhalf[i] = HIGHBD_WRAPLOW(dct_const_round_shift(input[i] * Sqrt2), bd);
186 187
  }
  for (i = 0; i < 32; ++i) {
188 189
    output[i] =
        HIGHBD_WRAPLOW(dct_const_round_shift(input[32 + i] * 4 * Sqrt2), bd);
190
  }
191
  aom_highbd_idct32_c(inputhalf, output + 32, bd);
192 193 194 195
  // Note overall scaling factor is 4 * sqrt(2)  times orthogonal
}

static void highbd_idct64_col_c(const tran_low_t *input, tran_low_t *output,
196
                                int bd) {
197 198 199 200
  int32_t in[64], out[64];
  int i;
  (void)bd;
  for (i = 0; i < 64; ++i) in[i] = (int32_t)input[i];
201
  av1_idct64_new(in, out, inv_cos_bit_col_dct_64, inv_stage_range_col_dct_64);
202 203 204 205
  for (i = 0; i < 64; ++i) output[i] = (tran_low_t)out[i];
}

static void highbd_idct64_row_c(const tran_low_t *input, tran_low_t *output,
206
                                int bd) {
207 208 209 210
  int32_t in[64], out[64];
  int i;
  (void)bd;
  for (i = 0; i < 64; ++i) in[i] = (int32_t)input[i];
211
  av1_idct64_new(in, out, inv_cos_bit_row_dct_64, inv_stage_range_row_dct_64);
212 213 214
  for (i = 0; i < 64; ++i) output[i] = (tran_low_t)out[i];
}
#endif  // CONFIG_TX64X64
215
#endif  // CONFIG_HIGHBITDEPTH
216

Jingning Han's avatar
Jingning Han committed
217
// Inverse identity transform and add.
218
#if CONFIG_EXT_TX
219
static void inv_idtx_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Jingning Han's avatar
Jingning Han committed
220
                           int bs, int tx_type) {
221
  int r, c;
222
  const int shift = bs < 32 ? 3 : (bs < 64 ? 2 : 1);
Debargha Mukherjee's avatar
Debargha Mukherjee committed
223
  if (tx_type == IDTX) {
Jingning Han's avatar
Jingning Han committed
224 225
    for (r = 0; r < bs; ++r) {
      for (c = 0; c < bs; ++c)
Debargha Mukherjee's avatar
Debargha Mukherjee committed
226 227 228
        dest[c] = clip_pixel_add(dest[c], input[c] >> shift);
      dest += stride;
      input += bs;
Jingning Han's avatar
Jingning Han committed
229
    }
230 231
  }
}
232
#endif  // CONFIG_EXT_TX
233

clang-format's avatar
clang-format committed
234 235 236 237 238
#define FLIPUD_PTR(dest, stride, size)       \
  do {                                       \
    (dest) = (dest) + ((size)-1) * (stride); \
    (stride) = -(stride);                    \
  } while (0)
239

240
#if CONFIG_EXT_TX
clang-format's avatar
clang-format committed
241 242 243
static void maybe_flip_strides(uint8_t **dst, int *dstride, tran_low_t **src,
                               int *sstride, int tx_type, int sizey,
                               int sizex) {
244 245 246 247 248 249 250 251
  // Note that the transpose of src will be added to dst. In order to LR
  // flip the addends (in dst coordinates), we UD flip the src. To UD flip
  // the addends, we UD flip the dst.
  switch (tx_type) {
    case DCT_DCT:
    case ADST_DCT:
    case DCT_ADST:
    case ADST_ADST:
Debargha Mukherjee's avatar
Debargha Mukherjee committed
252
    case IDTX:
Jingning Han's avatar
Jingning Han committed
253 254
    case V_DCT:
    case H_DCT:
255
    case V_ADST:
clang-format's avatar
clang-format committed
256
    case H_ADST: break;
257 258
    case FLIPADST_DCT:
    case FLIPADST_ADST:
259
    case V_FLIPADST:
260
      // flip UD
261
      FLIPUD_PTR(*dst, *dstride, sizey);
262 263 264
      break;
    case DCT_FLIPADST:
    case ADST_FLIPADST:
265
    case H_FLIPADST:
266
      // flip LR
267
      FLIPUD_PTR(*src, *sstride, sizex);
268 269 270
      break;
    case FLIPADST_FLIPADST:
      // flip UD
271
      FLIPUD_PTR(*dst, *dstride, sizey);
272
      // flip LR
273
      FLIPUD_PTR(*src, *sstride, sizex);
274
      break;
clang-format's avatar
clang-format committed
275
    default: assert(0); break;
276 277
  }
}
278
#endif  // CONFIG_EXT_TX
279

280
#if CONFIG_HIGHBITDEPTH
281
#if CONFIG_EXT_TX
282
static void highbd_inv_idtx_add_c(const tran_low_t *input, uint8_t *dest8,
283
                                  int stride, int bs, int tx_type, int bd) {
284 285 286
  int r, c;
  const int shift = bs < 32 ? 3 : 2;
  uint16_t *dest = CONVERT_TO_SHORTPTR(dest8);
287

Debargha Mukherjee's avatar
Debargha Mukherjee committed
288
  if (tx_type == IDTX) {
289 290
    for (r = 0; r < bs; ++r) {
      for (c = 0; c < bs; ++c)
Debargha Mukherjee's avatar
Debargha Mukherjee committed
291 292 293
        dest[c] = highbd_clip_pixel_add(dest[c], input[c] >> shift, bd);
      dest += stride;
      input += bs;
294
    }
295 296
  }
}
297

clang-format's avatar
clang-format committed
298 299 300
static void maybe_flip_strides16(uint16_t **dst, int *dstride, tran_low_t **src,
                                 int *sstride, int tx_type, int sizey,
                                 int sizex) {
301 302 303 304 305 306 307 308
  // Note that the transpose of src will be added to dst. In order to LR
  // flip the addends (in dst coordinates), we UD flip the src. To UD flip
  // the addends, we UD flip the dst.
  switch (tx_type) {
    case DCT_DCT:
    case ADST_DCT:
    case DCT_ADST:
    case ADST_ADST:
Debargha Mukherjee's avatar
Debargha Mukherjee committed
309 310 311
    case IDTX:
    case V_DCT:
    case H_DCT:
312
    case V_ADST:
clang-format's avatar
clang-format committed
313
    case H_ADST: break;
314 315
    case FLIPADST_DCT:
    case FLIPADST_ADST:
316
    case V_FLIPADST:
317
      // flip UD
318
      FLIPUD_PTR(*dst, *dstride, sizey);
319 320 321
      break;
    case DCT_FLIPADST:
    case ADST_FLIPADST:
322
    case H_FLIPADST:
323
      // flip LR
324
      FLIPUD_PTR(*src, *sstride, sizex);
325 326 327
      break;
    case FLIPADST_FLIPADST:
      // flip UD
328
      FLIPUD_PTR(*dst, *dstride, sizey);
329
      // flip LR
330
      FLIPUD_PTR(*src, *sstride, sizex);
331
      break;
clang-format's avatar
clang-format committed
332
    default: assert(0); break;
333 334
  }
}
335
#endif  // CONFIG_EXT_TX
336
#endif  // CONFIG_HIGHBITDEPTH
337

Yaowu Xu's avatar
Yaowu Xu committed
338 339
void av1_iht4x4_16_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                         int tx_type) {
340
  static const transform_2d IHT_4[] = {
Luca Barbato's avatar
Luca Barbato committed
341 342 343 344
    { aom_idct4_c, aom_idct4_c },    // DCT_DCT  = 0
    { aom_iadst4_c, aom_idct4_c },   // ADST_DCT = 1
    { aom_idct4_c, aom_iadst4_c },   // DCT_ADST = 2
    { aom_iadst4_c, aom_iadst4_c },  // ADST_ADST = 3
345
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
346 347 348 349 350 351 352 353 354 355 356 357 358
    { aom_iadst4_c, aom_idct4_c },   // FLIPADST_DCT
    { aom_idct4_c, aom_iadst4_c },   // DCT_FLIPADST
    { aom_iadst4_c, aom_iadst4_c },  // FLIPADST_FLIPADST
    { aom_iadst4_c, aom_iadst4_c },  // ADST_FLIPADST
    { aom_iadst4_c, aom_iadst4_c },  // FLIPADST_ADST
    { iidtx4_c, iidtx4_c },          // IDTX
    { aom_idct4_c, iidtx4_c },       // V_DCT
    { iidtx4_c, aom_idct4_c },       // H_DCT
    { aom_iadst4_c, iidtx4_c },      // V_ADST
    { iidtx4_c, aom_iadst4_c },      // H_ADST
    { aom_iadst4_c, iidtx4_c },      // V_FLIPADST
    { iidtx4_c, aom_iadst4_c },      // H_FLIPADST
#endif                               // CONFIG_EXT_TX
359 360 361
  };

  int i, j;
362
  tran_low_t tmp[4][4];
363 364 365
  tran_low_t out[4][4];
  tran_low_t *outp = &out[0][0];
  int outstride = 4;
366 367 368

  // inverse transform row vectors
  for (i = 0; i < 4; ++i) {
369
    IHT_4[tx_type].rows(input, out[i]);
clang-format's avatar
clang-format committed
370
    input += 4;
371 372 373
  }

  // transpose
374 375 376
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      tmp[j][i] = out[i][j];
377
    }
378 379 380 381
  }

  // inverse transform column vectors
  for (i = 0; i < 4; ++i) {
382
    IHT_4[tx_type].cols(tmp[i], out[i]);
383 384 385
  }

#if CONFIG_EXT_TX
386
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 4, 4);
387 388 389 390
#endif

  // Sum with the destination
  for (i = 0; i < 4; ++i) {
391
    for (j = 0; j < 4; ++j) {
392 393 394
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 4));
395 396 397 398
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
399 400
void av1_iht4x8_32_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                         int tx_type) {
401
  static const transform_2d IHT_4x8[] = {
Luca Barbato's avatar
Luca Barbato committed
402 403 404 405
    { aom_idct8_c, aom_idct4_c },    // DCT_DCT
    { aom_iadst8_c, aom_idct4_c },   // ADST_DCT
    { aom_idct8_c, aom_iadst4_c },   // DCT_ADST
    { aom_iadst8_c, aom_iadst4_c },  // ADST_ADST
406
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
407 408 409 410 411 412 413 414 415 416 417 418
    { aom_iadst8_c, aom_idct4_c },   // FLIPADST_DCT
    { aom_idct8_c, aom_iadst4_c },   // DCT_FLIPADST
    { aom_iadst8_c, aom_iadst4_c },  // FLIPADST_FLIPADST
    { aom_iadst8_c, aom_iadst4_c },  // ADST_FLIPADST
    { aom_iadst8_c, aom_iadst4_c },  // FLIPADST_ADST
    { iidtx8_c, iidtx4_c },          // IDTX
    { aom_idct8_c, iidtx4_c },       // V_DCT
    { iidtx8_c, aom_idct4_c },       // H_DCT
    { aom_iadst8_c, iidtx4_c },      // V_ADST
    { iidtx8_c, aom_iadst4_c },      // H_ADST
    { aom_iadst8_c, iidtx4_c },      // V_FLIPADST
    { iidtx8_c, aom_iadst4_c },      // H_FLIPADST
419
#endif
420 421
  };

422 423
  const int n = 4;
  const int n2 = 8;
424
  int i, j;
425
  tran_low_t out[4][8], tmp[4][8], outtmp[4];
426
  tran_low_t *outp = &out[0][0];
427
  int outstride = n2;
428 429

  // inverse transform row vectors and transpose
430
  for (i = 0; i < n2; ++i) {
431
    IHT_4x8[tx_type].rows(input, outtmp);
432
    for (j = 0; j < n; ++j)
433
      tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
434
    input += n;
435 436 437
  }

  // inverse transform column vectors
438
  for (i = 0; i < n; ++i) {
439
    IHT_4x8[tx_type].cols(tmp[i], out[i]);
440 441
  }

442
#if CONFIG_EXT_TX
443
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n2, n);
444
#endif
445 446

  // Sum with the destination
447 448
  for (i = 0; i < n2; ++i) {
    for (j = 0; j < n; ++j) {
449 450 451 452 453 454 455
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
456 457
void av1_iht8x4_32_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                         int tx_type) {
458
  static const transform_2d IHT_8x4[] = {
Luca Barbato's avatar
Luca Barbato committed
459 460 461 462
    { aom_idct4_c, aom_idct8_c },    // DCT_DCT
    { aom_iadst4_c, aom_idct8_c },   // ADST_DCT
    { aom_idct4_c, aom_iadst8_c },   // DCT_ADST
    { aom_iadst4_c, aom_iadst8_c },  // ADST_ADST
463
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
464 465 466 467 468 469 470 471 472 473 474 475
    { aom_iadst4_c, aom_idct8_c },   // FLIPADST_DCT
    { aom_idct4_c, aom_iadst8_c },   // DCT_FLIPADST
    { aom_iadst4_c, aom_iadst8_c },  // FLIPADST_FLIPADST
    { aom_iadst4_c, aom_iadst8_c },  // ADST_FLIPADST
    { aom_iadst4_c, aom_iadst8_c },  // FLIPADST_ADST
    { iidtx4_c, iidtx8_c },          // IDTX
    { aom_idct4_c, iidtx8_c },       // V_DCT
    { iidtx4_c, aom_idct8_c },       // H_DCT
    { aom_iadst4_c, iidtx8_c },      // V_ADST
    { iidtx4_c, aom_iadst8_c },      // H_ADST
    { aom_iadst4_c, iidtx8_c },      // V_FLIPADST
    { iidtx4_c, aom_iadst8_c },      // H_FLIPADST
476
#endif
477
  };
478 479
  const int n = 4;
  const int n2 = 8;
480 481

  int i, j;
482
  tran_low_t out[8][4], tmp[8][4], outtmp[8];
483
  tran_low_t *outp = &out[0][0];
484
  int outstride = n;
485 486

  // inverse transform row vectors and transpose
487
  for (i = 0; i < n; ++i) {
488
    IHT_8x4[tx_type].rows(input, outtmp);
489
    for (j = 0; j < n2; ++j)
490
      tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
491
    input += n2;
492 493 494
  }

  // inverse transform column vectors
495
  for (i = 0; i < n2; ++i) {
496
    IHT_8x4[tx_type].cols(tmp[i], out[i]);
497 498
  }

499
#if CONFIG_EXT_TX
500
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n2);
501
#endif
502 503

  // Sum with the destination
504 505
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n2; ++j) {
506 507 508 509 510 511 512
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
    }
  }
}

513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
void av1_iht4x16_64_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                          int tx_type) {
  static const transform_2d IHT_4x16[] = {
    { aom_idct16_c, aom_idct4_c },    // DCT_DCT
    { aom_iadst16_c, aom_idct4_c },   // ADST_DCT
    { aom_idct16_c, aom_iadst4_c },   // DCT_ADST
    { aom_iadst16_c, aom_iadst4_c },  // ADST_ADST
#if CONFIG_EXT_TX
    { aom_iadst16_c, aom_idct4_c },   // FLIPADST_DCT
    { aom_idct16_c, aom_iadst4_c },   // DCT_FLIPADST
    { aom_iadst16_c, aom_iadst4_c },  // FLIPADST_FLIPADST
    { aom_iadst16_c, aom_iadst4_c },  // ADST_FLIPADST
    { aom_iadst16_c, aom_iadst4_c },  // FLIPADST_ADST
    { iidtx16_c, iidtx4_c },          // IDTX
    { aom_idct16_c, iidtx4_c },       // V_DCT
    { iidtx16_c, aom_idct4_c },       // H_DCT
    { aom_iadst16_c, iidtx4_c },      // V_ADST
    { iidtx16_c, aom_iadst4_c },      // H_ADST
    { aom_iadst16_c, iidtx4_c },      // V_FLIPADST
    { iidtx16_c, aom_iadst4_c },      // H_FLIPADST
#endif
  };

  const int n = 4;
  const int n4 = 16;
  int i, j;
539
  tran_low_t out[4][16], tmp[4][16], outtmp[4];
540 541 542 543 544 545
  tran_low_t *outp = &out[0][0];
  int outstride = n4;

  // inverse transform row vectors and transpose
  for (i = 0; i < n4; ++i) {
    IHT_4x16[tx_type].rows(input, outtmp);
546
    for (j = 0; j < n; ++j) tmp[j][i] = outtmp[j];
547 548 549 550
    input += n;
  }

  // inverse transform column vectors
551
  for (i = 0; i < n; ++i) IHT_4x16[tx_type].cols(tmp[i], out[i]);
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592

#if CONFIG_EXT_TX
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n4, n);
#endif

  // Sum with the destination
  for (i = 0; i < n4; ++i) {
    for (j = 0; j < n; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
    }
  }
}

void av1_iht16x4_64_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                          int tx_type) {
  static const transform_2d IHT_16x4[] = {
    { aom_idct4_c, aom_idct16_c },    // DCT_DCT
    { aom_iadst4_c, aom_idct16_c },   // ADST_DCT
    { aom_idct4_c, aom_iadst16_c },   // DCT_ADST
    { aom_iadst4_c, aom_iadst16_c },  // ADST_ADST
#if CONFIG_EXT_TX
    { aom_iadst4_c, aom_idct16_c },   // FLIPADST_DCT
    { aom_idct4_c, aom_iadst16_c },   // DCT_FLIPADST
    { aom_iadst4_c, aom_iadst16_c },  // FLIPADST_FLIPADST
    { aom_iadst4_c, aom_iadst16_c },  // ADST_FLIPADST
    { aom_iadst4_c, aom_iadst16_c },  // FLIPADST_ADST
    { iidtx4_c, iidtx16_c },          // IDTX
    { aom_idct4_c, iidtx16_c },       // V_DCT
    { iidtx4_c, aom_idct16_c },       // H_DCT
    { aom_iadst4_c, iidtx16_c },      // V_ADST
    { iidtx4_c, aom_iadst16_c },      // H_ADST
    { aom_iadst4_c, iidtx16_c },      // V_FLIPADST
    { iidtx4_c, aom_iadst16_c },      // H_FLIPADST
#endif
  };
  const int n = 4;
  const int n4 = 16;

  int i, j;
593
  tran_low_t out[16][4], tmp[16][4], outtmp[16];
594 595 596 597 598 599
  tran_low_t *outp = &out[0][0];
  int outstride = n;

  // inverse transform row vectors and transpose
  for (i = 0; i < n; ++i) {
    IHT_16x4[tx_type].rows(input, outtmp);
600
    for (j = 0; j < n4; ++j) tmp[j][i] = outtmp[j];
601 602 603 604
    input += n4;
  }

  // inverse transform column vectors
605
  for (i = 0; i < n4; ++i) IHT_16x4[tx_type].cols(tmp[i], out[i]);
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620

#if CONFIG_EXT_TX
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n4);
#endif

  // Sum with the destination
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n4; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
621 622
void av1_iht8x16_128_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                           int tx_type) {
623
  static const transform_2d IHT_8x16[] = {
Luca Barbato's avatar
Luca Barbato committed
624 625 626 627
    { aom_idct16_c, aom_idct8_c },    // DCT_DCT
    { aom_iadst16_c, aom_idct8_c },   // ADST_DCT
    { aom_idct16_c, aom_iadst8_c },   // DCT_ADST
    { aom_iadst16_c, aom_iadst8_c },  // ADST_ADST
628
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
629 630 631 632 633 634 635 636 637 638 639 640
    { aom_iadst16_c, aom_idct8_c },   // FLIPADST_DCT
    { aom_idct16_c, aom_iadst8_c },   // DCT_FLIPADST
    { aom_iadst16_c, aom_iadst8_c },  // FLIPADST_FLIPADST
    { aom_iadst16_c, aom_iadst8_c },  // ADST_FLIPADST
    { aom_iadst16_c, aom_iadst8_c },  // FLIPADST_ADST
    { iidtx16_c, iidtx8_c },          // IDTX
    { aom_idct16_c, iidtx8_c },       // V_DCT
    { iidtx16_c, aom_idct8_c },       // H_DCT
    { aom_iadst16_c, iidtx8_c },      // V_ADST
    { iidtx16_c, aom_iadst8_c },      // H_ADST
    { aom_iadst16_c, iidtx8_c },      // V_FLIPADST
    { iidtx16_c, aom_iadst8_c },      // H_FLIPADST
641
#endif
642 643 644 645 646
  };

  const int n = 8;
  const int n2 = 16;
  int i, j;
647
  tran_low_t out[8][16], tmp[8][16], outtmp[8];
648 649 650 651 652 653 654
  tran_low_t *outp = &out[0][0];
  int outstride = n2;

  // inverse transform row vectors and transpose
  for (i = 0; i < n2; ++i) {
    IHT_8x16[tx_type].rows(input, outtmp);
    for (j = 0; j < n; ++j)
655
      tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
clang-format's avatar
clang-format committed
656
    input += n;
657 658 659 660
  }

  // inverse transform column vectors
  for (i = 0; i < n; ++i) {
661
    IHT_8x16[tx_type].cols(tmp[i], out[i]);
662 663
  }

664
#if CONFIG_EXT_TX
665
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n2, n);
666
#endif
667 668 669 670 671 672 673 674 675 676 677

  // Sum with the destination
  for (i = 0; i < n2; ++i) {
    for (j = 0; j < n; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
678 679
void av1_iht16x8_128_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                           int tx_type) {
680
  static const transform_2d IHT_16x8[] = {
Luca Barbato's avatar
Luca Barbato committed
681 682 683 684
    { aom_idct8_c, aom_idct16_c },    // DCT_DCT
    { aom_iadst8_c, aom_idct16_c },   // ADST_DCT
    { aom_idct8_c, aom_iadst16_c },   // DCT_ADST
    { aom_iadst8_c, aom_iadst16_c },  // ADST_ADST
685
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
686 687 688 689 690 691 692 693 694 695 696 697
    { aom_iadst8_c, aom_idct16_c },   // FLIPADST_DCT
    { aom_idct8_c, aom_iadst16_c },   // DCT_FLIPADST
    { aom_iadst8_c, aom_iadst16_c },  // FLIPADST_FLIPADST
    { aom_iadst8_c, aom_iadst16_c },  // ADST_FLIPADST
    { aom_iadst8_c, aom_iadst16_c },  // FLIPADST_ADST
    { iidtx8_c, iidtx16_c },          // IDTX
    { aom_idct8_c, iidtx16_c },       // V_DCT
    { iidtx8_c, aom_idct16_c },       // H_DCT
    { aom_iadst8_c, iidtx16_c },      // V_ADST
    { iidtx8_c, aom_iadst16_c },      // H_ADST
    { aom_iadst8_c, iidtx16_c },      // V_FLIPADST
    { iidtx8_c, aom_iadst16_c },      // H_FLIPADST
698
#endif
699 700 701 702 703
  };
  const int n = 8;
  const int n2 = 16;

  int i, j;
704
  tran_low_t out[16][8], tmp[16][8], outtmp[16];
705 706 707 708 709 710 711
  tran_low_t *outp = &out[0][0];
  int outstride = n;

  // inverse transform row vectors and transpose
  for (i = 0; i < n; ++i) {
    IHT_16x8[tx_type].rows(input, outtmp);
    for (j = 0; j < n2; ++j)
712
      tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
clang-format's avatar
clang-format committed
713
    input += n2;
714 715 716 717
  }

  // inverse transform column vectors
  for (i = 0; i < n2; ++i) {
718
    IHT_16x8[tx_type].cols(tmp[i], out[i]);
719 720
  }

721
#if CONFIG_EXT_TX
722
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n2);
723
#endif
724 725 726 727 728 729 730 731 732 733 734

  // Sum with the destination
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n2; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}

735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
void av1_iht8x32_256_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                           int tx_type) {
  static const transform_2d IHT_8x32[] = {
    { aom_idct32_c, aom_idct8_c },     // DCT_DCT
    { ihalfright32_c, aom_idct8_c },   // ADST_DCT
    { aom_idct32_c, aom_iadst8_c },    // DCT_ADST
    { ihalfright32_c, aom_iadst8_c },  // ADST_ADST
#if CONFIG_EXT_TX
    { ihalfright32_c, aom_idct8_c },   // FLIPADST_DCT
    { aom_idct32_c, aom_iadst8_c },    // DCT_FLIPADST
    { ihalfright32_c, aom_iadst8_c },  // FLIPADST_FLIPADST
    { ihalfright32_c, aom_iadst8_c },  // ADST_FLIPADST
    { ihalfright32_c, aom_iadst8_c },  // FLIPADST_ADST
    { iidtx32_c, iidtx8_c },           // IDTX
    { aom_idct32_c, iidtx8_c },        // V_DCT
    { iidtx32_c, aom_idct8_c },        // H_DCT
    { ihalfright32_c, iidtx8_c },      // V_ADST
    { iidtx32_c, aom_iadst8_c },       // H_ADST
    { ihalfright32_c, iidtx8_c },      // V_FLIPADST
    { iidtx32_c, aom_iadst8_c },       // H_FLIPADST
#endif
  };

  const int n = 8;
  const int n4 = 32;
  int i, j;
761
  tran_low_t out[8][32], tmp[8][32], outtmp[8];
762 763 764 765 766 767
  tran_low_t *outp = &out[0][0];
  int outstride = n4;

  // inverse transform row vectors and transpose
  for (i = 0; i < n4; ++i) {
    IHT_8x32[tx_type].rows(input, outtmp);
768
    for (j = 0; j < n; ++j) tmp[j][i] = outtmp[j];
769 770 771 772
    input += n;
  }

  // inverse transform column vectors
773
  for (i = 0; i < n; ++i) IHT_8x32[tx_type].cols(tmp[i], out[i]);
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814

#if CONFIG_EXT_TX
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n4, n);
#endif

  // Sum with the destination
  for (i = 0; i < n4; ++i) {
    for (j = 0; j < n; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}

void av1_iht32x8_256_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                           int tx_type) {
  static const transform_2d IHT_32x8[] = {
    { aom_idct8_c, aom_idct32_c },     // DCT_DCT
    { aom_iadst8_c, aom_idct32_c },    // ADST_DCT
    { aom_idct8_c, ihalfright32_c },   // DCT_ADST
    { aom_iadst8_c, ihalfright32_c },  // ADST_ADST
#if CONFIG_EXT_TX
    { aom_iadst8_c, aom_idct32_c },    // FLIPADST_DCT
    { aom_idct8_c, ihalfright32_c },   // DCT_FLIPADST
    { aom_iadst8_c, ihalfright32_c },  // FLIPADST_FLIPADST
    { aom_iadst8_c, ihalfright32_c },  // ADST_FLIPADST
    { aom_iadst8_c, ihalfright32_c },  // FLIPADST_ADST
    { iidtx8_c, iidtx32_c },           // IDTX
    { aom_idct8_c, iidtx32_c },        // V_DCT
    { iidtx8_c, aom_idct32_c },        // H_DCT
    { aom_iadst8_c, iidtx32_c },       // V_ADST
    { iidtx8_c, ihalfright32_c },      // H_ADST
    { aom_iadst8_c, iidtx32_c },       // V_FLIPADST
    { iidtx8_c, ihalfright32_c },      // H_FLIPADST
#endif
  };
  const int n = 8;
  const int n4 = 32;

  int i, j;
815
  tran_low_t out[32][8], tmp[32][8], outtmp[32];
816 817 818 819 820 821
  tran_low_t *outp = &out[0][0];
  int outstride = n;

  // inverse transform row vectors and transpose
  for (i = 0; i < n; ++i) {
    IHT_32x8[tx_type].rows(input, outtmp);
822
    for (j = 0; j < n4; ++j) tmp[j][i] = outtmp[j];
823 824 825 826
    input += n4;
  }

  // inverse transform column vectors
827
  for (i = 0; i < n4; ++i) IHT_32x8[tx_type].cols(tmp[i], out[i]);
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842

#if CONFIG_EXT_TX
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n4);
#endif

  // Sum with the destination
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n4; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
843 844
void av1_iht16x32_512_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                            int tx_type) {
845
  static const transform_2d IHT_16x32[] = {
Luca Barbato's avatar
Luca Barbato committed
846 847 848 849
    { aom_idct32_c, aom_idct16_c },     // DCT_DCT
    { ihalfright32_c, aom_idct16_c },   // ADST_DCT
    { aom_idct32_c, aom_iadst16_c },    // DCT_ADST
    { ihalfright32_c, aom_iadst16_c },  // ADST_ADST
850
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
851 852 853 854 855 856 857 858 859 860 861 862
    { ihalfright32_c, aom_idct16_c },   // FLIPADST_DCT
    { aom_idct32_c, aom_iadst16_c },    // DCT_FLIPADST
    { ihalfright32_c, aom_iadst16_c },  // FLIPADST_FLIPADST
    { ihalfright32_c, aom_iadst16_c },  // ADST_FLIPADST
    { ihalfright32_c, aom_iadst16_c },  // FLIPADST_ADST
    { iidtx32_c, iidtx16_c },           // IDTX
    { aom_idct32_c, iidtx16_c },        // V_DCT
    { iidtx32_c, aom_idct16_c },        // H_DCT
    { ihalfright32_c, iidtx16_c },      // V_ADST
    { iidtx32_c, aom_iadst16_c },       // H_ADST
    { ihalfright32_c, iidtx16_c },      // V_FLIPADST
    { iidtx32_c, aom_iadst16_c },       // H_FLIPADST
863
#endif
864 865 866 867 868
  };

  const int n = 16;
  const int n2 = 32;
  int i, j;
869
  tran_low_t out[16][32], tmp[16][32], outtmp[16];
870 871 872 873 874 875 876
  tran_low_t *outp = &out[0][0];
  int outstride = n2;

  // inverse transform row vectors and transpose
  for (i = 0; i < n2; ++i) {
    IHT_16x32[tx_type].rows(input, outtmp);
    for (j = 0; j < n; ++j)
877
      tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
clang-format's avatar
clang-format committed
878
    input += n;
879 880 881 882
  }

  // inverse transform column vectors
  for (i = 0; i < n; ++i) {
883
    IHT_16x32[tx_type].cols(tmp[i], out[i]);
884 885
  }

886
#if CONFIG_EXT_TX
887
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n2, n);
888
#endif
889 890 891 892 893 894 895 896 897 898 899

  // Sum with the destination
  for (i = 0; i < n2; ++i) {
    for (j = 0; j < n; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
900 901
void av1_iht32x16_512_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                            int tx_type) {
902
  static const transform_2d IHT_32x16[] = {
Luca Barbato's avatar
Luca Barbato committed
903 904 905 906
    { aom_idct16_c, aom_idct32_c },     // DCT_DCT
    { aom_iadst16_c, aom_idct32_c },    // ADST_DCT
    { aom_idct16_c, ihalfright32_c },   // DCT_ADST
    { aom_iadst16_c, ihalfright32_c },  // ADST_ADST
907
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
908 909 910 911 912 913 914 915 916 917 918 919
    { aom_iadst16_c, aom_idct32_c },    // FLIPADST_DCT
    { aom_idct16_c, ihalfright32_c },   // DCT_FLIPADST
    { aom_iadst16_c, ihalfright32_c },  // FLIPADST_FLIPADST
    { aom_iadst16_c, ihalfright32_c },  // ADST_FLIPADST
    { aom_iadst16_c, ihalfright32_c },  // FLIPADST_ADST
    { iidtx16_c, iidtx32_c },           // IDTX
    { aom_idct16_c, iidtx32_c },        // V_DCT
    { iidtx16_c, aom_idct32_c },        // H_DCT
    { aom_iadst16_c, iidtx32_c },       // V_ADST
    { iidtx16_c, ihalfright32_c },      // H_ADST
    { aom_iadst16_c, iidtx32_c },       // V_FLIPADST
    { iidtx16_c, ihalfright32_c },      // H_FLIPADST
920
#endif
921 922 923 924 925
  };
  const int n = 16;
  const int n2 = 32;

  int i, j;
926
  tran_low_t out[32][16], tmp[32][16], outtmp[32];
927 928 929 930 931 932 933
  tran_low_t *outp = &out[0][0];
  int outstride = n;

  // inverse transform row vectors and transpose
  for (i = 0; i < n; ++i) {
    IHT_32x16[tx_type].rows(input, outtmp);
    for (j = 0; j < n2; ++j)
934
      tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
clang-format's avatar
clang-format committed
935
    input += n2;
936 937 938 939
  }

  // inverse transform column vectors
  for (i = 0; i < n2; ++i) {
940
    IHT_32x16[tx_type].cols(tmp[i], out[i]);
941 942
  }

943
#if CONFIG_EXT_TX
944
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n2);
945
#endif
946 947 948 949 950 951 952 953 954 955 956

  // Sum with the destination
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n2; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
957 958
void av1_iht8x8_64_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                         int tx_type) {
959
  static const transform_2d IHT_8[] = {
Luca Barbato's avatar
Luca Barbato committed
960 961 962 963
    { aom_idct8_c, aom_idct8_c },    // DCT_DCT  = 0
    { aom_iadst8_c, aom_idct8_c },   // ADST_DCT = 1
    { aom_idct8_c, aom_iadst8_c },   // DCT_ADST = 2
    { aom_iadst8_c, aom_iadst8_c },  // ADST_ADST = 3
964
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
965 966 967 968 969 970 971 972 973 974 975 976 977
    { aom_iadst8_c, aom_idct8_c },   // FLIPADST_DCT
    { aom_idct8_c, aom_iadst8_c },   // DCT_FLIPADST
    { aom_iadst8_c, aom_iadst8_c },  // FLIPADST_FLIPADST
    { aom_iadst8_c, aom_iadst8_c },  // ADST_FLIPADST
    { aom_iadst8_c, aom_iadst8_c },  // FLIPADST_ADST
    { iidtx8_c, iidtx8_c },          // IDTX
    { aom_idct8_c, iidtx8_c },       // V_DCT
    { iidtx8_c, aom_idct8_c },       // H_DCT
    { aom_iadst8_c, iidtx8_c },      // V_ADST
    { iidtx8_c, aom_iadst8_c },      // H_ADST
    { aom_iadst8_c, iidtx8_c },      // V_FLIPADST
    { iidtx8_c, aom_iadst8_c },      // H_FLIPADST
#endif                               // CONFIG_EXT_TX
978 979
  };

Jingning Han's avatar
Jingning Han committed
980
  int i, j;
981
  tran_low_t tmp[8][8];
982 983 984
  tran_low_t out[8][8];
  tran_low_t *outp = &out[0][0];
  int outstride = 8;
Jingning Han's avatar
Jingning Han committed
985 986 987

  // inverse transform row vectors
  for (i = 0; i < 8; ++i) {
988
    IHT_8[tx_type].rows(input, out[i]);
clang-format's avatar
clang-format committed
989
    input += 8;
990 991 992
  }

  // transpose
993 994 995
  for (i = 0; i < 8; i++) {
    for (j = 0; j < 8; j++) {
      tmp[j][i] = out[i][j];
996
    }
Jingning Han's avatar
Jingning Han committed
997 998 999 1000
  }

  // inverse transform column vectors
  for (i = 0; i < 8; ++i) {
1001
    IHT_8[tx_type].cols(tmp[i], out[i]);
1002 1003 1004
  }

#if CONFIG_EXT_TX
1005
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 8, 8);
1006 1007 1008 1009
#endif

  // Sum with the destination
  for (i = 0; i < 8; ++i) {
Jingning Han's avatar
Jingning Han committed
1010
    for (j = 0; j < 8; ++j) {
1011 1012 1013
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
Jingning Han's avatar
Jingning Han committed
1014 1015 1016 1017
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
1018 1019
void av1_iht16x16_256_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                            int tx_type) {
1020
  static const transform_2d IHT_16[] = {
Luca Barbato's avatar
Luca Barbato committed
1021 1022 1023 1024
    { aom_idct16_c, aom_idct16_c },    // DCT_DCT  = 0
    { aom_iadst16_c, aom_idct16_c },   // ADST_DCT = 1
    { aom_idct16_c, aom_iadst16_c },   // DCT_ADST = 2
    { aom_iadst16_c, aom_iadst16_c },  // ADST_ADST = 3
1025
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
    { aom_iadst16_c, aom_idct16_c },   // FLIPADST_DCT
    { aom_idct16_c, aom_iadst16_c },   // DCT_FLIPADST
    { aom_iadst16_c, aom_iadst16_c },  // FLIPADST_FLIPADST
    { aom_iadst16_c, aom_iadst16_c },  // ADST_FLIPADST
    { aom_iadst16_c, aom_iadst16_c },  // FLIPADST_ADST
    { iidtx16_c, iidtx16_c },          // IDTX
    { aom_idct16_c, iidtx16_c },       // V_DCT
    { iidtx16_c, aom_idct16_c },       // H_DCT
    { aom_iadst16_c, iidtx16_c },      // V_ADST
    { iidtx16_c, aom_iadst16_c },      // H_ADST
    { aom_iadst16_c, iidtx16_c },      // V_FLIPADST
    { iidtx16_c, aom_iadst16_c },      // H_FLIPADST
#endif                                 // CONFIG_EXT_TX
1039
  };
1040

Jingning Han's avatar
Jingning Han committed
1041
  int i, j;
1042
  tran_low_t tmp[16][16];
1043 1044 1045 1046 1047 1048 1049
  tran_low_t out[16][16];
  tran_low_t *outp = &out[0][0];
  int outstride = 16;

  // inverse transform row vectors
  for (i = 0; i < 16; ++i) {
    IHT_16[tx_type].rows(input, out[i]);
clang-format's avatar
clang-format committed
1050
    input += 16;
1051 1052 1053
  }

  // transpose
1054 1055 1056
  for (i = 0; i < 16; i++) {
    for (j = 0; j < 16; j++) {
      tmp[j][i] = out[i][j];
1057 1058
    }
  }
Jingning Han's avatar
Jingning Han committed
1059

1060
  // inverse transform column vectors
Jingning Han's avatar
Jingning Han committed
1061
  for (i = 0; i < 16; ++i) {
1062
    IHT_16[tx_type].cols(tmp[i], out[i]);
Jingning Han's avatar
Jingning Han committed
1063 1064
  }

1065
#if CONFIG_EXT_TX
1066
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 16, 16);
1067 1068 1069
#endif

  // Sum with the destination
Jingning Han's avatar
Jingning Han committed
1070 1071
  for (i = 0; i < 16; ++i) {
    for (j = 0; j < 16; ++j) {
1072 1073 1074
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
Jingning Han's avatar
Jingning Han committed
1075 1076 1077 1078
    }
  }
}

1079
#if CONFIG_EXT_TX
Yaowu Xu's avatar
Yaowu Xu committed
1080 1081
void av1_iht32x32_1024_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                             int tx_type) {
1082
  static const transform_2d IHT_32[] = {
Luca Barbato's avatar
Luca Barbato committed
1083 1084 1085
    { aom_idct32_c, aom_idct32_c },      // DCT_DCT
    { ihalfright32_c, aom_idct32_c },    // ADST_DCT
    { aom_idct32_c, ihalfright32_c },    // DCT_ADST
clang-format's avatar
clang-format committed
1086
    { ihalfright32_c, ihalfright32_c },  // ADST_ADST
Luca Barbato's avatar
Luca Barbato committed
1087 1088
    { ihalfright32_c, aom_idct32_c },    // FLIPADST_DCT
    { aom_idct32_c, ihalfright32_c },    // DCT_FLIPADST
clang-format's avatar
clang-format committed
1089 1090 1091 1092
    { ihalfright32_c, ihalfright32_c },  // FLIPADST_FLIPADST
    { ihalfright32_c, ihalfright32_c },  // ADST_FLIPADST
    { ihalfright32_c, ihalfright32_c },  // FLIPADST_ADST
    { iidtx32_c, iidtx32_c },            // IDTX
Luca Barbato's avatar
Luca Barbato committed
1093 1094
    { aom_idct32_c, iidtx32_c },         // V_DCT
    { iidtx32_c, aom_idct32_c },         // H_DCT
1095 1096 1097 1098
    { ihalfright32_c, iidtx32_c },       // V_ADST
    { iidtx32_c, ihalfright32_c },       // H_ADST
    { ihalfright32_c, iidtx32_c },       // V_FLIPADST
    { iidtx32_c, ihalfright32_c },       // H_FLIPADST
1099 1100 1101
  };

  int i, j;
1102
  tran_low_t tmp[32][32];
1103 1104 1105 1106 1107 1108 1109
  tran_low_t out[32][32];
  tran_low_t *outp = &out[0][0];
  int outstride = 32;

  // inverse transform row vectors
  for (i = 0; i < 32; ++i) {
    IHT_32[tx_type].rows(input, out[i]);
clang-format's avatar
clang-format committed
1110
    input += 32;
1111 1112 1113
  }

  // transpose
1114 1115 1116
  for (i = 0; i < 32; i++) {
    for (j = 0; j < 32; j++) {
      tmp[j][i] = out[i][j];
1117 1118 1119 1120 1121
    }
  }

  // inverse transform column vectors
  for (i = 0; i < 32; ++i) {
1122
    IHT_32[tx_type].cols(tmp[i], out[i]);
1123 1124
  }

1125
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 32, 32);
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135

  // Sum with the destination
  for (i = 0; i < 32; ++i) {
    for (j = 0; j < 32; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}
1136
#endif  // CONFIG_EXT_TX
1137 1138 1139 1140 1141 1142 1143 1144 1145

#if CONFIG_TX64X64
void av1_iht64x64_4096_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                             int tx_type) {
  static const transform_2d IHT_64[] = {
    { idct64_col_c, idct64_row_c },      // DCT_DCT
    { ihalfright64_c, idct64_row_c },    // ADST_DCT
    { idct64_col_c, ihalfright64_c },    // DCT_ADST
    { ihalfright64_c, ihalfright64_c },  // ADST_ADST
1146
#if CONFIG_EXT_TX
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
    { ihalfright64_c, idct64_row_c },    // FLIPADST_DCT
    { idct64_col_c, ihalfright64_c },    // DCT_FLIPADST
    { ihalfright64_c, ihalfright64_c },  // FLIPADST_FLIPADST
    { ihalfright64_c, ihalfright64_c },  // ADST_FLIPADST
    { ihalfright64_c, ihalfright64_c },  // FLIPADST_ADST
    { iidtx64_c, iidtx64_c },            // IDTX
    { idct64_col_c, iidtx64_c },         // V_DCT
    { iidtx64_c, idct64_row_c },         // H_DCT
    { ihalfright64_c, iidtx64_c },       // V_ADST
    { iidtx64_c, ihalfright64_c },       // H_ADST
    { ihalfright64_c, iidtx64_c },       // V_FLIPADST
    { iidtx64_c, ihalfright64_c },       // H_FLIPADST