Coverage Report

Created: 2026-10-27 06:57

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
22.3M
int av1_get_tx_scale(const TX_SIZE tx_size) {
25
22.3M
  const int pels = tx_size_2d[tx_size];
26
  // Largest possible pels is 4096 (64x64).
27
22.3M
  return (pels > 256) + (pels > 1024);
28
22.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
2.78M
                            int eob, int bd) {
36
2.78M
  if (eob > 1)
37
1.95M
    av1_highbd_iwht4x4_16_add(input, dest, stride, bd);
38
835k
  else
39
835k
    av1_highbd_iwht4x4_1_add(input, dest, stride, bd);
40
2.78M
}
41
42
static void highbd_inv_txfm_add_4x4_c(const tran_low_t *input, uint8_t *dest,
43
2.89M
                                      int stride, const TxfmParam *txfm_param) {
44
2.89M
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
45
2.89M
  int eob = txfm_param->eob;
46
2.89M
  int bd = txfm_param->bd;
47
2.89M
  int lossless = txfm_param->lossless;
48
2.89M
  const int32_t *src = cast_to_int32(input);
49
2.89M
  const TX_TYPE tx_type = txfm_param->tx_type;
50
2.89M
  if (lossless) {
51
2.78M
    assert(tx_type == DCT_DCT);
52
2.78M
    av1_highbd_iwht4x4_add(input, dest, stride, eob, bd);
53
2.78M
    return;
54
2.78M
  }
55
56
110k
  av1_inv_txfm2d_add_4x4_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, bd);
57
110k
}
58
59
static void highbd_inv_txfm_add_4x8_c(const tran_low_t *input, uint8_t *dest,
60
52.0k
                                      int stride, const TxfmParam *txfm_param) {
61
52.0k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
62
52.0k
  const int32_t *src = cast_to_int32(input);
63
52.0k
  av1_inv_txfm2d_add_4x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
64
52.0k
                           txfm_param->tx_type, txfm_param->bd);
65
52.0k
}
66
67
static void highbd_inv_txfm_add_8x4_c(const tran_low_t *input, uint8_t *dest,
68
71.7k
                                      int stride, const TxfmParam *txfm_param) {
69
71.7k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
70
71.7k
  const int32_t *src = cast_to_int32(input);
71
71.7k
  av1_inv_txfm2d_add_8x4_c(src, CONVERT_TO_SHORTPTR(dest), stride,
72
71.7k
                           txfm_param->tx_type, txfm_param->bd);
73
71.7k
}
74
75
static void highbd_inv_txfm_add_16x32_c(const tran_low_t *input, uint8_t *dest,
76
                                        int stride,
77
26.3k
                                        const TxfmParam *txfm_param) {
78
26.3k
  const int32_t *src = cast_to_int32(input);
79
26.3k
  av1_inv_txfm2d_add_16x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
80
26.3k
                             txfm_param->tx_type, txfm_param->bd);
81
26.3k
}
82
83
static void highbd_inv_txfm_add_32x16_c(const tran_low_t *input, uint8_t *dest,
84
                                        int stride,
85
25.5k
                                        const TxfmParam *txfm_param) {
86
25.5k
  const int32_t *src = cast_to_int32(input);
87
25.5k
  av1_inv_txfm2d_add_32x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
88
25.5k
                             txfm_param->tx_type, txfm_param->bd);
89
25.5k
}
90
91
static void highbd_inv_txfm_add_16x4_c(const tran_low_t *input, uint8_t *dest,
92
                                       int stride,
93
60.6k
                                       const TxfmParam *txfm_param) {
94
60.6k
  const int32_t *src = cast_to_int32(input);
95
60.6k
  av1_inv_txfm2d_add_16x4_c(src, CONVERT_TO_SHORTPTR(dest), stride,
96
60.6k
                            txfm_param->tx_type, txfm_param->bd);
97
60.6k
}
98
99
static void highbd_inv_txfm_add_4x16_c(const tran_low_t *input, uint8_t *dest,
100
                                       int stride,
101
33.3k
                                       const TxfmParam *txfm_param) {
102
33.3k
  const int32_t *src = cast_to_int32(input);
103
33.3k
  av1_inv_txfm2d_add_4x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
104
33.3k
                            txfm_param->tx_type, txfm_param->bd);
105
33.3k
}
106
107
static void highbd_inv_txfm_add_32x8_c(const tran_low_t *input, uint8_t *dest,
108
                                       int stride,
109
27.4k
                                       const TxfmParam *txfm_param) {
110
27.4k
  const int32_t *src = cast_to_int32(input);
111
27.4k
  av1_inv_txfm2d_add_32x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
112
27.4k
                            txfm_param->tx_type, txfm_param->bd);
113
27.4k
}
114
115
static void highbd_inv_txfm_add_8x32_c(const tran_low_t *input, uint8_t *dest,
116
                                       int stride,
117
19.8k
                                       const TxfmParam *txfm_param) {
118
19.8k
  const int32_t *src = cast_to_int32(input);
119
19.8k
  av1_inv_txfm2d_add_8x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
120
19.8k
                            txfm_param->tx_type, txfm_param->bd);
121
19.8k
}
122
123
static void highbd_inv_txfm_add_32x64_c(const tran_low_t *input, uint8_t *dest,
124
                                        int stride,
125
6.51k
                                        const TxfmParam *txfm_param) {
126
6.51k
  const int32_t *src = cast_to_int32(input);
127
6.51k
  av1_inv_txfm2d_add_32x64_c(src, CONVERT_TO_SHORTPTR(dest), stride,
128
6.51k
                             txfm_param->tx_type, txfm_param->bd);
129
6.51k
}
130
131
static void highbd_inv_txfm_add_64x32_c(const tran_low_t *input, uint8_t *dest,
132
                                        int stride,
133
4.84k
                                        const TxfmParam *txfm_param) {
134
4.84k
  const int32_t *src = cast_to_int32(input);
135
4.84k
  av1_inv_txfm2d_add_64x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
136
4.84k
                             txfm_param->tx_type, txfm_param->bd);
137
4.84k
}
138
139
static void highbd_inv_txfm_add_16x64_c(const tran_low_t *input, uint8_t *dest,
140
                                        int stride,
141
4.99k
                                        const TxfmParam *txfm_param) {
142
4.99k
  const int32_t *src = cast_to_int32(input);
143
4.99k
  av1_inv_txfm2d_add_16x64_c(src, CONVERT_TO_SHORTPTR(dest), stride,
144
4.99k
                             txfm_param->tx_type, txfm_param->bd);
145
4.99k
}
146
147
static void highbd_inv_txfm_add_64x16_c(const tran_low_t *input, uint8_t *dest,
148
                                        int stride,
149
3.67k
                                        const TxfmParam *txfm_param) {
150
3.67k
  const int32_t *src = cast_to_int32(input);
151
3.67k
  av1_inv_txfm2d_add_64x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
152
3.67k
                             txfm_param->tx_type, txfm_param->bd);
153
3.67k
}
154
155
static void highbd_inv_txfm_add_8x8_c(const tran_low_t *input, uint8_t *dest,
156
224k
                                      int stride, const TxfmParam *txfm_param) {
157
224k
  int bd = txfm_param->bd;
158
224k
  const TX_TYPE tx_type = txfm_param->tx_type;
159
224k
  const int32_t *src = cast_to_int32(input);
160
161
224k
  av1_inv_txfm2d_add_8x8_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, bd);
162
224k
}
163
164
static void highbd_inv_txfm_add_16x16_c(const tran_low_t *input, uint8_t *dest,
165
                                        int stride,
166
106k
                                        const TxfmParam *txfm_param) {
167
106k
  int bd = txfm_param->bd;
168
106k
  const TX_TYPE tx_type = txfm_param->tx_type;
169
106k
  const int32_t *src = cast_to_int32(input);
170
171
106k
  av1_inv_txfm2d_add_16x16_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
172
106k
                             bd);
173
106k
}
174
175
static void highbd_inv_txfm_add_8x16_c(const tran_low_t *input, uint8_t *dest,
176
                                       int stride,
177
48.7k
                                       const TxfmParam *txfm_param) {
178
48.7k
  const int32_t *src = cast_to_int32(input);
179
48.7k
  av1_inv_txfm2d_add_8x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
180
48.7k
                            txfm_param->tx_type, txfm_param->bd);
181
48.7k
}
182
183
static void highbd_inv_txfm_add_16x8_c(const tran_low_t *input, uint8_t *dest,
184
                                       int stride,
185
78.1k
                                       const TxfmParam *txfm_param) {
186
78.1k
  const int32_t *src = cast_to_int32(input);
187
78.1k
  av1_inv_txfm2d_add_16x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
188
78.1k
                            txfm_param->tx_type, txfm_param->bd);
189
78.1k
}
190
191
static void highbd_inv_txfm_add_32x32_c(const tran_low_t *input, uint8_t *dest,
192
                                        int stride,
193
63.5k
                                        const TxfmParam *txfm_param) {
194
63.5k
  const int bd = txfm_param->bd;
195
63.5k
  const TX_TYPE tx_type = txfm_param->tx_type;
196
63.5k
  const int32_t *src = cast_to_int32(input);
197
198
63.5k
  av1_inv_txfm2d_add_32x32_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
199
63.5k
                             bd);
200
63.5k
}
201
202
static void highbd_inv_txfm_add_64x64_c(const tran_low_t *input, uint8_t *dest,
203
                                        int stride,
204
24.3k
                                        const TxfmParam *txfm_param) {
205
24.3k
  const int bd = txfm_param->bd;
206
24.3k
  const TX_TYPE tx_type = txfm_param->tx_type;
207
24.3k
  const int32_t *src = cast_to_int32(input);
208
24.3k
  assert(tx_type == DCT_DCT);
209
24.3k
  av1_inv_txfm2d_add_64x64_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
210
24.3k
                             bd);
211
24.3k
}
212
213
static void init_txfm_param(const MACROBLOCKD *xd, int plane, TX_SIZE tx_size,
214
                            TX_TYPE tx_type, int eob, int reduced_tx_set,
215
3.77M
                            TxfmParam *txfm_param) {
216
3.77M
  (void)plane;
217
3.77M
  txfm_param->tx_type = tx_type;
218
3.77M
  txfm_param->tx_size = tx_size;
219
3.77M
  txfm_param->eob = eob;
220
3.77M
  txfm_param->lossless = xd->lossless[xd->mi[0]->segment_id];
221
3.77M
  txfm_param->bd = xd->bd;
222
3.77M
  txfm_param->is_hbd = is_cur_buf_hbd(xd);
223
3.77M
  txfm_param->tx_set_type = av1_get_ext_tx_set_type(
224
3.77M
      txfm_param->tx_size, is_inter_block(xd->mi[0]), reduced_tx_set);
225
3.77M
}
226
227
void av1_highbd_inv_txfm_add_c(const tran_low_t *input, uint8_t *dest,
228
3.77M
                               int stride, const TxfmParam *txfm_param) {
229
3.77M
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
230
3.77M
  const TX_SIZE tx_size = txfm_param->tx_size;
231
3.77M
  switch (tx_size) {
232
63.5k
    case TX_32X32:
233
63.5k
      highbd_inv_txfm_add_32x32_c(input, dest, stride, txfm_param);
234
63.5k
      break;
235
106k
    case TX_16X16:
236
106k
      highbd_inv_txfm_add_16x16_c(input, dest, stride, txfm_param);
237
106k
      break;
238
224k
    case TX_8X8:
239
224k
      highbd_inv_txfm_add_8x8_c(input, dest, stride, txfm_param);
240
224k
      break;
241
52.0k
    case TX_4X8:
242
52.0k
      highbd_inv_txfm_add_4x8_c(input, dest, stride, txfm_param);
243
52.0k
      break;
244
71.7k
    case TX_8X4:
245
71.7k
      highbd_inv_txfm_add_8x4_c(input, dest, stride, txfm_param);
246
71.7k
      break;
247
48.7k
    case TX_8X16:
248
48.7k
      highbd_inv_txfm_add_8x16_c(input, dest, stride, txfm_param);
249
48.7k
      break;
250
78.1k
    case TX_16X8:
251
78.1k
      highbd_inv_txfm_add_16x8_c(input, dest, stride, txfm_param);
252
78.1k
      break;
253
26.3k
    case TX_16X32:
254
26.3k
      highbd_inv_txfm_add_16x32_c(input, dest, stride, txfm_param);
255
26.3k
      break;
256
25.5k
    case TX_32X16:
257
25.5k
      highbd_inv_txfm_add_32x16_c(input, dest, stride, txfm_param);
258
25.5k
      break;
259
24.3k
    case TX_64X64:
260
24.3k
      highbd_inv_txfm_add_64x64_c(input, dest, stride, txfm_param);
261
24.3k
      break;
262
6.51k
    case TX_32X64:
263
6.51k
      highbd_inv_txfm_add_32x64_c(input, dest, stride, txfm_param);
264
6.51k
      break;
265
4.84k
    case TX_64X32:
266
4.84k
      highbd_inv_txfm_add_64x32_c(input, dest, stride, txfm_param);
267
4.84k
      break;
268
4.99k
    case TX_16X64:
269
4.99k
      highbd_inv_txfm_add_16x64_c(input, dest, stride, txfm_param);
270
4.99k
      break;
271
3.67k
    case TX_64X16:
272
3.67k
      highbd_inv_txfm_add_64x16_c(input, dest, stride, txfm_param);
273
3.67k
      break;
274
2.89M
    case TX_4X4:
275
      // this is like av1_short_idct4x4 but has a special case around eob<=1
276
      // which is significant (not just an optimization) for the lossless
277
      // case.
278
2.89M
      highbd_inv_txfm_add_4x4_c(input, dest, stride, txfm_param);
279
2.89M
      break;
280
60.6k
    case TX_16X4:
281
60.6k
      highbd_inv_txfm_add_16x4_c(input, dest, stride, txfm_param);
282
60.6k
      break;
283
33.3k
    case TX_4X16:
284
33.3k
      highbd_inv_txfm_add_4x16_c(input, dest, stride, txfm_param);
285
33.3k
      break;
286
19.8k
    case TX_8X32:
287
19.8k
      highbd_inv_txfm_add_8x32_c(input, dest, stride, txfm_param);
288
19.8k
      break;
289
27.4k
    case TX_32X8:
290
27.4k
      highbd_inv_txfm_add_32x8_c(input, dest, stride, txfm_param);
291
27.4k
      break;
292
0
    default: assert(0 && "Invalid transform size"); break;
293
3.77M
  }
294
3.77M
}
295
296
void av1_inv_txfm_add_c(const tran_low_t *dqcoeff, uint8_t *dst, int stride,
297
2.67M
                        const TxfmParam *txfm_param) {
298
2.67M
  const TX_SIZE tx_size = txfm_param->tx_size;
299
2.67M
  DECLARE_ALIGNED(32, uint16_t, tmp[MAX_TX_SQUARE]);
300
2.67M
  int tmp_stride = MAX_TX_SIZE;
301
2.67M
  int w = tx_size_wide[tx_size];
302
2.67M
  int h = tx_size_high[tx_size];
303
17.6M
  for (int r = 0; r < h; ++r) {
304
188M
    for (int c = 0; c < w; ++c) {
305
173M
      tmp[r * tmp_stride + c] = dst[r * stride + c];
306
173M
    }
307
15.0M
  }
308
309
2.67M
  av1_highbd_inv_txfm_add(dqcoeff, CONVERT_TO_BYTEPTR(tmp), tmp_stride,
310
2.67M
                          txfm_param);
311
312
17.6M
  for (int r = 0; r < h; ++r) {
313
188M
    for (int c = 0; c < w; ++c) {
314
173M
      dst[r * stride + c] = (uint8_t)tmp[r * tmp_stride + c];
315
173M
    }
316
15.0M
  }
317
2.67M
}
318
319
void av1_inverse_transform_block(const MACROBLOCKD *xd,
320
                                 const tran_low_t *dqcoeff, int plane,
321
                                 TX_TYPE tx_type, TX_SIZE tx_size, uint8_t *dst,
322
3.86M
                                 int stride, int eob, int reduced_tx_set) {
323
3.86M
  if (!eob) return;
324
325
3.86M
  assert(eob <= av1_get_max_eob(tx_size));
326
327
3.77M
  TxfmParam txfm_param;
328
3.77M
  init_txfm_param(xd, plane, tx_size, tx_type, eob, reduced_tx_set,
329
3.77M
                  &txfm_param);
330
3.77M
  assert(av1_ext_tx_used[txfm_param.tx_set_type][txfm_param.tx_type]);
331
332
3.77M
  if (txfm_param.is_hbd) {
333
1.10M
    av1_highbd_inv_txfm_add(dqcoeff, dst, stride, &txfm_param);
334
2.67M
  } else {
335
2.67M
    av1_inv_txfm_add(dqcoeff, dst, stride, &txfm_param);
336
2.67M
  }
337
3.77M
}