Coverage Report

Created: 2026-04-01 07:24

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