• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * 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.
10  */
11 
12 #include <assert.h>
13 
14 #include "config/aom_dsp_rtcd.h"
15 #include "config/av1_rtcd.h"
16 
17 #include "aom_dsp/txfm_common.h"
18 #include "av1/common/enums.h"
19 #include "av1/common/av1_txfm.h"
20 #include "av1/encoder/av1_fwd_txfm1d.h"
21 #include "av1/encoder/av1_fwd_txfm1d_cfg.h"
22 
fwd_txfm_type_to_func(TXFM_TYPE txfm_type)23 static INLINE TxfmFunc fwd_txfm_type_to_func(TXFM_TYPE txfm_type) {
24   switch (txfm_type) {
25     case TXFM_TYPE_DCT4: return av1_fdct4_new;
26     case TXFM_TYPE_DCT8: return av1_fdct8_new;
27     case TXFM_TYPE_DCT16: return av1_fdct16_new;
28     case TXFM_TYPE_DCT32: return av1_fdct32_new;
29     case TXFM_TYPE_DCT64: return av1_fdct64_new;
30     case TXFM_TYPE_ADST4: return av1_fadst4_new;
31     case TXFM_TYPE_ADST8: return av1_fadst8_new;
32     case TXFM_TYPE_ADST16: return av1_fadst16_new;
33     case TXFM_TYPE_IDENTITY4: return av1_fidentity4_c;
34     case TXFM_TYPE_IDENTITY8: return av1_fidentity8_c;
35     case TXFM_TYPE_IDENTITY16: return av1_fidentity16_c;
36     case TXFM_TYPE_IDENTITY32: return av1_fidentity32_c;
37     default: assert(0); return NULL;
38   }
39 }
40 
av1_gen_fwd_stage_range(int8_t * stage_range_col,int8_t * stage_range_row,const TXFM_2D_FLIP_CFG * cfg,int bd)41 void av1_gen_fwd_stage_range(int8_t *stage_range_col, int8_t *stage_range_row,
42                              const TXFM_2D_FLIP_CFG *cfg, int bd) {
43   // Take the shift from the larger dimension in the rectangular case.
44   const int8_t *shift = cfg->shift;
45   // i < MAX_TXFM_STAGE_NUM will mute above array bounds warning
46   for (int i = 0; i < cfg->stage_num_col && i < MAX_TXFM_STAGE_NUM; ++i) {
47     stage_range_col[i] = cfg->stage_range_col[i] + shift[0] + bd + 1;
48   }
49 
50   // i < MAX_TXFM_STAGE_NUM will mute above array bounds warning
51   for (int i = 0; i < cfg->stage_num_row && i < MAX_TXFM_STAGE_NUM; ++i) {
52     stage_range_row[i] = cfg->stage_range_row[i] + shift[0] + shift[1] + bd + 1;
53   }
54 }
55 
fwd_txfm2d_c(const int16_t * input,int32_t * output,const int stride,const TXFM_2D_FLIP_CFG * cfg,int32_t * buf,int bd)56 static INLINE void fwd_txfm2d_c(const int16_t *input, int32_t *output,
57                                 const int stride, const TXFM_2D_FLIP_CFG *cfg,
58                                 int32_t *buf, int bd) {
59   int c, r;
60   // Note when assigning txfm_size_col, we use the txfm_size from the
61   // row configuration and vice versa. This is intentionally done to
62   // accurately perform rectangular transforms. When the transform is
63   // rectangular, the number of columns will be the same as the
64   // txfm_size stored in the row cfg struct. It will make no difference
65   // for square transforms.
66   const int txfm_size_col = tx_size_wide[cfg->tx_size];
67   const int txfm_size_row = tx_size_high[cfg->tx_size];
68   // Take the shift from the larger dimension in the rectangular case.
69   const int8_t *shift = cfg->shift;
70   const int rect_type = get_rect_tx_log_ratio(txfm_size_col, txfm_size_row);
71   int8_t stage_range_col[MAX_TXFM_STAGE_NUM];
72   int8_t stage_range_row[MAX_TXFM_STAGE_NUM];
73   assert(cfg->stage_num_col <= MAX_TXFM_STAGE_NUM);
74   assert(cfg->stage_num_row <= MAX_TXFM_STAGE_NUM);
75   av1_gen_fwd_stage_range(stage_range_col, stage_range_row, cfg, bd);
76 
77   const int8_t cos_bit_col = cfg->cos_bit_col;
78   const int8_t cos_bit_row = cfg->cos_bit_row;
79   const TxfmFunc txfm_func_col = fwd_txfm_type_to_func(cfg->txfm_type_col);
80   const TxfmFunc txfm_func_row = fwd_txfm_type_to_func(cfg->txfm_type_row);
81 
82   // use output buffer as temp buffer
83   int32_t *temp_in = output;
84   int32_t *temp_out = output + txfm_size_row;
85 
86   // Columns
87   for (c = 0; c < txfm_size_col; ++c) {
88     if (cfg->ud_flip == 0) {
89       for (r = 0; r < txfm_size_row; ++r) temp_in[r] = input[r * stride + c];
90     } else {
91       for (r = 0; r < txfm_size_row; ++r)
92         // flip upside down
93         temp_in[r] = input[(txfm_size_row - r - 1) * stride + c];
94     }
95     av1_round_shift_array(temp_in, txfm_size_row, -shift[0]);
96     txfm_func_col(temp_in, temp_out, cos_bit_col, stage_range_col);
97     av1_round_shift_array(temp_out, txfm_size_row, -shift[1]);
98     if (cfg->lr_flip == 0) {
99       for (r = 0; r < txfm_size_row; ++r)
100         buf[r * txfm_size_col + c] = temp_out[r];
101     } else {
102       for (r = 0; r < txfm_size_row; ++r)
103         // flip from left to right
104         buf[r * txfm_size_col + (txfm_size_col - c - 1)] = temp_out[r];
105     }
106   }
107 
108   // Rows
109   for (r = 0; r < txfm_size_row; ++r) {
110     txfm_func_row(buf + r * txfm_size_col, output + r * txfm_size_col,
111                   cos_bit_row, stage_range_row);
112     av1_round_shift_array(output + r * txfm_size_col, txfm_size_col, -shift[2]);
113     if (abs(rect_type) == 1) {
114       // Multiply everything by Sqrt2 if the transform is rectangular and the
115       // size difference is a factor of 2.
116       for (c = 0; c < txfm_size_col; ++c) {
117         output[r * txfm_size_col + c] = round_shift(
118             (int64_t)output[r * txfm_size_col + c] * NewSqrt2, NewSqrt2Bits);
119       }
120     }
121   }
122 }
123 
av1_fwd_txfm2d_4x8_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)124 void av1_fwd_txfm2d_4x8_c(const int16_t *input, int32_t *output, int stride,
125                           TX_TYPE tx_type, int bd) {
126   DECLARE_ALIGNED(32, int32_t, txfm_buf[4 * 8]);
127   TXFM_2D_FLIP_CFG cfg;
128   av1_get_fwd_txfm_cfg(tx_type, TX_4X8, &cfg);
129   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
130 }
131 
av1_fwd_txfm2d_8x4_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)132 void av1_fwd_txfm2d_8x4_c(const int16_t *input, int32_t *output, int stride,
133                           TX_TYPE tx_type, int bd) {
134   int32_t txfm_buf[8 * 4];
135   TXFM_2D_FLIP_CFG cfg;
136   av1_get_fwd_txfm_cfg(tx_type, TX_8X4, &cfg);
137   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
138 }
139 
av1_fwd_txfm2d_8x16_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)140 void av1_fwd_txfm2d_8x16_c(const int16_t *input, int32_t *output, int stride,
141                            TX_TYPE tx_type, int bd) {
142   DECLARE_ALIGNED(32, int32_t, txfm_buf[8 * 16]);
143   TXFM_2D_FLIP_CFG cfg;
144   av1_get_fwd_txfm_cfg(tx_type, TX_8X16, &cfg);
145   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
146 }
147 
av1_fwd_txfm2d_16x8_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)148 void av1_fwd_txfm2d_16x8_c(const int16_t *input, int32_t *output, int stride,
149                            TX_TYPE tx_type, int bd) {
150   int32_t txfm_buf[16 * 8];
151   TXFM_2D_FLIP_CFG cfg;
152   av1_get_fwd_txfm_cfg(tx_type, TX_16X8, &cfg);
153   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
154 }
155 
av1_fwd_txfm2d_16x32_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)156 void av1_fwd_txfm2d_16x32_c(const int16_t *input, int32_t *output, int stride,
157                             TX_TYPE tx_type, int bd) {
158   DECLARE_ALIGNED(32, int32_t, txfm_buf[16 * 32]);
159   TXFM_2D_FLIP_CFG cfg;
160   av1_get_fwd_txfm_cfg(tx_type, TX_16X32, &cfg);
161   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
162 }
163 
av1_fwd_txfm2d_32x16_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)164 void av1_fwd_txfm2d_32x16_c(const int16_t *input, int32_t *output, int stride,
165                             TX_TYPE tx_type, int bd) {
166   int32_t txfm_buf[32 * 16];
167   TXFM_2D_FLIP_CFG cfg;
168   av1_get_fwd_txfm_cfg(tx_type, TX_32X16, &cfg);
169   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
170 }
171 
av1_fwd_txfm2d_4x16_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)172 void av1_fwd_txfm2d_4x16_c(const int16_t *input, int32_t *output, int stride,
173                            TX_TYPE tx_type, int bd) {
174   DECLARE_ALIGNED(32, int32_t, txfm_buf[4 * 16]);
175   TXFM_2D_FLIP_CFG cfg;
176   av1_get_fwd_txfm_cfg(tx_type, TX_4X16, &cfg);
177   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
178 }
179 
av1_fwd_txfm2d_16x4_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)180 void av1_fwd_txfm2d_16x4_c(const int16_t *input, int32_t *output, int stride,
181                            TX_TYPE tx_type, int bd) {
182   int32_t txfm_buf[16 * 4];
183   TXFM_2D_FLIP_CFG cfg;
184   av1_get_fwd_txfm_cfg(tx_type, TX_16X4, &cfg);
185   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
186 }
187 
av1_fwd_txfm2d_8x32_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)188 void av1_fwd_txfm2d_8x32_c(const int16_t *input, int32_t *output, int stride,
189                            TX_TYPE tx_type, int bd) {
190   DECLARE_ALIGNED(32, int32_t, txfm_buf[32 * 8]);
191   TXFM_2D_FLIP_CFG cfg;
192   av1_get_fwd_txfm_cfg(tx_type, TX_8X32, &cfg);
193   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
194 }
195 
av1_fwd_txfm2d_32x8_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)196 void av1_fwd_txfm2d_32x8_c(const int16_t *input, int32_t *output, int stride,
197                            TX_TYPE tx_type, int bd) {
198   int32_t txfm_buf[32 * 8];
199   TXFM_2D_FLIP_CFG cfg;
200   av1_get_fwd_txfm_cfg(tx_type, TX_32X8, &cfg);
201   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
202 }
203 
av1_fwd_txfm2d_4x4_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)204 void av1_fwd_txfm2d_4x4_c(const int16_t *input, int32_t *output, int stride,
205                           TX_TYPE tx_type, int bd) {
206   int32_t txfm_buf[4 * 4];
207   TXFM_2D_FLIP_CFG cfg;
208   av1_get_fwd_txfm_cfg(tx_type, TX_4X4, &cfg);
209   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
210 }
211 
av1_fwd_txfm2d_8x8_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)212 void av1_fwd_txfm2d_8x8_c(const int16_t *input, int32_t *output, int stride,
213                           TX_TYPE tx_type, int bd) {
214   int32_t txfm_buf[8 * 8];
215   TXFM_2D_FLIP_CFG cfg;
216   av1_get_fwd_txfm_cfg(tx_type, TX_8X8, &cfg);
217   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
218 }
219 
av1_fwd_txfm2d_16x16_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)220 void av1_fwd_txfm2d_16x16_c(const int16_t *input, int32_t *output, int stride,
221                             TX_TYPE tx_type, int bd) {
222   int32_t txfm_buf[16 * 16];
223   TXFM_2D_FLIP_CFG cfg;
224   av1_get_fwd_txfm_cfg(tx_type, TX_16X16, &cfg);
225   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
226 }
227 
av1_fwd_txfm2d_32x32_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)228 void av1_fwd_txfm2d_32x32_c(const int16_t *input, int32_t *output, int stride,
229                             TX_TYPE tx_type, int bd) {
230   int32_t txfm_buf[32 * 32];
231   TXFM_2D_FLIP_CFG cfg;
232   av1_get_fwd_txfm_cfg(tx_type, TX_32X32, &cfg);
233   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
234 }
235 
av1_fwd_txfm2d_64x64_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)236 void av1_fwd_txfm2d_64x64_c(const int16_t *input, int32_t *output, int stride,
237                             TX_TYPE tx_type, int bd) {
238   int32_t txfm_buf[64 * 64];
239   TXFM_2D_FLIP_CFG cfg;
240   av1_get_fwd_txfm_cfg(tx_type, TX_64X64, &cfg);
241   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
242 
243   // Zero out top-right 32x32 area.
244   for (int row = 0; row < 32; ++row) {
245     memset(output + row * 64 + 32, 0, 32 * sizeof(*output));
246   }
247   // Zero out the bottom 64x32 area.
248   memset(output + 32 * 64, 0, 32 * 64 * sizeof(*output));
249   // Re-pack non-zero coeffs in the first 32x32 indices.
250   for (int row = 1; row < 32; ++row) {
251     memcpy(output + row * 32, output + row * 64, 32 * sizeof(*output));
252   }
253 }
254 
av1_fwd_txfm2d_32x64_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)255 void av1_fwd_txfm2d_32x64_c(const int16_t *input, int32_t *output, int stride,
256                             TX_TYPE tx_type, int bd) {
257   DECLARE_ALIGNED(32, int32_t, txfm_buf[32 * 64]);
258   TXFM_2D_FLIP_CFG cfg;
259   av1_get_fwd_txfm_cfg(tx_type, TX_32X64, &cfg);
260   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
261   // Zero out the bottom 32x32 area.
262   memset(output + 32 * 32, 0, 32 * 32 * sizeof(*output));
263   // Note: no repacking needed here.
264 }
265 
av1_fwd_txfm2d_64x32_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)266 void av1_fwd_txfm2d_64x32_c(const int16_t *input, int32_t *output, int stride,
267                             TX_TYPE tx_type, int bd) {
268   int32_t txfm_buf[64 * 32];
269   TXFM_2D_FLIP_CFG cfg;
270   av1_get_fwd_txfm_cfg(tx_type, TX_64X32, &cfg);
271   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
272 
273   // Zero out right 32x32 area.
274   for (int row = 0; row < 32; ++row) {
275     memset(output + row * 64 + 32, 0, 32 * sizeof(*output));
276   }
277   // Re-pack non-zero coeffs in the first 32x32 indices.
278   for (int row = 1; row < 32; ++row) {
279     memcpy(output + row * 32, output + row * 64, 32 * sizeof(*output));
280   }
281 }
282 
av1_fwd_txfm2d_16x64_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)283 void av1_fwd_txfm2d_16x64_c(const int16_t *input, int32_t *output, int stride,
284                             TX_TYPE tx_type, int bd) {
285   DECLARE_ALIGNED(32, int32_t, txfm_buf[64 * 16]);
286   TXFM_2D_FLIP_CFG cfg;
287   av1_get_fwd_txfm_cfg(tx_type, TX_16X64, &cfg);
288   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
289   // Zero out the bottom 16x32 area.
290   memset(output + 16 * 32, 0, 16 * 32 * sizeof(*output));
291   // Note: no repacking needed here.
292 }
293 
av1_fwd_txfm2d_64x16_c(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)294 void av1_fwd_txfm2d_64x16_c(const int16_t *input, int32_t *output, int stride,
295                             TX_TYPE tx_type, int bd) {
296   int32_t txfm_buf[64 * 16];
297   TXFM_2D_FLIP_CFG cfg;
298   av1_get_fwd_txfm_cfg(tx_type, TX_64X16, &cfg);
299   fwd_txfm2d_c(input, output, stride, &cfg, txfm_buf, bd);
300   // Zero out right 32x16 area.
301   for (int row = 0; row < 16; ++row) {
302     memset(output + row * 64 + 32, 0, 32 * sizeof(*output));
303   }
304   // Re-pack non-zero coeffs in the first 32x16 indices.
305   for (int row = 1; row < 16; ++row) {
306     memcpy(output + row * 32, output + row * 64, 32 * sizeof(*output));
307   }
308 }
309 
310 static const int8_t fwd_shift_4x4[3] = { 2, 0, 0 };
311 static const int8_t fwd_shift_8x8[3] = { 2, -1, 0 };
312 static const int8_t fwd_shift_16x16[3] = { 2, -2, 0 };
313 static const int8_t fwd_shift_32x32[3] = { 2, -4, 0 };
314 static const int8_t fwd_shift_64x64[3] = { 0, -2, -2 };
315 static const int8_t fwd_shift_4x8[3] = { 2, -1, 0 };
316 static const int8_t fwd_shift_8x4[3] = { 2, -1, 0 };
317 static const int8_t fwd_shift_8x16[3] = { 2, -2, 0 };
318 static const int8_t fwd_shift_16x8[3] = { 2, -2, 0 };
319 static const int8_t fwd_shift_16x32[3] = { 2, -4, 0 };
320 static const int8_t fwd_shift_32x16[3] = { 2, -4, 0 };
321 static const int8_t fwd_shift_32x64[3] = { 0, -2, -2 };
322 static const int8_t fwd_shift_64x32[3] = { 2, -4, -2 };
323 static const int8_t fwd_shift_4x16[3] = { 2, -1, 0 };
324 static const int8_t fwd_shift_16x4[3] = { 2, -1, 0 };
325 static const int8_t fwd_shift_8x32[3] = { 2, -2, 0 };
326 static const int8_t fwd_shift_32x8[3] = { 2, -2, 0 };
327 static const int8_t fwd_shift_16x64[3] = { 0, -2, 0 };
328 static const int8_t fwd_shift_64x16[3] = { 2, -4, 0 };
329 
330 const int8_t *fwd_txfm_shift_ls[TX_SIZES_ALL] = {
331   fwd_shift_4x4,   fwd_shift_8x8,   fwd_shift_16x16, fwd_shift_32x32,
332   fwd_shift_64x64, fwd_shift_4x8,   fwd_shift_8x4,   fwd_shift_8x16,
333   fwd_shift_16x8,  fwd_shift_16x32, fwd_shift_32x16, fwd_shift_32x64,
334   fwd_shift_64x32, fwd_shift_4x16,  fwd_shift_16x4,  fwd_shift_8x32,
335   fwd_shift_32x8,  fwd_shift_16x64, fwd_shift_64x16,
336 };
337 
338 const int8_t fwd_cos_bit_col[MAX_TXWH_IDX /*txw_idx*/]
339                             [MAX_TXWH_IDX /*txh_idx*/] = {
340                               { 13, 13, 13, 0, 0 },
341                               { 13, 13, 13, 12, 0 },
342                               { 13, 13, 13, 12, 13 },
343                               { 0, 13, 13, 12, 13 },
344                               { 0, 0, 13, 12, 13 }
345                             };
346 
347 const int8_t fwd_cos_bit_row[MAX_TXWH_IDX /*txw_idx*/]
348                             [MAX_TXWH_IDX /*txh_idx*/] = {
349                               { 13, 13, 12, 0, 0 },
350                               { 13, 13, 13, 12, 0 },
351                               { 13, 13, 12, 13, 12 },
352                               { 0, 12, 13, 12, 11 },
353                               { 0, 0, 12, 11, 10 }
354                             };
355 
356 static const int8_t fdct4_range_mult2[4] = { 0, 2, 3, 3 };
357 static const int8_t fdct8_range_mult2[6] = { 0, 2, 4, 5, 5, 5 };
358 static const int8_t fdct16_range_mult2[8] = { 0, 2, 4, 6, 7, 7, 7, 7 };
359 static const int8_t fdct32_range_mult2[10] = { 0, 2, 4, 6, 8, 9, 9, 9, 9, 9 };
360 static const int8_t fdct64_range_mult2[12] = { 0,  2,  4,  6,  8,  10,
361                                                11, 11, 11, 11, 11, 11 };
362 
363 static const int8_t fadst4_range_mult2[7] = { 0, 2, 4, 3, 3, 3, 3 };
364 static const int8_t fadst8_range_mult2[8] = { 0, 0, 1, 3, 3, 5, 5, 5 };
365 static const int8_t fadst16_range_mult2[10] = { 0, 0, 1, 3, 3, 5, 5, 7, 7, 7 };
366 
367 static const int8_t fidtx4_range_mult2[1] = { 1 };
368 static const int8_t fidtx8_range_mult2[1] = { 2 };
369 static const int8_t fidtx16_range_mult2[1] = { 3 };
370 static const int8_t fidtx32_range_mult2[1] = { 4 };
371 
372 #if 0
373 const int8_t fwd_idtx_range_row[MAX_TXWH_IDX /*txw_idx*/]
374                                [MAX_TXWH_IDX /*txh_idx*/] = { { 2, 4, 5, 0, 0 },
375                                                               { 3, 4, 5, 6, 0 },
376                                                               { 4, 5, 6, 7, 8 },
377                                                               { 0, 5, 6, 7, 8 },
378                                                               { 0, 0, 7, 8,
379                                                                 9 } };
380 #endif
381 
382 const int8_t *fwd_txfm_range_mult2_list[TXFM_TYPES] = {
383   fdct4_range_mult2,  fdct8_range_mult2,   fdct16_range_mult2,
384   fdct32_range_mult2, fdct64_range_mult2,  fadst4_range_mult2,
385   fadst8_range_mult2, fadst16_range_mult2, fidtx4_range_mult2,
386   fidtx8_range_mult2, fidtx16_range_mult2, fidtx32_range_mult2
387 };
388 
set_fwd_txfm_non_scale_range(TXFM_2D_FLIP_CFG * cfg)389 static INLINE void set_fwd_txfm_non_scale_range(TXFM_2D_FLIP_CFG *cfg) {
390   av1_zero(cfg->stage_range_col);
391   av1_zero(cfg->stage_range_row);
392 
393   const int8_t *range_mult2_col = fwd_txfm_range_mult2_list[cfg->txfm_type_col];
394   if (cfg->txfm_type_col != TXFM_TYPE_INVALID) {
395     int stage_num_col = cfg->stage_num_col;
396     for (int i = 0; i < stage_num_col; ++i)
397       cfg->stage_range_col[i] = (range_mult2_col[i] + 1) >> 1;
398   }
399 
400   if (cfg->txfm_type_row != TXFM_TYPE_INVALID) {
401     int stage_num_row = cfg->stage_num_row;
402     const int8_t *range_mult2_row =
403         fwd_txfm_range_mult2_list[cfg->txfm_type_row];
404     for (int i = 0; i < stage_num_row; ++i) {
405       cfg->stage_range_row[i] =
406           (range_mult2_col[cfg->stage_num_col - 1] + range_mult2_row[i] + 1) >>
407           1;
408     }
409   }
410 }
411 
av1_get_fwd_txfm_cfg(TX_TYPE tx_type,TX_SIZE tx_size,TXFM_2D_FLIP_CFG * cfg)412 void av1_get_fwd_txfm_cfg(TX_TYPE tx_type, TX_SIZE tx_size,
413                           TXFM_2D_FLIP_CFG *cfg) {
414   assert(cfg != NULL);
415   cfg->tx_size = tx_size;
416   set_flip_cfg(tx_type, cfg);
417   const TX_TYPE_1D tx_type_1d_col = vtx_tab[tx_type];
418   const TX_TYPE_1D tx_type_1d_row = htx_tab[tx_type];
419   const int txw_idx = tx_size_wide_log2[tx_size] - tx_size_wide_log2[0];
420   const int txh_idx = tx_size_high_log2[tx_size] - tx_size_high_log2[0];
421   cfg->shift = fwd_txfm_shift_ls[tx_size];
422   cfg->cos_bit_col = fwd_cos_bit_col[txw_idx][txh_idx];
423   cfg->cos_bit_row = fwd_cos_bit_row[txw_idx][txh_idx];
424   cfg->txfm_type_col = av1_txfm_type_ls[txh_idx][tx_type_1d_col];
425   cfg->txfm_type_row = av1_txfm_type_ls[txw_idx][tx_type_1d_row];
426   cfg->stage_num_col = av1_txfm_stage_num_list[cfg->txfm_type_col];
427   cfg->stage_num_row = av1_txfm_stage_num_list[cfg->txfm_type_row];
428   set_fwd_txfm_non_scale_range(cfg);
429 }
430