1 /******************************************************************************
2  *
3  * Copyright (C) 2015 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 ih264d_process_intra_mb.c
23  *
24  * \brief
25  *    Contains routines that decode a I slice type
26  *
27  * Detailed_description
28  *
29  * \date
30  *    07/07/2003
31  *
32  * \author  NS
33  **************************************************************************
34  */
35 
36 #include <string.h>
37 #include "ih264d_bitstrm.h"
38 #include "ih264d_defs.h"
39 #include "ih264d_debug.h"
40 #include "ih264d_tables.h"
41 #include "ih264d_structs.h"
42 #include "ih264d_defs.h"
43 #include "ih264d_parse_cavlc.h"
44 #include "ih264d_mb_utils.h"
45 #include "ih264d_parse_slice.h"
46 #include "ih264d_process_intra_mb.h"
47 #include "ih264d_error_handler.h"
48 #include "ih264d_quant_scaling.h"
49 #include "ih264d_tables.h"
50 
51 /*!
52  **************************************************************************
53  * \if Function name : ih264d_itrans_recon_luma_dc \endif
54  *
55  * \brief
56  *    This function does InvTransform, scaling and reconstruction of Luma DC.
57  *
58  * \return
59  *    0 on Success and Error code otherwise
60  **************************************************************************
61  */
ih264d_itrans_recon_luma_dc(dec_struct_t * ps_dec,WORD16 * pi2_src,WORD16 * pi2_coeff_block,const UWORD16 * pu2_weigh_mat)62 void ih264d_itrans_recon_luma_dc(dec_struct_t *ps_dec,
63                                  WORD16* pi2_src,
64                                  WORD16* pi2_coeff_block,
65                                  const UWORD16 *pu2_weigh_mat)
66 {
67     WORD32 i;
68     WORD16 pi2_out[16];
69     WORD32 pi4_tmp[16];
70     WORD16 *pi2_out_ptr = &pi2_out[0];
71     PROFILE_DISABLE_IQ_IT_RECON_RETURN()
72     ps_dec->pf_ihadamard_scaling_4x4(pi2_src, pi2_out,
73                                      ps_dec->pu2_quant_scale_y, pu2_weigh_mat,
74                                      ps_dec->u1_qp_y_div6, pi4_tmp);
75     for(i = 0; i < 4; i++)
76     {
77         pi2_coeff_block[0] = pi2_out_ptr[0];
78         pi2_coeff_block[4 * 16] = pi2_out_ptr[4];
79         pi2_coeff_block[8 * 16] = pi2_out_ptr[8];
80         pi2_coeff_block[12 * 16] = pi2_out_ptr[12];
81 
82         pi2_out_ptr++; /* Point to next column */
83         pi2_coeff_block += 16;
84     }
85 }
86 /*!
87  **************************************************************************
88  * \if Function name : ih264d_read_intra_pred_modes \endif
89  *
90  * \brief
91  *    Reads the intra pred mode related values of I4x4 MB from bitstream.
92  *
93  *    This function will read the prev intra pred mode flags and
94  *    stores it in pu1_prev_intra4x4_pred_mode_flag. If the u4_flag
95  *    indicates that most probable mode is not intra pred mode, then
96  *    the rem_intra4x4_pred_mode is read and stored in
97  *    pu1_rem_intra4x4_pred_mode array.
98  *
99  *
100  * \return
101  *    0 on success and Error code otherwise
102  *
103  **************************************************************************
104  */
ih264d_read_intra_pred_modes(dec_struct_t * ps_dec,UWORD8 * pu1_prev_intra4x4_pred_mode_flag,UWORD8 * pu1_rem_intra4x4_pred_mode,UWORD32 u4_trans_form8x8)105 WORD32 ih264d_read_intra_pred_modes(dec_struct_t * ps_dec,
106                                     UWORD8 * pu1_prev_intra4x4_pred_mode_flag,
107                                     UWORD8 * pu1_rem_intra4x4_pred_mode,
108                                     UWORD32 u4_trans_form8x8)
109 {
110     WORD32 i4x4_luma_blk_idx = 0, i8x8_luma_blk_idx = 0;
111 
112     dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
113 
114     if(!u4_trans_form8x8)
115     {
116         for(i4x4_luma_blk_idx = 0; i4x4_luma_blk_idx < 16; ++i4x4_luma_blk_idx)
117         {
118             UWORD32 u4_temp;
119             SWITCHOFFTRACE;
120 
121             GETBIT(u4_temp, ps_bitstrm->u4_ofst, ps_bitstrm->pu4_buffer);
122             *pu1_prev_intra4x4_pred_mode_flag = (UWORD8)u4_temp;
123             if(!(*pu1_prev_intra4x4_pred_mode_flag))
124             {
125                 GETBITS(u4_temp, ps_bitstrm->u4_ofst, ps_bitstrm->pu4_buffer, 3);
126 
127                 *(pu1_rem_intra4x4_pred_mode) = (UWORD8)u4_temp;
128             }
129 
130             pu1_prev_intra4x4_pred_mode_flag++;
131             pu1_rem_intra4x4_pred_mode++;
132         }
133     }
134     else
135     {
136         /**********************************************************************/
137         /* prev_intra4x4_pred_modes to be interpreted as                      */
138         /* prev_intra8x8_pred_modes in case of transform 8x8                  */
139         /**********************************************************************/
140         for(i8x8_luma_blk_idx = 0; i8x8_luma_blk_idx < 4; i8x8_luma_blk_idx++)
141         {
142             UWORD32 u4_temp;
143             GETBIT(u4_temp, ps_bitstrm->u4_ofst, ps_bitstrm->pu4_buffer);
144             *pu1_prev_intra4x4_pred_mode_flag = (UWORD8)u4_temp;
145             if(!(*pu1_prev_intra4x4_pred_mode_flag))
146             {
147                 GETBITS(u4_temp, ps_bitstrm->u4_ofst, ps_bitstrm->pu4_buffer, 3);
148 
149                 (*pu1_rem_intra4x4_pred_mode) = (UWORD8)u4_temp;
150             }
151             pu1_prev_intra4x4_pred_mode_flag++;
152             pu1_rem_intra4x4_pred_mode++;
153         }
154     }
155     return (0);
156 }
ih264d_unpack_coeff4x4_4x4blk(dec_struct_t * ps_dec,WORD16 * pi2_out_coeff_data,UWORD8 * pu1_inv_scan)157 WORD32 ih264d_unpack_coeff4x4_4x4blk(dec_struct_t * ps_dec,
158                                    WORD16 *pi2_out_coeff_data,
159                                    UWORD8 *pu1_inv_scan)
160 {
161     tu_sblk4x4_coeff_data_t *ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_proc_tu_coeff_data;
162     UWORD16 u2_sig_coeff_map = ps_tu_4x4->u2_sig_coeff_map;
163     WORD32 idx = 0;
164     WORD16 *pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
165     WORD32 dc_only_flag = 0;
166     WORD32 num_coeff = 0;
167 
168     PROFILE_DISABLE_UNPACK_LUMA()
169     while(u2_sig_coeff_map)
170     {
171         idx = CLZ(u2_sig_coeff_map);
172 
173         idx = 31 - idx;
174         RESET_BIT(u2_sig_coeff_map,idx);
175 
176         idx = pu1_inv_scan[idx];
177         pi2_out_coeff_data[idx] = *pi2_coeff_data++;
178         num_coeff++;
179     }
180 
181     if((num_coeff == 1) && (idx == 0))
182     {
183         dc_only_flag = 1;
184     }
185 
186     {
187         WORD32 offset;
188         offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
189         offset = ALIGN4(offset);
190         ps_dec->pv_proc_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_proc_tu_coeff_data + offset);
191     }
192 
193     return dc_only_flag;
194 }
195 
ih264d_unpack_coeff4x4_8x8blk(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD16 ui2_luma_csbp,WORD16 * pi2_out_coeff_data)196 UWORD32 ih264d_unpack_coeff4x4_8x8blk(dec_struct_t * ps_dec,
197                                    dec_mb_info_t * ps_cur_mb_info,
198                                    UWORD16 ui2_luma_csbp,
199                                    WORD16 *pi2_out_coeff_data)
200 {
201     UWORD8 *pu1_inv_scan;
202     UWORD8 u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
203     UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld;
204     UWORD32 u4_luma_dc_only_csbp = 0;
205     WORD32 dc_only_flag = 0;
206 
207     PROFILE_DISABLE_UNPACK_LUMA()
208     if(u1_field_coding_flag || u1_mb_field_decoding_flag)
209     {
210         pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_fld;
211     }
212     else
213     {
214         pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
215     }
216 
217     // sub 0
218     if(ui2_luma_csbp & 0x1)
219     {
220         memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
221         dc_only_flag = ih264d_unpack_coeff4x4_4x4blk(ps_dec,
222                                       pi2_out_coeff_data,
223                                       pu1_inv_scan);
224 
225         INSERT_BIT(u4_luma_dc_only_csbp, 0, dc_only_flag);
226     }
227 
228     pi2_out_coeff_data += 16;
229     // sub 1
230     if(ui2_luma_csbp & 0x2)
231     {
232         memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
233         dc_only_flag = ih264d_unpack_coeff4x4_4x4blk(ps_dec,
234                                       pi2_out_coeff_data,
235                                       pu1_inv_scan);
236         INSERT_BIT(u4_luma_dc_only_csbp, 1, dc_only_flag);
237     }
238 
239     pi2_out_coeff_data += 16 + 32;
240     // sub 2
241     if(ui2_luma_csbp & 0x10)
242     {
243         memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
244         dc_only_flag = ih264d_unpack_coeff4x4_4x4blk(ps_dec,
245                                       pi2_out_coeff_data,
246                                       pu1_inv_scan);
247         INSERT_BIT(u4_luma_dc_only_csbp, 4, dc_only_flag);
248     }
249 
250     pi2_out_coeff_data += 16;
251     // sub 3
252     if(ui2_luma_csbp & 0x20)
253     {
254         memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
255         dc_only_flag = ih264d_unpack_coeff4x4_4x4blk(ps_dec,
256                                       pi2_out_coeff_data,
257                                       pu1_inv_scan);
258         INSERT_BIT(u4_luma_dc_only_csbp, 5, dc_only_flag);
259     }
260     return u4_luma_dc_only_csbp;
261 }
ih264d_unpack_coeff8x8_8x8blk_cavlc(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD16 ui2_luma_csbp,WORD16 * pi2_out_coeff_data)262 WORD32 ih264d_unpack_coeff8x8_8x8blk_cavlc(dec_struct_t * ps_dec,
263                                             dec_mb_info_t * ps_cur_mb_info,
264                                             UWORD16 ui2_luma_csbp,
265                                             WORD16 *pi2_out_coeff_data)
266 {
267     UWORD8 *pu1_inv_scan;
268     UWORD8 u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
269     UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld;
270     WORD32 dc_only_flag = 0;
271 
272     PROFILE_DISABLE_UNPACK_LUMA()
273     if(ui2_luma_csbp & 0x33)
274     {
275         memset(pi2_out_coeff_data,0,64*sizeof(WORD16));
276     }
277 
278     if(!u1_mb_field_decoding_flag)
279     {
280         pu1_inv_scan =
281                         (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[0];
282     }
283     else
284     {
285         pu1_inv_scan =
286                         (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[0];
287     }
288     // sub 0
289     if(ui2_luma_csbp & 0x1)
290     {
291         dc_only_flag = ih264d_unpack_coeff4x4_4x4blk(ps_dec,
292                                       pi2_out_coeff_data,
293                                       pu1_inv_scan);
294     }
295 
296     if(!u1_mb_field_decoding_flag)
297     {
298         pu1_inv_scan =
299                         (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[1];
300     }
301     else
302     {
303         pu1_inv_scan =
304                         (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[1];
305     }
306     // sub 1
307     if(ui2_luma_csbp & 0x2)
308     {
309         dc_only_flag = 0;
310         ih264d_unpack_coeff4x4_4x4blk(ps_dec,
311                                       pi2_out_coeff_data,
312                                       pu1_inv_scan);
313     }
314 
315     if(!u1_mb_field_decoding_flag)
316     {
317         pu1_inv_scan =
318                         (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[2];
319     }
320     else
321     {
322         pu1_inv_scan =
323                         (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[2];
324     }
325     // sub 2
326     if(ui2_luma_csbp & 0x10)
327     {
328         dc_only_flag = 0;
329         ih264d_unpack_coeff4x4_4x4blk(ps_dec,
330                                       pi2_out_coeff_data,
331                                       pu1_inv_scan);
332     }
333 
334     if(!u1_mb_field_decoding_flag)
335     {
336         pu1_inv_scan =
337                         (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[3];
338     }
339     else
340     {
341         pu1_inv_scan =
342                         (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[3];
343     }
344     // sub 3
345     if(ui2_luma_csbp & 0x20)
346     {
347         dc_only_flag = 0;
348         ih264d_unpack_coeff4x4_4x4blk(ps_dec,
349                                       pi2_out_coeff_data,
350                                       pu1_inv_scan);
351     }
352     return dc_only_flag;
353 }
ih264d_unpack_coeff4x4_8x8blk_chroma(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD16 ui2_chroma_csbp,WORD16 * pi2_out_coeff_data)354 void ih264d_unpack_coeff4x4_8x8blk_chroma(dec_struct_t * ps_dec,
355                                           dec_mb_info_t * ps_cur_mb_info,
356                                           UWORD16 ui2_chroma_csbp,
357                                           WORD16 *pi2_out_coeff_data)
358 {
359     UWORD8 *pu1_inv_scan;
360     UWORD8 u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
361     UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld;
362 
363     PROFILE_DISABLE_UNPACK_CHROMA()
364     if(u1_field_coding_flag || u1_mb_field_decoding_flag)
365     {
366         pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_fld;
367     }
368     else
369     {
370         pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
371     }
372 
373     if(ui2_chroma_csbp & 0x1)
374     {
375         memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
376         ih264d_unpack_coeff4x4_4x4blk(ps_dec,
377                                       pi2_out_coeff_data,
378                                       pu1_inv_scan);
379     }
380     pi2_out_coeff_data += 16;
381     if(ui2_chroma_csbp & 0x2)
382     {
383         memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
384         ih264d_unpack_coeff4x4_4x4blk(ps_dec,
385                                       pi2_out_coeff_data,
386                                       pu1_inv_scan);
387     }
388 
389     pi2_out_coeff_data += 16;
390     if(ui2_chroma_csbp & 0x4)
391     {
392         memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
393         ih264d_unpack_coeff4x4_4x4blk(ps_dec,
394                                       pi2_out_coeff_data,
395                                       pu1_inv_scan);
396     }
397 
398     pi2_out_coeff_data += 16;
399     if(ui2_chroma_csbp & 0x8)
400     {
401         memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
402         ih264d_unpack_coeff4x4_4x4blk(ps_dec,
403                                       pi2_out_coeff_data,
404                                       pu1_inv_scan);
405     }
406 }
ih264d_unpack_luma_coeff4x4_mb(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 intra_flag)407 UWORD32 ih264d_unpack_luma_coeff4x4_mb(dec_struct_t * ps_dec,
408                                     dec_mb_info_t * ps_cur_mb_info,
409                                     UWORD8 intra_flag)
410 {
411     UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
412     UWORD16 ui2_luma_csbp = ps_cur_mb_info->u2_luma_csbp;
413     UWORD8 *pu1_inv_scan = ps_dec->pu1_inv_scan;
414     WORD16 *pi2_coeff_data = ps_dec->pi2_coeff_data;
415 
416     PROFILE_DISABLE_UNPACK_LUMA()
417     if(!ps_cur_mb_info->u1_tran_form8x8)
418     {
419         UWORD32 u4_luma_dc_only_csbp = 0;
420         UWORD32 u4_temp = 0;
421         WORD16* pi2_dc_val = NULL;
422         /*
423          * Reserve the pointer to dc vals. The dc vals will be copied
424          * after unpacking of ac vals since memset to 0 inside.
425          */
426         if(intra_flag && (u1_mb_type != I_4x4_MB))
427         {
428             if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0))
429             {
430                 pi2_dc_val = (WORD16 *)ps_dec->pv_proc_tu_coeff_data;
431 
432                 ps_dec->pv_proc_tu_coeff_data = (void *)(pi2_dc_val + 16);
433             }
434         }
435 
436         if(ui2_luma_csbp)
437         {
438             pi2_coeff_data = ps_dec->pi2_coeff_data;
439             u4_temp = ih264d_unpack_coeff4x4_8x8blk(ps_dec,
440                                           ps_cur_mb_info,
441                                           ui2_luma_csbp,
442                                           pi2_coeff_data);
443             u4_luma_dc_only_csbp = u4_temp;
444 
445             pi2_coeff_data += 32;
446 
447             ui2_luma_csbp = ui2_luma_csbp >> 2;
448             u4_temp = ih264d_unpack_coeff4x4_8x8blk(ps_dec,
449                                           ps_cur_mb_info,
450                                           ui2_luma_csbp,
451                                           pi2_coeff_data);
452 
453             u4_luma_dc_only_csbp |= (u4_temp << 2);
454 
455             pi2_coeff_data += 32 + 64;
456 
457             ui2_luma_csbp = ui2_luma_csbp >> 6;
458             u4_temp = ih264d_unpack_coeff4x4_8x8blk(ps_dec,
459                                           ps_cur_mb_info,
460                                           ui2_luma_csbp,
461                                           pi2_coeff_data);
462 
463             u4_luma_dc_only_csbp |= (u4_temp << 8);
464 
465             pi2_coeff_data += 32;
466 
467             ui2_luma_csbp = ui2_luma_csbp >> 2;
468             u4_temp = ih264d_unpack_coeff4x4_8x8blk(ps_dec,
469                                           ps_cur_mb_info,
470                                           ui2_luma_csbp,
471                                           pi2_coeff_data);
472             u4_luma_dc_only_csbp |= (u4_temp << 10);
473         }
474 
475         if(pi2_dc_val != NULL)
476         {
477             WORD32 i;
478             pi2_coeff_data = ps_dec->pi2_coeff_data;
479             for(i = 0; i < 4; i++)
480             {
481                 pi2_coeff_data[0] = pi2_dc_val[0];
482                 pi2_coeff_data[4 * 16] = pi2_dc_val[4];
483                 pi2_coeff_data[8 * 16] = pi2_dc_val[8];
484                 pi2_coeff_data[12 * 16] = pi2_dc_val[12];
485 
486                 pi2_dc_val++; /* Point to next column */
487                 pi2_coeff_data += 16;
488             }
489             u4_luma_dc_only_csbp = ps_cur_mb_info->u2_luma_csbp ^ 0xFFFF;
490         }
491         return u4_luma_dc_only_csbp;
492     }
493     else
494     {
495         UWORD32 u4_luma_dc_only_cbp = 0;
496         WORD32 dc_only_flag;
497         if(ui2_luma_csbp)
498         {
499             pi2_coeff_data = ps_dec->pi2_coeff_data;
500             dc_only_flag = ih264d_unpack_coeff8x8_8x8blk_cavlc(ps_dec,
501                                           ps_cur_mb_info,
502                                           ui2_luma_csbp,
503                                           pi2_coeff_data);
504             INSERT_BIT(u4_luma_dc_only_cbp, 0, dc_only_flag);
505 
506             pi2_coeff_data += 64;
507 
508             ui2_luma_csbp = ui2_luma_csbp >> 2;
509             dc_only_flag = ih264d_unpack_coeff8x8_8x8blk_cavlc(ps_dec,
510                                           ps_cur_mb_info,
511                                           ui2_luma_csbp,
512                                           pi2_coeff_data);
513 
514             INSERT_BIT(u4_luma_dc_only_cbp, 1, dc_only_flag);
515 
516             pi2_coeff_data += 64;
517 
518             ui2_luma_csbp = ui2_luma_csbp >> 6;
519             dc_only_flag = ih264d_unpack_coeff8x8_8x8blk_cavlc(ps_dec,
520                                           ps_cur_mb_info,
521                                           ui2_luma_csbp,
522                                           pi2_coeff_data);
523 
524             INSERT_BIT(u4_luma_dc_only_cbp, 2, dc_only_flag);
525 
526             pi2_coeff_data += 64;
527             ui2_luma_csbp = ui2_luma_csbp >> 2;
528             dc_only_flag = ih264d_unpack_coeff8x8_8x8blk_cavlc(ps_dec,
529                                           ps_cur_mb_info,
530                                           ui2_luma_csbp,
531                                           pi2_coeff_data);
532             INSERT_BIT(u4_luma_dc_only_cbp, 3, dc_only_flag);
533         }
534         return u4_luma_dc_only_cbp;
535     }
536 
537 }
538 
ih264d_unpack_chroma_coeff4x4_mb(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info)539 void ih264d_unpack_chroma_coeff4x4_mb(dec_struct_t * ps_dec,
540                                       dec_mb_info_t * ps_cur_mb_info)
541 {
542     UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
543     UWORD16 ui2_chroma_csbp = ps_cur_mb_info->u2_chroma_csbp;
544     UWORD8 *pu1_inv_scan = ps_dec->pu1_inv_scan;
545     WORD16 *pi2_coeff_data = ps_dec->pi2_coeff_data;
546     WORD32 i;
547     WORD16 *pi2_dc_val_u = NULL;
548     WORD16 *pi2_dc_val_v = NULL;
549 
550     PROFILE_DISABLE_UNPACK_CHROMA()
551     if((ps_cur_mb_info->u1_cbp >> 4) == CBPC_ALLZERO)
552         return;
553 
554     /*
555      * Reserve the pointers to dc vals. The dc vals will be copied
556      * after unpacking of ac vals since memset to 0 inside.
557      */
558     if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag,1))
559     {
560         pi2_dc_val_u = (WORD16 *)ps_dec->pv_proc_tu_coeff_data;
561 
562         ps_dec->pv_proc_tu_coeff_data = (void *)(pi2_dc_val_u + 4);
563     }
564     if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag,2))
565     {
566         pi2_dc_val_v = (WORD16 *)ps_dec->pv_proc_tu_coeff_data;
567 
568         ps_dec->pv_proc_tu_coeff_data = (void *)(pi2_dc_val_v + 4);
569     }
570 
571     if((ps_cur_mb_info->u1_cbp >> 4) == CBPC_NONZERO)
572     {
573         pi2_coeff_data = ps_dec->pi2_coeff_data;
574         ih264d_unpack_coeff4x4_8x8blk_chroma(ps_dec,
575                                              ps_cur_mb_info,
576                                              ui2_chroma_csbp,
577                                              pi2_coeff_data);
578 
579         pi2_coeff_data += 64;
580         ui2_chroma_csbp = ui2_chroma_csbp >> 4;
581         ih264d_unpack_coeff4x4_8x8blk_chroma(ps_dec,
582                                              ps_cur_mb_info,
583                                              ui2_chroma_csbp,
584                                              pi2_coeff_data);
585 
586     }
587 
588     pi2_coeff_data = ps_dec->pi2_coeff_data;
589     if(pi2_dc_val_u != NULL)
590     {
591         pi2_coeff_data[0] = *pi2_dc_val_u++;
592         pi2_coeff_data[1 * 16] = *pi2_dc_val_u++;
593         pi2_coeff_data[2 * 16] = *pi2_dc_val_u++;
594         pi2_coeff_data[3 * 16] = *pi2_dc_val_u++;
595     }
596     else
597     {
598         pi2_coeff_data[0] = 0;
599         pi2_coeff_data[1 * 16] = 0;
600         pi2_coeff_data[2 * 16] = 0;
601         pi2_coeff_data[3 * 16] = 0;
602     }
603     pi2_coeff_data += 64;
604     if(pi2_dc_val_v != NULL)
605     {
606         pi2_coeff_data[0] = *pi2_dc_val_v++;
607         pi2_coeff_data[1 * 16] = *pi2_dc_val_v++;
608         pi2_coeff_data[2 * 16] = *pi2_dc_val_v++;
609         pi2_coeff_data[3 * 16] = *pi2_dc_val_v++;
610     }
611     else
612     {
613         pi2_coeff_data[0] = 0;
614         pi2_coeff_data[1 * 16] = 0;
615         pi2_coeff_data[2 * 16] = 0;
616         pi2_coeff_data[3 * 16] = 0;
617     }
618 }
ih264d_unpack_luma_coeff8x8_mb(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info)619 UWORD32 ih264d_unpack_luma_coeff8x8_mb(dec_struct_t * ps_dec,
620                                     dec_mb_info_t * ps_cur_mb_info)
621 {
622     WORD32 blk_8x8_cnt;
623     WORD16 *pi2_out_coeff_data = ps_dec->pi2_coeff_data;
624     UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld;
625     UWORD8 *pu1_inv_scan;
626     UWORD32 u4_luma_dc_only_cbp = 0;
627 
628     PROFILE_DISABLE_UNPACK_LUMA()
629     if(!u1_field_coding_flag)
630     {
631         /*******************************************************************/
632         /* initializing inverse scan  matrices                             */
633         /*******************************************************************/
634         pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_prog8x8_cabac;
635     }
636     else
637     {
638         /*******************************************************************/
639         /* initializing inverse scan  matrices                             */
640         /*******************************************************************/
641         pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_int8x8_cabac;
642     }
643 
644     for(blk_8x8_cnt = 0; blk_8x8_cnt < 4; blk_8x8_cnt++)
645     {
646         if(CHECKBIT(ps_cur_mb_info->u1_cbp, blk_8x8_cnt))
647         {
648             tu_blk8x8_coeff_data_t *ps_tu_8x8 = (tu_blk8x8_coeff_data_t *)ps_dec->pv_proc_tu_coeff_data;
649             UWORD32 u4_sig_coeff_map;
650             WORD32 idx = 0;
651             WORD16 *pi2_coeff_data = &ps_tu_8x8->ai2_level[0];
652             WORD32 num_coeff = 0;
653 
654             /* memset 64 coefficient to zero */
655             memset(pi2_out_coeff_data,0,64*sizeof(WORD16));
656 
657             u4_sig_coeff_map = ps_tu_8x8->au4_sig_coeff_map[1];
658 
659             while(u4_sig_coeff_map)
660             {
661                 idx = CLZ(u4_sig_coeff_map);
662 
663                 idx = 31 - idx;
664                 RESET_BIT(u4_sig_coeff_map,idx);
665 
666                 idx = pu1_inv_scan[idx + 32];
667                 pi2_out_coeff_data[idx] = *pi2_coeff_data++;
668                 num_coeff++;
669             }
670 
671             u4_sig_coeff_map = ps_tu_8x8->au4_sig_coeff_map[0];
672             while(u4_sig_coeff_map)
673             {
674                 idx = CLZ(u4_sig_coeff_map);
675 
676                 idx = 31 - idx;
677                 RESET_BIT(u4_sig_coeff_map,idx);
678 
679                 idx = pu1_inv_scan[idx];
680                 pi2_out_coeff_data[idx] = *pi2_coeff_data++;
681                 num_coeff++;
682             }
683 
684             if((num_coeff == 1) && (idx == 0))
685             {
686                 SET_BIT(u4_luma_dc_only_cbp,blk_8x8_cnt);
687             }
688 
689 
690             {
691                 WORD32 offset;
692                 offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_8x8;
693                 offset = ALIGN4(offset);
694                 ps_dec->pv_proc_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_proc_tu_coeff_data + offset);
695             }
696         }
697         pi2_out_coeff_data += 64;
698     }
699 
700     return u4_luma_dc_only_cbp;
701 }
702 /*!
703  **************************************************************************
704  * \if Function name : ih264d_process_intra_mb \endif
705  *
706  * \brief
707  *    This function decodes an I MB. Intraprediction is carried out followed
708  *    by InvTramsform. Both IntraPrediction and Reconstrucion are carried out
709  *    row buffer itself.
710  *
711  *
712  * \return
713  *    0 on Success and Error code otherwise
714  **************************************************************************
715  */
ih264d_process_intra_mb(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_mb_num)716 WORD32 ih264d_process_intra_mb(dec_struct_t * ps_dec,
717                                dec_mb_info_t * ps_cur_mb_info,
718                                UWORD8 u1_mb_num)
719 {
720     UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
721     UWORD8 uc_temp = ps_cur_mb_info->u1_mb_ngbr_availablity;
722     UWORD8 u1_top_available = BOOLEAN(uc_temp & TOP_MB_AVAILABLE_MASK);
723     UWORD8 u1_left_available = BOOLEAN(uc_temp & LEFT_MB_AVAILABLE_MASK);
724     UWORD8 u1_use_top_right_mb = BOOLEAN(uc_temp & TOP_RIGHT_MB_AVAILABLE_MASK);
725     UWORD8 u1_use_top_left_mb = BOOLEAN(uc_temp & TOP_LEFT_MB_AVAILABLE_MASK);
726     UWORD8 uc_useTopMB = u1_top_available;
727     UWORD16 u2_use_left_mb = u1_left_available;
728     UWORD16 u2_use_left_mb_pack;
729     UWORD8 *pu1_luma_pred_buffer;
730     /* CHANGED CODE */
731     UWORD8 *pu1_luma_rec_buffer;
732     UWORD8 *puc_top;
733 
734     mb_neigbour_params_t *ps_left_mb;
735     mb_neigbour_params_t *ps_top_mb;
736     mb_neigbour_params_t *ps_top_right_mb;
737     mb_neigbour_params_t *ps_curmb;
738 
739     UWORD16 u2_mbx = ps_cur_mb_info->u2_mbx;
740     UWORD32 ui_pred_width, ui_rec_width;
741     WORD16 *pi2_y_coeff;
742     UWORD8 u1_mbaff, u1_topmb, u1_mb_field_decoding_flag;
743     UWORD32 u4_num_pmbair;
744     UWORD16 ui2_luma_csbp = ps_cur_mb_info->u2_luma_csbp;
745     UWORD8 *pu1_yleft, *pu1_ytop_left;
746     /* Chroma variables*/
747     UWORD8 *pu1_top_u;
748     UWORD8 *pu1_uleft;
749     UWORD8 *pu1_u_top_left;
750     /* CHANGED CODE */
751     UWORD8 *pu1_mb_cb_rei1_buffer, *pu1_mb_cr_rei1_buffer;
752     UWORD32 u4_recwidth_cr;
753     /* CHANGED CODE */
754     tfr_ctxt_t *ps_frame_buf = ps_dec->ps_frame_buf_ip_recon;
755     UWORD32 u4_luma_dc_only_csbp = 0;
756     UWORD32 u4_luma_dc_only_cbp = 0;
757 
758     UWORD8 *pu1_prev_intra4x4_pred_mode_data = (UWORD8 *)ps_dec->pv_proc_tu_coeff_data;                 //Pointer to keep track of intra4x4_pred_mode data in pv_proc_tu_coeff_data buffer
759     u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
760     u1_topmb = ps_cur_mb_info->u1_topmb;
761     u4_num_pmbair = (u1_mb_num >> u1_mbaff);
762 
763 
764     /*--------------------------------------------------------------------*/
765     /* Find the current MB's mb params                                    */
766     /*--------------------------------------------------------------------*/
767     u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
768 
769     ps_curmb = ps_cur_mb_info->ps_curmb;
770     ps_top_mb = ps_cur_mb_info->ps_top_mb;
771     ps_left_mb = ps_cur_mb_info->ps_left_mb;
772     ps_top_right_mb = ps_cur_mb_info->ps_top_right_mb;
773 
774     /*--------------------------------------------------------------------*/
775     /* Check whether neighbouring MB is Inter MB and                      */
776     /* constrained intra pred is 1.                                       */
777     /*--------------------------------------------------------------------*/
778     u2_use_left_mb_pack = (u2_use_left_mb << 8) + u2_use_left_mb;
779 
780     if(ps_dec->ps_cur_pps->u1_constrained_intra_pred_flag)
781     {
782         UWORD8 u1_left = (UWORD8)u2_use_left_mb;
783 
784         uc_useTopMB = uc_useTopMB
785                         && ((ps_top_mb->u1_mb_type != P_MB)
786                                         && (ps_top_mb->u1_mb_type != B_MB));
787         u2_use_left_mb = u2_use_left_mb
788                         && ((ps_left_mb->u1_mb_type != P_MB)
789                                         && (ps_left_mb->u1_mb_type != B_MB));
790 
791         u2_use_left_mb_pack = (u2_use_left_mb << 8) + u2_use_left_mb;
792         if(u1_mbaff)
793         {
794             if(u1_mb_field_decoding_flag ^ ps_left_mb->u1_mb_fld)
795             {
796                 u1_left = u1_left
797                                 && (((ps_left_mb + 1)->u1_mb_type != P_MB)
798                                                 && ((ps_left_mb + 1)->u1_mb_type
799                                                                 != B_MB));
800                 u2_use_left_mb = u2_use_left_mb && u1_left;
801                 if(u1_mb_field_decoding_flag)
802                     u2_use_left_mb_pack = (u1_left << 8)
803                                     + (u2_use_left_mb_pack & 0xff);
804                 else
805                     u2_use_left_mb_pack = (u2_use_left_mb << 8)
806                                     + (u2_use_left_mb);
807             }
808         }
809         u1_use_top_right_mb =
810                         u1_use_top_right_mb
811                                         && ((ps_top_right_mb->u1_mb_type != P_MB)
812                                                         && (ps_top_right_mb->u1_mb_type
813                                                                         != B_MB));
814 
815         u1_use_top_left_mb =
816                         u1_use_top_left_mb
817                                         && ((ps_cur_mb_info->u1_topleft_mbtype != P_MB)
818                                                         && (ps_cur_mb_info->u1_topleft_mbtype
819                                                                         != B_MB));
820     }
821 
822     /*********************Common pointer calculations *************************/
823     /* CHANGED CODE */
824     pu1_luma_pred_buffer = ps_dec->pu1_y;
825     pu1_luma_rec_buffer = ps_frame_buf->pu1_dest_y + (u4_num_pmbair << 4);
826     pu1_mb_cb_rei1_buffer = ps_frame_buf->pu1_dest_u
827                     + (u4_num_pmbair << 3) * YUV420SP_FACTOR;
828     pu1_mb_cr_rei1_buffer = ps_frame_buf->pu1_dest_v + (u4_num_pmbair << 3);
829     ui_pred_width = MB_SIZE;
830     ui_rec_width = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
831     u4_recwidth_cr = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
832     /************* Current and top luma pointer *****************/
833 
834     if(u1_mbaff)
835     {
836         if(u1_topmb == 0)
837         {
838             pu1_luma_rec_buffer += (
839                             u1_mb_field_decoding_flag ?
840                                             (ui_rec_width >> 1) :
841                                             (ui_rec_width << 4));
842             pu1_mb_cb_rei1_buffer += (
843                             u1_mb_field_decoding_flag ?
844                                             (u4_recwidth_cr >> 1) :
845                                             (u4_recwidth_cr << 3));
846             pu1_mb_cr_rei1_buffer += (
847                             u1_mb_field_decoding_flag ?
848                                             (u4_recwidth_cr >> 1) :
849                                             (u4_recwidth_cr << 3));
850         }
851     }
852 
853     /* CHANGED CODE */
854     if(ps_dec->u4_use_intrapred_line_copy == 1)
855     {
856         puc_top = ps_dec->pu1_prev_y_intra_pred_line + (ps_cur_mb_info->u2_mbx << 4);
857         pu1_top_u = ps_dec->pu1_prev_u_intra_pred_line
858                         + (ps_cur_mb_info->u2_mbx << 3) * YUV420SP_FACTOR;
859     }
860     else
861     {
862         puc_top = pu1_luma_rec_buffer - ui_rec_width;
863         pu1_top_u = pu1_mb_cb_rei1_buffer - u4_recwidth_cr;
864     }
865     /* CHANGED CODE */
866 
867     /************* Left pointer *****************/
868     pu1_yleft = pu1_luma_rec_buffer - 1;
869     pu1_uleft = pu1_mb_cb_rei1_buffer - 1 * YUV420SP_FACTOR;
870 
871     /**************Top Left pointer calculation**********/
872     pu1_ytop_left = puc_top - 1;
873     pu1_u_top_left = pu1_top_u - 1 * YUV420SP_FACTOR;
874 
875     /* CHANGED CODE */
876     PROFILE_DISABLE_INTRA_PRED()
877     {
878         pu1_prev_intra4x4_pred_mode_data = (UWORD8 *)ps_dec->pv_proc_tu_coeff_data;
879         if(u1_mb_type == I_4x4_MB && ps_cur_mb_info->u1_tran_form8x8 == 0)
880         {
881             ps_dec->pv_proc_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_proc_tu_coeff_data + 32);
882 
883         }
884         else if (u1_mb_type == I_4x4_MB && ps_cur_mb_info->u1_tran_form8x8 == 1)
885         {
886             ps_dec->pv_proc_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_proc_tu_coeff_data + 8);
887         }
888     }
889     if(!ps_cur_mb_info->u1_tran_form8x8)
890     {
891         u4_luma_dc_only_csbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
892                                        ps_cur_mb_info,
893                                        1);
894     }
895     else
896     {
897         if(!ps_dec->ps_cur_pps->u1_entropy_coding_mode)
898         {
899             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
900                                            ps_cur_mb_info,
901                                            1);
902         }
903         else
904         {
905             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff8x8_mb(ps_dec,
906                                            ps_cur_mb_info);
907         }
908     }
909 
910     pi2_y_coeff = ps_dec->pi2_coeff_data;
911 
912     if(u1_mb_type != I_4x4_MB)
913     {
914         UWORD8 u1_intrapred_mode = MB_TYPE_TO_INTRA_16x16_MODE(u1_mb_type);
915         /*--------------------------------------------------------------------*/
916         /* 16x16 IntraPrediction                                              */
917         /*--------------------------------------------------------------------*/
918         {
919             UWORD8 u1_packed_modes = (u1_top_available << 1)
920                             + u1_left_available;
921             UWORD8 u1_err_code =
922                             (u1_intrapred_mode & 1) ?
923                                             u1_intrapred_mode :
924                                             (u1_intrapred_mode ^ 2);
925 
926             if((u1_err_code & u1_packed_modes) ^ u1_err_code)
927             {
928                 u1_intrapred_mode = 0;
929                 ps_dec->i4_error_code = ERROR_INTRAPRED;
930             }
931         }
932         {
933             UWORD8 au1_ngbr_pels[33];
934             /* Get neighbour pixels */
935             /* left pels */
936             if(u2_use_left_mb)
937             {
938                 WORD32 i;
939                 for(i = 0; i < 16; i++)
940                     au1_ngbr_pels[16 - 1 - i] = pu1_yleft[i * ui_rec_width];
941             }
942             else
943             {
944                 memset(au1_ngbr_pels, 0, 16);
945             }
946 
947             /* top left pels */
948             au1_ngbr_pels[16] = *pu1_ytop_left;
949 
950             /* top pels */
951             if(uc_useTopMB)
952             {
953                 memcpy(au1_ngbr_pels + 16 + 1, puc_top, 16);
954             }
955             else
956             {
957                 memset(au1_ngbr_pels + 16 + 1, 0, 16);
958             }
959             PROFILE_DISABLE_INTRA_PRED()
960             ps_dec->apf_intra_pred_luma_16x16[u1_intrapred_mode](
961                             au1_ngbr_pels, pu1_luma_rec_buffer, 1, ui_rec_width,
962                             ((uc_useTopMB << 2) | u2_use_left_mb));
963         }
964         {
965             UWORD32 i;
966             WORD16 ai2_tmp[16];
967             for(i = 0; i < 16; i++)
968             {
969                 WORD16 *pi2_level = pi2_y_coeff + (i << 4);
970                 UWORD8 *pu1_pred_sblk = pu1_luma_rec_buffer
971                                 + ((i & 0x3) * BLK_SIZE)
972                                 + (i >> 2) * (ui_rec_width << 2);
973                 PROFILE_DISABLE_IQ_IT_RECON()
974                 {
975                     if(CHECKBIT(ps_cur_mb_info->u2_luma_csbp, i))
976                     {
977                         ps_dec->pf_iquant_itrans_recon_luma_4x4(
978                                         pi2_level,
979                                         pu1_pred_sblk,
980                                         pu1_pred_sblk,
981                                         ui_rec_width,
982                                         ui_rec_width,
983                                         gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
984                                         (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[0],
985                                         ps_cur_mb_info->u1_qp_div6, ai2_tmp, 1,
986                                         pi2_level);
987                     }
988                     else if((CHECKBIT(u4_luma_dc_only_csbp, i)) && pi2_level[0] != 0)
989                     {
990                         ps_dec->pf_iquant_itrans_recon_luma_4x4_dc(
991                                         pi2_level,
992                                         pu1_pred_sblk,
993                                         pu1_pred_sblk,
994                                         ui_rec_width,
995                                         ui_rec_width,
996                                         gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
997                                         (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[0],
998                                         ps_cur_mb_info->u1_qp_div6, ai2_tmp, 1,
999                                         pi2_level);
1000                     }
1001                 }
1002             }
1003         }
1004     }
1005     else if(!ps_cur_mb_info->u1_tran_form8x8)
1006     {
1007         UWORD8 u1_is_left_sub_block, u1_is_top_sub_block = uc_useTopMB;
1008         UWORD8 u1_sub_blk_x, u1_sub_blk_y, u1_sub_mb_num;
1009         WORD8 i1_top_pred_mode;
1010         WORD8 i1_left_pred_mode;
1011         UWORD8 *pu1_top, *pu1_left, *pu1_top_left, *pu1_top_right;
1012         WORD8 *pi1_cur_pred_mode, *pi1_left_pred_mode, *pc_topPredMode;
1013         UWORD16 ui2_left_pred_buf_width = 0xffff;
1014         WORD8 i1_intra_pred;
1015         UWORD8 *pu1_prev_intra4x4_pred_mode_flag = pu1_prev_intra4x4_pred_mode_data;
1016         UWORD8 *pu1_rem_intra4x4_pred_mode = pu1_prev_intra4x4_pred_mode_data + 16;
1017         WORD16 *pi2_y_coeff1;
1018         UWORD8 u1_cur_sub_block;
1019         UWORD16 ui2_top_rt_mask;
1020 
1021         /*--------------------------------------------------------------------*/
1022         /* 4x4 IntraPrediction                                                */
1023         /*--------------------------------------------------------------------*/
1024         /* Calculation of Top Right subblock mask                             */
1025         /*                                                                    */
1026         /* (a) Set it to default mask                                         */
1027         /*     [It has 0 for sublocks which will never have top-right sub block] */
1028         /*                                                                    */
1029         /* (b) If top MB is not available                                     */
1030         /*      Clear the bits of the first row sub blocks                    */
1031         /*                                                                    */
1032         /* (c) Set/Clear bit for top-right sublock of MB                      */
1033         /*      [5 sub-block in decoding order] based on TOP RIGHT MB availablity */
1034         /*--------------------------------------------------------------------*/
1035 
1036         pu1_top = puc_top;
1037 
1038         ui2_top_rt_mask = (u1_use_top_right_mb << 3) | (0x5750);
1039         if(uc_useTopMB)
1040             ui2_top_rt_mask |= 0x7;
1041 
1042         /*Top Related initialisations*/
1043 
1044 
1045         pi1_cur_pred_mode = ps_cur_mb_info->ps_curmb->pi1_intrapredmodes;
1046         pc_topPredMode = ps_cur_mb_info->ps_top_mb->pi1_intrapredmodes;
1047         /*--------------------------------------
1048          if(u1_mbaff)
1049          {
1050 
1051          pi1_cur_pred_mode += (u2_mbx << 2);
1052          pc_topPredMode = pi1_cur_pred_mode + ps_cur_mb_info->i1_offset;
1053          pi1_cur_pred_mode += (u1_topmb) ? 0: 4;
1054          }*/
1055 
1056         if(u1_top_available)
1057         {
1058             if(ps_top_mb->u1_mb_type == I_4x4_MB)
1059                 *(WORD32*)pi1_cur_pred_mode = *(WORD32*)pc_topPredMode;
1060             else
1061                 *(WORD32*)pi1_cur_pred_mode =
1062                                 (uc_useTopMB) ? DC_DC_DC_DC : NOT_VALID;
1063         }
1064         else
1065             *(WORD32*)pi1_cur_pred_mode = NOT_VALID;
1066         /* CHANGED CODE */
1067 
1068         /* CHANGED CODE */
1069 
1070         /*Left Related initialisations*/
1071         pi1_left_pred_mode = ps_dec->pi1_left_pred_mode;
1072         if(!u1_mbaff)
1073         {
1074 
1075             if(u1_left_available)
1076             {
1077 
1078                 if(ps_left_mb->u1_mb_type != I_4x4_MB)
1079                     *(WORD32*)pi1_left_pred_mode =
1080                                     (u2_use_left_mb_pack) ?
1081                                     DC_DC_DC_DC :
1082                                                             NOT_VALID;
1083 
1084             }
1085             else
1086             {
1087 
1088                 *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1089             }
1090 
1091         }
1092         else
1093         {
1094             UWORD8 u1_curMbfld = ps_cur_mb_info->u1_mb_field_decodingflag;
1095             UWORD8 u1_leftMbfld = ps_left_mb->u1_mb_fld;
1096 
1097             if(u1_curMbfld ^ u1_leftMbfld)
1098             {
1099 
1100                 if(u1_topmb
1101                                 | ((u1_topmb == 0)
1102                                                 && ((ps_curmb - 1)->u1_mb_type
1103                                                                 != I_4x4_MB)))
1104                 {
1105                     if(u1_left_available)
1106                     {
1107                         if(ps_left_mb->u1_mb_type != I_4x4_MB)
1108                         {
1109                             if(CHECKBIT(u2_use_left_mb_pack,0) == 0)
1110                                 *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1111                             else
1112                                 *(WORD32*)pi1_left_pred_mode = DC_DC_DC_DC;
1113                         }
1114                     }
1115                     else
1116                         *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1117 
1118                     if(u1_curMbfld)
1119                     {
1120                         if(u1_left_available)
1121                         {
1122                             if((ps_left_mb + 1)->u1_mb_type != I_4x4_MB)
1123                             {
1124                                 if(u2_use_left_mb_pack >> 8)
1125                                     *(WORD32*)(pi1_left_pred_mode + 4) =
1126                                                     DC_DC_DC_DC;
1127                                 else
1128                                     *(WORD32*)(pi1_left_pred_mode + 4) =
1129                                                     NOT_VALID;
1130                             }
1131                         }
1132                         else
1133                             *(WORD32*)(pi1_left_pred_mode + 4) = NOT_VALID;
1134                         pi1_left_pred_mode[1] = pi1_left_pred_mode[2];
1135                         pi1_left_pred_mode[2] = pi1_left_pred_mode[4];
1136                         pi1_left_pred_mode[3] = pi1_left_pred_mode[6];
1137                         *(WORD32*)(pi1_left_pred_mode + 4) =
1138                                         *(WORD32*)pi1_left_pred_mode;
1139                     }
1140                     else
1141                     {
1142 
1143                         pi1_left_pred_mode[7] = pi1_left_pred_mode[3];
1144                         pi1_left_pred_mode[6] = pi1_left_pred_mode[3];
1145                         pi1_left_pred_mode[5] = pi1_left_pred_mode[2];
1146                         pi1_left_pred_mode[4] = pi1_left_pred_mode[2];
1147                         pi1_left_pred_mode[3] = pi1_left_pred_mode[1];
1148                         pi1_left_pred_mode[2] = pi1_left_pred_mode[1];
1149                         pi1_left_pred_mode[1] = pi1_left_pred_mode[0];
1150                     }
1151                 }
1152                 pi1_left_pred_mode += (u1_topmb) ? 0 : 4;
1153             }
1154             else
1155             {
1156 
1157                 pi1_left_pred_mode += (u1_topmb) ? 0 : 4;
1158                 if(u1_left_available)
1159                 {
1160 
1161                     if(ps_left_mb->u1_mb_type != I_4x4_MB)
1162                         *(WORD32*)pi1_left_pred_mode =
1163                                         (u2_use_left_mb_pack) ?
1164                                         DC_DC_DC_DC :
1165                                                                 NOT_VALID;
1166                 }
1167                 else
1168                     *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1169             }
1170         }
1171         /* One time pointer initialisations*/
1172         pi2_y_coeff1 = pi2_y_coeff;
1173         pu1_top_left = pu1_ytop_left;
1174 
1175         /* Scan the sub-blocks in Raster Scan Order */
1176         for(u1_sub_mb_num = 0; u1_sub_mb_num < 16; u1_sub_mb_num++)
1177         {
1178             UWORD8 au1_ngbr_pels[13];
1179 
1180             u1_sub_blk_x = u1_sub_mb_num & 0x3;
1181             u1_sub_blk_y = u1_sub_mb_num >> 2;
1182             i1_top_pred_mode = pi1_cur_pred_mode[u1_sub_blk_x];
1183             i1_left_pred_mode = pi1_left_pred_mode[u1_sub_blk_y];
1184             u1_use_top_right_mb = (!!CHECKBIT(ui2_top_rt_mask, u1_sub_mb_num));
1185 
1186             /*********** left subblock availability**********/
1187             if(u1_sub_blk_x)
1188                 u1_is_left_sub_block = 1;
1189             else
1190                 u1_is_left_sub_block =
1191                                 (u1_sub_blk_y < 2) ?
1192                                                 (CHECKBIT(u2_use_left_mb_pack,
1193                                                           0)) :
1194                                                 (u2_use_left_mb_pack >> 8);
1195 
1196             /* CHANGED CODE */
1197             if(u1_sub_blk_y)
1198                 u1_is_top_sub_block = 1;
1199 
1200             /* CHANGED CODE */
1201             /***************** Top *********************/
1202             if(ps_dec->u4_use_intrapred_line_copy == 1)
1203             {
1204 
1205                 if(u1_sub_blk_y)
1206                     pu1_top = pu1_luma_rec_buffer - ui_rec_width;
1207                 else
1208                     pu1_top = puc_top + (u1_sub_blk_x << 2);
1209             }
1210             else
1211             {
1212                 pu1_top = pu1_luma_rec_buffer - ui_rec_width;
1213             }
1214             /***************** Top Right *********************/
1215             pu1_top_right = pu1_top + 4;
1216             /***************** Top Left *********************/
1217             pu1_top_left = pu1_top - 1;
1218             /***************** Left *********************/
1219             pu1_left = pu1_luma_rec_buffer - 1;
1220             /* CHANGED CODE */
1221 
1222             /*---------------------------------------------------------------*/
1223             /* Calculation of Intra prediction mode                          */
1224             /*---------------------------------------------------------------*/
1225             i1_intra_pred = ((i1_left_pred_mode < 0) | (i1_top_pred_mode < 0)) ?
1226                             DC : MIN(i1_left_pred_mode, i1_top_pred_mode);
1227             {
1228                 UWORD8 u1_packed_modes = (u1_is_top_sub_block << 1)
1229                                 + u1_is_left_sub_block;
1230                 UWORD8 *pu1_intra_err_codes =
1231                                 (UWORD8 *)gau1_ih264d_intra_pred_err_code;
1232                 UWORD8 uc_b2b0 = ((u1_sub_mb_num & 4) >> 1) | (u1_sub_mb_num & 1);
1233                 UWORD8 uc_b3b1 = ((u1_sub_mb_num & 8) >> 2)
1234                                 | ((u1_sub_mb_num & 2) >> 1);
1235 
1236                 u1_cur_sub_block = (uc_b3b1 << 2) + uc_b2b0;
1237                 PROFILE_DISABLE_INTRA_PRED()
1238                 if(!pu1_prev_intra4x4_pred_mode_flag[u1_cur_sub_block])
1239                 {
1240                     i1_intra_pred =
1241                                     pu1_rem_intra4x4_pred_mode[u1_cur_sub_block]
1242                                                     + (pu1_rem_intra4x4_pred_mode[u1_cur_sub_block]
1243                                                                     >= i1_intra_pred);
1244                 }
1245                 i1_intra_pred = CLIP3(0, 8, i1_intra_pred);
1246                 {
1247                     UWORD8 u1_err_code = pu1_intra_err_codes[i1_intra_pred];
1248 
1249                     if((u1_err_code & u1_packed_modes) ^ u1_err_code)
1250                      {
1251                         i1_intra_pred = 0;
1252                         ps_dec->i4_error_code = ERROR_INTRAPRED;
1253                      }
1254 
1255                 }
1256             }
1257             {
1258                 /* Get neighbour pixels */
1259                 /* left pels */
1260                 if(u1_is_left_sub_block)
1261                 {
1262                     WORD32 i;
1263                     for(i = 0; i < 4; i++)
1264                         au1_ngbr_pels[4 - 1 - i] = pu1_left[i * ui_rec_width];
1265                 }
1266                 else
1267                 {
1268                     memset(au1_ngbr_pels, 0, 4);
1269                 }
1270 
1271                 /* top left pels */
1272                 au1_ngbr_pels[4] = *pu1_top_left;
1273 
1274                 /* top pels */
1275                 if(u1_is_top_sub_block)
1276                 {
1277                     memcpy(au1_ngbr_pels + 4 + 1, pu1_top, 4);
1278                 }
1279                 else
1280                 {
1281                     memset(au1_ngbr_pels + 4 + 1, 0, 4);
1282                 }
1283 
1284                 /* top right pels */
1285                 if(u1_use_top_right_mb)
1286                 {
1287                     memcpy(au1_ngbr_pels + 4 * 2 + 1, pu1_top_right, 4);
1288                 }
1289                 else if(u1_is_top_sub_block)
1290                 {
1291                     memset(au1_ngbr_pels + 4 * 2 + 1, au1_ngbr_pels[4 * 2], 4);
1292                 }
1293             }
1294             PROFILE_DISABLE_INTRA_PRED()
1295             ps_dec->apf_intra_pred_luma_4x4[i1_intra_pred](
1296                             au1_ngbr_pels, pu1_luma_rec_buffer, 1,
1297                             ui_rec_width,
1298                             ((u1_is_top_sub_block << 2) | u1_is_left_sub_block));
1299 
1300             /* CHANGED CODE */
1301             if(CHECKBIT(ui2_luma_csbp, u1_sub_mb_num))
1302             {
1303                 WORD16 ai2_tmp[16];
1304                 PROFILE_DISABLE_IQ_IT_RECON()
1305                 {
1306                     if(CHECKBIT(u4_luma_dc_only_csbp, u1_sub_mb_num))
1307                     {
1308                         ps_dec->pf_iquant_itrans_recon_luma_4x4_dc(
1309                                         pi2_y_coeff1,
1310                                         pu1_luma_rec_buffer,
1311                                         pu1_luma_rec_buffer,
1312                                         ui_rec_width,
1313                                         ui_rec_width,
1314                                         gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
1315                                         (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[0],
1316                                         ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
1317                                         NULL);
1318                     }
1319                     else
1320                     {
1321                         ps_dec->pf_iquant_itrans_recon_luma_4x4(
1322                                         pi2_y_coeff1,
1323                                         pu1_luma_rec_buffer,
1324                                         pu1_luma_rec_buffer,
1325                                         ui_rec_width,
1326                                         ui_rec_width,
1327                                         gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
1328                                         (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[0],
1329                                         ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
1330                                         NULL);
1331                     }
1332                 }
1333 
1334             }
1335 
1336             /*---------------------------------------------------------------*/
1337             /* Update sub block number                                       */
1338             /*---------------------------------------------------------------*/
1339             pi2_y_coeff1 += 16;
1340             pu1_luma_rec_buffer +=
1341                             (u1_sub_blk_x == 3) ? (ui_rec_width << 2) - 12 : 4;
1342             pu1_luma_pred_buffer +=
1343                             (u1_sub_blk_x == 3) ? (ui_pred_width << 2) - 12 : 4;
1344             /* CHANGED CODE */
1345             pi1_cur_pred_mode[u1_sub_blk_x] = i1_intra_pred;
1346             pi1_left_pred_mode[u1_sub_blk_y] = i1_intra_pred;
1347         }
1348     }
1349     else if((u1_mb_type == I_4x4_MB) && (ps_cur_mb_info->u1_tran_form8x8 == 1))
1350     {
1351         UWORD8 u1_is_left_sub_block, u1_is_top_sub_block = uc_useTopMB;
1352         UWORD8 u1_sub_blk_x, u1_sub_blk_y, u1_sub_mb_num;
1353         WORD8 i1_top_pred_mode;
1354         WORD8 i1_left_pred_mode;
1355         UWORD8 *pu1_top, *pu1_left, *pu1_top_left;
1356         WORD8 *pi1_cur_pred_mode, *pi1_left_pred_mode, *pc_topPredMode;
1357         UWORD16 ui2_left_pred_buf_width = 0xffff;
1358         WORD8 i1_intra_pred;
1359         UWORD8 *pu1_prev_intra4x4_pred_mode_flag = pu1_prev_intra4x4_pred_mode_data;
1360         UWORD8 *pu1_rem_intra4x4_pred_mode = pu1_prev_intra4x4_pred_mode_data + 4;
1361         WORD16 *pi2_y_coeff1;
1362         UWORD16 ui2_top_rt_mask;
1363         UWORD32 u4_4x4_left_offset = 0;
1364 
1365         /*--------------------------------------------------------------------*/
1366         /* 8x8 IntraPrediction                                                */
1367         /*--------------------------------------------------------------------*/
1368         /* Calculation of Top Right subblock mask                             */
1369         /*                                                                    */
1370         /* (a) Set it to default mask                                         */
1371         /*  [It has 0 for sublocks which will never have top-right sub block] */
1372         /*                                                                    */
1373         /* (b) If top MB is not available                                     */
1374         /*      Clear the bits of the first row sub blocks                    */
1375         /*                                                                    */
1376         /* (c) Set/Clear bit for top-right sublock of MB                      */
1377         /*  [5 sub-block in decoding order] based on TOP RIGHT MB availablity */
1378         /*                                                                    */
1379         /* ui2_top_rt_mask: marks availibility of top right(neighbour)         */
1380         /* in the 8x8 Block ordering                                          */
1381         /*                                                                    */
1382         /*      tr0   tr1                                                     */
1383         /*   0    1   tr3                                                     */
1384         /*   2    3                                                           */
1385         /*                                                                    */
1386         /*  Top rights for 0 is in top MB                                     */
1387         /*  top right of 1 will be in top right MB                            */
1388         /*  top right of 3 in right MB and hence not available                */
1389         /*  This corresponds to ui2_top_rt_mask  having default value 0x4      */
1390         /*--------------------------------------------------------------------*/
1391 
1392         ui2_top_rt_mask = (u1_use_top_right_mb << 1) | (0x4);
1393 
1394         if(uc_useTopMB)
1395         {
1396             ui2_top_rt_mask |= 0x1;
1397         }
1398 
1399         /* Top Related initialisations */
1400         pi1_cur_pred_mode = ps_cur_mb_info->ps_curmb->pi1_intrapredmodes;
1401         pc_topPredMode = ps_cur_mb_info->ps_top_mb->pi1_intrapredmodes;
1402         /*
1403          if(u1_mbaff)
1404          {
1405          pi1_cur_pred_mode += (u2_mbx << 2);
1406          pc_topPredMode = pi1_cur_pred_mode + ps_cur_mb_info->i1_offset;
1407          pi1_cur_pred_mode += (u1_topmb) ? 0: 4;
1408          }
1409          */
1410         if(u1_top_available)
1411         {
1412             if(ps_top_mb->u1_mb_type == I_4x4_MB)
1413             {
1414                 *(WORD32*)pi1_cur_pred_mode = *(WORD32*)pc_topPredMode;
1415             }
1416             else
1417             {
1418                 *(WORD32*)pi1_cur_pred_mode =
1419                                 (uc_useTopMB) ? DC_DC_DC_DC : NOT_VALID;
1420             }
1421         }
1422         else
1423         {
1424             *(WORD32*)pi1_cur_pred_mode = NOT_VALID;
1425         }
1426 
1427         pu1_top = puc_top - 8;
1428 
1429         /*Left Related initialisations*/
1430         pi1_left_pred_mode = ps_dec->pi1_left_pred_mode;
1431 
1432         if(!u1_mbaff)
1433         {
1434             if(u1_left_available)
1435             {
1436                 if(ps_left_mb->u1_mb_type != I_4x4_MB)
1437                 {
1438                     *(WORD32*)pi1_left_pred_mode =
1439                                     (u2_use_left_mb_pack) ?
1440                                     DC_DC_DC_DC :
1441                                                             NOT_VALID;
1442                 }
1443             }
1444             else
1445             {
1446                 *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1447             }
1448         }
1449         else
1450         {
1451             UWORD8 u1_curMbfld = ps_cur_mb_info->u1_mb_field_decodingflag;
1452 
1453             UWORD8 u1_leftMbfld = ps_left_mb->u1_mb_fld;
1454 
1455             if((!u1_curMbfld) && (u1_leftMbfld))
1456             {
1457                 u4_4x4_left_offset = 1;
1458             }
1459 
1460             if(u1_curMbfld ^ u1_leftMbfld)
1461             {
1462 
1463                 if(u1_topmb
1464                                 | ((u1_topmb == 0)
1465                                                 && ((ps_curmb - 1)->u1_mb_type
1466                                                                 != I_4x4_MB)))
1467 
1468                 {
1469                     if(u1_left_available)
1470                     {
1471                         if(ps_left_mb->u1_mb_type != I_4x4_MB)
1472                         {
1473                             if(CHECKBIT(u2_use_left_mb_pack,0) == 0)
1474                             {
1475                                 *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1476                             }
1477                             else
1478                             {
1479                                 *(WORD32*)pi1_left_pred_mode = DC_DC_DC_DC;
1480                             }
1481                         }
1482                     }
1483                     else
1484                     {
1485                         *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1486                     }
1487 
1488                     if(u1_curMbfld)
1489                     {
1490                         if(u1_left_available)
1491                         {
1492                             if((ps_left_mb + 1)->u1_mb_type != I_4x4_MB)
1493                             {
1494                                 if(u2_use_left_mb_pack >> 8)
1495                                 {
1496                                     *(WORD32*)(pi1_left_pred_mode + 4) =
1497                                                     DC_DC_DC_DC;
1498                                 }
1499                                 else
1500                                 {
1501                                     *(WORD32*)(pi1_left_pred_mode + 4) =
1502                                                     NOT_VALID;
1503                                 }
1504                             }
1505                         }
1506                         else
1507                         {
1508                             *(WORD32*)(pi1_left_pred_mode + 4) = NOT_VALID;
1509                         }
1510 
1511                         pi1_left_pred_mode[1] = pi1_left_pred_mode[2];
1512                         pi1_left_pred_mode[2] = pi1_left_pred_mode[4];
1513                         pi1_left_pred_mode[3] = pi1_left_pred_mode[6];
1514                         *(WORD32*)(pi1_left_pred_mode + 4) =
1515                                         *(WORD32*)pi1_left_pred_mode;
1516                     }
1517                     else
1518                     {
1519                         pi1_left_pred_mode[7] = pi1_left_pred_mode[3];
1520                         pi1_left_pred_mode[6] = pi1_left_pred_mode[3];
1521                         pi1_left_pred_mode[5] = pi1_left_pred_mode[2];
1522                         pi1_left_pred_mode[4] = pi1_left_pred_mode[2];
1523                         pi1_left_pred_mode[3] = pi1_left_pred_mode[1];
1524                         pi1_left_pred_mode[2] = pi1_left_pred_mode[1];
1525                         pi1_left_pred_mode[1] = pi1_left_pred_mode[0];
1526                     }
1527                 }
1528                 pi1_left_pred_mode += (u1_topmb) ? 0 : 4;
1529             }
1530             else
1531             {
1532                 pi1_left_pred_mode += (u1_topmb) ? 0 : 4;
1533 
1534                 if(u1_left_available)
1535                 {
1536                     if(ps_left_mb->u1_mb_type != I_4x4_MB)
1537                     {
1538                         *(WORD32*)pi1_left_pred_mode =
1539                                         (u2_use_left_mb_pack) ?
1540                                         DC_DC_DC_DC :
1541                                                                 NOT_VALID;
1542                     }
1543                 }
1544                 else
1545                 {
1546                     *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1547                 }
1548             }
1549         }
1550 
1551         /* One time pointer initialisations*/
1552         pi2_y_coeff1 = pi2_y_coeff;
1553 
1554         if(u1_use_top_left_mb)
1555         {
1556             pu1_top_left = pu1_ytop_left;
1557         }
1558         else
1559         {
1560             pu1_top_left = NULL;
1561         }
1562 
1563         /* Scan the sub-blocks in Raster Scan Order */
1564         for(u1_sub_mb_num = 0; u1_sub_mb_num < 4; u1_sub_mb_num++)
1565         {
1566             u1_sub_blk_x = (u1_sub_mb_num & 0x1);
1567             u1_sub_blk_y = (u1_sub_mb_num >> 1);
1568             i1_top_pred_mode = pi1_cur_pred_mode[u1_sub_blk_x << 1];
1569             i1_left_pred_mode = pi1_left_pred_mode[u1_sub_blk_y << 1];
1570 
1571             if(2 == u1_sub_mb_num)
1572             {
1573                 i1_left_pred_mode = pi1_left_pred_mode[(u1_sub_blk_y << 1)
1574                                 + u4_4x4_left_offset];
1575             }
1576 
1577             u1_use_top_right_mb = (!!CHECKBIT(ui2_top_rt_mask, u1_sub_mb_num));
1578 
1579             /*********** left subblock availability**********/
1580             if(u1_sub_blk_x)
1581             {
1582                 u1_is_left_sub_block = 1;
1583             }
1584             else
1585             {
1586                 u1_is_left_sub_block =
1587                                 (u1_sub_blk_y < 1) ?
1588                                                 (CHECKBIT(u2_use_left_mb_pack,
1589                                                           0)) :
1590                                                 (u2_use_left_mb_pack >> 8);
1591             }
1592 
1593             /***************** Top *********************/
1594             if(u1_sub_blk_y)
1595             {
1596                 u1_is_top_sub_block = 1;
1597                 // sushant
1598                 pu1_top = /*pu1_luma_pred_buffer*/pu1_luma_rec_buffer - ui_rec_width;
1599             }
1600             else
1601             {
1602                 pu1_top += 8;
1603             }
1604 
1605             /***************** Left *********************/
1606             if((u1_sub_blk_x) | (u4_num_pmbair != 0))
1607             {
1608                 // sushant
1609                 pu1_left = /*pu1_luma_pred_buffer*/pu1_luma_rec_buffer - 1;
1610                 ui2_left_pred_buf_width = ui_rec_width;
1611             }
1612             else
1613             {
1614                 pu1_left = pu1_yleft;
1615                 pu1_yleft += (ui_rec_width << 3);
1616                 ui2_left_pred_buf_width = ui_rec_width;
1617             }
1618 
1619             /***************** Top Left *********************/
1620             if(u1_sub_mb_num)
1621             {
1622                 pu1_top_left = (u1_sub_blk_x) ?
1623                                 pu1_top - 1 : pu1_left - ui_rec_width;
1624 
1625                 if((u1_sub_blk_x && (!u1_is_top_sub_block))
1626                                 || ((!u1_sub_blk_x) && (!u1_is_left_sub_block)))
1627                 {
1628                     pu1_top_left = NULL;
1629                 }
1630             }
1631 
1632             /*---------------------------------------------------------------*/
1633             /* Calculation of Intra prediction mode                          */
1634             /*---------------------------------------------------------------*/
1635             i1_intra_pred = ((i1_left_pred_mode < 0) | (i1_top_pred_mode < 0)) ?
1636                             DC : MIN(i1_left_pred_mode, i1_top_pred_mode);
1637             {
1638                 UWORD8 u1_packed_modes = (u1_is_top_sub_block << 1)
1639                                 + u1_is_left_sub_block;
1640                 UWORD8 *pu1_intra_err_codes =
1641                                 (UWORD8 *)gau1_ih264d_intra_pred_err_code;
1642 
1643                 /********************************************************************/
1644                 /* Same intra4x4_pred_mode array is filled with intra4x4_pred_mode  */
1645                 /* for a MB with 8x8 intrapredicition                               */
1646                 /********************************************************************/
1647                 PROFILE_DISABLE_INTRA_PRED()
1648                 if(!pu1_prev_intra4x4_pred_mode_flag[u1_sub_mb_num])
1649                 {
1650                     i1_intra_pred = pu1_rem_intra4x4_pred_mode[u1_sub_mb_num]
1651                                     + (pu1_rem_intra4x4_pred_mode[u1_sub_mb_num]
1652                                                     >= i1_intra_pred);
1653                 }
1654                 i1_intra_pred = CLIP3(0, 8, i1_intra_pred);
1655                 {
1656                     UWORD8 u1_err_code = pu1_intra_err_codes[i1_intra_pred];
1657 
1658                     if((u1_err_code & u1_packed_modes) ^ u1_err_code)
1659                     {
1660                         i1_intra_pred = 0;
1661                         ps_dec->i4_error_code = ERROR_INTRAPRED;
1662                     }
1663                 }
1664             }
1665 
1666             {
1667                 UWORD8 au1_ngbr_pels[25];
1668                 WORD32 ngbr_avail;
1669                 ngbr_avail = u1_is_left_sub_block << 0;
1670                 ngbr_avail |= u1_is_top_sub_block << 2;
1671 
1672                 if(pu1_top_left)
1673                     ngbr_avail |= 1 << 1;
1674 
1675                 ngbr_avail |= u1_use_top_right_mb << 3;
1676                 PROFILE_DISABLE_INTRA_PRED()
1677                 {
1678                     ps_dec->pf_intra_pred_ref_filtering(pu1_left, pu1_top_left,
1679                                                         pu1_top, au1_ngbr_pels,
1680                                                         ui2_left_pred_buf_width,
1681                                                         ngbr_avail);
1682 
1683                     ps_dec->apf_intra_pred_luma_8x8[i1_intra_pred](
1684                                     au1_ngbr_pels, pu1_luma_rec_buffer, 1,
1685                                     ui_rec_width,
1686                                     ((u1_is_top_sub_block << 2) | u1_is_left_sub_block));
1687                 }
1688             }
1689 
1690             /* Inverse Transform and Reconstruction */
1691             if(CHECKBIT(ps_cur_mb_info->u1_cbp, u1_sub_mb_num))
1692             {
1693                 WORD16 *pi2_scale_matrix_ptr;
1694                 WORD16 ai2_tmp[64];
1695 
1696                 pi2_scale_matrix_ptr =
1697                                 ps_dec->s_high_profile.i2_scalinglist8x8[0];
1698                 PROFILE_DISABLE_IQ_IT_RECON()
1699                 {
1700                     if(CHECKBIT(u4_luma_dc_only_cbp, u1_sub_mb_num))
1701                     {
1702                         ps_dec->pf_iquant_itrans_recon_luma_8x8_dc(
1703                                         pi2_y_coeff1,
1704                                         pu1_luma_rec_buffer,
1705                                         pu1_luma_rec_buffer,
1706                                         ui_rec_width,
1707                                         ui_rec_width,
1708                                         gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
1709                                         (UWORD16 *)pi2_scale_matrix_ptr,
1710                                         ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
1711                                         NULL);
1712                     }
1713                     else
1714                     {
1715                         ps_dec->pf_iquant_itrans_recon_luma_8x8(
1716                                         pi2_y_coeff1,
1717                                         pu1_luma_rec_buffer,
1718                                         pu1_luma_rec_buffer,
1719                                         ui_rec_width,
1720                                         ui_rec_width,
1721                                         gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
1722                                         (UWORD16 *)pi2_scale_matrix_ptr,
1723                                         ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
1724                                         NULL);
1725                     }
1726                 }
1727 
1728             }
1729 
1730             /*---------------------------------------------------------------*/
1731             /* Update sub block number                                       */
1732             /*---------------------------------------------------------------*/
1733             pi2_y_coeff1 += 64;
1734 
1735             pu1_luma_rec_buffer +=
1736                             (u1_sub_blk_x == 1) ?
1737                                             (ui_rec_width << 3) - (8 * 1) : 8;
1738 
1739             /*---------------------------------------------------------------*/
1740             /* Pred mode filled in terms of 4x4 block so replicated in 2     */
1741             /* locations.                                                    */
1742             /*---------------------------------------------------------------*/
1743             pi1_cur_pred_mode[u1_sub_blk_x << 1] = i1_intra_pred;
1744             pi1_cur_pred_mode[(u1_sub_blk_x << 1) + 1] = i1_intra_pred;
1745             pi1_left_pred_mode[u1_sub_blk_y << 1] = i1_intra_pred;
1746             pi1_left_pred_mode[(u1_sub_blk_y << 1) + 1] = i1_intra_pred;
1747         }
1748     }
1749     /* Decode Chroma Block */
1750     ih264d_unpack_chroma_coeff4x4_mb(ps_dec,
1751                                      ps_cur_mb_info);
1752     /*--------------------------------------------------------------------*/
1753     /* Chroma Blocks decoding                                             */
1754     /*--------------------------------------------------------------------*/
1755     {
1756         UWORD8 u1_intra_chrom_pred_mode;
1757         UWORD8 u1_chroma_cbp = (UWORD8)(ps_cur_mb_info->u1_cbp >> 4);
1758 
1759         /*--------------------------------------------------------------------*/
1760         /* Perform Chroma intra prediction                                    */
1761         /*--------------------------------------------------------------------*/
1762 
1763         u1_intra_chrom_pred_mode = CHROMA_TO_LUMA_INTRA_MODE(
1764                         ps_cur_mb_info->u1_chroma_pred_mode);
1765 
1766         {
1767             UWORD8 u1_packed_modes = (u1_top_available << 1)
1768                             + u1_left_available;
1769             UWORD8 u1_err_code =
1770                             (u1_intra_chrom_pred_mode & 1) ?
1771                                             u1_intra_chrom_pred_mode :
1772                                             (u1_intra_chrom_pred_mode ^ 2);
1773             if((u1_err_code & u1_packed_modes) ^ u1_err_code)
1774             {
1775                 u1_intra_chrom_pred_mode = 0;
1776                 ps_dec->i4_error_code = ERROR_INTRAPRED;
1777             }
1778         }
1779 
1780         /* CHANGED CODE */
1781         if(u1_chroma_cbp != CBPC_ALLZERO)
1782         {
1783             UWORD16 u2_chroma_csbp =
1784                             (u1_chroma_cbp == CBPC_ACZERO) ?
1785                                             0 : ps_cur_mb_info->u2_chroma_csbp;
1786             UWORD32 u4_scale_u;
1787             UWORD32 u4_scale_v;
1788 
1789             {
1790                 UWORD16 au2_ngbr_pels[33];
1791                 UWORD8 *pu1_ngbr_pels = (UWORD8 *)au2_ngbr_pels;
1792                 UWORD16 *pu2_left_uv;
1793                 UWORD16 *pu2_topleft_uv;
1794                 WORD32 use_left1 = (u2_use_left_mb_pack & 0x0ff);
1795                 WORD32 use_left2 = (u2_use_left_mb_pack & 0xff00) >> 8;
1796 
1797                 pu2_left_uv = (UWORD16 *)pu1_uleft;
1798                 pu2_topleft_uv = (UWORD16 *)pu1_u_top_left;
1799                 /* Get neighbour pixels */
1800                 /* left pels */
1801                 if(u2_use_left_mb_pack)
1802                 {
1803                     WORD32 i;
1804                     if(use_left1)
1805                     {
1806                         for(i = 0; i < 4; i++)
1807                             au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
1808                                             * u4_recwidth_cr / YUV420SP_FACTOR];
1809                     }
1810                     else
1811                     {
1812                         memset(au2_ngbr_pels + 4, 0, 4 * sizeof(UWORD16));
1813                     }
1814 
1815                     if(use_left2)
1816                     {
1817                         for(i = 4; i < 8; i++)
1818                             au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
1819                                             * u4_recwidth_cr / YUV420SP_FACTOR];
1820                     }
1821                     else
1822                     {
1823                         memset(au2_ngbr_pels, 0, 4 * sizeof(UWORD16));
1824                     }
1825                 }
1826                 else
1827                 {
1828                     memset(au2_ngbr_pels, 0, 8 * sizeof(UWORD16));
1829                 }
1830 
1831                 /* top left pels */
1832                 au2_ngbr_pels[8] = *pu2_topleft_uv;
1833 
1834                 /* top pels */
1835                 if(uc_useTopMB)
1836                 {
1837                     memcpy(au2_ngbr_pels + 8 + 1, pu1_top_u,
1838                            8 * sizeof(UWORD16));
1839                 }
1840                 else
1841                 {
1842                     memset(au2_ngbr_pels + 8 + 1, 0, 8 * sizeof(UWORD16));
1843                 }
1844 
1845                 PROFILE_DISABLE_INTRA_PRED()
1846                 ps_dec->apf_intra_pred_chroma[u1_intra_chrom_pred_mode](
1847                                 pu1_ngbr_pels,
1848                                 pu1_mb_cb_rei1_buffer,
1849                                 1,
1850                                 u4_recwidth_cr,
1851                                 ((uc_useTopMB << 2) | (use_left2 << 4)
1852                                                 | use_left1));
1853             }
1854             u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
1855             u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
1856             pi2_y_coeff = ps_dec->pi2_coeff_data;
1857 
1858             {
1859                 UWORD32 i;
1860                 WORD16 ai2_tmp[16];
1861                 for(i = 0; i < 4; i++)
1862                 {
1863                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
1864                     UWORD8 *pu1_pred_sblk = pu1_mb_cb_rei1_buffer
1865                                     + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
1866                                     + (i >> 1) * (u4_recwidth_cr << 2);
1867                     PROFILE_DISABLE_IQ_IT_RECON()
1868                     {
1869                         if(CHECKBIT(u2_chroma_csbp, i))
1870                         {
1871                             ps_dec->pf_iquant_itrans_recon_chroma_4x4(
1872                                             pi2_level,
1873                                             pu1_pred_sblk,
1874                                             pu1_pred_sblk,
1875                                             u4_recwidth_cr,
1876                                             u4_recwidth_cr,
1877                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
1878                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[1],
1879                                             u4_scale_u, ai2_tmp, pi2_level);
1880                         }
1881                         else if(pi2_level[0] != 0)
1882                         {
1883                             ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
1884                                             pi2_level,
1885                                             pu1_pred_sblk,
1886                                             pu1_pred_sblk,
1887                                             u4_recwidth_cr,
1888                                             u4_recwidth_cr,
1889                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
1890                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[1],
1891                                             u4_scale_u, ai2_tmp, pi2_level);
1892                         }
1893                     }
1894 
1895                 }
1896             }
1897 
1898             pi2_y_coeff += MB_CHROM_SIZE;
1899             u2_chroma_csbp = u2_chroma_csbp >> 4;
1900             {
1901                 UWORD32 i;
1902                 WORD16 ai2_tmp[16];
1903                 for(i = 0; i < 4; i++)
1904                 {
1905                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
1906                     UWORD8 *pu1_pred_sblk = pu1_mb_cb_rei1_buffer + 1
1907                                     + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
1908                                     + (i >> 1) * (u4_recwidth_cr << 2);
1909                     PROFILE_DISABLE_IQ_IT_RECON()
1910                     {
1911                         if(CHECKBIT(u2_chroma_csbp, i))
1912                         {
1913                             ps_dec->pf_iquant_itrans_recon_chroma_4x4(
1914                                             pi2_level,
1915                                             pu1_pred_sblk,
1916                                             pu1_pred_sblk,
1917                                             u4_recwidth_cr,
1918                                             u4_recwidth_cr,
1919                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
1920                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[2],
1921                                             u4_scale_v, ai2_tmp, pi2_level);
1922                         }
1923                         else if(pi2_level[0] != 0)
1924                         {
1925                             ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
1926                                             pi2_level,
1927                                             pu1_pred_sblk,
1928                                             pu1_pred_sblk,
1929                                             u4_recwidth_cr,
1930                                             u4_recwidth_cr,
1931                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
1932                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[2],
1933                                             u4_scale_v, ai2_tmp, pi2_level);
1934                         }
1935                     }
1936                 }
1937             }
1938 
1939         }
1940         else
1941         {
1942             /* If no inverse transform is needed, pass recon buffer pointer */
1943             /* to Intraprediction module instead of pred buffer pointer     */
1944             {
1945                 UWORD16 au2_ngbr_pels[33];
1946                 UWORD8 *pu1_ngbr_pels = (UWORD8 *)au2_ngbr_pels;
1947                 UWORD16 *pu2_left_uv;
1948                 UWORD16 *pu2_topleft_uv;
1949                 WORD32 use_left1 = (u2_use_left_mb_pack & 0x0ff);
1950                 WORD32 use_left2 = (u2_use_left_mb_pack & 0xff00) >> 8;
1951 
1952                 pu2_topleft_uv = (UWORD16 *)pu1_u_top_left;
1953                 pu2_left_uv = (UWORD16 *)pu1_uleft;
1954 
1955                 /* Get neighbour pixels */
1956                 /* left pels */
1957                 if(u2_use_left_mb_pack)
1958                 {
1959                     WORD32 i;
1960                     if(use_left1)
1961                     {
1962                         for(i = 0; i < 4; i++)
1963                             au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
1964                                             * u4_recwidth_cr / YUV420SP_FACTOR];
1965                     }
1966                     else
1967                     {
1968                         memset(au2_ngbr_pels + 4, 0, 4 * sizeof(UWORD16));
1969                     }
1970 
1971                     if(use_left2)
1972                     {
1973                         for(i = 4; i < 8; i++)
1974                             au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
1975                                             * u4_recwidth_cr / YUV420SP_FACTOR];
1976                     }
1977                     else
1978                     {
1979                         memset(au2_ngbr_pels, 0, 4 * sizeof(UWORD16));
1980                     }
1981 
1982                 }
1983                 else
1984                 {
1985                     memset(au2_ngbr_pels, 0, 8 * sizeof(UWORD16));
1986                 }
1987 
1988                 /* top left pels */
1989                 au2_ngbr_pels[8] = *pu2_topleft_uv;
1990 
1991                 /* top pels */
1992                 if(uc_useTopMB)
1993                 {
1994                     memcpy(au2_ngbr_pels + 8 + 1, pu1_top_u,
1995                            8 * sizeof(UWORD16));
1996                 }
1997                 else
1998                 {
1999                     memset(au2_ngbr_pels + 8 + 1, 0, 8 * sizeof(UWORD16));
2000                 }
2001 
2002                 PROFILE_DISABLE_INTRA_PRED()
2003                 ps_dec->apf_intra_pred_chroma[u1_intra_chrom_pred_mode](
2004                                 pu1_ngbr_pels,
2005                                 pu1_mb_cb_rei1_buffer,
2006                                 1,
2007                                 u4_recwidth_cr,
2008                                 ((uc_useTopMB << 2) | (use_left2 << 4)
2009                                                 | use_left1));
2010             }
2011 
2012         }
2013 
2014     }
2015     return OK;
2016 }
2017