Coverage Report

Created: 2025-12-03 07:28

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