Coverage Report

Created: 2026-11-12 08:20

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