Home | History | Annotate | Download | only in decoder
      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  */
     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  */
    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 }
    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 
    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 }
    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 }
    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 }
    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 
    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 }
    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  */
    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                 {
   1246                     UWORD8 u1_err_code = pu1_intra_err_codes[i1_intra_pred];
   1247 
   1248                     if((u1_err_code & u1_packed_modes) ^ u1_err_code)
   1249                      {
   1250                         i1_intra_pred = 0;
   1251                         ps_dec->i4_error_code = ERROR_INTRAPRED;
   1252                      }
   1253 
   1254                 }
   1255             }
   1256             {
   1257                 /* Get neighbour pixels */
   1258                 /* left pels */
   1259                 if(u1_is_left_sub_block)
   1260                 {
   1261                     WORD32 i;
   1262                     for(i = 0; i < 4; i++)
   1263                         au1_ngbr_pels[4 - 1 - i] = pu1_left[i * ui_rec_width];
   1264                 }
   1265                 else
   1266                 {
   1267                     memset(au1_ngbr_pels, 0, 4);
   1268                 }
   1269 
   1270                 /* top left pels */
   1271                 au1_ngbr_pels[4] = *pu1_top_left;
   1272 
   1273                 /* top pels */
   1274                 if(u1_is_top_sub_block)
   1275                 {
   1276                     memcpy(au1_ngbr_pels + 4 + 1, pu1_top, 4);
   1277                 }
   1278                 else
   1279                 {
   1280                     memset(au1_ngbr_pels + 4 + 1, 0, 4);
   1281                 }
   1282 
   1283                 /* top right pels */
   1284                 if(u1_use_top_right_mb)
   1285                 {
   1286                     memcpy(au1_ngbr_pels + 4 * 2 + 1, pu1_top_right, 4);
   1287                 }
   1288                 else if(u1_is_top_sub_block)
   1289                 {
   1290                     memset(au1_ngbr_pels + 4 * 2 + 1, au1_ngbr_pels[4 * 2], 4);
   1291                 }
   1292             }
   1293             PROFILE_DISABLE_INTRA_PRED()
   1294             ps_dec->apf_intra_pred_luma_4x4[i1_intra_pred](
   1295                             au1_ngbr_pels, pu1_luma_rec_buffer, 1,
   1296                             ui_rec_width,
   1297                             ((u1_is_top_sub_block << 2) | u1_is_left_sub_block));
   1298 
   1299             /* CHANGED CODE */
   1300             if(CHECKBIT(ui2_luma_csbp, u1_sub_mb_num))
   1301             {
   1302                 WORD16 ai2_tmp[16];
   1303                 PROFILE_DISABLE_IQ_IT_RECON()
   1304                 {
   1305                     if(CHECKBIT(u4_luma_dc_only_csbp, u1_sub_mb_num))
   1306                     {
   1307                         ps_dec->pf_iquant_itrans_recon_luma_4x4_dc(
   1308                                         pi2_y_coeff1,
   1309                                         pu1_luma_rec_buffer,
   1310                                         pu1_luma_rec_buffer,
   1311                                         ui_rec_width,
   1312                                         ui_rec_width,
   1313                                         gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
   1314                                         (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[0],
   1315                                         ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
   1316                                         NULL);
   1317                     }
   1318                     else
   1319                     {
   1320                         ps_dec->pf_iquant_itrans_recon_luma_4x4(
   1321                                         pi2_y_coeff1,
   1322                                         pu1_luma_rec_buffer,
   1323                                         pu1_luma_rec_buffer,
   1324                                         ui_rec_width,
   1325                                         ui_rec_width,
   1326                                         gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
   1327                                         (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[0],
   1328                                         ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
   1329                                         NULL);
   1330                     }
   1331                 }
   1332 
   1333             }
   1334 
   1335             /*---------------------------------------------------------------*/
   1336             /* Update sub block number                                       */
   1337             /*---------------------------------------------------------------*/
   1338             pi2_y_coeff1 += 16;
   1339             pu1_luma_rec_buffer +=
   1340                             (u1_sub_blk_x == 3) ? (ui_rec_width << 2) - 12 : 4;
   1341             pu1_luma_pred_buffer +=
   1342                             (u1_sub_blk_x == 3) ? (ui_pred_width << 2) - 12 : 4;
   1343             /* CHANGED CODE */
   1344             pi1_cur_pred_mode[u1_sub_blk_x] = i1_intra_pred;
   1345             pi1_left_pred_mode[u1_sub_blk_y] = i1_intra_pred;
   1346         }
   1347     }
   1348     else if((u1_mb_type == I_4x4_MB) && (ps_cur_mb_info->u1_tran_form8x8 == 1))
   1349     {
   1350         UWORD8 u1_is_left_sub_block, u1_is_top_sub_block = uc_useTopMB;
   1351         UWORD8 u1_sub_blk_x, u1_sub_blk_y, u1_sub_mb_num;
   1352         WORD8 i1_top_pred_mode;
   1353         WORD8 i1_left_pred_mode;
   1354         UWORD8 *pu1_top, *pu1_left, *pu1_top_left;
   1355         WORD8 *pi1_cur_pred_mode, *pi1_left_pred_mode, *pc_topPredMode;
   1356         UWORD16 ui2_left_pred_buf_width = 0xffff;
   1357         WORD8 i1_intra_pred;
   1358         UWORD8 *pu1_prev_intra4x4_pred_mode_flag = pu1_prev_intra4x4_pred_mode_data;
   1359         UWORD8 *pu1_rem_intra4x4_pred_mode = pu1_prev_intra4x4_pred_mode_data + 4;
   1360         WORD16 *pi2_y_coeff1;
   1361         UWORD16 ui2_top_rt_mask;
   1362         UWORD32 u4_4x4_left_offset = 0;
   1363 
   1364         /*--------------------------------------------------------------------*/
   1365         /* 8x8 IntraPrediction                                                */
   1366         /*--------------------------------------------------------------------*/
   1367         /* Calculation of Top Right subblock mask                             */
   1368         /*                                                                    */
   1369         /* (a) Set it to default mask                                         */
   1370         /*  [It has 0 for sublocks which will never have top-right sub block] */
   1371         /*                                                                    */
   1372         /* (b) If top MB is not available                                     */
   1373         /*      Clear the bits of the first row sub blocks                    */
   1374         /*                                                                    */
   1375         /* (c) Set/Clear bit for top-right sublock of MB                      */
   1376         /*  [5 sub-block in decoding order] based on TOP RIGHT MB availablity */
   1377         /*                                                                    */
   1378         /* ui2_top_rt_mask: marks availibility of top right(neighbour)         */
   1379         /* in the 8x8 Block ordering                                          */
   1380         /*                                                                    */
   1381         /*      tr0   tr1                                                     */
   1382         /*   0    1   tr3                                                     */
   1383         /*   2    3                                                           */
   1384         /*                                                                    */
   1385         /*  Top rights for 0 is in top MB                                     */
   1386         /*  top right of 1 will be in top right MB                            */
   1387         /*  top right of 3 in right MB and hence not available                */
   1388         /*  This corresponds to ui2_top_rt_mask  having default value 0x4      */
   1389         /*--------------------------------------------------------------------*/
   1390 
   1391         ui2_top_rt_mask = (u1_use_top_right_mb << 1) | (0x4);
   1392 
   1393         if(uc_useTopMB)
   1394         {
   1395             ui2_top_rt_mask |= 0x1;
   1396         }
   1397 
   1398         /* Top Related initialisations */
   1399         pi1_cur_pred_mode = ps_cur_mb_info->ps_curmb->pi1_intrapredmodes;
   1400         pc_topPredMode = ps_cur_mb_info->ps_top_mb->pi1_intrapredmodes;
   1401         /*
   1402          if(u1_mbaff)
   1403          {
   1404          pi1_cur_pred_mode += (u2_mbx << 2);
   1405          pc_topPredMode = pi1_cur_pred_mode + ps_cur_mb_info->i1_offset;
   1406          pi1_cur_pred_mode += (u1_topmb) ? 0: 4;
   1407          }
   1408          */
   1409         if(u1_top_available)
   1410         {
   1411             if(ps_top_mb->u1_mb_type == I_4x4_MB)
   1412             {
   1413                 *(WORD32*)pi1_cur_pred_mode = *(WORD32*)pc_topPredMode;
   1414             }
   1415             else
   1416             {
   1417                 *(WORD32*)pi1_cur_pred_mode =
   1418                                 (uc_useTopMB) ? DC_DC_DC_DC : NOT_VALID;
   1419             }
   1420         }
   1421         else
   1422         {
   1423             *(WORD32*)pi1_cur_pred_mode = NOT_VALID;
   1424         }
   1425 
   1426         pu1_top = puc_top - 8;
   1427 
   1428         /*Left Related initialisations*/
   1429         pi1_left_pred_mode = ps_dec->pi1_left_pred_mode;
   1430 
   1431         if(!u1_mbaff)
   1432         {
   1433             if(u1_left_available)
   1434             {
   1435                 if(ps_left_mb->u1_mb_type != I_4x4_MB)
   1436                 {
   1437                     *(WORD32*)pi1_left_pred_mode =
   1438                                     (u2_use_left_mb_pack) ?
   1439                                     DC_DC_DC_DC :
   1440                                                             NOT_VALID;
   1441                 }
   1442             }
   1443             else
   1444             {
   1445                 *(WORD32*)pi1_left_pred_mode = NOT_VALID;
   1446             }
   1447         }
   1448         else
   1449         {
   1450             UWORD8 u1_curMbfld = ps_cur_mb_info->u1_mb_field_decodingflag;
   1451 
   1452             UWORD8 u1_leftMbfld = ps_left_mb->u1_mb_fld;
   1453 
   1454             if((!u1_curMbfld) && (u1_leftMbfld))
   1455             {
   1456                 u4_4x4_left_offset = 1;
   1457             }
   1458 
   1459             if(u1_curMbfld ^ u1_leftMbfld)
   1460             {
   1461 
   1462                 if(u1_topmb
   1463                                 | ((u1_topmb == 0)
   1464                                                 && ((ps_curmb - 1)->u1_mb_type
   1465                                                                 != I_4x4_MB)))
   1466 
   1467                 {
   1468                     if(u1_left_available)
   1469                     {
   1470                         if(ps_left_mb->u1_mb_type != I_4x4_MB)
   1471                         {
   1472                             if(CHECKBIT(u2_use_left_mb_pack,0) == 0)
   1473                             {
   1474                                 *(WORD32*)pi1_left_pred_mode = NOT_VALID;
   1475                             }
   1476                             else
   1477                             {
   1478                                 *(WORD32*)pi1_left_pred_mode = DC_DC_DC_DC;
   1479                             }
   1480                         }
   1481                     }
   1482                     else
   1483                     {
   1484                         *(WORD32*)pi1_left_pred_mode = NOT_VALID;
   1485                     }
   1486 
   1487                     if(u1_curMbfld)
   1488                     {
   1489                         if(u1_left_available)
   1490                         {
   1491                             if((ps_left_mb + 1)->u1_mb_type != I_4x4_MB)
   1492                             {
   1493                                 if(u2_use_left_mb_pack >> 8)
   1494                                 {
   1495                                     *(WORD32*)(pi1_left_pred_mode + 4) =
   1496                                                     DC_DC_DC_DC;
   1497                                 }
   1498                                 else
   1499                                 {
   1500                                     *(WORD32*)(pi1_left_pred_mode + 4) =
   1501                                                     NOT_VALID;
   1502                                 }
   1503                             }
   1504                         }
   1505                         else
   1506                         {
   1507                             *(WORD32*)(pi1_left_pred_mode + 4) = NOT_VALID;
   1508                         }
   1509 
   1510                         pi1_left_pred_mode[1] = pi1_left_pred_mode[2];
   1511                         pi1_left_pred_mode[2] = pi1_left_pred_mode[4];
   1512                         pi1_left_pred_mode[3] = pi1_left_pred_mode[6];
   1513                         *(WORD32*)(pi1_left_pred_mode + 4) =
   1514                                         *(WORD32*)pi1_left_pred_mode;
   1515                     }
   1516                     else
   1517                     {
   1518                         pi1_left_pred_mode[7] = pi1_left_pred_mode[3];
   1519                         pi1_left_pred_mode[6] = pi1_left_pred_mode[3];
   1520                         pi1_left_pred_mode[5] = pi1_left_pred_mode[2];
   1521                         pi1_left_pred_mode[4] = pi1_left_pred_mode[2];
   1522                         pi1_left_pred_mode[3] = pi1_left_pred_mode[1];
   1523                         pi1_left_pred_mode[2] = pi1_left_pred_mode[1];
   1524                         pi1_left_pred_mode[1] = pi1_left_pred_mode[0];
   1525                     }
   1526                 }
   1527                 pi1_left_pred_mode += (u1_topmb) ? 0 : 4;
   1528             }
   1529             else
   1530             {
   1531                 pi1_left_pred_mode += (u1_topmb) ? 0 : 4;
   1532 
   1533                 if(u1_left_available)
   1534                 {
   1535                     if(ps_left_mb->u1_mb_type != I_4x4_MB)
   1536                     {
   1537                         *(WORD32*)pi1_left_pred_mode =
   1538                                         (u2_use_left_mb_pack) ?
   1539                                         DC_DC_DC_DC :
   1540                                                                 NOT_VALID;
   1541                     }
   1542                 }
   1543                 else
   1544                 {
   1545                     *(WORD32*)pi1_left_pred_mode = NOT_VALID;
   1546                 }
   1547             }
   1548         }
   1549 
   1550         /* One time pointer initialisations*/
   1551         pi2_y_coeff1 = pi2_y_coeff;
   1552 
   1553         if(u1_use_top_left_mb)
   1554         {
   1555             pu1_top_left = pu1_ytop_left;
   1556         }
   1557         else
   1558         {
   1559             pu1_top_left = NULL;
   1560         }
   1561 
   1562         /* Scan the sub-blocks in Raster Scan Order */
   1563         for(u1_sub_mb_num = 0; u1_sub_mb_num < 4; u1_sub_mb_num++)
   1564         {
   1565             u1_sub_blk_x = (u1_sub_mb_num & 0x1);
   1566             u1_sub_blk_y = (u1_sub_mb_num >> 1);
   1567             i1_top_pred_mode = pi1_cur_pred_mode[u1_sub_blk_x << 1];
   1568             i1_left_pred_mode = pi1_left_pred_mode[u1_sub_blk_y << 1];
   1569 
   1570             if(2 == u1_sub_mb_num)
   1571             {
   1572                 i1_left_pred_mode = pi1_left_pred_mode[(u1_sub_blk_y << 1)
   1573                                 + u4_4x4_left_offset];
   1574             }
   1575 
   1576             u1_use_top_right_mb = (!!CHECKBIT(ui2_top_rt_mask, u1_sub_mb_num));
   1577 
   1578             /*********** left subblock availability**********/
   1579             if(u1_sub_blk_x)
   1580             {
   1581                 u1_is_left_sub_block = 1;
   1582             }
   1583             else
   1584             {
   1585                 u1_is_left_sub_block =
   1586                                 (u1_sub_blk_y < 1) ?
   1587                                                 (CHECKBIT(u2_use_left_mb_pack,
   1588                                                           0)) :
   1589                                                 (u2_use_left_mb_pack >> 8);
   1590             }
   1591 
   1592             /***************** Top *********************/
   1593             if(u1_sub_blk_y)
   1594             {
   1595                 u1_is_top_sub_block = 1;
   1596                 // sushant
   1597                 pu1_top = /*pu1_luma_pred_buffer*/pu1_luma_rec_buffer - ui_rec_width;
   1598             }
   1599             else
   1600             {
   1601                 pu1_top += 8;
   1602             }
   1603 
   1604             /***************** Left *********************/
   1605             if((u1_sub_blk_x) | (u4_num_pmbair != 0))
   1606             {
   1607                 // sushant
   1608                 pu1_left = /*pu1_luma_pred_buffer*/pu1_luma_rec_buffer - 1;
   1609                 ui2_left_pred_buf_width = ui_rec_width;
   1610             }
   1611             else
   1612             {
   1613                 pu1_left = pu1_yleft;
   1614                 pu1_yleft += (ui_rec_width << 3);
   1615                 ui2_left_pred_buf_width = ui_rec_width;
   1616             }
   1617 
   1618             /***************** Top Left *********************/
   1619             if(u1_sub_mb_num)
   1620             {
   1621                 pu1_top_left = (u1_sub_blk_x) ?
   1622                                 pu1_top - 1 : pu1_left - ui_rec_width;
   1623 
   1624                 if((u1_sub_blk_x && (!u1_is_top_sub_block))
   1625                                 || ((!u1_sub_blk_x) && (!u1_is_left_sub_block)))
   1626                 {
   1627                     pu1_top_left = NULL;
   1628                 }
   1629             }
   1630 
   1631             /*---------------------------------------------------------------*/
   1632             /* Calculation of Intra prediction mode                          */
   1633             /*---------------------------------------------------------------*/
   1634             i1_intra_pred = ((i1_left_pred_mode < 0) | (i1_top_pred_mode < 0)) ?
   1635                             DC : MIN(i1_left_pred_mode, i1_top_pred_mode);
   1636             {
   1637                 UWORD8 u1_packed_modes = (u1_is_top_sub_block << 1)
   1638                                 + u1_is_left_sub_block;
   1639                 UWORD8 *pu1_intra_err_codes =
   1640                                 (UWORD8 *)gau1_ih264d_intra_pred_err_code;
   1641 
   1642                 /********************************************************************/
   1643                 /* Same intra4x4_pred_mode array is filled with intra4x4_pred_mode  */
   1644                 /* for a MB with 8x8 intrapredicition                               */
   1645                 /********************************************************************/
   1646                 PROFILE_DISABLE_INTRA_PRED()
   1647                 if(!pu1_prev_intra4x4_pred_mode_flag[u1_sub_mb_num])
   1648                 {
   1649                     i1_intra_pred = pu1_rem_intra4x4_pred_mode[u1_sub_mb_num]
   1650                                     + (pu1_rem_intra4x4_pred_mode[u1_sub_mb_num]
   1651                                                     >= i1_intra_pred);
   1652                 }
   1653                 {
   1654                     UWORD8 u1_err_code = pu1_intra_err_codes[i1_intra_pred];
   1655 
   1656                     if((u1_err_code & u1_packed_modes) ^ u1_err_code)
   1657                     {
   1658                         i1_intra_pred = 0;
   1659                         ps_dec->i4_error_code = ERROR_INTRAPRED;
   1660                     }
   1661                 }
   1662             }
   1663 
   1664             {
   1665                 UWORD8 au1_ngbr_pels[25];
   1666                 WORD32 ngbr_avail;
   1667                 ngbr_avail = u1_is_left_sub_block << 0;
   1668                 ngbr_avail |= u1_is_top_sub_block << 2;
   1669 
   1670                 if(pu1_top_left)
   1671                     ngbr_avail |= 1 << 1;
   1672 
   1673                 ngbr_avail |= u1_use_top_right_mb << 3;
   1674                 PROFILE_DISABLE_INTRA_PRED()
   1675                 {
   1676                     ps_dec->pf_intra_pred_ref_filtering(pu1_left, pu1_top_left,
   1677                                                         pu1_top, au1_ngbr_pels,
   1678                                                         ui2_left_pred_buf_width,
   1679                                                         ngbr_avail);
   1680 
   1681                     ps_dec->apf_intra_pred_luma_8x8[i1_intra_pred](
   1682                                     au1_ngbr_pels, pu1_luma_rec_buffer, 1,
   1683                                     ui_rec_width,
   1684                                     ((u1_is_top_sub_block << 2) | u1_is_left_sub_block));
   1685                 }
   1686             }
   1687 
   1688             /* Inverse Transform and Reconstruction */
   1689             if(CHECKBIT(ps_cur_mb_info->u1_cbp, u1_sub_mb_num))
   1690             {
   1691                 WORD16 *pi2_scale_matrix_ptr;
   1692                 WORD16 ai2_tmp[64];
   1693 
   1694                 pi2_scale_matrix_ptr =
   1695                                 ps_dec->s_high_profile.i2_scalinglist8x8[0];
   1696                 PROFILE_DISABLE_IQ_IT_RECON()
   1697                 {
   1698                     if(CHECKBIT(u4_luma_dc_only_cbp, u1_sub_mb_num))
   1699                     {
   1700                         ps_dec->pf_iquant_itrans_recon_luma_8x8_dc(
   1701                                         pi2_y_coeff1,
   1702                                         pu1_luma_rec_buffer,
   1703                                         pu1_luma_rec_buffer,
   1704                                         ui_rec_width,
   1705                                         ui_rec_width,
   1706                                         gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
   1707                                         (UWORD16 *)pi2_scale_matrix_ptr,
   1708                                         ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
   1709                                         NULL);
   1710                     }
   1711                     else
   1712                     {
   1713                         ps_dec->pf_iquant_itrans_recon_luma_8x8(
   1714                                         pi2_y_coeff1,
   1715                                         pu1_luma_rec_buffer,
   1716                                         pu1_luma_rec_buffer,
   1717                                         ui_rec_width,
   1718                                         ui_rec_width,
   1719                                         gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
   1720                                         (UWORD16 *)pi2_scale_matrix_ptr,
   1721                                         ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
   1722                                         NULL);
   1723                     }
   1724                 }
   1725 
   1726             }
   1727 
   1728             /*---------------------------------------------------------------*/
   1729             /* Update sub block number                                       */
   1730             /*---------------------------------------------------------------*/
   1731             pi2_y_coeff1 += 64;
   1732 
   1733             pu1_luma_rec_buffer +=
   1734                             (u1_sub_blk_x == 1) ?
   1735                                             (ui_rec_width << 3) - (8 * 1) : 8;
   1736 
   1737             /*---------------------------------------------------------------*/
   1738             /* Pred mode filled in terms of 4x4 block so replicated in 2     */
   1739             /* locations.                                                    */
   1740             /*---------------------------------------------------------------*/
   1741             pi1_cur_pred_mode[u1_sub_blk_x << 1] = i1_intra_pred;
   1742             pi1_cur_pred_mode[(u1_sub_blk_x << 1) + 1] = i1_intra_pred;
   1743             pi1_left_pred_mode[u1_sub_blk_y << 1] = i1_intra_pred;
   1744             pi1_left_pred_mode[(u1_sub_blk_y << 1) + 1] = i1_intra_pred;
   1745         }
   1746     }
   1747     /* Decode Chroma Block */
   1748     ih264d_unpack_chroma_coeff4x4_mb(ps_dec,
   1749                                      ps_cur_mb_info);
   1750     /*--------------------------------------------------------------------*/
   1751     /* Chroma Blocks decoding                                             */
   1752     /*--------------------------------------------------------------------*/
   1753     {
   1754         UWORD8 u1_intra_chrom_pred_mode;
   1755         UWORD8 u1_chroma_cbp = (UWORD8)(ps_cur_mb_info->u1_cbp >> 4);
   1756 
   1757         /*--------------------------------------------------------------------*/
   1758         /* Perform Chroma intra prediction                                    */
   1759         /*--------------------------------------------------------------------*/
   1760 
   1761         u1_intra_chrom_pred_mode = CHROMA_TO_LUMA_INTRA_MODE(
   1762                         ps_cur_mb_info->u1_chroma_pred_mode);
   1763 
   1764         {
   1765             UWORD8 u1_packed_modes = (u1_top_available << 1)
   1766                             + u1_left_available;
   1767             UWORD8 u1_err_code =
   1768                             (u1_intra_chrom_pred_mode & 1) ?
   1769                                             u1_intra_chrom_pred_mode :
   1770                                             (u1_intra_chrom_pred_mode ^ 2);
   1771             if((u1_err_code & u1_packed_modes) ^ u1_err_code)
   1772             {
   1773                 u1_intra_chrom_pred_mode = 0;
   1774                 ps_dec->i4_error_code = ERROR_INTRAPRED;
   1775             }
   1776         }
   1777 
   1778         /* CHANGED CODE */
   1779         if(u1_chroma_cbp != CBPC_ALLZERO)
   1780         {
   1781             UWORD16 u2_chroma_csbp =
   1782                             (u1_chroma_cbp == CBPC_ACZERO) ?
   1783                                             0 : ps_cur_mb_info->u2_chroma_csbp;
   1784             UWORD32 u4_scale_u;
   1785             UWORD32 u4_scale_v;
   1786 
   1787             {
   1788                 UWORD16 au2_ngbr_pels[33];
   1789                 UWORD8 *pu1_ngbr_pels = (UWORD8 *)au2_ngbr_pels;
   1790                 UWORD16 *pu2_left_uv;
   1791                 UWORD16 *pu2_topleft_uv;
   1792                 WORD32 use_left1 = (u2_use_left_mb_pack & 0x0ff);
   1793                 WORD32 use_left2 = (u2_use_left_mb_pack & 0xff00) >> 8;
   1794 
   1795                 pu2_left_uv = (UWORD16 *)pu1_uleft;
   1796                 pu2_topleft_uv = (UWORD16 *)pu1_u_top_left;
   1797                 /* Get neighbour pixels */
   1798                 /* left pels */
   1799                 if(u2_use_left_mb_pack)
   1800                 {
   1801                     WORD32 i;
   1802                     if(use_left1)
   1803                     {
   1804                         for(i = 0; i < 4; i++)
   1805                             au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
   1806                                             * u4_recwidth_cr / YUV420SP_FACTOR];
   1807                     }
   1808                     else
   1809                     {
   1810                         memset(au2_ngbr_pels + 4, 0, 4 * sizeof(UWORD16));
   1811                     }
   1812 
   1813                     if(use_left2)
   1814                     {
   1815                         for(i = 4; i < 8; i++)
   1816                             au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
   1817                                             * u4_recwidth_cr / YUV420SP_FACTOR];
   1818                     }
   1819                     else
   1820                     {
   1821                         memset(au2_ngbr_pels, 0, 4 * sizeof(UWORD16));
   1822                     }
   1823                 }
   1824                 else
   1825                 {
   1826                     memset(au2_ngbr_pels, 0, 8 * sizeof(UWORD16));
   1827                 }
   1828 
   1829                 /* top left pels */
   1830                 au2_ngbr_pels[8] = *pu2_topleft_uv;
   1831 
   1832                 /* top pels */
   1833                 if(uc_useTopMB)
   1834                 {
   1835                     memcpy(au2_ngbr_pels + 8 + 1, pu1_top_u,
   1836                            8 * sizeof(UWORD16));
   1837                 }
   1838                 else
   1839                 {
   1840                     memset(au2_ngbr_pels + 8 + 1, 0, 8 * sizeof(UWORD16));
   1841                 }
   1842 
   1843                 PROFILE_DISABLE_INTRA_PRED()
   1844                 ps_dec->apf_intra_pred_chroma[u1_intra_chrom_pred_mode](
   1845                                 pu1_ngbr_pels,
   1846                                 pu1_mb_cb_rei1_buffer,
   1847                                 1,
   1848                                 u4_recwidth_cr,
   1849                                 ((uc_useTopMB << 2) | (use_left2 << 4)
   1850                                                 | use_left1));
   1851             }
   1852             u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
   1853             u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
   1854             pi2_y_coeff = ps_dec->pi2_coeff_data;
   1855 
   1856             {
   1857                 UWORD32 i;
   1858                 WORD16 ai2_tmp[16];
   1859                 for(i = 0; i < 4; i++)
   1860                 {
   1861                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
   1862                     UWORD8 *pu1_pred_sblk = pu1_mb_cb_rei1_buffer
   1863                                     + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
   1864                                     + (i >> 1) * (u4_recwidth_cr << 2);
   1865                     PROFILE_DISABLE_IQ_IT_RECON()
   1866                     {
   1867                         if(CHECKBIT(u2_chroma_csbp, i))
   1868                         {
   1869                             ps_dec->pf_iquant_itrans_recon_chroma_4x4(
   1870                                             pi2_level,
   1871                                             pu1_pred_sblk,
   1872                                             pu1_pred_sblk,
   1873                                             u4_recwidth_cr,
   1874                                             u4_recwidth_cr,
   1875                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
   1876                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[1],
   1877                                             u4_scale_u, ai2_tmp, pi2_level);
   1878                         }
   1879                         else if(pi2_level[0] != 0)
   1880                         {
   1881                             ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
   1882                                             pi2_level,
   1883                                             pu1_pred_sblk,
   1884                                             pu1_pred_sblk,
   1885                                             u4_recwidth_cr,
   1886                                             u4_recwidth_cr,
   1887                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
   1888                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[1],
   1889                                             u4_scale_u, ai2_tmp, pi2_level);
   1890                         }
   1891                     }
   1892 
   1893                 }
   1894             }
   1895 
   1896             pi2_y_coeff += MB_CHROM_SIZE;
   1897             u2_chroma_csbp = u2_chroma_csbp >> 4;
   1898             {
   1899                 UWORD32 i;
   1900                 WORD16 ai2_tmp[16];
   1901                 for(i = 0; i < 4; i++)
   1902                 {
   1903                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
   1904                     UWORD8 *pu1_pred_sblk = pu1_mb_cb_rei1_buffer + 1
   1905                                     + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
   1906                                     + (i >> 1) * (u4_recwidth_cr << 2);
   1907                     PROFILE_DISABLE_IQ_IT_RECON()
   1908                     {
   1909                         if(CHECKBIT(u2_chroma_csbp, i))
   1910                         {
   1911                             ps_dec->pf_iquant_itrans_recon_chroma_4x4(
   1912                                             pi2_level,
   1913                                             pu1_pred_sblk,
   1914                                             pu1_pred_sblk,
   1915                                             u4_recwidth_cr,
   1916                                             u4_recwidth_cr,
   1917                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
   1918                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[2],
   1919                                             u4_scale_v, ai2_tmp, pi2_level);
   1920                         }
   1921                         else if(pi2_level[0] != 0)
   1922                         {
   1923                             ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
   1924                                             pi2_level,
   1925                                             pu1_pred_sblk,
   1926                                             pu1_pred_sblk,
   1927                                             u4_recwidth_cr,
   1928                                             u4_recwidth_cr,
   1929                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
   1930                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[2],
   1931                                             u4_scale_v, ai2_tmp, pi2_level);
   1932                         }
   1933                     }
   1934                 }
   1935             }
   1936 
   1937         }
   1938         else
   1939         {
   1940             /* If no inverse transform is needed, pass recon buffer pointer */
   1941             /* to Intraprediction module instead of pred buffer pointer     */
   1942             {
   1943                 UWORD16 au2_ngbr_pels[33];
   1944                 UWORD8 *pu1_ngbr_pels = (UWORD8 *)au2_ngbr_pels;
   1945                 UWORD16 *pu2_left_uv;
   1946                 UWORD16 *pu2_topleft_uv;
   1947                 WORD32 use_left1 = (u2_use_left_mb_pack & 0x0ff);
   1948                 WORD32 use_left2 = (u2_use_left_mb_pack & 0xff00) >> 8;
   1949 
   1950                 pu2_topleft_uv = (UWORD16 *)pu1_u_top_left;
   1951                 pu2_left_uv = (UWORD16 *)pu1_uleft;
   1952 
   1953                 /* Get neighbour pixels */
   1954                 /* left pels */
   1955                 if(u2_use_left_mb_pack)
   1956                 {
   1957                     WORD32 i;
   1958                     if(use_left1)
   1959                     {
   1960                         for(i = 0; i < 4; i++)
   1961                             au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
   1962                                             * u4_recwidth_cr / YUV420SP_FACTOR];
   1963                     }
   1964                     else
   1965                     {
   1966                         memset(au2_ngbr_pels + 4, 0, 4 * sizeof(UWORD16));
   1967                     }
   1968 
   1969                     if(use_left2)
   1970                     {
   1971                         for(i = 4; i < 8; i++)
   1972                             au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
   1973                                             * u4_recwidth_cr / YUV420SP_FACTOR];
   1974                     }
   1975                     else
   1976                     {
   1977                         memset(au2_ngbr_pels, 0, 4 * sizeof(UWORD16));
   1978                     }
   1979 
   1980                 }
   1981                 else
   1982                 {
   1983                     memset(au2_ngbr_pels, 0, 8 * sizeof(UWORD16));
   1984                 }
   1985 
   1986                 /* top left pels */
   1987                 au2_ngbr_pels[8] = *pu2_topleft_uv;
   1988 
   1989                 /* top pels */
   1990                 if(uc_useTopMB)
   1991                 {
   1992                     memcpy(au2_ngbr_pels + 8 + 1, pu1_top_u,
   1993                            8 * sizeof(UWORD16));
   1994                 }
   1995                 else
   1996                 {
   1997                     memset(au2_ngbr_pels + 8 + 1, 0, 8 * sizeof(UWORD16));
   1998                 }
   1999 
   2000                 PROFILE_DISABLE_INTRA_PRED()
   2001                 ps_dec->apf_intra_pred_chroma[u1_intra_chrom_pred_mode](
   2002                                 pu1_ngbr_pels,
   2003                                 pu1_mb_cb_rei1_buffer,
   2004                                 1,
   2005                                 u4_recwidth_cr,
   2006                                 ((uc_useTopMB << 2) | (use_left2 << 4)
   2007                                                 | use_left1));
   2008             }
   2009 
   2010         }
   2011 
   2012     }
   2013     return OK;
   2014 }
   2015