Coverage Report

Created: 2026-02-14 07:09

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