Coverage Report

Created: 2026-02-26 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/aom/av1/encoder/hybrid_fwd_txfm.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 "config/aom_config.h"
13
#include "config/av1_rtcd.h"
14
#include "config/aom_dsp_rtcd.h"
15
16
#include "av1/common/idct.h"
17
#include "av1/common/blockd.h"
18
#include "av1/encoder/hybrid_fwd_txfm.h"
19
20
/* 4-point reversible, orthonormal Walsh-Hadamard in 3.5 adds, 0.5 shifts per
21
   pixel. */
22
12.1M
void av1_fwht4x4_c(const int16_t *input, tran_low_t *output, int stride) {
23
12.1M
  int i;
24
12.1M
  tran_high_t a1, b1, c1, d1, e1;
25
12.1M
  const int16_t *ip_pass0 = input;
26
12.1M
  const tran_low_t *ip = NULL;
27
12.1M
  tran_low_t *op = output;
28
29
60.5M
  for (i = 0; i < 4; i++) {
30
48.4M
    a1 = ip_pass0[0 * stride];
31
48.4M
    b1 = ip_pass0[1 * stride];
32
48.4M
    c1 = ip_pass0[2 * stride];
33
48.4M
    d1 = ip_pass0[3 * stride];
34
35
48.4M
    a1 += b1;
36
48.4M
    d1 = d1 - c1;
37
48.4M
    e1 = (a1 - d1) >> 1;
38
48.4M
    b1 = e1 - b1;
39
48.4M
    c1 = e1 - c1;
40
48.4M
    a1 -= c1;
41
48.4M
    d1 += b1;
42
48.4M
    op[0] = (tran_low_t)a1;
43
48.4M
    op[4] = (tran_low_t)c1;
44
48.4M
    op[8] = (tran_low_t)d1;
45
48.4M
    op[12] = (tran_low_t)b1;
46
47
48.4M
    ip_pass0++;
48
48.4M
    op++;
49
48.4M
  }
50
12.1M
  ip = output;
51
12.1M
  op = output;
52
53
60.7M
  for (i = 0; i < 4; i++) {
54
48.6M
    a1 = ip[0];
55
48.6M
    b1 = ip[1];
56
48.6M
    c1 = ip[2];
57
48.6M
    d1 = ip[3];
58
59
48.6M
    a1 += b1;
60
48.6M
    d1 -= c1;
61
48.6M
    e1 = (a1 - d1) >> 1;
62
48.6M
    b1 = e1 - b1;
63
48.6M
    c1 = e1 - c1;
64
48.6M
    a1 -= c1;
65
48.6M
    d1 += b1;
66
48.6M
    op[0] = (tran_low_t)(a1 * UNIT_QUANT_FACTOR);
67
48.6M
    op[1] = (tran_low_t)(c1 * UNIT_QUANT_FACTOR);
68
48.6M
    op[2] = (tran_low_t)(d1 * UNIT_QUANT_FACTOR);
69
48.6M
    op[3] = (tran_low_t)(b1 * UNIT_QUANT_FACTOR);
70
71
48.6M
    ip += 4;
72
48.6M
    op += 4;
73
48.6M
  }
74
12.1M
}
75
76
void av1_highbd_fwht4x4_c(const int16_t *input, tran_low_t *output,
77
12.1M
                          int stride) {
78
12.1M
  av1_fwht4x4_c(input, output, stride);
79
12.1M
}
80
81
static void highbd_fwd_txfm_4x4(const int16_t *src_diff, tran_low_t *coeff,
82
12.2M
                                int diff_stride, TxfmParam *txfm_param) {
83
12.2M
  int32_t *dst_coeff = (int32_t *)coeff;
84
12.2M
  const TX_TYPE tx_type = txfm_param->tx_type;
85
12.2M
  const int bd = txfm_param->bd;
86
12.2M
  if (txfm_param->lossless) {
87
12.1M
    assert(tx_type == DCT_DCT);
88
12.1M
    av1_highbd_fwht4x4(src_diff, coeff, diff_stride);
89
12.1M
    return;
90
12.1M
  }
91
135k
  av1_fwd_txfm2d_4x4(src_diff, dst_coeff, diff_stride, tx_type, bd);
92
135k
}
93
94
static void highbd_fwd_txfm_4x8(const int16_t *src_diff, tran_low_t *coeff,
95
23.1k
                                int diff_stride, TxfmParam *txfm_param) {
96
23.1k
  int32_t *dst_coeff = (int32_t *)coeff;
97
23.1k
  av1_fwd_txfm2d_4x8(src_diff, dst_coeff, diff_stride, txfm_param->tx_type,
98
23.1k
                     txfm_param->bd);
99
23.1k
}
100
101
static void highbd_fwd_txfm_8x4(const int16_t *src_diff, tran_low_t *coeff,
102
28.1k
                                int diff_stride, TxfmParam *txfm_param) {
103
28.1k
  int32_t *dst_coeff = (int32_t *)coeff;
104
28.1k
  av1_fwd_txfm2d_8x4(src_diff, dst_coeff, diff_stride, txfm_param->tx_type,
105
28.1k
                     txfm_param->bd);
106
28.1k
}
107
108
static void highbd_fwd_txfm_8x16(const int16_t *src_diff, tran_low_t *coeff,
109
68.2k
                                 int diff_stride, TxfmParam *txfm_param) {
110
68.2k
  int32_t *dst_coeff = (int32_t *)coeff;
111
68.2k
  const TX_TYPE tx_type = txfm_param->tx_type;
112
68.2k
  const int bd = txfm_param->bd;
113
68.2k
  av1_fwd_txfm2d_8x16(src_diff, dst_coeff, diff_stride, tx_type, bd);
114
68.2k
}
115
116
static void highbd_fwd_txfm_16x8(const int16_t *src_diff, tran_low_t *coeff,
117
79.5k
                                 int diff_stride, TxfmParam *txfm_param) {
118
79.5k
  int32_t *dst_coeff = (int32_t *)coeff;
119
79.5k
  const TX_TYPE tx_type = txfm_param->tx_type;
120
79.5k
  const int bd = txfm_param->bd;
121
79.5k
  av1_fwd_txfm2d_16x8(src_diff, dst_coeff, diff_stride, tx_type, bd);
122
79.5k
}
123
124
static void highbd_fwd_txfm_16x32(const int16_t *src_diff, tran_low_t *coeff,
125
31.8k
                                  int diff_stride, TxfmParam *txfm_param) {
126
31.8k
  int32_t *dst_coeff = (int32_t *)coeff;
127
31.8k
  av1_fwd_txfm2d_16x32(src_diff, dst_coeff, diff_stride, txfm_param->tx_type,
128
31.8k
                       txfm_param->bd);
129
31.8k
}
130
131
static void highbd_fwd_txfm_32x16(const int16_t *src_diff, tran_low_t *coeff,
132
34.2k
                                  int diff_stride, TxfmParam *txfm_param) {
133
34.2k
  int32_t *dst_coeff = (int32_t *)coeff;
134
34.2k
  av1_fwd_txfm2d_32x16(src_diff, dst_coeff, diff_stride, txfm_param->tx_type,
135
34.2k
                       txfm_param->bd);
136
34.2k
}
137
138
#if !CONFIG_REALTIME_ONLY
139
static void highbd_fwd_txfm_16x4(const int16_t *src_diff, tran_low_t *coeff,
140
0
                                 int diff_stride, TxfmParam *txfm_param) {
141
0
  int32_t *dst_coeff = (int32_t *)coeff;
142
0
  av1_fwd_txfm2d_16x4(src_diff, dst_coeff, diff_stride, txfm_param->tx_type,
143
0
                      txfm_param->bd);
144
0
}
145
146
static void highbd_fwd_txfm_4x16(const int16_t *src_diff, tran_low_t *coeff,
147
0
                                 int diff_stride, TxfmParam *txfm_param) {
148
0
  int32_t *dst_coeff = (int32_t *)coeff;
149
0
  av1_fwd_txfm2d_4x16(src_diff, dst_coeff, diff_stride, txfm_param->tx_type,
150
0
                      txfm_param->bd);
151
0
}
152
153
static void highbd_fwd_txfm_32x8(const int16_t *src_diff, tran_low_t *coeff,
154
0
                                 int diff_stride, TxfmParam *txfm_param) {
155
0
  int32_t *dst_coeff = (int32_t *)coeff;
156
0
  av1_fwd_txfm2d_32x8(src_diff, dst_coeff, diff_stride, txfm_param->tx_type,
157
0
                      txfm_param->bd);
158
0
}
159
160
static void highbd_fwd_txfm_8x32(const int16_t *src_diff, tran_low_t *coeff,
161
0
                                 int diff_stride, TxfmParam *txfm_param) {
162
0
  int32_t *dst_coeff = (int32_t *)coeff;
163
0
  av1_fwd_txfm2d_8x32(src_diff, dst_coeff, diff_stride, txfm_param->tx_type,
164
0
                      txfm_param->bd);
165
0
}
166
#endif
167
168
static void highbd_fwd_txfm_8x8(const int16_t *src_diff, tran_low_t *coeff,
169
281k
                                int diff_stride, TxfmParam *txfm_param) {
170
281k
  int32_t *dst_coeff = (int32_t *)coeff;
171
281k
  const TX_TYPE tx_type = txfm_param->tx_type;
172
281k
  const int bd = txfm_param->bd;
173
281k
  av1_fwd_txfm2d_8x8(src_diff, dst_coeff, diff_stride, tx_type, bd);
174
281k
}
175
176
static void highbd_fwd_txfm_16x16(const int16_t *src_diff, tran_low_t *coeff,
177
320k
                                  int diff_stride, TxfmParam *txfm_param) {
178
320k
  int32_t *dst_coeff = (int32_t *)coeff;
179
320k
  const TX_TYPE tx_type = txfm_param->tx_type;
180
320k
  const int bd = txfm_param->bd;
181
320k
  av1_fwd_txfm2d_16x16(src_diff, dst_coeff, diff_stride, tx_type, bd);
182
320k
}
183
184
static void highbd_fwd_txfm_32x32(const int16_t *src_diff, tran_low_t *coeff,
185
220k
                                  int diff_stride, TxfmParam *txfm_param) {
186
220k
  int32_t *dst_coeff = (int32_t *)coeff;
187
220k
  const TX_TYPE tx_type = txfm_param->tx_type;
188
220k
  const int bd = txfm_param->bd;
189
220k
  av1_fwd_txfm2d_32x32(src_diff, dst_coeff, diff_stride, tx_type, bd);
190
220k
}
191
192
static void highbd_fwd_txfm_32x64(const int16_t *src_diff, tran_low_t *coeff,
193
0
                                  int diff_stride, TxfmParam *txfm_param) {
194
0
  assert(txfm_param->tx_type == DCT_DCT);
195
0
  int32_t *dst_coeff = (int32_t *)coeff;
196
0
  const int bd = txfm_param->bd;
197
0
  av1_fwd_txfm2d_32x64(src_diff, dst_coeff, diff_stride, txfm_param->tx_type,
198
0
                       bd);
199
0
}
200
201
static void highbd_fwd_txfm_64x32(const int16_t *src_diff, tran_low_t *coeff,
202
0
                                  int diff_stride, TxfmParam *txfm_param) {
203
0
  assert(txfm_param->tx_type == DCT_DCT);
204
0
  int32_t *dst_coeff = (int32_t *)coeff;
205
0
  const int bd = txfm_param->bd;
206
0
  av1_fwd_txfm2d_64x32(src_diff, dst_coeff, diff_stride, txfm_param->tx_type,
207
0
                       bd);
208
0
}
209
210
#if !CONFIG_REALTIME_ONLY
211
static void highbd_fwd_txfm_16x64(const int16_t *src_diff, tran_low_t *coeff,
212
0
                                  int diff_stride, TxfmParam *txfm_param) {
213
0
  assert(txfm_param->tx_type == DCT_DCT);
214
0
  int32_t *dst_coeff = (int32_t *)coeff;
215
0
  const int bd = txfm_param->bd;
216
0
  av1_fwd_txfm2d_16x64(src_diff, dst_coeff, diff_stride, DCT_DCT, bd);
217
0
}
218
219
static void highbd_fwd_txfm_64x16(const int16_t *src_diff, tran_low_t *coeff,
220
0
                                  int diff_stride, TxfmParam *txfm_param) {
221
0
  assert(txfm_param->tx_type == DCT_DCT);
222
0
  int32_t *dst_coeff = (int32_t *)coeff;
223
0
  const int bd = txfm_param->bd;
224
0
  av1_fwd_txfm2d_64x16(src_diff, dst_coeff, diff_stride, DCT_DCT, bd);
225
0
}
226
#endif
227
228
static void highbd_fwd_txfm_64x64(const int16_t *src_diff, tran_low_t *coeff,
229
0
                                  int diff_stride, TxfmParam *txfm_param) {
230
0
  assert(txfm_param->tx_type == DCT_DCT);
231
0
  int32_t *dst_coeff = (int32_t *)coeff;
232
0
  const int bd = txfm_param->bd;
233
0
  av1_fwd_txfm2d_64x64(src_diff, dst_coeff, diff_stride, DCT_DCT, bd);
234
0
}
235
236
void av1_fwd_txfm(const int16_t *src_diff, tran_low_t *coeff, int diff_stride,
237
13.3M
                  TxfmParam *txfm_param) {
238
13.3M
  if (txfm_param->bd == 8)
239
13.3M
    av1_lowbd_fwd_txfm(src_diff, coeff, diff_stride, txfm_param);
240
18.4E
  else
241
18.4E
    av1_highbd_fwd_txfm(src_diff, coeff, diff_stride, txfm_param);
242
13.3M
}
243
244
void av1_lowbd_fwd_txfm_c(const int16_t *src_diff, tran_low_t *coeff,
245
13.3M
                          int diff_stride, TxfmParam *txfm_param) {
246
13.3M
  av1_highbd_fwd_txfm(src_diff, coeff, diff_stride, txfm_param);
247
13.3M
}
248
249
void av1_highbd_fwd_txfm(const int16_t *src_diff, tran_low_t *coeff,
250
13.3M
                         int diff_stride, TxfmParam *txfm_param) {
251
13.3M
  assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]);
252
13.3M
  const TX_SIZE tx_size = txfm_param->tx_size;
253
13.3M
  switch (tx_size) {
254
0
    case TX_64X64:
255
0
      highbd_fwd_txfm_64x64(src_diff, coeff, diff_stride, txfm_param);
256
0
      break;
257
0
    case TX_32X64:
258
0
      highbd_fwd_txfm_32x64(src_diff, coeff, diff_stride, txfm_param);
259
0
      break;
260
0
    case TX_64X32:
261
0
      highbd_fwd_txfm_64x32(src_diff, coeff, diff_stride, txfm_param);
262
0
      break;
263
264
220k
    case TX_32X32:
265
220k
      highbd_fwd_txfm_32x32(src_diff, coeff, diff_stride, txfm_param);
266
220k
      break;
267
320k
    case TX_16X16:
268
320k
      highbd_fwd_txfm_16x16(src_diff, coeff, diff_stride, txfm_param);
269
320k
      break;
270
281k
    case TX_8X8:
271
281k
      highbd_fwd_txfm_8x8(src_diff, coeff, diff_stride, txfm_param);
272
281k
      break;
273
23.1k
    case TX_4X8:
274
23.1k
      highbd_fwd_txfm_4x8(src_diff, coeff, diff_stride, txfm_param);
275
23.1k
      break;
276
28.1k
    case TX_8X4:
277
28.1k
      highbd_fwd_txfm_8x4(src_diff, coeff, diff_stride, txfm_param);
278
28.1k
      break;
279
68.2k
    case TX_8X16:
280
68.2k
      highbd_fwd_txfm_8x16(src_diff, coeff, diff_stride, txfm_param);
281
68.2k
      break;
282
79.5k
    case TX_16X8:
283
79.5k
      highbd_fwd_txfm_16x8(src_diff, coeff, diff_stride, txfm_param);
284
79.5k
      break;
285
31.8k
    case TX_16X32:
286
31.8k
      highbd_fwd_txfm_16x32(src_diff, coeff, diff_stride, txfm_param);
287
31.8k
      break;
288
34.2k
    case TX_32X16:
289
34.2k
      highbd_fwd_txfm_32x16(src_diff, coeff, diff_stride, txfm_param);
290
34.2k
      break;
291
12.2M
    case TX_4X4:
292
12.2M
      highbd_fwd_txfm_4x4(src_diff, coeff, diff_stride, txfm_param);
293
12.2M
      break;
294
0
#if !CONFIG_REALTIME_ONLY
295
0
    case TX_4X16:
296
0
      highbd_fwd_txfm_4x16(src_diff, coeff, diff_stride, txfm_param);
297
0
      break;
298
0
    case TX_16X4:
299
0
      highbd_fwd_txfm_16x4(src_diff, coeff, diff_stride, txfm_param);
300
0
      break;
301
0
    case TX_8X32:
302
0
      highbd_fwd_txfm_8x32(src_diff, coeff, diff_stride, txfm_param);
303
0
      break;
304
0
    case TX_32X8:
305
0
      highbd_fwd_txfm_32x8(src_diff, coeff, diff_stride, txfm_param);
306
0
      break;
307
0
    case TX_16X64:
308
0
      highbd_fwd_txfm_16x64(src_diff, coeff, diff_stride, txfm_param);
309
0
      break;
310
0
    case TX_64X16:
311
0
      highbd_fwd_txfm_64x16(src_diff, coeff, diff_stride, txfm_param);
312
0
      break;
313
0
#endif
314
0
    default: assert(0); break;
315
13.3M
  }
316
13.3M
}
317
318
void av1_quick_txfm(int use_hadamard, TX_SIZE tx_size, BitDepthInfo bd_info,
319
                    const int16_t *src_diff, int src_stride,
320
1.48M
                    tran_low_t *coeff) {
321
1.48M
  if (use_hadamard) {
322
1.25M
    switch (tx_size) {
323
0
      case TX_4X4: aom_hadamard_4x4(src_diff, src_stride, coeff); break;
324
474k
      case TX_8X8: aom_hadamard_8x8(src_diff, src_stride, coeff); break;
325
421k
      case TX_16X16: aom_hadamard_16x16(src_diff, src_stride, coeff); break;
326
359k
      case TX_32X32: aom_hadamard_32x32(src_diff, src_stride, coeff); break;
327
0
      default: assert(0);
328
1.25M
    }
329
1.25M
  } else {
330
228k
    TxfmParam txfm_param;
331
228k
    txfm_param.tx_type = DCT_DCT;
332
228k
    txfm_param.tx_size = tx_size;
333
228k
    txfm_param.lossless = 0;
334
228k
    txfm_param.bd = bd_info.bit_depth;
335
228k
    txfm_param.is_hbd = bd_info.use_highbitdepth_buf;
336
228k
    txfm_param.tx_set_type = EXT_TX_SET_ALL16;
337
228k
    av1_fwd_txfm(src_diff, coeff, src_stride, &txfm_param);
338
228k
  }
339
1.48M
}