Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibDecoder/TDecSbac.cpp


Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (12 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibDecoder/TDecSbac.cpp

    r443 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    5252, m_cCUSplitFlagSCModel       ( 1,             1,               NUM_SPLIT_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels )
    5353, m_cCUSkipFlagSCModel        ( 1,             1,               NUM_SKIP_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    54 #if LGE_ILLUCOMP_B0045
    55 , m_cCUICFlagSCModel          ( 1,             1,               NUM_IC_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
    56 #endif
    5754, m_cCUMergeFlagExtSCModel    ( 1,             1,               NUM_MERGE_FLAG_EXT_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
    5855, m_cCUMergeIdxExtSCModel     ( 1,             1,               NUM_MERGE_IDX_EXT_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
    59 #if H3D_IVRP
    60 , m_cResPredFlagSCModel       ( 1,             1,               NUM_RES_PRED_FLAG_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
    61 #endif
    62 #if QC_ARP_D0177
    63 , m_cCUPUARPW                 ( 1,             1,               NUM_ARPW_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
     56#if H_3D_ARP
     57, m_cCUPUARPWSCModel          ( 1,             1,               NUM_ARPW_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
     58#endif
     59#if H_3D_IC
     60, m_cCUICFlagSCModel          ( 1,             1,               NUM_IC_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
    6461#endif
    6562, m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    6663, m_cCUPredModeSCModel        ( 1,             1,               NUM_PRED_MODE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    67 , m_cCUAlfCtrlFlagSCModel     ( 1,             1,               NUM_ALF_CTRL_FLAG_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
    6864, m_cCUIntraPredSCModel       ( 1,             1,               NUM_ADI_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
    6965, m_cCUChromaPredSCModel      ( 1,             1,               NUM_CHROMA_PRED_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     
    8278, m_cCUAbsSCModel             ( 1,             1,               NUM_ABS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    8379, m_cMVPIdxSCModel            ( 1,             1,               NUM_MVP_IDX_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
    84 , m_cALFFlagSCModel           ( 1,             1,               NUM_ALF_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    85 , m_cALFUvlcSCModel           ( 1,             1,               NUM_ALF_UVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    86 , m_cALFSvlcSCModel           ( 1,             1,               NUM_ALF_SVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    8780, m_cCUAMPSCModel             ( 1,             1,               NUM_CU_AMP_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
    88 #if LGE_SAO_MIGRATION_D0091
    89 , m_cSaoMergeSCModel          ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
     81, m_cSaoMergeSCModel      ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
    9082, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
    91 #else
    92 , m_cSaoFlagSCModel           ( 1,             1,               NUM_SAO_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    93 , m_cSaoUvlcSCModel           ( 1,             1,               NUM_SAO_UVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    94 , m_cSaoSvlcSCModel           ( 1,             1,               NUM_SAO_SVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    95 , m_cSaoMergeLeftSCModel      ( 1,             1,               NUM_SAO_MERGE_LEFT_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
    96 , m_cSaoMergeUpSCModel        ( 1,             1,               NUM_SAO_MERGE_UP_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
    97 , m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
    98 #endif
    99 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    100 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    101 , m_cDmmFlagSCModel           ( 1,             1,               NUM_DMM_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    102 , m_cDmmModeSCModel           ( 1,             1,               NUM_DMM_MODE_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    103 #endif
    104 , m_cDmmDataSCModel           ( 1,             1,               NUM_DMM_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    105 #endif
    106 #if LGE_EDGE_INTRA_A0070
    107 , m_cEdgeIntraSCModel         ( 1,             1,               NUM_EDGE_INTRA_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
    108 #if LGE_EDGE_INTRA_DELTA_DC
    109 , m_cEdgeIntraDeltaDCSCModel  ( 1,             1,               NUM_EDGE_INTRA_DELTA_DC_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
    110 #endif
    111 #endif
    112 #if RWTH_SDC_DLT_B0036
    113 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    114 , m_cSDCFlagSCModel             ( 1,             1,                 SDC_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    115 #else
    116 , m_cDepthModeModel             ( 1,             1,                 DEPTH_MODE_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    117 , m_cDmmDeltaFlagModel             ( 1,             1,                 DMM_DELTA_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    118 #endif
    119 #if RWTH_SDC_CTX_SIMPL_D0032
    120 , m_cSDCResidualFlagSCModel     ( 1,             1,  SDC_NUM_RESIDUAL_FLAG_CTX  , m_contextModels + m_numContextModels, m_numContextModels)
    121 , m_cSDCResidualSCModel         ( 1,             1,  SDC_NUM_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
    122 , m_cSDCPredModeSCModel             ( 1,             3,                 SDC_NUM_PRED_MODE_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
    123 #else
    124 , m_cSDCResidualFlagSCModel     ( 1,             2,  SDC_NUM_RESIDUAL_FLAG_CTX  , m_contextModels + m_numContextModels, m_numContextModels)
    125 , m_cSDCResidualSignFlagSCModel ( 1,             2,  SDC_NUM_SIGN_FLAG_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
    126 , m_cSDCResidualSCModel         ( 1,             2,  SDC_NUM_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
    127 , m_cSDCPredModeSCModel             ( 1,             3,                 SDC_NUM_PRED_MODE_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
    128 #endif
     83, m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
     84, m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
     85#if H_3D_DIM
     86, m_cDepthIntraModeSCModel    ( 1,             1,               NUM_DEPTH_INTRA_MODE_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
     87, m_cDdcFlagSCModel           ( 1,             1,               NUM_DDC_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
     88, m_cDdcDataSCModel           ( 1,             1,               NUM_DDC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
     89#if H_3D_DIM_DMM
     90, m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
     91#if !SEC_DMM2_E0146
     92, m_cDmm2DataSCModel          ( 1,             1,               NUM_DMM2_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
     93#endif
     94, m_cDmm3DataSCModel          ( 1,             1,               NUM_DMM3_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
     95#endif
     96#if H_3D_DIM_RBC
     97, m_cRbcDataSCModel           ( 1,             1,               NUM_RBC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
     98#endif
     99#if H_3D_DIM_SDC
     100, m_cSDCResidualFlagSCModel     ( 1,             1,             SDC_NUM_RESIDUAL_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
     101, m_cSDCResidualSCModel         ( 1,             1,             SDC_NUM_RESIDUAL_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     102#endif
     103#endif
     104#if LGE_INTER_SDC_E0156
     105, m_cInterSDCFlagSCModel             ( 1,             1,  NUM_INTER_SDC_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     106, m_cInterSDCResidualSCModel         ( 1,             1,  NUM_INTER_SDC_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
     107, m_cInterSDCResidualSignFlagSCModel ( 1,             1,  NUM_INTER_SDC_SIGN_FLAG_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
    129108#endif
    130109{
    131110  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
    132   m_iSliceGranularity = 0;
    133111}
    134112
     
    141119// ====================================================================================================================
    142120
    143 #if CABAC_INIT_FLAG
    144121Void TDecSbac::resetEntropy(TComSlice* pSlice)
    145122{
     
    162139  }
    163140
    164 #else
    165 Void TDecSbac::resetEntropywithQPandInitIDC (Int  qp, Int iID)
    166 {
    167   SliceType sliceType = (SliceType)iID;
    168 #endif 
    169 
    170141  m_cCUSplitFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
    171142  m_cCUSkipFlagSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
    172 #if LGE_ILLUCOMP_B0045
    173   m_cCUICFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_IC_FLAG );
    174 #endif
    175143  m_cCUMergeFlagExtSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
    176144  m_cCUMergeIdxExtSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
    177 #if H3D_IVRP
    178   m_cResPredFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_RES_PRED_FLAG );
    179 #endif
    180 #if QC_ARP_D0177
    181   m_cCUPUARPW.initBuffer                ( sliceType, qp, (UChar*)INIT_ARPW );
    182 #endif
    183   m_cCUAlfCtrlFlagSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_ALF_CTRL_FLAG );
     145#if H_3D_ARP
     146  m_cCUPUARPWSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_ARPW );
     147#endif
     148#if H_3D_IC
     149  m_cCUICFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_IC_FLAG );
     150#endif
    184151  m_cCUPartSizeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PART_SIZE );
    185152  m_cCUAMPSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_CU_AMP_POS );
     
    200167  m_cCUAbsSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
    201168  m_cMVPIdxSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_MVP_IDX );
    202   m_cALFFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_ALF_FLAG );
    203   m_cALFUvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_ALF_UVLC );
    204   m_cALFSvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_ALF_SVLC );
    205 #if LGE_SAO_MIGRATION_D0091
    206   m_cSaoMergeSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
     169  m_cSaoMergeSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
    207170  m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
    208 #else
    209   m_cSaoFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_SAO_FLAG );
    210   m_cSaoUvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_SAO_UVLC );
    211   m_cSaoSvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_SAO_SVLC );
    212   m_cSaoMergeLeftSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG );
    213   m_cSaoMergeUpSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
    214   m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
    215 #endif
    216171
    217172  m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
    218 #if LGE_EDGE_INTRA_A0070
    219   m_cEdgeIntraSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_EDGE_INTRA );
    220 #if LGE_EDGE_INTRA_DELTA_DC
    221   m_cEdgeIntraDeltaDCSCModel.initBuffer  ( sliceType, qp, (UChar*)INIT_EDGE_INTRA_DELTA_DC );
    222 #endif
     173  m_cTransformSkipSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
     174  m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
     175#if H_3D_DIM
     176  m_cDepthIntraModeSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE );
     177  m_cDdcFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_FLAG );
     178  m_cDdcDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_DATA );
     179#if H_3D_DIM_DMM
     180  m_cDmm1DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM1_DATA );
     181#if !SEC_DMM2_E0146
     182  m_cDmm2DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM2_DATA );
     183#endif
     184  m_cDmm3DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM3_DATA );
     185#endif
     186#if H_3D_DIM_RBC
     187  m_cRbcDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_RBC_DATA );
     188#endif
     189#if H_3D_DIM_SDC
     190  m_cSDCResidualFlagSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
     191  m_cSDCResidualSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
     192#endif
     193#endif
     194#if LGE_INTER_SDC_E0156
     195  m_cInterSDCFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_INTER_SDC_FLAG );
     196  m_cInterSDCResidualSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_INTER_SDC_RESIDUAL );
     197  m_cInterSDCResidualSignFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTER_SDC_SIGN_FLAG );
    223198#endif
    224199  m_uiLastDQpNonZero  = 0;
    225 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    226 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    227   m_cDmmFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMM_FLAG );
    228   m_cDmmModeSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMM_MODE );
    229 #endif
    230   m_cDmmDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMM_DATA );
    231 #endif
    232 #if RWTH_SDC_DLT_B0036
    233 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    234   m_cSDCFlagSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_SDC_FLAG );
    235 #else
    236   m_cDepthModeModel.initBuffer              ( sliceType, qp, (UChar*)INIT_DEPTHMODE_FLAG );
    237   m_cDmmDeltaFlagModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMMDELTA_FLAG );
    238 #endif
    239   m_cSDCResidualFlagSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
    240   m_cSDCResidualSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
    241 #if !RWTH_SDC_CTX_SIMPL_D0032
    242   m_cSDCResidualSignFlagSCModel.initBuffer  ( sliceType, qp, (UChar*)INIT_SDC_SIGN_FLAG );
    243 #endif
    244   m_cSDCPredModeSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_SDC_PRED_MODE );
    245 #endif
    246200 
    247201  // new structure
     
    258212  UInt uiBit;
    259213  m_pcTDecBinIf->decodeBinTrm(uiBit);
     214  assert(uiBit); // end_of_sub_stream_one_bit must be equal to 1
    260215  m_pcTDecBinIf->finish(); 
    261 #if !OL_FLUSH_ALIGN
    262   // Account for misaligned CABAC.
    263   Int iCABACReadAhead = m_pcTDecBinIf->getBitsReadAhead();
    264   iCABACReadAhead--;
    265   Int iStreamBits = 8-m_pcBitstream->getNumBitsUntilByteAligned();
    266   if (iCABACReadAhead >= iStreamBits)
    267   {
    268     // Misaligned CABAC has read into the 1st byte of the next tile.
    269     // Back up a byte prior to alignment.
    270     m_pcBitstream->backupByte();
    271   }
    272 #endif
    273216  m_pcBitstream->readOutTrailingBits();
    274217  m_cCUSplitFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
    275218  m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
    276 #if LGE_ILLUCOMP_B0045
    277   m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
    278 #endif
    279219  m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT );
    280220  m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT );
    281 #if H3D_IVRP
    282   m_cResPredFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_RES_PRED_FLAG );
    283 #endif
    284 #if QC_ARP_D0177
    285   m_cCUPUARPW.initBuffer                 ( eSliceType, iQp, (UChar*)INIT_ARPW );
    286 #endif
    287   m_cCUAlfCtrlFlagSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG );
     221#if H_3D_ARP
     222  m_cCUPUARPWSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_ARPW );
     223#endif
     224#if H_3D_IC
     225  m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
     226#endif
    288227  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
    289228  m_cCUAMPSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );
     
    304243  m_cCUAbsSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
    305244  m_cMVPIdxSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
    306   m_cALFFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_FLAG );
    307   m_cALFUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_UVLC );
    308   m_cALFSvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC );
    309 #if LGE_SAO_MIGRATION_D0091
    310   m_cSaoMergeSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
     245  m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
    311246  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
    312 #else
    313   m_cSaoFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG );
    314   m_cSaoUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC );
    315   m_cSaoSvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_SVLC );
    316   m_cSaoMergeLeftSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG );
    317   m_cSaoMergeUpSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
    318   m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
    319 #endif
    320247  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
    321 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    322 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    323   m_cDmmFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG );
    324   m_cDmmModeSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_MODE );
    325 #endif
    326   m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
    327 #endif
    328 #if RWTH_SDC_DLT_B0036
    329 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    330   m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
    331 #else
    332   m_cDepthModeModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DEPTHMODE_FLAG );
    333   m_cDmmDeltaFlagModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMMDELTA_FLAG );
    334 #endif
    335   m_cSDCResidualFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
    336   m_cSDCResidualSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
    337 #if !RWTH_SDC_CTX_SIMPL_D0032
    338   m_cSDCResidualSignFlagSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG );
    339 #endif
    340   m_cSDCPredModeSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE );
    341 #endif
    342 
     248  m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
     249  m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
     250
     251#if H_3D_DIM
     252  m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
     253  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
     254  m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
     255#if H_3D_DIM_DMM
     256  m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
     257#if !SEC_DMM2_E0146
     258  m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
     259#endif
     260  m_cDmm3DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA );
     261#endif
     262#if H_3D_DIM_RBC
     263  m_cRbcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_RBC_DATA );
     264#endif
     265#if H_3D_DIM_SDC
     266  m_cSDCResidualFlagSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
     267  m_cSDCResidualSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
     268#endif
     269#endif
     270#if LGE_INTER_SDC_E0156
     271  m_cInterSDCFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_FLAG );
     272  m_cInterSDCResidualSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_RESIDUAL );
     273  m_cInterSDCResidualSignFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_SIGN_FLAG );
     274#endif
    343275  m_pcTDecBinIf->start();
    344276}
    345277
    346 Void TDecSbac::readTileMarker( UInt& uiTileIdx, UInt uiBitsUsed )
    347 {
    348   UInt uiSymbol;
    349   uiTileIdx = 0;
    350   for (Int iShift=uiBitsUsed-1; iShift>=0; iShift--)
    351   {
    352     m_pcTDecBinIf->decodeBinEP ( uiSymbol );
    353     if (uiSymbol)
    354     {
    355       uiTileIdx |= (1<<iShift);
    356     }
    357   }
    358 }
    359 
    360278Void TDecSbac::parseTerminatingBit( UInt& ruiBit )
    361279{
    362280  m_pcTDecBinIf->decodeBinTrm( ruiBit );
     281  if ( ruiBit )
     282  {
     283    m_pcTDecBinIf->finish();
     284  }
    363285}
    364286
     
    440362}
    441363
    442 /** Parsing of coeff_abs_level_minus3
    443  * \param ruiSymbol reference to coeff_abs_level_minus3
    444  * \param ruiGoRiceParam reference to Rice parameter
     364
     365/** Parsing of coeff_abs_level_remaing
     366 * \param ruiSymbol reference to coeff_abs_level_remaing
     367 * \param ruiParam reference to parameter
    445368 * \returns Void
    446369 */
    447 Void TDecSbac::xReadGoRiceExGolomb( UInt &ruiSymbol, UInt &ruiGoRiceParam )
    448 {
    449   Bool bExGolomb    = false;
    450   UInt uiCodeWord   = 0;
    451   UInt uiQuotient   = 0;
    452   UInt uiRemainder  = 0;
    453   UInt uiMaxVlc     = g_auiGoRiceRange[ ruiGoRiceParam ];
    454   UInt uiMaxPreLen  = g_auiGoRicePrefixLen[ ruiGoRiceParam ];
    455 
     370Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam )
     371{
     372
     373  UInt prefix   = 0;
     374  UInt codeWord = 0;
    456375  do
    457376  {
    458     uiQuotient++;
    459     m_pcTDecBinIf->decodeBinEP( uiCodeWord );
    460   }
    461   while( uiCodeWord && uiQuotient < uiMaxPreLen );
    462 
    463   uiCodeWord  = 1 - uiCodeWord;
    464   uiQuotient -= uiCodeWord;
    465 
    466   if ( ruiGoRiceParam > 0 )
    467   {
    468     m_pcTDecBinIf->decodeBinsEP( uiRemainder, ruiGoRiceParam );   
    469   }
    470 
    471   ruiSymbol      = uiRemainder + ( uiQuotient << ruiGoRiceParam );
    472   bExGolomb      = ruiSymbol == ( uiMaxVlc + 1 );
    473 
    474   if( bExGolomb )
    475   {
    476     xReadEpExGolomb( uiCodeWord, 0 );
    477     ruiSymbol += uiCodeWord;
    478   }
    479 
    480   ruiGoRiceParam = g_aauiGoRiceUpdate[ ruiGoRiceParam ][ min<UInt>( ruiSymbol, 23 ) ];
     377    prefix++;
     378    m_pcTDecBinIf->decodeBinEP( codeWord );
     379  }
     380  while( codeWord);
     381  codeWord  = 1 - codeWord;
     382  prefix -= codeWord;
     383  codeWord=0;
     384  if (prefix < COEF_REMAIN_BIN_REDUCTION )
     385  {
     386    m_pcTDecBinIf->decodeBinsEP(codeWord,rParam);
     387    rSymbol = (prefix<<rParam) + codeWord;
     388  }
     389  else
     390  {
     391    m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam);
     392    rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord;
     393  }
     394}
     395
     396#if H_3D_DIM
     397Void TDecSbac::xReadExGolombLevel( UInt& ruiSymbol, ContextModel& rcSCModel  )
     398{
     399  UInt uiSymbol;
     400  UInt uiCount = 0;
     401  do
     402  {
     403    m_pcTDecBinIf->decodeBin( uiSymbol, rcSCModel );
     404    uiCount++;
     405  }
     406  while( uiSymbol && ( uiCount != 13 ) );
     407
     408  ruiSymbol = uiCount - 1;
     409
     410  if( uiSymbol )
     411  {
     412    xReadEpExGolomb( uiSymbol, 0 );
     413    ruiSymbol += uiSymbol + 1;
     414  }
    481415
    482416  return;
    483417}
    484418
     419Void TDecSbac::xParseDimDeltaDC( Pel& rValDeltaDC, UInt dimType )
     420{
     421  UInt absValDeltaDC = 0;
     422  xReadExGolombLevel( absValDeltaDC, m_cDdcDataSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) );
     423  rValDeltaDC = (Pel)absValDeltaDC;
     424
     425  if( rValDeltaDC != 0 )
     426  {
     427    UInt uiSign;
     428    m_pcTDecBinIf->decodeBinEP( uiSign );
     429    if ( uiSign )
     430    {
     431      rValDeltaDC = -rValDeltaDC;
     432    }
     433  }
     434}
     435#if H_3D_DIM_DMM
     436Void TDecSbac::xParseDmm1WedgeIdx( UInt& ruiTabIdx, Int iNumBit )
     437{
     438  UInt uiSymbol, uiIdx = 0;
     439  for( Int i = 0; i < iNumBit; i++ )
     440  {
     441    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm1DataSCModel.get(0, 0, 0) );
     442    uiIdx += uiSymbol << i;
     443  }
     444  ruiTabIdx = uiIdx;
     445}
     446#if !SEC_DMM2_E0146
     447Void TDecSbac::xParseDmm2Offset( Int& riOffset )
     448{
     449  Int iDeltaEnd = 0;
     450  if( DMM2_DELTAEND_MAX > 0 )
     451  {
     452    UInt uiFlag = 0;
     453    m_pcTDecBinIf->decodeBin( uiFlag, m_cDmm2DataSCModel.get(0, 0, 0) );
     454
     455    if( uiFlag )
     456    {
     457      UInt uiAbsValMinus1;
     458      UInt uiSymbol;
     459      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm2DataSCModel.get(0, 0, 0) ); uiAbsValMinus1  = uiSymbol;
     460      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm2DataSCModel.get(0, 0, 0) ); uiAbsValMinus1 |= uiSymbol << 1;
     461      iDeltaEnd = uiAbsValMinus1 + 1;
     462      UInt uiSign;
     463      m_pcTDecBinIf->decodeBinEP( uiSign );
     464      if( uiSign )
     465      {
     466        iDeltaEnd = -iDeltaEnd;
     467      }
     468    }
     469  }
     470  riOffset = iDeltaEnd;
     471}
     472#endif
     473Void TDecSbac::xParseDmm3WedgeIdx( UInt& ruiIntraIdx, Int iNumBit )
     474{
     475  UInt uiSymbol, uiIdx = 0;
     476  for( Int i = 0; i < iNumBit; i++ )
     477  {
     478    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm3DataSCModel.get(0, 0, 0) );
     479    uiIdx += uiSymbol << i;
     480  }
     481  ruiIntraIdx = uiIdx;
     482}
     483#endif
     484#if H_3D_DIM_RBC
     485Void TDecSbac::xParseRbcEdge( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     486{
     487  UInt uiSymbol = 0;
     488
     489  // 1. Top(0) or Left(1)
     490  UChar ucLeft;
     491  m_pcTDecBinIf->decodeBinEP( uiSymbol );
     492  ucLeft = uiSymbol;
     493
     494  // 2. Start position (lowest bit first)
     495  UChar ucStart = 0;
     496  for( UInt ui = 0; ui < 6 - uiDepth; ui++ )
     497  {
     498    m_pcTDecBinIf->decodeBinEP( uiSymbol );
     499    ucStart |= (uiSymbol << ui);
     500  }
     501
     502  // 3. Number of edges
     503  UChar ucMax = 0;
     504  for( UInt ui = 0; ui < 7 - uiDepth; ui++ )
     505  {
     506    m_pcTDecBinIf->decodeBinEP( uiSymbol );
     507    ucMax |= (uiSymbol << ui);
     508  }
     509  ucMax++; // +1
     510
     511  // 4. Edges
     512  UChar* pucSymbolList = (UChar*) xMalloc( UChar, 256 * RBC_MAX_EDGE_NUM_PER_4x4 );
     513  for( Int iPtr = 0; iPtr < ucMax; iPtr++ )
     514  {
     515    UChar ucEdge = 0;
     516    UInt  uiReorderEdge = 0;
     517    for( UInt ui = 0; ui < 6; ui++ )
     518    {
     519      m_pcTDecBinIf->decodeBin( uiSymbol, m_cRbcDataSCModel.get( 0, 0, 0 ) );
     520      ucEdge <<= 1;
     521      ucEdge |= uiSymbol;
     522      if( uiSymbol == 0 )
     523        break;
     524    }
     525
     526    switch( ucEdge )
     527    {
     528    case 0 :  // "0"       
     529      uiReorderEdge = 0;
     530      break;
     531    case 2 :  // "10"
     532      uiReorderEdge = 1;
     533      break;
     534    case 6 :  // "110"
     535      uiReorderEdge = 2;
     536      break;
     537    case 14 : // "1110"
     538      uiReorderEdge = 3;
     539      break;
     540    case 30 : // "11110"
     541      uiReorderEdge = 4;
     542      break;
     543    case 62 : // "111110"
     544      uiReorderEdge = 5;
     545      break;
     546    case 63 : // "111111"
     547      uiReorderEdge = 6;
     548      break;
     549    default :
     550      printf("parseIntraEdgeChain: error (unknown code %d)\n",ucEdge);
     551      assert(false);
     552      break;
     553    }
     554    pucSymbolList[iPtr] = uiReorderEdge;
     555  }
     556  /////////////////////
     557  // Edge Reconstruction
     558  Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx );
     559  pcCU->reconPartition( uiAbsPartIdx, uiDepth, ucLeft == 1, ucStart, ucMax, pucSymbolList, pbRegion );
     560  xFree( pucSymbolList );
     561}
     562#endif
     563#if H_3D_DIM_SDC
     564Void TDecSbac::xParseSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSegment )
     565{
     566  assert( pcCU->getSlice()->getIsDepth() );
     567  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
     568  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
     569  assert( uiSegment < 2 );
     570 
     571  UInt uiResidual = 0;
     572  UInt uiBit      = 0;
     573  UInt uiAbsIdx   = 0;
     574  UInt uiSign     = 0;
     575  Int  iIdx       = 0;
     576 
     577#if H_3D_DIM_DLT
     578  UInt uiMaxResidualBits = pcCU->getSlice()->getVPS()->getBitsPerDepthValue( pcCU->getSlice()->getLayerIdInVps() );
     579#else
     580  UInt uiMaxResidualBits = g_bitDepthY;
     581#endif
     582  assert( uiMaxResidualBits <= g_bitDepthY );
     583 
     584  m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
     585 
     586  if (uiResidual)
     587  {
     588    // decode residual sign bit
     589    m_pcTDecBinIf->decodeBinEP(uiSign);
     590   
     591    // decode residual magnitude
     592    // prefix part
     593    UInt uiCount = 0;
     594#if H_3D_DIM_DLT
     595    UInt uiNumDepthValues = pcCU->getSlice()->getVPS()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() );
     596#else
     597    UInt uiNumDepthValues = ((1 << g_bitDepthY)-1);
     598#endif
     599    UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2);
     600    for ( UInt ui = 0; ui < uiPrefixThreshold; ui++)
     601    {
     602      m_pcTDecBinIf->decodeBin( uiBit, m_cSDCResidualSCModel.get(0, 0, 0) );
     603      if ( uiBit == 0 )
     604        break;
     605      else
     606        uiCount++;
     607    }
     608    // suffix part
     609    if ( uiCount == uiPrefixThreshold )
     610    {
     611      for ( UInt ui = 0; ui < numBitsForValue(uiNumDepthValues - uiPrefixThreshold); ui++ )
     612      {
     613        m_pcTDecBinIf->decodeBinEP( uiBit );
     614        uiAbsIdx |= uiBit << ui;
     615      }
     616      uiAbsIdx += uiCount;
     617    }
     618    else
     619      uiAbsIdx = uiCount;
     620   
     621    uiAbsIdx += 1;
     622    iIdx =(Int)(uiSign ? -1 : 1)*uiAbsIdx;
     623  }
     624 
     625  pcCU->setSDCSegmentDCOffset(iIdx, uiSegment, uiAbsPartIdx);
     626}
     627#endif
     628#endif
    485629
    486630/** Parse I_PCM information.
     
    495639{
    496640  UInt uiSymbol;
    497   Int numSubseqIPCM = 0;
    498   Bool readPCMSampleFlag = false;
    499 
    500   if(pcCU->getNumSucIPCM() > 0)
    501   {
    502     readPCMSampleFlag = true;
    503   }
    504   else
    505   {
     641
    506642    m_pcTDecBinIf->decodeBinTrm(uiSymbol);
    507643
     644#if H_MV_ENC_DEC_TRAC
     645      DTRACE_CU("pcm_flag", uiSymbol)
     646#endif
    508647    if (uiSymbol)
    509648    {
    510       readPCMSampleFlag = true;
    511       m_pcTDecBinIf->decodeNumSubseqIPCM(numSubseqIPCM);
    512       pcCU->setNumSucIPCM(numSubseqIPCM + 1);
    513       m_pcTDecBinIf->decodePCMAlignBits();
    514     }
    515   }
    516 
    517   if (readPCMSampleFlag == true)
    518   {
    519649    Bool bIpcmFlag = true;
    520 
    521650
    522651    pcCU->setPartSizeSubParts  ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
    523652    pcCU->setSizeSubParts      ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
     653    pcCU->setTrIdxSubParts     ( 0, uiAbsPartIdx, uiDepth );
    524654    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
    525655
     
    582712    }
    583713
    584     pcCU->setNumSucIPCM( pcCU->getNumSucIPCM() - 1);
    585     if(pcCU->getNumSucIPCM() == 0)
    586     {
    587       m_pcTDecBinIf->resetBac();
    588     }
    589   }
     714    m_pcTDecBinIf->start();
     715  }
     716}
     717
     718Void TDecSbac::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     719{
     720  UInt uiSymbol;
     721  m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) );
     722#if H_MV_ENC_DEC_TRAC
     723  DTRACE_CU("cu_transquant_bypass_flag", uiSymbol);
     724#endif
     725  pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth);
    590726}
    591727
     
    606742  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
    607743  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
     744#if !H_MV_ENC_DEC_TRAC
    608745  DTRACE_CABAC_VL( g_nSymbolCounter++ );
    609746  DTRACE_CABAC_T( "\tSkipFlag" );
     
    613750  DTRACE_CABAC_V( uiSymbol );
    614751  DTRACE_CABAC_T( "\n");
     752#endif
    615753 
    616754  if( uiSymbol )
    617755  {
    618     pcCU->setPredModeSubParts( MODE_SKIP,  uiAbsPartIdx, uiDepth );
     756    pcCU->setSkipFlagSubParts( true,        uiAbsPartIdx, uiDepth );
     757    pcCU->setPredModeSubParts( MODE_INTER,  uiAbsPartIdx, uiDepth );
    619758    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
    620759    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
    621760    pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth );
    622761  }
    623 }
    624 
    625 #if LGE_ILLUCOMP_B0045
    626 /** parse illumination compensation flag
    627  * \param pcCU
    628  * \param uiAbsPartIdx
    629  * \param uiDepth
    630  * \returns Void
    631  */
    632 Void TDecSbac::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    633 {
    634   UInt uiSymbol = 0;
    635   UInt uiCtxIC = pcCU->getCtxICFlag( uiAbsPartIdx );
    636   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, uiCtxIC ) );
    637   DTRACE_CABAC_VL( g_nSymbolCounter++ );
    638   DTRACE_CABAC_T( "\tICFlag" );
    639   DTRACE_CABAC_T( "\tuiCtxIC: ");
    640   DTRACE_CABAC_V( uiCtxIC );
    641   DTRACE_CABAC_T( "\tuiSymbol: ");
    642   DTRACE_CABAC_V( uiSymbol );
    643   DTRACE_CABAC_T( "\n");
    644  
    645   pcCU->setICFlagSubParts( uiSymbol ? true : false , uiAbsPartIdx, 0, uiDepth );
    646 }
    647 #endif
    648 
     762#if H_MV_ENC_DEC_TRAC
     763  DTRACE_CU("cu_skip_flag", uiSymbol);
     764#endif
     765}
    649766
    650767/** parse merge flag
     
    659776  UInt uiSymbol;
    660777  m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) );
     778#if H_MV_ENC_DEC_TRAC
     779  DTRACE_PU("merge_flag", uiSymbol)
     780#endif
    661781  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
    662782
     783#if !H_MV_ENC_DEC_TRAC
    663784  DTRACE_CABAC_VL( g_nSymbolCounter++ );
    664785  DTRACE_CABAC_T( "\tMergeFlag: " );
     
    669790  DTRACE_CABAC_V( uiAbsPartIdx );
    670791  DTRACE_CABAC_T( "\n" );
    671 }
    672 
    673 Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth )
    674 {
    675   UInt uiNumCand = MRG_MAX_NUM_CANDS;
     792#endif
     793}
     794
     795Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex )
     796{
    676797  UInt uiUnaryIdx = 0;
    677   uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
    678 #if HHI_MPI
    679   const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE;
    680   const UInt uiMviMergePos = bMVIAvailable ? HHI_MPI_MERGE_POS : uiNumCand;
    681 #endif
     798  UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
    682799  if ( uiNumCand > 1 )
    683800  {
     
    698815      }
    699816    }
     817#if H_MV_ENC_DEC_TRAC
     818    DTRACE_PU("merge_idx", uiUnaryIdx)
     819#endif
    700820  }
    701821  ruiMergeIndex = uiUnaryIdx;
    702822
     823#if !H_MV_ENC_DEC_TRAC
    703824  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    704825  DTRACE_CABAC_T( "\tparseMergeIndex()" )
     
    706827  DTRACE_CABAC_V( ruiMergeIndex )
    707828  DTRACE_CABAC_T( "\n" )
    708 #if HHI_MPI
    709   if( ruiMergeIndex > uiMviMergePos )
    710   {
    711     assert( bMVIAvailable );
    712     ruiMergeIndex--;
    713   }
    714   else if( ruiMergeIndex == uiMviMergePos )
    715   {
    716     assert( bMVIAvailable );
    717     pcCU->setTextureModeDepthSubParts( uiDepth, uiAbsPartIdx, uiDepth );
    718   }
    719 #endif
    720 }
    721 
    722 #if H3D_IVRP
    723 Void
    724 TDecSbac::parseResPredFlag( TComDataCU* pcCU, Bool& rbResPredFlag, UInt uiAbsPartIdx, UInt uiDepth )
    725 {
    726   UInt uiCtx    = pcCU->getCtxResPredFlag( uiAbsPartIdx );
    727   UInt uiSymbol = 0;
    728   m_pcTDecBinIf->decodeBin( uiSymbol, m_cResPredFlagSCModel.get( 0, 0, uiCtx ) );
    729   rbResPredFlag = ( uiSymbol != 0 );
    730 }
    731 #endif
    732 
    733 #if H3D_IVMP
    734 Void TDecSbac::parseMVPIdx      ( Int& riMVPIdx, Int iNumAMVPCands )
    735 {
    736   UInt uiSymbol;
    737   xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, iNumAMVPCands-1);
    738   riMVPIdx = uiSymbol;
    739 }
    740 #else
     829#endif
     830}
     831
    741832Void TDecSbac::parseMVPIdx      ( Int& riMVPIdx )
    742833{
     
    745836  riMVPIdx = uiSymbol;
    746837}
    747 #endif
    748838
    749839Void TDecSbac::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     
    754844    return;
    755845  }
    756  
     846
    757847  UInt uiSymbol;
    758 
    759 #if H3D_QTL
     848#if H_3D_QTLPC
    760849  Bool bParseSplitFlag    = true;
    761850
     
    765854  Bool bIntraSliceDetect  = (pcCU->getSlice()->getSliceType() == I_SLICE);
    766855
    767   Bool rapPic     = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
    768   if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTLPC())
     856  Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
     857
     858  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL() && sps->getUsePC())
    769859  {
    770860    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
     
    777867#endif
    778868    m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) );
     869#if H_MV_ENC_DEC_TRAC
     870    DTRACE_CU("split_cu_flag", uiSymbol);
     871#else
    779872    DTRACE_CABAC_VL( g_nSymbolCounter++ )
    780873    DTRACE_CABAC_T( "\tSplitFlag\n" )
    781 #if H3D_QTL
     874#endif
     875#if H_3D_QTLPC
    782876  }
    783877  else
     878  {
    784879    uiSymbol = 0;
    785 #endif
    786 
     880  }
     881#endif
    787882  pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
    788883 
     
    801896  PartSize eMode;
    802897
    803 #if H3D_QTL
     898#if H_3D_QTLPC
    804899  Bool bParsePartSize    = true;
    805900  TComSPS *sps           = pcCU->getPic()->getSlice(0)->getSPS();
     
    808903  Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE);
    809904
    810   Bool rapPic     = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
    811   if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTLPC())
     905  Bool rapPic     = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
     906
     907  if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL() && sps->getUsePC())
    812908  {
    813909    TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr());
     
    820916  }
    821917#endif
     918
    822919 
    823920  if ( pcCU->isIntra( uiAbsPartIdx ) )
    824921  {
    825 #if H3D_QTL
     922#if H_3D_QTLPC
    826923    if(bParsePartSize)
    827924    {
    828925#endif
    829       uiSymbol = 1;
     926     uiSymbol = 1;
    830927      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    831928      {
    832929        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) );
     930#if H_MV_ENC_DEC_TRAC         
     931        DTRACE_CU("part_mode", uiSymbol)
     932#endif       
    833933      }
    834934      eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
    835 #if H3D_QTL
     935#if H_3D_QTLPC
    836936    }
    837937#endif
     
    851951  else
    852952  {
    853 #if H3D_QTL
     953#if H_3D_QTLPC
    854954    if(bParsePartSize)
    855955    {
    856956#endif
    857957      UInt uiMaxNumBits = 2;
    858       if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getSlice()->getSPS()->getDisInter4x4() && (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) )
     958      if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) )
    859959      {
    860960        uiMaxNumBits ++;
     
    874974        if (eMode == SIZE_2NxN)
    875975        {
    876             m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 ));
     976          m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 ));
    877977          if (uiSymbol == 0)
    878978          {
     
    891991        }
    892992      }
    893 #if H3D_QTL
     993#if H_MV_ENC_DEC_TRAC         
     994      DTRACE_CU("part_mode", eMode )
     995#endif
     996#if H_3D_QTLPC
    894997    }
    895998#endif
     
    9171020  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) );
    9181021  iPredMode += uiSymbol;
     1022#if H_MV_ENC_DEC_TRAC         
     1023  DTRACE_CU("pred_mode_flag", uiSymbol)
     1024#endif       
    9191025  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
    9201026}
    921 #if PKU_QC_DEPTH_INTRA_UNI_D0195
    922 Void TDecSbac::parseDepthIntraMode  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    923 {
    924   UInt uiPuIdx = ( pcCU->getWidth(uiAbsPartIdx) == 64 )? 2 : ( ( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && pcCU->getWidth(uiAbsPartIdx) == 8 )? 0 : 1);
    925   UInt uiDir = 0;
    926   Bool bSDCFlag = 0;
    927   UInt uiSymbol = 1;
    928   UInt uiCode = 0 ;
    929   UInt uiBinNum = 0;
    930   UInt uiCtxDepthMode = 0;
    931   if ( uiPuIdx ==2 )
    932   {
    933     while(uiBinNum<2 && uiSymbol)
    934     {
    935       uiCtxDepthMode = uiPuIdx*3 + uiBinNum;
    936       m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
    937       uiCode = (uiCode<<1)+uiSymbol;
    938       uiBinNum++;
    939     }
    940     if (uiCode == 0)      { uiDir = PLANAR_IDX; bSDCFlag = 1;}
    941     else if (uiCode == 2) { uiDir = 0;          bSDCFlag = 0;}
    942     else if (uiCode == 3) { uiDir = DC_IDX;     bSDCFlag = 1;}
    943   }
    944   else if ( uiPuIdx ==0 )
    945   {
    946     while(uiBinNum<3 && uiSymbol)
    947     {
    948       uiCtxDepthMode = uiPuIdx*3 + ( uiBinNum >= 2? 2 : uiBinNum );
    949       m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
    950       uiCode = (uiCode<<1)+uiSymbol;
    951       uiBinNum++;
    952     }
    953     if (uiCode == 0)      { uiDir = 0;                     bSDCFlag = 0;}
    954     else if (uiCode == 2) { uiDir = DMM_WEDGE_FULL_IDX;    bSDCFlag = 0;}
    955     else if (uiCode == 6) { uiDir = DMM_WEDGE_PREDTEX_IDX; bSDCFlag = 0;}
    956     else if (uiCode == 7) { uiDir = EDGE_INTRA_IDX;        bSDCFlag = 0;}
    957   }
    958   else
    959   {
    960     uiCtxDepthMode = uiPuIdx*3 ;
    961     m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
    962     uiCode = (uiCode<<1)+uiSymbol;
    963     if (!uiSymbol)
    964     {
    965       uiCtxDepthMode = uiPuIdx*3 + 1;
    966       m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
    967       uiCode = (uiCode<<1)+uiSymbol;
    968       if (uiSymbol)
     1027
     1028Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
     1029{
     1030  PartSize mode = pcCU->getPartitionSize( absPartIdx );
     1031  UInt partNum = mode==SIZE_NxN?4:1;
     1032  UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
     1033  UInt mpmPred[4],symbol;
     1034  Int j,intraPredMode;   
     1035  if (mode==SIZE_NxN)
     1036  {
     1037    depth++;
     1038  }
     1039  for (j=0;j<partNum;j++)
     1040  {
     1041#if H_3D_DIM
     1042    if( pcCU->getSlice()->getVpsDepthModesFlag() )
     1043    {
     1044      parseIntraDepth( pcCU, absPartIdx+partOffset*j, depth );
     1045    }
     1046    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
     1047#if H_3D_DIM_SDC
     1048      if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
     1049#endif
     1050    {
     1051#endif
     1052    m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
     1053    mpmPred[j] = symbol;
     1054#if H_MV_ENC_DEC_TRAC         
     1055    DTRACE_CU("prev_intra_luma_pred_flag", symbol)
     1056#endif
     1057#if H_3D_DIM
     1058    }
     1059#endif
     1060  }
     1061  for (j=0;j<partNum;j++)
     1062  {
     1063#if H_3D_DIM
     1064    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
     1065#if H_3D_DIM_SDC
     1066      if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
     1067#endif
     1068    {
     1069#endif
     1070    Int preds[3] = {-1, -1, -1};
     1071    Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); 
     1072    if (mpmPred[j])
     1073    {
     1074      m_pcTDecBinIf->decodeBinEP( symbol );
     1075      if (symbol)
     1076      {
     1077        m_pcTDecBinIf->decodeBinEP( symbol );
     1078        symbol++;
     1079      }
     1080#if H_MV_ENC_DEC_TRAC         
     1081      DTRACE_CU("mpm_idx", symbol)
     1082#endif
     1083      intraPredMode = preds[symbol];
     1084    }
     1085    else
     1086    {
     1087      m_pcTDecBinIf->decodeBinsEP( symbol, 5 );
     1088      intraPredMode = symbol;
     1089#if H_MV_ENC_DEC_TRAC         
     1090      DTRACE_CU("rem_intra_luma_pred_mode", symbol)
     1091#endif       
     1092      //postponed sorting of MPMs (only in remaining branch)
     1093      if (preds[0] > preds[1])
    9691094      {
    970         uiCtxDepthMode = uiPuIdx*3 + 2;
    971         m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
    972         uiCode = (uiCode<<1)+uiSymbol;
    973       }
    974     }
    975     else
    976     {
    977       uiCtxDepthMode = uiPuIdx*3 + 1;
    978       m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
    979       uiCode = (uiCode<<1)+uiSymbol;
    980       if (!uiSymbol)
    981       {
    982         uiCtxDepthMode = uiPuIdx*3 + 2;
    983         m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
    984         uiCode = (uiCode<<1)+uiSymbol;
    985       }
    986       else
    987       {
    988         uiBinNum = 0;
    989         while( uiSymbol && uiBinNum<3 )
    990         {
    991           uiCtxDepthMode = uiPuIdx*3 + 2;
    992           m_pcTDecBinIf->decodeBin(uiSymbol,m_cDepthModeModel.get(0,0,uiCtxDepthMode));
    993           uiCode = (uiCode<<1)+uiSymbol;
    994           uiBinNum++;
    995         }
    996       }
    997     }
    998     if (uiCode == 0)       { uiDir = PLANAR_IDX;              bSDCFlag = 1;}
    999     else if (uiCode == 2)  { uiDir = 5;                       bSDCFlag = 0;}
    1000     else if (uiCode == 3)  { uiDir = DMM_WEDGE_FULL_IDX;      bSDCFlag = 1;}
    1001     else if (uiCode == 4)  { uiDir = DMM_WEDGE_FULL_IDX;      bSDCFlag = 0;}
    1002     else if (uiCode == 5)  { uiDir = DMM_CONTOUR_PREDTEX_IDX; bSDCFlag = 0;}
    1003     else if (uiCode == 6)  { uiDir = DMM_WEDGE_PREDTEX_IDX;   bSDCFlag = 0;}
    1004     else if (uiCode == 14) { uiDir = DC_IDX;                  bSDCFlag = 1;}
    1005     else if (uiCode == 31) { uiDir = DMM_WEDGE_PREDDIR_IDX;   bSDCFlag = 0;}
    1006     else if (uiCode == 30) { uiDir = EDGE_INTRA_IDX;          bSDCFlag = 0;}
    1007   }
    1008   pcCU->setLumaIntraDirSubParts( (UChar)uiDir, uiAbsPartIdx, uiDepth );
    1009   pcCU->setSDCFlagSubParts(bSDCFlag, uiAbsPartIdx, 0, uiDepth);
    1010 }
    1011 Void TDecSbac::parseDepthModelingTable  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    1012 {
    1013   parseDepthIntraMode(pcCU,uiAbsPartIdx,uiDepth);
    1014  
    1015   UInt uiDir = pcCU->getLumaIntraDir(uiAbsPartIdx);
    1016   Bool bSdcFlag =  pcCU->getSDCAvailable(uiAbsPartIdx) && pcCU->getSDCFlag(uiAbsPartIdx);
    1017   Bool bDmmFlag = (uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX &&(!bSdcFlag))? 1:0;
    1018   if (uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX)//DMM modes and SDC DMM1
    1019   {
    1020     if( uiDir == DMM_WEDGE_FULL_IDX )          { xParseWedgeFullInfo          ( pcCU, uiAbsPartIdx, uiDepth ); }
    1021     else if( uiDir == DMM_WEDGE_PREDTEX_IDX )  { xParseWedgePredTexInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
    1022     else if( uiDir == DMM_WEDGE_PREDDIR_IDX )  { xParseWedgePredDirInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
    1023   }
    1024   else if(uiDir >= EDGE_INTRA_IDX)//CCM mode
    1025   {
    1026     xParseEdgeIntraInfo( pcCU, uiAbsPartIdx, uiDepth );
    1027   }
    1028  
     1095        std::swap(preds[0], preds[1]);
     1096      }
     1097      if (preds[0] > preds[2])
     1098      {
     1099        std::swap(preds[0], preds[2]);
     1100      }
     1101      if (preds[1] > preds[2])
     1102      {
     1103        std::swap(preds[1], preds[2]);
     1104      }
     1105      for ( Int i = 0; i < predNum; i++ )
     1106      {
     1107        intraPredMode += ( intraPredMode >= preds[i] );
     1108      }
     1109    }
     1110    pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
     1111#if H_3D_DIM
     1112    }
     1113#endif
     1114  }
     1115}
     1116
     1117Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     1118{
    10291119  UInt uiSymbol;
    1030   if (bDmmFlag)
    1031   {
    1032     if (bDmmFlag)
    1033     {
    1034       m_pcTDecBinIf->decodeBin( uiSymbol , m_cDmmDeltaFlagModel.get(0, 0, 0) );
    1035       uiDir += uiSymbol;
    1036     }
    1037     if (uiSymbol)
    1038     {
    1039       UInt uiDC;
    1040       Int iDC = 0,iDC1 = 0,iDC2 = 0;
    1041       for ( Int i = 0; i  <2; i++ )
    1042       {
    1043         xReadExGolombLevel( uiDC, m_cDmmDataSCModel.get(0, 0, 1) );
    1044         iDC = uiDC;
    1045         if ( uiDC )
    1046         {
    1047           UInt uiSign;
    1048           m_pcTDecBinIf->decodeBinEP( uiSign );
    1049           if ( uiSign )
    1050           {
    1051             iDC = -iDC;
    1052           }
    1053         }
    1054         if ( i == 0 ) { iDC1 = iDC; }
    1055         else          { iDC2 = iDC; }
    1056       }
    1057 
    1058       if( uiDir == DMM_WEDGE_FULL_D_IDX )   
    1059       {
    1060         pcCU->setWedgeFullDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
    1061         pcCU->setWedgeFullDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
    1062       }
    1063       else if( uiDir == DMM_WEDGE_PREDDIR_D_IDX )
    1064       {
    1065         pcCU->setWedgePredDirDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
    1066         pcCU->setWedgePredDirDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
    1067       }
    1068       else if( uiDir == DMM_WEDGE_PREDTEX_D_IDX) 
    1069       {
    1070         pcCU->setWedgePredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
    1071         pcCU->setWedgePredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
    1072       }
    1073       else if (uiDir== DMM_CONTOUR_PREDTEX_D_IDX )
    1074       {
    1075         pcCU->setContourPredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
    1076         pcCU->setContourPredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
    1077       }
    1078     }
    1079   }
    1080   else if (uiDir >= EDGE_INTRA_IDX)
    1081   {
    1082     m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
    1083     if( uiSymbol )
    1084     {
    1085       uiDir = EDGE_INTRA_DELTA_IDX;
    1086       Int iDeltaDC = 0,iDeltaDC0 = 0,iDeltaDC1 = 0;
    1087       for (Int i = 0; i<2; i++)
    1088       {
    1089         xReadExGolombLevel( (UInt &) iDeltaDC, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
    1090         if( iDeltaDC != 0 )
    1091         {
    1092           UInt uiSign;
    1093           m_pcTDecBinIf->decodeBinEP( uiSign );
    1094           if ( uiSign )
    1095           {
    1096             iDeltaDC = -iDeltaDC;
    1097           }
    1098         }
    1099         if ( i == 0 ) { iDeltaDC0 = iDeltaDC; }
    1100         else          { iDeltaDC1 = iDeltaDC; }
    1101       }
    1102 
    1103       pcCU->setEdgeDeltaDC0( uiAbsPartIdx, iDeltaDC0 );
    1104       pcCU->setEdgeDeltaDC1( uiAbsPartIdx, iDeltaDC1 );
    1105     }
    1106   }
    1107   else if(bSdcFlag)//SDC mode
    1108   {
    1109     assert(pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_NxN);
    1110     pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth);
    1111     pcCU->setCbfSubParts(1, 1, 1, uiAbsPartIdx, uiDepth);
    1112 
    1113     UInt uiNumSegments = ( uiDir == DC_IDX || uiDir == PLANAR_IDX )? 1 : 2;
    1114     for (int uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
    1115     {
    1116       parseSDCResidualData(pcCU, uiAbsPartIdx, uiDepth, uiSeg);
    1117     }
    1118   }
    1119 
    1120   pcCU->setLumaIntraDirSubParts( (UChar)uiDir, uiAbsPartIdx, uiDepth );
    1121 }
    1122 #endif
    1123 Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    1124 {
    1125   UInt uiSymbol;
    1126   Int  intraPredMode;
    1127 #if PKU_QC_DEPTH_INTRA_UNI_D0195
    1128   if (pcCU->getSlice()->getSPS()->isDepth())
    1129   {
    1130     parseDepthModelingTable(pcCU, uiAbsPartIdx, uiDepth);
    1131   }
    1132   if (pcCU->getLumaIntraDir(uiAbsPartIdx)<NUM_INTRA_MODE && !pcCU->getSDCFlag(uiAbsPartIdx))
    1133   {
    1134 #else
    1135 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    1136   UInt uiFlag = 0;
    1137   if( pcCU->getSlice()->getSPS()->getUseDMM() && (g_uiMaxCUWidth>>uiDepth) <= DMM_WEDGEMODEL_MAX_SIZE )
    1138   {
    1139     m_pcTDecBinIf->decodeBin( uiFlag, m_cDmmFlagSCModel.get(0, 0, 0) );
    1140   }
    1141   if( uiFlag )
    1142   {
    1143     UInt uiDMMode;
    1144 
    1145 #if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX
    1146     m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode  = uiSymbol;
    1147     m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode |= uiSymbol << 1;
    1148     if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && g_uiMaxCUWidth>>uiDepth > 4 )
    1149     {
    1150       m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode |= uiSymbol << 2;
    1151     }
    1152 #else
    1153     m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode  = uiSymbol;
    1154     if ( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && g_uiMaxCUWidth>>uiDepth > 4 )
    1155     {
    1156       m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get(0, 0, 0) ); uiDMMode |= uiSymbol << 1;
    1157     }
    1158 #endif
    1159     intraPredMode = uiDMMode + NUM_INTRA_MODE;
    1160 
    1161 #if HHI_DMM_WEDGE_INTRA
    1162     if( intraPredMode == DMM_WEDGE_FULL_IDX )          { xParseWedgeFullInfo          ( pcCU, uiAbsPartIdx, uiDepth ); }
    1163     if( intraPredMode == DMM_WEDGE_FULL_D_IDX )        { xParseWedgeFullDeltaInfo     ( pcCU, uiAbsPartIdx, uiDepth ); }
    1164     if( intraPredMode == DMM_WEDGE_PREDDIR_IDX )       { xParseWedgePredDirInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
    1165     if( intraPredMode == DMM_WEDGE_PREDDIR_D_IDX )     { xParseWedgePredDirDeltaInfo  ( pcCU, uiAbsPartIdx, uiDepth ); }
    1166 #endif
    1167 #if HHI_DMM_PRED_TEX
    1168     if( intraPredMode == DMM_WEDGE_PREDTEX_D_IDX )     { xParseWedgePredTexDeltaInfo  ( pcCU, uiAbsPartIdx, uiDepth ); }
    1169 #if LGE_DMM3_SIMP_C0044
    1170     if( intraPredMode == DMM_WEDGE_PREDTEX_IDX )       { xParseWedgePredTexInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
    1171 #endif
    1172     if( intraPredMode == DMM_CONTOUR_PREDTEX_D_IDX )   { xParseContourPredTexDeltaInfo( pcCU, uiAbsPartIdx, uiDepth ); }
    1173 #endif
    1174   }
    1175   else
    1176   {
    1177 #endif
    1178 
    1179 #if LGE_EDGE_INTRA_A0070
    1180     Bool bCodeEdgeIntra = false;
    1181     if( pcCU->getSlice()->getSPS()->isDepth() )
    1182     {
    1183       UInt uiPUWidth = pcCU->getWidth( uiAbsPartIdx ) >> (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0);
    1184       if( uiPUWidth <= LGE_EDGE_INTRA_MAX_SIZE && uiPUWidth >= LGE_EDGE_INTRA_MIN_SIZE )
    1185         bCodeEdgeIntra = true;
    1186     }
    1187 #endif
    1188 #endif
    1189     Int uiPreds[3] = {-1, -1, -1};
    1190     Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); 
    1191 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    1192 #if LGE_EDGE_INTRA_A0070
    1193     UInt uiCheckBit = 0;
    1194 #endif
    1195 #endif
    1196 
    1197     m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
    1198 
    1199     if ( uiSymbol )
    1200     {
    1201       m_pcTDecBinIf->decodeBinEP( uiSymbol );
    1202       if (uiSymbol)
    1203       {
    1204         m_pcTDecBinIf->decodeBinEP( uiSymbol );
    1205         uiSymbol++;
    1206       }
    1207       intraPredMode = uiPreds[uiSymbol];
    1208     }
    1209     else
    1210     {
    1211       intraPredMode = 0;
    1212 
    1213 
    1214       m_pcTDecBinIf->decodeBinsEP( uiSymbol, 5 );
    1215 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    1216 #if LGE_EDGE_INTRA_A0070
    1217       if (bCodeEdgeIntra)
    1218       {
    1219         if (uiSymbol==31)
    1220         {
    1221           m_pcTDecBinIf->decodeBinsEP(uiCheckBit,1);
    1222           if (uiCheckBit)
    1223             uiSymbol = EDGE_INTRA_IDX;
    1224         }
    1225       }
    1226 #endif
    1227 #endif
    1228       intraPredMode = uiSymbol;
    1229 
    1230       //postponed sorting of MPMs (only in remaining branch)
    1231       if (uiPreds[0] > uiPreds[1])
    1232       {
    1233         std::swap(uiPreds[0], uiPreds[1]);
    1234       }
    1235       if (uiPreds[0] > uiPreds[2])
    1236       {
    1237         std::swap(uiPreds[0], uiPreds[2]);
    1238       }
    1239       if (uiPreds[1] > uiPreds[2])
    1240       {
    1241         std::swap(uiPreds[1], uiPreds[2]);
    1242       }
    1243 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    1244 #if LGE_EDGE_INTRA_A0070
    1245       if ( intraPredMode != EDGE_INTRA_IDX)
    1246       {
    1247 #endif
    1248 #endif
    1249         for ( Int i = 0; i < uiPredNum; i++ )
    1250         {
    1251           intraPredMode += ( intraPredMode >= uiPreds[i] );
    1252         }
    1253 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    1254 #if LGE_EDGE_INTRA_A0070
    1255       }
    1256 #endif
    1257 #endif
    1258     }
    1259 
    1260 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    1261 #if LGE_EDGE_INTRA_A0070
    1262     if( intraPredMode == EDGE_INTRA_IDX )
    1263     {
    1264       xParseEdgeIntraInfo( pcCU, uiAbsPartIdx, uiDepth );
    1265 #if LGE_EDGE_INTRA_DELTA_DC
    1266       m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
    1267       if( uiSymbol )
    1268       {
    1269         intraPredMode = EDGE_INTRA_DELTA_IDX;
    1270         Int iDeltaDC0;
    1271         Int iDeltaDC1;
    1272 
    1273         xReadExGolombLevel( (UInt &) iDeltaDC0, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
    1274         if( iDeltaDC0 != 0 )
    1275         {
    1276           UInt uiSign;
    1277           m_pcTDecBinIf->decodeBinEP( uiSign );
    1278           if ( uiSign )
    1279           {
    1280             iDeltaDC0 = -iDeltaDC0;
    1281           }
    1282         }
    1283         xReadExGolombLevel( (UInt &) iDeltaDC1, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
    1284         if( iDeltaDC1 != 0 )
    1285         {
    1286           UInt uiSign;
    1287           m_pcTDecBinIf->decodeBinEP( uiSign );
    1288           if ( uiSign )
    1289           {
    1290             iDeltaDC1 = -iDeltaDC1;
    1291           }
    1292         }
    1293 
    1294         pcCU->setEdgeDeltaDC0( uiAbsPartIdx, iDeltaDC0 );
    1295         pcCU->setEdgeDeltaDC1( uiAbsPartIdx, iDeltaDC1 );
    1296       }
    1297 #endif
    1298     }
    1299 #endif
    1300 
    1301 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    1302   }
    1303 #endif
    1304   pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, uiAbsPartIdx, uiDepth );
    1305 #else
    1306   pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, uiAbsPartIdx, uiDepth );
    1307 }
    1308 #endif
    1309 }
    1310 
    1311 Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    1312 {
    1313   UInt uiSymbol;
    13141120
    13151121  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
     
    13171123  if( uiSymbol == 0 )
    13181124  {
     1125#if H_MV_ENC_DEC_TRAC         
     1126    DTRACE_CU("intra_chroma_pred_mode", uiSymbol )
     1127#endif       
    13191128    uiSymbol = DM_CHROMA_IDX;
    13201129  }
    13211130  else
    13221131  {
    1323     if( pcCU->getSlice()->getSPS()->getUseLMChroma() )
    1324     {
    1325       m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 1 ) );
    1326     }
    1327     else
    1328     {
    1329       uiSymbol = 1;
    1330     }
    1331 
    1332     if( uiSymbol == 0 )
    1333     {
    1334       uiSymbol = LM_CHROMA_IDX;
    1335     }
    1336     else
    13371132    {
    13381133      UInt uiIPredMode;
    13391134      m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 );
     1135#if H_MV_ENC_DEC_TRAC         
     1136      DTRACE_CU("intra_chroma_pred_mode", uiIPredMode )
     1137#endif       
    13401138      UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
    13411139      pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
     
    13471145}
    13481146
    1349 Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth )
     1147#if H_3D_DIM
     1148Void TDecSbac::parseIntraDepth( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
     1149{
     1150  parseIntraDepthMode( pcCU, absPartIdx, depth );
     1151
     1152  UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
     1153  UInt dimType = getDimType( dir );
     1154
     1155  switch( dimType )
     1156  {
     1157#if H_3D_DIM_DMM
     1158  case( DMM1_IDX ):
     1159    {
     1160      UInt uiTabIdx = 0;
     1161      xParseDmm1WedgeIdx( uiTabIdx, g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
     1162      pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, absPartIdx, depth );
     1163    } break;
     1164#if !SEC_DMM2_E0146
     1165  case( DMM2_IDX ):
     1166    {
     1167      Int iOffset = 0;
     1168      xParseDmm2Offset( iOffset );
     1169      pcCU->setDmm2DeltaEndSubParts( iOffset, absPartIdx, depth );
     1170    } break;
     1171#endif
     1172  case( DMM3_IDX ):
     1173    {
     1174      UInt uiIntraIdx = 0;
     1175      xParseDmm3WedgeIdx( uiIntraIdx, g_dmm3IntraTabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
     1176      pcCU->setDmm3IntraTabIdxSubParts( uiIntraIdx, absPartIdx, depth );
     1177    } break;
     1178  case( DMM4_IDX ): break;
     1179#endif
     1180#if H_3D_DIM_RBC
     1181  case( RBC_IDX ):
     1182    {
     1183      xParseRbcEdge( pcCU, absPartIdx, depth );
     1184    } break;
     1185#endif
     1186  default: break;
     1187  }
     1188
     1189#if H_3D_DIM_SDC
     1190  if( pcCU->getSDCFlag(absPartIdx) )
     1191  {
     1192    assert(pcCU->getPartitionSize(absPartIdx)==SIZE_2Nx2N);
     1193    pcCU->setTrIdxSubParts(0, absPartIdx, depth);
     1194    pcCU->setCbfSubParts(1, 1, 1, absPartIdx, depth);
     1195
     1196    UInt uiNumSegments = ( dir == DC_IDX || dir == PLANAR_IDX )? 1 : 2;
     1197    for (UInt uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
     1198    {
     1199      xParseSDCResidualData(pcCU, absPartIdx, depth, uiSeg);
     1200    }
     1201  }
     1202  else
     1203  {
     1204#endif
     1205    if( dimType < DIM_NUM_TYPE )
     1206    {
     1207      UInt symbol;
     1208      m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) );
     1209      if( symbol )
     1210      {
     1211        dir += symbol;
     1212        for( UInt segment = 0; segment < 2; segment++ )
     1213        {
     1214          Pel valDeltaDC = 0;
     1215          xParseDimDeltaDC( valDeltaDC, dimType );
     1216          pcCU->setDimDeltaDC( dimType, segment, absPartIdx, valDeltaDC );
     1217        }
     1218      }
     1219    }
     1220#if H_3D_DIM_SDC
     1221  }
     1222#endif
     1223
     1224  pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
     1225}
     1226
     1227Void TDecSbac::parseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
     1228{
     1229  UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 );
     1230  UInt dir = 0;
     1231  Bool sdcFlag = 0;
     1232  UInt symbol = 1;
     1233  UInt modeCode = 0 ;
     1234  UInt binNum = 0;
     1235  UInt ctxDepthMode = 0;
     1236
     1237  if( puIdx == 2 )
     1238  {
     1239#if !LGE_SDC_REMOVE_DC_E0158
     1240    while( binNum < 2 && symbol )
     1241#endif
     1242    {
     1243      ctxDepthMode = puIdx*3 + binNum;
     1244      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
     1245      modeCode = (modeCode<<1) + symbol;
     1246      binNum++;
     1247    }
     1248         if( modeCode == 0 ) { dir = PLANAR_IDX; sdcFlag = 1;}
     1249#if LGE_SDC_REMOVE_DC_E0158
     1250    else if( modeCode == 1 ) { dir = 0;          sdcFlag = 0;}
     1251#else
     1252    else if( modeCode == 2 ) { dir = 0;          sdcFlag = 0;}
     1253    else if( modeCode == 3 ) { dir =     DC_IDX; sdcFlag = 1;}
     1254#endif
     1255  }
     1256  else if( puIdx == 0 )
     1257  {
     1258    while( binNum < 3 && symbol )
     1259    {
     1260      ctxDepthMode = puIdx*3 + ((binNum >= 2) ? 2 : binNum);
     1261      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
     1262      modeCode = (modeCode<<1) + symbol;
     1263      binNum++;
     1264    }
     1265         if( modeCode == 0 ) { dir = 0;                       sdcFlag = 0;}
     1266    else if( modeCode == 2 ) { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 0;}
     1267    else if( modeCode == 6 ) { dir = (2*DMM3_IDX+DIM_OFFSET); sdcFlag = 0;}
     1268    else if( modeCode == 7 ) { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
     1269  }
     1270  else
     1271  {
     1272#if ZJU_DEPTH_INTRA_MODE_E0204
     1273      UInt maxBinNum = 0;
     1274      m_pcTDecBinIf->decodeBinEP(symbol);
     1275      if( symbol == 1 )
     1276      {
     1277          maxBinNum = 3;
     1278      }
     1279      else
     1280      {
     1281          maxBinNum = 2;
     1282          symbol = 1;
     1283      }
     1284      while( binNum<maxBinNum && symbol )
     1285      {
     1286          ctxDepthMode = puIdx*3 + ( binNum >= 2 ? 2 : binNum );
     1287          m_pcTDecBinIf->decodeBin(symbol,m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode));
     1288          modeCode = (modeCode<<1)+symbol;
     1289          binNum++;
     1290      }
     1291      if( maxBinNum == 3 )
     1292      {
     1293          if ( modeCode == 0 )       { dir =  PLANAR_IDX;             sdcFlag = 1;}
     1294          else if ( modeCode == 2 )  { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
     1295          else if ( modeCode == 6 )  { dir = (2*DMM3_IDX+DIM_OFFSET); sdcFlag = 0;}
     1296          else if ( modeCode == 7 )  { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 0;}
     1297      }
     1298      else
     1299      {
     1300          if ( modeCode == 0 )       { dir = 5;                       sdcFlag = 0;}
     1301          else if ( modeCode == 2 )  { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 1;}
     1302          else if ( modeCode == 3 )  { dir = (2*DMM4_IDX+DIM_OFFSET); sdcFlag = 0;}
     1303      }
     1304#else
     1305    ctxDepthMode = puIdx*3 ;
     1306    m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
     1307    modeCode = (modeCode<<1) + symbol;
     1308    if( !symbol )
     1309    {
     1310      ctxDepthMode = puIdx*3 + 1;
     1311      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
     1312      modeCode = (modeCode<<1) + symbol;
     1313      if( symbol )
     1314      {
     1315        ctxDepthMode = puIdx*3 + 2;
     1316        m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
     1317        modeCode = (modeCode<<1) + symbol;
     1318      }
     1319    }
     1320    else
     1321    {
     1322      ctxDepthMode = puIdx*3 + 1;
     1323      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
     1324      modeCode = (modeCode<<1) + symbol;
     1325      if( !symbol )
     1326      {
     1327        ctxDepthMode = puIdx*3 + 2;
     1328        m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
     1329        modeCode = (modeCode<<1) + symbol;
     1330      }
     1331      else
     1332      {
     1333        binNum = 0;
     1334#if LGE_SDC_REMOVE_DC_E0158
     1335#if !SEC_DMM2_E0146
     1336        while( symbol && binNum < 2 )
     1337#endif
     1338#else
     1339#if SEC_DMM2_E0146
     1340        while( symbol && binNum < 2 )
     1341#else
     1342        while( symbol && binNum < 3 )
     1343#endif
     1344#endif
     1345        {
     1346          ctxDepthMode = puIdx*3 + 2;
     1347          m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
     1348          modeCode = (modeCode<<1) + symbol;
     1349          binNum++;
     1350        }
     1351      }
     1352    }
     1353         if( modeCode == 0  ) { dir =  PLANAR_IDX;             sdcFlag = 1;}
     1354    else if( modeCode == 2  ) { dir = 5;                       sdcFlag = 0;}
     1355    else if( modeCode == 3  ) { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 1;}
     1356    else if( modeCode == 4  ) { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 0;}
     1357    else if( modeCode == 5  ) { dir = (2*DMM4_IDX+DIM_OFFSET); sdcFlag = 0;}
     1358    else if( modeCode == 6  ) { dir = (2*DMM3_IDX+DIM_OFFSET); sdcFlag = 0;}
     1359#if LGE_SDC_REMOVE_DC_E0158
     1360#if SEC_DMM2_E0146
     1361    else if( modeCode == 7 )  { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
     1362#else
     1363    else if( modeCode == 14 ) { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
     1364    else if( modeCode == 15 ) { dir = (2*DMM2_IDX+DIM_OFFSET); sdcFlag = 0;}
     1365#endif
     1366#else
     1367    else if( modeCode == 14 ) { dir =      DC_IDX;             sdcFlag = 1;}
     1368#if SEC_DMM2_E0146
     1369    else if( modeCode == 15 ) { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
     1370#else
     1371    else if( modeCode == 30 ) { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
     1372    else if( modeCode == 31 ) { dir = (2*DMM2_IDX+DIM_OFFSET); sdcFlag = 0;}
     1373#endif
     1374#endif
     1375#endif
     1376  }
     1377  pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
     1378#if H_3D_DIM_SDC
     1379  pcCU->setSDCFlagSubParts( sdcFlag, absPartIdx, depth );
     1380#endif
     1381}
     1382#endif
     1383
     1384Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
    13501385{
    13511386  UInt uiSymbol;
    13521387  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
    13531388  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
    1354   m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
     1389  uiSymbol = 0;
     1390  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
     1391  {
     1392    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
     1393  }
    13551394
    13561395  if( uiSymbol )
    13571396  {
    13581397    uiSymbol = 2;
     1398  }
     1399  else
     1400  {
     1401    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) );
     1402    assert(uiSymbol == 0 || uiSymbol == 1);
    13591403  }
    13601404
    13611405  uiSymbol++;
    13621406  ruiInterDir = uiSymbol;
     1407#if H_MV_ENC_DEC_TRAC
     1408    DTRACE_PU("inter_pred_idc", ruiInterDir - 1 )   
     1409#endif
     1410
    13631411  return;
    13641412}
    13651413
    1366 Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList )
     1414Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
    13671415{
    13681416  UInt uiSymbol;
    1369 
    1370   if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C)
    13711417  {
    13721418    ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
     
    13751421    if( uiSymbol )
    13761422    {
    1377       xReadUnaryMaxSymbol( uiSymbol, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C )-2 );
    1378       uiSymbol++;
     1423      UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
     1424      pCtx++;
     1425      UInt ui;
     1426      for( ui = 0; ui < uiRefNum; ++ui )
     1427      {
     1428        if( ui == 0 )
     1429        {
     1430          m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
     1431        }
     1432        else
     1433        {
     1434          m_pcTDecBinIf->decodeBinEP( uiSymbol );
     1435        }
     1436        if( uiSymbol == 0 )
     1437        {
     1438          break;
     1439        }
     1440      }
     1441      uiSymbol = ui + 1;
    13791442    }
    13801443    riRefFrmIdx = uiSymbol;
    13811444  }
     1445
     1446#if H_MV_ENC_DEC_TRAC
     1447#if ENC_DEC_TRACE
     1448  if ( eRefList == REF_PIC_LIST_0 )
     1449  {
     1450    DTRACE_PU("ref_idx_l0", uiSymbol)
     1451  }
    13821452  else
    13831453  {
    1384     ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
    1385     m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
    1386 
    1387     if( uiSymbol )
    1388     {
    1389       xReadUnaryMaxSymbol( uiSymbol, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 );
    1390       uiSymbol++;
    1391     }
    1392     riRefFrmIdx = uiSymbol;
    1393   }
    1394 
     1454    DTRACE_PU("ref_idx_l1", uiSymbol)
     1455  }
     1456#endif
     1457#endif
    13951458  return;
    13961459}
     
    14121475  else
    14131476  {
    1414 
    14151477    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
    14161478    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
     
    14651527{
    14661528  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
     1529#if !H_MV_ENC_DEC_TRAC
    14671530  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    14681531  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
     
    14721535  DTRACE_CABAC_V( uiLog2TransformBlockSize )
    14731536  DTRACE_CABAC_T( "\n" )
    1474 }
    1475 
    1476 Void TDecSbac::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf )
     1537#endif
     1538}
     1539
     1540Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
    14771541{
    14781542  UInt uiSymbol;
    14791543  const UInt uiCtx = 0;
    14801544  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
     1545#if !H_MV_ENC_DEC_TRAC
    14811546  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    14821547  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
     
    14881553  DTRACE_CABAC_V( uiAbsPartIdx )
    14891554  DTRACE_CABAC_T( "\n" )
     1555#else
     1556  DTRACE_CU( "rqt_root_cbf", uiSymbol )
     1557#endif
    14901558 
    14911559  uiQtRootCbf = uiSymbol;
     
    14981566  Int  iDQp;
    14991567 
    1500   m_pcTDecBinIf->decodeBin( uiDQp, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) );
    1501  
    1502   if ( uiDQp == 0 )
    1503   {
    1504     qp = pcCU->getRefQP(uiAbsPartIdx);
    1505   }
    1506   else
     1568  UInt uiSymbol;
     1569
     1570  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
     1571
     1572  if( uiDQp >= CU_DQP_TU_CMAX)
     1573  {
     1574    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k );
     1575    uiDQp+=uiSymbol;
     1576  }
     1577
     1578  if ( uiDQp > 0 )
    15071579  {
    15081580    UInt uiSign;
    15091581    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
    15101582    m_pcTDecBinIf->decodeBinEP(uiSign);
    1511 
    1512     UInt uiMaxAbsDQpMinus1 = 24 + (qpBdOffsetY/2) + (uiSign);
    1513     UInt uiAbsDQpMinus1;
    1514     xReadUnaryMaxSymbol (uiAbsDQpMinus1,  &m_cCUDeltaQpSCModel.get( 0, 0, 1 ), 1, uiMaxAbsDQpMinus1);
    1515 
    1516     iDQp = uiAbsDQpMinus1 + 1;
    1517 
     1583    iDQp = uiDQp;
    15181584    if(uiSign)
    15191585    {
    15201586      iDQp = -iDQp;
    15211587    }
    1522 
    15231588    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
    15241589  }
    1525  
    1526   UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)))<<(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)) ;
    1527   UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
    1528   pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
     1590  else
     1591  {
     1592    qp = pcCU->getRefQP(uiAbsPartIdx);
     1593  }
     1594  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); 
     1595  pcCU->setCodedQP(qp);
    15291596}
    15301597
     
    15321599{
    15331600  UInt uiSymbol;
    1534   const UInt uiCtx = pcCU->getCtxQtCbf( uiAbsPartIdx, eType, uiTrDepth );
     1601  const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
    15351602  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
    1536  
     1603#if !H_MV_ENC_DEC_TRAC 
    15371604  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    15381605  DTRACE_CABAC_T( "\tparseQtCbf()" )
     
    15461613  DTRACE_CABAC_V( uiAbsPartIdx )
    15471614  DTRACE_CABAC_T( "\n" )
     1615#endif
    15481616 
    15491617  pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
     1618}
     1619
     1620void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType)
     1621{
     1622  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
     1623  {
     1624    return;
     1625  }
     1626  if(width != 4 || height != 4)
     1627  {
     1628    return;
     1629  }
     1630 
     1631  UInt useTransformSkip;
     1632  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
     1633  if(eTType!= TEXT_LUMA)
     1634  {
     1635    const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth;
     1636    if(uiLog2TrafoSize == 2)
     1637    {
     1638      uiDepth --;
     1639    }
     1640  }
     1641#if !H_MV_ENC_DEC_TRAC
     1642  DTRACE_CABAC_VL( g_nSymbolCounter++ )
     1643  DTRACE_CABAC_T("\tparseTransformSkip()");
     1644  DTRACE_CABAC_T( "\tsymbol=" )
     1645  DTRACE_CABAC_V( useTransformSkip )
     1646  DTRACE_CABAC_T( "\tAddr=" )
     1647  DTRACE_CABAC_V( pcCU->getAddr() )
     1648  DTRACE_CABAC_T( "\tetype=" )
     1649  DTRACE_CABAC_V( eTType )
     1650  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
     1651  DTRACE_CABAC_V( uiAbsPartIdx )
     1652  DTRACE_CABAC_T( "\n" )
     1653#endif
     1654
     1655  pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth);
    15501656}
    15511657
     
    15661672  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
    15671673
     1674  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
     1675  blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
     1676  blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
     1677  shiftX= eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
     1678  shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
    15681679  // posX
    1569   Int widthCtx = eTType ? 4 : width;
    1570   const UInt *puiCtxIdxX = g_uiLastCtx + ( g_aucConvertToBit[ widthCtx ] * ( g_aucConvertToBit[ widthCtx ] + 3 ) );
    15711680  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
    15721681  {
    1573     if ( eTType  )
    1574     {
    1575       m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + (uiPosLastX>>g_aucConvertToBit[ width ])  ) );
    1576     }
    1577     else
    1578     {
    1579       m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + puiCtxIdxX[ uiPosLastX ] ) );
    1580     }
     1682    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) );
    15811683    if( !uiLast )
    15821684    {
     
    15861688
    15871689  // posY
    1588   Int heightCtx = eTType? 4 : height;
    1589   const UInt *puiCtxIdxY = g_uiLastCtx + ( g_aucConvertToBit[ heightCtx ] * ( g_aucConvertToBit[ heightCtx ] + 3 ) );
    15901690  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
    15911691  {
    1592     if (eTType)
    1593     {
    1594       m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + (uiPosLastY>>g_aucConvertToBit[ height ]) ) );
    1595     }
    1596     else
    1597     {
    1598       m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + puiCtxIdxY[ uiPosLastY ] ) );
    1599     }
     1692    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) );
    16001693    if( !uiLast )
    16011694    {
     
    16341727Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
    16351728{
     1729#if !H_MV_ENC_DEC_TRAC
    16361730  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    16371731  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
     
    16581752  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
    16591753  DTRACE_CABAC_T( "\n" )
     1754#endif
    16601755 
    16611756  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
     
    16641759    uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
    16651760  }
    1666  
     1761  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
     1762  {
     1763    parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType);
     1764  }
     1765
    16671766  eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
    16681767 
     
    16721771  const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
    16731772  UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
    1674   int blockType = uiLog2BlockSize;
    1675   if (uiWidth != uiHeight)
    1676   {
    1677     uiScanIdx = SCAN_DIAG;
    1678     blockType = 4;
    1679   }
    16801773 
    16811774  //===== decode last significant =====
     
    16861779
    16871780  //===== decode significance flags =====
    1688   UInt uiScanPosLast   = uiBlkPosLast;
    1689   if (uiScanIdx == SCAN_ZIGZAG)
    1690   {
    1691     // Map zigzag to diagonal scan
    1692     uiScanIdx = SCAN_DIAG;
    1693   }
    1694   const UInt * scan;
    1695   if (uiWidth == uiHeight)
    1696   {
    1697     scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
    1698   }
    1699   else
    1700   {
    1701     scan = g_sigScanNSQT[ uiLog2BlockSize - 2 ];
    1702   }
     1781  UInt uiScanPosLast;
     1782  const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
    17031783  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
    17041784  {
     
    17141794
    17151795  const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
    1716   UInt uiNumOne                = 0;
     1796  UInt c1 = 1;
    17171797  UInt uiGoRiceParam           = 0;
    17181798
    1719   UInt const tsig = pcCU->getSlice()->getPPS()->getTSIG();
    1720 #if LOSSLESS_CODING
    17211799  Bool beValid;
    1722   if (pcCU->isLosslessCoded(uiAbsPartIdx))
     1800  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
    17231801  {
    17241802    beValid = false;
     
    17281806    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
    17291807  }
    1730 #else
    1731   Bool beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
    1732 #endif
    17331808  UInt absSum = 0;
    17341809
     
    17371812  const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
    17381813  const UInt * scanCG;
    1739   if (uiWidth == uiHeight)
    17401814  {
    17411815    scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
     
    17481822      scanCG = g_sigLastScanCG32x32;
    17491823    }
    1750   }
    1751   else
    1752   {
    1753     scanCG = g_sigCGScanNSQT[ uiLog2BlockSize - 2 ];
    17541824  }
    17551825  Int  iScanPosSig             = (Int) uiScanPosLast;
     
    17721842    }
    17731843
    1774       // decode significant_coeffgroup_flag
    1775       Int iCGBlkPos = scanCG[ iSubSet ];
    1776       Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
    1777       Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
    1778       if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) )
    1779       {
    1780         iCGPosY = (uiScanIdx == SCAN_HOR ? iCGBlkPos : 0);
    1781         iCGPosX = (uiScanIdx == SCAN_VER ? iCGBlkPos : 0);
    1782       }
    1783       if( iSubSet == iLastScanSet || iSubSet == 0)
    1784       {
    1785         uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
    1786       }
    1787       else
    1788       {
    1789           UInt uiSigCoeffGroup;
    1790           UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight );
    1791           m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
    1792           uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
    1793       }
    1794 
    1795       // decode significant_coeff_flag
    1796       UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
    1797       for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
    1798       {
    1799         uiBlkPos  = scan[ iScanPosSig ];
    1800         uiPosY    = uiBlkPos >> uiLog2BlockSize;
    1801         uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
    1802         uiSig     = 0;
    1803        
    1804         if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
     1844    // decode significant_coeffgroup_flag
     1845    Int iCGBlkPos = scanCG[ iSubSet ];
     1846    Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
     1847    Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
     1848    if( iSubSet == iLastScanSet || iSubSet == 0)
     1849    {
     1850      uiSigCoeffGroupFlag[ iCGBlkPos ] = 1;
     1851    }
     1852    else
     1853    {
     1854      UInt uiSigCoeffGroup;
     1855      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
     1856      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
     1857      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
     1858    }
     1859
     1860    // decode significant_coeff_flag
     1861    Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
     1862    UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
     1863    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
     1864    {
     1865      uiBlkPos  = scan[ iScanPosSig ];
     1866      uiPosY    = uiBlkPos >> uiLog2BlockSize;
     1867      uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
     1868      uiSig     = 0;
     1869     
     1870      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
     1871      {
     1872        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
    18051873        {
    1806           if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
    1807           {
    1808             uiCtxSig  = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType );
    1809             m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
    1810           }
    1811           else
    1812           {
    1813             uiSig = 1;
    1814           }
     1874          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
     1875          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
    18151876        }
    1816         pcCoef[ uiBlkPos ] = uiSig;
    1817         if( uiSig )
     1877        else
    18181878        {
    1819           pos[ numNonZero ] = uiBlkPos;
    1820           numNonZero ++;
    1821           if( lastNZPosInCG == -1 )
    1822           {
    1823             lastNZPosInCG = iScanPosSig;
    1824           }
    1825           firstNZPosInCG = iScanPosSig;
     1879          uiSig = 1;
    18261880        }
    18271881      }
    1828 
     1882      pcCoef[ uiBlkPos ] = uiSig;
     1883      if( uiSig )
     1884      {
     1885        pos[ numNonZero ] = uiBlkPos;
     1886        numNonZero ++;
     1887        if( lastNZPosInCG == -1 )
     1888        {
     1889          lastNZPosInCG = iScanPosSig;
     1890        }
     1891        firstNZPosInCG = iScanPosSig;
     1892      }
     1893    }
    18291894   
    18301895    if( numNonZero )
    18311896    {
    1832       Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= (Int)tsig );
     1897      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
    18331898      absSum = 0;
    1834 
    1835       UInt c1 = 1;
    18361899      UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
    18371900      UInt uiBin;
    1838      
    1839       if( uiNumOne > 0 )
     1901      if( c1 == 0 )
    18401902      {
    18411903        uiCtxSet++;
    18421904      }
    1843      
    1844       uiNumOne       >>= 1;
     1905      c1 = 1;
    18451906      ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
    18461907      Int absCoeff[SCAN_SET_SIZE];
     
    19001961          {
    19011962            UInt uiLevel;
    1902             xReadGoRiceExGolomb( uiLevel, uiGoRiceParam );
     1963            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam );
    19031964            absCoeff[ idx ] = uiLevel + baseLevel;
     1965            if(absCoeff[idx]>3*(1<<uiGoRiceParam))
     1966            {
     1967              uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4);
     1968            }
    19041969          }
    19051970
     
    19071972          {
    19081973            iFirstCoeff2 = 0;
    1909             uiNumOne++;
    19101974          }
    19111975        }
     
    19231987          // Infer sign of 1st element.
    19241988          if (absSum&0x1)
     1989          {
    19251990            pcCoef[ blkPos ] = -pcCoef[ blkPos ];
     1991          }
    19261992        }
    19271993        else
     
    19331999      }
    19342000    }
    1935     else
    1936     {
    1937       uiNumOne >>= 1;
    1938     }
    19392001  }
    19402002 
     
    19422004}
    19432005
    1944 #if LGE_SAO_MIGRATION_D0091
     2006
    19452007Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
    19462008{
    1947     if (maxSymbol == 0)
    1948     {
    1949         val = 0;
    1950         return;
    1951     }
    1952 
    1953     UInt code;
    1954     Int  i;
     2009  if (maxSymbol == 0)
     2010  {
     2011    val = 0;
     2012    return;
     2013  }
     2014
     2015  UInt code;
     2016  Int  i;
     2017  m_pcTDecBinIf->decodeBinEP( code );
     2018  if ( code == 0 )
     2019  {
     2020    val = 0;
     2021    return;
     2022  }
     2023
     2024  i=1;
     2025  while (1)
     2026  {
    19552027    m_pcTDecBinIf->decodeBinEP( code );
    19562028    if ( code == 0 )
    19572029    {
    1958         val = 0;
    1959         return;
    1960     }
    1961 
    1962     i=1;
    1963     while (1)
    1964     {
    1965         m_pcTDecBinIf->decodeBinEP( code );
    1966         if ( code == 0 )
    1967         {
    1968             break;
    1969         }
    1970         i++;
    1971         if (i == maxSymbol)
    1972         {
    1973             break;
    1974         }
    1975     }   
    1976 
    1977     val = i;
    1978 }
    1979 
     2030      break;
     2031    }
     2032    i++;
     2033    if (i == maxSymbol)
     2034    {
     2035      break;
     2036    }
     2037  }
     2038
     2039  val = i;
     2040}
    19802041Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
    19812042{
    1982     m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
    1983 }
    1984 
     2043  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
     2044}
    19852045Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
    19862046{
    1987     UInt uiCode;
    1988     m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
    1989     ruiVal = (Int)uiCode;
    1990 }
    1991 
     2047  UInt uiCode;
     2048  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
     2049  ruiVal = (Int)uiCode;
     2050}
    19922051Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
    19932052{
    1994     UInt uiCode;
    1995     m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
    1996     if (uiCode == 0)
    1997     {
    1998         ruiVal = 0;
     2053  UInt uiCode;
     2054  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
     2055  if (uiCode == 0)
     2056  {
     2057    ruiVal = 0;
     2058  }
     2059  else
     2060  {
     2061    m_pcTDecBinIf->decodeBinEP( uiCode );
     2062    if (uiCode == 0)
     2063    {
     2064      ruiVal = 5;
    19992065    }
    20002066    else
    20012067    {
    2002         m_pcTDecBinIf->decodeBinEP( uiCode );
    2003         if (uiCode == 0)
    2004         {
    2005             ruiVal = 5;
    2006         }
    2007         else
    2008         {
    2009             ruiVal = 1;
    2010         }
    2011     }
    2012 }
    2013 
    2014 inline Void copySaoOneLcuParam(SaoLcuParam* psDst,  SaoLcuParam* psSrc)
    2015 {
    2016     Int i;
    2017     psDst->partIdx = psSrc->partIdx;
    2018     psDst->typeIdx = psSrc->typeIdx;
    2019     if (psDst->typeIdx != -1)
    2020     {
    2021         psDst->subTypeIdx = psSrc->subTypeIdx ;
    2022         psDst->length  = psSrc->length;
    2023         for (i=0;i<psDst->length;i++)
    2024         {
    2025             psDst->offset[i] = psSrc->offset[i];
    2026         }
    2027     }
    2028     else
    2029     {
    2030         psDst->length  = 0;
    2031         for (i=0;i<SAO_BO_LEN;i++)
    2032         {
    2033             psDst->offset[i] = 0;
    2034         }
    2035     }
    2036 }
    2037 
    2038 Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx)
    2039 {
    2040     UInt uiSymbol;
    2041     static Int iTypeLength[MAX_NUM_SAO_TYPE] =
    2042     {
    2043         SAO_EO_LEN,
    2044         SAO_EO_LEN,
    2045         SAO_EO_LEN,
    2046         SAO_EO_LEN,
    2047         SAO_BO_LEN
    2048     };
    2049 
    2050     if (compIdx==2)
    2051     {
    2052         uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1);
    2053     }
    2054     else
    2055     {
    2056         parseSaoTypeIdx(uiSymbol);
    2057     }
    2058     psSaoLcuParam->typeIdx = (Int)uiSymbol - 1;
    2059 
    2060     if (uiSymbol)
    2061     {
    2062         psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx];
    2063 #if FULL_NBIT
    2064         Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + (g_uiBitDepth-8)-5),5) );
    2065 #else
    2066         Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + g_uiBitIncrement-5),5) );
    2067 #endif
    2068 
    2069         if( psSaoLcuParam->typeIdx == SAO_BO )
    2070         {
    2071             for(Int i=0; i< psSaoLcuParam->length; i++)
    2072             {
    2073                 parseSaoMaxUvlc(uiSymbol, offsetTh -1 );
    2074                 psSaoLcuParam->offset[i] = uiSymbol;
    2075             }   
    2076             for(Int i=0; i< psSaoLcuParam->length; i++)
    2077             {
    2078                 if (psSaoLcuParam->offset[i] != 0)
    2079                 {
    2080                     m_pcTDecBinIf->decodeBinEP ( uiSymbol);
    2081                     if (uiSymbol)
    2082                     {
    2083                         psSaoLcuParam->offset[i] = -psSaoLcuParam->offset[i] ;
    2084                     }
    2085                 }
    2086             }
    2087             parseSaoUflc(5, uiSymbol );
    2088             psSaoLcuParam->subTypeIdx = uiSymbol;
    2089         }
    2090         else if( psSaoLcuParam->typeIdx < 4 )
    2091         {
    2092             parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[0] = uiSymbol;   
    2093             parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[1] = uiSymbol;
    2094             parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol;
    2095             parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol;
    2096             if (compIdx != 2)
    2097             {
    2098                 parseSaoUflc(2, uiSymbol );
    2099                 psSaoLcuParam->subTypeIdx = uiSymbol;
    2100                 psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx;
    2101             }
    2102         }
    2103     }
    2104     else
    2105     {
    2106         psSaoLcuParam->length = 0;
    2107     }
    2108 }
    2109 
    2110 Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
    2111 {
    2112     Int iAddr = pcCU->getAddr();
    2113     UInt uiSymbol;
    2114 
    2115     for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
    2116     {
    2117         pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag    = 0;
    2118         pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag  = 0;
    2119         pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx     = 0;
    2120         pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx        =-1;
    2121         pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0]      = 0;
    2122         pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1]      = 0;
    2123         pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2]      = 0;
    2124         pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3]      = 0;
    2125     }
    2126     if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] )
    2127     {
    2128         if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
    2129         {
    2130             parseSaoMerge(uiSymbol);
    2131             pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; 
    2132         }
    2133         if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0)
    2134         {
    2135             if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
    2136             {
    2137                 parseSaoMerge(uiSymbol);
    2138                 pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol;
    2139             }
    2140         }
    2141     }
    2142 
    2143     for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
    2144     {
    2145         if ((iCompIdx == 0  && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0  && pSaoParam->bSaoFlag[1]) )
    2146         {
    2147             if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
    2148             {
    2149                 pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag;
    2150             }
    2151             else
    2152             {
    2153                 pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0;
    2154             }
    2155 
    2156             if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0)
    2157             {
    2158                 if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
    2159                 {
    2160                     pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag;
    2161                 }
    2162                 else
    2163                 {
    2164                     pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0;
    2165                 }
    2166    
    2167                 if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag)
    2168                 {
    2169                     pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx;
    2170                     parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx);
    2171                 }
    2172                 else
    2173                 {
    2174                     copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]);
    2175                 }
    2176             }
    2177             else
    2178             {
    2179                 copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr],  &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]);
    2180             }
    2181         }
    2182         else
    2183         {
    2184             pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx    = -1;
    2185             pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0;
    2186         }
    2187     }
    2188 }
    2189 #else
    2190 Void TDecSbac::parseSaoUvlc (UInt& ruiVal)
    2191 {
    2192   UInt uiCode;
    2193   Int  i;
    2194 
    2195   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoUvlcSCModel.get( 0, 0, 0 ) );
    2196   if ( uiCode == 0 )
    2197   {
    2198     ruiVal = 0;
    2199     return;
    2200   }
    2201 
    2202   i=1;
    2203   while (1)
    2204   {
    2205     m_pcTDecBinIf->decodeBin( uiCode, m_cSaoUvlcSCModel.get( 0, 0, 1 ) );
    2206     if ( uiCode == 0 ) break;
    2207     i++;
    2208   }
    2209 
    2210   ruiVal = i;
    2211 }
    2212 
    2213 Void TDecSbac::parseSaoSvlc (Int&  riVal)
    2214 {
    2215   UInt uiCode;
    2216   Int  iSign;
    2217   Int  i;
    2218 
    2219   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoSvlcSCModel.get( 0, 0, 0 ) );
    2220 
    2221   if ( uiCode == 0 )
    2222   {
    2223     riVal = 0;
    2224     return;
    2225   }
    2226 
    2227   // read sign
    2228   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoSvlcSCModel.get( 0, 0, 1 ) );
    2229 
    2230   if ( uiCode == 0 )
    2231   {
    2232     iSign =  1;
    2233   }
    2234   else
    2235   {
    2236     iSign = -1;
    2237   }
    2238 
    2239   // read magnitude
    2240   i=1;
    2241   while (1)
    2242   {
    2243     m_pcTDecBinIf->decodeBin( uiCode, m_cSaoSvlcSCModel.get( 0, 0, 2 ) );
    2244     if ( uiCode == 0 ) break;
    2245     i++;
    2246   }
    2247 
    2248   riVal = i*iSign;
    2249 }
    2250 
    2251 Void TDecSbac::parseSaoUflc (UInt&  riVal)
    2252 {
    2253   UInt uiSymbol;
    2254   riVal = 0;
    2255   for (Int i=0;i<5;i++)
    2256   {
    2257     m_pcTDecBinIf->decodeBinEP ( uiSymbol );
    2258     if (uiSymbol)
    2259     {
    2260       riVal |= (1<<i);
    2261     }
    2262   }
    2263 }
    2264 Void TDecSbac::parseSaoMergeLeft (UInt&  ruiVal, UInt uiCompIdx)
    2265 {
    2266   UInt uiCode;
    2267   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx ) );
    2268   ruiVal = (Int)uiCode;
    2269 }
    2270 
    2271 Void TDecSbac::parseSaoMergeUp (UInt&  ruiVal)
    2272 {
    2273   UInt uiCode;
    2274   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeUpSCModel.get( 0, 0, 0 ) );
    2275   ruiVal = (Int)uiCode;
    2276 }
    2277 Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
    2278 {
    2279   UInt uiCode;
    2280   Int  i;
    2281   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
    2282   if ( uiCode == 0 )
    2283   {
    2284     ruiVal = 0;
    2285     return;
    2286   }
    2287   i=1;
    2288   while (1)
    2289   {
    2290     m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) );
    2291     if ( uiCode == 0 ) break;
    2292     i++;
    2293   }
    2294   ruiVal = i;
     2068      ruiVal = 1;
     2069    }
     2070  }
    22952071}
    22962072
     
    23022078  if (psDst->typeIdx != -1)
    23032079  {
    2304     if (psDst->typeIdx == SAO_BO)
    2305     {
    2306       psDst->bandPosition = psSrc->bandPosition ;
    2307     }
    2308     else
    2309     {
    2310       psDst->bandPosition = 0;
    2311     }
     2080    psDst->subTypeIdx = psSrc->subTypeIdx ;
    23122081    psDst->length  = psSrc->length;
    23132082    for (i=0;i<psDst->length;i++)
     
    23252094  }
    23262095}
    2327 Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam)
     2096
     2097Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx)
    23282098{
    23292099  UInt uiSymbol;
    2330   Int iSymbol;
    2331   static Int iTypeLength[MAX_NUM_SAO_TYPE] = {
     2100  static Int iTypeLength[MAX_NUM_SAO_TYPE] =
     2101  {
    23322102    SAO_EO_LEN,
    23332103    SAO_EO_LEN,
     
    23372107  };
    23382108
    2339   parseSaoTypeIdx(uiSymbol);
     2109  if (compIdx==2)
     2110  {
     2111    uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1);
     2112  }
     2113  else
     2114  {
     2115    parseSaoTypeIdx(uiSymbol);
     2116  }
    23402117  psSaoLcuParam->typeIdx = (Int)uiSymbol - 1;
    23412118  if (uiSymbol)
    23422119  {
    23432120    psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx];
     2121
     2122    Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY;
     2123    Int offsetTh = 1 << min(bitDepth - 5,5);
     2124
    23442125    if( psSaoLcuParam->typeIdx == SAO_BO )
    23452126    {
    2346       // Parse Left Band Index
    2347       parseSaoUflc( uiSymbol );
    2348       psSaoLcuParam->bandPosition = uiSymbol;
    23492127      for(Int i=0; i< psSaoLcuParam->length; i++)
    23502128      {
    2351         parseSaoSvlc(iSymbol);
    2352         psSaoLcuParam->offset[i] = iSymbol;
     2129        parseSaoMaxUvlc(uiSymbol, offsetTh -1 );
     2130        psSaoLcuParam->offset[i] = uiSymbol;
    23532131      }   
     2132      for(Int i=0; i< psSaoLcuParam->length; i++)
     2133      {
     2134        if (psSaoLcuParam->offset[i] != 0)
     2135        {
     2136          m_pcTDecBinIf->decodeBinEP ( uiSymbol);
     2137          if (uiSymbol)
     2138          {
     2139            psSaoLcuParam->offset[i] = -psSaoLcuParam->offset[i] ;
     2140          }
     2141        }
     2142      }
     2143      parseSaoUflc(5, uiSymbol );
     2144      psSaoLcuParam->subTypeIdx = uiSymbol;
    23542145    }
    23552146    else if( psSaoLcuParam->typeIdx < 4 )
    23562147    {
    2357       parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[0] = uiSymbol;
    2358       parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[1] = uiSymbol;
    2359       parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[2] = -(Int)uiSymbol;
    2360       parseSaoUvlc(uiSymbol); psSaoLcuParam->offset[3] = -(Int)uiSymbol;
    2361     }
     2148      parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[0] = uiSymbol;
     2149      parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[1] = uiSymbol;
     2150      parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol;
     2151      parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol;
     2152     if (compIdx != 2)
     2153     {
     2154       parseSaoUflc(2, uiSymbol );
     2155       psSaoLcuParam->subTypeIdx = uiSymbol;
     2156       psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx;
     2157     }
     2158   }
    23622159  }
    23632160  else
     
    23672164}
    23682165
    2369 Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Bool bLFCrossSliceBoundaryFlag)
     2166Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
    23702167{
    23712168  Int iAddr = pcCU->getAddr();
     
    23752172    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag    = 0;
    23762173    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag  = 0;
    2377     pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition   = 0;
     2174    pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx     = 0;
    23782175    pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx        = -1;
    23792176    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0]     = 0;
     
    23822179    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3]     = 0;
    23832180
    2384     if (pSaoParam->bSaoFlag[iCompIdx])
    2385     {
    2386       if (rx>0 && iCUAddrInSlice!=0)
    2387       {
    2388         parseSaoMergeLeft(uiSymbol,iCompIdx); pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = (Int)uiSymbol;
     2181  }
     2182 if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] )
     2183  {
     2184    if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
     2185    {
     2186      parseSaoMerge(uiSymbol);
     2187      pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; 
     2188    }
     2189    if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0)
     2190    {
     2191      if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
     2192      {
     2193        parseSaoMerge(uiSymbol);
     2194        pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol;
     2195      }
     2196    }
     2197  }
     2198
     2199  for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
     2200  {
     2201    if ((iCompIdx == 0  && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0  && pSaoParam->bSaoFlag[1]) )
     2202    {
     2203      if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
     2204      {
     2205        pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag;
    23892206      }
    23902207      else
     
    23952212      if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0)
    23962213      {
    2397         if ((ry > 0) && (iCUAddrUpInSlice>0||bLFCrossSliceBoundaryFlag))
     2214        if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
    23982215        {
    2399           parseSaoMergeUp(uiSymbol);  pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = uiSymbol;
     2216          pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag;
    24002217        }
    24012218        else
     
    24052222        if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag)
    24062223        {
    2407           parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]));
     2224          pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx;
     2225          parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx);
    24082226        }
    24092227        else
     
    24202238    {
    24212239      pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1;
    2422       pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition = 0;
    2423     }
    2424   }
    2425 }
    2426 #endif
     2240      pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0;
     2241    }
     2242  }
     2243}
     2244
    24272245/**
    24282246 - Initialize our contexts from the nominated source.
     
    24542272}
    24552273
    2456 Void TDecSbac::decodeFlush ( )
    2457 {
    2458   UInt uiBit;
    2459   m_pcTDecBinIf->decodeBinTrm(uiBit);
    2460   m_pcTDecBinIf->flush();
    2461 
    2462 }
    2463 
    2464 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX || (LGE_EDGE_INTRA_A0070 && LGE_EDGE_INTRA_DELTA_DC)
    2465 Void TDecSbac::xReadExGolombLevel( UInt& ruiSymbol, ContextModel& rcSCModel  )
    2466 {
    2467   UInt uiSymbol;
    2468   UInt uiCount = 0;
    2469   do
    2470   {
    2471     m_pcTDecBinIf->decodeBin( uiSymbol, rcSCModel );
    2472     uiCount++;
    2473   }
    2474   while( uiSymbol && ( uiCount != 13 ) );
    2475 
    2476   ruiSymbol = uiCount - 1;
     2274#if H_3D_ARP
     2275Void TDecSbac::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2276{
     2277  UInt uiMaxW = pcCU->getSlice()->getARPStepNum() - 1;
     2278  UInt uiW = 0;
     2279  UInt uiOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
     2280  UInt uiCode = 0;
     2281
     2282  assert ( uiMaxW > 0 );
     2283
     2284  m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 0 + uiOffset ) );
     2285
     2286  uiW = uiCode;
     2287  if( 1 == uiW )   
     2288  {
     2289    m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPWSCModel.get( 0, 0, 3 ) );
     2290    uiW += ( 1 == uiCode ? 1 : 0 );
     2291  }
     2292#if H_MV_ENC_DEC_TRAC
     2293  DTRACE_CU("iv_res_pred_weight_idx", uiW )
     2294#endif
     2295  pcCU->setARPWSubParts( ( UChar )( uiW ) , uiAbsPartIdx, uiDepth ); 
     2296}
     2297#endif
     2298
     2299#if H_3D_IC
     2300/** parse illumination compensation flag
     2301 * \param pcCU
     2302 * \param uiAbsPartIdx
     2303 * \param uiDepth
     2304 * \returns Void
     2305 */
     2306Void TDecSbac::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2307{
     2308  UInt uiSymbol = 0;
     2309  UInt uiCtxIC = pcCU->getCtxICFlag( uiAbsPartIdx );
     2310  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, uiCtxIC ) );
     2311#if !H_MV_ENC_DEC_TRAC
     2312  DTRACE_CABAC_VL( g_nSymbolCounter++ );
     2313  DTRACE_CABAC_T( "\tICFlag" );
     2314  DTRACE_CABAC_T( "\tuiCtxIC: ");
     2315  DTRACE_CABAC_V( uiCtxIC );
     2316  DTRACE_CABAC_T( "\tuiSymbol: ");
     2317  DTRACE_CABAC_V( uiSymbol );
     2318  DTRACE_CABAC_T( "\n");
     2319#else
     2320  DTRACE_CU("ic_flag", uiSymbol)
     2321#endif
     2322 
     2323  pcCU->setICFlagSubParts( uiSymbol ? true : false , uiAbsPartIdx, 0, uiDepth );
     2324}
     2325#endif
     2326
     2327#if LGE_INTER_SDC_E0156
     2328Void TDecSbac::parseInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2329{
     2330  UInt uiSymbol = 0;
     2331  UInt uiCtxInterSDCFlag = pcCU->getCtxInterSDCFlag( uiAbsPartIdx );
     2332
     2333  m_pcTDecBinIf->decodeBin( uiSymbol, m_cInterSDCFlagSCModel.get( 0, 0, uiCtxInterSDCFlag ) );
    24772334
    24782335  if( uiSymbol )
    24792336  {
    2480     xReadEpExGolomb( uiSymbol, 0 );
    2481     ruiSymbol += uiSymbol + 1;
    2482   }
    2483 
    2484   return;
    2485 }
    2486 #endif
    2487 #if HHI_DMM_WEDGE_INTRA
    2488 Void TDecSbac::xParseWedgeFullInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2489 {
    2490   Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
    2491   Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx];
    2492 
    2493   UInt uiSymbol, uiTabIdx = 0;
    2494   for ( Int i = 0; i < iBits; i++ )
    2495   {
    2496     m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 0) );
    2497     uiTabIdx += ( uiSymbol && i == 0 ) ? 1 : 0;
    2498     uiTabIdx += ( uiSymbol && i == 1 ) ? 2 : 0;
    2499     uiTabIdx += ( uiSymbol && i == 2 ) ? 4 : 0;
    2500     uiTabIdx += ( uiSymbol && i == 3 ) ? 8 : 0;
    2501     uiTabIdx += ( uiSymbol && i == 4 ) ? 16 : 0;
    2502     uiTabIdx += ( uiSymbol && i == 5 ) ? 32 : 0;
    2503     uiTabIdx += ( uiSymbol && i == 6 ) ? 64 : 0;
    2504     uiTabIdx += ( uiSymbol && i == 7 ) ? 128 : 0;
    2505     uiTabIdx += ( uiSymbol && i == 8 ) ? 256 : 0;
    2506     uiTabIdx += ( uiSymbol && i == 9 ) ? 512 : 0;
    2507     uiTabIdx += ( uiSymbol && i == 10 ) ? 1024 : 0;
    2508     uiTabIdx += ( uiSymbol && i == 11 ) ? 2048 : 0;
    2509     uiTabIdx += ( uiSymbol && i == 12 ) ? 4096 : 0;
    2510   }
    2511 
    2512   pcCU->setWedgeFullTabIdxSubParts( uiTabIdx, uiAbsPartIdx, uiDepth );
    2513 }
    2514 
    2515 Void TDecSbac::xParseWedgeFullDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2516 {
    2517   Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
    2518   Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx];
    2519 
    2520   UInt uiSymbol, uiTabIdx = 0;
    2521   for ( Int i = 0; i < iBits; i++ )
    2522   {
    2523     m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 0) );
    2524     uiTabIdx += ( uiSymbol && i == 0 ) ? 1 : 0;
    2525     uiTabIdx += ( uiSymbol && i == 1 ) ? 2 : 0;
    2526     uiTabIdx += ( uiSymbol && i == 2 ) ? 4 : 0;
    2527     uiTabIdx += ( uiSymbol && i == 3 ) ? 8 : 0;
    2528     uiTabIdx += ( uiSymbol && i == 4 ) ? 16 : 0;
    2529     uiTabIdx += ( uiSymbol && i == 5 ) ? 32 : 0;
    2530     uiTabIdx += ( uiSymbol && i == 6 ) ? 64 : 0;
    2531     uiTabIdx += ( uiSymbol && i == 7 ) ? 128 : 0;
    2532     uiTabIdx += ( uiSymbol && i == 8 ) ? 256 : 0;
    2533     uiTabIdx += ( uiSymbol && i == 9 ) ? 512 : 0;
    2534     uiTabIdx += ( uiSymbol && i == 10 ) ? 1024 : 0;
    2535     uiTabIdx += ( uiSymbol && i == 11 ) ? 2048 : 0;
    2536     uiTabIdx += ( uiSymbol && i == 12 ) ? 4096 : 0;
    2537   }
    2538 
    2539   pcCU->setWedgeFullTabIdxSubParts( uiTabIdx, uiAbsPartIdx, uiDepth );
    2540 
    2541   UInt uiDC1, uiDC2;
    2542   xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
    2543   Int iDC1 = uiDC1;
    2544   if ( uiDC1 )
    2545   {
    2546     UInt uiSign;
    2547     m_pcTDecBinIf->decodeBinEP( uiSign );
    2548     if ( uiSign )
    2549     {
    2550       iDC1 = -iDC1;
    2551     }
    2552   }
    2553   xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
    2554   Int iDC2 = uiDC2;
    2555   if ( uiDC2 )
    2556   {
    2557     UInt uiSign;
    2558     m_pcTDecBinIf->decodeBinEP( uiSign );
    2559     if ( uiSign )
    2560     {
    2561       iDC2 = -iDC2;
    2562     }
    2563   }
    2564 
    2565   pcCU->setWedgeFullDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
    2566   pcCU->setWedgeFullDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
    2567 }
    2568 
    2569 Void TDecSbac::xParseWedgePredDirInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2570 {
    2571   if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 )
    2572   {
    2573     UInt uiDeltaEnd = 0;
    2574     m_pcTDecBinIf->decodeBin( uiDeltaEnd, m_cDmmDataSCModel.get(0, 0, 2) );
    2575 
    2576     Int iDeltaEnd;
    2577     if( uiDeltaEnd != 0 )
    2578     {
    2579       UInt uiAbsValMinus1;
    2580       UInt uiSymbol;
    2581       m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1  = uiSymbol;
    2582       m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1 |= uiSymbol << 1;
    2583       uiDeltaEnd = uiAbsValMinus1 + 1;
    2584 
    2585       iDeltaEnd = uiDeltaEnd;
    2586       UInt uiSign;
    2587       m_pcTDecBinIf->decodeBinEP( uiSign );
    2588       if( uiSign )
    2589       {
    2590         iDeltaEnd = -iDeltaEnd;
    2591       }
    2592     }
    2593     else
    2594     {
    2595       iDeltaEnd = 0;
    2596     }
    2597     pcCU->setWedgePredDirDeltaEndSubParts( iDeltaEnd, uiAbsPartIdx, uiDepth );
    2598   }
    2599 }
    2600 
    2601 Void TDecSbac::xParseWedgePredDirDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2602 {
    2603   if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 )
    2604   {
    2605     UInt uiDeltaEnd = 0;
    2606     m_pcTDecBinIf->decodeBin( uiDeltaEnd, m_cDmmDataSCModel.get(0, 0, 2) );
    2607 
    2608     Int iDeltaEnd;
    2609     if( uiDeltaEnd != 0 )
    2610     {
    2611       UInt uiAbsValMinus1;
    2612       UInt uiSymbol;
    2613       m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1  = uiSymbol;
    2614       m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 2) ); uiAbsValMinus1 |= uiSymbol << 1;
    2615       uiDeltaEnd = uiAbsValMinus1 + 1;
    2616 
    2617       iDeltaEnd = uiDeltaEnd;
    2618       UInt uiSign;
    2619       m_pcTDecBinIf->decodeBinEP( uiSign );
    2620       if( uiSign )
    2621       {
    2622         iDeltaEnd = -iDeltaEnd;
    2623       }
    2624     }
    2625     else
    2626     {
    2627       iDeltaEnd = 0;
    2628     }
    2629 
    2630     pcCU->setWedgePredDirDeltaEndSubParts( iDeltaEnd, uiAbsPartIdx, uiDepth );
    2631   }
    2632 
    2633   UInt uiDC1, uiDC2;
    2634   xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
    2635   Int iDC1 = uiDC1;
    2636   if ( uiDC1 )
    2637   {
    2638     UInt uiSign;
    2639     m_pcTDecBinIf->decodeBinEP( uiSign );
    2640     if ( uiSign )
    2641     {
    2642       iDC1 = -iDC1;
    2643     }
    2644   }
    2645   xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
    2646   Int iDC2 = uiDC2;
    2647   if ( uiDC2 )
    2648   {
    2649     UInt uiSign;
    2650     m_pcTDecBinIf->decodeBinEP( uiSign );
    2651     if ( uiSign )
    2652     {
    2653       iDC2 = -iDC2;
    2654     }
    2655   }
    2656 
    2657   pcCU->setWedgePredDirDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
    2658   pcCU->setWedgePredDirDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
    2659 }
    2660 #endif
    2661 #if HHI_DMM_PRED_TEX
    2662 #if LGE_DMM3_SIMP_C0044
    2663 Void TDecSbac::xParseWedgePredTexInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2664 {
    2665   Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
    2666   Int iBits = g_aucWedgeTexPredBitsListIdx[iIntraIdx];
    2667 
    2668   UInt uiSymbol, uiTabIdx = 0;
    2669   for ( Int i = 0; i < iBits; i++ )
    2670   {
    2671     m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmDataSCModel.get(0, 0, 3) );
    2672     uiTabIdx += ( uiSymbol && i == 0 ) ? 1 : 0;
    2673     uiTabIdx += ( uiSymbol && i == 1 ) ? 2 : 0;
    2674     uiTabIdx += ( uiSymbol && i == 2 ) ? 4 : 0;
    2675     uiTabIdx += ( uiSymbol && i == 3 ) ? 8 : 0;
    2676     uiTabIdx += ( uiSymbol && i == 4 ) ? 16 : 0;
    2677     uiTabIdx += ( uiSymbol && i == 5 ) ? 32 : 0;
    2678     uiTabIdx += ( uiSymbol && i == 6 ) ? 64 : 0;
    2679     uiTabIdx += ( uiSymbol && i == 7 ) ? 128 : 0;
    2680     uiTabIdx += ( uiSymbol && i == 8 ) ? 256 : 0;
    2681     uiTabIdx += ( uiSymbol && i == 9 ) ? 512 : 0;
    2682     uiTabIdx += ( uiSymbol && i == 10 ) ? 1024 : 0;
    2683   }
    2684 
    2685   pcCU->setWedgePredTexIntraTabIdxSubParts( uiTabIdx, uiAbsPartIdx, uiDepth );
    2686 }
    2687 #endif
    2688 
    2689 Void TDecSbac::xParseWedgePredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2690 {
    2691 #if LGE_DMM3_SIMP_C0044
    2692   xParseWedgePredTexInfo( pcCU, uiAbsPartIdx, uiDepth );
    2693 #endif
    2694   UInt uiDC1, uiDC2;
    2695   xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
    2696   Int iDC1 = uiDC1;
    2697   if ( uiDC1 )
    2698   {
    2699     UInt uiSign;
    2700     m_pcTDecBinIf->decodeBinEP( uiSign );
    2701     if ( uiSign )
    2702     {
    2703       iDC1 = -iDC1;
    2704     }
    2705   }
    2706   xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
    2707   Int iDC2 = uiDC2;
    2708   if ( uiDC2 )
    2709   {
    2710     UInt uiSign;
    2711     m_pcTDecBinIf->decodeBinEP( uiSign );
    2712     if ( uiSign )
    2713     {
    2714       iDC2 = -iDC2;
    2715     }
    2716   }
    2717 
    2718   pcCU->setWedgePredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
    2719   pcCU->setWedgePredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
    2720 }
    2721 
    2722 Void TDecSbac::xParseContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2723 {
    2724   UInt uiDC1, uiDC2;
    2725   xReadExGolombLevel( uiDC1, m_cDmmDataSCModel.get(0, 0, 1) );
    2726   Int iDC1 = uiDC1;
    2727   if ( uiDC1 )
    2728   {
    2729     UInt uiSign;
    2730     m_pcTDecBinIf->decodeBinEP( uiSign );
    2731     if ( uiSign )
    2732     {
    2733       iDC1 = -iDC1;
    2734     }
    2735   }
    2736   xReadExGolombLevel( uiDC2, m_cDmmDataSCModel.get(0, 0, 1) );
    2737   Int iDC2 = uiDC2;
    2738   if ( uiDC2 )
    2739   {
    2740     UInt uiSign;
    2741     m_pcTDecBinIf->decodeBinEP( uiSign );
    2742     if ( uiSign )
    2743     {
    2744       iDC2 = -iDC2;
    2745     }
    2746   }
    2747 
    2748   pcCU->setContourPredTexDeltaDC1SubParts( iDC1, uiAbsPartIdx, uiDepth );
    2749   pcCU->setContourPredTexDeltaDC2SubParts( iDC2, uiAbsPartIdx, uiDepth );
    2750 }
    2751 #endif
    2752 #if QC_ARP_D0177
    2753 Void TDecSbac::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2754 {
    2755   UInt nMaxW = pcCU->getSlice()->getARPStepNum() - 1;
    2756 #if !QC_ARP_WARNING_FIX
    2757   assert (nMaxW >= 0);
    2758 #endif
    2759   UInt nW = 0;
    2760   if( nMaxW > 0 )
    2761   {
    2762     UInt nOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
    2763 #if !QC_ARP_WARNING_FIX
    2764     assert( 0 <= nOffset && nOffset <= 2 );
    2765 #endif
    2766     UInt uiCode = 0;
    2767     m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPW.get( 0, 0, 0 + nOffset ) );
    2768     nW = uiCode;
    2769     if( nW == 1 )   
    2770     {
    2771       m_pcTDecBinIf->decodeBin( uiCode , m_cCUPUARPW.get( 0, 0, 3 ) );
    2772       nW += ( uiCode == 1 );
    2773     }
    2774   }
    2775   pcCU->setARPWSubParts( ( UChar )( nW ) , uiAbsPartIdx, uiDepth ); 
    2776 }
    2777 #endif
    2778 #if LGE_EDGE_INTRA_A0070
    2779 Void TDecSbac::xParseEdgeIntraInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2780 {
    2781   UInt uiSymbol = 0;
    2782 
    2783   // 1. Top(0) or Left(1)
    2784   UChar ucLeft;
    2785   m_pcTDecBinIf->decodeBinEP( uiSymbol );
    2786   ucLeft = uiSymbol;
    2787 
    2788   // 2. Start position (lowest bit first)
    2789   UChar ucStart = 0;
    2790   for( UInt ui = 0; ui < 6 - uiDepth; ui++ )
    2791   {
    2792     m_pcTDecBinIf->decodeBinEP( uiSymbol );
    2793     ucStart |= (uiSymbol << ui);
    2794   }
    2795 
    2796   // 3. Number of edges
    2797   UChar ucMax = 0;
    2798   for( UInt ui = 0; ui < 7 - uiDepth; ui++ )
    2799   {
    2800     m_pcTDecBinIf->decodeBinEP( uiSymbol );
    2801     ucMax |= (uiSymbol << ui);
    2802   }
    2803   ucMax++; // +1
    2804 
    2805   // 4. Edges
    2806   UChar* pucSymbolList = (UChar*) xMalloc( UChar, 256 * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
    2807   UInt uiCtxEdgeIntra = pcCU->getCtxEdgeIntra( uiAbsPartIdx );
    2808   for( Int iPtr = 0; iPtr < ucMax; iPtr++ )
    2809   {
    2810     UChar ucEdge = 0;
    2811     UInt  uiReorderEdge = 0;
    2812     // Left-friendly direction
    2813     // 0 (   0deg) => 0
    2814     // 1 (  45deg) => 10
    2815     // 2 ( -45deg) => 110
    2816     // 3 (  90deg) => 1110
    2817     // 4 ( -90deg) => 11110
    2818     // 5 ( 135deg) => 111110
    2819     // 6 (-135deg) => 111111
    2820     // Right-friendly direction
    2821     // 0 (   0deg) => 0
    2822     // 1 ( -45deg) => 10
    2823     // 2 (  45deg) => 110
    2824     // 3 ( -90deg) => 1110
    2825     // 4 (  90deg) => 11110
    2826     // 5 (-135deg) => 111110
    2827     // 6 ( 135deg) => 111111
    2828     // refer to a paper "An efficient chain code with Huffman coding"
    2829     for( UInt ui = 0; ui < 6; ui++ )
    2830     {
    2831       m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) );
    2832       ucEdge <<= 1;
    2833       ucEdge |= uiSymbol;
    2834       if( uiSymbol == 0 )
    2835         break;
    2836     }
    2837 
    2838     switch( ucEdge )
    2839     {
    2840     case 0 :  // "0"
    2841       uiReorderEdge = 0;
    2842       break;
    2843     case 2 :  // "10"
    2844       uiReorderEdge = 1;
    2845       break;
    2846     case 6 :  // "110"
    2847       uiReorderEdge = 2;
    2848       break;
    2849     case 14 : // "1110"
    2850       uiReorderEdge = 3;
    2851       break;
    2852     case 30 : // "11110"
    2853       uiReorderEdge = 4;
    2854       break;
    2855     case 62 : // "111110"
    2856       uiReorderEdge = 5;
    2857       break;
    2858     case 63 : // "111111"
    2859       uiReorderEdge = 6;
    2860       break;
    2861     default :
    2862       printf("parseIntraEdgeChain: error (unknown code %d)\n",ucEdge);
    2863       assert(false);
    2864       break;
    2865     }
    2866     pucSymbolList[iPtr] = uiReorderEdge;
    2867   }
    2868   /////////////////////
    2869   // Edge Reconstruction
    2870   Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx );
    2871   pcCU->reconPartition( uiAbsPartIdx, uiDepth, ucLeft == 1, ucStart, ucMax, pucSymbolList, pbRegion );
    2872   xFree( pucSymbolList );
    2873 }
    2874 #endif
    2875  
    2876 #if RWTH_SDC_DLT_B0036
    2877 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    2878 Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2879 {
    2880   assert( pcCU->getSlice()->getSPS()->isDepth() );
    2881  
    2882   UInt uiSymbol = 0;
    2883   UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx );
    2884   m_pcTDecBinIf->decodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) );
    2885  
    2886   if( uiSymbol == 1 )
    2887   {
    2888     pcCU->setPartSizeSubParts(SIZE_2Nx2N, uiAbsPartIdx, uiDepth);
    2889    
    2890     pcCU->setSDCFlagSubParts( true, uiAbsPartIdx, 0, uiDepth);
    2891     pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth);
    2892     pcCU->setCbfSubParts(1, 1, 1, uiAbsPartIdx, uiDepth);
    2893   }
    2894 }
    2895 
    2896 Void TDecSbac::parseSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2897 {
    2898   assert( pcCU->getSlice()->getSPS()->isDepth() );
    2899   assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
    2900  
    2901   assert( pcCU->getSDCFlag(uiAbsPartIdx) );
    2902  
    2903   UInt uiCtx            = 0;
    2904  
    2905   UInt uiMPModeIdx      = 0;
    2906  
    2907   for(Int i=0; i<RWTH_SDC_NUM_PRED_MODES-1; i++)
    2908   {
    2909     UInt uiIsMostProb = 0;
    2910 #if INTEL_SDC64_D0193
    2911     if( !(pcCU->getWidth(uiAbsPartIdx) == 64 && i == 1))
    2912 #endif
    2913     m_pcTDecBinIf->decodeBin( uiIsMostProb, m_cSDCPredModeSCModel.get( 0, i, uiCtx ) );
    2914    
    2915     if ( uiIsMostProb == 1 )
    2916       break;
    2917    
    2918     // else: get next most probable pred mode
    2919     uiMPModeIdx = (uiMPModeIdx+1)%RWTH_SDC_NUM_PRED_MODES;
    2920   }
    2921  
    2922   Int intraPredMode = g_auiSDCPredModes[uiMPModeIdx];
    2923  
    2924 #if HHI_DMM_WEDGE_INTRA
    2925   if( intraPredMode == DMM_WEDGE_FULL_IDX )          { xParseWedgeFullInfo          ( pcCU, uiAbsPartIdx, uiDepth ); }
    2926   if( intraPredMode == DMM_WEDGE_PREDDIR_IDX )       { xParseWedgePredDirInfo       ( pcCU, uiAbsPartIdx, uiDepth ); }
    2927 #endif
    2928  
    2929   pcCU->setLumaIntraDirSubParts((UChar)intraPredMode, uiAbsPartIdx, uiDepth);
    2930 }
    2931 #endif
    2932 
    2933 Void TDecSbac::parseSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSegment )
    2934 {
    2935   assert( pcCU->getSlice()->getSPS()->isDepth() );
    2936   assert( pcCU->getSDCFlag(uiAbsPartIdx) );
    2937   assert( uiSegment < 2 );
    2938  
    2939   UInt uiResidual = 0;
    2940   UInt uiBit      = 0;
     2337    pcCU->setInterSDCFlagSubParts( true, uiAbsPartIdx, 0, uiDepth );
     2338    pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth );
     2339    pcCU->setCbfSubParts( 1, 1, 1, uiAbsPartIdx, uiDepth );
     2340  }
     2341  else
     2342  {
     2343    pcCU->setInterSDCFlagSubParts( false, uiAbsPartIdx, 0, uiDepth);
     2344  }
     2345}
     2346
     2347Void TDecSbac::parseInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSegment )
     2348{
    29412349  UInt uiAbsIdx   = 0;
    29422350  UInt uiSign     = 0;
    29432351  Int  iIdx       = 0;
    2944  
    2945   UInt uiMaxResidualBits  = pcCU->getSlice()->getSPS()->getBitsPerDepthValue();
    2946   assert( uiMaxResidualBits <= g_uiBitDepth );
    2947  
    2948 #if RWTH_SDC_CTX_SIMPL_D0032
    2949   m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
    2950 #else
    2951   m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, uiSegment, 0 ) );
    2952 #endif
    2953  
    2954   if (uiResidual)
    2955   {
    2956     // decode residual sign bit
    2957 #if RWTH_SDC_CTX_SIMPL_D0032
    2958     m_pcTDecBinIf->decodeBinEP(uiSign);
    2959 #else
    2960     m_pcTDecBinIf->decodeBin(uiSign, m_cSDCResidualSignFlagSCModel.get( 0, uiSegment, 0 ) );
    2961 #endif
    2962    
    2963     // decode residual magnitude
    2964 #if LGE_CONCATENATE_D0141
    2965     //prefix part
    2966     UInt uiCount = 0;
    2967     UInt uiNumDepthValues = pcCU->getSlice()->getSPS()->getNumDepthValues();
    2968     UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2);
    2969     for ( UInt ui = 0; ui < uiPrefixThreshold; ui++)
    2970     {
    2971         m_pcTDecBinIf->decodeBin( uiBit, m_cSDCResidualSCModel.get(0, 0, 0) );
    2972         if ( uiBit == 0 )
    2973             break;
    2974         else
    2975             uiCount++;
    2976     }
    2977     //suffix part
    2978     if ( uiCount == uiPrefixThreshold )
    2979     {
    2980         for ( UInt ui = 0; ui < ( (UInt)ceil( Log2(uiNumDepthValues - uiPrefixThreshold) ) ); ui++ )
    2981         {
    2982             m_pcTDecBinIf->decodeBinEP( uiBit );
    2983             uiAbsIdx |= uiBit << ui;
    2984         }
    2985         uiAbsIdx += uiCount;
    2986     }
    2987     else
    2988         uiAbsIdx = uiCount;
    2989 #else
    2990     for (Int i=0; i<uiMaxResidualBits; i++)
    2991     {
    2992 #if RWTH_SDC_CTX_SIMPL_D0032
    2993       m_pcTDecBinIf->decodeBin(uiBit, m_cSDCResidualSCModel.get( 0, 0, i ) );
    2994 #else
    2995       m_pcTDecBinIf->decodeBin(uiBit, m_cSDCResidualSCModel.get( 0, uiSegment, i ) );
    2996 #endif
    2997       uiAbsIdx |= uiBit << i;
    2998     }
    2999 #endif
    3000    
    3001     uiAbsIdx += 1;
    3002     iIdx =(Int)(uiSign ? -1 : 1)*uiAbsIdx;
    3003   }
    3004  
    3005   pcCU->setSDCSegmentDCOffset(iIdx, uiSegment, uiAbsPartIdx);
     2352
     2353  xReadExGolombLevel( uiAbsIdx, m_cInterSDCResidualSCModel.get( 0, 0, 0 ) );
     2354
     2355  uiAbsIdx++;
     2356  m_pcTDecBinIf->decodeBin( uiSign, m_cInterSDCResidualSignFlagSCModel.get( 0, 0, 0 ) );
     2357  iIdx = (Int)( uiSign ? -1 : 1 ) * uiAbsIdx;
     2358
     2359  pcCU->setInterSDCSegmentDCOffset( iIdx, uiSegment, uiAbsPartIdx );
    30062360}
    30072361#endif
Note: See TracChangeset for help on using the changeset viewer.