Coverage Report

Created: 2026-03-08 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/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
3.63M
int av1_get_tx_scale(const TX_SIZE tx_size) {
25
3.63M
  const int pels = tx_size_2d[tx_size];
26
  // Largest possible pels is 4096 (64x64).
27
3.63M
  return (pels > 256) + (pels > 1024);
28
3.63M
}
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
616k
                            int eob, int bd) {
36
616k
  if (eob > 1)
37
170k
    av1_highbd_iwht4x4_16_add(input, dest, stride, bd);
38
445k
  else
39
445k
    av1_highbd_iwht4x4_1_add(input, dest, stride, bd);
40
616k
}
41
42
void av1_highbd_inv_txfm_add_4x4_c(const tran_low_t *input, uint8_t *dest,
43
762k
                                   int stride, const TxfmParam *txfm_param) {
44
762k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
45
762k
  int eob = txfm_param->eob;
46
762k
  int bd = txfm_param->bd;
47
762k
  int lossless = txfm_param->lossless;
48
762k
  const int32_t *src = cast_to_int32(input);
49
762k
  const TX_TYPE tx_type = txfm_param->tx_type;
50
762k
  if (lossless) {
51
616k
    assert(tx_type == DCT_DCT);
52
616k
    av1_highbd_iwht4x4_add(input, dest, stride, eob, bd);
53
616k
    return;
54
616k
  }
55
56
146k
  av1_inv_txfm2d_add_4x4_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, bd);
57
146k
}
58
59
void av1_highbd_inv_txfm_add_4x8_c(const tran_low_t *input, uint8_t *dest,
60
72.3k
                                   int stride, const TxfmParam *txfm_param) {
61
72.3k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
62
72.3k
  const int32_t *src = cast_to_int32(input);
63
72.3k
  av1_inv_txfm2d_add_4x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
64
72.3k
                           txfm_param->tx_type, txfm_param->bd);
65
72.3k
}
66
67
void av1_highbd_inv_txfm_add_8x4_c(const tran_low_t *input, uint8_t *dest,
68
111k
                                   int stride, const TxfmParam *txfm_param) {
69
111k
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
70
111k
  const int32_t *src = cast_to_int32(input);
71
111k
  av1_inv_txfm2d_add_8x4_c(src, CONVERT_TO_SHORTPTR(dest), stride,
72
111k
                           txfm_param->tx_type, txfm_param->bd);
73
111k
}
74
75
void av1_highbd_inv_txfm_add_16x32_c(const tran_low_t *input, uint8_t *dest,
76
22.0k
                                     int stride, const TxfmParam *txfm_param) {
77
22.0k
  const int32_t *src = cast_to_int32(input);
78
22.0k
  av1_inv_txfm2d_add_16x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
79
22.0k
                             txfm_param->tx_type, txfm_param->bd);
80
22.0k
}
81
82
void av1_highbd_inv_txfm_add_32x16_c(const tran_low_t *input, uint8_t *dest,
83
25.3k
                                     int stride, const TxfmParam *txfm_param) {
84
25.3k
  const int32_t *src = cast_to_int32(input);
85
25.3k
  av1_inv_txfm2d_add_32x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
86
25.3k
                             txfm_param->tx_type, txfm_param->bd);
87
25.3k
}
88
89
void av1_highbd_inv_txfm_add_16x4_c(const tran_low_t *input, uint8_t *dest,
90
82.0k
                                    int stride, const TxfmParam *txfm_param) {
91
82.0k
  const int32_t *src = cast_to_int32(input);
92
82.0k
  av1_inv_txfm2d_add_16x4_c(src, CONVERT_TO_SHORTPTR(dest), stride,
93
82.0k
                            txfm_param->tx_type, txfm_param->bd);
94
82.0k
}
95
96
void av1_highbd_inv_txfm_add_4x16_c(const tran_low_t *input, uint8_t *dest,
97
45.4k
                                    int stride, const TxfmParam *txfm_param) {
98
45.4k
  const int32_t *src = cast_to_int32(input);
99
45.4k
  av1_inv_txfm2d_add_4x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
100
45.4k
                            txfm_param->tx_type, txfm_param->bd);
101
45.4k
}
102
103
void av1_highbd_inv_txfm_add_32x8_c(const tran_low_t *input, uint8_t *dest,
104
35.0k
                                    int stride, const TxfmParam *txfm_param) {
105
35.0k
  const int32_t *src = cast_to_int32(input);
106
35.0k
  av1_inv_txfm2d_add_32x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
107
35.0k
                            txfm_param->tx_type, txfm_param->bd);
108
35.0k
}
109
110
void av1_highbd_inv_txfm_add_8x32_c(const tran_low_t *input, uint8_t *dest,
111
27.2k
                                    int stride, const TxfmParam *txfm_param) {
112
27.2k
  const int32_t *src = cast_to_int32(input);
113
27.2k
  av1_inv_txfm2d_add_8x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
114
27.2k
                            txfm_param->tx_type, txfm_param->bd);
115
27.2k
}
116
117
void av1_highbd_inv_txfm_add_32x64_c(const tran_low_t *input, uint8_t *dest,
118
4.95k
                                     int stride, const TxfmParam *txfm_param) {
119
4.95k
  const int32_t *src = cast_to_int32(input);
120
4.95k
  av1_inv_txfm2d_add_32x64_c(src, CONVERT_TO_SHORTPTR(dest), stride,
121
4.95k
                             txfm_param->tx_type, txfm_param->bd);
122
4.95k
}
123
124
void av1_highbd_inv_txfm_add_64x32_c(const tran_low_t *input, uint8_t *dest,
125
6.22k
                                     int stride, const TxfmParam *txfm_param) {
126
6.22k
  const int32_t *src = cast_to_int32(input);
127
6.22k
  av1_inv_txfm2d_add_64x32_c(src, CONVERT_TO_SHORTPTR(dest), stride,
128
6.22k
                             txfm_param->tx_type, txfm_param->bd);
129
6.22k
}
130
131
void av1_highbd_inv_txfm_add_16x64_c(const tran_low_t *input, uint8_t *dest,
132
8.13k
                                     int stride, const TxfmParam *txfm_param) {
133
8.13k
  const int32_t *src = cast_to_int32(input);
134
8.13k
  av1_inv_txfm2d_add_16x64_c(src, CONVERT_TO_SHORTPTR(dest), stride,
135
8.13k
                             txfm_param->tx_type, txfm_param->bd);
136
8.13k
}
137
138
void av1_highbd_inv_txfm_add_64x16_c(const tran_low_t *input, uint8_t *dest,
139
7.33k
                                     int stride, const TxfmParam *txfm_param) {
140
7.33k
  const int32_t *src = cast_to_int32(input);
141
7.33k
  av1_inv_txfm2d_add_64x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
142
7.33k
                             txfm_param->tx_type, txfm_param->bd);
143
7.33k
}
144
145
void av1_highbd_inv_txfm_add_8x8_c(const tran_low_t *input, uint8_t *dest,
146
212k
                                   int stride, const TxfmParam *txfm_param) {
147
212k
  int bd = txfm_param->bd;
148
212k
  const TX_TYPE tx_type = txfm_param->tx_type;
149
212k
  const int32_t *src = cast_to_int32(input);
150
151
212k
  av1_inv_txfm2d_add_8x8_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, bd);
152
212k
}
153
154
void av1_highbd_inv_txfm_add_16x16_c(const tran_low_t *input, uint8_t *dest,
155
188k
                                     int stride, const TxfmParam *txfm_param) {
156
188k
  int bd = txfm_param->bd;
157
188k
  const TX_TYPE tx_type = txfm_param->tx_type;
158
188k
  const int32_t *src = cast_to_int32(input);
159
160
188k
  av1_inv_txfm2d_add_16x16_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
161
188k
                             bd);
162
188k
}
163
164
void av1_highbd_inv_txfm_add_8x16_c(const tran_low_t *input, uint8_t *dest,
165
68.1k
                                    int stride, const TxfmParam *txfm_param) {
166
68.1k
  const int32_t *src = cast_to_int32(input);
167
68.1k
  av1_inv_txfm2d_add_8x16_c(src, CONVERT_TO_SHORTPTR(dest), stride,
168
68.1k
                            txfm_param->tx_type, txfm_param->bd);
169
68.1k
}
170
171
void av1_highbd_inv_txfm_add_16x8_c(const tran_low_t *input, uint8_t *dest,
172
105k
                                    int stride, const TxfmParam *txfm_param) {
173
105k
  const int32_t *src = cast_to_int32(input);
174
105k
  av1_inv_txfm2d_add_16x8_c(src, CONVERT_TO_SHORTPTR(dest), stride,
175
105k
                            txfm_param->tx_type, txfm_param->bd);
176
105k
}
177
178
void av1_highbd_inv_txfm_add_32x32_c(const tran_low_t *input, uint8_t *dest,
179
96.5k
                                     int stride, const TxfmParam *txfm_param) {
180
96.5k
  const int bd = txfm_param->bd;
181
96.5k
  const TX_TYPE tx_type = txfm_param->tx_type;
182
96.5k
  const int32_t *src = cast_to_int32(input);
183
184
96.5k
  av1_inv_txfm2d_add_32x32_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
185
96.5k
                             bd);
186
96.5k
}
187
188
void av1_highbd_inv_txfm_add_64x64_c(const tran_low_t *input, uint8_t *dest,
189
76.3k
                                     int stride, const TxfmParam *txfm_param) {
190
76.3k
  const int bd = txfm_param->bd;
191
76.3k
  const TX_TYPE tx_type = txfm_param->tx_type;
192
76.3k
  const int32_t *src = cast_to_int32(input);
193
76.3k
  assert(tx_type == DCT_DCT);
194
76.3k
  av1_inv_txfm2d_add_64x64_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type,
195
76.3k
                             bd);
196
76.3k
}
197
198
static void init_txfm_param(const MACROBLOCKD *xd, int plane, TX_SIZE tx_size,
199
                            TX_TYPE tx_type, int eob, int reduced_tx_set,
200
1.95M
                            TxfmParam *txfm_param) {
201
1.95M
  (void)plane;
202
1.95M
  txfm_param->tx_type = tx_type;
203
1.95M
  txfm_param->tx_size = tx_size;
204
1.95M
  txfm_param->eob = eob;
205
1.95M
  txfm_param->lossless = xd->lossless[xd->mi[0]->segment_id];
206
1.95M
  txfm_param->bd = xd->bd;
207
1.95M
  txfm_param->is_hbd = is_cur_buf_hbd(xd);
208
1.95M
  txfm_param->tx_set_type = av1_get_ext_tx_set_type(
209
1.95M
      txfm_param->tx_size, is_inter_block(xd->mi[0]), reduced_tx_set);
210
1.95M
}
211
212
void av1_highbd_inv_txfm_add_c(const tran_low_t *input, uint8_t *dest,
213
1.95M
                               int stride, const TxfmParam *txfm_param) {
214
1.95M
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
215
1.95M
  const TX_SIZE tx_size = txfm_param->tx_size;
216
1.95M
  switch (tx_size) {
217
96.5k
    case TX_32X32:
218
96.5k
      av1_highbd_inv_txfm_add_32x32_c(input, dest, stride, txfm_param);
219
96.5k
      break;
220
188k
    case TX_16X16:
221
188k
      av1_highbd_inv_txfm_add_16x16_c(input, dest, stride, txfm_param);
222
188k
      break;
223
212k
    case TX_8X8:
224
212k
      av1_highbd_inv_txfm_add_8x8_c(input, dest, stride, txfm_param);
225
212k
      break;
226
72.3k
    case TX_4X8:
227
72.3k
      av1_highbd_inv_txfm_add_4x8_c(input, dest, stride, txfm_param);
228
72.3k
      break;
229
111k
    case TX_8X4:
230
111k
      av1_highbd_inv_txfm_add_8x4_c(input, dest, stride, txfm_param);
231
111k
      break;
232
68.1k
    case TX_8X16:
233
68.1k
      av1_highbd_inv_txfm_add_8x16_c(input, dest, stride, txfm_param);
234
68.1k
      break;
235
105k
    case TX_16X8:
236
105k
      av1_highbd_inv_txfm_add_16x8_c(input, dest, stride, txfm_param);
237
105k
      break;
238
22.0k
    case TX_16X32:
239
22.0k
      av1_highbd_inv_txfm_add_16x32_c(input, dest, stride, txfm_param);
240
22.0k
      break;
241
25.3k
    case TX_32X16:
242
25.3k
      av1_highbd_inv_txfm_add_32x16_c(input, dest, stride, txfm_param);
243
25.3k
      break;
244
76.3k
    case TX_64X64:
245
76.3k
      av1_highbd_inv_txfm_add_64x64_c(input, dest, stride, txfm_param);
246
76.3k
      break;
247
4.95k
    case TX_32X64:
248
4.95k
      av1_highbd_inv_txfm_add_32x64_c(input, dest, stride, txfm_param);
249
4.95k
      break;
250
6.22k
    case TX_64X32:
251
6.22k
      av1_highbd_inv_txfm_add_64x32_c(input, dest, stride, txfm_param);
252
6.22k
      break;
253
8.13k
    case TX_16X64:
254
8.13k
      av1_highbd_inv_txfm_add_16x64_c(input, dest, stride, txfm_param);
255
8.13k
      break;
256
7.33k
    case TX_64X16:
257
7.33k
      av1_highbd_inv_txfm_add_64x16_c(input, dest, stride, txfm_param);
258
7.33k
      break;
259
762k
    case TX_4X4:
260
      // this is like av1_short_idct4x4 but has a special case around eob<=1
261
      // which is significant (not just an optimization) for the lossless
262
      // case.
263
762k
      av1_highbd_inv_txfm_add_4x4_c(input, dest, stride, txfm_param);
264
762k
      break;
265
82.0k
    case TX_16X4:
266
82.0k
      av1_highbd_inv_txfm_add_16x4_c(input, dest, stride, txfm_param);
267
82.0k
      break;
268
45.4k
    case TX_4X16:
269
45.4k
      av1_highbd_inv_txfm_add_4x16_c(input, dest, stride, txfm_param);
270
45.4k
      break;
271
27.2k
    case TX_8X32:
272
27.2k
      av1_highbd_inv_txfm_add_8x32_c(input, dest, stride, txfm_param);
273
27.2k
      break;
274
35.0k
    case TX_32X8:
275
35.0k
      av1_highbd_inv_txfm_add_32x8_c(input, dest, stride, txfm_param);
276
35.0k
      break;
277
0
    default: assert(0 && "Invalid transform size"); break;
278
1.95M
  }
279
1.95M
}
280
281
void av1_inv_txfm_add_c(const tran_low_t *dqcoeff, uint8_t *dst, int stride,
282
1.25M
                        const TxfmParam *txfm_param) {
283
1.25M
  const TX_SIZE tx_size = txfm_param->tx_size;
284
1.25M
  DECLARE_ALIGNED(32, uint16_t, tmp[MAX_TX_SQUARE]);
285
1.25M
  int tmp_stride = MAX_TX_SIZE;
286
1.25M
  int w = tx_size_wide[tx_size];
287
1.25M
  int h = tx_size_high[tx_size];
288
13.3M
  for (int r = 0; r < h; ++r) {
289
262M
    for (int c = 0; c < w; ++c) {
290
250M
      tmp[r * tmp_stride + c] = dst[r * stride + c];
291
250M
    }
292
12.0M
  }
293
294
1.25M
  av1_highbd_inv_txfm_add(dqcoeff, CONVERT_TO_BYTEPTR(tmp), tmp_stride,
295
1.25M
                          txfm_param);
296
297
13.3M
  for (int r = 0; r < h; ++r) {
298
262M
    for (int c = 0; c < w; ++c) {
299
250M
      dst[r * stride + c] = (uint8_t)tmp[r * tmp_stride + c];
300
250M
    }
301
12.0M
  }
302
1.25M
}
303
304
void av1_inverse_transform_block(const MACROBLOCKD *xd,
305
                                 const tran_low_t *dqcoeff, int plane,
306
                                 TX_TYPE tx_type, TX_SIZE tx_size, uint8_t *dst,
307
1.95M
                                 int stride, int eob, int reduced_tx_set) {
308
1.95M
  if (!eob) return;
309
310
1.95M
  assert(eob <= av1_get_max_eob(tx_size));
311
312
1.95M
  TxfmParam txfm_param;
313
1.95M
  init_txfm_param(xd, plane, tx_size, tx_type, eob, reduced_tx_set,
314
1.95M
                  &txfm_param);
315
1.95M
  assert(av1_ext_tx_used[txfm_param.tx_set_type][txfm_param.tx_type]);
316
317
1.95M
  if (txfm_param.is_hbd) {
318
702k
    av1_highbd_inv_txfm_add(dqcoeff, dst, stride, &txfm_param);
319
1.25M
  } else {
320
1.25M
    av1_inv_txfm_add(dqcoeff, dst, stride, &txfm_param);
321
1.25M
  }
322
1.95M
}