Coverage Report

Created: 2026-09-14 07:15

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