Coverage Report

Created: 2022-08-24 06:15

/src/aom/av1/common/idct.c
Line
Count
Source (jump to first uncovered line)
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 <math.h>
13
14
#include "config/aom_dsp_rtcd.h"
15
#include "config/av1_rtcd.h"
16
17
#include "aom_ports/mem.h"
18
#include "av1/common/av1_inv_txfm1d_cfg.h"
19
#include "av1/common/av1_txfm.h"
20
#include "av1/common/blockd.h"
21
#include "av1/common/enums.h"
22
#include "av1/common/idct.h"
23
24
52.5M
int av1_get_tx_scale(const TX_SIZE tx_size) {
25
52.5M
  const int pels = tx_size_2d[tx_size];
26
  // Largest possible pels is 4096 (64x64).
27
52.5M
  return (pels > 256) + (pels > 1024);
28
52.5M
}
29
30
// NOTE: The implementation of all inverses need to be aware of the fact
31
// that input and output could be the same buffer.
32
33
// idct
34
void av1_highbd_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
35
51.2k
                            int eob, int bd) {
36
51.2k
  if (eob > 1)
37
8.12k
    av1_highbd_iwht4x4_16_add(input, dest, stride, bd);
38
43.0k
  else
39
43.0k
    av1_highbd_iwht4x4_1_add(input, dest, stride, bd);
40
51.2k
}
41
42
void av1_highbd_inv_txfm_add_4x4_c(const tran_low_t *input, uint8_t *dest,
43
85.8k
                                   int stride, const TxfmParam *txfm_param) {
44
85.8k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
45
85.8k
  int eob = txfm_param->eob;
46
85.8k
  int bd = txfm_param->bd;
47
85.8k
  int lossless = txfm_param->lossless;
48
85.8k
  const int32_t *src = cast_to_int32(input);
49
85.8k
  const TX_TYPE tx_type = txfm_param->tx_type;
50
85.8k
  if (lossless) {
51
51.2k
    assert(tx_type == DCT_DCT);
52
51.2k
    av1_highbd_iwht4x4_add(input, dest, stride, eob, bd);
53
51.2k
    return;
54
51.2k
  }
55
56
34.6k
  av1_inv_txfm2d_add_4x4_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, bd);
57
34.6k
}
58
59
void av1_highbd_inv_txfm_add_4x8_c(const tran_low_t *input, uint8_t *dest,
60
8.07k
                                   int stride, const TxfmParam *txfm_param) {
61
8.07k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
62
8.07k
  const int32_t *src = cast_to_int32(input);
63
8.07k
  av1_inv_txfm2d_add_4x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
64
8.07k
                           txfm_param->tx_type, txfm_param->bd);
65
8.07k
}
66
67
void av1_highbd_inv_txfm_add_8x4_c(const tran_low_t *input, uint8_t *dest,
68
8.08k
                                   int stride, const TxfmParam *txfm_param) {
69
8.08k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
70
8.08k
  const int32_t *src = cast_to_int32(input);
71
8.08k
  av1_inv_txfm2d_add_8x4_c(src, CONVERT_TO_SHORTPTR(dest), stride,
72
8.08k
                           txfm_param->tx_type, txfm_param->bd);
73
8.08k
}
74
75
void av1_highbd_inv_txfm_add_16x32_c(const tran_low_t *input, uint8_t *dest,
76
4.00k
                                     int stride, const TxfmParam *txfm_param) {
77
4.00k
  const int32_t *src = cast_to_int32(input);
78
4.00k
  av1_inv_txfm2d_add_16x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
79
4.00k
                             txfm_param->tx_type, txfm_param->bd);
80
4.00k
}
81
82
void av1_highbd_inv_txfm_add_32x16_c(const tran_low_t *input, uint8_t *dest,
83
4.30k
                                     int stride, const TxfmParam *txfm_param) {
84
4.30k
  const int32_t *src = cast_to_int32(input);
85
4.30k
  av1_inv_txfm2d_add_32x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
86
4.30k
                             txfm_param->tx_type, txfm_param->bd);
87
4.30k
}
88
89
void av1_highbd_inv_txfm_add_16x4_c(const tran_low_t *input, uint8_t *dest,
90
0
                                    int stride, const TxfmParam *txfm_param) {
91
0
  const int32_t *src = cast_to_int32(input);
92
0
  av1_inv_txfm2d_add_16x4_c(src, CONVERT_TO_SHORTPTR(dest), stride,
93
0
                            txfm_param->tx_type, txfm_param->bd);
94
0
}
95
96
void av1_highbd_inv_txfm_add_4x16_c(const tran_low_t *input, uint8_t *dest,
97
570
                                    int stride, const TxfmParam *txfm_param) {
98
570
  const int32_t *src = cast_to_int32(input);
99
570
  av1_inv_txfm2d_add_4x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
100
570
                            txfm_param->tx_type, txfm_param->bd);
101
570
}
102
103
void av1_highbd_inv_txfm_add_32x8_c(const tran_low_t *input, uint8_t *dest,
104
0
                                    int stride, const TxfmParam *txfm_param) {
105
0
  const int32_t *src = cast_to_int32(input);
106
0
  av1_inv_txfm2d_add_32x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
107
0
                            txfm_param->tx_type, txfm_param->bd);
108
0
}
109
110
void av1_highbd_inv_txfm_add_8x32_c(const tran_low_t *input, uint8_t *dest,
111
152
                                    int stride, const TxfmParam *txfm_param) {
112
152
  const int32_t *src = cast_to_int32(input);
113
152
  av1_inv_txfm2d_add_8x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
114
152
                            txfm_param->tx_type, txfm_param->bd);
115
152
}
116
117
void av1_highbd_inv_txfm_add_32x64_c(const tran_low_t *input, uint8_t *dest,
118
5.09k
                                     int stride, const TxfmParam *txfm_param) {
119
5.09k
  const int32_t *src = cast_to_int32(input);
120
5.09k
  av1_inv_txfm2d_add_32x64_c(src, CONVERT_TO_SHORTPTR(dest), stride,
121
5.09k
                             txfm_param->tx_type, txfm_param->bd);
122
5.09k
}
123
124
void av1_highbd_inv_txfm_add_64x32_c(const tran_low_t *input, uint8_t *dest,
125
5.62k
                                     int stride, const TxfmParam *txfm_param) {
126
5.62k
  const int32_t *src = cast_to_int32(input);
127
5.62k
  av1_inv_txfm2d_add_64x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
128
5.62k
                             txfm_param->tx_type, txfm_param->bd);
129
5.62k
}
130
131
void av1_highbd_inv_txfm_add_16x64_c(const tran_low_t *input, uint8_t *dest,
132
0
                                     int stride, const TxfmParam *txfm_param) {
133
0
  const int32_t *src = cast_to_int32(input);
134
0
  av1_inv_txfm2d_add_16x64_c(src, CONVERT_TO_SHORTPTR(dest), stride,
135
0
                             txfm_param->tx_type, txfm_param->bd);
136
0
}
137
138
void av1_highbd_inv_txfm_add_64x16_c(const tran_low_t *input, uint8_t *dest,
139
0
                                     int stride, const TxfmParam *txfm_param) {
140
0
  const int32_t *src = cast_to_int32(input);
141
0
  av1_inv_txfm2d_add_64x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
142
0
                             txfm_param->tx_type, txfm_param->bd);
143
0
}
144
145
void av1_highbd_inv_txfm_add_8x8_c(const tran_low_t *input, uint8_t *dest,
146
17.7k
                                   int stride, const TxfmParam *txfm_param) {
147
17.7k
  int bd = txfm_param->bd;
148
17.7k
  const TX_TYPE tx_type = txfm_param->tx_type;
149
17.7k
  const int32_t *src = cast_to_int32(input);
150
151
17.7k
  av1_inv_txfm2d_add_8x8_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, bd);
152
17.7k
}
153
154
void av1_highbd_inv_txfm_add_16x16_c(const tran_low_t *input, uint8_t *dest,
155
29.0k
                                     int stride, const TxfmParam *txfm_param) {
156
29.0k
  int bd = txfm_param->bd;
157
29.0k
  const TX_TYPE tx_type = txfm_param->tx_type;
158
29.0k
  const int32_t *src = cast_to_int32(input);
159
160
29.0k
  av1_inv_txfm2d_add_16x16_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
161
29.0k
                             bd);
162
29.0k
}
163
164
void av1_highbd_inv_txfm_add_8x16_c(const tran_low_t *input, uint8_t *dest,
165
12.1k
                                    int stride, const TxfmParam *txfm_param) {
166
12.1k
  const int32_t *src = cast_to_int32(input);
167
12.1k
  av1_inv_txfm2d_add_8x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
168
12.1k
                            txfm_param->tx_type, txfm_param->bd);
169
12.1k
}
170
171
void av1_highbd_inv_txfm_add_16x8_c(const tran_low_t *input, uint8_t *dest,
172
12.4k
                                    int stride, const TxfmParam *txfm_param) {
173
12.4k
  const int32_t *src = cast_to_int32(input);
174
12.4k
  av1_inv_txfm2d_add_16x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
175
12.4k
                            txfm_param->tx_type, txfm_param->bd);
176
12.4k
}
177
178
void av1_highbd_inv_txfm_add_32x32_c(const tran_low_t *input, uint8_t *dest,
179
18.6k
                                     int stride, const TxfmParam *txfm_param) {
180
18.6k
  const int bd = txfm_param->bd;
181
18.6k
  const TX_TYPE tx_type = txfm_param->tx_type;
182
18.6k
  const int32_t *src = cast_to_int32(input);
183
184
18.6k
  av1_inv_txfm2d_add_32x32_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
185
18.6k
                             bd);
186
18.6k
}
187
188
void av1_highbd_inv_txfm_add_64x64_c(const tran_low_t *input, uint8_t *dest,
189
25.0k
                                     int stride, const TxfmParam *txfm_param) {
190
25.0k
  const int bd = txfm_param->bd;
191
25.0k
  const TX_TYPE tx_type = txfm_param->tx_type;
192
25.0k
  const int32_t *src = cast_to_int32(input);
193
25.0k
  assert(tx_type == DCT_DCT);
194
25.0k
  av1_inv_txfm2d_add_64x64_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
195
25.0k
                             bd);
196
25.0k
}
197
198
static void init_txfm_param(const MACROBLOCKD *xd, int plane, TX_SIZE tx_size,
199
                            TX_TYPE tx_type, int eob, int reduced_tx_set,
200
236k
                            TxfmParam *txfm_param) {
201
236k
  (void)plane;
202
236k
  txfm_param->tx_type = tx_type;
203
236k
  txfm_param->tx_size = tx_size;
204
236k
  txfm_param->eob = eob;
205
236k
  txfm_param->lossless = xd->lossless[xd->mi[0]->segment_id];
206
236k
  txfm_param->bd = xd->bd;
207
236k
  txfm_param->is_hbd = is_cur_buf_hbd(xd);
208
236k
  txfm_param->tx_set_type = av1_get_ext_tx_set_type(
209
236k
      txfm_param->tx_size, is_inter_block(xd->mi[0]), reduced_tx_set);
210
236k
}
211
212
void av1_highbd_inv_txfm_add_c(const tran_low_t *input, uint8_t *dest,
213
236k
                               int stride, const TxfmParam *txfm_param) {
214
236k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
215
236k
  const TX_SIZE tx_size = txfm_param->tx_size;
216
236k
  switch (tx_size) {
217
18.6k
    case TX_32X32:
218
18.6k
      av1_highbd_inv_txfm_add_32x32_c(input, dest, stride, txfm_param);
219
18.6k
      break;
220
29.0k
    case TX_16X16:
221
29.0k
      av1_highbd_inv_txfm_add_16x16_c(input, dest, stride, txfm_param);
222
29.0k
      break;
223
17.7k
    case TX_8X8:
224
17.7k
      av1_highbd_inv_txfm_add_8x8_c(input, dest, stride, txfm_param);
225
17.7k
      break;
226
8.07k
    case TX_4X8:
227
8.07k
      av1_highbd_inv_txfm_add_4x8_c(input, dest, stride, txfm_param);
228
8.07k
      break;
229
8.08k
    case TX_8X4:
230
8.08k
      av1_highbd_inv_txfm_add_8x4_c(input, dest, stride, txfm_param);
231
8.08k
      break;
232
12.1k
    case TX_8X16:
233
12.1k
      av1_highbd_inv_txfm_add_8x16_c(input, dest, stride, txfm_param);
234
12.1k
      break;
235
12.4k
    case TX_16X8:
236
12.4k
      av1_highbd_inv_txfm_add_16x8_c(input, dest, stride, txfm_param);
237
12.4k
      break;
238
4.00k
    case TX_16X32:
239
4.00k
      av1_highbd_inv_txfm_add_16x32_c(input, dest, stride, txfm_param);
240
4.00k
      break;
241
4.30k
    case TX_32X16:
242
4.30k
      av1_highbd_inv_txfm_add_32x16_c(input, dest, stride, txfm_param);
243
4.30k
      break;
244
25.0k
    case TX_64X64:
245
25.0k
      av1_highbd_inv_txfm_add_64x64_c(input, dest, stride, txfm_param);
246
25.0k
      break;
247
5.09k
    case TX_32X64:
248
5.09k
      av1_highbd_inv_txfm_add_32x64_c(input, dest, stride, txfm_param);
249
5.09k
      break;
250
5.62k
    case TX_64X32:
251
5.62k
      av1_highbd_inv_txfm_add_64x32_c(input, dest, stride, txfm_param);
252
5.62k
      break;
253
0
    case TX_16X64:
254
0
      av1_highbd_inv_txfm_add_16x64_c(input, dest, stride, txfm_param);
255
0
      break;
256
0
    case TX_64X16:
257
0
      av1_highbd_inv_txfm_add_64x16_c(input, dest, stride, txfm_param);
258
0
      break;
259
85.8k
    case TX_4X4:
260
      // this is like av1_short_idct4x4 but has a special case around eob<=1
261
      // which is significant (not just an optimization) for the lossless
262
      // case.
263
85.8k
      av1_highbd_inv_txfm_add_4x4_c(input, dest, stride, txfm_param);
264
85.8k
      break;
265
0
    case TX_16X4:
266
0
      av1_highbd_inv_txfm_add_16x4_c(input, dest, stride, txfm_param);
267
0
      break;
268
570
    case TX_4X16:
269
570
      av1_highbd_inv_txfm_add_4x16_c(input, dest, stride, txfm_param);
270
570
      break;
271
152
    case TX_8X32:
272
152
      av1_highbd_inv_txfm_add_8x32_c(input, dest, stride, txfm_param);
273
152
      break;
274
0
    case TX_32X8:
275
0
      av1_highbd_inv_txfm_add_32x8_c(input, dest, stride, txfm_param);
276
0
      break;
277
0
    default: assert(0 && "Invalid transform size"); break;
278
236k
  }
279
236k
}
280
281
void av1_inv_txfm_add_c(const tran_low_t *dqcoeff, uint8_t *dst, int stride,
282
236k
                        const TxfmParam *txfm_param) {
283
236k
  const TX_SIZE tx_size = txfm_param->tx_size;
284
236k
  DECLARE_ALIGNED(32, uint16_t, tmp[MAX_TX_SQUARE]);
285
236k
  int tmp_stride = MAX_TX_SIZE;
286
236k
  int w = tx_size_wide[tx_size];
287
236k
  int h = tx_size_high[tx_size];
288
4.49M
  for (int r = 0; r < h; ++r) {
289
165M
    for (int c = 0; c < w; ++c) {
290
161M
      tmp[r * tmp_stride + c] = dst[r * stride + c];
291
161M
    }
292
4.25M
  }
293
294
236k
  av1_highbd_inv_txfm_add(dqcoeff, CONVERT_TO_BYTEPTR(tmp), tmp_stride,
295
236k
                          txfm_param);
296
297
4.49M
  for (int r = 0; r < h; ++r) {
298
165M
    for (int c = 0; c < w; ++c) {
299
161M
      dst[r * stride + c] = (uint8_t)tmp[r * tmp_stride + c];
300
161M
    }
301
4.25M
  }
302
236k
}
303
304
void av1_inverse_transform_block(const MACROBLOCKD *xd,
305
                                 const tran_low_t *dqcoeff, int plane,
306
                                 TX_TYPE tx_type, TX_SIZE tx_size, uint8_t *dst,
307
236k
                                 int stride, int eob, int reduced_tx_set) {
308
236k
  if (!eob) return;
309
310
236k
  assert(eob <= av1_get_max_eob(tx_size));
311
312
236k
  TxfmParam txfm_param;
313
236k
  init_txfm_param(xd, plane, tx_size, tx_type, eob, reduced_tx_set,
314
236k
                  &txfm_param);
315
236k
  assert(av1_ext_tx_used[txfm_param.tx_set_type][txfm_param.tx_type]);
316
317
236k
  if (txfm_param.is_hbd) {
318
0
    av1_highbd_inv_txfm_add(dqcoeff, dst, stride, &txfm_param);
319
236k
  } else {
320
236k
    av1_inv_txfm_add(dqcoeff, dst, stride, &txfm_param);
321
236k
  }
322
236k
}