Coverage Report

Created: 2025-06-22 08:04

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