Coverage Report

Created: 2023-03-26 07:21

/src/libvpx/vp9/common/vp9_idct.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
 *  that can be found in the LICENSE file in the root of the source
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
#include <math.h>
12
13
#include "./vp9_rtcd.h"
14
#include "./vpx_dsp_rtcd.h"
15
#include "vp9/common/vp9_blockd.h"
16
#include "vp9/common/vp9_idct.h"
17
#include "vpx_dsp/inv_txfm.h"
18
#include "vpx_ports/mem.h"
19
20
void vp9_iht4x4_16_add_c(const tran_low_t *input, uint8_t *dest, int stride,
21
0
                         int tx_type) {
22
0
  const transform_2d IHT_4[] = {
23
0
    { idct4_c, idct4_c },   // DCT_DCT  = 0
24
0
    { iadst4_c, idct4_c },  // ADST_DCT = 1
25
0
    { idct4_c, iadst4_c },  // DCT_ADST = 2
26
0
    { iadst4_c, iadst4_c }  // ADST_ADST = 3
27
0
  };
28
29
0
  int i, j;
30
0
  tran_low_t out[4 * 4];
31
0
  tran_low_t *outptr = out;
32
0
  tran_low_t temp_in[4], temp_out[4];
33
34
  // inverse transform row vectors
35
0
  for (i = 0; i < 4; ++i) {
36
0
    IHT_4[tx_type].rows(input, outptr);
37
0
    input += 4;
38
0
    outptr += 4;
39
0
  }
40
41
  // inverse transform column vectors
42
0
  for (i = 0; i < 4; ++i) {
43
0
    for (j = 0; j < 4; ++j) temp_in[j] = out[j * 4 + i];
44
0
    IHT_4[tx_type].cols(temp_in, temp_out);
45
0
    for (j = 0; j < 4; ++j) {
46
0
      dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
47
0
                                            ROUND_POWER_OF_TWO(temp_out[j], 4));
48
0
    }
49
0
  }
50
0
}
51
52
static const transform_2d IHT_8[] = {
53
  { idct8_c, idct8_c },   // DCT_DCT  = 0
54
  { iadst8_c, idct8_c },  // ADST_DCT = 1
55
  { idct8_c, iadst8_c },  // DCT_ADST = 2
56
  { iadst8_c, iadst8_c }  // ADST_ADST = 3
57
};
58
59
void vp9_iht8x8_64_add_c(const tran_low_t *input, uint8_t *dest, int stride,
60
0
                         int tx_type) {
61
0
  int i, j;
62
0
  tran_low_t out[8 * 8];
63
0
  tran_low_t *outptr = out;
64
0
  tran_low_t temp_in[8], temp_out[8];
65
0
  const transform_2d ht = IHT_8[tx_type];
66
67
  // inverse transform row vectors
68
0
  for (i = 0; i < 8; ++i) {
69
0
    ht.rows(input, outptr);
70
0
    input += 8;
71
0
    outptr += 8;
72
0
  }
73
74
  // inverse transform column vectors
75
0
  for (i = 0; i < 8; ++i) {
76
0
    for (j = 0; j < 8; ++j) temp_in[j] = out[j * 8 + i];
77
0
    ht.cols(temp_in, temp_out);
78
0
    for (j = 0; j < 8; ++j) {
79
0
      dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
80
0
                                            ROUND_POWER_OF_TWO(temp_out[j], 5));
81
0
    }
82
0
  }
83
0
}
84
85
static const transform_2d IHT_16[] = {
86
  { idct16_c, idct16_c },   // DCT_DCT  = 0
87
  { iadst16_c, idct16_c },  // ADST_DCT = 1
88
  { idct16_c, iadst16_c },  // DCT_ADST = 2
89
  { iadst16_c, iadst16_c }  // ADST_ADST = 3
90
};
91
92
void vp9_iht16x16_256_add_c(const tran_low_t *input, uint8_t *dest, int stride,
93
0
                            int tx_type) {
94
0
  int i, j;
95
0
  tran_low_t out[16 * 16];
96
0
  tran_low_t *outptr = out;
97
0
  tran_low_t temp_in[16], temp_out[16];
98
0
  const transform_2d ht = IHT_16[tx_type];
99
100
  // Rows
101
0
  for (i = 0; i < 16; ++i) {
102
0
    ht.rows(input, outptr);
103
0
    input += 16;
104
0
    outptr += 16;
105
0
  }
106
107
  // Columns
108
0
  for (i = 0; i < 16; ++i) {
109
0
    for (j = 0; j < 16; ++j) temp_in[j] = out[j * 16 + i];
110
0
    ht.cols(temp_in, temp_out);
111
0
    for (j = 0; j < 16; ++j) {
112
0
      dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
113
0
                                            ROUND_POWER_OF_TWO(temp_out[j], 6));
114
0
    }
115
0
  }
116
0
}
117
118
// idct
119
void vp9_idct4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
120
890k
                     int eob) {
121
890k
  if (eob > 1)
122
731k
    vpx_idct4x4_16_add(input, dest, stride);
123
158k
  else
124
158k
    vpx_idct4x4_1_add(input, dest, stride);
125
890k
}
126
127
void vp9_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
128
76.7k
                     int eob) {
129
76.7k
  if (eob > 1)
130
65.2k
    vpx_iwht4x4_16_add(input, dest, stride);
131
11.5k
  else
132
11.5k
    vpx_iwht4x4_1_add(input, dest, stride);
133
76.7k
}
134
135
void vp9_idct8x8_add(const tran_low_t *input, uint8_t *dest, int stride,
136
661k
                     int eob) {
137
  // If dc is 1, then input[0] is the reconstructed value, do not need
138
  // dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1.
139
140
  // The calculation can be simplified if there are not many non-zero dct
141
  // coefficients. Use eobs to decide what to do.
142
661k
  if (eob == 1)
143
    // DC only DCT coefficient
144
157k
    vpx_idct8x8_1_add(input, dest, stride);
145
503k
  else if (eob <= 12)
146
219k
    vpx_idct8x8_12_add(input, dest, stride);
147
283k
  else
148
283k
    vpx_idct8x8_64_add(input, dest, stride);
149
661k
}
150
151
void vp9_idct16x16_add(const tran_low_t *input, uint8_t *dest, int stride,
152
501k
                       int eob) {
153
  /* The calculation can be simplified if there are not many non-zero dct
154
   * coefficients. Use eobs to separate different cases. */
155
501k
  if (eob == 1) /* DC only DCT coefficient. */
156
165k
    vpx_idct16x16_1_add(input, dest, stride);
157
335k
  else if (eob <= 10)
158
124k
    vpx_idct16x16_10_add(input, dest, stride);
159
210k
  else if (eob <= 38)
160
79.1k
    vpx_idct16x16_38_add(input, dest, stride);
161
131k
  else
162
131k
    vpx_idct16x16_256_add(input, dest, stride);
163
501k
}
164
165
void vp9_idct32x32_add(const tran_low_t *input, uint8_t *dest, int stride,
166
574k
                       int eob) {
167
574k
  if (eob == 1)
168
213k
    vpx_idct32x32_1_add(input, dest, stride);
169
361k
  else if (eob <= 34)
170
    // non-zero coeff only in upper-left 8x8
171
255k
    vpx_idct32x32_34_add(input, dest, stride);
172
106k
  else if (eob <= 135)
173
    // non-zero coeff only in upper-left 16x16
174
74.3k
    vpx_idct32x32_135_add(input, dest, stride);
175
31.7k
  else
176
31.7k
    vpx_idct32x32_1024_add(input, dest, stride);
177
574k
}
178
179
// iht
180
void vp9_iht4x4_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
181
470k
                    int stride, int eob) {
182
470k
  if (tx_type == DCT_DCT)
183
266k
    vp9_idct4x4_add(input, dest, stride, eob);
184
203k
  else
185
203k
    vp9_iht4x4_16_add(input, dest, stride, tx_type);
186
470k
}
187
188
void vp9_iht8x8_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
189
253k
                    int stride, int eob) {
190
253k
  if (tx_type == DCT_DCT) {
191
140k
    vp9_idct8x8_add(input, dest, stride, eob);
192
140k
  } else {
193
113k
    vp9_iht8x8_64_add(input, dest, stride, tx_type);
194
113k
  }
195
253k
}
196
197
void vp9_iht16x16_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
198
205k
                      int stride, int eob) {
199
205k
  if (tx_type == DCT_DCT) {
200
147k
    vp9_idct16x16_add(input, dest, stride, eob);
201
147k
  } else {
202
58.3k
    vp9_iht16x16_256_add(input, dest, stride, tx_type);
203
58.3k
  }
204
205k
}
205
206
#if CONFIG_VP9_HIGHBITDEPTH
207
208
void vp9_highbd_iht4x4_16_add_c(const tran_low_t *input, uint16_t *dest,
209
0
                                int stride, int tx_type, int bd) {
210
0
  const highbd_transform_2d IHT_4[] = {
211
0
    { vpx_highbd_idct4_c, vpx_highbd_idct4_c },   // DCT_DCT  = 0
212
0
    { vpx_highbd_iadst4_c, vpx_highbd_idct4_c },  // ADST_DCT = 1
213
0
    { vpx_highbd_idct4_c, vpx_highbd_iadst4_c },  // DCT_ADST = 2
214
0
    { vpx_highbd_iadst4_c, vpx_highbd_iadst4_c }  // ADST_ADST = 3
215
0
  };
216
217
0
  int i, j;
218
0
  tran_low_t out[4 * 4];
219
0
  tran_low_t *outptr = out;
220
0
  tran_low_t temp_in[4], temp_out[4];
221
222
  // Inverse transform row vectors.
223
0
  for (i = 0; i < 4; ++i) {
224
0
    IHT_4[tx_type].rows(input, outptr, bd);
225
0
    input += 4;
226
0
    outptr += 4;
227
0
  }
228
229
  // Inverse transform column vectors.
230
0
  for (i = 0; i < 4; ++i) {
231
0
    for (j = 0; j < 4; ++j) temp_in[j] = out[j * 4 + i];
232
0
    IHT_4[tx_type].cols(temp_in, temp_out, bd);
233
0
    for (j = 0; j < 4; ++j) {
234
0
      dest[j * stride + i] = highbd_clip_pixel_add(
235
0
          dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 4), bd);
236
0
    }
237
0
  }
238
0
}
239
240
static const highbd_transform_2d HIGH_IHT_8[] = {
241
  { vpx_highbd_idct8_c, vpx_highbd_idct8_c },   // DCT_DCT  = 0
242
  { vpx_highbd_iadst8_c, vpx_highbd_idct8_c },  // ADST_DCT = 1
243
  { vpx_highbd_idct8_c, vpx_highbd_iadst8_c },  // DCT_ADST = 2
244
  { vpx_highbd_iadst8_c, vpx_highbd_iadst8_c }  // ADST_ADST = 3
245
};
246
247
void vp9_highbd_iht8x8_64_add_c(const tran_low_t *input, uint16_t *dest,
248
0
                                int stride, int tx_type, int bd) {
249
0
  int i, j;
250
0
  tran_low_t out[8 * 8];
251
0
  tran_low_t *outptr = out;
252
0
  tran_low_t temp_in[8], temp_out[8];
253
0
  const highbd_transform_2d ht = HIGH_IHT_8[tx_type];
254
255
  // Inverse transform row vectors.
256
0
  for (i = 0; i < 8; ++i) {
257
0
    ht.rows(input, outptr, bd);
258
0
    input += 8;
259
0
    outptr += 8;
260
0
  }
261
262
  // Inverse transform column vectors.
263
0
  for (i = 0; i < 8; ++i) {
264
0
    for (j = 0; j < 8; ++j) temp_in[j] = out[j * 8 + i];
265
0
    ht.cols(temp_in, temp_out, bd);
266
0
    for (j = 0; j < 8; ++j) {
267
0
      dest[j * stride + i] = highbd_clip_pixel_add(
268
0
          dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 5), bd);
269
0
    }
270
0
  }
271
0
}
272
273
static const highbd_transform_2d HIGH_IHT_16[] = {
274
  { vpx_highbd_idct16_c, vpx_highbd_idct16_c },   // DCT_DCT  = 0
275
  { vpx_highbd_iadst16_c, vpx_highbd_idct16_c },  // ADST_DCT = 1
276
  { vpx_highbd_idct16_c, vpx_highbd_iadst16_c },  // DCT_ADST = 2
277
  { vpx_highbd_iadst16_c, vpx_highbd_iadst16_c }  // ADST_ADST = 3
278
};
279
280
void vp9_highbd_iht16x16_256_add_c(const tran_low_t *input, uint16_t *dest,
281
0
                                   int stride, int tx_type, int bd) {
282
0
  int i, j;
283
0
  tran_low_t out[16 * 16];
284
0
  tran_low_t *outptr = out;
285
0
  tran_low_t temp_in[16], temp_out[16];
286
0
  const highbd_transform_2d ht = HIGH_IHT_16[tx_type];
287
288
  // Rows
289
0
  for (i = 0; i < 16; ++i) {
290
0
    ht.rows(input, outptr, bd);
291
0
    input += 16;
292
0
    outptr += 16;
293
0
  }
294
295
  // Columns
296
0
  for (i = 0; i < 16; ++i) {
297
0
    for (j = 0; j < 16; ++j) temp_in[j] = out[j * 16 + i];
298
0
    ht.cols(temp_in, temp_out, bd);
299
0
    for (j = 0; j < 16; ++j) {
300
0
      dest[j * stride + i] = highbd_clip_pixel_add(
301
0
          dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 6), bd);
302
0
    }
303
0
  }
304
0
}
305
306
// idct
307
void vp9_highbd_idct4x4_add(const tran_low_t *input, uint16_t *dest, int stride,
308
386k
                            int eob, int bd) {
309
386k
  if (eob > 1)
310
315k
    vpx_highbd_idct4x4_16_add(input, dest, stride, bd);
311
70.8k
  else
312
70.8k
    vpx_highbd_idct4x4_1_add(input, dest, stride, bd);
313
386k
}
314
315
void vp9_highbd_iwht4x4_add(const tran_low_t *input, uint16_t *dest, int stride,
316
766k
                            int eob, int bd) {
317
766k
  if (eob > 1)
318
646k
    vpx_highbd_iwht4x4_16_add(input, dest, stride, bd);
319
120k
  else
320
120k
    vpx_highbd_iwht4x4_1_add(input, dest, stride, bd);
321
766k
}
322
323
void vp9_highbd_idct8x8_add(const tran_low_t *input, uint16_t *dest, int stride,
324
136k
                            int eob, int bd) {
325
  // If dc is 1, then input[0] is the reconstructed value, do not need
326
  // dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1.
327
328
  // The calculation can be simplified if there are not many non-zero dct
329
  // coefficients. Use eobs to decide what to do.
330
  // DC only DCT coefficient
331
136k
  if (eob == 1) {
332
33.1k
    vpx_highbd_idct8x8_1_add(input, dest, stride, bd);
333
103k
  } else if (eob <= 12) {
334
51.3k
    vpx_highbd_idct8x8_12_add(input, dest, stride, bd);
335
52.4k
  } else {
336
52.4k
    vpx_highbd_idct8x8_64_add(input, dest, stride, bd);
337
52.4k
  }
338
136k
}
339
340
void vp9_highbd_idct16x16_add(const tran_low_t *input, uint16_t *dest,
341
106k
                              int stride, int eob, int bd) {
342
  // The calculation can be simplified if there are not many non-zero dct
343
  // coefficients. Use eobs to separate different cases.
344
  // DC only DCT coefficient.
345
106k
  if (eob == 1) {
346
30.1k
    vpx_highbd_idct16x16_1_add(input, dest, stride, bd);
347
76.5k
  } else if (eob <= 10) {
348
34.1k
    vpx_highbd_idct16x16_10_add(input, dest, stride, bd);
349
42.3k
  } else if (eob <= 38) {
350
17.9k
    vpx_highbd_idct16x16_38_add(input, dest, stride, bd);
351
24.4k
  } else {
352
24.4k
    vpx_highbd_idct16x16_256_add(input, dest, stride, bd);
353
24.4k
  }
354
106k
}
355
356
void vp9_highbd_idct32x32_add(const tran_low_t *input, uint16_t *dest,
357
262k
                              int stride, int eob, int bd) {
358
  // Non-zero coeff only in upper-left 8x8
359
262k
  if (eob == 1) {
360
53.3k
    vpx_highbd_idct32x32_1_add(input, dest, stride, bd);
361
208k
  } else if (eob <= 34) {
362
147k
    vpx_highbd_idct32x32_34_add(input, dest, stride, bd);
363
147k
  } else if (eob <= 135) {
364
38.2k
    vpx_highbd_idct32x32_135_add(input, dest, stride, bd);
365
38.2k
  } else {
366
23.1k
    vpx_highbd_idct32x32_1024_add(input, dest, stride, bd);
367
23.1k
  }
368
262k
}
369
370
// iht
371
void vp9_highbd_iht4x4_add(TX_TYPE tx_type, const tran_low_t *input,
372
523k
                           uint16_t *dest, int stride, int eob, int bd) {
373
523k
  if (tx_type == DCT_DCT)
374
343k
    vp9_highbd_idct4x4_add(input, dest, stride, eob, bd);
375
179k
  else
376
179k
    vp9_highbd_iht4x4_16_add(input, dest, stride, tx_type, bd);
377
523k
}
378
379
void vp9_highbd_iht8x8_add(TX_TYPE tx_type, const tran_low_t *input,
380
229k
                           uint16_t *dest, int stride, int eob, int bd) {
381
229k
  if (tx_type == DCT_DCT) {
382
117k
    vp9_highbd_idct8x8_add(input, dest, stride, eob, bd);
383
117k
  } else {
384
111k
    vp9_highbd_iht8x8_64_add(input, dest, stride, tx_type, bd);
385
111k
  }
386
229k
}
387
388
void vp9_highbd_iht16x16_add(TX_TYPE tx_type, const tran_low_t *input,
389
163k
                             uint16_t *dest, int stride, int eob, int bd) {
390
163k
  if (tx_type == DCT_DCT) {
391
90.6k
    vp9_highbd_idct16x16_add(input, dest, stride, eob, bd);
392
90.6k
  } else {
393
73.1k
    vp9_highbd_iht16x16_256_add(input, dest, stride, tx_type, bd);
394
73.1k
  }
395
163k
}
396
#endif  // CONFIG_VP9_HIGHBITDEPTH