Coverage Report

Created: 2022-08-24 06:17

/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
1.70M
int av1_get_tx_scale(const TX_SIZE tx_size) {
25
1.70M
  const int pels = tx_size_2d[tx_size];
26
  // Largest possible pels is 4096 (64x64).
27
1.70M
  return (pels > 256) + (pels > 1024);
28
1.70M
}
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
89.2k
                            int eob, int bd) {
36
89.2k
  if (eob > 1)
37
57.9k
    av1_highbd_iwht4x4_16_add(input, dest, stride, bd);
38
31.3k
  else
39
31.3k
    av1_highbd_iwht4x4_1_add(input, dest, stride, bd);
40
89.2k
}
41
42
void av1_highbd_inv_txfm_add_4x4_c(const tran_low_t *input, uint8_t *dest,
43
146k
                                   int stride, const TxfmParam *txfm_param) {
44
146k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
45
146k
  int eob = txfm_param->eob;
46
146k
  int bd = txfm_param->bd;
47
146k
  int lossless = txfm_param->lossless;
48
146k
  const int32_t *src = cast_to_int32(input);
49
146k
  const TX_TYPE tx_type = txfm_param->tx_type;
50
146k
  if (lossless) {
51
89.2k
    assert(tx_type == DCT_DCT);
52
89.2k
    av1_highbd_iwht4x4_add(input, dest, stride, eob, bd);
53
89.2k
    return;
54
89.2k
  }
55
56
56.8k
  av1_inv_txfm2d_add_4x4_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, bd);
57
56.8k
}
58
59
void av1_highbd_inv_txfm_add_4x8_c(const tran_low_t *input, uint8_t *dest,
60
30.6k
                                   int stride, const TxfmParam *txfm_param) {
61
30.6k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
62
30.6k
  const int32_t *src = cast_to_int32(input);
63
30.6k
  av1_inv_txfm2d_add_4x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
64
30.6k
                           txfm_param->tx_type, txfm_param->bd);
65
30.6k
}
66
67
void av1_highbd_inv_txfm_add_8x4_c(const tran_low_t *input, uint8_t *dest,
68
46.4k
                                   int stride, const TxfmParam *txfm_param) {
69
46.4k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
70
46.4k
  const int32_t *src = cast_to_int32(input);
71
46.4k
  av1_inv_txfm2d_add_8x4_c(src, CONVERT_TO_SHORTPTR(dest), stride,
72
46.4k
                           txfm_param->tx_type, txfm_param->bd);
73
46.4k
}
74
75
void av1_highbd_inv_txfm_add_16x32_c(const tran_low_t *input, uint8_t *dest,
76
11.7k
                                     int stride, const TxfmParam *txfm_param) {
77
11.7k
  const int32_t *src = cast_to_int32(input);
78
11.7k
  av1_inv_txfm2d_add_16x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
79
11.7k
                             txfm_param->tx_type, txfm_param->bd);
80
11.7k
}
81
82
void av1_highbd_inv_txfm_add_32x16_c(const tran_low_t *input, uint8_t *dest,
83
14.0k
                                     int stride, const TxfmParam *txfm_param) {
84
14.0k
  const int32_t *src = cast_to_int32(input);
85
14.0k
  av1_inv_txfm2d_add_32x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
86
14.0k
                             txfm_param->tx_type, txfm_param->bd);
87
14.0k
}
88
89
void av1_highbd_inv_txfm_add_16x4_c(const tran_low_t *input, uint8_t *dest,
90
40.7k
                                    int stride, const TxfmParam *txfm_param) {
91
40.7k
  const int32_t *src = cast_to_int32(input);
92
40.7k
  av1_inv_txfm2d_add_16x4_c(src, CONVERT_TO_SHORTPTR(dest), stride,
93
40.7k
                            txfm_param->tx_type, txfm_param->bd);
94
40.7k
}
95
96
void av1_highbd_inv_txfm_add_4x16_c(const tran_low_t *input, uint8_t *dest,
97
26.2k
                                    int stride, const TxfmParam *txfm_param) {
98
26.2k
  const int32_t *src = cast_to_int32(input);
99
26.2k
  av1_inv_txfm2d_add_4x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
100
26.2k
                            txfm_param->tx_type, txfm_param->bd);
101
26.2k
}
102
103
void av1_highbd_inv_txfm_add_32x8_c(const tran_low_t *input, uint8_t *dest,
104
21.7k
                                    int stride, const TxfmParam *txfm_param) {
105
21.7k
  const int32_t *src = cast_to_int32(input);
106
21.7k
  av1_inv_txfm2d_add_32x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
107
21.7k
                            txfm_param->tx_type, txfm_param->bd);
108
21.7k
}
109
110
void av1_highbd_inv_txfm_add_8x32_c(const tran_low_t *input, uint8_t *dest,
111
19.1k
                                    int stride, const TxfmParam *txfm_param) {
112
19.1k
  const int32_t *src = cast_to_int32(input);
113
19.1k
  av1_inv_txfm2d_add_8x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
114
19.1k
                            txfm_param->tx_type, txfm_param->bd);
115
19.1k
}
116
117
void av1_highbd_inv_txfm_add_32x64_c(const tran_low_t *input, uint8_t *dest,
118
3.98k
                                     int stride, const TxfmParam *txfm_param) {
119
3.98k
  const int32_t *src = cast_to_int32(input);
120
3.98k
  av1_inv_txfm2d_add_32x64_c(src, CONVERT_TO_SHORTPTR(dest), stride,
121
3.98k
                             txfm_param->tx_type, txfm_param->bd);
122
3.98k
}
123
124
void av1_highbd_inv_txfm_add_64x32_c(const tran_low_t *input, uint8_t *dest,
125
5.01k
                                     int stride, const TxfmParam *txfm_param) {
126
5.01k
  const int32_t *src = cast_to_int32(input);
127
5.01k
  av1_inv_txfm2d_add_64x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
128
5.01k
                             txfm_param->tx_type, txfm_param->bd);
129
5.01k
}
130
131
void av1_highbd_inv_txfm_add_16x64_c(const tran_low_t *input, uint8_t *dest,
132
26.1k
                                     int stride, const TxfmParam *txfm_param) {
133
26.1k
  const int32_t *src = cast_to_int32(input);
134
26.1k
  av1_inv_txfm2d_add_16x64_c(src, CONVERT_TO_SHORTPTR(dest), stride,
135
26.1k
                             txfm_param->tx_type, txfm_param->bd);
136
26.1k
}
137
138
void av1_highbd_inv_txfm_add_64x16_c(const tran_low_t *input, uint8_t *dest,
139
6.07k
                                     int stride, const TxfmParam *txfm_param) {
140
6.07k
  const int32_t *src = cast_to_int32(input);
141
6.07k
  av1_inv_txfm2d_add_64x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
142
6.07k
                             txfm_param->tx_type, txfm_param->bd);
143
6.07k
}
144
145
void av1_highbd_inv_txfm_add_8x8_c(const tran_low_t *input, uint8_t *dest,
146
89.0k
                                   int stride, const TxfmParam *txfm_param) {
147
89.0k
  int bd = txfm_param->bd;
148
89.0k
  const TX_TYPE tx_type = txfm_param->tx_type;
149
89.0k
  const int32_t *src = cast_to_int32(input);
150
151
89.0k
  av1_inv_txfm2d_add_8x8_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, bd);
152
89.0k
}
153
154
void av1_highbd_inv_txfm_add_16x16_c(const tran_low_t *input, uint8_t *dest,
155
93.7k
                                     int stride, const TxfmParam *txfm_param) {
156
93.7k
  int bd = txfm_param->bd;
157
93.7k
  const TX_TYPE tx_type = txfm_param->tx_type;
158
93.7k
  const int32_t *src = cast_to_int32(input);
159
160
93.7k
  av1_inv_txfm2d_add_16x16_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
161
93.7k
                             bd);
162
93.7k
}
163
164
void av1_highbd_inv_txfm_add_8x16_c(const tran_low_t *input, uint8_t *dest,
165
30.2k
                                    int stride, const TxfmParam *txfm_param) {
166
30.2k
  const int32_t *src = cast_to_int32(input);
167
30.2k
  av1_inv_txfm2d_add_8x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
168
30.2k
                            txfm_param->tx_type, txfm_param->bd);
169
30.2k
}
170
171
void av1_highbd_inv_txfm_add_16x8_c(const tran_low_t *input, uint8_t *dest,
172
49.1k
                                    int stride, const TxfmParam *txfm_param) {
173
49.1k
  const int32_t *src = cast_to_int32(input);
174
49.1k
  av1_inv_txfm2d_add_16x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
175
49.1k
                            txfm_param->tx_type, txfm_param->bd);
176
49.1k
}
177
178
void av1_highbd_inv_txfm_add_32x32_c(const tran_low_t *input, uint8_t *dest,
179
63.2k
                                     int stride, const TxfmParam *txfm_param) {
180
63.2k
  const int bd = txfm_param->bd;
181
63.2k
  const TX_TYPE tx_type = txfm_param->tx_type;
182
63.2k
  const int32_t *src = cast_to_int32(input);
183
184
63.2k
  av1_inv_txfm2d_add_32x32_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
185
63.2k
                             bd);
186
63.2k
}
187
188
void av1_highbd_inv_txfm_add_64x64_c(const tran_low_t *input, uint8_t *dest,
189
48.0k
                                     int stride, const TxfmParam *txfm_param) {
190
48.0k
  const int bd = txfm_param->bd;
191
48.0k
  const TX_TYPE tx_type = txfm_param->tx_type;
192
48.0k
  const int32_t *src = cast_to_int32(input);
193
48.0k
  assert(tx_type == DCT_DCT);
194
48.0k
  av1_inv_txfm2d_add_64x64_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
195
48.0k
                             bd);
196
48.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
771k
                            TxfmParam *txfm_param) {
201
771k
  (void)plane;
202
771k
  txfm_param->tx_type = tx_type;
203
771k
  txfm_param->tx_size = tx_size;
204
771k
  txfm_param->eob = eob;
205
771k
  txfm_param->lossless = xd->lossless[xd->mi[0]->segment_id];
206
771k
  txfm_param->bd = xd->bd;
207
771k
  txfm_param->is_hbd = is_cur_buf_hbd(xd);
208
771k
  txfm_param->tx_set_type = av1_get_ext_tx_set_type(
209
771k
      txfm_param->tx_size, is_inter_block(xd->mi[0]), reduced_tx_set);
210
771k
}
211
212
void av1_highbd_inv_txfm_add_c(const tran_low_t *input, uint8_t *dest,
213
771k
                               int stride, const TxfmParam *txfm_param) {
214
771k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
215
771k
  const TX_SIZE tx_size = txfm_param->tx_size;
216
771k
  switch (tx_size) {
217
63.2k
    case TX_32X32:
218
63.2k
      av1_highbd_inv_txfm_add_32x32_c(input, dest, stride, txfm_param);
219
63.2k
      break;
220
93.7k
    case TX_16X16:
221
93.7k
      av1_highbd_inv_txfm_add_16x16_c(input, dest, stride, txfm_param);
222
93.7k
      break;
223
89.0k
    case TX_8X8:
224
89.0k
      av1_highbd_inv_txfm_add_8x8_c(input, dest, stride, txfm_param);
225
89.0k
      break;
226
30.6k
    case TX_4X8:
227
30.6k
      av1_highbd_inv_txfm_add_4x8_c(input, dest, stride, txfm_param);
228
30.6k
      break;
229
46.4k
    case TX_8X4:
230
46.4k
      av1_highbd_inv_txfm_add_8x4_c(input, dest, stride, txfm_param);
231
46.4k
      break;
232
30.2k
    case TX_8X16:
233
30.2k
      av1_highbd_inv_txfm_add_8x16_c(input, dest, stride, txfm_param);
234
30.2k
      break;
235
49.1k
    case TX_16X8:
236
49.1k
      av1_highbd_inv_txfm_add_16x8_c(input, dest, stride, txfm_param);
237
49.1k
      break;
238
11.7k
    case TX_16X32:
239
11.7k
      av1_highbd_inv_txfm_add_16x32_c(input, dest, stride, txfm_param);
240
11.7k
      break;
241
14.0k
    case TX_32X16:
242
14.0k
      av1_highbd_inv_txfm_add_32x16_c(input, dest, stride, txfm_param);
243
14.0k
      break;
244
48.0k
    case TX_64X64:
245
48.0k
      av1_highbd_inv_txfm_add_64x64_c(input, dest, stride, txfm_param);
246
48.0k
      break;
247
3.98k
    case TX_32X64:
248
3.98k
      av1_highbd_inv_txfm_add_32x64_c(input, dest, stride, txfm_param);
249
3.98k
      break;
250
5.01k
    case TX_64X32:
251
5.01k
      av1_highbd_inv_txfm_add_64x32_c(input, dest, stride, txfm_param);
252
5.01k
      break;
253
26.1k
    case TX_16X64:
254
26.1k
      av1_highbd_inv_txfm_add_16x64_c(input, dest, stride, txfm_param);
255
26.1k
      break;
256
6.07k
    case TX_64X16:
257
6.07k
      av1_highbd_inv_txfm_add_64x16_c(input, dest, stride, txfm_param);
258
6.07k
      break;
259
146k
    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
146k
      av1_highbd_inv_txfm_add_4x4_c(input, dest, stride, txfm_param);
264
146k
      break;
265
40.7k
    case TX_16X4:
266
40.7k
      av1_highbd_inv_txfm_add_16x4_c(input, dest, stride, txfm_param);
267
40.7k
      break;
268
26.2k
    case TX_4X16:
269
26.2k
      av1_highbd_inv_txfm_add_4x16_c(input, dest, stride, txfm_param);
270
26.2k
      break;
271
19.1k
    case TX_8X32:
272
19.1k
      av1_highbd_inv_txfm_add_8x32_c(input, dest, stride, txfm_param);
273
19.1k
      break;
274
21.7k
    case TX_32X8:
275
21.7k
      av1_highbd_inv_txfm_add_32x8_c(input, dest, stride, txfm_param);
276
21.7k
      break;
277
0
    default: assert(0 && "Invalid transform size"); break;
278
771k
  }
279
771k
}
280
281
void av1_inv_txfm_add_c(const tran_low_t *dqcoeff, uint8_t *dst, int stride,
282
320k
                        const TxfmParam *txfm_param) {
283
320k
  const TX_SIZE tx_size = txfm_param->tx_size;
284
320k
  DECLARE_ALIGNED(32, uint16_t, tmp[MAX_TX_SQUARE]);
285
320k
  int tmp_stride = MAX_TX_SIZE;
286
320k
  int w = tx_size_wide[tx_size];
287
320k
  int h = tx_size_high[tx_size];
288
6.07M
  for (int r = 0; r < h; ++r) {
289
165M
    for (int c = 0; c < w; ++c) {
290
159M
      tmp[r * tmp_stride + c] = dst[r * stride + c];
291
159M
    }
292
5.75M
  }
293
294
320k
  av1_highbd_inv_txfm_add(dqcoeff, CONVERT_TO_BYTEPTR(tmp), tmp_stride,
295
320k
                          txfm_param);
296
297
6.07M
  for (int r = 0; r < h; ++r) {
298
165M
    for (int c = 0; c < w; ++c) {
299
159M
      dst[r * stride + c] = (uint8_t)tmp[r * tmp_stride + c];
300
159M
    }
301
5.75M
  }
302
320k
}
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
788k
                                 int stride, int eob, int reduced_tx_set) {
308
788k
  if (!eob) return;
309
310
771k
  assert(eob <= av1_get_max_eob(tx_size));
311
312
771k
  TxfmParam txfm_param;
313
771k
  init_txfm_param(xd, plane, tx_size, tx_type, eob, reduced_tx_set,
314
771k
                  &txfm_param);
315
771k
  assert(av1_ext_tx_used[txfm_param.tx_set_type][txfm_param.tx_type]);
316
317
771k
  if (txfm_param.is_hbd) {
318
451k
    av1_highbd_inv_txfm_add(dqcoeff, dst, stride, &txfm_param);
319
451k
  } else {
320
320k
    av1_inv_txfm_add(dqcoeff, dst, stride, &txfm_param);
321
320k
  }
322
771k
}