/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 | 0 | int av1_get_tx_scale(const TX_SIZE tx_size) { |
25 | 0 | const int pels = tx_size_2d[tx_size]; |
26 | | // Largest possible pels is 4096 (64x64). |
27 | 0 | return (pels > 256) + (pels > 1024); |
28 | 0 | } |
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 | 0 | int eob, int bd) { |
36 | 0 | if (eob > 1) |
37 | 0 | av1_highbd_iwht4x4_16_add(input, dest, stride, bd); |
38 | 0 | else |
39 | 0 | av1_highbd_iwht4x4_1_add(input, dest, stride, bd); |
40 | 0 | } |
41 | | |
42 | | void av1_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 | | void av1_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 | | void av1_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 | | void av1_highbd_inv_txfm_add_16x32_c(const tran_low_t *input, uint8_t *dest, |
76 | 0 | int stride, const TxfmParam *txfm_param) { |
77 | 0 | const int32_t *src = cast_to_int32(input); |
78 | 0 | av1_inv_txfm2d_add_16x32_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
79 | 0 | txfm_param->tx_type, txfm_param->bd); |
80 | 0 | } |
81 | | |
82 | | void av1_highbd_inv_txfm_add_32x16_c(const tran_low_t *input, uint8_t *dest, |
83 | 0 | int stride, const TxfmParam *txfm_param) { |
84 | 0 | const int32_t *src = cast_to_int32(input); |
85 | 0 | av1_inv_txfm2d_add_32x16_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
86 | 0 | txfm_param->tx_type, txfm_param->bd); |
87 | 0 | } |
88 | | |
89 | | void av1_highbd_inv_txfm_add_16x4_c(const tran_low_t *input, uint8_t *dest, |
90 | 0 | int stride, const TxfmParam *txfm_param) { |
91 | 0 | const int32_t *src = cast_to_int32(input); |
92 | 0 | av1_inv_txfm2d_add_16x4_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
93 | 0 | txfm_param->tx_type, txfm_param->bd); |
94 | 0 | } |
95 | | |
96 | | void av1_highbd_inv_txfm_add_4x16_c(const tran_low_t *input, uint8_t *dest, |
97 | 0 | int stride, const TxfmParam *txfm_param) { |
98 | 0 | const int32_t *src = cast_to_int32(input); |
99 | 0 | av1_inv_txfm2d_add_4x16_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
100 | 0 | txfm_param->tx_type, txfm_param->bd); |
101 | 0 | } |
102 | | |
103 | | void av1_highbd_inv_txfm_add_32x8_c(const tran_low_t *input, uint8_t *dest, |
104 | 0 | int stride, const TxfmParam *txfm_param) { |
105 | 0 | const int32_t *src = cast_to_int32(input); |
106 | 0 | av1_inv_txfm2d_add_32x8_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
107 | 0 | txfm_param->tx_type, txfm_param->bd); |
108 | 0 | } |
109 | | |
110 | | void av1_highbd_inv_txfm_add_8x32_c(const tran_low_t *input, uint8_t *dest, |
111 | 0 | int stride, const TxfmParam *txfm_param) { |
112 | 0 | const int32_t *src = cast_to_int32(input); |
113 | 0 | av1_inv_txfm2d_add_8x32_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
114 | 0 | txfm_param->tx_type, txfm_param->bd); |
115 | 0 | } |
116 | | |
117 | | void av1_highbd_inv_txfm_add_32x64_c(const tran_low_t *input, uint8_t *dest, |
118 | 0 | int stride, const TxfmParam *txfm_param) { |
119 | 0 | const int32_t *src = cast_to_int32(input); |
120 | 0 | av1_inv_txfm2d_add_32x64_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
121 | 0 | txfm_param->tx_type, txfm_param->bd); |
122 | 0 | } |
123 | | |
124 | | void av1_highbd_inv_txfm_add_64x32_c(const tran_low_t *input, uint8_t *dest, |
125 | 0 | int stride, const TxfmParam *txfm_param) { |
126 | 0 | const int32_t *src = cast_to_int32(input); |
127 | 0 | av1_inv_txfm2d_add_64x32_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
128 | 0 | txfm_param->tx_type, txfm_param->bd); |
129 | 0 | } |
130 | | |
131 | | void av1_highbd_inv_txfm_add_16x64_c(const tran_low_t *input, uint8_t *dest, |
132 | 0 | int stride, const TxfmParam *txfm_param) { |
133 | 0 | const int32_t *src = cast_to_int32(input); |
134 | 0 | av1_inv_txfm2d_add_16x64_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
135 | 0 | txfm_param->tx_type, txfm_param->bd); |
136 | 0 | } |
137 | | |
138 | | void av1_highbd_inv_txfm_add_64x16_c(const tran_low_t *input, uint8_t *dest, |
139 | 0 | int stride, const TxfmParam *txfm_param) { |
140 | 0 | const int32_t *src = cast_to_int32(input); |
141 | 0 | av1_inv_txfm2d_add_64x16_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
142 | 0 | txfm_param->tx_type, txfm_param->bd); |
143 | 0 | } |
144 | | |
145 | | void av1_highbd_inv_txfm_add_8x8_c(const tran_low_t *input, uint8_t *dest, |
146 | 0 | int stride, const TxfmParam *txfm_param) { |
147 | 0 | int bd = txfm_param->bd; |
148 | 0 | const TX_TYPE tx_type = txfm_param->tx_type; |
149 | 0 | const int32_t *src = cast_to_int32(input); |
150 | |
|
151 | 0 | av1_inv_txfm2d_add_8x8_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, bd); |
152 | 0 | } |
153 | | |
154 | | void av1_highbd_inv_txfm_add_16x16_c(const tran_low_t *input, uint8_t *dest, |
155 | 0 | int stride, const TxfmParam *txfm_param) { |
156 | 0 | int bd = txfm_param->bd; |
157 | 0 | const TX_TYPE tx_type = txfm_param->tx_type; |
158 | 0 | const int32_t *src = cast_to_int32(input); |
159 | |
|
160 | 0 | av1_inv_txfm2d_add_16x16_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, |
161 | 0 | bd); |
162 | 0 | } |
163 | | |
164 | | void av1_highbd_inv_txfm_add_8x16_c(const tran_low_t *input, uint8_t *dest, |
165 | 0 | int stride, const TxfmParam *txfm_param) { |
166 | 0 | const int32_t *src = cast_to_int32(input); |
167 | 0 | av1_inv_txfm2d_add_8x16_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
168 | 0 | txfm_param->tx_type, txfm_param->bd); |
169 | 0 | } |
170 | | |
171 | | void av1_highbd_inv_txfm_add_16x8_c(const tran_low_t *input, uint8_t *dest, |
172 | 0 | int stride, const TxfmParam *txfm_param) { |
173 | 0 | const int32_t *src = cast_to_int32(input); |
174 | 0 | av1_inv_txfm2d_add_16x8_c(src, CONVERT_TO_SHORTPTR(dest), stride, |
175 | 0 | txfm_param->tx_type, txfm_param->bd); |
176 | 0 | } |
177 | | |
178 | | void av1_highbd_inv_txfm_add_32x32_c(const tran_low_t *input, uint8_t *dest, |
179 | 0 | int stride, const TxfmParam *txfm_param) { |
180 | 0 | const int bd = txfm_param->bd; |
181 | 0 | const TX_TYPE tx_type = txfm_param->tx_type; |
182 | 0 | const int32_t *src = cast_to_int32(input); |
183 | |
|
184 | 0 | av1_inv_txfm2d_add_32x32_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, |
185 | 0 | bd); |
186 | 0 | } |
187 | | |
188 | | void av1_highbd_inv_txfm_add_64x64_c(const tran_low_t *input, uint8_t *dest, |
189 | 0 | int stride, const TxfmParam *txfm_param) { |
190 | 0 | const int bd = txfm_param->bd; |
191 | 0 | const TX_TYPE tx_type = txfm_param->tx_type; |
192 | 0 | const int32_t *src = cast_to_int32(input); |
193 | 0 | assert(tx_type == DCT_DCT); |
194 | 0 | av1_inv_txfm2d_add_64x64_c(src, CONVERT_TO_SHORTPTR(dest), stride, tx_type, |
195 | 0 | bd); |
196 | 0 | } |
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 | 0 | TxfmParam *txfm_param) { |
201 | 0 | (void)plane; |
202 | 0 | txfm_param->tx_type = tx_type; |
203 | 0 | txfm_param->tx_size = tx_size; |
204 | 0 | txfm_param->eob = eob; |
205 | 0 | txfm_param->lossless = xd->lossless[xd->mi[0]->segment_id]; |
206 | 0 | txfm_param->bd = xd->bd; |
207 | 0 | txfm_param->is_hbd = is_cur_buf_hbd(xd); |
208 | 0 | txfm_param->tx_set_type = av1_get_ext_tx_set_type( |
209 | 0 | txfm_param->tx_size, is_inter_block(xd->mi[0]), reduced_tx_set); |
210 | 0 | } |
211 | | |
212 | | void av1_highbd_inv_txfm_add_c(const tran_low_t *input, uint8_t *dest, |
213 | 0 | int stride, const TxfmParam *txfm_param) { |
214 | 0 | assert(av1_ext_tx_used[txfm_param->tx_set_type][txfm_param->tx_type]); |
215 | 0 | const TX_SIZE tx_size = txfm_param->tx_size; |
216 | 0 | switch (tx_size) { |
217 | 0 | case TX_32X32: |
218 | 0 | av1_highbd_inv_txfm_add_32x32_c(input, dest, stride, txfm_param); |
219 | 0 | break; |
220 | 0 | case TX_16X16: |
221 | 0 | av1_highbd_inv_txfm_add_16x16_c(input, dest, stride, txfm_param); |
222 | 0 | break; |
223 | 0 | case TX_8X8: |
224 | 0 | av1_highbd_inv_txfm_add_8x8_c(input, dest, stride, txfm_param); |
225 | 0 | break; |
226 | 0 | case TX_4X8: |
227 | 0 | av1_highbd_inv_txfm_add_4x8_c(input, dest, stride, txfm_param); |
228 | 0 | break; |
229 | 0 | case TX_8X4: |
230 | 0 | av1_highbd_inv_txfm_add_8x4_c(input, dest, stride, txfm_param); |
231 | 0 | break; |
232 | 0 | case TX_8X16: |
233 | 0 | av1_highbd_inv_txfm_add_8x16_c(input, dest, stride, txfm_param); |
234 | 0 | break; |
235 | 0 | case TX_16X8: |
236 | 0 | av1_highbd_inv_txfm_add_16x8_c(input, dest, stride, txfm_param); |
237 | 0 | break; |
238 | 0 | case TX_16X32: |
239 | 0 | av1_highbd_inv_txfm_add_16x32_c(input, dest, stride, txfm_param); |
240 | 0 | break; |
241 | 0 | case TX_32X16: |
242 | 0 | av1_highbd_inv_txfm_add_32x16_c(input, dest, stride, txfm_param); |
243 | 0 | break; |
244 | 0 | case TX_64X64: |
245 | 0 | av1_highbd_inv_txfm_add_64x64_c(input, dest, stride, txfm_param); |
246 | 0 | break; |
247 | 0 | case TX_32X64: |
248 | 0 | av1_highbd_inv_txfm_add_32x64_c(input, dest, stride, txfm_param); |
249 | 0 | break; |
250 | 0 | case TX_64X32: |
251 | 0 | av1_highbd_inv_txfm_add_64x32_c(input, dest, stride, txfm_param); |
252 | 0 | break; |
253 | 0 | case TX_16X64: |
254 | 0 | av1_highbd_inv_txfm_add_16x64_c(input, dest, stride, txfm_param); |
255 | 0 | break; |
256 | 0 | case TX_64X16: |
257 | 0 | av1_highbd_inv_txfm_add_64x16_c(input, dest, stride, txfm_param); |
258 | 0 | break; |
259 | 0 | 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 | 0 | av1_highbd_inv_txfm_add_4x4_c(input, dest, stride, txfm_param); |
264 | 0 | break; |
265 | 0 | case TX_16X4: |
266 | 0 | av1_highbd_inv_txfm_add_16x4_c(input, dest, stride, txfm_param); |
267 | 0 | break; |
268 | 0 | case TX_4X16: |
269 | 0 | av1_highbd_inv_txfm_add_4x16_c(input, dest, stride, txfm_param); |
270 | 0 | break; |
271 | 0 | case TX_8X32: |
272 | 0 | av1_highbd_inv_txfm_add_8x32_c(input, dest, stride, txfm_param); |
273 | 0 | break; |
274 | 0 | case TX_32X8: |
275 | 0 | av1_highbd_inv_txfm_add_32x8_c(input, dest, stride, txfm_param); |
276 | 0 | break; |
277 | 0 | default: assert(0 && "Invalid transform size"); break; |
278 | 0 | } |
279 | 0 | } |
280 | | |
281 | | void av1_inv_txfm_add_c(const tran_low_t *dqcoeff, uint8_t *dst, int stride, |
282 | 0 | const TxfmParam *txfm_param) { |
283 | 0 | const TX_SIZE tx_size = txfm_param->tx_size; |
284 | 0 | DECLARE_ALIGNED(32, uint16_t, tmp[MAX_TX_SQUARE]); |
285 | 0 | int tmp_stride = MAX_TX_SIZE; |
286 | 0 | int w = tx_size_wide[tx_size]; |
287 | 0 | int h = tx_size_high[tx_size]; |
288 | 0 | for (int r = 0; r < h; ++r) { |
289 | 0 | for (int c = 0; c < w; ++c) { |
290 | 0 | tmp[r * tmp_stride + c] = dst[r * stride + c]; |
291 | 0 | } |
292 | 0 | } |
293 | |
|
294 | 0 | av1_highbd_inv_txfm_add(dqcoeff, CONVERT_TO_BYTEPTR(tmp), tmp_stride, |
295 | 0 | txfm_param); |
296 | |
|
297 | 0 | for (int r = 0; r < h; ++r) { |
298 | 0 | for (int c = 0; c < w; ++c) { |
299 | 0 | dst[r * stride + c] = (uint8_t)tmp[r * tmp_stride + c]; |
300 | 0 | } |
301 | 0 | } |
302 | 0 | } |
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 | 0 | int stride, int eob, int reduced_tx_set) { |
308 | 0 | if (!eob) return; |
309 | | |
310 | 0 | assert(eob <= av1_get_max_eob(tx_size)); |
311 | |
|
312 | 0 | TxfmParam txfm_param; |
313 | 0 | init_txfm_param(xd, plane, tx_size, tx_type, eob, reduced_tx_set, |
314 | 0 | &txfm_param); |
315 | 0 | assert(av1_ext_tx_used[txfm_param.tx_set_type][txfm_param.tx_type]); |
316 | |
|
317 | 0 | if (txfm_param.is_hbd) { |
318 | 0 | av1_highbd_inv_txfm_add(dqcoeff, dst, stride, &txfm_param); |
319 | 0 | } else { |
320 | 0 | av1_inv_txfm_add(dqcoeff, dst, stride, &txfm_param); |
321 | 0 | } |
322 | 0 | } |