blob: de6e05b3bc21d7857face1554f6e53d64b8e0fc4 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
12#include <math.h>
13
Yaowu Xuf883b422016-08-30 14:01:10 -070014#include "./aom_dsp_rtcd.h"
Geza Lorea1ddae52016-09-02 09:51:34 +010015#include "./av1_rtcd.h"
16#include "aom_dsp/inv_txfm.h"
17#include "aom_ports/mem.h"
Sarah Parkereec47e62017-05-15 20:49:22 -070018#include "av1/common/av1_inv_txfm1d_cfg.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070019#include "av1/common/blockd.h"
20#include "av1/common/enums.h"
21#include "av1/common/idct.h"
Nathan E. Eggee554f362017-10-04 14:44:38 -040022#if CONFIG_DAALA_TX4 || CONFIG_DAALA_TX8 || CONFIG_DAALA_TX16 || \
23 CONFIG_DAALA_TX32 || CONFIG_DAALA_TX64
Nathan E. Egge5e6bda82017-09-16 10:13:51 -040024#include "av1/common/daala_tx.h"
25#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070026
Jingning Hanff705452017-04-27 11:32:15 -070027int av1_get_tx_scale(const TX_SIZE tx_size) {
Yue Chenaa0d90f2017-08-24 17:56:24 -070028 const int pels = tx_size_2d[tx_size];
29 return (pels > 256) + (pels > 1024) + (pels > 4096);
Yaowu Xuc27fc142016-08-22 16:08:15 -070030}
31
Debargha Mukherjeee52816b2016-10-12 10:49:29 -070032// NOTE: The implementation of all inverses need to be aware of the fact
33// that input and output could be the same buffer.
34
Yaowu Xuc27fc142016-08-22 16:08:15 -070035#if CONFIG_EXT_TX
36static void iidtx4_c(const tran_low_t *input, tran_low_t *output) {
37 int i;
Monty Montgomery02078a32017-07-11 21:22:29 -040038 for (i = 0; i < 4; ++i) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070039 output[i] = (tran_low_t)dct_const_round_shift(input[i] * Sqrt2);
Monty Montgomery02078a32017-07-11 21:22:29 -040040 }
Yaowu Xuc27fc142016-08-22 16:08:15 -070041}
42
43static void iidtx8_c(const tran_low_t *input, tran_low_t *output) {
44 int i;
Monty Montgomerycf18fe42017-07-11 21:33:25 -040045 for (i = 0; i < 8; ++i) {
Monty Montgomerycf18fe42017-07-11 21:33:25 -040046 output[i] = input[i] * 2;
Monty Montgomerycf18fe42017-07-11 21:33:25 -040047 }
Yaowu Xuc27fc142016-08-22 16:08:15 -070048}
49
50static void iidtx16_c(const tran_low_t *input, tran_low_t *output) {
51 int i;
Monty Montgomerycb9c1c52017-07-17 18:15:30 -040052 for (i = 0; i < 16; ++i) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070053 output[i] = (tran_low_t)dct_const_round_shift(input[i] * 2 * Sqrt2);
Monty Montgomerycb9c1c52017-07-17 18:15:30 -040054 }
Yaowu Xuc27fc142016-08-22 16:08:15 -070055}
56
57static void iidtx32_c(const tran_low_t *input, tran_low_t *output) {
58 int i;
Monty Montgomery2cb52ba2017-07-17 18:27:27 -040059 for (i = 0; i < 32; ++i) {
Monty Montgomery2cb52ba2017-07-17 18:27:27 -040060 output[i] = input[i] * 4;
Monty Montgomery2cb52ba2017-07-17 18:27:27 -040061 }
Yaowu Xuc27fc142016-08-22 16:08:15 -070062}
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -070063
Nathan E. Eggee554f362017-10-04 14:44:38 -040064#if CONFIG_TX64X64 && !CONFIG_DAALA_TX64
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -070065static void iidtx64_c(const tran_low_t *input, tran_low_t *output) {
66 int i;
Monty Montgomerya4e245a2017-07-22 00:48:31 -040067 for (i = 0; i < 64; ++i) {
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -070068 output[i] = (tran_low_t)dct_const_round_shift(input[i] * 4 * Sqrt2);
Monty Montgomerya4e245a2017-07-22 00:48:31 -040069 }
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -070070}
71#endif // CONFIG_TX64X64
Jingning Hanec419e02016-11-01 18:19:30 -070072#endif // CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -070073
Debargha Mukherjeee52816b2016-10-12 10:49:29 -070074// For use in lieu of ADST
Yaowu Xuc27fc142016-08-22 16:08:15 -070075static void ihalfright32_c(const tran_low_t *input, tran_low_t *output) {
76 int i;
77 tran_low_t inputhalf[16];
Yaowu Xuc27fc142016-08-22 16:08:15 -070078 // Multiply input by sqrt(2)
79 for (i = 0; i < 16; ++i) {
80 inputhalf[i] = (tran_low_t)dct_const_round_shift(input[i] * Sqrt2);
81 }
Debargha Mukherjeee52816b2016-10-12 10:49:29 -070082 for (i = 0; i < 16; ++i) {
83 output[i] = input[16 + i] * 4;
84 }
Luca Barbatof0f98572016-09-03 12:14:15 +020085 aom_idct16_c(inputhalf, output + 16);
Yaowu Xuc27fc142016-08-22 16:08:15 -070086 // Note overall scaling factor is 4 times orthogonal
87}
88
Nathan E. Eggee554f362017-10-04 14:44:38 -040089#if CONFIG_TX64X64 && !CONFIG_DAALA_TX64
Debargha Mukherjee67d13472016-11-01 14:37:39 -070090static void idct64_col_c(const tran_low_t *input, tran_low_t *output) {
91 int32_t in[64], out[64];
92 int i;
93 for (i = 0; i < 64; ++i) in[i] = (int32_t)input[i];
Sarah Parkereec47e62017-05-15 20:49:22 -070094 av1_idct64_new(in, out, inv_cos_bit_col_dct_64, inv_stage_range_col_dct_64);
Debargha Mukherjee67d13472016-11-01 14:37:39 -070095 for (i = 0; i < 64; ++i) output[i] = (tran_low_t)out[i];
96}
97
98static void idct64_row_c(const tran_low_t *input, tran_low_t *output) {
99 int32_t in[64], out[64];
100 int i;
101 for (i = 0; i < 64; ++i) in[i] = (int32_t)input[i];
Sarah Parkereec47e62017-05-15 20:49:22 -0700102 av1_idct64_new(in, out, inv_cos_bit_row_dct_64, inv_stage_range_row_dct_64);
Debargha Mukherjee67d13472016-11-01 14:37:39 -0700103 for (i = 0; i < 64; ++i) output[i] = (tran_low_t)out[i];
104}
105
Debargha Mukherjee67d13472016-11-01 14:37:39 -0700106// For use in lieu of ADST
107static void ihalfright64_c(const tran_low_t *input, tran_low_t *output) {
108 int i;
109 tran_low_t inputhalf[32];
110 // Multiply input by sqrt(2)
111 for (i = 0; i < 32; ++i) {
112 inputhalf[i] = (tran_low_t)dct_const_round_shift(input[i] * Sqrt2);
113 }
114 for (i = 0; i < 32; ++i) {
115 output[i] = (tran_low_t)dct_const_round_shift(input[32 + i] * 4 * Sqrt2);
116 }
117 aom_idct32_c(inputhalf, output + 32);
118 // Note overall scaling factor is 4 * sqrt(2) times orthogonal
119}
120#endif // CONFIG_TX64X64
121
Yaowu Xuc27fc142016-08-22 16:08:15 -0700122// Inverse identity transform and add.
Jingning Hanec419e02016-11-01 18:19:30 -0700123#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -0700124static void inv_idtx_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Urvang Joshi2283d372017-10-02 17:16:45 -0700125 int bsx, int bsy, TX_TYPE tx_type) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700126 int r, c;
Debargha Mukherjee2b435012017-09-28 08:30:35 -0700127 const int pels = bsx * bsy;
128 const int shift = 3 - ((pels > 256) + (pels > 1024));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700129 if (tx_type == IDTX) {
Debargha Mukherjee2b435012017-09-28 08:30:35 -0700130 for (r = 0; r < bsy; ++r) {
131 for (c = 0; c < bsx; ++c)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700132 dest[c] = clip_pixel_add(dest[c], input[c] >> shift);
133 dest += stride;
Debargha Mukherjee2b435012017-09-28 08:30:35 -0700134 input += bsx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700135 }
136 }
137}
Jingning Hanec419e02016-11-01 18:19:30 -0700138#endif // CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -0700139
140#define FLIPUD_PTR(dest, stride, size) \
141 do { \
142 (dest) = (dest) + ((size)-1) * (stride); \
143 (stride) = -(stride); \
144 } while (0)
145
Jingning Hanec419e02016-11-01 18:19:30 -0700146#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -0700147static void maybe_flip_strides(uint8_t **dst, int *dstride, tran_low_t **src,
Urvang Joshi2283d372017-10-02 17:16:45 -0700148 int *sstride, TX_TYPE tx_type, int sizey,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700149 int sizex) {
150 // Note that the transpose of src will be added to dst. In order to LR
151 // flip the addends (in dst coordinates), we UD flip the src. To UD flip
152 // the addends, we UD flip the dst.
153 switch (tx_type) {
154 case DCT_DCT:
155 case ADST_DCT:
156 case DCT_ADST:
157 case ADST_ADST:
158 case IDTX:
159 case V_DCT:
160 case H_DCT:
161 case V_ADST:
162 case H_ADST: break;
163 case FLIPADST_DCT:
164 case FLIPADST_ADST:
165 case V_FLIPADST:
166 // flip UD
167 FLIPUD_PTR(*dst, *dstride, sizey);
168 break;
169 case DCT_FLIPADST:
170 case ADST_FLIPADST:
171 case H_FLIPADST:
172 // flip LR
173 FLIPUD_PTR(*src, *sstride, sizex);
174 break;
175 case FLIPADST_FLIPADST:
176 // flip UD
177 FLIPUD_PTR(*dst, *dstride, sizey);
178 // flip LR
179 FLIPUD_PTR(*src, *sstride, sizex);
180 break;
181 default: assert(0); break;
182 }
183}
Jingning Hanec419e02016-11-01 18:19:30 -0700184#endif // CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -0700185
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200186#if CONFIG_HIGHBITDEPTH
Sarah Parker31c66502017-05-19 16:51:07 -0700187#if CONFIG_EXT_TX && CONFIG_TX64X64
Yaowu Xuc27fc142016-08-22 16:08:15 -0700188static void highbd_inv_idtx_add_c(const tran_low_t *input, uint8_t *dest8,
Urvang Joshi2283d372017-10-02 17:16:45 -0700189 int stride, int bsx, int bsy, TX_TYPE tx_type,
Debargha Mukherjee2b435012017-09-28 08:30:35 -0700190 int bd) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700191 int r, c;
Debargha Mukherjee2b435012017-09-28 08:30:35 -0700192 const int pels = bsx * bsy;
193 const int shift = 3 - ((pels > 256) + (pels > 1024));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700194 uint16_t *dest = CONVERT_TO_SHORTPTR(dest8);
195
196 if (tx_type == IDTX) {
Debargha Mukherjee2b435012017-09-28 08:30:35 -0700197 for (r = 0; r < bsy; ++r) {
198 for (c = 0; c < bsx; ++c)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700199 dest[c] = highbd_clip_pixel_add(dest[c], input[c] >> shift, bd);
200 dest += stride;
Debargha Mukherjee2b435012017-09-28 08:30:35 -0700201 input += bsx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700202 }
203 }
204}
Sarah Parker31c66502017-05-19 16:51:07 -0700205#endif // CONFIG_EXT_TX && CONFIG_TX64X64
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200206#endif // CONFIG_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -0700207
Lester Lu432012f2017-08-17 14:39:29 -0700208#if CONFIG_LGT || CONFIG_LGT_FROM_PRED
Lester Lu708c1ec2017-06-14 14:54:49 -0700209void ilgt4(const tran_low_t *input, tran_low_t *output,
210 const tran_high_t *lgtmtx) {
Lester Lu918fe692017-08-17 14:39:29 -0700211 if (!lgtmtx) assert(0);
Lester Lu432012f2017-08-17 14:39:29 -0700212#if CONFIG_LGT_FROM_PRED
213 // For DCT/ADST, use butterfly implementations
214 if (lgtmtx[0] == DCT4) {
215 aom_idct4_c(input, output);
216 return;
217 } else if (lgtmtx[0] == ADST4) {
218 aom_iadst4_c(input, output);
219 return;
220 }
221#endif // CONFIG_LGT_FROM_PRED
222
Lester Lu918fe692017-08-17 14:39:29 -0700223 // evaluate s[j] = sum of all lgtmtx[j]*input[i] over i=1,...,4
Lester Lu708c1ec2017-06-14 14:54:49 -0700224 tran_high_t s[4] = { 0 };
225 for (int i = 0; i < 4; ++i)
226 for (int j = 0; j < 4; ++j) s[j] += lgtmtx[i * 4 + j] * input[i];
227
228 for (int i = 0; i < 4; ++i) output[i] = WRAPLOW(dct_const_round_shift(s[i]));
229}
230
231void ilgt8(const tran_low_t *input, tran_low_t *output,
232 const tran_high_t *lgtmtx) {
Lester Lu918fe692017-08-17 14:39:29 -0700233 if (!lgtmtx) assert(0);
Lester Lu432012f2017-08-17 14:39:29 -0700234#if CONFIG_LGT_FROM_PRED
235 // For DCT/ADST, use butterfly implementations
236 if (lgtmtx[0] == DCT8) {
237 aom_idct8_c(input, output);
238 return;
239 } else if (lgtmtx[0] == ADST8) {
240 aom_iadst8_c(input, output);
241 return;
242 }
243#endif // CONFIG_LGT_FROM_PRED
244
Lester Lu918fe692017-08-17 14:39:29 -0700245 // evaluate s[j] = sum of all lgtmtx[j]*input[i] over i=1,...,8
Lester Lu708c1ec2017-06-14 14:54:49 -0700246 tran_high_t s[8] = { 0 };
247 for (int i = 0; i < 8; ++i)
248 for (int j = 0; j < 8; ++j) s[j] += lgtmtx[i * 8 + j] * input[i];
249
250 for (int i = 0; i < 8; ++i) output[i] = WRAPLOW(dct_const_round_shift(s[i]));
251}
Lester Lu432012f2017-08-17 14:39:29 -0700252#endif // CONFIG_LGT || CONFIG_LGT_FROM_PRED
Lester Lu708c1ec2017-06-14 14:54:49 -0700253
Lester Lu432012f2017-08-17 14:39:29 -0700254#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -0700255// get_lgt4 and get_lgt8 return 1 and pick a lgt matrix if LGT is chosen to
256// apply. Otherwise they return 0
257int get_lgt4(const TxfmParam *txfm_param, int is_col,
258 const tran_high_t **lgtmtx) {
Sarah Parker90024e42017-10-06 16:50:47 -0700259#if CONFIG_EXT_TX
260 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
261#endif // CONFIG_EXT_TX
Lester Lu918fe692017-08-17 14:39:29 -0700262 if (is_col && (vtx_tab[txfm_param->tx_type] == ADST_1D ||
263 vtx_tab[txfm_param->tx_type] == FLIPADST_1D)) {
264 lgtmtx[0] = txfm_param->is_inter ? &lgt4_170[0][0] : &lgt4_140[0][0];
265 return 1;
266 } else if (!is_col && (htx_tab[txfm_param->tx_type] == ADST_1D ||
267 htx_tab[txfm_param->tx_type] == FLIPADST_1D)) {
268 lgtmtx[0] = txfm_param->is_inter ? &lgt4_170[0][0] : &lgt4_140[0][0];
Lester Lu708c1ec2017-06-14 14:54:49 -0700269 return 1;
270 }
Lester Lu918fe692017-08-17 14:39:29 -0700271 lgtmtx[0] = NULL;
Lester Lu708c1ec2017-06-14 14:54:49 -0700272 return 0;
273}
274
Lester Lu918fe692017-08-17 14:39:29 -0700275int get_lgt8(const TxfmParam *txfm_param, int is_col,
276 const tran_high_t **lgtmtx) {
Sarah Parker90024e42017-10-06 16:50:47 -0700277#if CONFIG_EXT_TX
278 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
279#endif // CONFIG_EXT_TX
Lester Lu918fe692017-08-17 14:39:29 -0700280 if (is_col && (vtx_tab[txfm_param->tx_type] == ADST_1D ||
281 vtx_tab[txfm_param->tx_type] == FLIPADST_1D)) {
282 lgtmtx[0] = txfm_param->is_inter ? &lgt8_170[0][0] : &lgt8_150[0][0];
283 return 1;
284 } else if (!is_col && (htx_tab[txfm_param->tx_type] == ADST_1D ||
285 htx_tab[txfm_param->tx_type] == FLIPADST_1D)) {
286 lgtmtx[0] = txfm_param->is_inter ? &lgt8_170[0][0] : &lgt8_150[0][0];
Lester Lu708c1ec2017-06-14 14:54:49 -0700287 return 1;
288 }
Lester Lu918fe692017-08-17 14:39:29 -0700289 lgtmtx[0] = NULL;
Lester Lu708c1ec2017-06-14 14:54:49 -0700290 return 0;
291}
292#endif // CONFIG_LGT
293
Lester Lu432012f2017-08-17 14:39:29 -0700294#if CONFIG_LGT_FROM_PRED
295void ilgt16up(const tran_low_t *input, tran_low_t *output,
296 const tran_high_t *lgtmtx) {
297 if (lgtmtx[0] == DCT16) {
298 aom_idct16_c(input, output);
299 return;
300 } else if (lgtmtx[0] == ADST16) {
301 aom_iadst16_c(input, output);
302 return;
303 } else if (lgtmtx[0] == DCT32) {
304 aom_idct32_c(input, output);
305 return;
306 } else if (lgtmtx[0] == ADST32) {
307 ihalfright32_c(input, output);
308 return;
309 } else {
310 assert(0);
311 }
312}
313
314void get_discontinuity_1d(uint8_t *arr, int n, int *idx_max_diff) {
315 *idx_max_diff = -1;
316
317 int temp = 0, max_diff = 0, min_diff = INT_MAX;
318 for (int i = 1; i < n; ++i) {
319 temp = abs(arr[i] - arr[i - 1]);
320 if (temp > max_diff) {
321 max_diff = temp;
322 *idx_max_diff = i;
323 }
324 if (temp < min_diff) min_diff = temp;
325 }
326}
327
328void get_discontinuity_2d(uint8_t *dst, int stride, int n, int is_col,
329 int *idx_max_diff, int ntx) {
330 *idx_max_diff = -1;
331
332 int diff = 0, temp = 0, max_diff = 0, min_diff = INT_MAX;
333 for (int i = 1; i < n; ++i) {
334 temp = 0;
335 for (int j = 0; j < ntx; ++j) {
336 if (is_col) // vertical diff
337 diff = dst[i * stride + j] - dst[(i - 1) * stride + j];
338 else // horizontal diff
339 diff = dst[j * stride + i] - dst[j * stride + i - 1];
340 temp += diff * diff;
341 }
342 // temp/w is the i-th avg square diff
343 if (temp > max_diff) {
344 max_diff = temp;
345 *idx_max_diff = i;
346 }
347 if (temp < min_diff) min_diff = temp;
348 }
349}
350
351int idx_selfloop_wrt_mode(PREDICTION_MODE mode, int is_col) {
352 // 0: no self-loop
353 // 1: small self-loop
354 // 2: medium self-loop
355 // 3: large self-loop
356 switch (mode) {
357 case DC_PRED:
358 case SMOOTH_PRED:
359 // predition is good for both directions: large SLs for row and col
360 return 3;
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700361 case PAETH_PRED: return 0;
Lester Lu432012f2017-08-17 14:39:29 -0700362#if CONFIG_SMOOTH_HV
363 case SMOOTH_H_PRED:
364#endif
365 case H_PRED:
366 // prediction is good for H direction: large SL for row only
367 return is_col ? 0 : 3;
368#if CONFIG_SMOOTH_HV
369 case SMOOTH_V_PRED:
370#endif
371 case V_PRED:
372 // prediction is good for V direction: large SL for col only
373 return is_col ? 3 : 0;
374#if LGT_SL_INTRA
375 // directional mode: choose SL based on the direction
376 case D45_PRED: return is_col ? 2 : 0;
377 case D63_PRED: return is_col ? 3 : 0;
378 case D117_PRED: return is_col ? 3 : 1;
379 case D135_PRED: return 2;
380 case D153_PRED: return is_col ? 1 : 3;
381 case D207_PRED: return is_col ? 0 : 3;
382#else
383 case D45_PRED:
384 case D63_PRED:
385 case D117_PRED: return is_col ? 3 : 0;
386 case D135_PRED:
387 case D153_PRED:
388 case D207_PRED: return is_col ? 0 : 3;
389#endif
390 // inter: no SL
391 default: return 0;
392 }
393}
394
395void get_lgt4_from_pred(const TxfmParam *txfm_param, int is_col,
396 const tran_high_t **lgtmtx, int ntx) {
Sarah Parker90024e42017-10-06 16:50:47 -0700397#if CONFIG_EXT_TX
398 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
399#endif // CONFIG_EXT_TX
Lester Lu432012f2017-08-17 14:39:29 -0700400 PREDICTION_MODE mode = txfm_param->mode;
401 int stride = txfm_param->stride;
402 uint8_t *dst = txfm_param->dst;
403 int bp = -1;
404 uint8_t arr[4];
405
406 // Each lgt4mtx_arr[k][i] corresponds to a line graph with a self-loop on
407 // the first node, and possibly a weak edge within the line graph. i is
408 // the index of the weak edge (between the i-th and (i+1)-th pixels, i=0
409 // means no weak edge). k corresponds to the first self-loop's weight
410 const tran_high_t *lgt4mtx_arr[4][4] = {
411 { &lgt4_000[0][0], &lgt4_000w1[0][0], &lgt4_000w2[0][0],
412 &lgt4_000w3[0][0] },
413 { &lgt4_060[0][0], &lgt4_060_000w1[0][0], &lgt4_060_000w2[0][0],
414 &lgt4_060_000w3[0][0] },
415 { &lgt4_100[0][0], &lgt4_100_000w1[0][0], &lgt4_100_000w2[0][0],
416 &lgt4_100_000w3[0][0] },
417 { &lgt4_150[0][0], &lgt4_150_000w1[0][0], &lgt4_150_000w2[0][0],
418 &lgt4_150_000w3[0][0] },
419 };
420
421 // initialize to DCT or some LGTs, and then change later if necessary
422 int idx_sl = idx_selfloop_wrt_mode(mode, is_col);
423 lgtmtx[0] = lgt4mtx_arr[idx_sl][0];
424
425 // find the break point and replace the line graph by the one with a
426 // break point
427 if (mode == DC_PRED || mode == SMOOTH_PRED) {
428 // Do not use break point, since 1) is_left_available and is_top_available
429 // in DC_PRED are not known by txfm_param for now, so accessing
430 // both boundaries anyway may cause a mismatch 2) DC prediciton
431 // typically yields very smooth residues so having the break point
432 // does not usually improve the RD result.
433 return;
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700434 } else if (mode == PAETH_PRED) {
435 // PAETH_PRED: use both 1D top boundary and 1D left boundary
Lester Lu432012f2017-08-17 14:39:29 -0700436 if (is_col)
437 for (int i = 0; i < 4; ++i) arr[i] = dst[i * stride];
438 else
439 for (int i = 0; i < 4; ++i) arr[i] = dst[i];
440 get_discontinuity_1d(&arr[0], 4, &bp);
441 } else if (mode == V_PRED) {
442 // V_PRED: use 1D top boundary only
443 if (is_col) return;
444 for (int i = 0; i < 4; ++i) arr[i] = dst[i];
445 get_discontinuity_1d(&arr[0], 4, &bp);
446 } else if (mode == H_PRED) {
447 // H_PRED: use 1D left boundary only
448 if (!is_col) return;
449 for (int i = 0; i < 4; ++i) arr[i] = dst[i * stride];
450 get_discontinuity_1d(&arr[0], 4, &bp);
451#if CONFIG_SMOOTH_HV
452 } else if (mode == SMOOTH_V_PRED) {
453 if (is_col) return;
454 for (int i = 0; i < 4; ++i) arr[i] = dst[-stride + i];
455 get_discontinuity_1d(&arr[0], 4, &bp);
456 } else if (mode == SMOOTH_H_PRED) {
457 if (!is_col) return;
458 for (int i = 0; i < 4; ++i) arr[i] = dst[i * stride - 1];
459 get_discontinuity_1d(&arr[0], 4, &bp);
460#endif
461 } else if (mode == D45_PRED || mode == D63_PRED || mode == D117_PRED) {
462 // directional modes closer to vertical (maybe include D135 later)
463 if (!is_col) get_discontinuity_2d(dst, stride, 4, 0, &bp, ntx);
464 } else if (mode == D135_PRED || mode == D153_PRED || mode == D207_PRED) {
465 // directional modes closer to horizontal
466 if (is_col) get_discontinuity_2d(dst, stride, 4, 1, &bp, ntx);
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700467 } else if (mode > PAETH_PRED) {
Lester Lu432012f2017-08-17 14:39:29 -0700468 // inter
469 get_discontinuity_2d(dst, stride, 4, is_col, &bp, ntx);
470 }
471
472#if LGT_SL_INTRA
473 if (bp != -1) lgtmtx[0] = lgt4mtx_arr[idx_sl][bp];
474#else
475 if (bp != -1) lgtmtx[0] = lgt4mtx_arr[0][bp];
476#endif
477}
478
479void get_lgt8_from_pred(const TxfmParam *txfm_param, int is_col,
480 const tran_high_t **lgtmtx, int ntx) {
Sarah Parker90024e42017-10-06 16:50:47 -0700481#if CONFIG_EXT_TX
482 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
483#endif // CONFIG_EXT_TX
Lester Lu432012f2017-08-17 14:39:29 -0700484 PREDICTION_MODE mode = txfm_param->mode;
485 int stride = txfm_param->stride;
486 uint8_t *dst = txfm_param->dst;
487 int bp = -1;
488 uint8_t arr[8];
489
490 const tran_high_t *lgt8mtx_arr[4][8] = {
491 { &lgt8_000[0][0], &lgt8_000w1[0][0], &lgt8_000w2[0][0], &lgt8_000w3[0][0],
492 &lgt8_000w4[0][0], &lgt8_000w5[0][0], &lgt8_000w6[0][0],
493 &lgt8_000w7[0][0] },
494 { &lgt8_060[0][0], &lgt8_060_000w1[0][0], &lgt8_060_000w2[0][0],
495 &lgt8_060_000w3[0][0], &lgt8_060_000w4[0][0], &lgt8_060_000w5[0][0],
496 &lgt8_060_000w6[0][0], &lgt8_060_000w7[0][0] },
497 { &lgt8_100[0][0], &lgt8_100_000w1[0][0], &lgt8_100_000w2[0][0],
498 &lgt8_100_000w3[0][0], &lgt8_100_000w4[0][0], &lgt8_100_000w5[0][0],
499 &lgt8_100_000w6[0][0], &lgt8_100_000w7[0][0] },
500 { &lgt8_150[0][0], &lgt8_150_000w1[0][0], &lgt8_150_000w2[0][0],
501 &lgt8_150_000w3[0][0], &lgt8_150_000w4[0][0], &lgt8_150_000w5[0][0],
502 &lgt8_150_000w6[0][0], &lgt8_150_000w7[0][0] },
503 };
504
505 int idx_sl = idx_selfloop_wrt_mode(mode, is_col);
506 lgtmtx[0] = lgt8mtx_arr[idx_sl][0];
507
508 if (mode == DC_PRED || mode == SMOOTH_PRED) {
509 return;
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700510 } else if (mode == PAETH_PRED) {
Lester Lu432012f2017-08-17 14:39:29 -0700511 if (is_col)
512 for (int i = 0; i < 8; ++i) arr[i] = dst[i * stride];
513 else
514 for (int i = 0; i < 8; ++i) arr[i] = dst[i];
515 get_discontinuity_1d(&arr[0], 8, &bp);
516 } else if (mode == V_PRED) {
517 if (is_col) return;
518 for (int i = 0; i < 8; ++i) arr[i] = dst[i];
519 get_discontinuity_1d(&arr[0], 8, &bp);
520 } else if (mode == H_PRED) {
521 if (!is_col) return;
522 for (int i = 0; i < 8; ++i) arr[i] = dst[i * stride];
523 get_discontinuity_1d(&arr[0], 8, &bp);
524#if CONFIG_SMOOTH_HV
525 } else if (mode == SMOOTH_V_PRED) {
526 if (is_col) return;
527 for (int i = 0; i < 8; ++i) arr[i] = dst[-stride + i];
528 get_discontinuity_1d(&arr[0], 8, &bp);
529 } else if (mode == SMOOTH_H_PRED) {
530 if (!is_col) return;
531 for (int i = 0; i < 8; ++i) arr[i] = dst[i * stride - 1];
532 get_discontinuity_1d(&arr[0], 8, &bp);
533#endif
534 } else if (mode == D45_PRED || mode == D63_PRED || mode == D117_PRED) {
535 if (!is_col) get_discontinuity_2d(dst, stride, 8, 0, &bp, ntx);
536 } else if (mode == D135_PRED || mode == D153_PRED || mode == D207_PRED) {
537 if (is_col) get_discontinuity_2d(dst, stride, 8, 1, &bp, ntx);
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700538 } else if (mode > PAETH_PRED) {
Lester Lu432012f2017-08-17 14:39:29 -0700539 get_discontinuity_2d(dst, stride, 8, is_col, &bp, ntx);
540 }
541
542#if LGT_SL_INTRA
543 if (bp != -1) lgtmtx[0] = lgt8mtx_arr[idx_sl][bp];
544#else
545 if (bp != -1) lgtmtx[0] = lgt8mtx_arr[0][bp];
546#endif
547}
548
549// Since LGTs with length >8 are not implemented now, the following function
550// will just call DCT or ADST
551void get_lgt16up_from_pred(const TxfmParam *txfm_param, int is_col,
552 const tran_high_t **lgtmtx, int ntx) {
Sarah Parker90024e42017-10-06 16:50:47 -0700553#if CONFIG_EXT_TX
554 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
555#endif // CONFIG_EXT_TX
Lester Lu432012f2017-08-17 14:39:29 -0700556 int tx_length = is_col ? tx_size_high[txfm_param->tx_size]
557 : tx_size_wide[txfm_param->tx_size];
558 assert(tx_length == 16 || tx_length == 32);
559 PREDICTION_MODE mode = txfm_param->mode;
560
561 (void)ntx;
562 const tran_high_t *dctmtx =
563 tx_length == 16 ? &lgt16_000[0][0] : &lgt32_000[0][0];
564 const tran_high_t *adstmtx =
565 tx_length == 16 ? &lgt16_200[0][0] : &lgt32_200[0][0];
566
567 switch (mode) {
568 case DC_PRED:
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700569 case PAETH_PRED:
Lester Lu432012f2017-08-17 14:39:29 -0700570 case SMOOTH_PRED:
571 // prediction from both top and left -> ADST
572 lgtmtx[0] = adstmtx;
573 break;
574 case V_PRED:
575 case D45_PRED:
576 case D63_PRED:
577 case D117_PRED:
578#if CONFIG_SMOOTH_HV
579 case SMOOTH_V_PRED:
580#endif
581 // prediction from the top more than from the left -> ADST
582 lgtmtx[0] = is_col ? adstmtx : dctmtx;
583 break;
584 case H_PRED:
585 case D135_PRED:
586 case D153_PRED:
587 case D207_PRED:
588#if CONFIG_SMOOTH_HV
589 case SMOOTH_H_PRED:
590#endif
591 // prediction from the left more than from the top -> DCT
592 lgtmtx[0] = is_col ? dctmtx : adstmtx;
593 break;
594 default: lgtmtx[0] = dctmtx; break;
595 }
596}
597
598typedef void (*IlgtFunc)(const tran_low_t *input, tran_low_t *output,
599 const tran_high_t *lgtmtx);
600
601static IlgtFunc ilgt_func[4] = { ilgt4, ilgt8, ilgt16up, ilgt16up };
602
603typedef void (*GetLgtFunc)(const TxfmParam *txfm_param, int is_col,
604 const tran_high_t **lgtmtx, int ntx);
605
606static GetLgtFunc get_lgt_func[4] = { get_lgt4_from_pred, get_lgt8_from_pred,
607 get_lgt16up_from_pred,
608 get_lgt16up_from_pred };
609
610// this inline function corresponds to the up scaling before the transpose
611// operation in the av1_iht* functions
612static INLINE tran_low_t inv_upscale_wrt_txsize(const tran_high_t val,
613 const TX_SIZE tx_size) {
614 switch (tx_size) {
615 case TX_4X4:
616 case TX_8X8:
617 case TX_4X16:
618 case TX_16X4:
619 case TX_8X32:
620 case TX_32X8: return (tran_low_t)val;
621 case TX_4X8:
622 case TX_8X4:
623 case TX_8X16:
624 case TX_16X8: return (tran_low_t)dct_const_round_shift(val * Sqrt2);
625 default: assert(0); break;
626 }
627 return 0;
628}
629
630// This inline function corresponds to the bit shift before summing with the
631// destination in the av1_iht* functions
632static INLINE tran_low_t inv_downscale_wrt_txsize(const tran_low_t val,
633 const TX_SIZE tx_size) {
634 switch (tx_size) {
635 case TX_4X4: return ROUND_POWER_OF_TWO(val, 4);
636 case TX_4X8:
637 case TX_8X4:
638 case TX_8X8:
639 case TX_4X16:
640 case TX_16X4: return ROUND_POWER_OF_TWO(val, 5);
641 case TX_8X16:
642 case TX_16X8:
643 case TX_8X32:
644 case TX_32X8: return ROUND_POWER_OF_TWO(val, 6);
645 default: assert(0); break;
646 }
647 return 0;
648}
649
650void ilgt2d_from_pred_add(const tran_low_t *input, uint8_t *dest, int stride,
651 const TxfmParam *txfm_param) {
652 const TX_SIZE tx_size = txfm_param->tx_size;
653 const int w = tx_size_wide[tx_size];
654 const int h = tx_size_high[tx_size];
655 const int wlog2 = tx_size_wide_log2[tx_size];
656 const int hlog2 = tx_size_high_log2[tx_size];
657 assert(w <= 8 || h <= 8);
658
659 int i, j;
660 // largest 1D size allowed for LGT: 32
661 // largest 2D size allowed for LGT: 8x32=256
662 tran_low_t tmp[256], out[256], temp1d[32];
663 const tran_high_t *lgtmtx_col[1];
664 const tran_high_t *lgtmtx_row[1];
665 get_lgt_func[hlog2 - 2](txfm_param, 1, lgtmtx_col, w);
666 get_lgt_func[wlog2 - 2](txfm_param, 0, lgtmtx_row, h);
667
668// for inverse transform, to be consistent with av1_iht functions, we always
669// apply row transforms first and column transforms second, but both
670// row-first and column-first versions are implemented here for future
671// tests (use different lgtmtx_col[i], and choose row or column tx first
672// depending on transforms).
673#if 1
674 // inverse column transforms
675 for (i = 0; i < w; ++i) {
676 // transpose
677 for (j = 0; j < h; ++j) tmp[i * h + j] = input[j * w + i];
678 ilgt_func[hlog2 - 2](&tmp[i * h], temp1d, lgtmtx_col[0]);
679 // upscale, and store in place
680 for (j = 0; j < h; ++j)
681 tmp[i * h + j] = inv_upscale_wrt_txsize(temp1d[j], tx_size);
682 }
683 // inverse row transforms
684 for (i = 0; i < h; ++i) {
685 for (j = 0; j < w; ++j) temp1d[j] = tmp[j * h + i];
686 ilgt_func[wlog2 - 2](temp1d, &out[i * w], lgtmtx_row[0]);
687 }
688 // downscale + sum with the destination
689 for (i = 0; i < h; ++i) {
690 for (j = 0; j < w; ++j) {
691 int d = i * stride + j;
692 int s = i * w + j;
693 dest[d] =
694 clip_pixel_add(dest[d], inv_downscale_wrt_txsize(out[s], tx_size));
695 }
696 }
697#else
698 // inverse row transforms
699 for (i = 0; i < h; ++i) {
700 ilgt_func[wlog2 - 2](input, temp1d, lgtmtx_row[0]);
701 // upscale and transpose (tmp[j*h+i] <--> tmp[j][i])
702 for (j = 0; j < w; ++j)
703 tmp[j * h + i] = inv_upscale_wrt_txsize(temp1d[j], tx_size);
704 input += w;
705 }
706 // inverse column transforms
707 for (i = 0; i < w; ++i)
708 ilgt_func[hlog2 - 2](&tmp[i * h], &out[i * h], lgtmtx_col[0]);
709 // here, out[] is the transpose of 2D block of transform coefficients
710
711 // downscale + transform + sum with dest
712 for (i = 0; i < h; ++i) {
713 for (j = 0; j < w; ++j) {
714 int d = i * stride + j;
715 int s = j * h + i;
716 dest[d] =
717 clip_pixel_add(dest[d], inv_downscale_wrt_txsize(out[s], tx_size));
718 }
719 }
720#endif
721}
722#endif // CONFIG_LGT_FROM_PRED
723
Yaowu Xuf883b422016-08-30 14:01:10 -0700724void av1_iht4x4_16_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -0700725 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -0700726 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -0700727#if CONFIG_MRC_TX
728 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
729#endif // CONFIG_MRC_TX
Nathan E. Eggee554f362017-10-04 14:44:38 -0400730#if !CONFIG_DAALA_TX4
Monty Montgomery554d2c32017-07-11 21:01:07 -0400731 if (tx_type == DCT_DCT) {
732 aom_idct4x4_16_add(input, dest, stride);
733 return;
734 }
Monty Montgomery02078a32017-07-11 21:22:29 -0400735#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700736 static const transform_2d IHT_4[] = {
Nathan E. Eggee554f362017-10-04 14:44:38 -0400737#if CONFIG_DAALA_TX4
Nathan E. Egge1aefb5e2017-09-16 11:28:41 -0400738 { daala_idct4, daala_idct4 }, // DCT_DCT = 0
739 { daala_idst4, daala_idct4 }, // ADST_DCT = 1
740 { daala_idct4, daala_idst4 }, // DCT_ADST = 2
741 { daala_idst4, daala_idst4 }, // ADST_ADST = 3
Nathan E. Egge5e6bda82017-09-16 10:13:51 -0400742#if CONFIG_EXT_TX
Nathan E. Egge1aefb5e2017-09-16 11:28:41 -0400743 { daala_idst4, daala_idct4 }, // FLIPADST_DCT
744 { daala_idct4, daala_idst4 }, // DCT_FLIPADST
745 { daala_idst4, daala_idst4 }, // FLIPADST_FLIPADST
746 { daala_idst4, daala_idst4 }, // ADST_FLIPADST
747 { daala_idst4, daala_idst4 }, // FLIPADST_ADST
Nathan E. Egge31f24ee2017-09-18 11:25:26 -0400748 { daala_idtx4, daala_idtx4 }, // IDTX
749 { daala_idct4, daala_idtx4 }, // V_DCT
750 { daala_idtx4, daala_idct4 }, // H_DCT
751 { daala_idst4, daala_idtx4 }, // V_ADST
752 { daala_idtx4, daala_idst4 }, // H_ADST
753 { daala_idst4, daala_idtx4 }, // V_FLIPADST
754 { daala_idtx4, daala_idst4 }, // H_FLIPADST
Nathan E. Egge5e6bda82017-09-16 10:13:51 -0400755#endif
756#else
Luca Barbatof0f98572016-09-03 12:14:15 +0200757 { aom_idct4_c, aom_idct4_c }, // DCT_DCT = 0
758 { aom_iadst4_c, aom_idct4_c }, // ADST_DCT = 1
759 { aom_idct4_c, aom_iadst4_c }, // DCT_ADST = 2
760 { aom_iadst4_c, aom_iadst4_c }, // ADST_ADST = 3
Yaowu Xuc27fc142016-08-22 16:08:15 -0700761#if CONFIG_EXT_TX
Luca Barbatof0f98572016-09-03 12:14:15 +0200762 { aom_iadst4_c, aom_idct4_c }, // FLIPADST_DCT
763 { aom_idct4_c, aom_iadst4_c }, // DCT_FLIPADST
764 { aom_iadst4_c, aom_iadst4_c }, // FLIPADST_FLIPADST
765 { aom_iadst4_c, aom_iadst4_c }, // ADST_FLIPADST
766 { aom_iadst4_c, aom_iadst4_c }, // FLIPADST_ADST
767 { iidtx4_c, iidtx4_c }, // IDTX
768 { aom_idct4_c, iidtx4_c }, // V_DCT
769 { iidtx4_c, aom_idct4_c }, // H_DCT
770 { aom_iadst4_c, iidtx4_c }, // V_ADST
771 { iidtx4_c, aom_iadst4_c }, // H_ADST
772 { aom_iadst4_c, iidtx4_c }, // V_FLIPADST
773 { iidtx4_c, aom_iadst4_c }, // H_FLIPADST
Lester Lud8b1ddc2017-07-06 16:13:29 -0700774#endif
Nathan E. Egge5e6bda82017-09-16 10:13:51 -0400775#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700776 };
777
778 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +0100779 tran_low_t tmp[4][4];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700780 tran_low_t out[4][4];
781 tran_low_t *outp = &out[0][0];
782 int outstride = 4;
783
Monty Montgomerycb55dad2017-07-11 16:59:52 -0400784#if CONFIG_DCT_ONLY
785 assert(tx_type == DCT_DCT);
786#endif
787
Lester Lu708c1ec2017-06-14 14:54:49 -0700788#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -0700789 const tran_high_t *lgtmtx_col[1];
790 const tran_high_t *lgtmtx_row[1];
791 int use_lgt_col = get_lgt4(txfm_param, 1, lgtmtx_col);
792 int use_lgt_row = get_lgt4(txfm_param, 0, lgtmtx_row);
Lester Lu708c1ec2017-06-14 14:54:49 -0700793#endif
794
Yaowu Xuc27fc142016-08-22 16:08:15 -0700795 // inverse transform row vectors
796 for (i = 0; i < 4; ++i) {
Nathan E. Eggee554f362017-10-04 14:44:38 -0400797#if CONFIG_DAALA_TX4
Monty Montgomery02078a32017-07-11 21:22:29 -0400798 tran_low_t temp_in[4];
Sebastien Alaiwan77323262017-08-21 11:34:56 +0200799 for (j = 0; j < 4; j++) temp_in[j] = input[j] * 2;
Monty Montgomery02078a32017-07-11 21:22:29 -0400800 IHT_4[tx_type].rows(temp_in, out[i]);
801#else
Lester Lu708c1ec2017-06-14 14:54:49 -0700802#if CONFIG_LGT
803 if (use_lgt_row)
Lester Lu918fe692017-08-17 14:39:29 -0700804 ilgt4(input, out[i], lgtmtx_row[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -0700805 else
806#endif
807 IHT_4[tx_type].rows(input, out[i]);
Monty Montgomery02078a32017-07-11 21:22:29 -0400808#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700809 input += 4;
810 }
811
812 // transpose
Jonathan Matthews362d0c72017-05-09 14:53:11 +0100813 for (i = 0; i < 4; i++) {
814 for (j = 0; j < 4; j++) {
815 tmp[j][i] = out[i][j];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700816 }
817 }
818
819 // inverse transform column vectors
820 for (i = 0; i < 4; ++i) {
Lester Lu708c1ec2017-06-14 14:54:49 -0700821#if CONFIG_LGT
822 if (use_lgt_col)
Lester Lu918fe692017-08-17 14:39:29 -0700823 ilgt4(tmp[i], out[i], lgtmtx_col[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -0700824 else
825#endif
826 IHT_4[tx_type].cols(tmp[i], out[i]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700827 }
828
829#if CONFIG_EXT_TX
830 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 4, 4);
831#endif
832
833 // Sum with the destination
834 for (i = 0; i < 4; ++i) {
835 for (j = 0; j < 4; ++j) {
836 int d = i * stride + j;
837 int s = j * outstride + i;
Nathan E. Eggee554f362017-10-04 14:44:38 -0400838#if CONFIG_DAALA_TX4
Yaowu Xuc27fc142016-08-22 16:08:15 -0700839 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 4));
Monty Montgomery02078a32017-07-11 21:22:29 -0400840#else
841 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 4));
842#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700843 }
844 }
845}
846
Yaowu Xuf883b422016-08-30 14:01:10 -0700847void av1_iht4x8_32_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -0700848 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -0700849 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -0700850#if CONFIG_MRC_TX
851 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
852#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -0400853#if CONFIG_DCT_ONLY
854 assert(tx_type == DCT_DCT);
855#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700856 static const transform_2d IHT_4x8[] = {
Monty Montgomeryabd94512017-10-14 00:41:42 -0400857#if CONFIG_DAALA_TX4 && CONFIG_DAALA_TX8
858 { daala_idct8, daala_idct4 }, // DCT_DCT = 0
859 { daala_idst8, daala_idct4 }, // ADST_DCT = 1
860 { daala_idct8, daala_idst4 }, // DCT_ADST = 2
861 { daala_idst8, daala_idst4 }, // ADST_ADST = 3
862#if CONFIG_EXT_TX
863 { daala_idst8, daala_idct4 }, // FLIPADST_DCT
864 { daala_idct8, daala_idst4 }, // DCT_FLIPADST
865 { daala_idst8, daala_idst4 }, // FLIPADST_FLIPADST
866 { daala_idst8, daala_idst4 }, // ADST_FLIPADST
867 { daala_idst8, daala_idst4 }, // FLIPADST_ADST
868 { daala_idtx8, daala_idtx4 }, // IDTX
869 { daala_idct8, daala_idtx4 }, // V_DCT
870 { daala_idtx8, daala_idct4 }, // H_DCT
871 { daala_idst8, daala_idtx4 }, // V_ADST
872 { daala_idtx8, daala_idst4 }, // H_ADST
873 { daala_idst8, daala_idtx4 }, // V_FLIPADST
874 { daala_idtx8, daala_idst4 }, // H_FLIPADST
875#endif
876#else
Luca Barbatof0f98572016-09-03 12:14:15 +0200877 { aom_idct8_c, aom_idct4_c }, // DCT_DCT
878 { aom_iadst8_c, aom_idct4_c }, // ADST_DCT
879 { aom_idct8_c, aom_iadst4_c }, // DCT_ADST
880 { aom_iadst8_c, aom_iadst4_c }, // ADST_ADST
Jingning Hanec419e02016-11-01 18:19:30 -0700881#if CONFIG_EXT_TX
Luca Barbatof0f98572016-09-03 12:14:15 +0200882 { aom_iadst8_c, aom_idct4_c }, // FLIPADST_DCT
883 { aom_idct8_c, aom_iadst4_c }, // DCT_FLIPADST
884 { aom_iadst8_c, aom_iadst4_c }, // FLIPADST_FLIPADST
885 { aom_iadst8_c, aom_iadst4_c }, // ADST_FLIPADST
886 { aom_iadst8_c, aom_iadst4_c }, // FLIPADST_ADST
887 { iidtx8_c, iidtx4_c }, // IDTX
888 { aom_idct8_c, iidtx4_c }, // V_DCT
889 { iidtx8_c, aom_idct4_c }, // H_DCT
890 { aom_iadst8_c, iidtx4_c }, // V_ADST
891 { iidtx8_c, aom_iadst4_c }, // H_ADST
892 { aom_iadst8_c, iidtx4_c }, // V_FLIPADST
893 { iidtx8_c, aom_iadst4_c }, // H_FLIPADST
Jingning Hanec419e02016-11-01 18:19:30 -0700894#endif
Monty Montgomeryabd94512017-10-14 00:41:42 -0400895#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700896 };
897
898 const int n = 4;
899 const int n2 = 8;
900 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +0100901 tran_low_t out[4][8], tmp[4][8], outtmp[4];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700902 tran_low_t *outp = &out[0][0];
903 int outstride = n2;
904
Lester Lu708c1ec2017-06-14 14:54:49 -0700905#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -0700906 const tran_high_t *lgtmtx_col[1];
907 const tran_high_t *lgtmtx_row[1];
908 int use_lgt_col = get_lgt8(txfm_param, 1, lgtmtx_col);
909 int use_lgt_row = get_lgt4(txfm_param, 0, lgtmtx_row);
Lester Lu708c1ec2017-06-14 14:54:49 -0700910#endif
911
Monty Montgomeryabd94512017-10-14 00:41:42 -0400912 // Multi-way scaling matrix (bits):
913 // LGT/AV1 row,col input+0, rowTX+.5, mid+.5, colTX+1, out-5 == -3
914 // LGT row, Daala col input+0, rowTX+.5, mid+.5, colTX+0, out-4 == -3
915 // Daala row, LGT col input+1, rowTX+0, mid+0, colTX+1, out-5 == -3
916 // Daala row,col input+1, rowTX+0, mid+0, colTX+0, out-4 == -3
917
Yaowu Xuc27fc142016-08-22 16:08:15 -0700918 // inverse transform row vectors and transpose
919 for (i = 0; i < n2; ++i) {
Lester Lu708c1ec2017-06-14 14:54:49 -0700920#if CONFIG_LGT
Monty Montgomeryabd94512017-10-14 00:41:42 -0400921 if (use_lgt_row) {
922 // Scaling cases 1 and 2 above
923 // No input scaling
924 // Row transform (LGT; scales up .5 bits)
Lester Lu918fe692017-08-17 14:39:29 -0700925 ilgt4(input, outtmp, lgtmtx_row[0]);
Monty Montgomeryabd94512017-10-14 00:41:42 -0400926 // Transpose and mid scaling up by .5 bit
927 for (j = 0; j < n; ++j)
928 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
929 } else {
Lester Lu708c1ec2017-06-14 14:54:49 -0700930#endif
Monty Montgomeryabd94512017-10-14 00:41:42 -0400931#if CONFIG_DAALA_TX4 && CONFIG_DAALA_TX8
932 // Daala row transform; Scaling cases 3 and 4 above
933 tran_low_t temp_in[4];
934 // Input scaling up by 1 bit
935 for (j = 0; j < n; j++) temp_in[j] = input[j] * 2;
936 // Row transform; Daala does not scale
937 IHT_4x8[tx_type].rows(temp_in, outtmp);
938 // Transpose; no mid scaling
939 for (j = 0; j < n; ++j) tmp[j][i] = outtmp[j];
940#else
941 // AV1 row transform; Scaling case 1 only
942 // Row transform (AV1 scales up .5 bits)
943 IHT_4x8[tx_type].rows(input, outtmp);
944 // Transpose and mid scaling up by .5 bit
Yaowu Xuc27fc142016-08-22 16:08:15 -0700945 for (j = 0; j < n; ++j)
Jonathan Matthews362d0c72017-05-09 14:53:11 +0100946 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
Monty Montgomeryabd94512017-10-14 00:41:42 -0400947#endif
948#if CONFIG_LGT
949 }
950#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700951 input += n;
952 }
953
954 // inverse transform column vectors
Monty Montgomeryabd94512017-10-14 00:41:42 -0400955 // AV1/LGT column TX scales up by 1 bit, Daala does not scale
Yaowu Xuc27fc142016-08-22 16:08:15 -0700956 for (i = 0; i < n; ++i) {
Lester Lu708c1ec2017-06-14 14:54:49 -0700957#if CONFIG_LGT
958 if (use_lgt_col)
Lester Lu918fe692017-08-17 14:39:29 -0700959 ilgt8(tmp[i], out[i], lgtmtx_col[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -0700960 else
961#endif
962 IHT_4x8[tx_type].cols(tmp[i], out[i]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700963 }
964
Jingning Hanec419e02016-11-01 18:19:30 -0700965#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -0700966 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n2, n);
Jingning Hanec419e02016-11-01 18:19:30 -0700967#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700968
969 // Sum with the destination
970 for (i = 0; i < n2; ++i) {
971 for (j = 0; j < n; ++j) {
972 int d = i * stride + j;
973 int s = j * outstride + i;
Monty Montgomeryabd94512017-10-14 00:41:42 -0400974#if CONFIG_DAALA_TX4 && CONFIG_DAALA_TX8
975#if CONFIG_LGT
976 if (use_lgt_col)
977 // Output Scaling cases 1, 3
978 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
979 else
980#endif
981 // Output scaling cases 2, 4
982 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 4));
983#else
984 // Output scaling case 1 only
Yaowu Xuc27fc142016-08-22 16:08:15 -0700985 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
Monty Montgomeryabd94512017-10-14 00:41:42 -0400986#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700987 }
988 }
989}
990
Yaowu Xuf883b422016-08-30 14:01:10 -0700991void av1_iht8x4_32_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -0700992 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -0700993 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -0700994#if CONFIG_MRC_TX
995 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
996#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -0400997#if CONFIG_DCT_ONLY
998 assert(tx_type == DCT_DCT);
999#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001000 static const transform_2d IHT_8x4[] = {
Monty Montgomeryabd94512017-10-14 00:41:42 -04001001#if CONFIG_DAALA_TX4 && CONFIG_DAALA_TX8
1002 { daala_idct4, daala_idct8 }, // DCT_DCT = 0
1003 { daala_idst4, daala_idct8 }, // ADST_DCT = 1
1004 { daala_idct4, daala_idst8 }, // DCT_ADST = 2
1005 { daala_idst4, daala_idst8 }, // ADST_ADST = 3
1006#if CONFIG_EXT_TX
1007 { daala_idst4, daala_idct8 }, // FLIPADST_DCT
1008 { daala_idct4, daala_idst8 }, // DCT_FLIPADST
1009 { daala_idst4, daala_idst8 }, // FLIPADST_FLIPADST
1010 { daala_idst4, daala_idst8 }, // ADST_FLIPADST
1011 { daala_idst4, daala_idst8 }, // FLIPADST_ADST
1012 { daala_idtx4, daala_idtx8 }, // IDTX
1013 { daala_idct4, daala_idtx8 }, // V_DCT
1014 { daala_idtx4, daala_idct8 }, // H_DCT
1015 { daala_idst4, daala_idtx8 }, // V_ADST
1016 { daala_idtx4, daala_idst8 }, // H_ADST
1017 { daala_idst4, daala_idtx8 }, // V_FLIPADST
1018 { daala_idtx4, daala_idst8 }, // H_FLIPADST
1019#endif
1020#else
Luca Barbatof0f98572016-09-03 12:14:15 +02001021 { aom_idct4_c, aom_idct8_c }, // DCT_DCT
1022 { aom_iadst4_c, aom_idct8_c }, // ADST_DCT
1023 { aom_idct4_c, aom_iadst8_c }, // DCT_ADST
1024 { aom_iadst4_c, aom_iadst8_c }, // ADST_ADST
Jingning Hanec419e02016-11-01 18:19:30 -07001025#if CONFIG_EXT_TX
Luca Barbatof0f98572016-09-03 12:14:15 +02001026 { aom_iadst4_c, aom_idct8_c }, // FLIPADST_DCT
1027 { aom_idct4_c, aom_iadst8_c }, // DCT_FLIPADST
1028 { aom_iadst4_c, aom_iadst8_c }, // FLIPADST_FLIPADST
1029 { aom_iadst4_c, aom_iadst8_c }, // ADST_FLIPADST
1030 { aom_iadst4_c, aom_iadst8_c }, // FLIPADST_ADST
1031 { iidtx4_c, iidtx8_c }, // IDTX
1032 { aom_idct4_c, iidtx8_c }, // V_DCT
1033 { iidtx4_c, aom_idct8_c }, // H_DCT
1034 { aom_iadst4_c, iidtx8_c }, // V_ADST
1035 { iidtx4_c, aom_iadst8_c }, // H_ADST
1036 { aom_iadst4_c, iidtx8_c }, // V_FLIPADST
1037 { iidtx4_c, aom_iadst8_c }, // H_FLIPADST
Jingning Hanec419e02016-11-01 18:19:30 -07001038#endif
Monty Montgomeryabd94512017-10-14 00:41:42 -04001039#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001040 };
Lester Lud8b1ddc2017-07-06 16:13:29 -07001041
Yaowu Xuc27fc142016-08-22 16:08:15 -07001042 const int n = 4;
1043 const int n2 = 8;
1044
1045 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001046 tran_low_t out[8][4], tmp[8][4], outtmp[8];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001047 tran_low_t *outp = &out[0][0];
1048 int outstride = n;
1049
Lester Lu708c1ec2017-06-14 14:54:49 -07001050#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -07001051 const tran_high_t *lgtmtx_col[1];
1052 const tran_high_t *lgtmtx_row[1];
1053 int use_lgt_col = get_lgt4(txfm_param, 1, lgtmtx_col);
1054 int use_lgt_row = get_lgt8(txfm_param, 0, lgtmtx_row);
Lester Lu708c1ec2017-06-14 14:54:49 -07001055#endif
1056
Monty Montgomeryabd94512017-10-14 00:41:42 -04001057 // Multi-way scaling matrix (bits):
1058 // LGT/AV1 row,col input+0, rowTX+1, mid+.5, colTX+.5, out-5 == -3
1059 // LGT row, Daala col input+0, rowTX+1, mid+.5, colTX+.5, out-4 == -3
1060 // Daala row, LGT col input+1, rowTX+0, mid+0, colTX+1, out-5 == -3
1061 // Daala row,col input+1, rowTX+0, mid+0, colTX+0, out-4 == -3
1062
Yaowu Xuc27fc142016-08-22 16:08:15 -07001063 // inverse transform row vectors and transpose
1064 for (i = 0; i < n; ++i) {
Lester Lu708c1ec2017-06-14 14:54:49 -07001065#if CONFIG_LGT
Monty Montgomeryabd94512017-10-14 00:41:42 -04001066 if (use_lgt_row) {
1067 // Scaling cases 1 and 2 above
1068 // No input scaling
1069 // Row transform (LGT; scales up 1 bit)
Lester Lu918fe692017-08-17 14:39:29 -07001070 ilgt8(input, outtmp, lgtmtx_row[0]);
Monty Montgomeryabd94512017-10-14 00:41:42 -04001071 // Transpose and mid scaling up by .5 bit
1072 for (j = 0; j < n2; ++j)
1073 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
1074 } else {
Lester Lu708c1ec2017-06-14 14:54:49 -07001075#endif
Monty Montgomeryabd94512017-10-14 00:41:42 -04001076#if CONFIG_DAALA_TX4 && CONFIG_DAALA_TX8
1077 // Daala row transform; Scaling cases 3 and 4 above
1078 tran_low_t temp_in[8];
1079 // Input scaling up by 1 bit
1080 for (j = 0; j < n2; j++) temp_in[j] = input[j] * 2;
1081 // Row transform; Daala does not scale
1082 IHT_8x4[tx_type].rows(temp_in, outtmp);
1083 // Transpose; no mid scaling
1084 for (j = 0; j < n2; ++j) tmp[j][i] = outtmp[j];
1085#else
1086 // AV1 row transform; Scaling case 1 only
1087 // Row transform (AV1 scales up 1 bit)
1088 IHT_8x4[tx_type].rows(input, outtmp);
1089 // Transpose and mid scaling up by .5 bit
Yaowu Xuc27fc142016-08-22 16:08:15 -07001090 for (j = 0; j < n2; ++j)
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001091 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
Monty Montgomeryabd94512017-10-14 00:41:42 -04001092#endif
1093#if CONFIG_LGT
1094 }
1095#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001096 input += n2;
1097 }
1098
1099 // inverse transform column vectors
Monty Montgomeryabd94512017-10-14 00:41:42 -04001100 // AV1 and LGT scale up by .5 bits; Daala does not scale
Yaowu Xuc27fc142016-08-22 16:08:15 -07001101 for (i = 0; i < n2; ++i) {
Lester Lu708c1ec2017-06-14 14:54:49 -07001102#if CONFIG_LGT
1103 if (use_lgt_col)
Lester Lu918fe692017-08-17 14:39:29 -07001104 ilgt4(tmp[i], out[i], lgtmtx_col[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -07001105 else
1106#endif
1107 IHT_8x4[tx_type].cols(tmp[i], out[i]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001108 }
1109
Jingning Hanec419e02016-11-01 18:19:30 -07001110#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001111 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n2);
Jingning Hanec419e02016-11-01 18:19:30 -07001112#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001113
1114 // Sum with the destination
1115 for (i = 0; i < n; ++i) {
1116 for (j = 0; j < n2; ++j) {
1117 int d = i * stride + j;
1118 int s = j * outstride + i;
Monty Montgomeryabd94512017-10-14 00:41:42 -04001119#if CONFIG_DAALA_TX4 && CONFIG_DAALA_TX8
1120#if CONFIG_LGT
1121 if (use_lgt_col)
1122 // Output scaling cases 1, 3
1123 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
1124 else
1125#endif
1126 // Output scaling cases 2, 4
1127 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 4));
1128#else
1129 // Output scaling case 1
Yaowu Xuc27fc142016-08-22 16:08:15 -07001130 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
Monty Montgomeryabd94512017-10-14 00:41:42 -04001131#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001132 }
1133 }
1134}
1135
Debargha Mukherjee751de382016-12-13 02:54:22 -08001136void av1_iht4x16_64_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07001137 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07001138 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07001139#if CONFIG_MRC_TX
1140 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
1141#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001142#if CONFIG_DCT_ONLY
1143 assert(tx_type == DCT_DCT);
1144#endif
Debargha Mukherjee751de382016-12-13 02:54:22 -08001145 static const transform_2d IHT_4x16[] = {
1146 { aom_idct16_c, aom_idct4_c }, // DCT_DCT
1147 { aom_iadst16_c, aom_idct4_c }, // ADST_DCT
1148 { aom_idct16_c, aom_iadst4_c }, // DCT_ADST
1149 { aom_iadst16_c, aom_iadst4_c }, // ADST_ADST
1150#if CONFIG_EXT_TX
1151 { aom_iadst16_c, aom_idct4_c }, // FLIPADST_DCT
1152 { aom_idct16_c, aom_iadst4_c }, // DCT_FLIPADST
1153 { aom_iadst16_c, aom_iadst4_c }, // FLIPADST_FLIPADST
1154 { aom_iadst16_c, aom_iadst4_c }, // ADST_FLIPADST
1155 { aom_iadst16_c, aom_iadst4_c }, // FLIPADST_ADST
1156 { iidtx16_c, iidtx4_c }, // IDTX
1157 { aom_idct16_c, iidtx4_c }, // V_DCT
1158 { iidtx16_c, aom_idct4_c }, // H_DCT
1159 { aom_iadst16_c, iidtx4_c }, // V_ADST
1160 { iidtx16_c, aom_iadst4_c }, // H_ADST
1161 { aom_iadst16_c, iidtx4_c }, // V_FLIPADST
1162 { iidtx16_c, aom_iadst4_c }, // H_FLIPADST
1163#endif
1164 };
1165
1166 const int n = 4;
1167 const int n4 = 16;
1168 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001169 tran_low_t out[4][16], tmp[4][16], outtmp[4];
Debargha Mukherjee751de382016-12-13 02:54:22 -08001170 tran_low_t *outp = &out[0][0];
1171 int outstride = n4;
1172
Lester Lu708c1ec2017-06-14 14:54:49 -07001173#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -07001174 const tran_high_t *lgtmtx_row[1];
1175 int use_lgt_row = get_lgt4(txfm_param, 0, lgtmtx_row);
Lester Lu708c1ec2017-06-14 14:54:49 -07001176#endif
1177
Debargha Mukherjee751de382016-12-13 02:54:22 -08001178 // inverse transform row vectors and transpose
1179 for (i = 0; i < n4; ++i) {
Lester Lu708c1ec2017-06-14 14:54:49 -07001180#if CONFIG_LGT
1181 if (use_lgt_row)
Lester Lu918fe692017-08-17 14:39:29 -07001182 ilgt4(input, outtmp, lgtmtx_row[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -07001183 else
1184#endif
1185 IHT_4x16[tx_type].rows(input, outtmp);
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001186 for (j = 0; j < n; ++j) tmp[j][i] = outtmp[j];
Debargha Mukherjee751de382016-12-13 02:54:22 -08001187 input += n;
1188 }
1189
1190 // inverse transform column vectors
Lester Lu708c1ec2017-06-14 14:54:49 -07001191 for (i = 0; i < n; ++i) {
1192 IHT_4x16[tx_type].cols(tmp[i], out[i]);
1193 }
Debargha Mukherjee751de382016-12-13 02:54:22 -08001194
1195#if CONFIG_EXT_TX
1196 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n4, n);
1197#endif
1198
1199 // Sum with the destination
1200 for (i = 0; i < n4; ++i) {
1201 for (j = 0; j < n; ++j) {
1202 int d = i * stride + j;
1203 int s = j * outstride + i;
1204 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
1205 }
1206 }
1207}
1208
1209void av1_iht16x4_64_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07001210 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07001211 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07001212#if CONFIG_MRC_TX
1213 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
1214#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001215#if CONFIG_DCT_ONLY
1216 assert(tx_type == DCT_DCT);
1217#endif
Debargha Mukherjee751de382016-12-13 02:54:22 -08001218 static const transform_2d IHT_16x4[] = {
1219 { aom_idct4_c, aom_idct16_c }, // DCT_DCT
1220 { aom_iadst4_c, aom_idct16_c }, // ADST_DCT
1221 { aom_idct4_c, aom_iadst16_c }, // DCT_ADST
1222 { aom_iadst4_c, aom_iadst16_c }, // ADST_ADST
1223#if CONFIG_EXT_TX
1224 { aom_iadst4_c, aom_idct16_c }, // FLIPADST_DCT
1225 { aom_idct4_c, aom_iadst16_c }, // DCT_FLIPADST
1226 { aom_iadst4_c, aom_iadst16_c }, // FLIPADST_FLIPADST
1227 { aom_iadst4_c, aom_iadst16_c }, // ADST_FLIPADST
1228 { aom_iadst4_c, aom_iadst16_c }, // FLIPADST_ADST
1229 { iidtx4_c, iidtx16_c }, // IDTX
1230 { aom_idct4_c, iidtx16_c }, // V_DCT
1231 { iidtx4_c, aom_idct16_c }, // H_DCT
1232 { aom_iadst4_c, iidtx16_c }, // V_ADST
1233 { iidtx4_c, aom_iadst16_c }, // H_ADST
1234 { aom_iadst4_c, iidtx16_c }, // V_FLIPADST
1235 { iidtx4_c, aom_iadst16_c }, // H_FLIPADST
1236#endif
1237 };
Lester Lud8b1ddc2017-07-06 16:13:29 -07001238
Debargha Mukherjee751de382016-12-13 02:54:22 -08001239 const int n = 4;
1240 const int n4 = 16;
1241
1242 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001243 tran_low_t out[16][4], tmp[16][4], outtmp[16];
Debargha Mukherjee751de382016-12-13 02:54:22 -08001244 tran_low_t *outp = &out[0][0];
1245 int outstride = n;
1246
Lester Lu708c1ec2017-06-14 14:54:49 -07001247#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -07001248 const tran_high_t *lgtmtx_col[1];
1249 int use_lgt_col = get_lgt4(txfm_param, 1, lgtmtx_col);
Lester Lu708c1ec2017-06-14 14:54:49 -07001250#endif
1251
Debargha Mukherjee751de382016-12-13 02:54:22 -08001252 // inverse transform row vectors and transpose
1253 for (i = 0; i < n; ++i) {
1254 IHT_16x4[tx_type].rows(input, outtmp);
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001255 for (j = 0; j < n4; ++j) tmp[j][i] = outtmp[j];
Debargha Mukherjee751de382016-12-13 02:54:22 -08001256 input += n4;
1257 }
1258
1259 // inverse transform column vectors
Lester Lu708c1ec2017-06-14 14:54:49 -07001260 for (i = 0; i < n4; ++i) {
1261#if CONFIG_LGT
1262 if (use_lgt_col)
Lester Lu918fe692017-08-17 14:39:29 -07001263 ilgt4(tmp[i], out[i], lgtmtx_col[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -07001264 else
1265#endif
1266 IHT_16x4[tx_type].cols(tmp[i], out[i]);
1267 }
Debargha Mukherjee751de382016-12-13 02:54:22 -08001268
1269#if CONFIG_EXT_TX
1270 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n4);
1271#endif
1272
1273 // Sum with the destination
1274 for (i = 0; i < n; ++i) {
1275 for (j = 0; j < n4; ++j) {
1276 int d = i * stride + j;
1277 int s = j * outstride + i;
1278 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
1279 }
1280 }
1281}
1282
Yaowu Xuf883b422016-08-30 14:01:10 -07001283void av1_iht8x16_128_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07001284 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07001285 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07001286#if CONFIG_MRC_TX
1287 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
1288#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001289#if CONFIG_DCT_ONLY
1290 assert(tx_type == DCT_DCT);
1291#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001292 static const transform_2d IHT_8x16[] = {
Monty Montgomery7eb44542017-10-19 20:47:51 -04001293#if CONFIG_DAALA_TX8 && CONFIG_DAALA_TX16
1294 { daala_idct16, daala_idct8 }, // DCT_DCT = 0
1295 { daala_idst16, daala_idct8 }, // ADST_DCT = 1
1296 { daala_idct16, daala_idst8 }, // DCT_ADST = 2
1297 { daala_idst16, daala_idst8 }, // ADST_ADST = 3
1298#if CONFIG_EXT_TX
1299 { daala_idst16, daala_idct8 }, // FLIPADST_DCT
1300 { daala_idct16, daala_idst8 }, // DCT_FLIPADST
1301 { daala_idst16, daala_idst8 }, // FLIPADST_FLIPADST
1302 { daala_idst16, daala_idst8 }, // ADST_FLIPADST
1303 { daala_idst16, daala_idst8 }, // FLIPADST_ADST
1304 { daala_idtx16, daala_idtx8 }, // IDTX
1305 { daala_idct16, daala_idtx8 }, // V_DCT
1306 { daala_idtx16, daala_idct8 }, // H_DCT
1307 { daala_idst16, daala_idtx8 }, // V_ADST
1308 { daala_idtx16, daala_idst8 }, // H_ADST
1309 { daala_idst16, daala_idtx8 }, // V_FLIPADST
1310 { daala_idtx16, daala_idst8 }, // H_FLIPADST
1311#endif
1312#else
Luca Barbatof0f98572016-09-03 12:14:15 +02001313 { aom_idct16_c, aom_idct8_c }, // DCT_DCT
1314 { aom_iadst16_c, aom_idct8_c }, // ADST_DCT
1315 { aom_idct16_c, aom_iadst8_c }, // DCT_ADST
1316 { aom_iadst16_c, aom_iadst8_c }, // ADST_ADST
Jingning Hanec419e02016-11-01 18:19:30 -07001317#if CONFIG_EXT_TX
Luca Barbatof0f98572016-09-03 12:14:15 +02001318 { aom_iadst16_c, aom_idct8_c }, // FLIPADST_DCT
1319 { aom_idct16_c, aom_iadst8_c }, // DCT_FLIPADST
1320 { aom_iadst16_c, aom_iadst8_c }, // FLIPADST_FLIPADST
1321 { aom_iadst16_c, aom_iadst8_c }, // ADST_FLIPADST
1322 { aom_iadst16_c, aom_iadst8_c }, // FLIPADST_ADST
1323 { iidtx16_c, iidtx8_c }, // IDTX
1324 { aom_idct16_c, iidtx8_c }, // V_DCT
1325 { iidtx16_c, aom_idct8_c }, // H_DCT
1326 { aom_iadst16_c, iidtx8_c }, // V_ADST
1327 { iidtx16_c, aom_iadst8_c }, // H_ADST
1328 { aom_iadst16_c, iidtx8_c }, // V_FLIPADST
1329 { iidtx16_c, aom_iadst8_c }, // H_FLIPADST
Jingning Hanec419e02016-11-01 18:19:30 -07001330#endif
Monty Montgomery7eb44542017-10-19 20:47:51 -04001331#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001332 };
1333
1334 const int n = 8;
1335 const int n2 = 16;
1336 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001337 tran_low_t out[8][16], tmp[8][16], outtmp[8];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001338 tran_low_t *outp = &out[0][0];
1339 int outstride = n2;
1340
Lester Lu708c1ec2017-06-14 14:54:49 -07001341#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -07001342 const tran_high_t *lgtmtx_row[1];
1343 int use_lgt_row = get_lgt8(txfm_param, 0, lgtmtx_row);
Lester Lu708c1ec2017-06-14 14:54:49 -07001344#endif
1345
Monty Montgomery7eb44542017-10-19 20:47:51 -04001346 // Multi-way scaling matrix (bits):
1347 // LGT/AV1 row, AV1 col input+0, rowTX+1, mid+.5, colTX+1.5, out-6 == -3
1348 // LGT row, Daala col input+0, rowTX+1, mid+0, colTX+0, out-4 == -3
1349 // Daala row, LGT col N/A (no 16-point LGT)
1350 // Daala row,col input+1, rowTX+0, mid+0, colTX+0, out-4 == -3
1351
Yaowu Xuc27fc142016-08-22 16:08:15 -07001352 // inverse transform row vectors and transpose
1353 for (i = 0; i < n2; ++i) {
Lester Lu708c1ec2017-06-14 14:54:49 -07001354#if CONFIG_LGT
Monty Montgomery7eb44542017-10-19 20:47:51 -04001355 if (use_lgt_row) {
1356 // Scaling cases 1 and 2 above
1357 // No input scaling
1358 // Row transform (LGT; scales up 1 bit)
Lester Lu918fe692017-08-17 14:39:29 -07001359 ilgt8(input, outtmp, lgtmtx_row[0]);
Monty Montgomery7eb44542017-10-19 20:47:51 -04001360 // Transpose and mid scaling
1361 for (j = 0; j < n; ++j) {
1362#if CONFIG_DAALA_TX8 && CONFIG_DAALA_TX16
1363 // Mid scaling case 2
1364 tmp[j][i] = outtmp[j];
1365#else
1366 // Mid scaling case 1
1367 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
Lester Lu708c1ec2017-06-14 14:54:49 -07001368#endif
Monty Montgomery7eb44542017-10-19 20:47:51 -04001369 }
1370 } else {
1371#endif
1372#if CONFIG_DAALA_TX8 && CONFIG_DAALA_TX16
1373 tran_low_t temp_in[8];
1374 // Input scaling case 4
1375 for (j = 0; j < n; j++) temp_in[j] = input[j] * 2;
1376 // Row transform (Daala does not scale)
1377 IHT_8x16[tx_type].rows(temp_in, outtmp);
1378 // Transpose (no mid scaling)
1379 for (j = 0; j < n; ++j) tmp[j][i] = outtmp[j];
1380#else
1381 // Case 1; no input scaling
1382 // Row transform (AV1 scales up 1 bit)
1383 IHT_8x16[tx_type].rows(input, outtmp);
1384 // Transpose and mid scaling up .5 bits
Yaowu Xuc27fc142016-08-22 16:08:15 -07001385 for (j = 0; j < n; ++j)
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001386 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
Monty Montgomery7eb44542017-10-19 20:47:51 -04001387#endif
1388#if CONFIG_LGT
1389 }
1390#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001391 input += n;
1392 }
1393
1394 // inverse transform column vectors
Monty Montgomery7eb44542017-10-19 20:47:51 -04001395 // AV1 column TX scales up by 1.5 bit, Daala does not scale
Yaowu Xuc27fc142016-08-22 16:08:15 -07001396 for (i = 0; i < n; ++i) {
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001397 IHT_8x16[tx_type].cols(tmp[i], out[i]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001398 }
1399
Jingning Hanec419e02016-11-01 18:19:30 -07001400#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001401 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n2, n);
Jingning Hanec419e02016-11-01 18:19:30 -07001402#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001403
1404 // Sum with the destination
1405 for (i = 0; i < n2; ++i) {
1406 for (j = 0; j < n; ++j) {
1407 int d = i * stride + j;
1408 int s = j * outstride + i;
Monty Montgomery7eb44542017-10-19 20:47:51 -04001409#if CONFIG_DAALA_TX8 && CONFIG_DAALA_TX16
1410 // Output scaling cases 2 and 4
1411 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 4));
1412#else
1413 // Output scaling case 1
Yaowu Xuc27fc142016-08-22 16:08:15 -07001414 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
Monty Montgomery7eb44542017-10-19 20:47:51 -04001415#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001416 }
1417 }
1418}
1419
Yaowu Xuf883b422016-08-30 14:01:10 -07001420void av1_iht16x8_128_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07001421 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07001422 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07001423#if CONFIG_MRC_TX
1424 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
1425#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001426#if CONFIG_DCT_ONLY
1427 assert(tx_type == DCT_DCT);
1428#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001429 static const transform_2d IHT_16x8[] = {
Monty Montgomery7eb44542017-10-19 20:47:51 -04001430#if CONFIG_DAALA_TX8 && CONFIG_DAALA_TX16
1431 { daala_idct8, daala_idct16 }, // DCT_DCT = 0
1432 { daala_idst8, daala_idct16 }, // ADST_DCT = 1
1433 { daala_idct8, daala_idst16 }, // DCT_ADST = 2
1434 { daala_idst8, daala_idst16 }, // ADST_ADST = 3
1435#if CONFIG_EXT_TX
1436 { daala_idst8, daala_idct16 }, // FLIPADST_DCT
1437 { daala_idct8, daala_idst16 }, // DCT_FLIPADST
1438 { daala_idst8, daala_idst16 }, // FLIPADST_FLIPADST
1439 { daala_idst8, daala_idst16 }, // ADST_FLIPADST
1440 { daala_idst8, daala_idst16 }, // FLIPADST_ADST
1441 { daala_idtx8, daala_idtx16 }, // IDTX
1442 { daala_idct8, daala_idtx16 }, // V_DCT
1443 { daala_idtx8, daala_idct16 }, // H_DCT
1444 { daala_idst8, daala_idtx16 }, // V_ADST
1445 { daala_idtx8, daala_idst16 }, // H_ADST
1446 { daala_idst8, daala_idtx16 }, // V_FLIPADST
1447 { daala_idtx8, daala_idst16 }, // H_FLIPADST
1448#endif
1449#else
Luca Barbatof0f98572016-09-03 12:14:15 +02001450 { aom_idct8_c, aom_idct16_c }, // DCT_DCT
1451 { aom_iadst8_c, aom_idct16_c }, // ADST_DCT
1452 { aom_idct8_c, aom_iadst16_c }, // DCT_ADST
1453 { aom_iadst8_c, aom_iadst16_c }, // ADST_ADST
Jingning Hanec419e02016-11-01 18:19:30 -07001454#if CONFIG_EXT_TX
Luca Barbatof0f98572016-09-03 12:14:15 +02001455 { aom_iadst8_c, aom_idct16_c }, // FLIPADST_DCT
1456 { aom_idct8_c, aom_iadst16_c }, // DCT_FLIPADST
1457 { aom_iadst8_c, aom_iadst16_c }, // FLIPADST_FLIPADST
1458 { aom_iadst8_c, aom_iadst16_c }, // ADST_FLIPADST
1459 { aom_iadst8_c, aom_iadst16_c }, // FLIPADST_ADST
1460 { iidtx8_c, iidtx16_c }, // IDTX
1461 { aom_idct8_c, iidtx16_c }, // V_DCT
1462 { iidtx8_c, aom_idct16_c }, // H_DCT
1463 { aom_iadst8_c, iidtx16_c }, // V_ADST
1464 { iidtx8_c, aom_iadst16_c }, // H_ADST
1465 { aom_iadst8_c, iidtx16_c }, // V_FLIPADST
1466 { iidtx8_c, aom_iadst16_c }, // H_FLIPADST
Jingning Hanec419e02016-11-01 18:19:30 -07001467#endif
Monty Montgomery7eb44542017-10-19 20:47:51 -04001468#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001469 };
Lester Lud8b1ddc2017-07-06 16:13:29 -07001470
Yaowu Xuc27fc142016-08-22 16:08:15 -07001471 const int n = 8;
1472 const int n2 = 16;
1473
1474 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001475 tran_low_t out[16][8], tmp[16][8], outtmp[16];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001476 tran_low_t *outp = &out[0][0];
1477 int outstride = n;
1478
Lester Lu708c1ec2017-06-14 14:54:49 -07001479#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -07001480 const tran_high_t *lgtmtx_col[1];
1481 int use_lgt_col = get_lgt8(txfm_param, 1, lgtmtx_col);
Lester Lu708c1ec2017-06-14 14:54:49 -07001482#endif
1483
Monty Montgomery7eb44542017-10-19 20:47:51 -04001484 // Multi-way scaling matrix (bits):
1485 // AV1 row, LGT/AV1 col input+0, rowTX+1.5, mid+.5, colTX+1, out-6 == -3
1486 // LGT row, Daala col N/A (no 16-point LGT)
1487 // Daala row, LGT col input+1, rowTX+0, mid+1, colTX+1, out-6 == -3
1488 // Daala row, col input+1, rowTX+0, mid+0, colTX+0, out-4 == -3
1489
Yaowu Xuc27fc142016-08-22 16:08:15 -07001490 // inverse transform row vectors and transpose
1491 for (i = 0; i < n; ++i) {
Monty Montgomery7eb44542017-10-19 20:47:51 -04001492#if CONFIG_DAALA_TX8 && CONFIG_DAALA_TX16
1493 tran_low_t temp_in[16];
1494 // Input scaling cases 3 and 4
1495 for (j = 0; j < n2; j++) temp_in[j] = input[j] * 2;
1496 // Daala row TX, no scaling
1497 IHT_16x8[tx_type].rows(temp_in, outtmp);
1498// Transpose and mid scaling
1499#if CONFIG_LGT
1500 if (use_lgt_col)
1501 // Case 3
1502 for (j = 0; j < n2; ++j) tmp[j][i] = outtmp[j] * 2;
1503 else
1504#endif
1505 // Case 4
1506 for (j = 0; j < n2; ++j) tmp[j][i] = outtmp[j];
1507#else
1508 // Case 1
1509 // No input scaling
1510 // Row transform, AV1 scales up by 1.5 bits
Yaowu Xuc27fc142016-08-22 16:08:15 -07001511 IHT_16x8[tx_type].rows(input, outtmp);
Monty Montgomery7eb44542017-10-19 20:47:51 -04001512 // Transpose and mid scaling up .5 bits
Yaowu Xuc27fc142016-08-22 16:08:15 -07001513 for (j = 0; j < n2; ++j)
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001514 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
Monty Montgomery7eb44542017-10-19 20:47:51 -04001515#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001516 input += n2;
1517 }
1518
1519 // inverse transform column vectors
Monty Montgomery7eb44542017-10-19 20:47:51 -04001520 // AV!/LGT scales up by 1 bit, Daala does not scale
Yaowu Xuc27fc142016-08-22 16:08:15 -07001521 for (i = 0; i < n2; ++i) {
Lester Lu708c1ec2017-06-14 14:54:49 -07001522#if CONFIG_LGT
1523 if (use_lgt_col)
Lester Lu918fe692017-08-17 14:39:29 -07001524 ilgt8(tmp[i], out[i], lgtmtx_col[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -07001525 else
1526#endif
1527 IHT_16x8[tx_type].cols(tmp[i], out[i]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001528 }
1529
Jingning Hanec419e02016-11-01 18:19:30 -07001530#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001531 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n2);
Jingning Hanec419e02016-11-01 18:19:30 -07001532#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001533
1534 // Sum with the destination
1535 for (i = 0; i < n; ++i) {
1536 for (j = 0; j < n2; ++j) {
1537 int d = i * stride + j;
1538 int s = j * outstride + i;
Monty Montgomery7eb44542017-10-19 20:47:51 -04001539// Output scaling
1540#if CONFIG_DAALA_TX8 && CONFIG_DAALA_TX16
1541#if CONFIG_LGT
1542 if (use_lgt_col)
1543 // case 3
1544 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
1545 else
1546#endif
1547 // case 4
1548 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 4));
1549#else
1550 // case 1
Yaowu Xuc27fc142016-08-22 16:08:15 -07001551 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
Monty Montgomery7eb44542017-10-19 20:47:51 -04001552#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001553 }
1554 }
1555}
1556
Debargha Mukherjee751de382016-12-13 02:54:22 -08001557void av1_iht8x32_256_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07001558 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07001559 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07001560#if CONFIG_MRC_TX
1561 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
1562#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001563#if CONFIG_DCT_ONLY
1564 assert(tx_type == DCT_DCT);
1565#endif
Debargha Mukherjee751de382016-12-13 02:54:22 -08001566 static const transform_2d IHT_8x32[] = {
1567 { aom_idct32_c, aom_idct8_c }, // DCT_DCT
1568 { ihalfright32_c, aom_idct8_c }, // ADST_DCT
1569 { aom_idct32_c, aom_iadst8_c }, // DCT_ADST
1570 { ihalfright32_c, aom_iadst8_c }, // ADST_ADST
1571#if CONFIG_EXT_TX
1572 { ihalfright32_c, aom_idct8_c }, // FLIPADST_DCT
1573 { aom_idct32_c, aom_iadst8_c }, // DCT_FLIPADST
1574 { ihalfright32_c, aom_iadst8_c }, // FLIPADST_FLIPADST
1575 { ihalfright32_c, aom_iadst8_c }, // ADST_FLIPADST
1576 { ihalfright32_c, aom_iadst8_c }, // FLIPADST_ADST
1577 { iidtx32_c, iidtx8_c }, // IDTX
1578 { aom_idct32_c, iidtx8_c }, // V_DCT
1579 { iidtx32_c, aom_idct8_c }, // H_DCT
1580 { ihalfright32_c, iidtx8_c }, // V_ADST
1581 { iidtx32_c, aom_iadst8_c }, // H_ADST
1582 { ihalfright32_c, iidtx8_c }, // V_FLIPADST
1583 { iidtx32_c, aom_iadst8_c }, // H_FLIPADST
1584#endif
1585 };
1586
1587 const int n = 8;
1588 const int n4 = 32;
1589 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001590 tran_low_t out[8][32], tmp[8][32], outtmp[8];
Debargha Mukherjee751de382016-12-13 02:54:22 -08001591 tran_low_t *outp = &out[0][0];
1592 int outstride = n4;
1593
Lester Lu708c1ec2017-06-14 14:54:49 -07001594#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -07001595 const tran_high_t *lgtmtx_row[1];
1596 int use_lgt_row = get_lgt8(txfm_param, 0, lgtmtx_row);
Lester Lu708c1ec2017-06-14 14:54:49 -07001597#endif
1598
Debargha Mukherjee751de382016-12-13 02:54:22 -08001599 // inverse transform row vectors and transpose
1600 for (i = 0; i < n4; ++i) {
Lester Lu708c1ec2017-06-14 14:54:49 -07001601#if CONFIG_LGT
1602 if (use_lgt_row)
Lester Lu918fe692017-08-17 14:39:29 -07001603 ilgt8(input, outtmp, lgtmtx_row[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -07001604 else
1605#endif
1606 IHT_8x32[tx_type].rows(input, outtmp);
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001607 for (j = 0; j < n; ++j) tmp[j][i] = outtmp[j];
Debargha Mukherjee751de382016-12-13 02:54:22 -08001608 input += n;
1609 }
1610
1611 // inverse transform column vectors
Lester Lu708c1ec2017-06-14 14:54:49 -07001612 for (i = 0; i < n; ++i) {
1613 IHT_8x32[tx_type].cols(tmp[i], out[i]);
1614 }
Debargha Mukherjee751de382016-12-13 02:54:22 -08001615
1616#if CONFIG_EXT_TX
1617 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n4, n);
1618#endif
1619
1620 // Sum with the destination
1621 for (i = 0; i < n4; ++i) {
1622 for (j = 0; j < n; ++j) {
1623 int d = i * stride + j;
1624 int s = j * outstride + i;
1625 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
1626 }
1627 }
1628}
1629
1630void av1_iht32x8_256_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07001631 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07001632 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07001633#if CONFIG_MRC_TX
1634 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
1635#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001636#if CONFIG_DCT_ONLY
1637 assert(tx_type == DCT_DCT);
1638#endif
Debargha Mukherjee751de382016-12-13 02:54:22 -08001639 static const transform_2d IHT_32x8[] = {
1640 { aom_idct8_c, aom_idct32_c }, // DCT_DCT
1641 { aom_iadst8_c, aom_idct32_c }, // ADST_DCT
1642 { aom_idct8_c, ihalfright32_c }, // DCT_ADST
1643 { aom_iadst8_c, ihalfright32_c }, // ADST_ADST
1644#if CONFIG_EXT_TX
1645 { aom_iadst8_c, aom_idct32_c }, // FLIPADST_DCT
1646 { aom_idct8_c, ihalfright32_c }, // DCT_FLIPADST
1647 { aom_iadst8_c, ihalfright32_c }, // FLIPADST_FLIPADST
1648 { aom_iadst8_c, ihalfright32_c }, // ADST_FLIPADST
1649 { aom_iadst8_c, ihalfright32_c }, // FLIPADST_ADST
1650 { iidtx8_c, iidtx32_c }, // IDTX
1651 { aom_idct8_c, iidtx32_c }, // V_DCT
1652 { iidtx8_c, aom_idct32_c }, // H_DCT
1653 { aom_iadst8_c, iidtx32_c }, // V_ADST
1654 { iidtx8_c, ihalfright32_c }, // H_ADST
1655 { aom_iadst8_c, iidtx32_c }, // V_FLIPADST
1656 { iidtx8_c, ihalfright32_c }, // H_FLIPADST
1657#endif
1658 };
Lester Lud8b1ddc2017-07-06 16:13:29 -07001659
Debargha Mukherjee751de382016-12-13 02:54:22 -08001660 const int n = 8;
1661 const int n4 = 32;
1662
1663 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001664 tran_low_t out[32][8], tmp[32][8], outtmp[32];
Debargha Mukherjee751de382016-12-13 02:54:22 -08001665 tran_low_t *outp = &out[0][0];
1666 int outstride = n;
1667
Lester Lu708c1ec2017-06-14 14:54:49 -07001668#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -07001669 const tran_high_t *lgtmtx_col[1];
1670 int use_lgt_col = get_lgt4(txfm_param, 1, lgtmtx_col);
Lester Lu708c1ec2017-06-14 14:54:49 -07001671#endif
1672
Debargha Mukherjee751de382016-12-13 02:54:22 -08001673 // inverse transform row vectors and transpose
1674 for (i = 0; i < n; ++i) {
1675 IHT_32x8[tx_type].rows(input, outtmp);
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001676 for (j = 0; j < n4; ++j) tmp[j][i] = outtmp[j];
Debargha Mukherjee751de382016-12-13 02:54:22 -08001677 input += n4;
1678 }
1679
1680 // inverse transform column vectors
Lester Lu708c1ec2017-06-14 14:54:49 -07001681 for (i = 0; i < n4; ++i) {
1682#if CONFIG_LGT
1683 if (use_lgt_col)
Lester Lu918fe692017-08-17 14:39:29 -07001684 ilgt8(tmp[i], out[i], lgtmtx_col[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -07001685 else
1686#endif
1687 IHT_32x8[tx_type].cols(tmp[i], out[i]);
1688 }
Debargha Mukherjee751de382016-12-13 02:54:22 -08001689
1690#if CONFIG_EXT_TX
1691 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n4);
1692#endif
1693
1694 // Sum with the destination
1695 for (i = 0; i < n; ++i) {
1696 for (j = 0; j < n4; ++j) {
1697 int d = i * stride + j;
1698 int s = j * outstride + i;
1699 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
1700 }
1701 }
1702}
1703
Yaowu Xuf883b422016-08-30 14:01:10 -07001704void av1_iht16x32_512_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07001705 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07001706 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07001707#if CONFIG_MRC_TX
1708 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
1709#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001710#if CONFIG_DCT_ONLY
1711 assert(tx_type == DCT_DCT);
1712#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001713 static const transform_2d IHT_16x32[] = {
Monty Montgomeryad396852017-10-20 03:35:26 -04001714#if CONFIG_DAALA_TX16 && CONFIG_DAALA_TX32
1715 { daala_idct32, daala_idct16 }, // DCT_DCT = 0
1716 { daala_idst32, daala_idct16 }, // ADST_DCT = 1
1717 { daala_idct32, daala_idst16 }, // DCT_ADST = 2
1718 { daala_idst32, daala_idst16 }, // ADST_ADST = 3
1719#if CONFIG_EXT_TX
1720 { daala_idst32, daala_idct16 }, // FLIPADST_DCT
1721 { daala_idct32, daala_idst16 }, // DCT_FLIPADST
1722 { daala_idst32, daala_idst16 }, // FLIPADST_FLIPADST
1723 { daala_idst32, daala_idst16 }, // ADST_FLIPADST
1724 { daala_idst32, daala_idst16 }, // FLIPADST_ADST
1725 { daala_idtx32, daala_idtx16 }, // IDTX
1726 { daala_idct32, daala_idtx16 }, // V_DCT
1727 { daala_idtx32, daala_idct16 }, // H_DCT
1728 { daala_idst32, daala_idtx16 }, // V_ADST
1729 { daala_idtx32, daala_idst16 }, // H_ADST
1730 { daala_idst32, daala_idtx16 }, // V_FLIPADST
1731 { daala_idtx32, daala_idst16 }, // H_FLIPADST
1732#endif
1733#else
Luca Barbatof0f98572016-09-03 12:14:15 +02001734 { aom_idct32_c, aom_idct16_c }, // DCT_DCT
1735 { ihalfright32_c, aom_idct16_c }, // ADST_DCT
1736 { aom_idct32_c, aom_iadst16_c }, // DCT_ADST
1737 { ihalfright32_c, aom_iadst16_c }, // ADST_ADST
Jingning Hanec419e02016-11-01 18:19:30 -07001738#if CONFIG_EXT_TX
Luca Barbatof0f98572016-09-03 12:14:15 +02001739 { ihalfright32_c, aom_idct16_c }, // FLIPADST_DCT
1740 { aom_idct32_c, aom_iadst16_c }, // DCT_FLIPADST
1741 { ihalfright32_c, aom_iadst16_c }, // FLIPADST_FLIPADST
1742 { ihalfright32_c, aom_iadst16_c }, // ADST_FLIPADST
1743 { ihalfright32_c, aom_iadst16_c }, // FLIPADST_ADST
1744 { iidtx32_c, iidtx16_c }, // IDTX
1745 { aom_idct32_c, iidtx16_c }, // V_DCT
1746 { iidtx32_c, aom_idct16_c }, // H_DCT
1747 { ihalfright32_c, iidtx16_c }, // V_ADST
1748 { iidtx32_c, aom_iadst16_c }, // H_ADST
1749 { ihalfright32_c, iidtx16_c }, // V_FLIPADST
1750 { iidtx32_c, aom_iadst16_c }, // H_FLIPADST
Jingning Hanec419e02016-11-01 18:19:30 -07001751#endif
Monty Montgomeryad396852017-10-20 03:35:26 -04001752#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001753 };
1754
1755 const int n = 16;
1756 const int n2 = 32;
1757 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001758 tran_low_t out[16][32], tmp[16][32], outtmp[16];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001759 tran_low_t *outp = &out[0][0];
1760 int outstride = n2;
1761
1762 // inverse transform row vectors and transpose
1763 for (i = 0; i < n2; ++i) {
Monty Montgomeryad396852017-10-20 03:35:26 -04001764#if CONFIG_DAALA_TX16 && CONFIG_DAALA_TX32
1765 tran_low_t temp_in[16];
1766 for (j = 0; j < n; j++) temp_in[j] = input[j] * 2;
1767 IHT_16x32[tx_type].rows(temp_in, outtmp);
1768 for (j = 0; j < n; ++j) tmp[j][i] = outtmp[j] * 4;
1769#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001770 IHT_16x32[tx_type].rows(input, outtmp);
1771 for (j = 0; j < n; ++j)
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001772 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
Monty Montgomeryad396852017-10-20 03:35:26 -04001773#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001774 input += n;
1775 }
1776
1777 // inverse transform column vectors
Lester Lu708c1ec2017-06-14 14:54:49 -07001778 for (i = 0; i < n; ++i) IHT_16x32[tx_type].cols(tmp[i], out[i]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001779
Jingning Hanec419e02016-11-01 18:19:30 -07001780#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001781 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n2, n);
Jingning Hanec419e02016-11-01 18:19:30 -07001782#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001783
1784 // Sum with the destination
1785 for (i = 0; i < n2; ++i) {
1786 for (j = 0; j < n; ++j) {
1787 int d = i * stride + j;
1788 int s = j * outstride + i;
Monty Montgomeryad396852017-10-20 03:35:26 -04001789#if CONFIG_DAALA_TX16 && CONFIG_DAALA_TX32
1790 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
1791#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001792 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
Monty Montgomeryad396852017-10-20 03:35:26 -04001793#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001794 }
1795 }
1796}
1797
Yaowu Xuf883b422016-08-30 14:01:10 -07001798void av1_iht32x16_512_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07001799 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07001800 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07001801#if CONFIG_MRC_TX
1802 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
1803#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001804#if CONFIG_DCT_ONLY
1805 assert(tx_type == DCT_DCT);
1806#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001807 static const transform_2d IHT_32x16[] = {
Monty Montgomeryad396852017-10-20 03:35:26 -04001808#if CONFIG_DAALA_TX16 && CONFIG_DAALA_TX32
1809 { daala_idct16, daala_idct32 }, // DCT_DCT = 0
1810 { daala_idst16, daala_idct32 }, // ADST_DCT = 1
1811 { daala_idct16, daala_idst32 }, // DCT_ADST = 2
1812 { daala_idst16, daala_idst32 }, // ADST_ADST = 3
1813#if CONFIG_EXT_TX
1814 { daala_idst16, daala_idct32 }, // FLIPADST_DCT
1815 { daala_idct16, daala_idst32 }, // DCT_FLIPADST
1816 { daala_idst16, daala_idst32 }, // FLIPADST_FLIPADST
1817 { daala_idst16, daala_idst32 }, // ADST_FLIPADST
1818 { daala_idst16, daala_idst32 }, // FLIPADST_ADST
1819 { daala_idtx16, daala_idtx32 }, // IDTX
1820 { daala_idct16, daala_idtx32 }, // V_DCT
1821 { daala_idtx16, daala_idct32 }, // H_DCT
1822 { daala_idst16, daala_idtx32 }, // V_ADST
1823 { daala_idtx16, daala_idst32 }, // H_ADST
1824 { daala_idst16, daala_idtx32 }, // V_FLIPADST
1825 { daala_idtx16, daala_idst32 }, // H_FLIPADST
1826#endif
1827#else
Luca Barbatof0f98572016-09-03 12:14:15 +02001828 { aom_idct16_c, aom_idct32_c }, // DCT_DCT
1829 { aom_iadst16_c, aom_idct32_c }, // ADST_DCT
1830 { aom_idct16_c, ihalfright32_c }, // DCT_ADST
1831 { aom_iadst16_c, ihalfright32_c }, // ADST_ADST
Jingning Hanec419e02016-11-01 18:19:30 -07001832#if CONFIG_EXT_TX
Luca Barbatof0f98572016-09-03 12:14:15 +02001833 { aom_iadst16_c, aom_idct32_c }, // FLIPADST_DCT
1834 { aom_idct16_c, ihalfright32_c }, // DCT_FLIPADST
1835 { aom_iadst16_c, ihalfright32_c }, // FLIPADST_FLIPADST
1836 { aom_iadst16_c, ihalfright32_c }, // ADST_FLIPADST
1837 { aom_iadst16_c, ihalfright32_c }, // FLIPADST_ADST
1838 { iidtx16_c, iidtx32_c }, // IDTX
1839 { aom_idct16_c, iidtx32_c }, // V_DCT
1840 { iidtx16_c, aom_idct32_c }, // H_DCT
1841 { aom_iadst16_c, iidtx32_c }, // V_ADST
1842 { iidtx16_c, ihalfright32_c }, // H_ADST
1843 { aom_iadst16_c, iidtx32_c }, // V_FLIPADST
1844 { iidtx16_c, ihalfright32_c }, // H_FLIPADST
Jingning Hanec419e02016-11-01 18:19:30 -07001845#endif
Monty Montgomeryad396852017-10-20 03:35:26 -04001846#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001847 };
1848 const int n = 16;
1849 const int n2 = 32;
1850
1851 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001852 tran_low_t out[32][16], tmp[32][16], outtmp[32];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001853 tran_low_t *outp = &out[0][0];
1854 int outstride = n;
1855
1856 // inverse transform row vectors and transpose
1857 for (i = 0; i < n; ++i) {
Monty Montgomeryad396852017-10-20 03:35:26 -04001858#if CONFIG_DAALA_TX16 && CONFIG_DAALA_TX32
1859 tran_low_t temp_in[32];
1860 for (j = 0; j < n2; j++) temp_in[j] = input[j] * 2;
1861 IHT_32x16[tx_type].rows(temp_in, outtmp);
1862 for (j = 0; j < n2; ++j) tmp[j][i] = outtmp[j] * 4;
1863#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001864 IHT_32x16[tx_type].rows(input, outtmp);
1865 for (j = 0; j < n2; ++j)
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001866 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
Monty Montgomeryad396852017-10-20 03:35:26 -04001867#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001868 input += n2;
1869 }
1870
1871 // inverse transform column vectors
Lester Lu708c1ec2017-06-14 14:54:49 -07001872 for (i = 0; i < n2; ++i) IHT_32x16[tx_type].cols(tmp[i], out[i]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001873
Jingning Hanec419e02016-11-01 18:19:30 -07001874#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001875 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n2);
Jingning Hanec419e02016-11-01 18:19:30 -07001876#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001877
1878 // Sum with the destination
1879 for (i = 0; i < n; ++i) {
1880 for (j = 0; j < n2; ++j) {
1881 int d = i * stride + j;
1882 int s = j * outstride + i;
Monty Montgomeryad396852017-10-20 03:35:26 -04001883#if CONFIG_DAALA_TX16 && CONFIG_DAALA_TX32
1884 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
1885#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001886 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
Monty Montgomeryad396852017-10-20 03:35:26 -04001887#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001888 }
1889 }
1890}
Yaowu Xuc27fc142016-08-22 16:08:15 -07001891
Yaowu Xuf883b422016-08-30 14:01:10 -07001892void av1_iht8x8_64_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07001893 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07001894 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07001895#if CONFIG_MRC_TX
1896 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
1897#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001898#if CONFIG_DCT_ONLY
1899 assert(tx_type == DCT_DCT);
1900#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001901 static const transform_2d IHT_8[] = {
Nathan E. Eggee554f362017-10-04 14:44:38 -04001902#if CONFIG_DAALA_TX8
Nathan E. Egge8a873db2017-09-16 20:55:20 -04001903 { daala_idct8, daala_idct8 }, // DCT_DCT = 0
1904 { daala_idst8, daala_idct8 }, // ADST_DCT = 1
1905 { daala_idct8, daala_idst8 }, // DCT_ADST = 2
1906 { daala_idst8, daala_idst8 }, // ADST_ADST = 3
Nathan E. Egge75bfeb82017-09-16 20:41:24 -04001907#if CONFIG_EXT_TX
Nathan E. Egge8a873db2017-09-16 20:55:20 -04001908 { daala_idst8, daala_idct8 }, // FLIPADST_DCT
1909 { daala_idct8, daala_idst8 }, // DCT_FLIPADST
1910 { daala_idst8, daala_idst8 }, // FLIPADST_FLIPADST
1911 { daala_idst8, daala_idst8 }, // ADST_FLIPADST
1912 { daala_idst8, daala_idst8 }, // FLIPADST_ADST
Nathan E. Egge3f45fb32017-09-18 11:34:48 -04001913 { daala_idtx8, daala_idtx8 }, // IDTX
1914 { daala_idct8, daala_idtx8 }, // V_DCT
1915 { daala_idtx8, daala_idct8 }, // H_DCT
1916 { daala_idst8, daala_idtx8 }, // V_ADST
1917 { daala_idtx8, daala_idst8 }, // H_ADST
1918 { daala_idst8, daala_idtx8 }, // V_FLIPADST
1919 { daala_idtx8, daala_idst8 }, // H_FLIPADST
Nathan E. Egge75bfeb82017-09-16 20:41:24 -04001920#endif
1921#else
Luca Barbatof0f98572016-09-03 12:14:15 +02001922 { aom_idct8_c, aom_idct8_c }, // DCT_DCT = 0
1923 { aom_iadst8_c, aom_idct8_c }, // ADST_DCT = 1
1924 { aom_idct8_c, aom_iadst8_c }, // DCT_ADST = 2
1925 { aom_iadst8_c, aom_iadst8_c }, // ADST_ADST = 3
Yaowu Xuc27fc142016-08-22 16:08:15 -07001926#if CONFIG_EXT_TX
Luca Barbatof0f98572016-09-03 12:14:15 +02001927 { aom_iadst8_c, aom_idct8_c }, // FLIPADST_DCT
1928 { aom_idct8_c, aom_iadst8_c }, // DCT_FLIPADST
1929 { aom_iadst8_c, aom_iadst8_c }, // FLIPADST_FLIPADST
1930 { aom_iadst8_c, aom_iadst8_c }, // ADST_FLIPADST
1931 { aom_iadst8_c, aom_iadst8_c }, // FLIPADST_ADST
1932 { iidtx8_c, iidtx8_c }, // IDTX
1933 { aom_idct8_c, iidtx8_c }, // V_DCT
1934 { iidtx8_c, aom_idct8_c }, // H_DCT
1935 { aom_iadst8_c, iidtx8_c }, // V_ADST
1936 { iidtx8_c, aom_iadst8_c }, // H_ADST
1937 { aom_iadst8_c, iidtx8_c }, // V_FLIPADST
1938 { iidtx8_c, aom_iadst8_c }, // H_FLIPADST
Lester Lu708c1ec2017-06-14 14:54:49 -07001939#endif
Nathan E. Egge75bfeb82017-09-16 20:41:24 -04001940#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001941 };
1942
1943 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001944 tran_low_t tmp[8][8];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001945 tran_low_t out[8][8];
1946 tran_low_t *outp = &out[0][0];
1947 int outstride = 8;
1948
Lester Lu708c1ec2017-06-14 14:54:49 -07001949#if CONFIG_LGT
Lester Lu918fe692017-08-17 14:39:29 -07001950 const tran_high_t *lgtmtx_col[1];
1951 const tran_high_t *lgtmtx_row[1];
1952 int use_lgt_col = get_lgt8(txfm_param, 1, lgtmtx_col);
1953 int use_lgt_row = get_lgt8(txfm_param, 0, lgtmtx_row);
Lester Lu708c1ec2017-06-14 14:54:49 -07001954#endif
1955
Yaowu Xuc27fc142016-08-22 16:08:15 -07001956 // inverse transform row vectors
1957 for (i = 0; i < 8; ++i) {
Nathan E. Eggee554f362017-10-04 14:44:38 -04001958#if CONFIG_DAALA_TX8
Monty Montgomerycf18fe42017-07-11 21:33:25 -04001959 tran_low_t temp_in[8];
1960 for (j = 0; j < 8; j++) temp_in[j] = input[j] * 2;
1961 IHT_8[tx_type].rows(temp_in, out[i]);
1962#else
Lester Lu708c1ec2017-06-14 14:54:49 -07001963#if CONFIG_LGT
1964 if (use_lgt_row)
Lester Lu918fe692017-08-17 14:39:29 -07001965 ilgt8(input, out[i], lgtmtx_row[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -07001966 else
1967#endif
1968 IHT_8[tx_type].rows(input, out[i]);
Monty Montgomerycf18fe42017-07-11 21:33:25 -04001969#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001970 input += 8;
1971 }
1972
1973 // transpose
Jonathan Matthews362d0c72017-05-09 14:53:11 +01001974 for (i = 0; i < 8; i++) {
1975 for (j = 0; j < 8; j++) {
1976 tmp[j][i] = out[i][j];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001977 }
1978 }
1979
1980 // inverse transform column vectors
1981 for (i = 0; i < 8; ++i) {
Lester Lu708c1ec2017-06-14 14:54:49 -07001982#if CONFIG_LGT
1983 if (use_lgt_col)
Lester Lu918fe692017-08-17 14:39:29 -07001984 ilgt8(tmp[i], out[i], lgtmtx_col[0]);
Lester Lu708c1ec2017-06-14 14:54:49 -07001985 else
1986#endif
1987 IHT_8[tx_type].cols(tmp[i], out[i]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001988 }
1989
1990#if CONFIG_EXT_TX
1991 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 8, 8);
1992#endif
1993
1994 // Sum with the destination
1995 for (i = 0; i < 8; ++i) {
1996 for (j = 0; j < 8; ++j) {
1997 int d = i * stride + j;
1998 int s = j * outstride + i;
Nathan E. Eggee554f362017-10-04 14:44:38 -04001999#if CONFIG_DAALA_TX8
Monty Montgomerycf18fe42017-07-11 21:33:25 -04002000 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 4));
2001#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07002002 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
Monty Montgomerycf18fe42017-07-11 21:33:25 -04002003#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002004 }
2005 }
2006}
2007
Yaowu Xuf883b422016-08-30 14:01:10 -07002008void av1_iht16x16_256_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002009 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07002010 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07002011#if CONFIG_MRC_TX
2012 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
2013#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04002014#if CONFIG_DCT_ONLY
2015 assert(tx_type == DCT_DCT);
2016#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002017 static const transform_2d IHT_16[] = {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002018#if CONFIG_DAALA_TX16
Nathan E. Eggecbcff062017-09-16 22:32:19 -04002019 { daala_idct16, daala_idct16 }, // DCT_DCT = 0
2020 { daala_idst16, daala_idct16 }, // ADST_DCT = 1
2021 { daala_idct16, daala_idst16 }, // DCT_ADST = 2
2022 { daala_idst16, daala_idst16 }, // ADST_ADST = 3
Nathan E. Eggec5c1e562017-09-16 22:18:18 -04002023#if CONFIG_EXT_TX
Nathan E. Eggecbcff062017-09-16 22:32:19 -04002024 { daala_idst16, daala_idct16 }, // FLIPADST_DCT
2025 { daala_idct16, daala_idst16 }, // DCT_FLIPADST
2026 { daala_idst16, daala_idst16 }, // FLIPADST_FLIPADST
2027 { daala_idst16, daala_idst16 }, // ADST_FLIPADST
2028 { daala_idst16, daala_idst16 }, // FLIPADST_ADST
Nathan E. Egge74e7fd02017-09-18 11:40:31 -04002029 { daala_idtx16, daala_idtx16 }, // IDTX
2030 { daala_idct16, daala_idtx16 }, // V_DCT
2031 { daala_idtx16, daala_idct16 }, // H_DCT
2032 { daala_idst16, daala_idtx16 }, // V_ADST
2033 { daala_idtx16, daala_idst16 }, // H_ADST
2034 { daala_idst16, daala_idtx16 }, // V_FLIPADST
2035 { daala_idtx16, daala_idst16 }, // H_FLIPADST
Nathan E. Eggec5c1e562017-09-16 22:18:18 -04002036#endif
2037#else
Luca Barbatof0f98572016-09-03 12:14:15 +02002038 { aom_idct16_c, aom_idct16_c }, // DCT_DCT = 0
2039 { aom_iadst16_c, aom_idct16_c }, // ADST_DCT = 1
2040 { aom_idct16_c, aom_iadst16_c }, // DCT_ADST = 2
2041 { aom_iadst16_c, aom_iadst16_c }, // ADST_ADST = 3
Yaowu Xuc27fc142016-08-22 16:08:15 -07002042#if CONFIG_EXT_TX
Luca Barbatof0f98572016-09-03 12:14:15 +02002043 { aom_iadst16_c, aom_idct16_c }, // FLIPADST_DCT
2044 { aom_idct16_c, aom_iadst16_c }, // DCT_FLIPADST
2045 { aom_iadst16_c, aom_iadst16_c }, // FLIPADST_FLIPADST
2046 { aom_iadst16_c, aom_iadst16_c }, // ADST_FLIPADST
2047 { aom_iadst16_c, aom_iadst16_c }, // FLIPADST_ADST
2048 { iidtx16_c, iidtx16_c }, // IDTX
2049 { aom_idct16_c, iidtx16_c }, // V_DCT
2050 { iidtx16_c, aom_idct16_c }, // H_DCT
2051 { aom_iadst16_c, iidtx16_c }, // V_ADST
2052 { iidtx16_c, aom_iadst16_c }, // H_ADST
2053 { aom_iadst16_c, iidtx16_c }, // V_FLIPADST
2054 { iidtx16_c, aom_iadst16_c }, // H_FLIPADST
Lester Lu708c1ec2017-06-14 14:54:49 -07002055#endif
Nathan E. Eggec5c1e562017-09-16 22:18:18 -04002056#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002057 };
2058
2059 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01002060 tran_low_t tmp[16][16];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002061 tran_low_t out[16][16];
2062 tran_low_t *outp = &out[0][0];
2063 int outstride = 16;
2064
2065 // inverse transform row vectors
2066 for (i = 0; i < 16; ++i) {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002067#if CONFIG_DAALA_TX16
Monty Montgomerycb9c1c52017-07-17 18:15:30 -04002068 tran_low_t temp_in[16];
Sebastien Alaiwan77323262017-08-21 11:34:56 +02002069 for (j = 0; j < 16; j++) temp_in[j] = input[j] * 2;
Monty Montgomerycb9c1c52017-07-17 18:15:30 -04002070 IHT_16[tx_type].rows(temp_in, out[i]);
2071#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07002072 IHT_16[tx_type].rows(input, out[i]);
Monty Montgomerycb9c1c52017-07-17 18:15:30 -04002073#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002074 input += 16;
2075 }
2076
2077 // transpose
Jonathan Matthews362d0c72017-05-09 14:53:11 +01002078 for (i = 0; i < 16; i++) {
2079 for (j = 0; j < 16; j++) {
2080 tmp[j][i] = out[i][j];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002081 }
2082 }
2083
2084 // inverse transform column vectors
Lester Lu708c1ec2017-06-14 14:54:49 -07002085 for (i = 0; i < 16; ++i) IHT_16[tx_type].cols(tmp[i], out[i]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002086
2087#if CONFIG_EXT_TX
2088 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 16, 16);
2089#endif
2090
2091 // Sum with the destination
2092 for (i = 0; i < 16; ++i) {
2093 for (j = 0; j < 16; ++j) {
2094 int d = i * stride + j;
2095 int s = j * outstride + i;
Nathan E. Eggee554f362017-10-04 14:44:38 -04002096#if CONFIG_DAALA_TX16
Monty Montgomerycb9c1c52017-07-17 18:15:30 -04002097 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 4));
2098#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07002099 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
Monty Montgomerycb9c1c52017-07-17 18:15:30 -04002100#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002101 }
2102 }
2103}
2104
Nathan E. Eggee554f362017-10-04 14:44:38 -04002105#if CONFIG_EXT_TX || CONFIG_DAALA_TX32
Yaowu Xuf883b422016-08-30 14:01:10 -07002106void av1_iht32x32_1024_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002107 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07002108 const TX_TYPE tx_type = txfm_param->tx_type;
Monty Montgomerycb55dad2017-07-11 16:59:52 -04002109#if CONFIG_DCT_ONLY
2110 assert(tx_type == DCT_DCT);
2111#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002112 static const transform_2d IHT_32[] = {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002113#if CONFIG_DAALA_TX32
Nathan E. Eggedfd1a922017-09-16 23:35:30 -04002114 { daala_idct32, daala_idct32 }, // DCT_DCT
2115#if CONFIG_EXT_TX
Nathan E. Eggef6d3ba62017-09-18 15:40:08 -04002116 { daala_idst32, daala_idct32 }, // ADST_DCT
2117 { daala_idct32, daala_idst32 }, // DCT_ADST
2118 { daala_idst32, daala_idst32 }, // ADST_ADST
2119 { daala_idst32, daala_idct32 }, // FLIPADST_DCT
2120 { daala_idct32, daala_idst32 }, // DCT_FLIPADST
2121 { daala_idst32, daala_idst32 }, // FLIPADST_FLIPADST
2122 { daala_idst32, daala_idst32 }, // ADST_FLIPADST
2123 { daala_idst32, daala_idst32 }, // FLIPADST_ADST
2124 { daala_idtx32, daala_idtx32 }, // IDTX
2125 { daala_idct32, daala_idtx32 }, // V_DCT
2126 { daala_idtx32, daala_idct32 }, // H_DCT
2127 { daala_idst32, daala_idtx32 }, // V_ADST
2128 { daala_idtx32, daala_idst32 }, // H_ADST
2129 { daala_idst32, daala_idtx32 }, // V_FLIPADST
2130 { daala_idtx32, daala_idst32 }, // H_FLIPADST
Nathan E. Eggedfd1a922017-09-16 23:35:30 -04002131#endif
2132#else
2133 { aom_idct32_c, aom_idct32_c }, // DCT_DCT
Monty Montgomery2cb52ba2017-07-17 18:27:27 -04002134#if CONFIG_EXT_TX
Luca Barbatof0f98572016-09-03 12:14:15 +02002135 { ihalfright32_c, aom_idct32_c }, // ADST_DCT
2136 { aom_idct32_c, ihalfright32_c }, // DCT_ADST
Yaowu Xuc27fc142016-08-22 16:08:15 -07002137 { ihalfright32_c, ihalfright32_c }, // ADST_ADST
Luca Barbatof0f98572016-09-03 12:14:15 +02002138 { ihalfright32_c, aom_idct32_c }, // FLIPADST_DCT
2139 { aom_idct32_c, ihalfright32_c }, // DCT_FLIPADST
Yaowu Xuc27fc142016-08-22 16:08:15 -07002140 { ihalfright32_c, ihalfright32_c }, // FLIPADST_FLIPADST
2141 { ihalfright32_c, ihalfright32_c }, // ADST_FLIPADST
2142 { ihalfright32_c, ihalfright32_c }, // FLIPADST_ADST
2143 { iidtx32_c, iidtx32_c }, // IDTX
Luca Barbatof0f98572016-09-03 12:14:15 +02002144 { aom_idct32_c, iidtx32_c }, // V_DCT
2145 { iidtx32_c, aom_idct32_c }, // H_DCT
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002146 { ihalfright32_c, iidtx32_c }, // V_ADST
2147 { iidtx32_c, ihalfright32_c }, // H_ADST
2148 { ihalfright32_c, iidtx32_c }, // V_FLIPADST
2149 { iidtx32_c, ihalfright32_c }, // H_FLIPADST
Monty Montgomery2cb52ba2017-07-17 18:27:27 -04002150#endif
Nathan E. Eggedfd1a922017-09-16 23:35:30 -04002151#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002152 };
2153
2154 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01002155 tran_low_t tmp[32][32];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002156 tran_low_t out[32][32];
2157 tran_low_t *outp = &out[0][0];
2158 int outstride = 32;
2159
2160 // inverse transform row vectors
2161 for (i = 0; i < 32; ++i) {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002162#if CONFIG_DAALA_TX32
Monty Montgomery2cb52ba2017-07-17 18:27:27 -04002163 tran_low_t temp_in[32];
2164 for (j = 0; j < 32; j++) temp_in[j] = input[j] * 2;
2165 IHT_32[tx_type].rows(temp_in, out[i]);
2166#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07002167 IHT_32[tx_type].rows(input, out[i]);
Monty Montgomery2cb52ba2017-07-17 18:27:27 -04002168#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002169 input += 32;
2170 }
2171
2172 // transpose
Jonathan Matthews362d0c72017-05-09 14:53:11 +01002173 for (i = 0; i < 32; i++) {
2174 for (j = 0; j < 32; j++) {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002175#if CONFIG_DAALA_TX32
Monty Montgomery2cb52ba2017-07-17 18:27:27 -04002176 tmp[j][i] = out[i][j] * 4;
2177#else
Jonathan Matthews362d0c72017-05-09 14:53:11 +01002178 tmp[j][i] = out[i][j];
Monty Montgomery2cb52ba2017-07-17 18:27:27 -04002179#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002180 }
2181 }
2182
2183 // inverse transform column vectors
Lester Lu708c1ec2017-06-14 14:54:49 -07002184 for (i = 0; i < 32; ++i) IHT_32[tx_type].cols(tmp[i], out[i]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002185
2186 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 32, 32);
2187
2188 // Sum with the destination
2189 for (i = 0; i < 32; ++i) {
2190 for (j = 0; j < 32; ++j) {
2191 int d = i * stride + j;
2192 int s = j * outstride + i;
Nathan E. Eggee554f362017-10-04 14:44:38 -04002193#if CONFIG_DAALA_TX32
Monty Montgomery2cb52ba2017-07-17 18:27:27 -04002194 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
2195#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07002196 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
Monty Montgomery2cb52ba2017-07-17 18:27:27 -04002197#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002198 }
2199 }
2200}
Nathan E. Eggee554f362017-10-04 14:44:38 -04002201#endif // CONFIG_EXT_TX || CONFIG_DAALA_TX32
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002202
2203#if CONFIG_TX64X64
2204void av1_iht64x64_4096_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002205 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07002206 const TX_TYPE tx_type = txfm_param->tx_type;
Sarah Parker53f93db2017-07-11 17:20:04 -07002207#if CONFIG_MRC_TX
2208 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
2209#endif // CONFIG_MRC_TX
Monty Montgomerycb55dad2017-07-11 16:59:52 -04002210#if CONFIG_DCT_ONLY
2211 assert(tx_type == DCT_DCT);
2212#endif
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002213 static const transform_2d IHT_64[] = {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002214#if CONFIG_DAALA_TX64
Nathan E. Egge2496a852017-09-18 15:59:54 -04002215 { daala_idct64, daala_idct64 }, // DCT_DCT
2216 { daala_idst64, daala_idct64 }, // ADST_DCT
2217 { daala_idct64, daala_idst64 }, // DCT_ADST
2218 { daala_idst64, daala_idst64 }, // ADST_ADST
Nathan E. Egged8661142017-09-16 23:57:51 -04002219#if CONFIG_EXT_TX
Nathan E. Egge2496a852017-09-18 15:59:54 -04002220 { daala_idst64, daala_idct64 }, // FLIPADST_DCT
2221 { daala_idct64, daala_idst64 }, // DCT_FLIPADST
2222 { daala_idst64, daala_idst64 }, // FLIPADST_FLIPADST
2223 { daala_idst64, daala_idst64 }, // ADST_FLIPADST
2224 { daala_idst64, daala_idst64 }, // FLIPADST_ADST
2225 { daala_idtx64, daala_idtx64 }, // IDTX
2226 { daala_idct64, daala_idtx64 }, // V_DCT
2227 { daala_idtx64, daala_idct64 }, // H_DCT
2228 { daala_idst64, daala_idtx64 }, // V_ADST
2229 { daala_idtx64, daala_idst64 }, // H_ADST
2230 { daala_idst64, daala_idtx64 }, // V_FLIPADST
2231 { daala_idtx64, daala_idst64 }, // H_FLIPADST
Nathan E. Egged8661142017-09-16 23:57:51 -04002232#endif
2233#else
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002234 { idct64_col_c, idct64_row_c }, // DCT_DCT
2235 { ihalfright64_c, idct64_row_c }, // ADST_DCT
2236 { idct64_col_c, ihalfright64_c }, // DCT_ADST
2237 { ihalfright64_c, ihalfright64_c }, // ADST_ADST
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07002238#if CONFIG_EXT_TX
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002239 { ihalfright64_c, idct64_row_c }, // FLIPADST_DCT
2240 { idct64_col_c, ihalfright64_c }, // DCT_FLIPADST
2241 { ihalfright64_c, ihalfright64_c }, // FLIPADST_FLIPADST
2242 { ihalfright64_c, ihalfright64_c }, // ADST_FLIPADST
2243 { ihalfright64_c, ihalfright64_c }, // FLIPADST_ADST
2244 { iidtx64_c, iidtx64_c }, // IDTX
2245 { idct64_col_c, iidtx64_c }, // V_DCT
2246 { iidtx64_c, idct64_row_c }, // H_DCT
2247 { ihalfright64_c, iidtx64_c }, // V_ADST
2248 { iidtx64_c, ihalfright64_c }, // H_ADST
2249 { ihalfright64_c, iidtx64_c }, // V_FLIPADST
2250 { iidtx64_c, ihalfright64_c }, // H_FLIPADST
Lester Lu708c1ec2017-06-14 14:54:49 -07002251#endif
Nathan E. Egged8661142017-09-16 23:57:51 -04002252#endif
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002253 };
2254
2255 int i, j;
Jonathan Matthews362d0c72017-05-09 14:53:11 +01002256 tran_low_t tmp[64][64];
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002257 tran_low_t out[64][64];
2258 tran_low_t *outp = &out[0][0];
2259 int outstride = 64;
2260
2261 // inverse transform row vectors
2262 for (i = 0; i < 64; ++i) {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002263#if CONFIG_DAALA_TX64
Monty Montgomerya4e245a2017-07-22 00:48:31 -04002264 tran_low_t temp_in[64];
2265 for (j = 0; j < 64; j++) temp_in[j] = input[j] * 2;
2266 IHT_64[tx_type].rows(temp_in, out[i]);
2267// Do not rescale intermediate for Daala
2268#else
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002269 IHT_64[tx_type].rows(input, out[i]);
2270 for (j = 0; j < 64; ++j) out[i][j] = ROUND_POWER_OF_TWO(out[i][j], 1);
Monty Montgomerya4e245a2017-07-22 00:48:31 -04002271#endif
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002272 input += 64;
2273 }
2274
2275 // transpose
Jonathan Matthews362d0c72017-05-09 14:53:11 +01002276 for (i = 0; i < 64; i++) {
2277 for (j = 0; j < 64; j++) {
2278 tmp[j][i] = out[i][j];
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002279 }
2280 }
2281
2282 // inverse transform column vectors
Lester Lu708c1ec2017-06-14 14:54:49 -07002283 for (i = 0; i < 64; ++i) IHT_64[tx_type].cols(tmp[i], out[i]);
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002284
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07002285#if CONFIG_EXT_TX
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002286 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 64, 64);
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07002287#endif // CONFIG_EXT_TX
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002288
2289 // Sum with the destination
2290 for (i = 0; i < 64; ++i) {
2291 for (j = 0; j < 64; ++j) {
2292 int d = i * stride + j;
2293 int s = j * outstride + i;
Nathan E. Eggee554f362017-10-04 14:44:38 -04002294#if CONFIG_DAALA_TX64
Monty Montgomerya4e245a2017-07-22 00:48:31 -04002295 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 2));
2296#else
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002297 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
Monty Montgomerya4e245a2017-07-22 00:48:31 -04002298#endif
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002299 }
2300 }
2301}
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002302
2303void av1_iht64x32_2048_add_c(const tran_low_t *input, uint8_t *dest, int stride,
2304 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07002305 const TX_TYPE tx_type = txfm_param->tx_type;
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002306#if CONFIG_MRC_TX
2307 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
2308#endif // CONFIG_MRC_TX
2309#if CONFIG_DCT_ONLY
2310 assert(tx_type == DCT_DCT);
2311#endif
2312 static const transform_2d IHT_64x32[] = {
2313 { aom_idct32_c, idct64_row_c }, // DCT_DCT
2314 { ihalfright32_c, idct64_row_c }, // ADST_DCT
2315 { aom_idct32_c, ihalfright64_c }, // DCT_ADST
2316 { ihalfright32_c, ihalfright64_c }, // ADST_ADST
2317#if CONFIG_EXT_TX
2318 { ihalfright32_c, idct64_row_c }, // FLIPADST_DCT
2319 { aom_idct32_c, ihalfright64_c }, // DCT_FLIPADST
2320 { ihalfright32_c, ihalfright64_c }, // FLIPADST_FLIPADST
2321 { ihalfright32_c, ihalfright64_c }, // ADST_FLIPADST
2322 { ihalfright32_c, ihalfright64_c }, // FLIPADST_ADST
2323 { iidtx32_c, iidtx64_c }, // IDTX
2324 { aom_idct32_c, iidtx64_c }, // V_DCT
2325 { iidtx32_c, idct64_row_c }, // H_DCT
2326 { ihalfright32_c, iidtx64_c }, // V_ADST
2327 { iidtx32_c, ihalfright64_c }, // H_ADST
2328 { ihalfright32_c, iidtx64_c }, // V_FLIPADST
2329 { iidtx32_c, ihalfright64_c }, // H_FLIPADST
2330#endif
2331 };
2332 const int n = 32;
2333 const int n2 = 64;
2334
2335 int i, j;
2336 tran_low_t out[64][32], tmp[64][32], outtmp[64];
2337 tran_low_t *outp = &out[0][0];
2338 int outstride = n;
2339
2340 // inverse transform row vectors and transpose
2341 for (i = 0; i < n; ++i) {
2342 IHT_64x32[tx_type].rows(input, outtmp);
2343 for (j = 0; j < n2; ++j)
Debargha Mukherjee570423c2017-10-01 00:35:20 -07002344 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * InvSqrt2);
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002345 input += n2;
2346 }
2347
2348 // inverse transform column vectors
2349 for (i = 0; i < n2; ++i) IHT_64x32[tx_type].cols(tmp[i], out[i]);
2350
2351#if CONFIG_EXT_TX
2352 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n2);
2353#endif
2354
2355 // Sum with the destination
2356 for (i = 0; i < n; ++i) {
2357 for (j = 0; j < n2; ++j) {
2358 int d = i * stride + j;
2359 int s = j * outstride + i;
2360 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
2361 }
2362 }
2363}
2364
2365void av1_iht32x64_2048_add_c(const tran_low_t *input, uint8_t *dest, int stride,
2366 const TxfmParam *txfm_param) {
Urvang Joshi2283d372017-10-02 17:16:45 -07002367 const TX_TYPE tx_type = txfm_param->tx_type;
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002368#if CONFIG_MRC_TX
2369 assert(tx_type != MRC_DCT && "Invalid tx type for tx size");
2370#endif // CONFIG_MRC_TX
2371#if CONFIG_DCT_ONLY
2372 assert(tx_type == DCT_DCT);
2373#endif
2374 static const transform_2d IHT_32x64[] = {
2375 { idct64_col_c, aom_idct32_c }, // DCT_DCT
2376 { ihalfright64_c, aom_idct32_c }, // ADST_DCT
2377 { idct64_col_c, ihalfright32_c }, // DCT_ADST
2378 { ihalfright64_c, ihalfright32_c }, // ADST_ADST
2379#if CONFIG_EXT_TX
2380 { ihalfright64_c, aom_idct32_c }, // FLIPADST_DCT
2381 { idct64_col_c, ihalfright32_c }, // DCT_FLIPADST
2382 { ihalfright64_c, ihalfright32_c }, // FLIPADST_FLIPADST
2383 { ihalfright64_c, ihalfright32_c }, // ADST_FLIPADST
2384 { ihalfright64_c, ihalfright32_c }, // FLIPADST_ADST
2385 { iidtx64_c, iidtx32_c }, // IDTX
2386 { idct64_col_c, iidtx32_c }, // V_DCT
2387 { iidtx64_c, aom_idct32_c }, // H_DCT
2388 { ihalfright64_c, iidtx32_c }, // V_ADST
2389 { iidtx64_c, ihalfright32_c }, // H_ADST
2390 { ihalfright64_c, iidtx32_c }, // V_FLIPADST
2391 { iidtx64_c, ihalfright32_c }, // H_FLIPADST
2392#endif
2393 };
2394
2395 const int n = 32;
2396 const int n2 = 64;
2397 int i, j;
2398 tran_low_t out[32][64], tmp[32][64], outtmp[32];
2399 tran_low_t *outp = &out[0][0];
2400 int outstride = n2;
2401
2402 // inverse transform row vectors and transpose
2403 for (i = 0; i < n2; ++i) {
2404 IHT_32x64[tx_type].rows(input, outtmp);
2405 for (j = 0; j < n; ++j)
Debargha Mukherjee570423c2017-10-01 00:35:20 -07002406 tmp[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * InvSqrt2);
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002407 input += n;
2408 }
2409
2410 // inverse transform column vectors
2411 for (i = 0; i < n; ++i) IHT_32x64[tx_type].cols(tmp[i], out[i]);
2412
2413#if CONFIG_EXT_TX
2414 maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n2, n);
2415#endif
2416
2417 // Sum with the destination
2418 for (i = 0; i < n2; ++i) {
2419 for (j = 0; j < n; ++j) {
2420 int d = i * stride + j;
2421 int s = j * outstride + i;
2422 dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
2423 }
2424 }
2425}
2426
Debargha Mukherjee67d13472016-11-01 14:37:39 -07002427#endif // CONFIG_TX64X64
Yaowu Xuc27fc142016-08-22 16:08:15 -07002428
2429// idct
Yaowu Xuf883b422016-08-30 14:01:10 -07002430void av1_idct4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002431 const TxfmParam *txfm_param) {
Sarah Parker90024e42017-10-06 16:50:47 -07002432#if CONFIG_EXT_TX
2433 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
2434#endif // CONFIG_EXT_TX
Lester Lu27319b62017-07-10 16:57:15 -07002435 const int eob = txfm_param->eob;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002436 if (eob > 1)
Lester Lu27319b62017-07-10 16:57:15 -07002437 av1_iht4x4_16_add(input, dest, stride, txfm_param);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002438 else
Yaowu Xuf883b422016-08-30 14:01:10 -07002439 aom_idct4x4_1_add(input, dest, stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002440}
2441
Yaowu Xuf883b422016-08-30 14:01:10 -07002442void av1_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002443 const TxfmParam *txfm_param) {
Sarah Parker90024e42017-10-06 16:50:47 -07002444#if CONFIG_EXT_TX
2445 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
2446#endif // CONFIG_EXT_TX
Lester Lu27319b62017-07-10 16:57:15 -07002447 const int eob = txfm_param->eob;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002448 if (eob > 1)
Yaowu Xuf883b422016-08-30 14:01:10 -07002449 aom_iwht4x4_16_add(input, dest, stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002450 else
Yaowu Xuf883b422016-08-30 14:01:10 -07002451 aom_iwht4x4_1_add(input, dest, stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002452}
2453
Nathan E. Eggee554f362017-10-04 14:44:38 -04002454#if !CONFIG_DAALA_TX8
hui sua5315712017-03-20 11:37:15 -07002455static void idct8x8_add(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002456 const TxfmParam *txfm_param) {
Yi Luo2ab63cb2017-05-11 16:44:22 -07002457// If dc is 1, then input[0] is the reconstructed value, do not need
2458// dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1.
Yaowu Xuc27fc142016-08-22 16:08:15 -07002459
Yi Luo2ab63cb2017-05-11 16:44:22 -07002460// The calculation can be simplified if there are not many non-zero dct
2461// coefficients. Use eobs to decide what to do.
2462// TODO(yunqingwang): "eobs = 1" case is also handled in av1_short_idct8x8_c.
2463// Combine that with code here.
2464#if CONFIG_ADAPT_SCAN
Lester Lu27319b62017-07-10 16:57:15 -07002465 const int16_t half = txfm_param->eob_threshold[0];
Yi Luo2ab63cb2017-05-11 16:44:22 -07002466#else
2467 const int16_t half = 12;
2468#endif
2469
Lester Lu27319b62017-07-10 16:57:15 -07002470 const int eob = txfm_param->eob;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002471 if (eob == 1)
2472 // DC only DCT coefficient
Yaowu Xuf883b422016-08-30 14:01:10 -07002473 aom_idct8x8_1_add(input, dest, stride);
Yi Luo2ab63cb2017-05-11 16:44:22 -07002474 else if (eob <= half)
Yaowu Xuf883b422016-08-30 14:01:10 -07002475 aom_idct8x8_12_add(input, dest, stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002476 else
Yaowu Xuf883b422016-08-30 14:01:10 -07002477 aom_idct8x8_64_add(input, dest, stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002478}
Monty Montgomerycf18fe42017-07-11 21:33:25 -04002479#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002480
Nathan E. Eggee554f362017-10-04 14:44:38 -04002481#if !CONFIG_DAALA_TX16
hui sua5315712017-03-20 11:37:15 -07002482static void idct16x16_add(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002483 const TxfmParam *txfm_param) {
Yi Luo2ab63cb2017-05-11 16:44:22 -07002484// The calculation can be simplified if there are not many non-zero dct
2485// coefficients. Use eobs to separate different cases.
2486#if CONFIG_ADAPT_SCAN
Lester Lu27319b62017-07-10 16:57:15 -07002487 const int16_t half = txfm_param->eob_threshold[0];
2488 const int16_t quarter = txfm_param->eob_threshold[1];
Yi Luo2ab63cb2017-05-11 16:44:22 -07002489#else
2490 const int16_t half = 38;
2491 const int16_t quarter = 10;
2492#endif
2493
Lester Lu27319b62017-07-10 16:57:15 -07002494 const int eob = txfm_param->eob;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002495 if (eob == 1) /* DC only DCT coefficient. */
Yaowu Xuf883b422016-08-30 14:01:10 -07002496 aom_idct16x16_1_add(input, dest, stride);
Yi Luo2ab63cb2017-05-11 16:44:22 -07002497 else if (eob <= quarter)
Yaowu Xuf883b422016-08-30 14:01:10 -07002498 aom_idct16x16_10_add(input, dest, stride);
Yi Luo2ab63cb2017-05-11 16:44:22 -07002499 else if (eob <= half)
Yi Luof6176ab2017-04-28 15:48:56 -07002500 aom_idct16x16_38_add(input, dest, stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002501 else
Yaowu Xuf883b422016-08-30 14:01:10 -07002502 aom_idct16x16_256_add(input, dest, stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002503}
Monty Montgomerycb9c1c52017-07-17 18:15:30 -04002504#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002505
Sarah Parker5b8e6d22017-07-24 15:30:53 -07002506#if CONFIG_MRC_TX
2507static void imrc32x32_add_c(const tran_low_t *input, uint8_t *dest, int stride,
2508 const TxfmParam *txfm_param) {
2509#if CONFIG_ADAPT_SCAN
2510 const int16_t half = txfm_param->eob_threshold[0];
2511 const int16_t quarter = txfm_param->eob_threshold[1];
2512#else
2513 const int16_t half = 135;
2514 const int16_t quarter = 34;
2515#endif
2516
2517 const int eob = txfm_param->eob;
Sarah Parker99e7daa2017-08-29 10:30:13 -07002518 int n_masked_vals = 0;
2519 uint8_t *mask;
2520 uint8_t mask_tmp[32 * 32];
Sarah Parker5b8e6d22017-07-24 15:30:53 -07002521 if (eob == 1) {
2522 aom_idct32x32_1_add_c(input, dest, stride);
2523 } else {
Sarah Parker99e7daa2017-08-29 10:30:13 -07002524 if ((txfm_param->is_inter && SIGNAL_MRC_MASK_INTER) ||
2525 (!txfm_param->is_inter && SIGNAL_MRC_MASK_INTRA)) {
2526 mask = txfm_param->mask;
2527 } else {
2528 n_masked_vals =
2529 get_mrc_pred_mask(txfm_param->dst, txfm_param->stride, mask_tmp, 32,
2530 32, 32, txfm_param->is_inter);
2531 if (!is_valid_mrc_mask(n_masked_vals, 32, 32))
2532 assert(0 && "Invalid MRC mask");
2533 mask = mask_tmp;
2534 }
Sarah Parker5b8e6d22017-07-24 15:30:53 -07002535 if (eob <= quarter)
2536 // non-zero coeff only in upper-left 8x8
2537 aom_imrc32x32_34_add_c(input, dest, stride, mask);
2538 else if (eob <= half)
2539 // non-zero coeff only in upper-left 16x16
2540 aom_imrc32x32_135_add_c(input, dest, stride, mask);
2541 else
2542 aom_imrc32x32_1024_add_c(input, dest, stride, mask);
2543 }
2544}
2545#endif // CONFIG_MRC_TX
2546
Nathan E. Eggee554f362017-10-04 14:44:38 -04002547#if !CONFIG_DAALA_TX32
hui sua5315712017-03-20 11:37:15 -07002548static void idct32x32_add(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002549 const TxfmParam *txfm_param) {
Yi Luo2ab63cb2017-05-11 16:44:22 -07002550#if CONFIG_ADAPT_SCAN
Lester Lu27319b62017-07-10 16:57:15 -07002551 const int16_t half = txfm_param->eob_threshold[0];
2552 const int16_t quarter = txfm_param->eob_threshold[1];
Yi Luo2ab63cb2017-05-11 16:44:22 -07002553#else
2554 const int16_t half = 135;
2555 const int16_t quarter = 34;
2556#endif
2557
Lester Lu27319b62017-07-10 16:57:15 -07002558 const int eob = txfm_param->eob;
Yi Luo2ab63cb2017-05-11 16:44:22 -07002559 if (eob == 1)
2560 aom_idct32x32_1_add(input, dest, stride);
2561 else if (eob <= quarter)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002562 // non-zero coeff only in upper-left 8x8
Yaowu Xuf883b422016-08-30 14:01:10 -07002563 aom_idct32x32_34_add(input, dest, stride);
Yi Luo2ab63cb2017-05-11 16:44:22 -07002564 else if (eob <= half)
Yi Luo40f22ef2017-05-08 16:29:39 -07002565 // non-zero coeff only in upper-left 16x16
2566 aom_idct32x32_135_add(input, dest, stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002567 else
Yaowu Xuf883b422016-08-30 14:01:10 -07002568 aom_idct32x32_1024_add(input, dest, stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002569}
Monty Montgomery2cb52ba2017-07-17 18:27:27 -04002570#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002571
Nathan E. Eggee554f362017-10-04 14:44:38 -04002572#if CONFIG_TX64X64 && !CONFIG_DAALA_TX64
hui sua5315712017-03-20 11:37:15 -07002573static void idct64x64_add(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002574 const TxfmParam *txfm_param) {
2575 (void)txfm_param;
Urvang Joshi9136ab72017-07-28 14:15:49 -07002576 av1_iht64x64_4096_add(input, dest, stride, txfm_param);
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07002577}
Nathan E. Eggee554f362017-10-04 14:44:38 -04002578#endif // CONFIG_TX64X64 && !CONFIG_DAALA_TX64
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07002579
Yi Luo2ab63cb2017-05-11 16:44:22 -07002580static void inv_txfm_add_4x4(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002581 const TxfmParam *txfm_param) {
2582 const TX_TYPE tx_type = txfm_param->tx_type;
2583 if (txfm_param->lossless) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002584 assert(tx_type == DCT_DCT);
Lester Lu27319b62017-07-10 16:57:15 -07002585 av1_iwht4x4_add(input, dest, stride, txfm_param);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002586 return;
2587 }
2588
2589 switch (tx_type) {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002590#if !CONFIG_DAALA_TX4
Lester Lu27319b62017-07-10 16:57:15 -07002591 case DCT_DCT: av1_idct4x4_add(input, dest, stride, txfm_param); break;
Monty Montgomery02078a32017-07-11 21:22:29 -04002592#else
2593 case DCT_DCT:
2594#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002595 case ADST_DCT:
2596 case DCT_ADST:
Lester Luad8290b2017-06-12 18:26:18 -07002597 case ADST_ADST:
Nathan E. Eggee554f362017-10-04 14:44:38 -04002598#if CONFIG_LGT || CONFIG_DAALA_TX4
Lester Luad8290b2017-06-12 18:26:18 -07002599 // LGT only exists in C verson
Lester Lu27319b62017-07-10 16:57:15 -07002600 av1_iht4x4_16_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002601 break;
2602#else
Lester Lu27319b62017-07-10 16:57:15 -07002603 av1_iht4x4_16_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002604 break;
2605#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002606#if CONFIG_EXT_TX
2607 case FLIPADST_DCT:
2608 case DCT_FLIPADST:
2609 case FLIPADST_FLIPADST:
2610 case ADST_FLIPADST:
Lester Luad8290b2017-06-12 18:26:18 -07002611 case FLIPADST_ADST:
Nathan E. Eggee554f362017-10-04 14:44:38 -04002612#if CONFIG_LGT || CONFIG_DAALA_TX4
Lester Lu27319b62017-07-10 16:57:15 -07002613 av1_iht4x4_16_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002614 break;
2615#else
Lester Lu27319b62017-07-10 16:57:15 -07002616 av1_iht4x4_16_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002617 break;
2618#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002619 case V_DCT:
2620 case H_DCT:
2621 case V_ADST:
2622 case H_ADST:
2623 case V_FLIPADST:
2624 case H_FLIPADST:
2625 // Use C version since DST only exists in C code
Lester Lu27319b62017-07-10 16:57:15 -07002626 av1_iht4x4_16_add_c(input, dest, stride, txfm_param);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002627 break;
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002628 case IDTX: inv_idtx_add_c(input, dest, stride, 4, 4, tx_type); break;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002629#endif // CONFIG_EXT_TX
2630 default: assert(0); break;
2631 }
2632}
2633
Yi Luo2ab63cb2017-05-11 16:44:22 -07002634static void inv_txfm_add_4x8(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002635 const TxfmParam *txfm_param) {
Monty Montgomeryabd94512017-10-14 00:41:42 -04002636#if CONFIG_LGT || (CONFIG_DAALA_TX4 && CONFIG_DAALA_TX8)
Lester Lu27319b62017-07-10 16:57:15 -07002637 av1_iht4x8_32_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002638#else
Lester Lu27319b62017-07-10 16:57:15 -07002639 av1_iht4x8_32_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002640#endif
Yaowu Xuf883b422016-08-30 14:01:10 -07002641}
2642
Yi Luo2ab63cb2017-05-11 16:44:22 -07002643static void inv_txfm_add_8x4(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002644 const TxfmParam *txfm_param) {
Monty Montgomeryabd94512017-10-14 00:41:42 -04002645#if CONFIG_LGT || (CONFIG_DAALA_TX4 && CONFIG_DAALA_TX8)
Lester Lu27319b62017-07-10 16:57:15 -07002646 av1_iht8x4_32_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002647#else
Lester Lu27319b62017-07-10 16:57:15 -07002648 av1_iht8x4_32_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002649#endif
Yaowu Xuf883b422016-08-30 14:01:10 -07002650}
2651
hui sua5315712017-03-20 11:37:15 -07002652// These will be used by the masked-tx experiment in the future.
Sebastien Alaiwanfb838772017-10-24 12:02:54 +02002653#if CONFIG_RECT_TX_EXT
hui sua5315712017-03-20 11:37:15 -07002654static void inv_txfm_add_4x16(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002655 int stride, const TxfmParam *txfm_param) {
Lester Luad8290b2017-06-12 18:26:18 -07002656#if CONFIG_LGT
Lester Lu27319b62017-07-10 16:57:15 -07002657 av1_iht4x16_64_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002658#else
Lester Lu27319b62017-07-10 16:57:15 -07002659 av1_iht4x16_64_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002660#endif
Debargha Mukherjee751de382016-12-13 02:54:22 -08002661}
2662
hui sua5315712017-03-20 11:37:15 -07002663static void inv_txfm_add_16x4(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002664 int stride, const TxfmParam *txfm_param) {
Lester Luad8290b2017-06-12 18:26:18 -07002665#if CONFIG_LGT
Lester Lu27319b62017-07-10 16:57:15 -07002666 av1_iht16x4_64_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002667#else
Lester Lu27319b62017-07-10 16:57:15 -07002668 av1_iht16x4_64_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002669#endif
Debargha Mukherjee751de382016-12-13 02:54:22 -08002670}
2671
hui sua5315712017-03-20 11:37:15 -07002672static void inv_txfm_add_8x32(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002673 int stride, const TxfmParam *txfm_param) {
Lester Luad8290b2017-06-12 18:26:18 -07002674#if CONFIG_LGT
Lester Lu27319b62017-07-10 16:57:15 -07002675 av1_iht8x32_256_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002676#else
Lester Lu27319b62017-07-10 16:57:15 -07002677 av1_iht8x32_256_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002678#endif
Debargha Mukherjee751de382016-12-13 02:54:22 -08002679}
2680
hui sua5315712017-03-20 11:37:15 -07002681static void inv_txfm_add_32x8(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002682 int stride, const TxfmParam *txfm_param) {
Lester Luad8290b2017-06-12 18:26:18 -07002683#if CONFIG_LGT
Lester Lu27319b62017-07-10 16:57:15 -07002684 av1_iht32x8_256_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002685#else
Lester Lu27319b62017-07-10 16:57:15 -07002686 av1_iht32x8_256_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002687#endif
Debargha Mukherjee751de382016-12-13 02:54:22 -08002688}
Yue Chend6bdd462017-07-19 16:05:43 -07002689#endif
Debargha Mukherjee751de382016-12-13 02:54:22 -08002690
hui sua5315712017-03-20 11:37:15 -07002691static void inv_txfm_add_8x16(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002692 int stride, const TxfmParam *txfm_param) {
Monty Montgomery7eb44542017-10-19 20:47:51 -04002693#if CONFIG_LGT || (CONFIG_DAALA_TX8 && CONFIG_DAALA_TX16)
Lester Lu27319b62017-07-10 16:57:15 -07002694 av1_iht8x16_128_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002695#else
Lester Lu27319b62017-07-10 16:57:15 -07002696 av1_iht8x16_128_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002697#endif
hui sua5315712017-03-20 11:37:15 -07002698}
2699
2700static void inv_txfm_add_16x8(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002701 int stride, const TxfmParam *txfm_param) {
Monty Montgomery7eb44542017-10-19 20:47:51 -04002702#if CONFIG_LGT || (CONFIG_DAALA_TX8 && CONFIG_DAALA_TX16)
Lester Lu27319b62017-07-10 16:57:15 -07002703 av1_iht16x8_128_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002704#else
Lester Lu27319b62017-07-10 16:57:15 -07002705 av1_iht16x8_128_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002706#endif
hui sua5315712017-03-20 11:37:15 -07002707}
2708
2709static void inv_txfm_add_16x32(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002710 int stride, const TxfmParam *txfm_param) {
Monty Montgomeryad396852017-10-20 03:35:26 -04002711#if CONFIG_DAALA_TX16 && CONFIG_DAALA_TX32
2712 av1_iht16x32_512_add_c(input, dest, stride, txfm_param);
2713#else
Lester Lu27319b62017-07-10 16:57:15 -07002714 av1_iht16x32_512_add(input, dest, stride, txfm_param);
Monty Montgomeryad396852017-10-20 03:35:26 -04002715#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002716}
2717
hui sua5315712017-03-20 11:37:15 -07002718static void inv_txfm_add_32x16(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002719 int stride, const TxfmParam *txfm_param) {
Monty Montgomeryad396852017-10-20 03:35:26 -04002720#if CONFIG_DAALA_TX16 && CONFIG_DAALA_TX32
2721 av1_iht32x16_512_add_c(input, dest, stride, txfm_param);
2722#else
Lester Lu27319b62017-07-10 16:57:15 -07002723 av1_iht32x16_512_add(input, dest, stride, txfm_param);
Monty Montgomeryad396852017-10-20 03:35:26 -04002724#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002725}
Yaowu Xuc27fc142016-08-22 16:08:15 -07002726
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002727#if CONFIG_TX64X64
2728static void inv_txfm_add_32x64(const tran_low_t *input, uint8_t *dest,
2729 int stride, const TxfmParam *txfm_param) {
2730 av1_iht32x64_2048_add(input, dest, stride, txfm_param);
2731}
2732
2733static void inv_txfm_add_64x32(const tran_low_t *input, uint8_t *dest,
2734 int stride, const TxfmParam *txfm_param) {
2735 av1_iht64x32_2048_add(input, dest, stride, txfm_param);
2736}
2737#endif // CONFIG_TX64X64
2738
hui sua5315712017-03-20 11:37:15 -07002739static void inv_txfm_add_8x8(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07002740 const TxfmParam *txfm_param) {
2741 const TX_TYPE tx_type = txfm_param->tx_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002742 switch (tx_type) {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002743#if !CONFIG_DAALA_TX8
Lester Lu27319b62017-07-10 16:57:15 -07002744 case DCT_DCT: idct8x8_add(input, dest, stride, txfm_param); break;
Monty Montgomerycf18fe42017-07-11 21:33:25 -04002745#else
2746 case DCT_DCT:
2747#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002748 case ADST_DCT:
2749 case DCT_ADST:
Lester Luad8290b2017-06-12 18:26:18 -07002750 case ADST_ADST:
Nathan E. Eggee554f362017-10-04 14:44:38 -04002751#if CONFIG_LGT || CONFIG_DAALA_TX8
Lester Lu27319b62017-07-10 16:57:15 -07002752 av1_iht8x8_64_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002753 break;
2754#else
Lester Lu27319b62017-07-10 16:57:15 -07002755 av1_iht8x8_64_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002756 break;
2757#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002758#if CONFIG_EXT_TX
2759 case FLIPADST_DCT:
2760 case DCT_FLIPADST:
2761 case FLIPADST_FLIPADST:
2762 case ADST_FLIPADST:
Lester Luad8290b2017-06-12 18:26:18 -07002763 case FLIPADST_ADST:
Nathan E. Eggee554f362017-10-04 14:44:38 -04002764#if CONFIG_LGT || CONFIG_DAALA_TX8
Lester Lu27319b62017-07-10 16:57:15 -07002765 av1_iht8x8_64_add_c(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002766 break;
2767#else
Lester Lu27319b62017-07-10 16:57:15 -07002768 av1_iht8x8_64_add(input, dest, stride, txfm_param);
Lester Luad8290b2017-06-12 18:26:18 -07002769 break;
2770#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002771 case V_DCT:
2772 case H_DCT:
2773 case V_ADST:
2774 case H_ADST:
2775 case V_FLIPADST:
2776 case H_FLIPADST:
2777 // Use C version since DST only exists in C code
Lester Lu27319b62017-07-10 16:57:15 -07002778 av1_iht8x8_64_add_c(input, dest, stride, txfm_param);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002779 break;
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002780 case IDTX: inv_idtx_add_c(input, dest, stride, 8, 8, tx_type); break;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002781#endif // CONFIG_EXT_TX
2782 default: assert(0); break;
2783 }
2784}
2785
hui sua5315712017-03-20 11:37:15 -07002786static void inv_txfm_add_16x16(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002787 int stride, const TxfmParam *txfm_param) {
2788 const TX_TYPE tx_type = txfm_param->tx_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002789 switch (tx_type) {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002790#if !CONFIG_DAALA_TX16
Lester Lu27319b62017-07-10 16:57:15 -07002791 case DCT_DCT: idct16x16_add(input, dest, stride, txfm_param); break;
Monty Montgomerycb9c1c52017-07-17 18:15:30 -04002792#else
2793 case DCT_DCT:
2794#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002795 case ADST_DCT:
2796 case DCT_ADST:
Lester Lu27319b62017-07-10 16:57:15 -07002797 case ADST_ADST:
Nathan E. Eggee554f362017-10-04 14:44:38 -04002798#if CONFIG_DAALA_TX16
Nathan E. Egge34e12012017-09-13 09:02:32 -04002799 av1_iht16x16_256_add_c(input, dest, stride, txfm_param);
2800#else
Lester Lu27319b62017-07-10 16:57:15 -07002801 av1_iht16x16_256_add(input, dest, stride, txfm_param);
Nathan E. Eggee554f362017-10-04 14:44:38 -04002802#endif // CONFIG_DAALA_TX16
Lester Lu27319b62017-07-10 16:57:15 -07002803 break;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002804#if CONFIG_EXT_TX
2805 case FLIPADST_DCT:
2806 case DCT_FLIPADST:
2807 case FLIPADST_FLIPADST:
2808 case ADST_FLIPADST:
2809 case FLIPADST_ADST:
Yaowu Xuc27fc142016-08-22 16:08:15 -07002810 case V_DCT:
2811 case H_DCT:
2812 case V_ADST:
2813 case H_ADST:
2814 case V_FLIPADST:
Lester Lu27319b62017-07-10 16:57:15 -07002815 case H_FLIPADST:
Nathan E. Eggee554f362017-10-04 14:44:38 -04002816#if CONFIG_DAALA_TX16
Nathan E. Egge34e12012017-09-13 09:02:32 -04002817 av1_iht16x16_256_add_c(input, dest, stride, txfm_param);
2818#else
Lester Lu27319b62017-07-10 16:57:15 -07002819 av1_iht16x16_256_add(input, dest, stride, txfm_param);
Nathan E. Eggee554f362017-10-04 14:44:38 -04002820#endif // CONFIG_DAALA_TX16
Lester Lu27319b62017-07-10 16:57:15 -07002821 break;
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002822 case IDTX: inv_idtx_add_c(input, dest, stride, 16, 16, tx_type); break;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002823#endif // CONFIG_EXT_TX
Sarah Parker53f93db2017-07-11 17:20:04 -07002824#if CONFIG_MRC_TX
2825 case MRC_DCT: assert(0 && "Invalid tx type for tx size");
2826#endif // CONFIG_MRC_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07002827 default: assert(0); break;
2828 }
2829}
2830
hui sua5315712017-03-20 11:37:15 -07002831static void inv_txfm_add_32x32(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002832 int stride, const TxfmParam *txfm_param) {
2833 const TX_TYPE tx_type = txfm_param->tx_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002834 switch (tx_type) {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002835#if !CONFIG_DAALA_TX32
Lester Lu27319b62017-07-10 16:57:15 -07002836 case DCT_DCT: idct32x32_add(input, dest, stride, txfm_param); break;
Monty Montgomery2cb52ba2017-07-17 18:27:27 -04002837#else
2838 case DCT_DCT:
2839 av1_iht32x32_1024_add_c(input, dest, stride, txfm_param);
2840 break;
2841#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002842#if CONFIG_EXT_TX
2843 case ADST_DCT:
2844 case DCT_ADST:
2845 case ADST_ADST:
2846 case FLIPADST_DCT:
2847 case DCT_FLIPADST:
2848 case FLIPADST_FLIPADST:
2849 case ADST_FLIPADST:
2850 case FLIPADST_ADST:
2851 case V_DCT:
2852 case H_DCT:
2853 case V_ADST:
2854 case H_ADST:
2855 case V_FLIPADST:
Lester Lu27319b62017-07-10 16:57:15 -07002856 case H_FLIPADST:
2857 av1_iht32x32_1024_add_c(input, dest, stride, txfm_param);
2858 break;
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002859 case IDTX: inv_idtx_add_c(input, dest, stride, 32, 32, tx_type); break;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002860#endif // CONFIG_EXT_TX
Sarah Parker53f93db2017-07-11 17:20:04 -07002861#if CONFIG_MRC_TX
2862 case MRC_DCT: imrc32x32_add_c(input, dest, stride, txfm_param); break;
2863#endif // CONFIG_MRC_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07002864 default: assert(0); break;
2865 }
2866}
2867
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07002868#if CONFIG_TX64X64
hui sua5315712017-03-20 11:37:15 -07002869static void inv_txfm_add_64x64(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002870 int stride, const TxfmParam *txfm_param) {
2871 const TX_TYPE tx_type = txfm_param->tx_type;
Debargha Mukherjee570423c2017-10-01 00:35:20 -07002872 assert(tx_type == DCT_DCT);
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07002873 switch (tx_type) {
Nathan E. Eggee554f362017-10-04 14:44:38 -04002874#if !CONFIG_DAALA_TX64
Lester Lu27319b62017-07-10 16:57:15 -07002875 case DCT_DCT: idct64x64_add(input, dest, stride, txfm_param); break;
Monty Montgomerya4e245a2017-07-22 00:48:31 -04002876#else
2877 case DCT_DCT:
2878#endif
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07002879#if CONFIG_EXT_TX
2880 case ADST_DCT:
2881 case DCT_ADST:
2882 case ADST_ADST:
2883 case FLIPADST_DCT:
2884 case DCT_FLIPADST:
2885 case FLIPADST_FLIPADST:
2886 case ADST_FLIPADST:
2887 case FLIPADST_ADST:
2888 case V_DCT:
2889 case H_DCT:
2890 case V_ADST:
2891 case H_ADST:
2892 case V_FLIPADST:
Lester Lu27319b62017-07-10 16:57:15 -07002893 case H_FLIPADST:
2894 av1_iht64x64_4096_add_c(input, dest, stride, txfm_param);
2895 break;
Debargha Mukherjee2b435012017-09-28 08:30:35 -07002896 case IDTX: inv_idtx_add_c(input, dest, stride, 64, 64, tx_type); break;
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07002897#endif // CONFIG_EXT_TX
Sarah Parker53f93db2017-07-11 17:20:04 -07002898#if CONFIG_MRC_TX
2899 case MRC_DCT: assert(0 && "Invalid tx type for tx size");
2900#endif // CONFIG_MRC_TX
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07002901 default: assert(0); break;
2902 }
2903}
2904#endif // CONFIG_TX64X64
2905
Yaowu Xuf883b422016-08-30 14:01:10 -07002906void av1_highbd_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
2907 int eob, int bd) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002908 if (eob > 1)
Yaowu Xuf883b422016-08-30 14:01:10 -07002909 aom_highbd_iwht4x4_16_add(input, dest, stride, bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002910 else
Yaowu Xuf883b422016-08-30 14:01:10 -07002911 aom_highbd_iwht4x4_1_add(input, dest, stride, bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002912}
2913
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02002914static const int32_t *cast_to_int32(const tran_low_t *input) {
2915 assert(sizeof(int32_t) == sizeof(tran_low_t));
2916 return (const int32_t *)input;
2917}
2918
Yaowu Xuf883b422016-08-30 14:01:10 -07002919void av1_highbd_inv_txfm_add_4x4(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002920 int stride, const TxfmParam *txfm_param) {
Sarah Parker90024e42017-10-06 16:50:47 -07002921#if CONFIG_EXT_TX
2922 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
2923#endif // CONFIG_EXT_TX
Lester Lu27319b62017-07-10 16:57:15 -07002924 int eob = txfm_param->eob;
2925 int bd = txfm_param->bd;
2926 int lossless = txfm_param->lossless;
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02002927 const int32_t *src = cast_to_int32(input);
Urvang Joshi2283d372017-10-02 17:16:45 -07002928 const TX_TYPE tx_type = txfm_param->tx_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002929 if (lossless) {
2930 assert(tx_type == DCT_DCT);
Yaowu Xuf883b422016-08-30 14:01:10 -07002931 av1_highbd_iwht4x4_add(input, dest, stride, eob, bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002932 return;
2933 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002934 switch (tx_type) {
2935 case DCT_DCT:
2936 case ADST_DCT:
2937 case DCT_ADST:
2938 case ADST_ADST:
Yi Luo51281092017-06-26 16:36:15 -07002939 av1_inv_txfm2d_add_4x4(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
Sarah Parker31c66502017-05-19 16:51:07 -07002940 bd);
2941 break;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002942#if CONFIG_EXT_TX
2943 case FLIPADST_DCT:
2944 case DCT_FLIPADST:
2945 case FLIPADST_FLIPADST:
2946 case ADST_FLIPADST:
2947 case FLIPADST_ADST:
Yi Luo51281092017-06-26 16:36:15 -07002948 av1_inv_txfm2d_add_4x4(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
Yaowu Xuf883b422016-08-30 14:01:10 -07002949 bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002950 break;
Sarah Parker31c66502017-05-19 16:51:07 -07002951 // use the c version for anything including identity for now
Yaowu Xuc27fc142016-08-22 16:08:15 -07002952 case V_DCT:
2953 case H_DCT:
2954 case V_ADST:
2955 case H_ADST:
2956 case V_FLIPADST:
2957 case H_FLIPADST:
Yaowu Xuc27fc142016-08-22 16:08:15 -07002958 case IDTX:
Yi Luo51281092017-06-26 16:36:15 -07002959 av1_inv_txfm2d_add_4x4_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
2960 bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002961 break;
2962#endif // CONFIG_EXT_TX
2963 default: assert(0); break;
2964 }
2965}
2966
Yaowu Xuf883b422016-08-30 14:01:10 -07002967void av1_highbd_inv_txfm_add_4x8(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002968 int stride, const TxfmParam *txfm_param) {
Sarah Parker90024e42017-10-06 16:50:47 -07002969#if CONFIG_EXT_TX
2970 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
2971#endif // CONFIG_EXT_TX
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02002972 const int32_t *src = cast_to_int32(input);
Lester Lud8b1ddc2017-07-06 16:13:29 -07002973 av1_inv_txfm2d_add_4x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
Lester Lu27319b62017-07-10 16:57:15 -07002974 txfm_param->tx_type, txfm_param->bd);
Yaowu Xuf883b422016-08-30 14:01:10 -07002975}
2976
2977void av1_highbd_inv_txfm_add_8x4(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002978 int stride, const TxfmParam *txfm_param) {
Sarah Parker90024e42017-10-06 16:50:47 -07002979#if CONFIG_EXT_TX
2980 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
2981#endif // CONFIG_EXT_TX
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02002982 const int32_t *src = cast_to_int32(input);
Lester Lud8b1ddc2017-07-06 16:13:29 -07002983 av1_inv_txfm2d_add_8x4_c(src, CONVERT_TO_SHORTPTR(dest), stride,
Lester Lu27319b62017-07-10 16:57:15 -07002984 txfm_param->tx_type, txfm_param->bd);
Debargha Mukherjee751de382016-12-13 02:54:22 -08002985}
2986
hui sua5315712017-03-20 11:37:15 -07002987static void highbd_inv_txfm_add_8x16(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002988 int stride, const TxfmParam *txfm_param) {
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02002989 const int32_t *src = cast_to_int32(input);
Lester Lud8b1ddc2017-07-06 16:13:29 -07002990 av1_inv_txfm2d_add_8x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
Lester Lu27319b62017-07-10 16:57:15 -07002991 txfm_param->tx_type, txfm_param->bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002992}
2993
hui sua5315712017-03-20 11:37:15 -07002994static void highbd_inv_txfm_add_16x8(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07002995 int stride, const TxfmParam *txfm_param) {
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02002996 const int32_t *src = cast_to_int32(input);
Lester Lud8b1ddc2017-07-06 16:13:29 -07002997 av1_inv_txfm2d_add_16x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
Lester Lu27319b62017-07-10 16:57:15 -07002998 txfm_param->tx_type, txfm_param->bd);
Debargha Mukherjee751de382016-12-13 02:54:22 -08002999}
3000
hui sua5315712017-03-20 11:37:15 -07003001static void highbd_inv_txfm_add_16x32(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07003002 int stride, const TxfmParam *txfm_param) {
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02003003 const int32_t *src = cast_to_int32(input);
Lester Lud8b1ddc2017-07-06 16:13:29 -07003004 av1_inv_txfm2d_add_16x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
Lester Lu27319b62017-07-10 16:57:15 -07003005 txfm_param->tx_type, txfm_param->bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003006}
3007
hui sua5315712017-03-20 11:37:15 -07003008static void highbd_inv_txfm_add_32x16(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07003009 int stride, const TxfmParam *txfm_param) {
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02003010 const int32_t *src = cast_to_int32(input);
Lester Lud8b1ddc2017-07-06 16:13:29 -07003011 av1_inv_txfm2d_add_32x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
Lester Lu27319b62017-07-10 16:57:15 -07003012 txfm_param->tx_type, txfm_param->bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003013}
Yaowu Xuc27fc142016-08-22 16:08:15 -07003014
Debargha Mukherjee2b435012017-09-28 08:30:35 -07003015#if CONFIG_TX64X64
3016static void highbd_inv_txfm_add_32x64(const tran_low_t *input, uint8_t *dest,
3017 int stride, const TxfmParam *txfm_param) {
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02003018 const int32_t *src = cast_to_int32(input);
Debargha Mukherjee2b435012017-09-28 08:30:35 -07003019 av1_inv_txfm2d_add_32x64_c(src, CONVERT_TO_SHORTPTR(dest), stride,
3020 txfm_param->tx_type, txfm_param->bd);
3021}
3022
3023static void highbd_inv_txfm_add_64x32(const tran_low_t *input, uint8_t *dest,
3024 int stride, const TxfmParam *txfm_param) {
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02003025 const int32_t *src = cast_to_int32(input);
Debargha Mukherjee2b435012017-09-28 08:30:35 -07003026 av1_inv_txfm2d_add_64x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
3027 txfm_param->tx_type, txfm_param->bd);
3028}
3029#endif // CONFIG_TX64X64
3030
hui sua5315712017-03-20 11:37:15 -07003031static void highbd_inv_txfm_add_8x8(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07003032 int stride, const TxfmParam *txfm_param) {
3033 int bd = txfm_param->bd;
Urvang Joshi2283d372017-10-02 17:16:45 -07003034 const TX_TYPE tx_type = txfm_param->tx_type;
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02003035 const int32_t *src = cast_to_int32(input);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003036 switch (tx_type) {
3037 case DCT_DCT:
3038 case ADST_DCT:
3039 case DCT_ADST:
3040 case ADST_ADST:
Yi Luo51281092017-06-26 16:36:15 -07003041 av1_inv_txfm2d_add_8x8(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
Sarah Parker31c66502017-05-19 16:51:07 -07003042 bd);
3043 break;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003044#if CONFIG_EXT_TX
3045 case FLIPADST_DCT:
3046 case DCT_FLIPADST:
3047 case FLIPADST_FLIPADST:
3048 case ADST_FLIPADST:
3049 case FLIPADST_ADST:
Yi Luo51281092017-06-26 16:36:15 -07003050 av1_inv_txfm2d_add_8x8(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
Yaowu Xuf883b422016-08-30 14:01:10 -07003051 bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003052 break;
Sarah Parker31c66502017-05-19 16:51:07 -07003053 // use the c version for anything including identity for now
Yaowu Xuc27fc142016-08-22 16:08:15 -07003054 case V_DCT:
3055 case H_DCT:
3056 case V_ADST:
3057 case H_ADST:
3058 case V_FLIPADST:
3059 case H_FLIPADST:
Yaowu Xuc27fc142016-08-22 16:08:15 -07003060 case IDTX:
Yi Luo51281092017-06-26 16:36:15 -07003061 av1_inv_txfm2d_add_8x8_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
3062 bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003063 break;
3064#endif // CONFIG_EXT_TX
Sarah Parker31c66502017-05-19 16:51:07 -07003065 default: assert(0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003066 }
3067}
3068
hui sua5315712017-03-20 11:37:15 -07003069static void highbd_inv_txfm_add_16x16(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07003070 int stride, const TxfmParam *txfm_param) {
3071 int bd = txfm_param->bd;
Urvang Joshif8fe2ae2017-10-05 12:13:17 -07003072 const TX_TYPE tx_type = txfm_param->tx_type;
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02003073 const int32_t *src = cast_to_int32(input);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003074 switch (tx_type) {
3075 case DCT_DCT:
3076 case ADST_DCT:
3077 case DCT_ADST:
3078 case ADST_ADST:
Yi Luo51281092017-06-26 16:36:15 -07003079 av1_inv_txfm2d_add_16x16(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
3080 bd);
Sarah Parker31c66502017-05-19 16:51:07 -07003081 break;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003082#if CONFIG_EXT_TX
3083 case FLIPADST_DCT:
3084 case DCT_FLIPADST:
3085 case FLIPADST_FLIPADST:
3086 case ADST_FLIPADST:
3087 case FLIPADST_ADST:
Yi Luo51281092017-06-26 16:36:15 -07003088 av1_inv_txfm2d_add_16x16(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
3089 bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003090 break;
Sarah Parker31c66502017-05-19 16:51:07 -07003091 // use the c version for anything including identity for now
Yaowu Xuc27fc142016-08-22 16:08:15 -07003092 case V_DCT:
3093 case H_DCT:
3094 case V_ADST:
3095 case H_ADST:
3096 case V_FLIPADST:
3097 case H_FLIPADST:
Yaowu Xuc27fc142016-08-22 16:08:15 -07003098 case IDTX:
Yi Luo51281092017-06-26 16:36:15 -07003099 av1_inv_txfm2d_add_16x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
Sarah Parker31c66502017-05-19 16:51:07 -07003100 tx_type, bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003101 break;
3102#endif // CONFIG_EXT_TX
Sarah Parker31c66502017-05-19 16:51:07 -07003103 default: assert(0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003104 }
3105}
3106
hui sua5315712017-03-20 11:37:15 -07003107static void highbd_inv_txfm_add_32x32(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07003108 int stride, const TxfmParam *txfm_param) {
3109 int bd = txfm_param->bd;
Urvang Joshif8fe2ae2017-10-05 12:13:17 -07003110 const TX_TYPE tx_type = txfm_param->tx_type;
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02003111 const int32_t *src = cast_to_int32(input);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003112 switch (tx_type) {
3113 case DCT_DCT:
Yi Luo51281092017-06-26 16:36:15 -07003114 av1_inv_txfm2d_add_32x32(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
3115 bd);
Sarah Parker31c66502017-05-19 16:51:07 -07003116 break;
Rupert Swarbrickf16c3c82017-08-17 13:24:42 +01003117
3118 // The optimised version only supports DCT_DCT, so force use of
3119 // the C version for all other transform types.
3120 case ADST_DCT:
3121 case DCT_ADST:
3122 case ADST_ADST:
Sarah Parker31c66502017-05-19 16:51:07 -07003123#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07003124 case FLIPADST_DCT:
3125 case DCT_FLIPADST:
3126 case FLIPADST_FLIPADST:
3127 case ADST_FLIPADST:
3128 case FLIPADST_ADST:
Rupert Swarbrickf16c3c82017-08-17 13:24:42 +01003129 case IDTX:
Yaowu Xuc27fc142016-08-22 16:08:15 -07003130 case V_DCT:
3131 case H_DCT:
3132 case V_ADST:
3133 case H_ADST:
3134 case V_FLIPADST:
3135 case H_FLIPADST:
Rupert Swarbrickf16c3c82017-08-17 13:24:42 +01003136#endif // CONFIG_EXT_TX
Yi Luo51281092017-06-26 16:36:15 -07003137 av1_inv_txfm2d_add_32x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
Sarah Parker31c66502017-05-19 16:51:07 -07003138 tx_type, bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003139 break;
Rupert Swarbrickf16c3c82017-08-17 13:24:42 +01003140
Sarah Parker31c66502017-05-19 16:51:07 -07003141 default: assert(0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003142 }
3143}
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07003144
3145#if CONFIG_TX64X64
hui sua5315712017-03-20 11:37:15 -07003146static void highbd_inv_txfm_add_64x64(const tran_low_t *input, uint8_t *dest,
Lester Lu27319b62017-07-10 16:57:15 -07003147 int stride, const TxfmParam *txfm_param) {
3148 int bd = txfm_param->bd;
Urvang Joshif8fe2ae2017-10-05 12:13:17 -07003149 const TX_TYPE tx_type = txfm_param->tx_type;
Sebastien Alaiwan62c92e62017-10-04 15:09:19 +02003150 const int32_t *src = cast_to_int32(input);
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07003151 switch (tx_type) {
3152 case DCT_DCT:
Yi Luo51281092017-06-26 16:36:15 -07003153 av1_inv_txfm2d_add_64x64(src, CONVERT_TO_SHORTPTR(dest), stride, DCT_DCT,
3154 bd);
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07003155 break;
3156#if CONFIG_EXT_TX
3157 case ADST_DCT:
3158 case DCT_ADST:
3159 case ADST_ADST:
3160 case FLIPADST_DCT:
3161 case DCT_FLIPADST:
3162 case FLIPADST_FLIPADST:
3163 case ADST_FLIPADST:
3164 case FLIPADST_ADST:
3165 case V_DCT:
3166 case H_DCT:
3167 case V_ADST:
3168 case H_ADST:
3169 case V_FLIPADST:
3170 case H_FLIPADST:
Sarah Parker31c66502017-05-19 16:51:07 -07003171 // TODO(sarahparker)
3172 // I've deleted the 64x64 implementations that existed in lieu
3173 // of adst, flipadst and identity for simplicity but will bring back
3174 // in a later change. This shouldn't impact performance since
3175 // DCT_DCT is the only extended type currently allowed for 64x64,
3176 // as dictated by get_ext_tx_set_type in blockd.h.
Yi Luo51281092017-06-26 16:36:15 -07003177 av1_inv_txfm2d_add_64x64_c(src, CONVERT_TO_SHORTPTR(dest), stride,
Sarah Parker31c66502017-05-19 16:51:07 -07003178 DCT_DCT, bd);
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07003179 break;
3180 case IDTX:
Debargha Mukherjee2b435012017-09-28 08:30:35 -07003181 highbd_inv_idtx_add_c(input, dest, stride, 64, 64, tx_type, bd);
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07003182 break;
3183#endif // CONFIG_EXT_TX
3184 default: assert(0); break;
3185 }
3186}
3187#endif // CONFIG_TX64X64
Yaowu Xuc27fc142016-08-22 16:08:15 -07003188
hui subb9c73b2017-03-17 15:51:02 -07003189void av1_inv_txfm_add(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07003190 TxfmParam *txfm_param) {
Sarah Parker90024e42017-10-06 16:50:47 -07003191#if CONFIG_EXT_TX
3192 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
3193#endif // CONFIG_EXT_TX
Lester Lu27319b62017-07-10 16:57:15 -07003194 const TX_SIZE tx_size = txfm_param->tx_size;
Lester Lu432012f2017-08-17 14:39:29 -07003195#if CONFIG_LGT_FROM_PRED
3196 if (txfm_param->use_lgt) {
3197 assert(is_lgt_allowed(txfm_param->mode, tx_size));
3198 ilgt2d_from_pred_add(input, dest, stride, txfm_param);
3199 return;
3200 }
3201#endif // CONFIG_LGT_FROM_PRED
Yaowu Xuc27fc142016-08-22 16:08:15 -07003202 switch (tx_size) {
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07003203#if CONFIG_TX64X64
Lester Lu27319b62017-07-10 16:57:15 -07003204 case TX_64X64: inv_txfm_add_64x64(input, dest, stride, txfm_param); break;
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07003205#endif // CONFIG_TX64X64
Lester Lu27319b62017-07-10 16:57:15 -07003206 case TX_32X32: inv_txfm_add_32x32(input, dest, stride, txfm_param); break;
3207 case TX_16X16: inv_txfm_add_16x16(input, dest, stride, txfm_param); break;
3208 case TX_8X8: inv_txfm_add_8x8(input, dest, stride, txfm_param); break;
3209 case TX_4X8: inv_txfm_add_4x8(input, dest, stride, txfm_param); break;
3210 case TX_8X4: inv_txfm_add_8x4(input, dest, stride, txfm_param); break;
3211 case TX_8X16: inv_txfm_add_8x16(input, dest, stride, txfm_param); break;
3212 case TX_16X8: inv_txfm_add_16x8(input, dest, stride, txfm_param); break;
3213 case TX_16X32: inv_txfm_add_16x32(input, dest, stride, txfm_param); break;
3214 case TX_32X16: inv_txfm_add_32x16(input, dest, stride, txfm_param); break;
Debargha Mukherjee2b435012017-09-28 08:30:35 -07003215#if CONFIG_TX64X64
3216 case TX_64X32: inv_txfm_add_64x32(input, dest, stride, txfm_param); break;
3217 case TX_32X64: inv_txfm_add_32x64(input, dest, stride, txfm_param); break;
3218#endif // CONFIG_TX64X64
Yaowu Xuc27fc142016-08-22 16:08:15 -07003219 case TX_4X4:
Yaowu Xuf883b422016-08-30 14:01:10 -07003220 // this is like av1_short_idct4x4 but has a special case around eob<=1
Yaowu Xuc27fc142016-08-22 16:08:15 -07003221 // which is significant (not just an optimization) for the lossless
3222 // case.
Lester Lu27319b62017-07-10 16:57:15 -07003223 inv_txfm_add_4x4(input, dest, stride, txfm_param);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003224 break;
Sebastien Alaiwanfb838772017-10-24 12:02:54 +02003225#if CONFIG_RECT_TX_EXT
Lester Lu27319b62017-07-10 16:57:15 -07003226 case TX_32X8: inv_txfm_add_32x8(input, dest, stride, txfm_param); break;
3227 case TX_8X32: inv_txfm_add_8x32(input, dest, stride, txfm_param); break;
3228 case TX_16X4: inv_txfm_add_16x4(input, dest, stride, txfm_param); break;
3229 case TX_4X16: inv_txfm_add_4x16(input, dest, stride, txfm_param); break;
Yue Chen56e226e2017-05-02 16:21:40 -07003230#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003231 default: assert(0 && "Invalid transform size"); break;
3232 }
3233}
3234
Sarah Parker90024e42017-10-06 16:50:47 -07003235static void init_txfm_param(const MACROBLOCKD *xd,
3236#if CONFIG_EXT_TX
3237 int plane,
3238#endif // CONFIG_EXT_TX
3239 TX_SIZE tx_size, TX_TYPE tx_type, int eob,
3240 TxfmParam *txfm_param) {
Lester Lu27319b62017-07-10 16:57:15 -07003241 txfm_param->tx_type = tx_type;
3242 txfm_param->tx_size = tx_size;
3243 txfm_param->eob = eob;
3244 txfm_param->lossless = xd->lossless[xd->mi[0]->mbmi.segment_id];
Lester Lu27319b62017-07-10 16:57:15 -07003245 txfm_param->bd = xd->bd;
Sarah Parker90024e42017-10-06 16:50:47 -07003246#if CONFIG_EXT_TX
3247 const struct macroblockd_plane *const pd = &xd->plane[plane];
3248 const BLOCK_SIZE plane_bsize =
3249 get_plane_block_size(xd->mi[0]->mbmi.sb_type, pd);
3250 // TODO(sarahparker) This assumes reduced_tx_set_used == 0. I will do a
3251 // follow up refactor to make the actual value of reduced_tx_set_used
3252 // within this function.
3253 txfm_param->tx_set_type = get_ext_tx_set_type(
3254 txfm_param->tx_size, plane_bsize, is_inter_block(&xd->mi[0]->mbmi), 0);
3255#endif // CONFIG_EXT_TX
Lester Lu708c1ec2017-06-14 14:54:49 -07003256#if CONFIG_LGT
Lester Lu27319b62017-07-10 16:57:15 -07003257 txfm_param->is_inter = is_inter_block(&xd->mi[0]->mbmi);
Lester Lu708c1ec2017-06-14 14:54:49 -07003258#endif
Lester Lu432012f2017-08-17 14:39:29 -07003259#if CONFIG_LGT_FROM_PRED
3260 txfm_param->use_lgt = xd->mi[0]->mbmi.use_lgt;
3261#endif
Yi Luof8e87b42017-04-14 17:20:27 -07003262#if CONFIG_ADAPT_SCAN
Lester Lu27319b62017-07-10 16:57:15 -07003263 txfm_param->eob_threshold =
Yi Luo2ab63cb2017-05-11 16:44:22 -07003264 (const int16_t *)&xd->eob_threshold_md[tx_size][tx_type][0];
Yi Luof8e87b42017-04-14 17:20:27 -07003265#endif
3266}
3267
Angie Chiangad653a32017-07-31 15:30:58 -07003268#if !CONFIG_TXMG
Yi Luo51281092017-06-26 16:36:15 -07003269typedef void (*InvTxfmFunc)(const tran_low_t *dqcoeff, uint8_t *dst, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07003270 TxfmParam *txfm_param);
Yi Luo51281092017-06-26 16:36:15 -07003271
3272static InvTxfmFunc inv_txfm_func[2] = { av1_inv_txfm_add,
3273 av1_highbd_inv_txfm_add };
Angie Chiangad653a32017-07-31 15:30:58 -07003274#endif
Yi Luo51281092017-06-26 16:36:15 -07003275
Urvang Joshi0d1e4ff2017-04-27 16:17:25 -07003276void av1_inverse_transform_block(const MACROBLOCKD *xd,
Lester Lu708c1ec2017-06-14 14:54:49 -07003277 const tran_low_t *dqcoeff,
Lester Lu432012f2017-08-17 14:39:29 -07003278#if CONFIG_LGT_FROM_PRED
Lester Lu708c1ec2017-06-14 14:54:49 -07003279 PREDICTION_MODE mode,
3280#endif
Sarah Parker99e7daa2017-08-29 10:30:13 -07003281#if CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
3282 uint8_t *mrc_mask,
3283#endif // CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
Sarah Parker90024e42017-10-06 16:50:47 -07003284#if CONFIG_EXT_TX
3285 int plane,
3286#endif // CONFIG_EXT_TX
Lester Lu708c1ec2017-06-14 14:54:49 -07003287 TX_TYPE tx_type, TX_SIZE tx_size, uint8_t *dst,
3288 int stride, int eob) {
Angie Chiangd92d4bf2017-04-02 17:49:18 -07003289 if (!eob) return;
Yushin Chod0b77ac2017-10-20 17:33:16 -07003290
Lester Lu27319b62017-07-10 16:57:15 -07003291 TxfmParam txfm_param;
Sarah Parker90024e42017-10-06 16:50:47 -07003292 init_txfm_param(xd,
3293#if CONFIG_EXT_TX
3294 plane,
3295#endif // CONFIG_EXT_TX
3296 tx_size, tx_type, eob, &txfm_param);
Sarah Parker5b8e6d22017-07-24 15:30:53 -07003297#if CONFIG_LGT || CONFIG_MRC_TX
Lester Lu918fe692017-08-17 14:39:29 -07003298 txfm_param.is_inter = is_inter_block(&xd->mi[0]->mbmi);
Lester Lu432012f2017-08-17 14:39:29 -07003299#endif // CONFIG_LGT || CONFIG_MRC_TX
Sarah Parker99e7daa2017-08-29 10:30:13 -07003300#if CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
3301 txfm_param.mask = mrc_mask;
3302#endif // CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
Lester Lu432012f2017-08-17 14:39:29 -07003303#if CONFIG_LGT_FROM_PRED || CONFIG_MRC_TX
3304 txfm_param.dst = dst;
3305 txfm_param.stride = stride;
3306#if CONFIG_LGT_FROM_PRED
Sarah Parker5b8e6d22017-07-24 15:30:53 -07003307 txfm_param.mode = mode;
Lester Lu432012f2017-08-17 14:39:29 -07003308#endif // CONFIG_LGT_FROM_PRED
3309#endif // CONFIG_LGT_FROM_PRED || CONFIG_MRC_TX
Sarah Parker90024e42017-10-06 16:50:47 -07003310#if CONFIG_EXT_TX
3311 assert(av1_ext_tx_used[txfm_param.tx_set_type][txfm_param.tx_type]);
3312#endif // CONFIG_EXT_TX
Angie Chiangd92d4bf2017-04-02 17:49:18 -07003313
Yi Luo51281092017-06-26 16:36:15 -07003314 const int is_hbd = get_bitdepth_data_path_index(xd);
Angie Chiange3b604d2017-08-06 16:01:24 -07003315#if CONFIG_TXMG
3316 if (is_hbd) {
3317 av1_highbd_inv_txfm_add(dqcoeff, dst, stride, &txfm_param);
3318 } else {
3319 DECLARE_ALIGNED(16, uint16_t, tmp[MAX_TX_SQUARE]);
3320 int tmp_stride = MAX_TX_SIZE;
3321 int w = tx_size_wide[tx_size];
3322 int h = tx_size_high[tx_size];
3323 for (int r = 0; r < h; ++r) {
3324 for (int c = 0; c < w; ++c) {
3325 tmp[r * tmp_stride + c] = dst[r * stride + c];
3326 }
3327 }
3328
3329 av1_highbd_inv_txfm_add(dqcoeff, CONVERT_TO_BYTEPTR(tmp), tmp_stride,
3330 &txfm_param);
3331
3332 for (int r = 0; r < h; ++r) {
3333 for (int c = 0; c < w; ++c) {
Debargha Mukherjee5c3b0f82017-10-08 09:38:15 -07003334 dst[r * stride + c] = (uint8_t)tmp[r * tmp_stride + c];
Angie Chiange3b604d2017-08-06 16:01:24 -07003335 }
3336 }
3337 }
3338#else // CONFIG_TXMG
Lester Lu27319b62017-07-10 16:57:15 -07003339 inv_txfm_func[is_hbd](dqcoeff, dst, stride, &txfm_param);
Angie Chiangad653a32017-07-31 15:30:58 -07003340#endif // CONFIG_TXMG
Angie Chiangd92d4bf2017-04-02 17:49:18 -07003341}
3342
Angie Chiangbc2288c2017-04-09 15:41:17 -07003343void av1_inverse_transform_block_facade(MACROBLOCKD *xd, int plane, int block,
3344 int blk_row, int blk_col, int eob) {
3345 struct macroblockd_plane *const pd = &xd->plane[plane];
3346 tran_low_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
Sarah Parker99e7daa2017-08-29 10:30:13 -07003347#if CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
3348 uint8_t *mrc_mask = BLOCK_OFFSET(xd->mrc_mask, block);
3349#endif // CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
Angie Chiangbc2288c2017-04-09 15:41:17 -07003350 const PLANE_TYPE plane_type = get_plane_type(plane);
hui su0c6244b2017-07-12 17:11:43 -07003351 const TX_SIZE tx_size = av1_get_tx_size(plane, xd);
Jingning Han19b5c8f2017-07-06 15:10:12 -07003352 const TX_TYPE tx_type =
3353 av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size);
Angie Chiangbc2288c2017-04-09 15:41:17 -07003354 const int dst_stride = pd->dst.stride;
3355 uint8_t *dst =
3356 &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]];
Lester Lu918fe692017-08-17 14:39:29 -07003357 av1_inverse_transform_block(xd, dqcoeff,
Lester Lu432012f2017-08-17 14:39:29 -07003358#if CONFIG_LGT_FROM_PRED
Lester Lu918fe692017-08-17 14:39:29 -07003359 xd->mi[0]->mbmi.mode,
Lester Lu432012f2017-08-17 14:39:29 -07003360#endif // CONFIG_LGT_FROM_PRED
Sarah Parker99e7daa2017-08-29 10:30:13 -07003361#if CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
3362 mrc_mask,
3363#endif // CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
Sarah Parker90024e42017-10-06 16:50:47 -07003364#if CONFIG_EXT_TX
3365 plane,
3366#endif // CONFIG_EXT_TX
Lester Lu918fe692017-08-17 14:39:29 -07003367 tx_type, tx_size, dst, dst_stride, eob);
Angie Chiangbc2288c2017-04-09 15:41:17 -07003368}
3369
hui subb9c73b2017-03-17 15:51:02 -07003370void av1_highbd_inv_txfm_add(const tran_low_t *input, uint8_t *dest, int stride,
Lester Lu27319b62017-07-10 16:57:15 -07003371 TxfmParam *txfm_param) {
3372 const TX_SIZE tx_size = txfm_param->tx_size;
Sarah Parker90024e42017-10-06 16:50:47 -07003373#if CONFIG_EXT_TX
3374 assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
3375#endif // CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07003376 switch (tx_size) {
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07003377#if CONFIG_TX64X64
Lester Lu27319b62017-07-10 16:57:15 -07003378 case TX_64X64:
3379 highbd_inv_txfm_add_64x64(input, dest, stride, txfm_param);
3380 break;
Debargha Mukherjee6a47cff2016-11-02 14:57:42 -07003381#endif // CONFIG_TX64X64
Lester Lu27319b62017-07-10 16:57:15 -07003382 case TX_32X32:
3383 highbd_inv_txfm_add_32x32(input, dest, stride, txfm_param);
3384 break;
3385 case TX_16X16:
3386 highbd_inv_txfm_add_16x16(input, dest, stride, txfm_param);
3387 break;
3388 case TX_8X8:
3389 highbd_inv_txfm_add_8x8(input, dest, stride, txfm_param);
3390 break;
3391 case TX_4X8:
3392 av1_highbd_inv_txfm_add_4x8(input, dest, stride, txfm_param);
3393 break;
3394 case TX_8X4:
3395 av1_highbd_inv_txfm_add_8x4(input, dest, stride, txfm_param);
3396 break;
3397 case TX_8X16:
3398 highbd_inv_txfm_add_8x16(input, dest, stride, txfm_param);
3399 break;
3400 case TX_16X8:
3401 highbd_inv_txfm_add_16x8(input, dest, stride, txfm_param);
3402 break;
3403 case TX_16X32:
3404 highbd_inv_txfm_add_16x32(input, dest, stride, txfm_param);
3405 break;
3406 case TX_32X16:
3407 highbd_inv_txfm_add_32x16(input, dest, stride, txfm_param);
3408 break;
Debargha Mukherjee2b435012017-09-28 08:30:35 -07003409#if CONFIG_TX64X64
3410 case TX_64X32:
3411 highbd_inv_txfm_add_64x32(input, dest, stride, txfm_param);
3412 break;
3413 case TX_32X64:
3414 highbd_inv_txfm_add_32x64(input, dest, stride, txfm_param);
3415 break;
3416#endif // CONFIG_TX64X64
Yaowu Xuc27fc142016-08-22 16:08:15 -07003417 case TX_4X4:
Yaowu Xuf883b422016-08-30 14:01:10 -07003418 // this is like av1_short_idct4x4 but has a special case around eob<=1
Yaowu Xuc27fc142016-08-22 16:08:15 -07003419 // which is significant (not just an optimization) for the lossless
3420 // case.
Lester Lu27319b62017-07-10 16:57:15 -07003421 av1_highbd_inv_txfm_add_4x4(input, dest, stride, txfm_param);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003422 break;
3423 default: assert(0 && "Invalid transform size"); break;
3424 }
3425}