/src/libavc/decoder/svc/isvcd_iquant_itrans_residual.c
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2022 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | /** |
21 | | ******************************************************************************* |
22 | | * @file |
23 | | * isvcd_iquant_itrans_residual.c |
24 | | * |
25 | | * @brief |
26 | | * Contains definition of functions for h264 inverse quantization inverse |
27 | | *transformation and resd comp |
28 | | * |
29 | | * @author |
30 | | * Kishore |
31 | | * |
32 | | * @par List of Functions: |
33 | | * - isvcd_iquant_itrans_residual_4x4() |
34 | | * - isvcd_iquant_itrans_residual_8x8() |
35 | | * - isvcd_iquant_itrans_residual_4x4_dc() |
36 | | * - isvcd_iquant_itrans_residual_8x8_dc() |
37 | | * - isvcd_iquant_itrans_residual_chroma_4x4() |
38 | | * - isvcd_iquant_itrans_residual_chroma_4x4_dc() |
39 | | * |
40 | | * @remarks |
41 | | * None |
42 | | * |
43 | | ******************************************************************************* |
44 | | */ |
45 | | |
46 | | /* User include files */ |
47 | | #include "ih264_typedefs.h" |
48 | | #include "ih264_defs.h" |
49 | | #include "ih264_trans_macros.h" |
50 | | #include "ih264_macros.h" |
51 | | #include "ih264_platform_macros.h" |
52 | | #include "ih264_trans_data.h" |
53 | | #include "ih264_size_defs.h" |
54 | | #include "ih264_structs.h" |
55 | | #include "isvcd_iquant_itrans_residual.h" |
56 | | |
57 | | /*****************************************************************************/ |
58 | | /* */ |
59 | | /* Function Name : isvcd_iquant_itrans_residual_4x4 */ |
60 | | /* */ |
61 | | /* Description : this function computes the resd output from the */ |
62 | | /* IQ+IT */ |
63 | | /* */ |
64 | | /* Inputs : */ |
65 | | /* Globals : none */ |
66 | | /* Processing : */ |
67 | | /* */ |
68 | | /* Outputs : i4_nnz */ |
69 | | /* Returns : none */ |
70 | | /* */ |
71 | | /* Issues : none */ |
72 | | /* */ |
73 | | /* Revision History: */ |
74 | | /* */ |
75 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
76 | | /* 25 11 2021 Kishore creation */ |
77 | | /* */ |
78 | | /*****************************************************************************/ |
79 | | |
80 | | WORD32 isvcd_iquant_itrans_residual_4x4(WORD16 *pi2_src, WORD16 *pi2_pred, WORD16 *pi2_out, |
81 | | WORD32 pred_strd, WORD32 out_strd, |
82 | | const UWORD16 *pu2_iscal_mat, const UWORD16 *pu2_weigh_mat, |
83 | | UWORD32 u4_qp_div_6, WORD16 *pi2_tmp, WORD32 iq_start_idx, |
84 | | WORD16 *pi2_dc_ld_addr) |
85 | 0 | { |
86 | 0 | WORD16 *pi2_src_ptr = pi2_src; |
87 | 0 | WORD16 *pi2_tmp_ptr = pi2_tmp; |
88 | 0 | WORD16 *pi2_pred_ptr = pi2_pred; |
89 | 0 | WORD16 *pi2_out_ptr = pi2_out; |
90 | 0 | WORD16 x0, x1, x2, x3, i; |
91 | 0 | WORD32 q0, q1, q2, q3; |
92 | 0 | WORD16 i_macro; |
93 | 0 | WORD16 rnd_fact = (u4_qp_div_6 < 4) ? 1 << (3 - u4_qp_div_6) : 0; |
94 | 0 | WORD32 i4_nnz = 0; |
95 | | |
96 | | /* inverse quant */ |
97 | | /*horizontal inverse transform */ |
98 | 0 | for(i = 0; i < SUB_BLK_WIDTH_4x4; i++) |
99 | 0 | { |
100 | 0 | q0 = pi2_src_ptr[0]; |
101 | 0 | INV_QUANT(q0, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, rnd_fact, 4); |
102 | 0 | if(i == 0 && iq_start_idx == 1) |
103 | 0 | q0 = pi2_dc_ld_addr[0]; // Restoring dc value for intra case |
104 | |
|
105 | 0 | q2 = pi2_src_ptr[2]; |
106 | 0 | INV_QUANT(q2, pu2_iscal_mat[2], pu2_weigh_mat[2], u4_qp_div_6, rnd_fact, 4); |
107 | |
|
108 | 0 | x0 = q0 + q2; |
109 | 0 | x1 = q0 - q2; |
110 | |
|
111 | 0 | q1 = pi2_src_ptr[1]; |
112 | 0 | INV_QUANT(q1, pu2_iscal_mat[1], pu2_weigh_mat[1], u4_qp_div_6, rnd_fact, 4); |
113 | |
|
114 | 0 | q3 = pi2_src_ptr[3]; |
115 | 0 | INV_QUANT(q3, pu2_iscal_mat[3], pu2_weigh_mat[3], u4_qp_div_6, rnd_fact, 4); |
116 | |
|
117 | 0 | x2 = (q1 >> 1) - q3; |
118 | 0 | x3 = q1 + (q3 >> 1); |
119 | |
|
120 | 0 | pi2_tmp_ptr[0] = x0 + x3; |
121 | 0 | pi2_tmp_ptr[1] = x1 + x2; |
122 | 0 | pi2_tmp_ptr[2] = x1 - x2; |
123 | 0 | pi2_tmp_ptr[3] = x0 - x3; |
124 | |
|
125 | 0 | pi2_src_ptr += SUB_BLK_WIDTH_4x4; |
126 | 0 | pi2_tmp_ptr += SUB_BLK_WIDTH_4x4; |
127 | 0 | pu2_iscal_mat += SUB_BLK_WIDTH_4x4; |
128 | 0 | pu2_weigh_mat += SUB_BLK_WIDTH_4x4; |
129 | 0 | } |
130 | | |
131 | | /* vertical inverse transform */ |
132 | 0 | pi2_tmp_ptr = pi2_tmp; |
133 | 0 | for(i = 0; i < SUB_BLK_WIDTH_4x4; i++) |
134 | 0 | { |
135 | 0 | pi2_pred_ptr = pi2_pred; |
136 | 0 | pi2_out = pi2_out_ptr; |
137 | |
|
138 | 0 | x0 = (pi2_tmp_ptr[0] + pi2_tmp_ptr[8]); |
139 | 0 | x1 = (pi2_tmp_ptr[0] - pi2_tmp_ptr[8]); |
140 | 0 | x2 = (pi2_tmp_ptr[4] >> 1) - pi2_tmp_ptr[12]; |
141 | 0 | x3 = pi2_tmp_ptr[4] + (pi2_tmp_ptr[12] >> 1); |
142 | | |
143 | | /* inverse prediction */ |
144 | 0 | i_macro = x0 + x3; |
145 | 0 | i_macro = ((i_macro + 32) >> 6); |
146 | 0 | i_macro = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
147 | 0 | i4_nnz |= !!i_macro; |
148 | 0 | *pi2_out = i_macro; |
149 | 0 | pi2_pred_ptr += pred_strd; |
150 | 0 | pi2_out += out_strd; |
151 | |
|
152 | 0 | i_macro = x1 + x2; |
153 | 0 | i_macro = ((i_macro + 32) >> 6); |
154 | 0 | i_macro = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
155 | 0 | i4_nnz |= !!i_macro; |
156 | 0 | *pi2_out = i_macro; |
157 | 0 | pi2_pred_ptr += pred_strd; |
158 | 0 | pi2_out += out_strd; |
159 | |
|
160 | 0 | i_macro = x1 - x2; |
161 | 0 | i_macro = ((i_macro + 32) >> 6); |
162 | 0 | i_macro = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
163 | 0 | i4_nnz |= !!i_macro; |
164 | 0 | *pi2_out = i_macro; |
165 | 0 | pi2_pred_ptr += pred_strd; |
166 | 0 | pi2_out += out_strd; |
167 | |
|
168 | 0 | i_macro = x0 - x3; |
169 | 0 | i_macro = ((i_macro + 32) >> 6); |
170 | 0 | i_macro = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
171 | 0 | i4_nnz |= !!i_macro; |
172 | 0 | *pi2_out = i_macro; |
173 | |
|
174 | 0 | pi2_tmp_ptr++; |
175 | 0 | pi2_out_ptr++; |
176 | 0 | pi2_pred++; |
177 | 0 | } |
178 | 0 | return i4_nnz; |
179 | 0 | } |
180 | | /*****************************************************************************/ |
181 | | /* */ |
182 | | /* Function Name : isvcd_iquant_itrans_residual_4x4_dc */ |
183 | | /* */ |
184 | | /* Description : this function computes the resd output from the */ |
185 | | /* IQ+IT */ |
186 | | /* */ |
187 | | /* Inputs : */ |
188 | | /* Globals : none */ |
189 | | /* Processing : */ |
190 | | /* */ |
191 | | /* Outputs : i4_nnz */ |
192 | | /* Returns : none */ |
193 | | /* */ |
194 | | /* Issues : none */ |
195 | | /* */ |
196 | | /* Revision History: */ |
197 | | /* */ |
198 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
199 | | /* 25 11 2021 Kishore creation */ |
200 | | /* */ |
201 | | /*****************************************************************************/ |
202 | | |
203 | | WORD32 isvcd_iquant_itrans_residual_4x4_dc(WORD16 *pi2_src, WORD16 *pi2_pred, WORD16 *pi2_out, |
204 | | WORD32 pred_strd, WORD32 out_strd, |
205 | | const UWORD16 *pu2_iscal_mat, |
206 | | const UWORD16 *pu2_weigh_mat, UWORD32 u4_qp_div_6, |
207 | | WORD16 *pi2_tmp, WORD32 iq_start_idx, |
208 | | WORD16 *pi2_dc_ld_addr) |
209 | 0 | { |
210 | 0 | WORD32 i4_nnz = 0; |
211 | 0 | WORD16 *pi2_pred_ptr = pi2_pred; |
212 | 0 | WORD16 *pi2_out_ptr = pi2_out; |
213 | 0 | WORD32 q0; |
214 | 0 | WORD16 i_macro, i; |
215 | 0 | WORD16 rnd_fact = (u4_qp_div_6 < 4) ? 1 << (3 - u4_qp_div_6) : 0; |
216 | 0 | UNUSED(pi2_tmp); |
217 | |
|
218 | 0 | if(iq_start_idx == 0) |
219 | 0 | { |
220 | 0 | q0 = pi2_src[0]; |
221 | 0 | INV_QUANT(q0, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, rnd_fact, 4); |
222 | 0 | } |
223 | 0 | else |
224 | 0 | { |
225 | 0 | q0 = pi2_dc_ld_addr[0]; // Restoring dc value for intra case3 |
226 | 0 | } |
227 | 0 | i_macro = ((q0 + 32) >> 6); |
228 | 0 | for(i = 0; i < SUB_BLK_WIDTH_4x4; i++) |
229 | 0 | { |
230 | 0 | pi2_pred_ptr = pi2_pred; |
231 | 0 | pi2_out = pi2_out_ptr; |
232 | | |
233 | | /* inverse prediction */ |
234 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
235 | 0 | i4_nnz |= !!(*pi2_out); |
236 | 0 | pi2_pred_ptr += pred_strd; |
237 | 0 | pi2_out += out_strd; |
238 | |
|
239 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
240 | 0 | i4_nnz |= !!(*pi2_out); |
241 | 0 | pi2_pred_ptr += pred_strd; |
242 | 0 | pi2_out += out_strd; |
243 | |
|
244 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
245 | 0 | i4_nnz |= !!(*pi2_out); |
246 | 0 | pi2_pred_ptr += pred_strd; |
247 | 0 | pi2_out += out_strd; |
248 | |
|
249 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
250 | 0 | i4_nnz |= !!(*pi2_out); |
251 | |
|
252 | 0 | pi2_out_ptr++; |
253 | 0 | pi2_pred++; |
254 | 0 | } |
255 | 0 | return i4_nnz; |
256 | 0 | } |
257 | | /*****************************************************************************/ |
258 | | /* */ |
259 | | /* Function Name : isvcd_iquant_itrans_residual_8x8 */ |
260 | | /* */ |
261 | | /* Description : this function computes the resd output from the */ |
262 | | /* IQ+IT */ |
263 | | /* */ |
264 | | /* Inputs : */ |
265 | | /* Globals : none */ |
266 | | /* Processing : */ |
267 | | /* */ |
268 | | /* Outputs : i4_nnz */ |
269 | | /* Returns : none */ |
270 | | /* */ |
271 | | /* Issues : none */ |
272 | | /* */ |
273 | | /* Revision History: */ |
274 | | /* */ |
275 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
276 | | /* 25 11 2021 Kishore creation */ |
277 | | /* */ |
278 | | /*****************************************************************************/ |
279 | | |
280 | | WORD32 isvcd_iquant_itrans_residual_8x8(WORD16 *pi2_src, WORD16 *pi2_pred, WORD16 *pi2_out, |
281 | | WORD32 pred_strd, WORD32 out_strd, |
282 | | const UWORD16 *pu2_iscale_mat, const UWORD16 *pu2_weigh_mat, |
283 | | UWORD32 qp_div, WORD16 *pi2_tmp, WORD32 iq_start_idx, |
284 | | WORD16 *pi2_dc_ld_addr) |
285 | 0 | { |
286 | 0 | WORD32 i4_nnz = 0, i4_nnz_H = 0, i4_nnz_L = 0; |
287 | 0 | WORD32 i; |
288 | 0 | WORD16 *pi2_tmp_ptr = pi2_tmp; |
289 | 0 | WORD16 *pi2_pred_ptr = pi2_pred; |
290 | 0 | WORD16 *pi2_out_ptr = pi2_out; |
291 | 0 | WORD16 i_z0, i_z1, i_z2, i_z3, i_z4, i_z5, i_z6, i_z7; |
292 | 0 | WORD16 i_y0, i_y1, i_y2, i_y3, i_y4, i_y5, i_y6, i_y7; |
293 | 0 | WORD32 q; |
294 | 0 | WORD32 rnd_fact = (qp_div < 6) ? (1 << (5 - qp_div)) : 0; |
295 | 0 | UNUSED(iq_start_idx); |
296 | 0 | UNUSED(pi2_dc_ld_addr); |
297 | | /*************************************************************/ |
298 | | /* De quantization of coefficients. Will be replaced by SIMD */ |
299 | | /* operations on platform. Note : DC coeff is not scaled */ |
300 | | /*************************************************************/ |
301 | 0 | for(i = 0; i < (SUB_BLK_WIDTH_8x8 * SUB_BLK_WIDTH_8x8); i++) |
302 | 0 | { |
303 | 0 | q = pi2_src[i]; |
304 | 0 | INV_QUANT(q, pu2_iscale_mat[i], pu2_weigh_mat[i], qp_div, rnd_fact, 6); |
305 | 0 | pi2_tmp_ptr[i] = q; |
306 | 0 | } |
307 | | /* Perform Inverse transform */ |
308 | | /*--------------------------------------------------------------------*/ |
309 | | /* IDCT [ Horizontal transformation ] */ |
310 | | /*--------------------------------------------------------------------*/ |
311 | 0 | for(i = 0; i < SUB_BLK_WIDTH_8x8; i++) |
312 | 0 | { |
313 | | /*------------------------------------------------------------------*/ |
314 | | /* y0 = w0 + w4 */ |
315 | | /* y1 = -w3 + w5 - w7 - (w7 >> 1) */ |
316 | | /* y2 = w0 - w4 */ |
317 | | /* y3 = w1 + w7 - w3 - (w3 >> 1) */ |
318 | | /* y4 = (w2 >> 1) - w6 */ |
319 | | /* y5 = -w1 + w7 + w5 + (w5 >> 1) */ |
320 | | /* y6 = w2 + (w6 >> 1) */ |
321 | | /* y7 = w3 + w5 + w1 + (w1 >> 1) */ |
322 | | /*------------------------------------------------------------------*/ |
323 | 0 | i_y0 = (pi2_tmp_ptr[0] + pi2_tmp_ptr[4]); |
324 | |
|
325 | 0 | i_y1 = |
326 | 0 | ((WORD32) (-pi2_tmp_ptr[3]) + pi2_tmp_ptr[5] - pi2_tmp_ptr[7] - (pi2_tmp_ptr[7] >> 1)); |
327 | |
|
328 | 0 | i_y2 = (pi2_tmp_ptr[0] - pi2_tmp_ptr[4]); |
329 | 0 | i_y3 = ((WORD32) pi2_tmp_ptr[1] + pi2_tmp_ptr[7] - pi2_tmp_ptr[3] - (pi2_tmp_ptr[3] >> 1)); |
330 | 0 | i_y4 = ((pi2_tmp_ptr[2] >> 1) - pi2_tmp_ptr[6]); |
331 | |
|
332 | 0 | i_y5 = |
333 | 0 | ((WORD32) (-pi2_tmp_ptr[1]) + pi2_tmp_ptr[7] + pi2_tmp_ptr[5] + (pi2_tmp_ptr[5] >> 1)); |
334 | |
|
335 | 0 | i_y6 = (pi2_tmp_ptr[2] + (pi2_tmp_ptr[6] >> 1)); |
336 | 0 | i_y7 = ((WORD32) pi2_tmp_ptr[3] + pi2_tmp_ptr[5] + pi2_tmp_ptr[1] + (pi2_tmp_ptr[1] >> 1)); |
337 | | |
338 | | /*------------------------------------------------------------------*/ |
339 | | /* z0 = y0 + y6 */ |
340 | | /* z1 = y1 + (y7 >> 2) */ |
341 | | /* z2 = y2 + y4 */ |
342 | | /* z3 = y3 + (y5 >> 2) */ |
343 | | /* z4 = y2 - y4 */ |
344 | | /* z5 = (y3 >> 2) - y5 */ |
345 | | /* z6 = y0 - y6 */ |
346 | | /* z7 = y7 - (y1 >> 2) */ |
347 | | /*------------------------------------------------------------------*/ |
348 | 0 | i_z0 = i_y0 + i_y6; |
349 | 0 | i_z1 = i_y1 + (i_y7 >> 2); |
350 | 0 | i_z2 = i_y2 + i_y4; |
351 | 0 | i_z3 = i_y3 + (i_y5 >> 2); |
352 | 0 | i_z4 = i_y2 - i_y4; |
353 | 0 | i_z5 = (i_y3 >> 2) - i_y5; |
354 | 0 | i_z6 = i_y0 - i_y6; |
355 | 0 | i_z7 = i_y7 - (i_y1 >> 2); |
356 | | |
357 | | /*------------------------------------------------------------------*/ |
358 | | /* x0 = z0 + z7 */ |
359 | | /* x1 = z2 + z5 */ |
360 | | /* x2 = z4 + z3 */ |
361 | | /* x3 = z6 + z1 */ |
362 | | /* x4 = z6 - z1 */ |
363 | | /* x5 = z4 - z3 */ |
364 | | /* x6 = z2 - z5 */ |
365 | | /* x7 = z0 - z7 */ |
366 | | /*------------------------------------------------------------------*/ |
367 | 0 | pi2_tmp_ptr[0] = i_z0 + i_z7; |
368 | 0 | pi2_tmp_ptr[1] = i_z2 + i_z5; |
369 | 0 | pi2_tmp_ptr[2] = i_z4 + i_z3; |
370 | 0 | pi2_tmp_ptr[3] = i_z6 + i_z1; |
371 | 0 | pi2_tmp_ptr[4] = i_z6 - i_z1; |
372 | 0 | pi2_tmp_ptr[5] = i_z4 - i_z3; |
373 | 0 | pi2_tmp_ptr[6] = i_z2 - i_z5; |
374 | 0 | pi2_tmp_ptr[7] = i_z0 - i_z7; |
375 | | |
376 | | /* move to the next row */ |
377 | | // pi2_src_ptr += SUB_BLK_WIDTH_8x8; |
378 | 0 | pi2_tmp_ptr += SUB_BLK_WIDTH_8x8; |
379 | 0 | } |
380 | | /*--------------------------------------------------------------------*/ |
381 | | /* IDCT [ Vertical transformation] and Xij = (xij + 32)>>6 */ |
382 | | /* */ |
383 | | /* Add the prediction and store it back to reconstructed frame buffer */ |
384 | | /* [Prediction buffer itself in this case] */ |
385 | | /*--------------------------------------------------------------------*/ |
386 | |
|
387 | 0 | pi2_tmp_ptr = pi2_tmp; |
388 | 0 | for(i = 0; i < SUB_BLK_WIDTH_8x8; i++) |
389 | 0 | { |
390 | 0 | pi2_pred_ptr = pi2_pred; |
391 | 0 | pi2_out = pi2_out_ptr; |
392 | | /*------------------------------------------------------------------*/ |
393 | | /* y0j = w0j + w4j */ |
394 | | /* y1j = -w3j + w5j -w7j -(w7j >> 1) */ |
395 | | /* y2j = w0j -w4j */ |
396 | | /* y3j = w1j + w7j -w3j -(w3j >> 1) */ |
397 | | /* y4j = ( w2j >> 1 ) -w6j */ |
398 | | /* y5j = -w1j + w7j + w5j + (w5j >> 1) */ |
399 | | /* y6j = w2j + ( w6j >> 1 ) */ |
400 | | /* y7j = w3j + w5j + w1j + (w1j >> 1) */ |
401 | | /*------------------------------------------------------------------*/ |
402 | 0 | i_y0 = pi2_tmp_ptr[0] + pi2_tmp_ptr[32]; |
403 | |
|
404 | 0 | i_y1 = (WORD32) (-pi2_tmp_ptr[24]) + pi2_tmp_ptr[40] - pi2_tmp_ptr[56] - |
405 | 0 | (pi2_tmp_ptr[56] >> 1); |
406 | |
|
407 | 0 | i_y2 = pi2_tmp_ptr[0] - pi2_tmp_ptr[32]; |
408 | 0 | i_y3 = (WORD32) pi2_tmp_ptr[8] + pi2_tmp_ptr[56] - pi2_tmp_ptr[24] - (pi2_tmp_ptr[24] >> 1); |
409 | 0 | i_y4 = (pi2_tmp_ptr[16] >> 1) - pi2_tmp_ptr[48]; |
410 | |
|
411 | 0 | i_y5 = |
412 | 0 | (WORD32) (-pi2_tmp_ptr[8]) + pi2_tmp_ptr[56] + pi2_tmp_ptr[40] + (pi2_tmp_ptr[40] >> 1); |
413 | |
|
414 | 0 | i_y6 = pi2_tmp_ptr[16] + (pi2_tmp_ptr[48] >> 1); |
415 | 0 | i_y7 = (WORD32) pi2_tmp_ptr[24] + pi2_tmp_ptr[40] + pi2_tmp_ptr[8] + (pi2_tmp_ptr[8] >> 1); |
416 | | |
417 | | /*------------------------------------------------------------------*/ |
418 | | /* z0j = y0j + y6j */ |
419 | | /* z1j = y1j + (y7j >> 2) */ |
420 | | /* z2j = y2j + y4j */ |
421 | | /* z3j = y3j + (y5j >> 2) */ |
422 | | /* z4j = y2j -y4j */ |
423 | | /* z5j = (y3j >> 2) -y5j */ |
424 | | /* z6j = y0j -y6j */ |
425 | | /* z7j = y7j -(y1j >> 2) */ |
426 | | /*------------------------------------------------------------------*/ |
427 | 0 | i_z0 = i_y0 + i_y6; |
428 | 0 | i_z1 = i_y1 + (i_y7 >> 2); |
429 | 0 | i_z2 = i_y2 + i_y4; |
430 | 0 | i_z3 = i_y3 + (i_y5 >> 2); |
431 | 0 | i_z4 = i_y2 - i_y4; |
432 | 0 | i_z5 = (i_y3 >> 2) - i_y5; |
433 | 0 | i_z6 = i_y0 - i_y6; |
434 | 0 | i_z7 = i_y7 - (i_y1 >> 2); |
435 | | |
436 | | /*------------------------------------------------------------------*/ |
437 | | /* x0j = z0j + z7j */ |
438 | | /* x1j = z2j + z5j */ |
439 | | /* x2j = z4j + z3j */ |
440 | | /* x3j = z6j + z1j */ |
441 | | /* x4j = z6j -z1j */ |
442 | | /* x5j = z4j -z3j */ |
443 | | /* x6j = z2j -z5j */ |
444 | | /* x7j = z0j -z7j */ |
445 | | /*------------------------------------------------------------------*/ |
446 | 0 | *pi2_out = CLIP_RSD(((i_z0 + i_z7 + 32) >> 6) + (*pi2_pred_ptr)); |
447 | 0 | i4_nnz_H |= !!(*pi2_out); |
448 | | /* Change uc_recBuffer to Point to next element in the same column*/ |
449 | 0 | pi2_pred_ptr += pred_strd; |
450 | 0 | pi2_out += out_strd; |
451 | |
|
452 | 0 | *pi2_out = CLIP_RSD(((i_z2 + i_z5 + 32) >> 6) + (*pi2_pred_ptr)); |
453 | 0 | i4_nnz_H |= !!(*pi2_out); |
454 | 0 | pi2_pred_ptr += pred_strd; |
455 | 0 | pi2_out += out_strd; |
456 | |
|
457 | 0 | *pi2_out = CLIP_RSD(((i_z4 + i_z3 + 32) >> 6) + (*pi2_pred_ptr)); |
458 | 0 | i4_nnz_H |= !!(*pi2_out); |
459 | 0 | pi2_pred_ptr += pred_strd; |
460 | 0 | pi2_out += out_strd; |
461 | |
|
462 | 0 | *pi2_out = CLIP_RSD(((i_z6 + i_z1 + 32) >> 6) + (*pi2_pred_ptr)); |
463 | 0 | i4_nnz_H |= !!(*pi2_out); |
464 | 0 | pi2_pred_ptr += pred_strd; |
465 | 0 | pi2_out += out_strd; |
466 | |
|
467 | 0 | *pi2_out = CLIP_RSD(((i_z6 - i_z1 + 32) >> 6) + (*pi2_pred_ptr)); |
468 | 0 | i4_nnz_L |= !!(*pi2_out); |
469 | 0 | pi2_pred_ptr += pred_strd; |
470 | 0 | pi2_out += out_strd; |
471 | |
|
472 | 0 | *pi2_out = CLIP_RSD(((i_z4 - i_z3 + 32) >> 6) + (*pi2_pred_ptr)); |
473 | 0 | i4_nnz_L |= !!(*pi2_out); |
474 | 0 | pi2_pred_ptr += pred_strd; |
475 | 0 | pi2_out += out_strd; |
476 | |
|
477 | 0 | *pi2_out = CLIP_RSD(((i_z2 - i_z5 + 32) >> 6) + (*pi2_pred_ptr)); |
478 | 0 | i4_nnz_L |= !!(*pi2_out); |
479 | 0 | pi2_pred_ptr += pred_strd; |
480 | 0 | pi2_out += out_strd; |
481 | |
|
482 | 0 | *pi2_out = CLIP_RSD(((i_z0 - i_z7 + 32) >> 6) + (*pi2_pred_ptr)); |
483 | 0 | i4_nnz_L |= !!(*pi2_out); |
484 | |
|
485 | 0 | pi2_tmp_ptr++; |
486 | 0 | pi2_out_ptr++; |
487 | 0 | pi2_pred++; |
488 | 0 | if(i == 3) |
489 | 0 | { |
490 | 0 | i4_nnz = i4_nnz_H | (i4_nnz_L << 4); |
491 | 0 | i4_nnz_L = 0; |
492 | 0 | i4_nnz_H = 0; |
493 | 0 | } |
494 | 0 | } |
495 | 0 | i4_nnz |= (i4_nnz_H << 1) | (i4_nnz_L << 5); |
496 | 0 | return i4_nnz; |
497 | 0 | } |
498 | | /*****************************************************************************/ |
499 | | /* */ |
500 | | /* Function Name : isvcd_iquant_itrans_residual_8x8_dc */ |
501 | | /* */ |
502 | | /* Description : this function computes the resd output from the */ |
503 | | /* IQ+IT */ |
504 | | /* */ |
505 | | /* Inputs : */ |
506 | | /* Globals : none */ |
507 | | /* Processing : */ |
508 | | /* */ |
509 | | /* Outputs : i4_nnz */ |
510 | | /* Returns : none */ |
511 | | /* */ |
512 | | /* Issues : none */ |
513 | | /* */ |
514 | | /* Revision History: */ |
515 | | /* */ |
516 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
517 | | /* 25 11 2021 Kishore creation */ |
518 | | /* */ |
519 | | /*****************************************************************************/ |
520 | | |
521 | | WORD32 isvcd_iquant_itrans_residual_8x8_dc(WORD16 *pi2_src, WORD16 *pi2_pred, WORD16 *pi2_out, |
522 | | WORD32 pred_strd, WORD32 out_strd, |
523 | | const UWORD16 *pu2_iscale_mat, |
524 | | const UWORD16 *pu2_weigh_mat, UWORD32 qp_div, |
525 | | WORD16 *pi2_tmp, WORD32 iq_start_idx, |
526 | | WORD16 *pi2_dc_ld_addr) |
527 | 0 | { |
528 | 0 | WORD32 i4_nnz = 0, i4_nnz_H = 0, i4_nnz_L = 0; |
529 | 0 | WORD16 *pi2_pred_ptr = pi2_pred; |
530 | 0 | WORD16 *pi2_out_ptr = pi2_out; |
531 | 0 | WORD16 i, i_macro; |
532 | 0 | WORD32 q; |
533 | 0 | WORD32 rnd_fact = (qp_div < 6) ? (1 << (5 - qp_div)) : 0; |
534 | 0 | UNUSED(pi2_tmp); |
535 | 0 | UNUSED(iq_start_idx); |
536 | 0 | UNUSED(pi2_dc_ld_addr); |
537 | | /*************************************************************/ |
538 | | /* Dequantization of coefficients. Will be replaced by SIMD */ |
539 | | /* operations on platform. Note : DC coeff is not scaled */ |
540 | | /*************************************************************/ |
541 | 0 | q = pi2_src[0]; |
542 | 0 | INV_QUANT(q, pu2_iscale_mat[0], pu2_weigh_mat[0], qp_div, rnd_fact, 6); |
543 | 0 | i_macro = (q + 32) >> 6; |
544 | | /* Perform Inverse transform */ |
545 | | /*--------------------------------------------------------------------*/ |
546 | | /* IDCT [ Horizontal transformation ] */ |
547 | | /*--------------------------------------------------------------------*/ |
548 | | /*--------------------------------------------------------------------*/ |
549 | | /* IDCT [ Vertical transformation] and Xij = (xij + 32)>>6 */ |
550 | | /* */ |
551 | | /* Add the prediction and store it back to reconstructed frame buffer */ |
552 | | /* [Prediction buffer itself in this case] */ |
553 | | /*--------------------------------------------------------------------*/ |
554 | 0 | for(i = 0; i < SUB_BLK_WIDTH_8x8; i++) |
555 | 0 | { |
556 | 0 | pi2_pred_ptr = pi2_pred; |
557 | 0 | pi2_out = pi2_out_ptr; |
558 | | |
559 | | /* Change uc_recBuffer to Point to next element in the same column*/ |
560 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
561 | 0 | i4_nnz_H |= !!(*pi2_out); |
562 | 0 | pi2_pred_ptr += pred_strd; |
563 | 0 | pi2_out += out_strd; |
564 | |
|
565 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
566 | 0 | i4_nnz_H |= !!(*pi2_out); |
567 | 0 | pi2_pred_ptr += pred_strd; |
568 | 0 | pi2_out += out_strd; |
569 | |
|
570 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
571 | 0 | i4_nnz_H |= !!(*pi2_out); |
572 | 0 | pi2_pred_ptr += pred_strd; |
573 | 0 | pi2_out += out_strd; |
574 | |
|
575 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
576 | 0 | i4_nnz_H |= !!(*pi2_out); |
577 | 0 | pi2_pred_ptr += pred_strd; |
578 | 0 | pi2_out += out_strd; |
579 | |
|
580 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
581 | 0 | i4_nnz_L |= !!(*pi2_out); |
582 | 0 | pi2_pred_ptr += pred_strd; |
583 | 0 | pi2_out += out_strd; |
584 | |
|
585 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
586 | 0 | i4_nnz_L |= !!(*pi2_out); |
587 | 0 | pi2_pred_ptr += pred_strd; |
588 | 0 | pi2_out += out_strd; |
589 | |
|
590 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
591 | 0 | i4_nnz_L |= !!(*pi2_out); |
592 | 0 | pi2_pred_ptr += pred_strd; |
593 | 0 | pi2_out += out_strd; |
594 | |
|
595 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
596 | 0 | i4_nnz_L |= !!(*pi2_out); |
597 | |
|
598 | 0 | pi2_out_ptr++; |
599 | 0 | pi2_pred++; |
600 | 0 | if(i == 3) |
601 | 0 | { |
602 | 0 | i4_nnz = i4_nnz_H | (i4_nnz_L << 4); |
603 | 0 | i4_nnz_L = 0; |
604 | 0 | i4_nnz_H = 0; |
605 | 0 | } |
606 | 0 | } |
607 | 0 | i4_nnz |= (i4_nnz_H << 1) | (i4_nnz_L << 5); |
608 | 0 | return i4_nnz; |
609 | 0 | } |
610 | | /*****************************************************************************/ |
611 | | /* */ |
612 | | /* Function Name : isvcd_iquant_itrans_residual_chroma_4x4 */ |
613 | | /* */ |
614 | | /* Description : this function computes the resd output from the */ |
615 | | /* IQ+IT */ |
616 | | /* */ |
617 | | /* Inputs : */ |
618 | | /* Globals : none */ |
619 | | /* Processing : */ |
620 | | /* */ |
621 | | /* Outputs : i4_nnz */ |
622 | | /* Returns : none */ |
623 | | /* */ |
624 | | /* Issues : none */ |
625 | | /* */ |
626 | | /* Revision History: */ |
627 | | /* */ |
628 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
629 | | /* 25 11 2021 Kishore creation */ |
630 | | /* */ |
631 | | /*****************************************************************************/ |
632 | | |
633 | | WORD32 isvcd_iquant_itrans_residual_chroma_4x4(WORD16 *pi2_src, WORD16 *pi2_pred, WORD16 *pi2_out, |
634 | | WORD32 pred_strd, WORD32 out_strd, |
635 | | const UWORD16 *pu2_iscal_mat, |
636 | | const UWORD16 *pu2_weigh_mat, UWORD32 u4_qp_div_6, |
637 | | WORD16 *pi2_tmp, WORD16 *pi2_dc_src) |
638 | 0 | { |
639 | 0 | WORD32 i4_nnz = 0; |
640 | 0 | WORD16 *pi2_src_ptr = pi2_src; |
641 | 0 | WORD16 *pi2_tmp_ptr = pi2_tmp; |
642 | 0 | WORD16 *pi2_pred_ptr = pi2_pred; |
643 | 0 | WORD16 *pi2_out_ptr = pi2_out; |
644 | 0 | WORD16 x0, x1, x2, x3, i; |
645 | 0 | WORD32 q0, q1, q2, q3; |
646 | 0 | WORD16 i_macro; |
647 | 0 | WORD16 rnd_fact = (u4_qp_div_6 < 4) ? 1 << (3 - u4_qp_div_6) : 0; |
648 | | |
649 | | /* inverse quant */ |
650 | | /*horizontal inverse transform */ |
651 | 0 | for(i = 0; i < SUB_BLK_WIDTH_4x4; i++) |
652 | 0 | { |
653 | 0 | if(i == 0) |
654 | 0 | { |
655 | 0 | q0 = pi2_dc_src[0]; |
656 | 0 | } |
657 | 0 | else |
658 | 0 | { |
659 | 0 | q0 = pi2_src_ptr[0]; |
660 | 0 | INV_QUANT(q0, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, rnd_fact, 4); |
661 | 0 | } |
662 | |
|
663 | 0 | q2 = pi2_src_ptr[2]; |
664 | 0 | INV_QUANT(q2, pu2_iscal_mat[2], pu2_weigh_mat[2], u4_qp_div_6, rnd_fact, 4); |
665 | |
|
666 | 0 | x0 = q0 + q2; |
667 | 0 | x1 = q0 - q2; |
668 | |
|
669 | 0 | q1 = pi2_src_ptr[1]; |
670 | 0 | INV_QUANT(q1, pu2_iscal_mat[1], pu2_weigh_mat[1], u4_qp_div_6, rnd_fact, 4); |
671 | |
|
672 | 0 | q3 = pi2_src_ptr[3]; |
673 | 0 | INV_QUANT(q3, pu2_iscal_mat[3], pu2_weigh_mat[3], u4_qp_div_6, rnd_fact, 4); |
674 | |
|
675 | 0 | x2 = (q1 >> 1) - q3; |
676 | 0 | x3 = q1 + (q3 >> 1); |
677 | |
|
678 | 0 | pi2_tmp_ptr[0] = x0 + x3; |
679 | 0 | pi2_tmp_ptr[1] = x1 + x2; |
680 | 0 | pi2_tmp_ptr[2] = x1 - x2; |
681 | 0 | pi2_tmp_ptr[3] = x0 - x3; |
682 | |
|
683 | 0 | pi2_src_ptr += SUB_BLK_WIDTH_4x4; |
684 | 0 | pi2_tmp_ptr += SUB_BLK_WIDTH_4x4; |
685 | 0 | pu2_iscal_mat += SUB_BLK_WIDTH_4x4; |
686 | 0 | pu2_weigh_mat += SUB_BLK_WIDTH_4x4; |
687 | 0 | } |
688 | | |
689 | | /* vertical inverse transform */ |
690 | 0 | pi2_tmp_ptr = pi2_tmp; |
691 | 0 | for(i = 0; i < SUB_BLK_WIDTH_4x4; i++) |
692 | 0 | { |
693 | 0 | pi2_pred_ptr = pi2_pred; |
694 | 0 | pi2_out = pi2_out_ptr; |
695 | |
|
696 | 0 | x0 = (pi2_tmp_ptr[0] + pi2_tmp_ptr[8]); |
697 | 0 | x1 = (pi2_tmp_ptr[0] - pi2_tmp_ptr[8]); |
698 | 0 | x2 = (pi2_tmp_ptr[4] >> 1) - pi2_tmp_ptr[12]; |
699 | 0 | x3 = pi2_tmp_ptr[4] + (pi2_tmp_ptr[12] >> 1); |
700 | | |
701 | | /* inverse prediction */ |
702 | 0 | i_macro = x0 + x3; |
703 | 0 | i_macro = ((i_macro + 32) >> 6); |
704 | 0 | i_macro = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
705 | 0 | i4_nnz |= !!i_macro; |
706 | 0 | *pi2_out = i_macro; |
707 | 0 | pi2_pred_ptr += pred_strd; |
708 | 0 | pi2_out += out_strd; |
709 | |
|
710 | 0 | i_macro = x1 + x2; |
711 | 0 | i_macro = ((i_macro + 32) >> 6); |
712 | 0 | i_macro = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
713 | 0 | i4_nnz |= !!i_macro; |
714 | 0 | *pi2_out = i_macro; |
715 | 0 | pi2_pred_ptr += pred_strd; |
716 | 0 | pi2_out += out_strd; |
717 | |
|
718 | 0 | i_macro = x1 - x2; |
719 | 0 | i_macro = ((i_macro + 32) >> 6); |
720 | 0 | i_macro = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
721 | 0 | i4_nnz |= !!i_macro; |
722 | 0 | *pi2_out = i_macro; |
723 | 0 | pi2_pred_ptr += pred_strd; |
724 | 0 | pi2_out += out_strd; |
725 | |
|
726 | 0 | i_macro = x0 - x3; |
727 | 0 | i_macro = ((i_macro + 32) >> 6); |
728 | 0 | i_macro = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
729 | 0 | i4_nnz |= !!i_macro; |
730 | 0 | *pi2_out = i_macro; |
731 | |
|
732 | 0 | pi2_tmp_ptr++; |
733 | 0 | pi2_out_ptr += 2; // Interleaved store for output |
734 | 0 | pi2_pred += 2; // Interleaved load for pred buffer |
735 | 0 | } |
736 | 0 | return i4_nnz; |
737 | 0 | } |
738 | | /*****************************************************************************/ |
739 | | /* */ |
740 | | /* Function Name : isvcd_iquant_itrans_residual_chroma_4x4_dc */ |
741 | | /* */ |
742 | | /* Description : this function computes the resd output from the */ |
743 | | /* IQ+IT */ |
744 | | /* */ |
745 | | /* Inputs : */ |
746 | | /* Globals : none */ |
747 | | /* Processing : */ |
748 | | /* */ |
749 | | /* Outputs : i4_nnz */ |
750 | | /* Returns : none */ |
751 | | /* */ |
752 | | /* Issues : none */ |
753 | | /* */ |
754 | | /* Revision History: */ |
755 | | /* */ |
756 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
757 | | /* 25 11 2021 Kishore creation */ |
758 | | /* */ |
759 | | /*****************************************************************************/ |
760 | | |
761 | | WORD32 isvcd_iquant_itrans_residual_chroma_4x4_dc(WORD16 *pi2_src, WORD16 *pi2_pred, |
762 | | WORD16 *pi2_out, WORD32 pred_strd, |
763 | | WORD32 out_strd, const UWORD16 *pu2_iscal_mat, |
764 | | const UWORD16 *pu2_weigh_mat, UWORD32 u4_qp_div_6, |
765 | | WORD16 *pi2_tmp, WORD16 *pi2_dc_src) |
766 | 0 | { |
767 | 0 | WORD32 i4_nnz = 0; |
768 | 0 | WORD16 *pi2_pred_ptr = pi2_pred; |
769 | 0 | WORD16 *pi2_out_ptr = pi2_out; |
770 | 0 | WORD32 q0; |
771 | 0 | WORD16 i_macro, i; |
772 | 0 | UNUSED(pi2_src); |
773 | 0 | UNUSED(pu2_iscal_mat); |
774 | 0 | UNUSED(pu2_weigh_mat); |
775 | 0 | UNUSED(u4_qp_div_6); |
776 | 0 | UNUSED(pi2_tmp); |
777 | |
|
778 | 0 | q0 = pi2_dc_src[0]; // Restoring dc value for intra case3 |
779 | 0 | i_macro = ((q0 + 32) >> 6); |
780 | |
|
781 | 0 | for(i = 0; i < SUB_BLK_WIDTH_4x4; i++) |
782 | 0 | { |
783 | 0 | pi2_pred_ptr = pi2_pred; |
784 | 0 | pi2_out = pi2_out_ptr; |
785 | | |
786 | | /* inverse prediction */ |
787 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
788 | 0 | i4_nnz |= !!(*pi2_out); |
789 | 0 | pi2_pred_ptr += pred_strd; |
790 | 0 | pi2_out += out_strd; |
791 | |
|
792 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
793 | 0 | i4_nnz |= !!(*pi2_out); |
794 | 0 | pi2_pred_ptr += pred_strd; |
795 | 0 | pi2_out += out_strd; |
796 | |
|
797 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
798 | 0 | i4_nnz |= !!(*pi2_out); |
799 | 0 | pi2_pred_ptr += pred_strd; |
800 | 0 | pi2_out += out_strd; |
801 | |
|
802 | 0 | *pi2_out = CLIP_RSD(i_macro + (*pi2_pred_ptr)); |
803 | 0 | i4_nnz |= !!(*pi2_out); |
804 | |
|
805 | 0 | pi2_out_ptr += 2; |
806 | 0 | pi2_pred += 2; |
807 | 0 | } |
808 | 0 | return i4_nnz; |
809 | 0 | } |