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