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_pred_residual_recon.c
24 *
25 * @brief
26 * Contains definition of functions for svc inverse quantization inverse
27 * transformation and resd comp
28 *
29 * @author
30 * Kishore
31 *
32 * @par List of Functions:
33 * - isvcd_pred_residual_recon_chroma_8x8()
34 * - isvcd_residual_chroma_cb_cr_8x8()
35 * - isvcd_pred_residual_recon_chroma_4x4()
36 * - isvcd_pred_residual_recon_16x16()
37 * - isvcd_pred_residual_recon_4x4()
38 * - isvcd_pred_residual_recon_8x8()
39 * - isvcd_residual_luma_4x4()
40 * - isvcd_residual_luma_8x8()
41 * - isvcd_residual_luma_16x16()
42 *
43 * @remarks
44 * None
45 *
46 *******************************************************************************
47 */
48
49 /*****************************************************************************/
50 /* File Includes */
51 /*****************************************************************************/
52
53 /* User include files */
54 #include "ih264_typedefs.h"
55 #include "ih264_defs.h"
56 #include "ih264_trans_macros.h"
57 #include "ih264_macros.h"
58 #include "ih264_platform_macros.h"
59 #include "ih264_trans_data.h"
60 #include "ih264_size_defs.h"
61 #include "ih264_structs.h"
62 #include "isvcd_pred_residual_recon.h"
63
64 /*****************************************************************************/
65 /* */
66 /* Function Name : isvcd_pred_residual_recon_chroma_8x8 */
67 /* */
68 /* Description : this function computes the recon from */
69 /* the residual and pred buffer */
70 /* Inputs : */
71 /* Globals : none */
72 /* Processing : */
73 /* */
74 /* Outputs : none */
75 /* Returns : nnz */
76 /* */
77 /* Issues : none */
78 /* */
79 /* Revision History: */
80 /* */
81 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
82 /* 25 11 2021 Kishore creation */
83 /* */
84 /*****************************************************************************/
85
isvcd_pred_residual_recon_chroma_8x8(UWORD8 * pu1_pred,WORD16 * pi2_rsd,UWORD8 * pu1_out,WORD32 pred_strd,WORD32 rsd_strd,WORD32 out_strd)86 void isvcd_pred_residual_recon_chroma_8x8(UWORD8 *pu1_pred, WORD16 *pi2_rsd, UWORD8 *pu1_out,
87 WORD32 pred_strd, WORD32 rsd_strd, WORD32 out_strd)
88 {
89 UWORD8 *pu1_pred_ptr = pu1_pred;
90 WORD16 *pi2_rsd_ptr = pi2_rsd;
91 UWORD8 *pu1_out_ptr = pu1_out;
92 WORD16 i, j;
93 WORD16 i_macro;
94
95 for(i = 0; i < 8; i++)
96 {
97 pu1_pred_ptr = pu1_pred;
98 pi2_rsd_ptr = pi2_rsd;
99 pu1_out = pu1_out_ptr;
100
101 for(j = 0; j < 8; j++)
102 {
103 i_macro = *pu1_pred_ptr + *pi2_rsd_ptr;
104 *pu1_out = CLIP_U8(i_macro);
105 pu1_pred_ptr += pred_strd;
106 pi2_rsd_ptr += rsd_strd;
107 pu1_out += out_strd;
108 }
109
110 pu1_out_ptr += 2; // Interleaved store for output
111 pu1_pred += 2; // Interleaved load for pred buffer
112 pi2_rsd += 2;
113 }
114 }
115
116 /*****************************************************************************/
117 /* */
118 /* Function Name : isvcd_residual_chroma_cb_cr_8x8 */
119 /* */
120 /* Description : this function computes the nnz from the resd */
121 /* */
122 /* Inputs : */
123 /* Globals : none */
124 /* Processing : */
125 /* */
126 /* Outputs : none */
127 /* Returns : nnz */
128 /* */
129 /* Issues : none */
130 /* */
131 /* Revision History: */
132 /* */
133 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
134 /* 25 11 2021 Kishore creation */
135 /* */
136 /*****************************************************************************/
137
isvcd_residual_chroma_cb_cr_8x8(WORD16 * pi2_rsd,WORD32 rsd_strd)138 WORD32 isvcd_residual_chroma_cb_cr_8x8(WORD16 *pi2_rsd, WORD32 rsd_strd)
139 {
140 WORD16 *pi2_rsd_ptr_Cb = pi2_rsd;
141 WORD16 *pi2_rsd_ptr_Cr = pi2_rsd + 1;
142 WORD16 i, j;
143 WORD32 i4_nnz = 0, ai4_nnz_Cb[2][2] = {0}, ai4_nnz_Cr[2][2] = {0};
144
145 for(i = 0; i < 8; i++)
146 {
147 pi2_rsd_ptr_Cb = pi2_rsd;
148 pi2_rsd_ptr_Cr = pi2_rsd + 1;
149
150 for(j = 0; j < 8; j++)
151 {
152 ai4_nnz_Cb[j >> 2][i >> 2] |= !!(*pi2_rsd_ptr_Cb);
153 ai4_nnz_Cr[j >> 2][i >> 2] |= !!(*pi2_rsd_ptr_Cr);
154 pi2_rsd_ptr_Cb += rsd_strd;
155 pi2_rsd_ptr_Cr += rsd_strd;
156 }
157 pi2_rsd += 2;
158 }
159 i4_nnz = ai4_nnz_Cr[0][0] | (ai4_nnz_Cr[1][0] << 2);
160 i4_nnz |= (ai4_nnz_Cr[0][1] << 1) | (ai4_nnz_Cr[1][1] << 3);
161 i4_nnz <<= 4;
162 i4_nnz |= ai4_nnz_Cb[0][0] | (ai4_nnz_Cb[1][0] << 2);
163 i4_nnz |= (ai4_nnz_Cb[0][1] << 1) | (ai4_nnz_Cb[1][1] << 3);
164 return i4_nnz;
165 }
166
167 /*****************************************************************************/
168 /* */
169 /* Function Name : isvcd_pred_residual_recon_chroma_4x4 */
170 /* */
171 /* Description : this function computes the recon from */
172 /* the residual and pred buffer */
173 /* Inputs : */
174 /* Globals : none */
175 /* Processing : */
176 /* */
177 /* Outputs : none */
178 /* Returns : none */
179 /* */
180 /* Issues : none */
181 /* */
182 /* Revision History: */
183 /* */
184 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
185 /* 25 11 2021 Kishore creation */
186 /* */
187 /*****************************************************************************/
isvcd_pred_residual_recon_chroma_4x4(UWORD8 * pu1_pred,WORD16 * pi2_rsd,UWORD8 * pu1_out,WORD32 pred_strd,WORD32 rsd_strd,WORD32 out_strd)188 void isvcd_pred_residual_recon_chroma_4x4(UWORD8 *pu1_pred, WORD16 *pi2_rsd, UWORD8 *pu1_out,
189 WORD32 pred_strd, WORD32 rsd_strd, WORD32 out_strd)
190 {
191 UWORD8 *pu1_pred_ptr = pu1_pred;
192 WORD16 *pi2_rsd_ptr = pi2_rsd;
193 UWORD8 *pu1_out_ptr = pu1_out;
194 WORD16 i, j;
195 WORD16 i_macro;
196
197 for(i = 0; i < 4; i++)
198 {
199 pu1_pred_ptr = pu1_pred;
200 pi2_rsd_ptr = pi2_rsd;
201 pu1_out = pu1_out_ptr;
202
203 for(j = 0; j < 4; j++)
204 {
205 i_macro = *pu1_pred_ptr + *pi2_rsd_ptr;
206 *pu1_out = CLIP_U8(i_macro);
207 pu1_pred_ptr += pred_strd;
208 pi2_rsd_ptr += rsd_strd;
209 pu1_out += out_strd;
210 }
211
212 pu1_out_ptr += 2; // Interleaved store for output
213 pu1_pred += 2; // Interleaved load for pred buffer
214 pi2_rsd += 2;
215 }
216 }
217
218 /*****************************************************************************/
219 /* */
220 /* Function Name : isvcd_pred_residual_recon_16x16 */
221 /* */
222 /* Description : this function computes the recon from */
223 /* the residual and pred buffer */
224 /* Inputs : */
225 /* Globals : none */
226 /* Processing : */
227 /* */
228 /* Outputs : none */
229 /* Returns : nnz */
230 /* */
231 /* Issues : none */
232 /* */
233 /* Revision History: */
234 /* */
235 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
236 /* 25 11 2021 Kishore creation */
237 /* */
238 /*****************************************************************************/
239
isvcd_pred_residual_recon_16x16(UWORD8 * pu1_pred,WORD16 * pi2_rsd,UWORD8 * pu1_out,WORD32 pred_strd,WORD32 rsd_strd,WORD32 out_strd)240 WORD32 isvcd_pred_residual_recon_16x16(UWORD8 *pu1_pred, WORD16 *pi2_rsd, UWORD8 *pu1_out,
241 WORD32 pred_strd, WORD32 rsd_strd, WORD32 out_strd)
242 {
243 WORD32 i4_nnz = 0, i4_nnz_blk[4][4] = {0};
244 UWORD8 *pu1_pred_ptr = pu1_pred;
245 WORD16 *pi2_rsd_ptr = pi2_rsd;
246 UWORD8 *pu1_out_ptr = pu1_out;
247 WORD16 i, j;
248 WORD16 i_macro;
249
250 for(i = 0; i < 16; i++)
251 {
252 pu1_pred_ptr = pu1_pred;
253 pi2_rsd_ptr = pi2_rsd;
254 pu1_out = pu1_out_ptr;
255
256 for(j = 0; j < 16; j++)
257 {
258 i_macro = *pi2_rsd_ptr;
259 i4_nnz_blk[j >> 2][i >> 2] |= !!i_macro;
260 i_macro += *pu1_pred_ptr;
261 *pu1_out = CLIP_U8(i_macro);
262 pu1_pred_ptr += pred_strd;
263 pi2_rsd_ptr += rsd_strd;
264 pu1_out += out_strd;
265 }
266
267 pu1_out_ptr++;
268 pi2_rsd++;
269 pu1_pred++;
270 }
271
272 for(i = 0; i < 4; i++)
273 {
274 for(j = 0; j < 4; j++)
275 {
276 i4_nnz |= (i4_nnz_blk[j][i]) << (i + (j << 2));
277 }
278 }
279
280 return i4_nnz;
281 }
282
283 /*****************************************************************************/
284 /* */
285 /* Function Name : isvcd_pred_residual_recon_4x4 */
286 /* */
287 /* Description : this function computes the recon from */
288 /* the residual and pred buffer */
289 /* Inputs : */
290 /* Globals : none */
291 /* Processing : */
292 /* */
293 /* Outputs : none */
294 /* Returns : nnz */
295 /* */
296 /* Issues : none */
297 /* */
298 /* Revision History: */
299 /* */
300 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
301 /* 25 11 2021 Kishore creation */
302 /* */
303 /*****************************************************************************/
304
isvcd_pred_residual_recon_4x4(UWORD8 * pu1_pred,WORD16 * pi2_rsd,UWORD8 * pu1_out,WORD32 pred_strd,WORD32 rsd_strd,WORD32 out_strd)305 WORD32 isvcd_pred_residual_recon_4x4(UWORD8 *pu1_pred, WORD16 *pi2_rsd, UWORD8 *pu1_out,
306 WORD32 pred_strd, WORD32 rsd_strd, WORD32 out_strd)
307 {
308 WORD32 i4_nnz_blk[4][4] = {0};
309 UWORD8 *pu1_pred_ptr = pu1_pred;
310 WORD16 *pi2_rsd_ptr = pi2_rsd;
311 UWORD8 *pu1_out_ptr = pu1_out;
312 WORD16 i, j;
313 WORD16 i_macro;
314
315 for(i = 0; i < 4; i++)
316 {
317 pu1_pred_ptr = pu1_pred;
318 pi2_rsd_ptr = pi2_rsd;
319 pu1_out = pu1_out_ptr;
320
321 for(j = 0; j < 4; j++)
322 {
323 i_macro = *pi2_rsd_ptr;
324 i4_nnz_blk[j >> 2][i >> 2] |= !!i_macro;
325 i_macro += *pu1_pred_ptr;
326 *pu1_out = CLIP_U8(i_macro);
327 pu1_pred_ptr += pred_strd;
328 pi2_rsd_ptr += rsd_strd;
329 pu1_out += out_strd;
330 }
331
332 pu1_out_ptr++;
333 pi2_rsd++;
334 pu1_pred++;
335 }
336
337 return i4_nnz_blk[0][0];
338 }
339
340 /*****************************************************************************/
341 /* */
342 /* Function Name : isvcd_pred_residual_recon_8x8 */
343 /* */
344 /* Description : this function computes the recon from */
345 /* the residual and pred buffer */
346 /* Inputs : */
347 /* Globals : none */
348 /* Processing : */
349 /* */
350 /* Outputs : none */
351 /* Returns : nnz */
352 /* */
353 /* Issues : none */
354 /* */
355 /* Revision History: */
356 /* */
357 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
358 /* 25 11 2021 Kishore creation */
359 /* */
360 /*****************************************************************************/
361
isvcd_pred_residual_recon_8x8(UWORD8 * pu1_pred,WORD16 * pi2_rsd,UWORD8 * pu1_out,WORD32 pred_strd,WORD32 rsd_strd,WORD32 out_strd)362 WORD32 isvcd_pred_residual_recon_8x8(UWORD8 *pu1_pred, WORD16 *pi2_rsd, UWORD8 *pu1_out,
363 WORD32 pred_strd, WORD32 rsd_strd, WORD32 out_strd)
364 {
365 WORD32 i4_nnz = 0, i4_nnz_blk[4][4] = {0};
366 UWORD8 *pu1_pred_ptr = pu1_pred;
367 WORD16 *pi2_rsd_ptr = pi2_rsd;
368 UWORD8 *pu1_out_ptr = pu1_out;
369 WORD16 i, j;
370 WORD16 i_macro;
371
372 for(i = 0; i < 8; i++)
373 {
374 pu1_pred_ptr = pu1_pred;
375 pi2_rsd_ptr = pi2_rsd;
376 pu1_out = pu1_out_ptr;
377
378 for(j = 0; j < 8; j++)
379 {
380 i_macro = *pi2_rsd_ptr;
381 i4_nnz_blk[j >> 2][i >> 2] |= !!i_macro;
382 i_macro += *pu1_pred_ptr;
383 *pu1_out = CLIP_U8(i_macro);
384 pu1_pred_ptr += pred_strd;
385 pi2_rsd_ptr += rsd_strd;
386 pu1_out += out_strd;
387 }
388
389 pu1_out_ptr++;
390 pi2_rsd++;
391 pu1_pred++;
392 }
393
394 i4_nnz = i4_nnz_blk[0][0] | (i4_nnz_blk[1][0] << 4);
395 i4_nnz |= (i4_nnz_blk[0][1] << 1) | (i4_nnz_blk[1][1] << 5);
396
397 return i4_nnz;
398 }
399
400 /*****************************************************************************/
401 /* */
402 /* Function Name : isvcd_residual_luma_4x4 */
403 /* */
404 /* Description : this function computes the nnz from resd */
405 /* */
406 /* Inputs : */
407 /* Globals : none */
408 /* Processing : */
409 /* */
410 /* Outputs : none */
411 /* Returns : nnz */
412 /* */
413 /* Issues : none */
414 /* */
415 /* Revision History: */
416 /* */
417 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
418 /* 25 11 2021 Kishore creation */
419 /* */
420 /*****************************************************************************/
421
isvcd_residual_luma_4x4(WORD16 * pi2_rsd,WORD32 rsd_strd)422 WORD32 isvcd_residual_luma_4x4(WORD16 *pi2_rsd, WORD32 rsd_strd)
423 {
424 WORD32 i4_nnz_blk[4][4] = {0};
425 WORD16 *pi2_rsd_ptr = pi2_rsd;
426 WORD16 i, j;
427 WORD16 i_macro;
428
429 for(i = 0; i < 4; i++)
430 {
431 pi2_rsd_ptr = pi2_rsd;
432
433 for(j = 0; j < 4; j++)
434 {
435 i_macro = *pi2_rsd_ptr;
436 i4_nnz_blk[j >> 2][i >> 2] |= !!i_macro;
437 pi2_rsd_ptr += rsd_strd;
438 }
439 pi2_rsd++;
440 }
441 return i4_nnz_blk[0][0];
442 }
443
444 /*****************************************************************************/
445 /* */
446 /* Function Name : isvcd_residual_luma_8x8 */
447 /* */
448 /* Description : this function computes the nnz from resd */
449 /* */
450 /* Inputs : */
451 /* Globals : none */
452 /* Processing : */
453 /* */
454 /* Outputs : none */
455 /* Returns : nnz */
456 /* */
457 /* Issues : none */
458 /* */
459 /* Revision History: */
460 /* */
461 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
462 /* 25 11 2021 Kishore creation */
463 /* */
464 /*****************************************************************************/
465
isvcd_residual_luma_8x8(WORD16 * pi2_rsd,WORD32 rsd_strd)466 WORD32 isvcd_residual_luma_8x8(WORD16 *pi2_rsd, WORD32 rsd_strd)
467 {
468 WORD32 i4_nnz = 0, i4_nnz_blk[4][4] = {0};
469 WORD16 *pi2_rsd_ptr = pi2_rsd;
470 WORD16 i, j;
471 WORD16 i_macro;
472
473 for(i = 0; i < 8; i++)
474 {
475 pi2_rsd_ptr = pi2_rsd;
476
477 for(j = 0; j < 8; j++)
478 {
479 i_macro = *pi2_rsd_ptr;
480 i4_nnz_blk[j >> 2][i >> 2] |= !!i_macro;
481 pi2_rsd_ptr += rsd_strd;
482 }
483 pi2_rsd++;
484 }
485
486 i4_nnz = i4_nnz_blk[0][0] | (i4_nnz_blk[1][0] << 4);
487 i4_nnz |= (i4_nnz_blk[0][1] << 1) | (i4_nnz_blk[1][1] << 5);
488 return i4_nnz;
489 }
490
491 /*****************************************************************************/
492 /* */
493 /* Function Name : isvcd_residual_luma_16x16 */
494 /* */
495 /* Description : this function computes the nnz from resd */
496 /* */
497 /* Inputs : */
498 /* Globals : none */
499 /* Processing : */
500 /* */
501 /* Outputs : none */
502 /* Returns : nnz */
503 /* */
504 /* Issues : none */
505 /* */
506 /* Revision History: */
507 /* */
508 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
509 /* 25 11 2021 Kishore creation */
510 /* */
511 /*****************************************************************************/
512
isvcd_residual_luma_16x16(WORD16 * pi2_rsd,WORD32 rsd_strd)513 WORD32 isvcd_residual_luma_16x16(WORD16 *pi2_rsd, WORD32 rsd_strd)
514 {
515 WORD32 i4_nnz = 0, i4_nnz_blk[4][4] = {0};
516 WORD16 *pi2_rsd_ptr = pi2_rsd;
517 WORD16 i, j;
518 WORD16 i_macro;
519
520 for(i = 0; i < 16; i++)
521 {
522 pi2_rsd_ptr = pi2_rsd;
523
524 for(j = 0; j < 16; j++)
525 {
526 i_macro = *pi2_rsd_ptr;
527 i4_nnz_blk[j >> 2][i >> 2] |= !!i_macro;
528 pi2_rsd_ptr += rsd_strd;
529 }
530 pi2_rsd++;
531 }
532
533 for(i = 0; i < 4; i++)
534 {
535 for(j = 0; j < 4; j++)
536 {
537 i4_nnz |= (i4_nnz_blk[j][i]) << (i + (j << 2));
538 }
539 }
540 return i4_nnz;
541 }
542