Coverage Report

Created: 2026-04-01 07:49

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