Coverage Report

Created: 2025-08-11 08:01

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