Coverage Report

Created: 2024-06-18 06:48

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