Changeset 443 in 3DVCSoftware


Ignore:
Timestamp:
26 May 2013, 15:41:34 (11 years ago)
Author:
tech
Message:
  • Reintegrated branch 6.2-dev0 rev. 442.
  • Changed version number.
  • Added coding results.
Location:
trunk
Files:
72 edited

Legend:

Unmodified
Added
Removed
  • trunk/CommonTestConditionsCfgs/baseCfg_2view+depth.cfg

    r296 r443  
    151151ALFPicBasedEncode              : 1                                 # ALF LCU-based or picture-based encoding (0: LCU-based, 1: Picture-based) 
    152152MaxNumOffsetsPerPic            : 2048                              # default
    153 SAOInterleaving                : 0                                 # SAO interleaving flag (0: SAO parameter in APS, 1: SAO parameter in slice data)
     153SAOLcuBoundary              : 0                                 # 0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas
     154SAOLcuBasedOptimization : 1                                  # 0: SAO picture-based optimization, 1: SAO LCU-based optimization
    154155ConstrainedIntraPred           : 0                                 # Constrained Intra Prediction
    155156weighted_pred_flag             : 0                                 # weighted prediction flag (P-Slices)
     
    192193MultiviewMvRegMode        : 1                                      # use original depth maps for regularizing inter-view motion vector
    193194MultiviewMvRegLambdaScale : 1.0                                    # lambda scale factor for inter-view motion vector regularization
    194 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     195MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    195196InterViewSkip             : 0                                      # interview SKIP mode
    196197InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
     
    199200FCO                        : 0                                     # Flexible coding order flag in 3DV
    200201FCOCodingOrder             : T0D0D1T1                              # Coding order for Flexible coding order in 3DV
     202UseVSPCompensation         : 1                                     # Depth dependent tools: BVSP
     203UseDVPRefine               : 1                                     # Depth dependent tools: DoNBDV
    201204
    202205
  • trunk/CommonTestConditionsCfgs/baseCfg_2view.cfg

    r210 r443  
    145145ALFPicBasedEncode              : 1                                 # ALF LCU-based or picture-based encoding (0: LCU-based, 1: Picture-based) 
    146146MaxNumOffsetsPerPic            : 2048                              # default
    147 SAOInterleaving                : 0                                 # SAO interleaving flag (0: SAO parameter in APS, 1: SAO parameter in slice data)
     147SAOLcuBoundary              : 0                                 # 0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas
     148SAOLcuBasedOptimization : 1                                  # 0: SAO picture-based optimization, 1: SAO LCU-based optimization
    148149ConstrainedIntraPred           : 0                                 # Constrained Intra Prediction
    149150weighted_pred_flag             : 0                                 # weighted prediction flag (P-Slices)
     
    186187MultiviewMvRegMode        : 0                                      # use original depth maps for regularizing inter-view motion vector
    187188MultiviewMvRegLambdaScale : 0.0                                    # lambda scale factor for inter-view motion vector regularization
    188 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     189MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    189190InterViewSkip             : 0                                      # interview SKIP mode
    190191InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
  • trunk/CommonTestConditionsCfgs/baseCfg_3view+depth.cfg

    r296 r443  
    155155ALFPicBasedEncode              : 1                                 # ALF LCU-based or picture-based encoding (0: LCU-based, 1: Picture-based) 
    156156MaxNumOffsetsPerPic            : 2048                              # default
    157 SAOInterleaving                : 0                                 # SAO interleaving flag (0: SAO parameter in APS, 1: SAO parameter in slice data)
     157SAOLcuBoundary              : 0                                 # 0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas
     158SAOLcuBasedOptimization : 1                                  # 0: SAO picture-based optimization, 1: SAO LCU-based optimization
    158159ConstrainedIntraPred           : 0                                 # Constrained Intra Prediction
    159160weighted_pred_flag             : 0                                 # weighted prediction flag (P-Slices)
     
    196197MultiviewMvRegMode        : 1                                      # use original depth maps for regularizing inter-view motion vector
    197198MultiviewMvRegLambdaScale : 1.0                                    # lambda scale factor for inter-view motion vector regularization
    198 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     199MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    199200InterViewSkip             : 0                                      # interview SKIP mode
    200201InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
     
    203204FCO                        : 0                                      # Flexible coding order flag in 3DV
    204205FCOCodingOrder             : T0D0D1D2T1T2                           # Coding order for Flexible coding order in 3DV
    205 
     206UseVSPCompensation         : 1                                     # Depth dependent tools: BVSP
     207UseDVPRefine               : 1                                     # Depth dependent tools: DoNBDV
    206208
    207209#========== depth coding tools ==========
  • trunk/CommonTestConditionsCfgs/baseCfg_3view.cfg

    r210 r443  
    147147ALFPicBasedEncode              : 1                                 # ALF LCU-based or picture-based encoding (0: LCU-based, 1: Picture-based) 
    148148MaxNumOffsetsPerPic            : 2048                              # default
    149 SAOInterleaving                : 0                                 # SAO interleaving flag (0: SAO parameter in APS, 1: SAO parameter in slice data)
     149SAOLcuBoundary              : 0                                 # 0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas
     150SAOLcuBasedOptimization : 1                                  # 0: SAO picture-based optimization, 1: SAO LCU-based optimization
    150151ConstrainedIntraPred           : 0                                 # Constrained Intra Prediction
    151152weighted_pred_flag             : 0                                 # weighted prediction flag (P-Slices)
     
    188189MultiviewMvRegMode        : 0                                      # use original depth maps for regularizing inter-view motion vector
    189190MultiviewMvRegLambdaScale : 0.0                                    # lambda scale factor for inter-view motion vector regularization
    190 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     191MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    191192InterViewSkip             : 0                                      # interview SKIP mode
    192193InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
  • trunk/cfg/IBPsetting_balloons.cfg

    r297 r443  
    199199MultiviewMvRegMode        : 1                                      # use original depth maps for regularizing inter-view motion vector
    200200MultiviewMvRegLambdaScale : 1.0                                    # lambda scale factor for inter-view motion vector regularization
    201 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     201MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    202202InterViewSkip             : 0                                      # interview SKIP mode
    203203InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
  • trunk/cfg/IBPsetting_gtfly.cfg

    r297 r443  
    199199MultiviewMvRegMode        : 1                                      # use original depth maps for regularizing inter-view motion vector
    200200MultiviewMvRegLambdaScale : 1.0                                    # lambda scale factor for inter-view motion vector regularization
    201 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     201MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    202202InterViewSkip             : 0                                      # interview SKIP mode
    203203InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
  • trunk/cfg/IBPsetting_kendo.cfg

    r297 r443  
    199199MultiviewMvRegMode        : 1                                      # use original depth maps for regularizing inter-view motion vector
    200200MultiviewMvRegLambdaScale : 1.0                                    # lambda scale factor for inter-view motion vector regularization
    201 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     201MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    202202InterViewSkip             : 0                                      # interview SKIP mode
    203203InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
  • trunk/cfg/IBPsetting_news.cfg

    r297 r443  
    199199MultiviewMvRegMode        : 1                                      # use original depth maps for regularizing inter-view motion vector
    200200MultiviewMvRegLambdaScale : 1.0                                    # lambda scale factor for inter-view motion vector regularization
    201 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     201MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    202202InterViewSkip             : 0                                      # interview SKIP mode
    203203InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
  • trunk/cfg/IBPsetting_poznanhall.cfg

    r297 r443  
    199199MultiviewMvRegMode        : 1                                      # use original depth maps for regularizing inter-view motion vector
    200200MultiviewMvRegLambdaScale : 1.0                                    # lambda scale factor for inter-view motion vector regularization
    201 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     201MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    202202InterViewSkip             : 0                                      # interview SKIP mode
    203203InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
  • trunk/cfg/IBPsetting_poznanstreet.cfg

    r297 r443  
    199199MultiviewMvRegMode        : 1                                      # use original depth maps for regularizing inter-view motion vector
    200200MultiviewMvRegLambdaScale : 1.0                                    # lambda scale factor for inter-view motion vector regularization
    201 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     201MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    202202InterViewSkip             : 0                                      # interview SKIP mode
    203203InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
  • trunk/cfg/IBPsetting_undodancer.cfg

    r297 r443  
    199199MultiviewMvRegMode        : 1                                      # use original depth maps for regularizing inter-view motion vector
    200200MultiviewMvRegLambdaScale : 1.0                                    # lambda scale factor for inter-view motion vector regularization
    201 MultiviewResPred          : 1                                      # inter-view residual prediction (0:off, 1:on)
     201MultiviewResPred          : 1                                      # advanced inter-view residual prediction (0:off, 1:on)
    202202InterViewSkip             : 0                                      # interview SKIP mode
    203203InterViewSkipLambdaScale  : 8                                      # lambda scale for inter-view skip mode
  • trunk/source/App/TAppDecoder/TAppDecTop.cpp

    r296 r443  
    735735
    736736#if MERL_VSP_C0152
    737 Void TAppDecTop::setBWVSPLUT(TComSlice* pcSlice,  Int iCodedViewIdx,  Int iCurPoc)
     737Void TAppDecTop::setBWVSPLUT(
     738#if MERL_VSP_NBDV_RefVId_Fix_D0166
     739    Int iNeighborViewId,
     740#endif
     741    TComSlice* pcSlice,  Int iCodedViewIdx,  Int iCurPoc)
     742
    738743{
    739744  //first view does not have VSP
     
    742747  AOT( iCodedViewIdx <= 0);
    743748  //AOT( iCodedViewIdx >= m_iNumberOfViews );
     749#if !MERL_VSP_NBDV_RefVId_Fix_D0166
    744750  Int iNeighborViewId = 0;
     751#endif
    745752  //  Int* piShiftLUT = bRenderFromLeft ? m_cCamParsCollector.getBaseViewShiftLUTI()[iCodedViewIdx][iNeighborViewId][0] : m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
    746753  Int* piShiftLUT = m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
     754#if MERL_VSP_NBDV_RefVId_Fix_D0166
     755  pcSlice->setBWVSPLUTParam(piShiftLUT, 2-LOG2_DISP_PREC_LUT, iNeighborViewId );
     756#else
    747757  pcSlice->setBWVSPLUTParam(piShiftLUT, 2-LOG2_DISP_PREC_LUT );
     758#endif
    748759}
    749760#endif
  • trunk/source/App/TAppDecoder/TAppDecTop.h

    r296 r443  
    113113
    114114#if MERL_VSP_C0152
     115#if MERL_VSP_NBDV_RefVId_Fix_D0166
     116  Void  setBWVSPLUT( Int iNeighborViewId, TComSlice* pcSlice, Int iCodedViewIdx, Int iCurPoc );
     117#else
    115118  Void  setBWVSPLUT( TComSlice* pcSlice, Int iCodedViewIdx, Int iCurPoc   );
     119#endif
    116120#endif
    117121
  • trunk/source/App/TAppEncoder/TAppEncCfg.cpp

    r332 r443  
    383383#endif
    384384#if H3D_IVRP
     385#if QC_ARP_D0177
     386  ("MultiviewResPred", m_nUseAdvResPred,           (UInt)0, "usage of Advanced residual prediction" )
     387#else
    385388  ("MultiviewResPred", m_uiMultiviewResPredMode,   (UInt)0, "usage of inter-view residual prediction" )
     389#endif
     390#endif
     391#if MTK_D0156
     392  ("UseVSPCompensation", m_bUseVSPCompensation,   true, "Depth dependent tools: BVSP" )
     393  ("UseDVPRefine", m_bUseDVPRefine,   true, "Depth dependent tools: DoNBDV" )
    386394#endif
    387395
     
    392400  ("SAO", m_abUseSAO, std::vector<Bool>(1, true), "SAO")
    393401  ("MaxNumOffsetsPerPic", m_maxNumOffsetsPerPic, 2048, "2048: default")   
     402#if LGE_SAO_MIGRATION_D0091
     403  ("SAOLcuBoundary",          m_saoLcuBoundary,          false, "0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas")
     404  ("SAOLcuBasedOptimization", m_saoLcuBasedOptimization, true, "0: SAO picture-based optimization, 1: SAO LCU-based optimization ")
     405#else
    394406  ("SAOInterleaving", m_saoInterleavingFlag, false, "0: SAO Picture Mode, 1: SAO Interleaving ")   
     407#endif
    395408
    396409  ("ALFEncodePassReduction", m_iALFEncodePassReduction, 0, "0:Original 16-pass, 1: 1-pass, 2: 2-pass encoding")
     
    917930#endif
    918931#if H3D_IVRP
     932#if QC_ARP_D0177
     933#if QC_ARP_WARNING_FIX
     934  xConfirmPara    ( m_nUseAdvResPred > 1 , "0<=ARP<=1" );
     935#else
     936  xConfirmPara    ( m_nUseAdvResPred < 0 || m_nUseAdvResPred > 1 , "0<=ARP<=1" );
     937#endif
     938#else
    919939  xConfirmPara    ( m_uiMultiviewResPredMode > 1,                                     "MultiviewResPred must be less than or equal to 1" );
    920940  xConfirmPara    ( m_uiMultiviewResPredMode > 0 && m_uiPredDepthMapGeneration == 0 , "MultiviewResPred > 0 requires PredDepthMapGen > 0" );
     941#endif
    921942#endif
    922943  if( m_bUsingDepthMaps )
     
    16251646  printf("CIP:%d ", m_bUseConstrainedIntraPred);
    16261647  printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
     1648#if LGE_SAO_MIGRATION_D0091
     1649  printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0));
     1650#else
    16271651  printf("SAOInterleaving:%d ", (m_saoInterleavingFlag)?(1):(0));
     1652#endif
    16281653#if LOSSLESS_CODING
    16291654  printf("LosslessCuEnabled:%d ", (m_useLossless)? 1:0 );
     
    16721697  printf("IVSEnable: %d ", m_bUseIVS);
    16731698#endif
     1699#if QC_ARP_D0177
     1700  printf(" ARP:%d  " , m_nUseAdvResPred  );
     1701#endif
    16741702  printf("\n");
    16751703
     
    17081736  printf("DLT:%d ", m_bUseDLT ? 1 : 0 );
    17091737#endif
     1738
     1739#if MTK_D0156
     1740  printf("BVSP:%d ", m_bUseVSPCompensation ? 1 : 0 );
     1741  printf("DoNBDV:%d ",  m_bUseDVPRefine ? 1 : 0 );
     1742#endif
     1743
    17101744#if LGE_WVSO_A0119
    17111745  if ( m_bUseWVSO )
  • trunk/source/App/TAppEncoder/TAppEncCfg.h

    r332 r443  
    165165#endif
    166166  Int       m_maxNumOffsetsPerPic;                            ///< SAO maximun number of offset per picture
     167#if LGE_SAO_MIGRATION_D0091
     168  Bool      m_saoLcuBoundary;                                 ///< SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
     169  Bool      m_saoLcuBasedOptimization;                        ///< SAO LCU-based optimization
     170#else
    167171  Bool      m_saoInterleavingFlag;                            ///< SAO interleaving flag
     172#endif
    168173  // coding tools (loop filter)
    169174  vector<Bool> m_abUseALF;                                    ///< flag for using adaptive loop filter [0] - video, [1] - depth
     
    217222  Double    m_dMultiviewMvRegLambdaScale;                     ///< lambda scale for multiview motion vectors regularization
    218223#endif
    219 #if H3D_IVRP
     224#if H3D_IVRP
     225#if QC_ARP_D0177
     226  UInt      m_nUseAdvResPred;
     227#else
    220228  UInt      m_uiMultiviewResPredMode;          ///< using multiview residual prediction
     229#endif
    221230#endif
    222231
     
    317326#endif
    318327
     328#if MTK_D0156
     329
     330#if MERL_VSP_COMPENSATION_C0152
     331  Bool      m_bUseVSPCompensation;
     332#endif
     333
     334  Bool      m_bUseDVPRefine;
     335#endif
     336
    319337  // internal member functions
    320338  Void  xSetGlobal      ();                                   ///< set global variables
  • trunk/source/App/TAppEncoder/TAppEncTop.cpp

    r332 r443  
    223223#endif
    224224#if H3D_IVRP
     225#if QC_ARP_D0177
     226    m_acTEncTopList[iViewIdx]->setUseAdvRP                     ( iViewIdx ? m_nUseAdvResPred             : 0   );
     227    m_acTEncTopList[iViewIdx]->setARPStepNum                   ( iViewIdx ? QC_ARP_WFNR                  : 1   );
     228#else
    225229    m_acTEncTopList[iViewIdx]->setMultiviewResPredMode         ( m_uiMultiviewResPredMode );
     230#endif
     231#endif
     232#if MTK_D0156
     233#if MERL_VSP_COMPENSATION_C0152
     234    m_acTEncTopList[iViewIdx]->setUseVSPCompensation           ( iViewIdx ? m_bUseVSPCompensation : 0 );
     235#endif
     236    m_acTEncTopList[iViewIdx]->setUseDVPRefine                  ( iViewIdx ? m_bUseDVPRefine : 0 );
    226237#endif
    227238
     
    303314#endif
    304315    m_acTEncTopList[iViewIdx]->setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
     316#if LGE_SAO_MIGRATION_D0091
     317    m_acTEncTopList[iViewIdx]->setSaoLcuBoundary (m_saoLcuBoundary);
     318    m_acTEncTopList[iViewIdx]->setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
     319#else
    305320    m_acTEncTopList[iViewIdx]->setSaoInterleavingFlag (m_saoInterleavingFlag);
     321#endif
    306322    m_acTEncTopList[iViewIdx]->setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
    307323    m_acTEncTopList[iViewIdx]->setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
     
    560576      m_acTEncDepthTopList[iViewIdx]->setMultiviewMvRegLambdaScale    ( 0.0 );
    561577#endif
    562 #if H3D_IVRP
    563       m_acTEncDepthTopList[iViewIdx]->setMultiviewResPredMode         ( 0 );
     578#if H3D_IVRP
     579#if QC_ARP_D0177
     580    m_acTEncDepthTopList[iViewIdx]->setUseAdvRP                          ( 0 );
     581    m_acTEncDepthTopList[iViewIdx]->setARPStepNum                        ( 1 );
     582#else
     583    m_acTEncDepthTopList[iViewIdx]->setMultiviewResPredMode         ( 0 );
     584#endif
     585#endif
     586#if MTK_D0156
     587
     588#if MERL_VSP_COMPENSATION_C0152
     589      m_acTEncDepthTopList[iViewIdx]->setUseVSPCompensation           ( iViewIdx ? true : false );
     590#endif
     591
     592      m_acTEncDepthTopList[iViewIdx]->setUseDVPRefine                 ( iViewIdx ? true : false );
    564593#endif
    565594
     
    605634#endif
    606635      m_acTEncDepthTopList[iViewIdx]->setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
     636#if LGE_SAO_MIGRATION_D0091
     637      m_acTEncDepthTopList[iViewIdx]->setSaoLcuBoundary (m_saoLcuBoundary);
     638      m_acTEncDepthTopList[iViewIdx]->setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
     639#else
    607640      m_acTEncDepthTopList[iViewIdx]->setSaoInterleavingFlag (m_saoInterleavingFlag);
     641#endif
    608642      m_acTEncDepthTopList[iViewIdx]->setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
    609643      m_acTEncDepthTopList[iViewIdx]->setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
     
    10761110#if MERL_VSP_C0152
    10771111#if MERL_VSP_C0152_BugFix_ForNoDepthCase
    1078         if(m_bUsingDepthMaps) //VSP can be used only when depth is available as input
     1112        if(m_bUsingDepthMaps) // VSP can be used only when depth is available as input
    10791113        {
    10801114#endif
     
    10871121          pEncSlice->setRefPicBaseTxt(pcBaseTxtPic);
    10881122          pEncSlice->setRefPicBaseDepth(pcBaseDepthPic);
     1123#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1124          for (Int refViewId=0; refViewId < iViewIdx; refViewId++ )
     1125          {
     1126            pEncSlice->setListDepthPic(m_acTEncDepthTopList[refViewId]->getListPic(), refViewId ); // The list will store only the depth pictures
     1127            setBWVSPLUT(refViewId, iViewIdx, gopId, false);
     1128          }
     1129#endif
    10891130        }
     1131#if !MERL_VSP_NBDV_RefVId_Fix_D0166
    10901132        setBWVSPLUT( iViewIdx, gopId, false);
     1133#endif
     1134#endif
     1135
    10911136#if MERL_VSP_C0152_BugFix_ForNoDepthCase
    10921137        }
     
    11031148#endif
    11041149
    1105 #endif
    11061150        // call encoding function for one frame
    11071151        m_acTEncTopList[iViewIdx]->encode( eos[iViewIdx], pcPicYuvOrg, *m_picYuvRec[iViewIdx], outputAccessUnits, iNumEncoded, gopId );
     
    11181162          TEncSlice* pcSlice = (TEncSlice*) m_acTEncDepthTopList[iViewIdx]->getSliceEncoder();
    11191163          pcSlice->setRefPicBaseDepth(pcBaseDepthPic);
     1164#if  MERL_VSP_NBDV_RefVId_Fix_D0166
     1165          for (Int refViewId=0; refViewId < iViewIdx; refViewId++ )
     1166          {
     1167            pcSlice->setListDepthPic(m_acTEncDepthTopList[refViewId]->getListPic(), refViewId ); // The list will store only the depth pictures
     1168            setBWVSPLUT( refViewId, iViewIdx, gopId, true);
     1169          }
     1170#endif
    11201171        }
     1172#if !MERL_VSP_NBDV_RefVId_Fix_D0166
    11211173        setBWVSPLUT( iViewIdx, gopId, true);
     1174#endif
    11221175#endif
    11231176
     
    16361689
    16371690#if MERL_VSP_C0152
    1638 Void TAppEncTop::setBWVSPLUT(Int iCodedViewIdx, Int gopId, Bool isDepth)
     1691
     1692Void TAppEncTop::setBWVSPLUT(
     1693#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1694        Int iNeighborViewId,
     1695#endif
     1696        Int iCodedViewIdx, Int gopId, Bool isDepth)
    16391697{
    16401698  //first view does not have VSP
     
    16431701  AOT( iCodedViewIdx <= 0);
    16441702  AOT( iCodedViewIdx >= m_iNumberOfViews );
    1645 
     1703#if !MERL_VSP_NBDV_RefVId_Fix_D0166
    16461704  Int iNeighborViewId = 0;
     1705#endif
    16471706  //setting look-up table
    16481707  Int* piShiftLUT = m_cCameraData.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
     
    16511710  {
    16521711    TEncSlice* pcEncSlice = (TEncSlice*) m_acTEncDepthTopList[iCodedViewIdx]->getSliceEncoder();
     1712#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1713    pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT, iNeighborViewId );
     1714#else
    16531715    pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT );
     1716#endif
    16541717  }
    16551718  else
    16561719  {
    16571720    TEncSlice* pcEncSlice = (TEncSlice*) m_acTEncTopList[iCodedViewIdx]->getSliceEncoder();
     1721#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1722    pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT, iNeighborViewId );
     1723#else
    16581724    pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT );
     1725#endif
    16591726  }
    16601727
  • trunk/source/App/TAppEncoder/TAppEncTop.h

    r296 r443  
    167167
    168168#if MERL_VSP_C0152
     169#if MERL_VSP_NBDV_RefVId_Fix_D0166
     170  Void setBWVSPLUT( Int refViewIdx, Int iCodedViewIdx, Int gopId, Bool isDepth);
     171#else
    169172  Void setBWVSPLUT( Int iCodedViewIdx, Int gopId, Bool isDepth);
     173#endif
    170174#endif
    171175};// END CLASS DEFINITION TAppEncTop
  • trunk/source/Lib/TLibCommon/CommonDef.h

    r333 r443  
    5858
    5959#define HM_VERSION        "6.1"
    60 #define NV_VERSION        "6.2"                  ///< Current software version
     60#define NV_VERSION        "7.0"                  ///< Current software version
    6161
    6262// ====================================================================================================================
  • trunk/source/Lib/TLibCommon/ContextTables.h

    r332 r443  
    101101#define NUM_ALF_SVLC_CTX              3       ///< number of context models for ALF SVLC (filter coeff.)
    102102
     103#if LGE_SAO_MIGRATION_D0091
     104#define NUM_SAO_MERGE_FLAG_CTX        1       ///< number of context models for SAO merge flags
     105#define NUM_SAO_TYPE_IDX_CTX          1       ///< number of context models for SAO type index
     106#else
    103107#define NUM_SAO_FLAG_CTX              1       ///< number of context models for SAO flag
    104108#define NUM_SAO_UVLC_CTX              2       ///< number of context models for SAO UVLC
     
    108112#define NUM_SAO_MERGE_UP_FLAG_CTX     1       ///< number of context models for AO SVLC (filter coeff.)
    109113#define NUM_SAO_TYPE_IDX_CTX          2       ///< number of context models for AO SVLC (filter coeff.)
     114#endif
    110115#define CNU                          154      ///< dummy initialization value for unused context models 'Context model Not Used'
    111116
     
    128133
    129134#if RWTH_SDC_DLT_B0036
     135#if PKU_QC_DEPTH_INTRA_UNI_D0195
     136#define DEPTH_MODE_NUM_FLAG_CTX          8
     137#define DMM_DELTA_NUM_FLAG_CTX           1
     138#else
    130139#define SDC_NUM_FLAG_CTX                 3
     140#endif
    131141#define SDC_NUM_RESIDUAL_FLAG_CTX        1
     142#if !RWTH_SDC_CTX_SIMPL_D0032
    132143#define SDC_NUM_SIGN_FLAG_CTX            1
     144#endif
     145#if LGE_CONCATENATE_D0141
     146#define SDC_NUM_RESIDUAL_CTX             1
     147#else
     148#if RWTH_SDC_CTX_SIMPL_D0032
     149#define SDC_NUM_RESIDUAL_CTX             8
     150#else
    133151#define SDC_NUM_RESIDUAL_CTX             10
     152#endif
     153#endif
    134154
    135155#define SDC_NUM_PRED_MODE_CTX            5
     
    376396  { 141,  154,  159, },
    377397};
    378 
     398#if LGE_SAO_MIGRATION_D0091
     399static const UChar
     400INIT_SAO_MERGE_FLAG[3][NUM_SAO_MERGE_FLAG_CTX] =
     401{
     402  { 153,  },
     403  { 153,  },
     404  { 153,  },
     405};
     406
     407static const UChar
     408INIT_SAO_TYPE_IDX[3][NUM_SAO_TYPE_IDX_CTX] =
     409{
     410  { 200, },
     411  { 185, },
     412  { 160, },
     413};
     414#else
    379415static const UChar
    380416INIT_SAO_FLAG[3][NUM_SAO_FLAG_CTX] = 
     
    424460  { 200,  140, },
    425461};
     462#endif
    426463
    427464static const UChar
     
    487524#endif
    488525};
     526#if QC_ARP_D0177
     527#define NUM_ARPW_CTX                  4       ///< number of context models for generalized residual prediction weighting factor
     528static const UChar
     529INIT_ARPW[3][NUM_ARPW_CTX] =
     530{
     531  { 154 , 154 , 154 , 154 },
     532  { 154 , 154 , 154 , 154 },
     533  { 154 , 154 , 154 , 154 },
     534};
     535#endif
    489536
    490537#if LGE_EDGE_INTRA_A0070
     
    523570
    524571#if RWTH_SDC_DLT_B0036
     572#if PKU_QC_DEPTH_INTRA_UNI_D0195
     573static const UChar INIT_DEPTHMODE_FLAG[3][DEPTH_MODE_NUM_FLAG_CTX]=
     574{
     575  {0,  0,  64,   0, CNU,   0, CNU, 0},
     576  {0, 64,   0, CNU,   0, CNU,   0, 0},
     577  {64, 0, CNU,   0, CNU,   0,   0, 0}
     578};
     579static const UChar INIT_DMMDELTA_FLAG[3][DMM_DELTA_NUM_FLAG_CTX]=
     580{
     581  {0},
     582  {0},
     583  {64}
     584};
     585#else
    525586static const Short INIT_SDC_FLAG[3][SDC_NUM_FLAG_CTX][2] =
    526587{
     
    535596  }
    536597};
    537 
     598#endif
     599
     600#if RWTH_SDC_CTX_SIMPL_D0032
     601static const UChar INIT_SDC_RESIDUAL_FLAG[3][SDC_NUM_RESIDUAL_FLAG_CTX] =
     602{
     603  {
     604    CNU
     605   
     606  },
     607  {
     608    CNU
     609  },
     610  {
     611    CNU
     612  }
     613};
     614   
     615#if LGE_CONCATENATE_D0141
     616static const UChar INIT_SDC_RESIDUAL[3][SDC_NUM_RESIDUAL_CTX] =
     617{
     618    {
     619         155
     620    },
     621    {
     622         155
     623    },
     624    {
     625        155
     626    }
     627};
     628#else
     629static const UChar INIT_SDC_RESIDUAL[3][SDC_NUM_RESIDUAL_CTX] =
     630{
     631  {
     632    CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU
     633  },
     634  {
     635    CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU
     636  },
     637  {
     638    CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU
     639  }
     640};
     641#endif
     642
     643static const UChar INIT_SDC_PRED_MODE[3][3*SDC_NUM_PRED_MODE_CTX] =
     644{
     645  {
     646    CNU,    CNU
     647    ,CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU
     648  },
     649  {
     650    CNU,    CNU
     651    ,CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU
     652  },
     653  {
     654    CNU,    CNU
     655    ,CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU
     656  }
     657};
     658#else
    538659static const Short INIT_SDC_RESIDUAL_FLAG[3][3*SDC_NUM_RESIDUAL_FLAG_CTX][2] =
    539660{
     
    613734};
    614735#endif
     736#endif
    615737
    616738//! \}
  • trunk/source/Lib/TLibCommon/TComDataCU.cpp

    r332 r443  
    5353#if MERL_VSP_C0152
    5454
     55#if MTK_D0156
     56#define CHECK_ADD_YET(pcCURef,uiIdx,vspIdx) && ( (!m_pcSlice->getSPS()->getUseVSPCompensation()) || (!( (pcCURef)->getVSPIndex(uiIdx) == vspIdx && bVspMvZeroDone[vspIdx-1] )))
     57#else
    5558#define CHECK_ADD_YET(pcCURef,uiIdx,vspIdx) && !( (pcCURef)->getVSPIndex(uiIdx) == vspIdx && bVspMvZeroDone[vspIdx-1] )
    56 
    57 inline Void TComDataCU::xInheritVspMode( TComDataCU* pcCURef, UInt uiIdx, Bool* bVspMvZeroDone, Int iCount, Int* iVSPIndexTrue, TComMvField* pcMvFieldNeighbours, DisInfo* pDInfo )
    58 {
     59#endif
     60
     61inline Void TComDataCU::xInheritVspMode( TComDataCU* pcCURef, UInt uiIdx, Bool* bVspMvZeroDone, Int iCount, Int* iVSPIndexTrue, TComMvField* pcMvFieldNeighbours, DisInfo* pDInfo
     62#if QC_BVSP_CleanUP_D0191
     63  , UChar *puhInterDirNeighbours
     64#endif
     65#if MERL_VSP_NBDV_RefVId_Fix_D0166
     66    , Int*     iVSPDirTrue
     67#endif
     68    )
     69{
     70#if MTK_D0156
     71    if( !m_pcSlice->getSPS()->getUseVSPCompensation() )
     72    {
     73        return;
     74    }
     75#endif
     76
    5977  Int vspIdx = (Int) pcCURef->getVSPIndex(uiIdx);
    6078  if( vspIdx != 0 )
     
    6987    if (vspIdx < 4)
    7088    {
     89#if QC_BVSP_CleanUP_D0191
     90      puhInterDirNeighbours[ iCount] = 1;
     91#endif
     92#if MERL_VSP_NBDV_RefVId_Fix_D0166
     93      if(pDInfo->iN > 0 )
     94      { // using derived disparity and store corresponding used reference list and ref idx
     95        iVSPDirTrue[idx] = pDInfo->m_aListIdx[0];
     96        assert(pDInfo->m_aRefIdx[0] < 0);
     97#if MTK_VSP_USING_NBDV_D0105
     98        pcMvFieldNeighbours[iCount<<1].setMvField( pDInfo->m_acMvCandNoRef[0], pDInfo->m_aRefIdx[0] );
     99#else
     100        pcMvFieldNeighbours[iCount<<1].setMvField( pDInfo->m_acMvCand[0], pDInfo->m_aRefIdx[0] );
     101#endif
     102        if ( pcCURef->getSlice()->isInterB() )
     103        {
     104#if MTK_VSP_USING_NBDV_D0105
     105          pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0], pDInfo->m_aRefIdx[0] );
     106#else
     107          pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCand[0], pDInfo->m_aRefIdx[0] );
     108#endif
     109        }
     110      }
     111      else
     112      { // using the original neighboring block vsp reference list
     113        TComMv cMvPred = pcCURef->getCUMvField(REF_PIC_LIST_0)->getMv(uiIdx);
     114        Int    refId   = pcCURef->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiIdx);
     115
     116        assert(refId < 0);
     117        iVSPDirTrue[idx] = pcCURef->getVSPDir(uiIdx);
     118        pcMvFieldNeighbours[iCount<<1].setMvField( cMvPred, refId );
     119        if ( pcCURef->getSlice()->isInterB() )
     120        {
     121          pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cMvPred, refId );
     122        }
     123      }
     124
     125#else // !MERL_VSP_NBDV_RefVId_Fix_D0166
     126
     127#if MTK_VSP_USING_NBDV_D0105
     128      pcMvFieldNeighbours[ iCount<<1].setMvField ( pDInfo->m_acMvCandNoRef[0],  NOT_VALID );
     129#else
    71130      pcMvFieldNeighbours[ iCount<<1].setMvField ( pDInfo->m_acMvCand[0],  NOT_VALID );
     131#endif
    72132      if ( pcCURef->getSlice()->isInterB() )
    73133      {
     134#if MTK_VSP_USING_NBDV_D0105
     135        pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField ( pDInfo->m_acMvCandNoRef[0],  NOT_VALID );
     136#else
    74137         pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField ( pDInfo->m_acMvCand[0],  NOT_VALID );
    75       }
    76     }
    77   }
    78 }
    79 
    80 inline Bool TComDataCU::xAddVspMergeCand( UChar ucVspMergePos, Int vspIdx, Bool* bVspMvZeroDone, UInt uiDepth, Bool* abCandIsInter, Int& iCount,
    81                                           UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, Int* iVSPIndexTrue, Int mrgCandIdx, DisInfo* pDInfo )
    82 {
     138#endif
     139      }
     140#endif
     141    }
     142  }
     143}
     144
     145inline Bool TComDataCU::xAddVspMergeCand(
     146 UChar ucVspMergePos,
     147#if !LGE_VSP_INHERIT_D0092
     148 Int vspIdx,
     149 Bool* bVspMvZeroDone,
     150#endif
     151 UInt uiDepth,
     152 Bool* abCandIsInter,
     153 Int& iCount,
     154 UChar* puhInterDirNeighbours,
     155 TComMvField* pcMvFieldNeighbours,
     156 Int* iVSPIndexTrue,
     157 Int mrgCandIdx,
     158 DisInfo* pDInfo
     159#if MERL_VSP_NBDV_RefVId_Fix_D0166
     160 , Int*  iVspDirTrue
     161#endif
     162                                          )
     163{
     164#if MTK_D0156
     165    if( !m_pcSlice->getSPS()->getUseVSPCompensation() )
     166    {
     167        return true;
     168    }
     169#endif
     170
     171#if MTK_LGE_VSP_DEPTH_OFF_D0105_D0139
     172  if (getSlice()->getSPS()->isDepth())
     173  {
     174    return true;
     175  }
     176#endif
     177
    83178#if MERL_VSP_C0152_BugFix_ForNoDepthCase
    84179  TComPic* pRefPicBaseDepth = NULL;
    85180  pRefPicBaseDepth = getSlice()->getRefPicBaseDepth();
    86   if(ucVspMergePos == VSP_MERGE_POS && pRefPicBaseDepth) //VSP can be used only when depth is used as input
     181  if(ucVspMergePos == VSP_MERGE_POS && pRefPicBaseDepth) // VSP can be used only when depth is used as input
    87182#else
    88183  if( ucVspMergePos == VSP_MERGE_POS )
     
    90185  if( ucVspMergePos == VSP_MERGE_POS )
    91186  {
     187#if !LGE_VSP_INHERIT_D0092
    92188    Int idx = vspIdx - 1;
    93     {
     189#endif
     190    {
     191#if LGE_VSP_INHERIT_D0092
     192      if( getSlice()->getSPS()->getViewId() != 0 )
     193#else
    94194      if( getSlice()->getSPS()->getViewId() != 0 && bVspMvZeroDone[idx] == false )
     195#endif
    95196      {
    96197        {
    97198          abCandIsInter [iCount] = true;
     199#if !LGE_VSP_INHERIT_D0092
    98200          bVspMvZeroDone[idx] = true;
     201#endif
    99202
    100203          // get Inter Dir
     
    102205            (getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 0 ? 1 : 2));
    103206          puhInterDirNeighbours[iCount] = iInterDir; // The direction information does not matter
     207#if QC_BVSP_CleanUP_D0191
     208         puhInterDirNeighbours[iCount] = 1;
     209#endif
     210#if LGE_VSP_INHERIT_D0092
     211#if MERL_VSP_NBDV_RefVId_Fix_D0166
     212         assert(pDInfo->m_aRefIdx[0] < 0);
     213         iVspDirTrue[0] = pDInfo->m_aListIdx[0];
     214         Int iRefIdxList0 = NOT_VALID;
     215         Int iRefIdxList1 = NOT_VALID;
     216         iRefIdxList0 = getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==getSlice()->getPOC() ? 0 : (getSlice()->getNewRefIdx(REF_PIC_LIST_0)==-1 ? NOT_VALID : getSlice()->getNewRefIdx(REF_PIC_LIST_0));
     217         if ( getSlice()->isInterB() )
     218         {
     219            iRefIdxList1 = getSlice()->getRefPic(REF_PIC_LIST_1, 0)->getPOC()==getSlice()->getPOC() ? 0 : (getSlice()->getNewRefIdx(REF_PIC_LIST_1)==-1 ? NOT_VALID : getSlice()->getNewRefIdx(REF_PIC_LIST_1));
     220         }
     221
     222#if MTK_VSP_USING_NBDV_D0105
     223        //pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCandNoRef[0], pDInfo->m_aListIdx[0]==REF_PIC_LIST_0 ? iRefIdxList0 :NOT_VALID  );
     224        pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCandNoRef[0],  iRefIdxList0 );
     225#else
     226        pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCand[0],  iRefIdxList0 );
     227#endif
     228         if ( getSlice()->isInterB() )
     229         {
     230#if MTK_VSP_USING_NBDV_D0105
     231          pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0], iRefIdxList1 );
     232          //pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0],  iRefIdxList1);
     233#else
     234          pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCand[0], iRefIdxList1);
     235#endif
     236         }
     237         iVSPIndexTrue[iCount] = 1;
     238#else
     239
     240#if !MERL_General_Fix
     241         Int iRefIdxList0 = NOT_VALID;
     242         Int iRefIdxList1 = NOT_VALID;
     243         iRefIdxList0 = getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==getSlice()->getPOC() ? 0 : (getSlice()->getNewRefIdx(REF_PIC_LIST_0)==-1 ? NOT_VALID : getSlice()->getNewRefIdx(REF_PIC_LIST_0));
     244         if ( getSlice()->isInterB() )
     245         {
     246           iRefIdxList1 = getSlice()->getRefPic(REF_PIC_LIST_1, 0)->getPOC()==getSlice()->getPOC() ? 0 : (getSlice()->getNewRefIdx(REF_PIC_LIST_1)==-1 ? NOT_VALID : getSlice()->getNewRefIdx(REF_PIC_LIST_1));
     247         }
     248#if MTK_VSP_USING_NBDV_D0105
     249         pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCandNoRef[0],  iRefIdxList0 );
     250#else
     251         pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCand[0],  iRefIdxList0 );
     252#endif
     253         if ( getSlice()->isInterB() )
     254         {
     255#if MTK_VSP_USING_NBDV_D0105
     256           pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0], iRefIdxList1 );
     257#else
     258           pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCand[0], iRefIdxList1);
     259#endif
     260         }
     261         iVSPIndexTrue[iCount] = 1;
     262#else
     263         Int iRefIdx = NOT_VALID;
     264
     265#if QC_BVSP_CleanUP_D0191
     266         iRefIdx = getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==getSlice()->getPOC() ? 0: getSlice()->getNewRefIdx(REF_PIC_LIST_0);
     267#endif
     268#if MTK_VSP_USING_NBDV_D0105
     269         pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCandNoRef[0], iRefIdx );
     270#else
     271         pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCand[0], iRefIdx );
     272#endif
     273         if ( getSlice()->isInterB() )
     274         {
     275#if MTK_VSP_USING_NBDV_D0105
     276           pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0], iRefIdx );
     277#else
     278             pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCand[0], iRefIdx );
     279#endif
     280         }
     281         iVSPIndexTrue[iCount] = 1;
     282#endif
     283#endif
     284#else
    104285          // get Mv using checked disparity vector
    105286          if (vspIdx < 4) // spatial
    106287          {
    107             pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCand[0], NOT_VALID );
     288#if MERL_VSP_NBDV_RefVId_Fix_D0166
     289            assert(pDInfo->m_aRefIdx[0] < 0);
     290            iVspDirTrue[idx] = pDInfo->m_aListIdx[0];
     291
     292#if MTK_VSP_USING_NBDV_D0105
     293            pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCandNoRef[0], pDInfo->m_aRefIdx[0] );
     294#else
     295            pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCand[0], pDInfo->m_aRefIdx[0] );
     296#endif
    108297            if ( getSlice()->isInterB() )
    109298            {
     299#if MTK_VSP_USING_NBDV_D0105
     300              pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0], pDInfo->m_aRefIdx[0] );
     301#else
     302              pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCand[0], pDInfo->m_aRefIdx[0] );
     303#endif
     304            }
     305
     306#else
     307
     308#if MTK_VSP_USING_NBDV_D0105
     309            pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCandNoRef[0], NOT_VALID );
     310#else
     311            pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCand[0], NOT_VALID );
     312#endif
     313            if ( getSlice()->isInterB() )
     314            {
     315#if MTK_VSP_USING_NBDV_D0105
     316              pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0], NOT_VALID );
     317#else
    110318              pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCand[0], NOT_VALID );
     319#endif
    111320            }
     321#endif
    112322          }
    113323          iVSPIndexTrue[idx] = iCount;
     324#endif
    114325          if ( mrgCandIdx == iCount )
    115326          {
     
    155366#if MERL_VSP_C0152
    156367  m_piVSPIndex         = NULL;
     368#if MERL_VSP_NBDV_RefVId_Fix_D0166
     369  m_piVSPDir           = NULL;
     370#endif
    157371#endif
    158372  m_puhLumaIntraDir    = NULL;
     
    225439  m_pbResPredFlag      = NULL;
    226440#endif
     441#if QC_ARP_D0177
     442  m_puhARPW           = NULL;
     443#endif
    227444#if LGE_EDGE_INTRA_A0070
    228445  m_pucEdgeCode         = NULL;
     
    241458  m_apSegmentDCOffset[1] = NULL;
    242459#endif
     460#if QC_CU_NBDV_D0181
     461  m_pDvInfo              = NULL;
     462#endif
    243463}
    244464
     
    288508    m_pbICFlag           = (Bool*  )xMalloc(Bool,   uiNumPartition);
    289509#endif
     510#if QC_CU_NBDV_D0181
     511    m_pDvInfo            = (DisInfo* )xMalloc(DisInfo,  uiNumPartition);
     512#endif
    290513    m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
    291514#if MERL_VSP_C0152
    292515    m_piVSPIndex         = (Char*  )xMalloc(Char,   uiNumPartition);
     516#if MERL_VSP_NBDV_RefVId_Fix_D0166
     517    m_piVSPDir           = (Char*  )xMalloc(Char,   uiNumPartition);
     518#endif
    293519#endif
    294520#if H3D_IVRP
    295521    m_pbResPredAvailable = (Bool*  )xMalloc(Bool,   uiNumPartition);
    296522    m_pbResPredFlag      = (Bool*  )xMalloc(Bool,   uiNumPartition);
     523#if QC_ARP_D0177
     524    m_puhARPW            = new UChar[ uiNumPartition];
     525#endif
    297526#endif
    298527    m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
     
    448677#if MERL_VSP_C0152
    449678    if ( m_piVSPIndex         ) { xFree(m_piVSPIndex);          m_piVSPIndex        = NULL; }
     679#if MERL_VSP_NBDV_RefVId_Fix_D0166
     680    if ( m_piVSPDir           ) { xFree(m_piVSPDir  );          m_piVSPDir          = NULL; }
     681#endif
    450682#endif
    451683    if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
     
    453685    if ( m_pbResPredAvailable ) { xFree(m_pbResPredAvailable);  m_pbResPredAvailable= NULL; }
    454686    if ( m_pbResPredFlag      ) { xFree(m_pbResPredFlag);       m_pbResPredFlag     = NULL; }
     687#endif
     688#if QC_CU_NBDV_D0181
     689    if ( m_pDvInfo            ) { xFree(m_pDvInfo);             m_pDvInfo           = NULL; }
     690#endif
     691#if QC_ARP_D0177
     692    if ( m_puhARPW           )  { delete[] m_puhARPW;          m_puhARPW          = NULL; }
    455693#endif
    456694    if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
     
    627865    m_pbSDCFlag[ui] = pcFrom->getSDCFlag(ui);
    628866#endif
     867#if QC_ARP_D0177
     868    m_puhARPW[ui] = pcFrom->getARPW( ui );
     869#endif
    629870    m_puhWidth  [ui] = pcFrom->getWidth(ui);
    630871    m_puhHeight [ui] = pcFrom->getHeight(ui);
     
    644885#if MERL_VSP_C0152
    645886    m_piVSPIndex[ui] = pcFrom->m_piVSPIndex[ui];
     887#if MERL_VSP_NBDV_RefVId_Fix_D0166
     888    m_piVSPDir  [ui] = pcFrom->m_piVSPDir  [ui];
     889#endif
    646890#endif
    647891    m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
     
    687931#if MERL_VSP_C0152
    688932    memset( m_piVSPIndex        + firstElement, 0,                        numElements * sizeof( *m_piVSPIndex ) );
     933#if MERL_VSP_NBDV_RefVId_Fix_D0166
     934    memset( m_piVSPDir          + firstElement, 0,                        numElements * sizeof( *m_piVSPDir   ) );
     935#endif
    689936#endif
    690937    memset( m_puhLumaIntraDir   + firstElement, 2,                        numElements * sizeof( *m_puhLumaIntraDir ) );
     
    723970    memset( m_pbResPredAvailable       + firstElement, 0    , sizeof( Bool ) * numElements );
    724971    memset( m_pbResPredFlag            + firstElement, 0    , sizeof( Bool ) * numElements );
     972#endif
     973#if QC_ARP_D0177
     974    memset( m_puhARPW                  + firstElement, 0    , sizeof( UChar ) * numElements  );
    725975#endif
    726976  }
     
    8611111#if MERL_VSP_C0152
    8621112      m_piVSPIndex[ui] = 0;
     1113#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1114      m_piVSPDir  [ui] = 0;
     1115#endif
    8631116#endif
    8641117#if H3D_IVRP
    8651118      m_pbResPredAvailable[ui] = 0;
    8661119      m_pbResPredFlag[ui]      = 0;
     1120#endif
     1121#if QC_ARP_D0177
     1122      m_puhARPW[ui] = 0;
    8671123#endif
    8681124      m_puhLumaIntraDir[ui] = 2;
     
    9721228#if MERL_VSP_C0152
    9731229  memset( m_piVSPIndex,         0, iSizeInChar );
     1230#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1231  memset( m_piVSPDir  ,         0, iSizeInChar );
     1232#endif
    9741233#endif
    9751234#if H3D_IVRP
    9761235  memset( m_pbResPredAvailable, 0, iSizeInBool  );
    9771236  memset( m_pbResPredFlag,      0, iSizeInBool  );
     1237#endif
     1238#if QC_ARP_D0177
     1239  memset( m_puhARPW,            0, iSizeInUchar  );
    9781240#endif
    9791241  memset( m_puhLumaIntraDir,    2, iSizeInUchar );
     
    10151277  memset( m_apSegmentDCOffset[1],     0, sizeof(Pel) * m_uiNumPartition);
    10161278#endif
    1017 
     1279#if QC_CU_NBDV_D0181
     1280  m_pDvInfo->bDV = false;
     1281#endif
    10181282  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
    10191283  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
     
    10581322#if MERL_VSP_C0152
    10591323      m_piVSPIndex[ui]=pcCU->m_piVSPIndex[uiPartOffset+ui];
     1324#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1325      m_piVSPDir  [ui]=pcCU->m_piVSPDir  [uiPartOffset+ui];
     1326#endif
    10601327#endif
    10611328      m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
     
    10901357      m_pbResPredAvailable[ui] = pcCU->m_pbResPredAvailable[ uiPartOffset + ui ];
    10911358      m_pbResPredFlag     [ui] = pcCU->m_pbResPredFlag     [ uiPartOffset + ui ];
     1359#endif
     1360#if QC_ARP_D0177
     1361      m_puhARPW           [ui] = pcCU->getARPW( uiPartOffset+ui );
    10921362#endif
    10931363#if RWTH_SDC_DLT_B0036
     
    12081478#if MERL_VSP_C0152
    12091479  m_piVSPIndex          = pcCU->getVSPIndex()         + uiPart;
     1480#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1481  m_piVSPDir            = pcCU->getVSPDir  ()         + uiPart;
     1482#endif
    12101483#endif
    12111484#if H3D_IVRP
    12121485  m_pbResPredAvailable  = pcCU->getResPredAvail()     + uiPart;
    12131486  m_pbResPredFlag       = pcCU->getResPredFlag ()     + uiPart;
     1487#endif
     1488#if QC_ARP_D0177
     1489  m_puhARPW             = pcCU->getARPW() + uiPart;
    12141490#endif
    12151491  m_puhLumaIntraDir     = pcCU->getLumaIntraDir()     + uiPart;
     
    13131589  m_apSegmentDCOffset[1]    = pcCU->getSDCSegmentDCOffset(1) + uiPart;
    13141590#endif
    1315 }
    1316 
     1591#if QC_CU_NBDV_D0181
     1592  m_pDvInfo                 = pcCU->getDvInfo()              + uiPart;
     1593#endif
     1594}
     1595#if QC_CU_NBDV_D0181
     1596Void TComDataCU::copyDVInfoFrom (TComDataCU* pcCU, UInt uiAbsPartIdx)
     1597{
     1598  m_pDvInfo            = pcCU->getDvInfo()                + uiAbsPartIdx;
     1599}
     1600#endif
    13171601// Copy inter prediction info from the biggest CU
    1318 Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList )
     1602Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList
     1603#if QC_CU_NBDV_D0181
     1604  , Bool bNBDV
     1605#endif
     1606  )
    13191607{
    13201608  m_pcPic              = pcCU->getPic();
     
    13361624 
    13371625  m_pePartSize         = pcCU->getPartitionSize ()        + uiAbsPartIdx;
     1626#if QC_CU_NBDV_D0181
     1627  if(bNBDV == true)
     1628  {
     1629    m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
     1630    m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
     1631    m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
     1632  }
     1633  else
     1634  {
     1635#endif
    13381636#if HHI_INTERVIEW_SKIP
    13391637  m_pbRenderable         = pcCU->getRenderable()        + uiAbsPartIdx;
     
    13541652#if MERL_VSP_C0152
    13551653  m_piVSPIndex         = pcCU->getVSPIndex()              + uiAbsPartIdx;
     1654#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1655  m_piVSPDir           = pcCU->getVSPDir  ()              + uiAbsPartIdx;
     1656#endif
    13561657#endif
    13571658#if H3D_IVRP
     
    13591660  m_pbResPredFlag      = pcCU->getResPredFlag ()          + uiAbsPartIdx;
    13601661#endif
     1662#if QC_ARP_D0177
     1663  m_puhARPW           = pcCU->getARPW()                 + uiAbsPartIdx;
     1664#endif
    13611665  m_apiMVPIdx[eRefPicList] = pcCU->getMVPIdx(eRefPicList) + uiAbsPartIdx;
    13621666  m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx;
     
    13691673  memcpy(m_uiSliceStartCU,pcCU->m_uiSliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
    13701674  memcpy(m_uiEntropySliceStartCU,pcCU->m_uiEntropySliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
     1675#if QC_CU_NBDV_D0181
     1676  }
     1677#endif
    13711678}
    13721679
    13731680// Copy small CU to bigger CU.
    13741681// One of quarter parts overwritten by predicted sub part.
    1375 Void TComDataCU::copyPartFrom( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth )
     1682Void TComDataCU::copyPartFrom( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth
     1683#if QC_ARP_D0177
     1684     ,
     1685    Bool bRP
     1686#endif
     1687    )
    13761688{
    13771689  assert( uiPartUnitIdx<4 );
     
    14051717#if MERL_VSP_C0152
    14061718  memcpy( m_piVSPIndex          + uiOffset, pcCU->getVSPIndex(),          iSizeInChar );
     1719#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1720  memcpy( m_piVSPDir            + uiOffset, pcCU->getVSPDir  (),          iSizeInChar );
     1721#endif
    14071722#endif
    14081723#if H3D_IVRP
    14091724  memcpy( m_pbResPredAvailable  + uiOffset, pcCU->getResPredAvail(),      iSizeInBool  );
    14101725  memcpy( m_pbResPredFlag       + uiOffset, pcCU->getResPredFlag(),       iSizeInBool  );
     1726#endif
     1727#if QC_ARP_D0177
     1728  memcpy( m_puhARPW            + uiOffset,  pcCU->getARPW(),              iSizeInUchar );
    14111729#endif
    14121730  memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
     
    14861804
    14871805#if LGE_EDGE_INTRA_A0070
     1806#if QC_ARP_D0177
     1807  if( !bRP && pcCU->getSlice()->getSPS()->isDepth() )
     1808#else
    14881809  if( getSlice()->getSPS()->isDepth() )
     1810#endif
    14891811  {
    14901812    memcpy( getEdgeCode( uiOffset ), pcCU->getEdgeCode(0), iSizeInUchar * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
     
    15411863  memcpy( rpcCU->getICFlag()            + m_uiAbsIdxInLCU, m_pbICFlag,            iSizeInBool );
    15421864#endif
     1865#if QC_CU_NBDV_D0181
     1866  memcpy( rpcCU->getDvInfo()            + m_uiAbsIdxInLCU, m_pDvInfo,             sizeof(* m_pDvInfo) * m_uiNumPartition );
     1867#endif
    15431868  memcpy( rpcCU->getMergeIndex()        + m_uiAbsIdxInLCU, m_puhMergeIndex,       iSizeInUchar );
    15441869#if MERL_VSP_C0152
    15451870  memcpy( rpcCU->getVSPIndex()          + m_uiAbsIdxInLCU, m_piVSPIndex,         iSizeInChar );
     1871#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1872  memcpy( rpcCU->getVSPDir  ()          + m_uiAbsIdxInLCU, m_piVSPDir  ,         iSizeInChar );
     1873#endif
    15461874#endif
    15471875#if H3D_IVRP
    15481876  memcpy( rpcCU->getResPredAvail()      + m_uiAbsIdxInLCU, m_pbResPredAvailable,  iSizeInBool  );
    15491877  memcpy( rpcCU->getResPredFlag()       + m_uiAbsIdxInLCU, m_pbResPredFlag,       iSizeInBool  );
     1878#endif
     1879#if QC_ARP_D0177
     1880  memcpy( rpcCU->getARPW()              + m_uiAbsIdxInLCU, m_puhARPW,             iSizeInUchar );
    15501881#endif
    15511882  memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
     
    16742005  memcpy( rpcCU->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
    16752006#if MERL_VSP_C0152
    1676   memcpy( rpcCU->getVSPIndex()          + uiPartOffset, m_piVSPIndex,         iSizeInChar );
     2007  memcpy( rpcCU->getVSPIndex()          + uiPartOffset, m_piVSPIndex,          iSizeInChar );
     2008#if MERL_VSP_NBDV_RefVId_Fix_D0166
     2009  memcpy( rpcCU->getVSPDir  ()          + uiPartOffset, m_piVSPDir  ,          iSizeInChar );
     2010#endif
    16772011#endif
    16782012#if H3D_IVRP
    16792013  memcpy( rpcCU->getResPredAvail()      + uiPartOffset, m_pbResPredAvailable,  iSizeInBool  );
    16802014  memcpy( rpcCU->getResPredFlag()       + uiPartOffset, m_pbResPredFlag,       iSizeInBool  );
     2015#endif
     2016#if QC_ARP_D0177
     2017  memcpy( rpcCU->getARPW()              + uiPartOffset, m_puhARPW,            iSizeInUchar );
    16812018#endif
    16822019  memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
     
    26703007  return uiCtx;
    26713008}
    2672 
     3009#if QC_ARP_D0177
     3010UInt TComDataCU::getCTXARPWFlag( UInt uiAbsPartIdx )
     3011{
     3012  TComDataCU* pcTempCU;
     3013  UInt        uiTempPartIdx;
     3014  UInt        uiCtx = 0;
     3015 
     3016  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
     3017  uiCtx    = ( pcTempCU ) ? ((pcTempCU->getARPW( uiTempPartIdx )==0)?0:1) : 0;
     3018 
     3019  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
     3020  uiCtx   += ( pcTempCU ) ? ((pcTempCU->getARPW( uiTempPartIdx )==0)?0:1): 0;
     3021 
     3022  return uiCtx;
     3023}
     3024#endif
    26733025#if LGE_ILLUCOMP_B0045
    26743026UInt TComDataCU::getCtxICFlag( UInt uiAbsPartIdx )
     
    29073259}
    29083260
     3261#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    29093262UInt TComDataCU::getCtxSDCFlag( UInt uiAbsPartIdx )
    29103263{
     
    29233276  return uiCtx;
    29243277}
     3278#endif
    29253279
    29263280Bool TComDataCU::getSDCAvailable( UInt uiAbsPartIdx )
     
    29543308  setSubPart<Char>( iVSPIdx, m_piVSPIndex, uiAbsPartIdx, uiDepth, uiPartIdx );
    29553309}
    2956 #endif
     3310
     3311#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3312Void TComDataCU::setVSPDirSubParts ( Char iVSPDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
     3313{
     3314  setSubPart<Char>( iVSPDir, m_piVSPDir, uiAbsPartIdx, uiDepth, uiPartIdx );
     3315}
     3316#endif
     3317
     3318#endif // MERL_VSP_C0152
    29573319
    29583320#if H3D_IVRP
     
    29673329}
    29683330#endif
    2969 
     3331#if QC_CU_NBDV_D0181
     3332Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth )
     3333{
     3334  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
     3335  for (UInt ui = 0; ui < uiCurrPartNumb; ui++ )
     3336  {
     3337    m_pDvInfo[uiAbsPartIdx + ui] = cDvInfo;
     3338  }
     3339}
     3340#endif
    29703341Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
    29713342{
     
    29933364  UInt iNumbPart;
    29943365
     3366#if SHARP_ILLUCOMP_PARSE_D0060
     3367  if (!(getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N))
     3368  {
     3369    return false;
     3370  }
     3371  if (getSlice()->getIcSkipParseFlag())
     3372  {
     3373    if (getMergeFlag(uiAbsPartIdx) && getMergeIndex(uiAbsPartIdx) == 0)
     3374    {
     3375      return false;
     3376    }
     3377  }
     3378  if (getMergeFlag(uiAbsPartIdx))
     3379  {
     3380    return true;
     3381  }
     3382#endif
     3383#if !SHARP_ILLUCOMP_PARSE_D0060
    29953384  if(!getSlice()->getIsDepth())
    29963385  {
     3386#endif
    29973387    Int iWidth, iHeight;
    29983388
     
    30153405      }
    30163406    }
     3407#if !SHARP_ILLUCOMP_PARSE_D0060
    30173408  }
    30183409  else
     
    30363427    }
    30373428  }
     3429#endif
    30383430
    30393431  return false;
     
    30463438  Int iWidth, iHeight;
    30473439
     3440#if SHARP_ILLUCOMP_PARSE_D0060
     3441  if (!(getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N))
     3442  {
     3443    return false;
     3444  }
     3445  if (getSlice()->getIcSkipParseFlag())
     3446  {
     3447    if (getMergeFlag(uiAbsPartIdx) && getMergeIndex(uiAbsPartIdx) == 0)
     3448    {
     3449      return false;
     3450    }
     3451  }
     3452  if (getMergeFlag(uiAbsPartIdx))
     3453  {
     3454    return true;
     3455  }
     3456#endif
    30483457  UInt uiPartMode = getPartitionSize(uiAbsPartIdx);
    30493458
     
    35273936 */
    35283937#if MERL_VSP_C0152
    3529 Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int* iVSPIndexTrue, Int mrgCandIdx )
     3938Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int* iVSPIndexTrue
     3939#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3940        , Int* iVSPDirTrue
     3941#endif
     3942        , Int mrgCandIdx )
    35303943#else
    35313944Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx )
     
    35603973  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
    35613974
    3562 #if MERL_VSP_C0152
     3975#if MERL_VSP_C0152 && !LGE_VSP_INHERIT_D0092
    35633976  Bool bVspMvZeroDone[3] = {false, false, false};
    35643977#endif
     
    35843997#endif //H3D_NBDV
    35853998
    3586 #if H3D_IVRP
     3999#if H3D_IVRP & !QC_ARP_D0177
    35874000  Bool bDVAvail = true;
    35884001#endif
     
    35904003#if H3D_NBDV
    35914004  DisInfo cDisInfo;
     4005#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4006  cDisInfo.bDV = false; // default setting
     4007  cDisInfo.iN  = 0;
     4008#endif
     4009
     4010#if !QC_CU_NBDV_D0181
    35924011  cDisInfo.iN = 0;
     4012#endif
    35934013  if(!bNoPdmMerge)
    35944014  {
     
    35964016    if( !getPic()->getDepthCoded() )
    35974017#endif
     4018#if QC_CU_NBDV_D0181
     4019    {
     4020      cDisInfo.iN = getDvInfo(uiAbsPartIdx).iN;
     4021      cDisInfo.bDV = getDvInfo(uiAbsPartIdx).bDV;
     4022      cDisInfo.m_acMvCand[0] = getDvInfo(uiAbsPartIdx).m_acMvCand[0];
     4023      cDisInfo.m_aVIdxCan[0] = getDvInfo(uiAbsPartIdx).m_aVIdxCan[0];
     4024#if MTK_VSP_USING_NBDV_D0105
     4025      cDisInfo.m_acMvCandNoRef[0] = getDvInfo(uiAbsPartIdx).m_acMvCandNoRef[0];
     4026#endif
     4027#if MERL_General_Fix
     4028#if MERL_VSP_C0152
     4029#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4030      cDisInfo.m_aListIdx[0] = getDvInfo(uiAbsPartIdx).m_aListIdx[0];
     4031      cDisInfo.m_aRefIdx[0]  = getDvInfo(uiAbsPartIdx).m_aRefIdx[0];
     4032#endif
     4033#endif
     4034#endif
     4035    }
     4036#else
    35984037    getDisMvpCandNBDV(uiPUIdx, uiAbsPartIdx, &cDisInfo , true
    35994038#if MERL_VSP_C0152
     
    36014040#endif     
    36024041);
    3603   }
     4042#endif
     4043  }
     4044 
    36044045#if FCO_DVP_REFINE_C0132_C0170
    36054046  if(getPic()->getDepthCoded() )
     
    36184059  }
    36194060#endif
     4061#if !QC_CU_NBDV_D0181
    36204062  if(cDisInfo.iN==0)
    3621   {
     4063#else
     4064  if(cDisInfo.bDV == false)
     4065#endif
     4066  {
     4067#if !QC_CU_NBDV_D0181
    36224068    cDisInfo.iN = 1;
    36234069    cDisInfo.m_acMvCand[0].setHor(0);
    36244070    cDisInfo.m_acMvCand[0].setVer(0);
    36254071    cDisInfo.m_aVIdxCan[0] = 0;
    3626 #if H3D_IVRP
     4072#endif
     4073#if H3D_IVRP & !QC_ARP_D0177
    36274074    bDVAvail = false;
    36284075#endif
    36294076  }
     4077
     4078#if MERL_VSP_NBDV_RefVId_Fix_D0166 && !MTK_LGE_VSP_DEPTH_OFF_D0105_D0139
     4079  if (bNoPdmMerge && cDisInfo.bDV == false)
     4080  { // purely for default setting
     4081    cDisInfo.iN = 1;
     4082    cDisInfo.m_acMvCand[0].setHor(0);
     4083    cDisInfo.m_acMvCand[0].setVer(0);
     4084    cDisInfo.m_acMvCandNoRef[0].setHor(0);
     4085    cDisInfo.m_acMvCandNoRef[0].setVer(0);
     4086    cDisInfo.m_aVIdxCan[0] = 0;
     4087
     4088    RefPicList eRefPicList = REF_PIC_LIST_0 ;
     4089    Int refFrmIdx = 0;
     4090    getRefListAndRefFrmIdx(0, eRefPicList, refFrmIdx);
     4091    cDisInfo.m_aListIdx[0] = eRefPicList;
     4092    cDisInfo.m_aRefIdx [0] = -1-refFrmIdx;
     4093   }
     4094#endif
    36304095
    36314096#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
     
    36524117        clipMv(cMvPred);
    36534118        pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
     4119#if MTK_LGE_VSP_DEPTH_OFF_D0105_D0139
     4120        if (pcMvFieldNeighbours[iCount<<1].getRefIdx()<0)
     4121        {
     4122          assert(pcTextureCU->getVSPIndex(uiPartIdxCenter)!=0); 
     4123          for (Int i=0; i<getSlice()->getNumRefIdx(REF_PIC_LIST_0); i++)
     4124          {
     4125            if (getSlice()->getRefPOC(REF_PIC_LIST_0, i) == getSlice()->getPOC())
     4126            {
     4127              pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,i);
     4128              break;
     4129            }
     4130          }
     4131        }
     4132#endif
    36544133      }
    36554134      if ( getSlice()->isInterB() )
     
    36644143          clipMv(cMvPred);
    36654144          pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx());
     4145#if MTK_LGE_VSP_DEPTH_OFF_D0105_D0139
     4146          if (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()<0)
     4147          {
     4148            assert(pcTextureCU->getVSPIndex(uiPartIdxCenter)!=0); 
     4149            for (Int i=0; i<getSlice()->getNumRefIdx(REF_PIC_LIST_1); i++)
     4150            {
     4151              if (getSlice()->getRefPOC(REF_PIC_LIST_1, i) == getSlice()->getPOC())
     4152              {
     4153                pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,i);
     4154                break;
     4155              }
     4156            }
     4157          }
     4158#endif
    36664159        }
    36674160      }
    3668 #if MERL_VSP_C0152
    3669       xInheritVspMode( pcTextureCU, uiPartIdxCenter, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
    3670 #endif
    3671       if ( mrgCandIdx == iCount )
    3672       {
    3673         return;
    3674       }
    3675       iCount ++;
     4161#if MERL_VSP_C0152  && !QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
     4162#if !MTK_LGE_VSP_DEPTH_OFF_D0105_D0139
     4163      xInheritVspMode( pcTextureCU, uiPartIdxCenter, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo
     4164#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4165         , iVSPDirTrue
     4166#endif
     4167        ) ;
     4168#endif
     4169#endif
     4170#if MTK_LGE_VSP_DEPTH_OFF_D0105_D0139
     4171      if (!((pcMvFieldNeighbours[iCount<<1].getRefIdx()<0 && !getSlice()->isInterB())
     4172        || (pcMvFieldNeighbours[iCount<<1].getRefIdx()<0 && pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()<0 && getSlice()->isInterB())))
     4173      {
     4174#endif
     4175        if ( mrgCandIdx == iCount )
     4176        {
     4177          return;
     4178        }
     4179        iCount ++;
     4180#if MTK_LGE_VSP_DEPTH_OFF_D0105_D0139
     4181      }
     4182      else
     4183      {
     4184        assert(0);
     4185      }
     4186#endif
    36764187    }
    36774188  }
     
    36874198  iPdmDir[1] = iPdmInterDir;
    36884199#endif // H3D_NBDV
    3689 #if H3D_IVRP
     4200#if H3D_IVRP & !QC_ARP_D0177
    36904201  if (m_pcSlice->getSPS()->getMultiviewResPredMode()==1 && iPdmDir[0] && !bNoPdmMerge && cCurPS == SIZE_2Nx2N && bDVAvail)
    36914202  {
     
    37274238  } 
    37284239 
    3729 #endif //  H3D_IVMP
    3730 
     4240#endif //  H3D_IVMP
     4241
     4242#if !FIX_MERGE_D
    37314243#if MERL_VSP_COMPENSATION_C0152
    37324244  //===== vsp 0 =====
    37334245  if( iCount < 4 + extraMergeCand )
    3734     if ( !xAddVspMergeCand(0, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) )
     4246    if ( !xAddVspMergeCand(0, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo
     4247#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4248            , iVSPDirTrue
     4249#endif
     4250            )
     4251       )
    37354252      return;
     4253#endif
    37364254#endif
    37374255
     
    37514269  {
    37524270    if ( pcCULeft && !pcCULeft->isIntra( uiLeftPartIdx )
    3753 #if MERL_VSP_C0152
     4271#if MERL_VSP_C0152 && !LGE_VSP_INHERIT_D0092
    37544272      CHECK_ADD_YET(pcCULeft, uiLeftPartIdx, 1)
    37554273#endif
     
    38004318#endif
    38014319#if MERL_VSP_C0152
    3802         xInheritVspMode( pcCULeft, uiLeftPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
     4320#if LGE_VSP_INHERIT_D0092
     4321        if (pcCULeft->getVSPIndex(uiLeftPartIdx)==1)
     4322        {
     4323            iVSPIndexTrue[iCount] = 1;
     4324        }
     4325#else
     4326        xInheritVspMode( pcCULeft, uiLeftPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo
     4327#if QC_BVSP_CleanUP_D0191
     4328        ,puhInterDirNeighbours
     4329#endif
     4330#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4331         , iVSPDirTrue
     4332#endif
     4333                );
     4334#endif
    38034335#endif
    38044336        if ( mrgCandIdx == iCount )
     
    38254357    }
    38264358  if ( pcCUAbove && !pcCUAbove->isIntra( uiAbovePartIdx )
    3827 #if MERL_VSP_C0152
     4359#if MERL_VSP_C0152 && !LGE_VSP_INHERIT_D0092
    38284360    CHECK_ADD_YET(pcCUAbove, uiAbovePartIdx, 1)
    38294361#endif
     
    38734405#endif
    38744406#if MERL_VSP_C0152
    3875      xInheritVspMode( pcCUAbove, uiAbovePartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
     4407#if LGE_VSP_INHERIT_D0092
     4408    if (pcCUAbove->getVSPIndex(uiAbovePartIdx)==1)
     4409    {
     4410        iVSPIndexTrue[iCount] = 1;
     4411    }
     4412#else
     4413     xInheritVspMode( pcCUAbove, uiAbovePartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo
     4414#if QC_BVSP_CleanUP_D0191
     4415        ,puhInterDirNeighbours
     4416#endif
     4417#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4418       , iVSPDirTrue
     4419#endif
     4420             ) ;
     4421#endif
    38764422#endif
    38774423    if ( mrgCandIdx == iCount )
     
    38974443  }
    38984444  if ( pcCUAboveRight && !pcCUAboveRight->isIntra( uiAboveRightPartIdx )
    3899 #if MERL_VSP_C0152
     4445#if MERL_VSP_C0152 && !LGE_VSP_INHERIT_D0092
    39004446    CHECK_ADD_YET(pcCUAboveRight, uiAboveRightPartIdx, 1)
    39014447#endif
     
    39224468#endif
    39234469#if MERL_VSP_C0152
    3924     xInheritVspMode( pcCUAboveRight, uiAboveRightPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
     4470#if LGE_VSP_INHERIT_D0092
     4471    if (pcCUAboveRight->getVSPIndex(uiAboveRightPartIdx)==1)
     4472    {
     4473        iVSPIndexTrue[iCount] = 1;
     4474    }
     4475#else
     4476    xInheritVspMode( pcCUAboveRight, uiAboveRightPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo
     4477#if QC_BVSP_CleanUP_D0191
     4478        ,puhInterDirNeighbours
     4479#endif
     4480#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4481       , iVSPDirTrue
     4482#endif
     4483            ) ;
     4484#endif
    39254485#endif
    39264486    if ( mrgCandIdx == iCount )
     
    39804540#endif // H3D_IVMP
    39814541
     4542#if MERL_VSP_COMPENSATION_C0152
     4543  //===== vsp 3 =====
     4544#if LGE_VSP_INHERIT_D0092
     4545    if ( !xAddVspMergeCand(3, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo
     4546#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4547      , iVSPDirTrue
     4548#endif
     4549      ) )
     4550#else
     4551    if( iCount < 4 + extraMergeCand )
     4552        if ( !xAddVspMergeCand(3, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo
     4553#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4554          , iVSPDirTrue
     4555#endif   
     4556          ) )
     4557#endif
     4558            return;
     4559#endif
     4560
     4561#if MERL_VSP_C0152
     4562#if VSP_MERGE_POS < 4
     4563#if H3D_IVMP
     4564    if( iCount < 4 + extraMergeCand )
     4565#else
     4566    if( iCount < 4 )
     4567#endif
     4568    {
     4569#endif
     4570#endif
    39824571
    39834572  //left bottom
     
    39934582  }
    39944583  if ( pcCULeftBottom && !pcCULeftBottom->isIntra( uiLeftBottomPartIdx )
    3995 #if MERL_VSP_C0152
     4584#if MERL_VSP_C0152 && !LGE_VSP_INHERIT_D0092
    39964585    CHECK_ADD_YET(pcCULeftBottom, uiLeftBottomPartIdx, 1)
    39974586#endif
     
    40184607#endif
    40194608#if MERL_VSP_C0152
    4020      xInheritVspMode( pcCULeftBottom, uiLeftBottomPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
     4609#if LGE_VSP_INHERIT_D0092
     4610    if (pcCULeftBottom->getVSPIndex(uiLeftBottomPartIdx)==1)
     4611    {
     4612        iVSPIndexTrue[iCount] = 1;
     4613    }
     4614#else
     4615    xInheritVspMode( pcCULeftBottom, uiLeftBottomPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo
     4616#if QC_BVSP_CleanUP_D0191
     4617        ,puhInterDirNeighbours
     4618#endif
     4619#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4620       , iVSPDirTrue
     4621#endif
     4622             ) ;
     4623#endif
    40214624#endif
    40224625    if ( mrgCandIdx == iCount )
     
    40264629    iCount ++;
    40274630  }
    4028  
    4029  
     4631
     4632#if MERL_VSP_C0152  // Is this correct here?
     4633#if VSP_MERGE_POS < 4
     4634    }
     4635#endif
     4636#endif
     4637
    40304638  // above left
    40314639#if H3D_IVMP
     
    40464654    }
    40474655    if( pcCUAboveLeft && !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx )
    4048 #if MERL_VSP_C0152
     4656#if MERL_VSP_C0152 && !LGE_VSP_INHERIT_D0092
    40494657     CHECK_ADD_YET(pcCUAboveLeft, uiAboveLeftPartIdx, 1)
    40504658#endif
     
    40734681#endif
    40744682#if MERL_VSP_C0152
    4075      xInheritVspMode( pcCUAboveLeft, uiAboveLeftPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
     4683#if LGE_VSP_INHERIT_D0092
     4684    if (pcCUAboveLeft->getVSPIndex(uiAboveLeftPartIdx)==1)
     4685    {
     4686        iVSPIndexTrue[iCount] = 1;
     4687    }
     4688#else
     4689      xInheritVspMode( pcCUAboveLeft, uiAboveLeftPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo
     4690#if QC_BVSP_CleanUP_D0191
     4691        ,puhInterDirNeighbours
     4692#endif
     4693#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4694       , iVSPDirTrue
     4695#endif
     4696             ) ;
     4697#endif
    40764698#endif
    40774699      if ( mrgCandIdx == iCount )
     
    40864708  //===== vsp 5 =====
    40874709  if( iCount < 4 + extraMergeCand )
    4088     if ( !xAddVspMergeCand(5, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) )
     4710#if LGE_VSP_INHERIT_D0092
     4711    if ( !xAddVspMergeCand(5, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo
     4712#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4713         , iVSPDirTrue
     4714#endif
     4715))
     4716#else
     4717    if ( !xAddVspMergeCand(5, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo
     4718#if MERL_VSP_NBDV_RefVId_Fix_D0166
     4719         , iVSPDirTrue
     4720#endif
     4721            ))
     4722#endif
    40894723      return;
    40904724#endif
     
    42764910#if MERL_VSP_C0152
    42774911      Bool bValid = true;
     4912#if LGE_VSP_INHERIT_D0092
     4913      if (iVSPIndexTrue[i]==1 || iVSPIndexTrue[j]==1) // NOT_VALID
     4914#else
    42784915      if (pcMvFieldNeighbours[i<<1].getRefIdx() < 0 || pcMvFieldNeighbours[(j<<1)+1].getRefIdx() < 0) // NOT_VALID
     4916#endif
    42794917        bValid = false;
    42804918#endif
     4919
     4920#if MTK_D0156
     4921      if( !m_pcSlice->getSPS()->getUseVSPCompensation())
     4922      {
     4923          bValid = true;
     4924      }
     4925#endif
     4926
    42814927      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2)
    42824928#if MERL_VSP_C0152
     
    44475093  {
    44485094    if( pcCorner && !pcCorner->isIntra( uiCornerPUIdx )
    4449 #if MERL_VSP_C0152
     5095#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    44505096     && !pcCorner->getVSPIndex( uiCornerPUIdx )
    44515097#endif
     
    45935239    pcTmpCU = getPULeft(uiIdx, uiPartIdxLB, true, false);
    45945240  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
    4595 #if MERL_VSP_C0152
     5241#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    45965242  if(! pcTmpCU->getVSPIndex(uiIdx))
    45975243#endif
     
    46185264
    46195265  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
    4620 #if MERL_VSP_C0152
     5266#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    46215267  if(! pcTmpCU->getVSPIndex(uiIdx))
    46225268#endif
     
    46435289      pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true, false, true);
    46445290  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
    4645 #if MERL_VSP_C0152
     5291#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    46465292  if(! pcTmpCU->getVSPIndex(uiIdx))
    46475293#endif
     
    46675313      pcTmpCU = getPUBelowLeft(uiIdx, uiPartIdxLB, true, false);
    46685314  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
    4669 #if MERL_VSP_C0152
     5315#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    46705316  if(! pcTmpCU->getVSPIndex(uiIdx))
    46715317#endif
     
    46945340    assert(uiPartIdxLT == (m_uiAbsIdxInLCU + uiPartAddr));
    46955341  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
    4696 #if MERL_VSP_C0152
     5342#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    46975343  if(! pcTmpCU->getVSPIndex(uiIdx))
    46985344#endif
     
    49025548  Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth();
    49035549  Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
    4904 
     5550#if !QC_BVSP_CleanUP_D0191
     5551#if LGE_ROUND_OFFSET_D0135
     5552  Int depthPosX = Clip3(0,   iPictureWidth - iBlkWidth,  iBlkX + ((mv->getHor()+2)>>2));
     5553  Int depthPosY = Clip3(0,   iPictureHeight- iBlkHeight,  iBlkY + ((mv->getVer()+2)>>2));
     5554#else
    49055555  Int depthPosX = Clip3(0,   iPictureWidth - iBlkWidth,  iBlkX + (mv->getHor()>>2));
    49065556  Int depthPosY = Clip3(0,   iPictureHeight- iBlkHeight,  iBlkY + (mv->getVer()>>2));
     5557#endif
    49075558
    49085559  Pel *pDepthPel   = pcBaseViewDepthPicYuv->getLumaAddr() + depthPosX + depthPosY * depStride;
     5560#endif
    49095561  Pel  maxDepthVal = 0;
    49105562
    49115563  if ( bSimpleDvpRefine )
    49125564  {
     5565#if LGE_ROUND_OFFSET_D0135
     5566    Int depthStartPosX = Clip3(0,   iPictureWidth - iBlkWidth,  iBlkX + ((mv->getHor()+2)>>2));
     5567    Int depthStartPosY = Clip3(0,   iPictureHeight- iBlkHeight,  iBlkY + ((mv->getVer()+2)>>2));
     5568    Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
     5569    Int depthEndPosY   = Clip3(0,   iPictureHeight - 1,  iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
     5570#else
    49135571    Int depthStartPosX = Clip3(0,   iPictureWidth - iBlkWidth,  iBlkX + (mv->getHor()>>2));
    49145572    Int depthStartPosY = Clip3(0,   iPictureHeight- iBlkHeight,  iBlkY + (mv->getVer()>>2));
    49155573    Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + (mv->getHor()>>2));
    49165574    Int depthEndPosY   = Clip3(0,   iPictureHeight - 1,  iBlkY + iBlkHeight - 1 + (mv->getVer()>>2));
     5575#endif
     5576#if !MTK_DEPTH_TO_DISP_D0138
    49175577    Int iCenterX = (depthStartPosX + depthEndPosX) >> 1;
    49185578    Int iCenterY = (depthStartPosY + depthEndPosY) >> 1;
     5579#endif
    49195580
    49205581    Pel *depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
     
    49245585    aiDepth[2] = depthTL[ (depthStartPosY) * depStride + depthEndPosX   ];      // Right Top
    49255586    aiDepth[3] = depthTL[ (depthEndPosY)   * depStride + depthEndPosX   ];      // Right Bottom
     5587#if MTK_DEPTH_TO_DISP_D0138
     5588    for (Int i = 0; i < 4; i++)
     5589#else
    49265590    aiDepth[4] = depthTL[ (iCenterY)       * depStride + iCenterX       ];      // Center
    49275591    for (Int i = 0; i < 5; i++)
     5592#endif
    49285593    {
    49295594      if (maxDepthVal < aiDepth[i])
     
    49315596    }
    49325597  }
     5598#if !QC_BVSP_CleanUP_D0191
    49335599  else
    49345600  {
     
    49435609    }
    49445610  }
     5611#endif
    49455612
    49465613  Int iDisp = aiShiftLUT[ maxDepthVal ] << iShiftPrec;
     
    49485615  return iDisp;
    49495616}
    4950 Void TComDataCU::estimateDVFromDM(UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred, Bool bSimpleDvpRefine)
     5617
     5618Void TComDataCU::estimateDVFromDM(
     5619#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5620          Int refViewIdx,
     5621#endif
     5622          UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred, Bool bSimpleDvpRefine)
    49515623{
    49525624  if (picDepth)
     
    49625634    Int  iShiftPrec;
    49635635
    4964     getSlice()->getBWVSPLUTParam(aiShiftLUT, iShiftPrec);
     5636    getSlice()->getBWVSPLUTParam(aiShiftLUT, iShiftPrec
     5637#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5638            , refViewIdx
     5639#endif
     5640            );
    49655641
    49665642    Pel iDisp = getMcpFromDM( pcBaseViewDepthPicYuv, cMvPred, iBlkX, iBlkY, iWidth, iHeight, aiShiftLUT, iShiftPrec, bSimpleDvpRefine );
     
    49915667          clipMv(cMvPred);
    49925668
    4993           TComPic* picDepth = getSlice()->getRefPicBaseDepth();
    4994 
     5669          TComPic* picDepth = NULL;
     5670#if MERL_General_Fix
     5671#if MERL_VSP_C0152
     5672#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5673          Int refPOC = getSlice()->getRefPic(eRefPicList, refId)->getPOC();
     5674          picDepth = getSlice()->getDepthRefPic(refViewIdx, refPOC);
     5675          assert(refPOC == getSlice()->getPOC());
     5676          assert(picDepth != NULL);
     5677#else
     5678          picDepth = getSlice()->getRefPicBaseDepth();
     5679#endif
     5680#endif
     5681#else
     5682          picDepth = getSlice()->getRefPicBaseDepth();
     5683#endif
     5684
     5685#if QC_CU_NBDV_D0181 && MERL_VSP_C0152
     5686          pNbDvInfo->m_acMvCandNoRef[pNbDvInfo->iN] = cMvPred;
     5687#endif
    49955688          if (picDepth && bDepthRefine)
    4996             estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cMvPred, true);
    4997 
     5689            estimateDVFromDM(
     5690#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5691                    refViewIdx,
     5692#endif
     5693                    uiPartIdx, picDepth, uiPartAddr, &cMvPred, true);
     5694
     5695
     5696#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5697          pNbDvInfo->m_aListIdx[ pNbDvInfo->iN ] = eRefPicList;
     5698          pNbDvInfo->m_aRefIdx [ pNbDvInfo->iN ] = -1-refId;
     5699          assert(pNbDvInfo->m_aRefIdx [ pNbDvInfo->iN ] < 0);
     5700#endif
    49985701          pNbDvInfo->m_acMvCand[ pNbDvInfo->iN   ] = cMvPred;
    49995702          pNbDvInfo->m_aVIdxCan[ pNbDvInfo->iN++ ] = refViewIdx;
     
    50105713        }
    50115714      }
    5012 #if MERL_VSP_C0152
     5715#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    50135716      else if (pcTmpCU->getVSPIndex(uiIdx) != 0) // is VSP
    50145717      {
    5015         TComPic* picDepth = pcTmpCU->getSlice()->getRefPicBaseDepth();
     5718        TComPic* picDepth = NULL;
     5719
     5720#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5721        RefPicList privateRefPicList = (RefPicList) pcTmpCU->getVSPDir( uiIdx );
     5722        assert(privateRefPicList == REF_PIC_LIST_0 || privateRefPicList == REF_PIC_LIST_1);
     5723        Int  refIdx = -1-pcTmpCU->getCUMvField( privateRefPicList )->getRefIdx( uiIdx ); // a trick when storing refIdx for temporal BVSP
     5724        assert(refIdx >= 0);
     5725        Int  refViewIdx = getSlice()->getRefViewId(privateRefPicList, refIdx);
     5726        Int  refPOC = getSlice()->getRefPOC(privateRefPicList, refIdx);
     5727
     5728        picDepth = getSlice()->getDepthRefPic(refViewIdx, refPOC);
     5729        assert(refPOC == getSlice()->getPOC());
     5730        assert(picDepth != NULL);
     5731#else
     5732        picDepth = pcTmpCU->getSlice()->getRefPicBaseDepth();
     5733#endif
     5734
     5735#if QC_CU_NBDV_D0181 && MERL_VSP_C0152
     5736        pNbDvInfo->m_acMvCandNoRef[pNbDvInfo->iN] = cMvPred;
     5737#endif
    50165738        if (picDepth && bDepthRefine)
    5017           estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cMvPred);
     5739          estimateDVFromDM(
     5740#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5741                  refViewIdx,
     5742#endif
     5743                  uiPartIdx, picDepth, uiPartAddr, &cMvPred);
    50185744
    50195745        cMvPred.setVer(0);
    50205746
     5747#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5748        pNbDvInfo->m_aRefIdx [ pNbDvInfo->iN ] = -1-refIdx;
     5749        pNbDvInfo->m_aListIdx[ pNbDvInfo->iN ] = privateRefPicList;
     5750        pNbDvInfo->m_acMvCand[ pNbDvInfo->iN ] = cMvPred;
     5751        pNbDvInfo->m_aVIdxCan[ pNbDvInfo->iN ] = refViewIdx;
     5752        assert(pNbDvInfo->m_aRefIdx [ pNbDvInfo->iN ] < 0);
     5753        pNbDvInfo->iN++;
     5754#else
    50215755        pNbDvInfo->m_acMvCand[ pNbDvInfo->iN]   = cMvPred;
    50225756        pNbDvInfo->m_aVIdxCan[ pNbDvInfo->iN++] = 0; // refViewIdx;
     5757#endif
    50235758        return true;
    50245759      }
     
    50755810}
    50765811
    5077 
     5812#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5813Bool TComDataCU::getRefListAndRefFrmIdx(Int targetRefViewIdx, RefPicList& eRefPicList, Int& refFrmIdx)
     5814{
     5815  Bool isFound = false;
     5816  RefPicList privateRefPicList = REF_PIC_LIST_0;
     5817
     5818  refFrmIdx = 0;
     5819  for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1) && isFound == false; iList++)
     5820  {
     5821    privateRefPicList = RefPicList(iList);
     5822    for (Int refIdx = 0; refIdx < getSlice()->getNumRefIdx(privateRefPicList); refIdx++)
     5823    {
     5824      Int refViewIdx  = getSlice()->getRefViewId( privateRefPicList, refIdx);
     5825      if ( refViewIdx == targetRefViewIdx)
     5826      {
     5827        refFrmIdx = refIdx;
     5828        eRefPicList = privateRefPicList;
     5829        isFound = true;
     5830        break;
     5831      }
     5832    }
     5833  }
     5834
     5835  return isFound;
     5836}
     5837#endif
     5838
     5839#if QC_CU_NBDV_D0181
     5840Bool TComDataCU::getDisMvpCandNBDV( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo , Bool bParMerge
     5841#else
    50785842Void TComDataCU::getDisMvpCandNBDV( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo , Bool bParMerge
     5843#endif
    50795844#if MERL_VSP_C0152
    50805845                                , Bool bDepthRefine
     
    50995864  }
    51005865
     5866#if MTK_D0156
     5867  if( !m_pcSlice->getSPS()->getUseDVPRefine() )
     5868  {
     5869      bDepthRefine = false;
     5870  }
     5871#endif
     5872
    51015873  // Get Positions 
    51025874  PartSize eCUMode    = getPartitionSize( uiPartAddr );   
     5875#if QC_CU_NBDV_D0181
     5876  assert(eCUMode == SIZE_2Nx2N);
     5877#endif
    51035878  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB; 
    51045879
     
    51685943          {
    51695944            clipMv(cColMv);
    5170             TComPic* picDepth = getSlice()->getRefPicBaseDepth();
     5945            TComPic* picDepth = NULL;
     5946#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5947            Int currPoc = getSlice()->getPOC();
     5948            picDepth = getSlice()->getDepthRefPic(iTargetViewIdx, currPoc);
     5949            assert(picDepth != NULL);
     5950#else
     5951            picDepth = getSlice()->getRefPicBaseDepth();
     5952#endif
     5953#if QC_CU_NBDV_D0181 && MERL_VSP_C0152
     5954            pDInfo->m_acMvCandNoRef[pDInfo->iN] = cColMv;
     5955#endif
    51715956            if (picDepth && bDepthRefine)
     5957#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5958              estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv, true);
     5959#else
    51725960              estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cColMv, true);
    5173 
    5174             pDInfo->m_acMvCand[ pDInfo->iN] = cColMv;
     5961#endif
     5962
     5963#if MERL_VSP_NBDV_RefVId_Fix_D0166
     5964            Int refFrmIdx = 0;
     5965            RefPicList privateRefPicList = REF_PIC_LIST_0;
     5966            getRefListAndRefFrmIdx(iTargetViewIdx, privateRefPicList, refFrmIdx);
     5967           
     5968            pDInfo->m_aListIdx[ pDInfo->iN ]  = privateRefPicList;
     5969            pDInfo->m_aRefIdx [ pDInfo->iN ]  = -1-refFrmIdx;
     5970            assert(pDInfo->m_aRefIdx [ pDInfo->iN ] < 0);
     5971#endif
     5972            pDInfo->m_acMvCand[ pDInfo->iN ]  = cColMv;
    51755973            pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetViewIdx;
     5974#if QC_CU_NBDV_D0181
     5975            return true;
     5976#else
    51765977            return ;
     5978#endif
    51775979          }
    51785980        } // Loop positions
     
    52036005  bCheckMcpDv = true;
    52046006  if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, uiPartIdx, uiPartAddr, pDInfo, bCheckMcpDv, &cMvpDvInfo, DVFROM_LEFT, bDepthRefine ) )
     6007#if !QC_CU_NBDV_D0181
    52056008    return;
    5206 
     6009#else
     6010    return true;
     6011#endif
    52076012
    52086013  //// ******* Get disparity from above block ******* /////
     
    52256030    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
    52266031    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, uiPartIdx, uiPartAddr, pDInfo, bCheckMcpDv, &cMvpDvInfo, DVFROM_ABOVE, bDepthRefine ) )
     6032#if !QC_CU_NBDV_D0181
    52276033      return;
     6034#else
     6035      return true;
     6036#endif
    52286037  }
    52296038
     
    52436052    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
    52446053    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, uiPartIdx, uiPartAddr, pDInfo, bCheckMcpDv, &cMvpDvInfo, DVFROM_ABOVERIGHT, bDepthRefine ) )
     6054#if !QC_CU_NBDV_D0181
    52456055      return;
     6056#else
     6057      return true;
     6058#endif
    52466059  }
    52476060
     
    52626075    bCheckMcpDv = true;
    52636076    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, uiPartIdx, uiPartAddr, pDInfo, bCheckMcpDv, &cMvpDvInfo, DVFROM_LEFTBELOW, bDepthRefine ) )
     6077#if !QC_CU_NBDV_D0181
    52646078      return;
     6079#else
     6080      return true;
     6081#endif
    52656082  }
    52666083
     
    52826099    bCheckMcpDv = (( getAddr() - pcTmpCU->getAddr() ) <= 1);
    52836100    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, uiPartIdx, uiPartAddr, pDInfo, bCheckMcpDv, &cMvpDvInfo, DVFROM_ABOVELEFT, bDepthRefine ) )
     6101#if !QC_CU_NBDV_D0181
    52846102      return;
     6103#else
     6104      return true;
     6105#endif
    52856106  }
    52866107
     
    52976118          clipMv( cDispVec );
    52986119
    5299           TComPic* picDepth = getSlice()->getRefPicBaseDepth();
     6120          TComPic* picDepth = NULL;
     6121#if MERL_VSP_NBDV_RefVId_Fix_D0166
     6122          Int refPOC = getSlice()->getPOC();
     6123          picDepth = getSlice()->getDepthRefPic(0, refPOC);
     6124          assert(picDepth!=NULL);
     6125#else
     6126          picDepth = getSlice()->getRefPicBaseDepth();
     6127#endif
     6128
     6129#if QC_CU_NBDV_D0181 && MERL_VSP_C0152
     6130          pDInfo->m_acMvCandNoRef[pDInfo->iN] = cDispVec;
     6131#endif
    53006132          if (picDepth && bDepthRefine)
     6133#if MERL_VSP_NBDV_RefVId_Fix_D0166
     6134            estimateDVFromDM(0, uiPartIdx, picDepth, uiPartAddr, &cDispVec, true); // from base view
     6135#else
    53016136            estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cDispVec, true);
    5302 
    5303           pDInfo->m_acMvCand[ pDInfo->iN]   = cDispVec;
     6137#endif
     6138
     6139#if MERL_VSP_NBDV_RefVId_Fix_D0166 //if DVMCP is used, do a local reference frame list and idx search
     6140          Int refFrmIdx = 0;
     6141          RefPicList privateRefPicList = REF_PIC_LIST_0 ;
     6142          getRefListAndRefFrmIdx(0, privateRefPicList, refFrmIdx); // find the reference picture from base view
     6143
     6144          pDInfo->m_aListIdx[ pDInfo->iN ]  = privateRefPicList;
     6145          pDInfo->m_aRefIdx [ pDInfo->iN ]  = -1-refFrmIdx;
     6146          assert(pDInfo->m_aRefIdx [ pDInfo->iN ] < 0);
     6147#endif
     6148
     6149          pDInfo->m_acMvCand[ pDInfo->iN ]  = cDispVec;
    53046150          pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0;
     6151#if !QC_CU_NBDV_D0181
    53056152          return;
     6153#else
     6154          return true;
     6155#endif
    53066156        }
    53076157      }
    53086158    }
    53096159  }
     6160
     6161#if SEC_DEFAULT_DV_D0112
     6162  {
     6163    TComPic* picDepth = NULL;
     6164    TComMv defaultDV(0, 0);
     6165
     6166#if MERL_VSP_NBDV_RefVId_Fix_D0166
     6167    Int refPOC = getSlice()->getPOC();
     6168    picDepth = getSlice()->getDepthRefPic(0, refPOC);
     6169    assert(picDepth!=NULL);
     6170#else
     6171    picDepth = getSlice()->getRefPicBaseDepth();
     6172#endif
     6173
     6174#if MERL_General_Fix
     6175#if QC_CU_NBDV_D0181 && MERL_VSP_C0152
     6176    pDInfo->m_acMvCandNoRef[pDInfo->iN] = defaultDV;
     6177#endif
     6178#endif
     6179
     6180    if (picDepth && bDepthRefine)
     6181    {
     6182#if MERL_VSP_NBDV_RefVId_Fix_D0166
     6183      estimateDVFromDM(0, uiPartIdx, picDepth, uiPartAddr, &defaultDV, true); // from base view
     6184#else
     6185      estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &defaultDV, true);
     6186#endif
     6187    }
     6188
     6189#if MERL_VSP_NBDV_RefVId_Fix_D0166
     6190    Int refFrmIdx = 0;
     6191    RefPicList privateRefPicList = REF_PIC_LIST_0 ;
     6192    getRefListAndRefFrmIdx(0, privateRefPicList, refFrmIdx); // find the reference picture from base view
     6193
     6194    pDInfo->m_aListIdx[ pDInfo->iN ]  = privateRefPicList;
     6195    pDInfo->m_aRefIdx [ pDInfo->iN ]  = -1-refFrmIdx;
     6196    assert(pDInfo->m_aRefIdx [ pDInfo->iN ] < 0);
     6197#endif
     6198    pDInfo->m_acMvCand[pDInfo->iN] = defaultDV;
     6199    pDInfo->m_aVIdxCan[pDInfo->iN] = 0;
     6200#if MERL_VSP_NBDV_RefVId_Fix_D0166  // Bug fix for Samsung code.
     6201    pDInfo->iN++;
     6202#endif
     6203  }
     6204#endif
     6205
     6206#if QC_CU_NBDV_D0181
     6207  return false;
     6208#else
    53106209  return;
     6210#endif
    53116211}
    53126212#endif
     
    53226222 */
    53236223#if H3D_IVMP
     6224#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
    53246225Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo, Int iMVPIdx)
    53256226{
     6227    fillMvpCandBase(uiPartIdx, uiPartAddr, eRefPicList, iRefIdx, pInfo);
     6228}
     6229#else
     6230Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo, Int iMVPIdx)
     6231{
     6232
    53266233  if (!m_pcSlice->getSPS()->getViewId() || !m_pcSlice->getSPS()->getMultiviewMvPredMode())
    53276234  {
     
    53506257      // Extension part
    53516258      DisInfo cDisInfo;
     6259#if QC_CU_NBDV_D0181
     6260      cDisInfo.iN = this->getDvInfo(0).iN;
     6261      cDisInfo.m_acMvCand[0]=this->getDvInfo(0).m_acMvCand[0];
     6262      cDisInfo.m_aVIdxCan[0] = this->getDvInfo(0).m_aVIdxCan[0];
     6263      cDisInfo.bDV = this->getDvInfo(0).bDV;
     6264#else
    53526265      cDisInfo.iN = 0;
    53536266#if FCO_DVP_REFINE_C0132_C0170
     
    53826295        cDisInfo.m_aVIdxCan[0] = 0;
    53836296      }
     6297#endif
    53846298      Int paiPdmRefIdx[4] = {-1, -1, -1, -1};
    53856299      Int iPdmDir[4]      = {-1, -1, -1, -1};
     
    54026316  }
    54036317}
     6318#endif
    54046319
    54056320
     
    57006615  }
    57016616 
    5702 #if MERL_VSP_C0152
     6617#if MERL_VSP_C0152&!QC_BVSP_CleanUP_D0191
    57036618  if(pcTmpCU != NULL && pcTmpCU->getVSPIndex(uiIdx))
    57046619  {
     
    58166731  }
    58176732
    5818 #if MERL_VSP_C0152
     6733#if MERL_VSP_C0152 &!QC_BVSP_CleanUP_D0191
    58196734  if(pcTmpCU->getVSPIndex(uiIdx))
    58206735  {
     
    59796894  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
    59806895  iColViewIdx = pColCU->getSlice()->getViewId();
    5981 #if MERL_VSP_C0152
     6896#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    59826897  if( pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr) < 0)
    59836898  {
     
    70807995  memcpy( m_piVSPIndex + uiAbsPartIdxDst,  pcCU->getVSPIndex() + uiAbsPartIdxSrc, sizeof( m_piVSPIndex[0] ) * uiNumPartition );
    70817996#endif
     7997#if MERL_VSP_NBDV_RefVId_Fix_D0166
     7998  memcpy( m_piVSPDir   + uiAbsPartIdxDst,  pcCU->getVSPDir  () + uiAbsPartIdxSrc, sizeof( m_piVSPDir  [0] ) * uiNumPartition );
     7999#endif
    70828000
    70838001#if !MTK_UNCONSTRAINED_MVI_B0083
     
    71588076TComDataCU::getResidualSamples( UInt uiPartIdx, Bool bRecon, TComYuv* pcYuv )
    71598077{
     8078#if !QC_ARP_D0177
    71608079  TComResidualGenerator*  pcResidualGenerator = m_pcSlice->getSPS()->getResidualGenerator();
    71618080  ROFRS( pcResidualGenerator, false );
     8081#endif
     8082
    71628083#if H3D_NBDV
    71638084  DisInfo cDisInfo;
     8085#if !QC_CU_NBDV_D0181
    71648086  cDisInfo.iN = 0;
     8087#else
     8088  cDisInfo.bDV = false;
     8089#endif
    71658090  PartSize m_peSaved =  getPartitionSize( 0 );
    71668091  m_pePartSize[0] =  SIZE_2Nx2N;
     
    71828107  else
    71838108#endif
    7184 
     8109#if !QC_CU_NBDV_D0181
    71858110  getDisMvpCandNBDV( 0, 0,  &cDisInfo, false ); 
    7186 
    71878111  if( cDisInfo.iN == 0)
     8112#else
     8113  cDisInfo.bDV = getDvInfo(0).bDV;
     8114#if MERL_VSP_C0152
     8115  cDisInfo.m_acMvCand[0] = getDvInfo(0).m_acMvCandNoRef[0];
     8116#else
     8117  cDisInfo.m_acMvCand[0] = getDvInfo(0).m_acMvCand[0];
     8118#endif
     8119  cDisInfo.m_aVIdxCan[0] = 0;
     8120  cDisInfo.iN = getDvInfo(0).iN;
     8121  if( cDisInfo.bDV == false)
     8122#endif
    71888123  {
    71898124    m_pePartSize[0] = m_peSaved;
     
    71918126  }
    71928127  else
     8128#if QC_ARP_D0177
     8129  if(m_pcSlice->getSPS()->getUseAdvRP()) 
     8130  {
     8131     m_pePartSize[0] = m_peSaved;
     8132     return true;
     8133  }
     8134  else
     8135    return false;
     8136#else
    71938137  {
    71948138    Bool bAvailable = pcResidualGenerator->getResidualSamples( this, uiPartIdx, pcYuv, cDisInfo.m_acMvCand[0], bRecon );       
     
    71968140    return bAvailable;
    71978141  }
     8142#endif
    71988143#else
    71998144  return pcResidualGenerator->getResidualSamples( this, uiPartIdx, pcYuv, bRecon );
     
    72018146}
    72028147#endif
    7203 
     8148#if QC_ARP_D0177
     8149Void TComDataCU::setARPWSubParts ( UChar w, UInt uiAbsPartIdx, UInt uiDepth )
     8150{
     8151  assert( sizeof( *m_puhARPW) == 1 );
     8152  memset( m_puhARPW + uiAbsPartIdx, w, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
     8153}
     8154#endif
    72048155#if LGE_EDGE_INTRA_A0070
    72058156Void TComDataCU::reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion )
  • trunk/source/Lib/TLibCommon/TComDataCU.h

    r332 r443  
    195195                                      ///< value 0: non-VSP, value 1: VSP
    196196#endif
     197#if MERL_VSP_NBDV_RefVId_Fix_D0166
     198  Char*         m_piVSPDir;           ///< 0: LIST0; 1: LIST1
     199#endif
    197200#if AMP_MRG
    198201  Bool          m_bIsMergeAMP;
     
    214217  Bool*         m_pbResPredFlag;      ///< array of residual prediction flags
    215218#endif
    216 
     219#if QC_ARP_D0177
     220  UChar*        m_puhARPW;
     221#endif
    217222#if LGE_EDGE_INTRA_A0070
    218223  UChar*        m_pucEdgeCode;          ///< array of edge code
     
    268273  Pel*          m_apSegmentDCOffset[2];
    269274#endif
    270 
     275#if QC_CU_NBDV_D0181
     276  DisInfo*      m_pDvInfo;
     277#endif
    271278protected:
    272279 
     
    275282  Bool          xAddMVPCandOrder      ( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir );
    276283#if MERL_VSP_C0152
    277   inline Bool   xAddVspMergeCand      ( UChar ucVspMergePos, Int vspIdx, Bool* bVspMvZeroDone, UInt uiDepth, Bool* abCandIsInter, Int& iCount,
    278                                         UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, Int* iVSPIndexTrue, Int mrgCandIdx, DisInfo* pDisInfo );
    279   inline Void   xInheritVspMode       ( TComDataCU* pcCURef, UInt uiIdx, Bool* bVspMvZeroDone, Int iCount, Int* iVSPIndexTrue, TComMvField* pcMvFieldNeighbours, DisInfo* pDInfo ) ;
     284  inline Bool   xAddVspMergeCand      (
     285 UChar ucVspMergePos,
     286#if !LGE_VSP_INHERIT_D0092
     287 Int vspIdx,
     288 Bool* bVspMvZeroDone,
     289#endif
     290 UInt uiDepth,
     291 Bool* abCandIsInter,
     292 Int& iCount,
     293 UChar* puhInterDirNeighbours,
     294 TComMvField* pcMvFieldNeighbours,
     295 Int* iVSPIndexTrue,
     296 Int mrgCandIdx,
     297 DisInfo* pDisInfo
     298#if MERL_VSP_NBDV_RefVId_Fix_D0166
     299 , Int*   iVspDirTrue = NULL
     300#endif
     301                                        );
     302  inline Void   xInheritVspMode       ( TComDataCU* pcCURef, UInt uiIdx, Bool* bVspMvZeroDone, Int iCount, Int* iVSPIndexTrue, TComMvField* pcMvFieldNeighbours, DisInfo* pDInfo
     303#if QC_BVSP_CleanUP_D0191
     304   ,UChar *puhInterDirNeighbours
     305#endif
     306#if MERL_VSP_NBDV_RefVId_Fix_D0166
     307                                      , Int *iVSPDirTrue
     308#endif
     309    ) ;
    280310#endif
    281311  Void          deriveRightBottomIdx        ( PartSize eCUMode, UInt uiPartIdx, UInt& ruiPartIdxRB );
     
    299329 
    300330  /// compute scaling factor from POC difference
     331#if !QC_ARP_D0177
    301332  Int           xGetDistScaleFactor   ( Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC );
    302  
     333#endif
    303334  Void xDeriveCenterIdx( PartSize eCUMode, UInt uiPartIdx, UInt& ruiPartIdxCenter );
    304335  Bool xGetCenterCol( UInt uiPartIdx, RefPicList eRefPicList, int iRefIdx, TComMv *pcMv );
     
    314345  // create / destroy / initialize / copy
    315346  // -------------------------------------------------------------------------------------------------------------------
    316  
     347#if QC_ARP_D0177
     348  Int           xGetDistScaleFactor   ( Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC );
     349#endif 
     350
    317351  Void          create                ( UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
    318352#if ADAPTIVE_QP_SELECTION
     
    326360  Void          initSubCU             ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp );
    327361  Void          setOutsideCUPart      ( UInt uiAbsPartIdx, UInt uiDepth );
    328 
     362#if QC_CU_NBDV_D0181
     363  Void          copyDVInfoFrom (TComDataCU* pcCU, UInt uiAbsPartIdx);
     364#endif
    329365  Void          copySubCU             ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth );
    330   Void          copyInterPredInfoFrom ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList );
    331   Void          copyPartFrom          ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth );
     366  Void          copyInterPredInfoFrom ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList
     367#if QC_CU_NBDV_D0181
     368  , Bool bNBDV = false
     369#endif
     370  );
     371  Void          copyPartFrom          ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth
     372#if QC_ARP_D0177
     373      ,
     374      Bool bRP = false
     375#endif
     376  );
    332377 
    333378  Void          copyToPic             ( UChar uiDepth );
     
    458503  Void          setVSPIndex        ( UInt uiIdx, Int n )     { m_piVSPIndex[uiIdx] = n;    }
    459504  Void          setVSPIndexSubParts( Char bVSPIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
     505#endif
     506#if MERL_VSP_NBDV_RefVId_Fix_D0166
     507  Char*         getVSPDir          ()                        { return m_piVSPDir;                           }
     508  Char          getVSPDir          ( UInt uiIdx )            { return m_piVSPDir[uiIdx];                  }
     509  Void          setVSPDir          ( UInt uiIdx, Int n )     { m_piVSPDir[uiIdx] = n;  }
     510  Void          setVSPDirSubParts  ( Char bVSPDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
     511  Bool          getRefListAndRefFrmIdx(Int targetRefViewIdx, RefPicList& eRefPicList, Int& refFrmIdx);
    460512#endif
    461513
     
    474526#endif
    475527#endif
     528#if QC_CU_NBDV_D0181
     529  DisInfo*      getDvInfo             ()                        { return m_pDvInfo;                }
     530  DisInfo       getDvInfo             (UInt uiIdx)              { return m_pDvInfo[uiIdx];         }
     531  Void          setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth );
     532#endif
    476533
    477534#if AMP_MRG
     
    537594  Bool          getUnifiedMvPredCan       ( UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge );
    538595  Void          getDisMvpCand        ( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo );
     596#if QC_CU_NBDV_D0181
     597  Bool          getDisMvpCandNBDV( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo , Bool bParMerg = false
     598#else
    539599  Void          getDisMvpCandNBDV( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo , Bool bParMerg = false
     600#endif
    540601#if MERL_VSP_C0152
    541602                              , Bool bDepthRefine = false
     
    548609#if MERL_VSP_C0152
    549610  Pel           getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iWidth, Int iHeight, Int* aiShiftLUT, Int iShiftPrec, Bool bSimpleDvpRefine = false);
    550   Void          estimateDVFromDM(UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred, Bool bSimpleDvpRefine = false);
     611  Void          estimateDVFromDM(
     612#if MERL_VSP_NBDV_RefVId_Fix_D0166
     613                Int refViewIdx,
     614#endif
     615                UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred, Bool bSimpleDvpRefine = false);
    551616#endif
    552617  Bool          getIViewOrgDepthMvPred( UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv );
     
    568633  Bool          getResidualSamples( UInt uiPartIdx, Bool bRecon, TComYuv* pcYuv = 0 );
    569634#endif
     635#if QC_ARP_D0177
     636  UChar*        getARPW          ()                        { return m_puhARPW;               }
     637  UChar         getARPW          ( UInt uiIdx )            { return m_puhARPW[uiIdx];        }
     638  Void          setARPW          ( UInt uiIdx, UChar w )   { m_puhARPW[uiIdx] = w;           }
     639  Void          setARPWSubParts  ( UChar w, UInt uiAbsPartIdx, UInt uiDepth );
     640  Double        getARPWFactor    ( UInt uiIdx );
     641#endif
    570642  // -------------------------------------------------------------------------------------------------------------------
    571643  // member functions for accessing partition information
     
    647719  Bool          hasEqualMotion              ( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx );
    648720#if MERL_VSP_C0152
    649   Void          getInterMergeCandidates     ( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int* uiVSPIndexTrue, Int mrgCandIdx = -1 );
     721  Void          getInterMergeCandidates     ( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int* uiVSPIndexTrue,
     722#if MERL_VSP_NBDV_RefVId_Fix_D0166
     723                Int* iVSPDir,
     724#endif
     725                Int mrgCandIdx = -1 );
    650726#else
    651727  Void          getInterMergeCandidates     ( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx = -1 );
     
    688764  UInt          getCtxResPredFlag               ( UInt   uiAbsPartIdx                                 );
    689765#endif
    690  
     766#if QC_ARP_D0177
     767  UInt          getCTXARPWFlag                 ( UInt   uiAbsPartIdx                                 );
     768#endif 
    691769  UInt          getSliceStartCU         ( UInt pos )                  { return m_uiSliceStartCU[pos-m_uiAbsIdxInLCU];                                                                                          }
    692770  UInt          getEntropySliceStartCU  ( UInt pos )                  { return m_uiEntropySliceStartCU[pos-m_uiAbsIdxInLCU];                                                                                   }
     
    808886  Void          setSDCFlagSubParts  ( Bool bSDCFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
    809887 
     888#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    810889  UInt          getCtxSDCFlag              ( UInt uiAbsPartIdx );
     890#endif
    811891 
    812892  Bool          getSDCAvailable             ( UInt uiAbsPartIdx );
  • trunk/source/Lib/TLibCommon/TComDepthMapGenerator.h

    r332 r443  
    8080
    8181  UInt      getPdm  ()                            { if( m_aacActiveSPS[0][1] ) { return m_aacActiveSPS[0][1]->getPredDepthMapGeneration(); } return 0; }
    82 #if H3D_IVRP
     82#if H3D_IVRP & !QC_ARP_D0177
    8383  UInt      getResPrd ()                          { if( m_aacActiveSPS[0][1] ) { return m_aacActiveSPS[0][1]->getMultiviewResPredMode  (); } return 0; }
    8484#endif
  • trunk/source/Lib/TLibCommon/TComInterpolationFilter.cpp

    r56 r443  
    7272  { -2, 10, 58, -2 }
    7373};
    74 
     74#if QC_ARP_D0177
     75const Short TComInterpolationFilter::m_lumaFilterARP[4][NTAPS_LUMA_ARP] =
     76{
     77  {64,  0},
     78  {48, 16},
     79  {32, 32},
     80  {16, 48}
     81};
     82const Short TComInterpolationFilter::m_chromaFilterARP[8][NTAPS_CHROMA_ARP] =
     83{
     84  {64,  0},
     85  {56,  8},
     86  {48, 16},
     87  {40, 24},
     88  {32, 32},
     89  {24, 40},
     90  {16, 48},
     91  {8,  56}
     92};
     93#endif
    7594// ====================================================================================================================
    7695// Private member functions
     
    320339 * \param  isLast     Flag indicating whether it is the last filtering operation
    321340 */
    322 Void TComInterpolationFilter::filterHorLuma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isLast )
     341Void TComInterpolationFilter::filterHorLuma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isLast
     342#if QC_ARP_D0177
     343    ,
     344    Bool filterType
     345#endif
     346    )
    323347{
    324348  assert(frac >= 0 && frac < 4);
     
    330354  else
    331355  {
    332     filterHor<NTAPS_LUMA>(src, srcStride, dst, dstStride, width, height, isLast, m_lumaFilter[frac]);
     356#if QC_ARP_D0177
     357    if(filterType)
     358      filterHor<NTAPS_LUMA_ARP>(src, srcStride, dst, dstStride, width, height, isLast, m_lumaFilterARP[frac]);
     359    else
     360#endif
     361      filterHor<NTAPS_LUMA>(src, srcStride, dst, dstStride, width, height, isLast, m_lumaFilter[frac]);
    333362  }
    334363}
     
    347376 * \param  isLast     Flag indicating whether it is the last filtering operation
    348377 */
    349 Void TComInterpolationFilter::filterVerLuma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast )
     378Void TComInterpolationFilter::filterVerLuma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast
     379#if QC_ARP_D0177
     380    ,
     381    Bool filterType
     382#endif
     383    )
    350384{
    351385  assert(frac >= 0 && frac < 4);
     
    357391  else
    358392  {
    359     filterVer<NTAPS_LUMA>(src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_lumaFilter[frac]);   
     393#if QC_ARP_D0177
     394    if(filterType)
     395      filterVer<NTAPS_LUMA_ARP>(src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_lumaFilterARP[frac]);   
     396    else
     397#endif
     398      filterVer<NTAPS_LUMA>(src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_lumaFilter[frac]);   
    360399  }
    361400}
     
    373412 * \param  isLast     Flag indicating whether it is the last filtering operation
    374413 */
    375 Void TComInterpolationFilter::filterHorChroma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isLast )
     414Void TComInterpolationFilter::filterHorChroma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isLast
     415#if QC_ARP_D0177
     416    ,
     417    Bool filterType
     418#endif
     419    )
    376420{
    377421  assert(frac >= 0 && frac < 8);
     
    383427  else
    384428  {
     429#if QC_ARP_D0177
     430    if(filterType)
     431      filterHor<NTAPS_CHROMA_ARP>(src, srcStride, dst, dstStride, width, height, isLast, m_chromaFilterARP[frac]);   
     432    else
     433#endif
    385434    filterHor<NTAPS_CHROMA>(src, srcStride, dst, dstStride, width, height, isLast, m_chromaFilter[frac]);
    386435  }
     
    400449 * \param  isLast     Flag indicating whether it is the last filtering operation
    401450 */
    402 Void TComInterpolationFilter::filterVerChroma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast )
     451Void TComInterpolationFilter::filterVerChroma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast
     452#if QC_ARP_D0177
     453    ,
     454    Bool filterType
     455#endif
     456    )
    403457{
    404458  assert(frac >= 0 && frac < 8);
     
    410464  else
    411465  {
    412     filterVer<NTAPS_CHROMA>(src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_chromaFilter[frac]);   
     466#if QC_ARP_D0177
     467    if(filterType)
     468      filterVer<NTAPS_CHROMA_ARP>(src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_chromaFilterARP[frac]); 
     469    else
     470#endif
     471      filterVer<NTAPS_CHROMA>(src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_chromaFilter[frac]);   
    413472  }
    414473}
  • trunk/source/Lib/TLibCommon/TComInterpolationFilter.h

    r56 r443  
    4444//! \ingroup TLibCommon
    4545//! \{
     46#if QC_ARP_D0177
     47#define NTAPS_LUMA_ARP    2 ///< Number of taps for luma
     48#define NTAPS_CHROMA_ARP  2 ///< Number of taps for chroma
     49#endif
    4650
    4751#define NTAPS_LUMA        8 ///< Number of taps for luma
     
    5862  static const Short m_lumaFilter[4][NTAPS_LUMA];     ///< Luma filter taps
    5963  static const Short m_chromaFilter[8][NTAPS_CHROMA]; ///< Chroma filter taps
    60  
     64#if QC_ARP_D0177
     65  static const Short m_lumaFilterARP  [4][NTAPS_LUMA_ARP];     ///< Luma filter taps
     66  static const Short m_chromaFilterARP[8][NTAPS_CHROMA_ARP]; ///< Chroma filter taps
     67#endif
     68
    6169  static Void filterCopy(const Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Bool isFirst, Bool isLast);
    6270 
     
    7381  ~TComInterpolationFilter() {}
    7482
    75   Void filterHorLuma  (Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac,               Bool isLast );
    76   Void filterVerLuma  (Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast );
    77   Void filterHorChroma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac,               Bool isLast );
    78   Void filterVerChroma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast );
     83  Void filterHorLuma  (Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac,               Bool isLast
     84#if QC_ARP_D0177
     85    ,
     86    Bool filterType = 0
     87#endif
     88    );
     89  Void filterVerLuma  (Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast
     90#if QC_ARP_D0177
     91    ,
     92    Bool filterType = 0
     93#endif
     94    );
     95  Void filterHorChroma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac,               Bool isLast
     96#if QC_ARP_D0177
     97    ,
     98    Bool filterType = 0
     99#endif
     100    );
     101  Void filterVerChroma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast
     102#if QC_ARP_D0177
     103    ,
     104    Bool filterType = 0
     105#endif
     106    );
    79107};
    80108
  • trunk/source/Lib/TLibCommon/TComLoopFilter.cpp

    r296 r443  
    428428  //-- Set BS for Intra MB : BS = 4 or 3
    429429  if ( pcCUP->isIntra(uiPartP) || pcCUQ->isIntra(uiPartQ)
    430 #if MERL_VSP_C0152
     430#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    431431    || pcCUP->getVSPIndex(uiPartP) || pcCUQ->getVSPIndex(uiPartQ)
    432432#endif
     
    438438  //-- Set BS for not Intra MB : BS = 2 or 1 or 0
    439439  if ( !pcCUP->isIntra(uiPartP) && !pcCUQ->isIntra(uiPartQ)
    440 #if MERL_VSP_C0152
     440#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    441441    && !pcCUP->getVSPIndex(uiPartP) && !pcCUQ->getVSPIndex(uiPartQ)
    442442#endif
     
    534534  }   // enf of "if( not Intra )"
    535535 
    536 #if MERL_VSP_C0152
     536#if MERL_VSP_C0152 & !QC_BVSP_CleanUP_D0191
    537537  if ( pcCUP->getVSPIndex(uiPartP) || pcCUQ->getVSPIndex(uiPartQ))
    538538  {
  • trunk/source/Lib/TLibCommon/TComMotionInfo.h

    r332 r443  
    6464  TComMv m_acMvCand[ DIS_CANS ];            ///< array of motion vector predictor candidates
    6565  Int    m_aVIdxCan[ DIS_CANS ];            ///< array of motion vector predictor candidates
     66#if QC_CU_NBDV_D0181
     67  Bool bDV;
     68#if MERL_VSP_C0152
     69  TComMv m_acMvCandNoRef[ DIS_CANS ];
     70#endif
     71#endif
    6672  Int    iN;                                ///< number of motion vector predictor candidates
     73#if MERL_VSP_NBDV_RefVId_Fix_D0166
     74  Int    m_aListIdx[ DIS_CANS ];            ///< array of reference list of derived NBDV
     75  Int    m_aRefIdx [ DIS_CANS ];            ///< array of reference frame index corresponding to either RefList0/1
     76#endif
    6777} DisInfo;
    6878
  • trunk/source/Lib/TLibCommon/TComPicYuv.cpp

    r332 r443  
    488488  }
    489489}
    490 
     490#if QC_ARP_D0177
     491Void  TComPicYuv::clearPic()
     492{
     493  ::memset ( m_apiPicBufY, 0 , sizeof (Pel) * ( m_iPicWidth       + (m_iLumaMarginX   << 1)) * ( m_iPicHeight       + (m_iLumaMarginY   << 1)) );
     494  ::memset ( m_apiPicBufU, 0 , sizeof (Pel) * ((m_iPicWidth >> 1) + (m_iChromaMarginX << 1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY << 1)) );
     495  ::memset ( m_apiPicBufV, 0 , sizeof (Pel) * ((m_iPicWidth >> 1) + (m_iChromaMarginX << 1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY << 1)) );
     496}
     497#endif
    491498//! \}
  • trunk/source/Lib/TLibCommon/TComPicYuv.h

    r56 r443  
    183183  Void  setLumaTo    ( Pel pVal ); 
    184184  Void  setChromaTo  ( Pel pVal ); 
    185 
     185#if QC_ARP_D0177
     186  Void    clearPic();
     187#endif
    186188};// END CLASS DEFINITION TComPicYuv
    187189
  • trunk/source/Lib/TLibCommon/TComPrediction.cpp

    r332 r443  
    5050#endif
    5151
     52#if HHI_DELTADC_DLT_D0035
     53#define GetDepthValue2Idx(val)     (pcCU->getSlice()->getSPS()->depthValue2idx(val))
     54#define GetIdx2DepthValue(val)     (pcCU->getSlice()->getSPS()->idx2DepthValue(val))
     55#endif
     56
     57#if MERL_General_Fix
     58#if MERL_VSP_C0152
     59#if MERL_CVSP_D0165
     60Int TComPrediction::m_iRangeLuma[12]   = {14, 34, 21, 15, 36, 26, 21, 49, 41, 36, 80, 72};
     61Int TComPrediction::m_iRangeChroma[12] = { 2,  8,  5,  4, 11,  9,  8, 19, 17, 15, 34, 32};
     62#endif
     63#endif
     64#endif
     65
    5266TComPrediction::TComPrediction()
    5367: m_pLumaRecBuffer(0)
     
    7892
    7993  m_cYuvPredTemp.destroy();
    80 
     94#if QC_ARP_D0177
     95  m_acYuvPredBase[0].destroy();
     96  m_acYuvPredBase[1].destroy();
     97  m_acYuvDiff[0].destroy();
     98  m_acYuvDiff[1].destroy();
     99#endif
    81100  if( m_pLumaRecBuffer )
    82101  {
     
    119138
    120139    m_cYuvPredTemp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
     140#if QC_ARP_D0177
     141    m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
     142    m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
     143    m_acYuvDiff    [0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
     144    m_acYuvDiff    [1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
     145#endif
    121146  }
    122147
     
    535560  // Do prediction
    536561  {
     562#if QC_DC_PREDICTOR_D0183
     563    Int iMean0, iMean1;
     564    getPredDCs( pbRegion, iWidth, pSrc+srcStride+1, srcStride, iMean0, iMean1 );
     565#else
    537566    //UInt uiSum0 = 0, uiSum1 = 0;
    538567    Int iSum0 = 0, iSum1 = 0;
     
    573602    iMean0 = iSum0 / iCount0; // TODO : integer op.
    574603    iMean1 = iSum1 / iCount1;
     604#endif
    575605#if LGE_EDGE_INTRA_DELTA_DC
    576606    if( bDelta )
     
    751781}
    752782
    753 #if H3D_IVRP
     783#if H3D_IVRP & !QC_ARP_D0177
    754784Void TComPrediction::residualPrediction(TComDataCU* pcCU, TComYuv* pcYuvPred, TComYuv* pcYuvResPred)
    755785{
     
    768798  pcYuvPred->add(pcYuvResPred, iWidth, iHeight);
    769799}
     800#endif
     801
     802#if MERL_General_Fix
     803#if MERL_VSP_C0152
     804// Function to perform VSP block compensation
     805Void  TComPrediction::xPredInterVSPBlk(TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, TComMv cMv, RefPicList eRefPicList, TComYuv*& rpcYuvPred
     806                                     , Bool bi
     807#if !MERL_Bi_VSP_D0166
     808                                     , Int vspIdx
     809#endif
     810                                       )
     811{
     812  TComPic*    pRefPicBaseTxt        = NULL;
     813  TComPicYuv* pcBaseViewTxtPicYuv   = NULL;
     814  TComPicYuv* pcBaseViewDepthPicYuv = NULL;
     815  Int iBlkX = 0;
     816  Int iBlkY = 0;
     817  Int* pShiftLUT;
     818  Int  iShiftPrec;
     819
     820#if !MERL_VSP_NBDV_RefVId_Fix_D0166
     821  pRefPicBaseTxt        = pcCU->getSlice()->getRefPicBaseTxt();
     822  pcBaseViewTxtPicYuv   = pRefPicBaseTxt->getPicYuvRec();
     823  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getRefPicBaseDepth();
     824  pcBaseViewDepthPicYuv     = pRefPicBaseDepth->getPicYuvRec();
     825
     826  Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
     827  Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
     828  pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec);
     829  xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getSPS()->isDepth(), rpcYuvPred );
     830  xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), rpcYuvPred );
     831
     832#else // MERL_VSP_NBDV_RefVId_Fix_D0166
     833   // Step 1: get depth reference
     834#if QC_BVSP_CleanUP_D0191
     835  RefPicList privateRefPicList = REF_PIC_LIST_0;
     836  Int refIdxList0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
     837  Int refIdxList1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
     838  privateRefPicList = refIdxList0 != NOT_VALID ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
     839  if(privateRefPicList == REF_PIC_LIST_1 && refIdxList1== NOT_VALID )
     840  {
     841    assert(0);
     842  }
     843  Int privateRefIdx = privateRefPicList == REF_PIC_LIST_0 ? refIdxList0 : refIdxList1;
     844  Int viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, privateRefIdx);
     845  Int refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, privateRefIdx);
     846#else
     847  //recover VSP reference frame according to negative refIdx number
     848  RefPicList privateRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
     849  assert(privateRefPicList == REF_PIC_LIST_0 || privateRefPicList == REF_PIC_LIST_1);
     850  Int  refIdx = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr ); // texture ref index, a trick when storing refIdx
     851  Int  viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, refIdx);  // texture view id
     852  Int  refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, refIdx);     // texture POC
     853#endif
     854  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getDepthRefPic(viewId, refPoc);
     855
     856  pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
     857  assert(refPoc == pcCU->getSlice()->getPOC());
     858  assert(pRefPicBaseDepth != NULL);
     859  assert(pcBaseViewDepthPicYuv != NULL);
     860
     861  iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
     862  iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
     863#if MERL_Bi_VSP_D0166
     864  // Step 2: get texture reference
     865  pRefPicBaseTxt = xGetVspRefTxt( pcCU, uiPartAddr, eRefPicList);
     866  pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
     867  assert(pcBaseViewTxtPicYuv != NULL);
     868
     869  // initialize the LUT according to the reference view idx
     870  pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec, pRefPicBaseTxt->getViewId());
     871
     872  // Step 3: Do compensation
     873  xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getSPS()->isDepth(), rpcYuvPred, bi );
     874  xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), rpcYuvPred, bi );
     875#else
     876  // Step 2: get texture reference
     877  pRefPicBaseTxt = pcCU->getSlice()->getRefPic(privateRefPicList, refIdx);
     878  pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
     879  assert(pcBaseViewTxtPicYuv != NULL);
     880
     881  //initialize the LUT according to the reference view idx
     882  pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec, pRefPicBaseTxt->getViewId());
     883
     884  // Step 3: Do compensation
     885  xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
     886  xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
     887#endif
     888
     889#endif
     890}
     891
     892#endif
     893
     894#if MERL_Bi_VSP_D0166
     895TComPic*  TComPrediction::xGetVspRefTxt(TComDataCU* pcCU, UInt uiPartAddr, RefPicList eRefPicList)
     896{
     897#if QC_BVSP_CleanUP_D0191
     898  RefPicList privateRefPicList = REF_PIC_LIST_0;
     899  Int refIdxList0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
     900  Int refIdxList1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
     901  privateRefPicList = refIdxList0 != NOT_VALID ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
     902  if(privateRefPicList == REF_PIC_LIST_1 && refIdxList1==NOT_VALID )
     903  {
     904    assert(0);
     905  }
     906  Int privateRefIdx = privateRefPicList == REF_PIC_LIST_0 ? refIdxList0 : refIdxList1;
     907  Int viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, privateRefIdx);
     908#else
     909  RefPicList  privateRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
     910  Int         refIdx = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr ); // texture ref index, a trick when storing refIdx
     911  Int         viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, refIdx);  // texture view id
     912#endif
     913  TComPic*    refPic = NULL;
     914
     915  assert(privateRefPicList == REF_PIC_LIST_0 || privateRefPicList == REF_PIC_LIST_1);
     916
     917  if (privateRefPicList == eRefPicList)
     918  {
     919#if QC_BVSP_CleanUP_D0191
     920    Int  refIdxt = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
     921#else
     922    Int  refIdxt = -1-pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
     923#endif
     924    assert(refIdxt>= 0);
     925    refPic = pcCU->getSlice()->getRefPic(eRefPicList, refIdxt);
     926  }
     927  else
     928  {
     929    // Find the other interview reference in order to do VSP
     930    RefPicList otherRefPicList = privateRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
     931    Bool isFound = false;
     932    for (Int iRefIdx = 0; iRefIdx <pcCU->getSlice()->getNumRefIdx(otherRefPicList); iRefIdx ++ )
     933    {
     934      Int refViewIdx  = pcCU->getSlice()->getRefViewId( otherRefPicList, iRefIdx);
     935      if ( (refViewIdx != pcCU->getSlice()->getViewId()) && (refViewIdx != viewId ) )
     936      {
     937        refPic = pcCU->getSlice()->getRefPic(otherRefPicList, iRefIdx);
     938        isFound = true;
     939        break;
     940      }
     941    }
     942
     943    if (isFound == false)
     944    {
     945#if QC_BVSP_CleanUP_D0191
     946      Int  refIdxTxt = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
     947#else
     948      Int  refIdxTxt = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
     949#endif
     950      assert(refIdxTxt >= 0);
     951      refPic = pcCU->getSlice()->getRefPic(privateRefPicList, refIdxTxt);
     952    }
     953    assert(isFound);
     954  }
     955  assert(refPic != NULL);
     956  return refPic;
     957}
     958#endif
    770959#endif
    771960
     
    781970  if (vspIdx != 0)
    782971  {
     972#if !QC_BVSP_CleanUP_D0191
    783973    if (iRefIdx >= 0)
    784974    {
     
    786976    }
    787977    assert (iRefIdx < 0); // assert (iRefIdx == NOT_VALID);
     978#endif
    788979  }
    789980  else
     
    8101001  }
    8111002#endif
    812 
     1003#if QC_ARP_D0177
     1004  if(
     1005#if MERL_General_Fix // TODO: Maybe logically redundant, but easier to read. Need verification before being removed
     1006#if MERL_VSP_C0152
     1007       vspIdx == 0 &&
     1008#endif
     1009#endif
     1010       pcCU->getSlice()->getSPS()->isDepth() == false
     1011    && pcCU->getSlice()->getSPS()->getViewId() > 0
     1012    && pcCU->getSlice()->getSPS()->getUseAdvRP() > 0
     1013    && pcCU->getARPW( uiPartAddr ) > 0
     1014    && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC()
     1015    && (pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N || pcCU->isSkipped(uiPartAddr))
     1016    )
     1017  {
     1018    xPredInterUniARP( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , iPartIdx , bi );
     1019  }
     1020  else
     1021  {
     1022#endif
    8131023#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
    8141024  if( pcCU->getSlice()->getSPS()->isDepth() )
     
    8161026#if MERL_VSP_C0152
    8171027    if (vspIdx != 0)
    818     { // depth, vsp
     1028    { // depth, vsp compensation
     1029#if !MERL_General_Fix
    8191030      // get depth estimator here
    8201031      TComPic* pRefPicBaseDepth = pcCU->getSlice()->getRefPicBaseDepth();
     
    8331044      xPredInterLumaBlkFromDM  ( pcBaseViewDepthPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,     pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
    8341045      xPredInterChromaBlkFromDM( pcBaseViewDepthPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1,  pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
     1046#else
     1047#if MERL_Bi_VSP_D0166
     1048      xPredInterVSPBlk(pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, cMv, eRefPicList, rpcYuvPred, bi );
     1049#else
     1050      xPredInterVSPBlk(pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, cMv, eRefPicList, rpcYuvPred, bi, vspIdx );
     1051#endif
     1052#endif
    8351053    }
    8361054    else
     
    8551073#endif// MERL_VSP_C0152 //else
    8561074  }
    857   else
     1075  else  // texture
    8581076  {
    8591077#endif
    8601078#if MERL_VSP_C0152
    8611079    if ( vspIdx != 0 )
    862     { // texture, vsp
     1080    { // texture, vsp compensation
     1081#if !MERL_General_Fix
    8631082      TComPic*    pRefPicBaseTxt        = pcCU->getSlice()->getRefPicBaseTxt();
    8641083      TComPicYuv* pcBaseViewTxtPicYuv   = pRefPicBaseTxt->getPicYuvRec();
     
    8791098      xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
    8801099      xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
     1100#else
     1101#if MERL_Bi_VSP_D0166
     1102      xPredInterVSPBlk(pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, cMv, eRefPicList, rpcYuvPred, bi );
     1103#else
     1104      xPredInterVSPBlk(pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, cMv, eRefPicList, rpcYuvPred, bi, vspIdx );
     1105#endif
     1106#endif
    8811107    }
    8821108    else//texture not VSP
     
    9111137   }
    9121138#endif
    913 }
    914 
     1139#if QC_ARP_D0177
     1140  }
     1141#endif
     1142}
     1143
     1144#if QC_ARP_D0177
     1145Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bi, TComMvField * pNewMvFiled )
     1146{
     1147  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
     1148  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
     1149  Bool        bTobeScaled = false;
     1150  UChar dW = pcCU->getARPW ( uiPartAddr );
     1151  TComPic* pcPicYuvBaseCol =  NULL;
     1152  TComPic* pcPicYuvBaseRef =  NULL;
     1153  DisInfo cDistparity;
     1154
     1155  if( pNewMvFiled )
     1156  {
     1157    iRefIdx = pNewMvFiled->getRefIdx();
     1158    cMv = pNewMvFiled->getMv();
     1159  }
     1160
     1161#if QC_CU_NBDV_D0181
     1162  cDistparity.bDV           = pcCU->getDvInfo(uiPartAddr).bDV;
     1163  if( cDistparity.bDV )
     1164  {
     1165#if MERL_VSP_C0152
     1166    cDistparity.m_acMvCand[0] = pcCU->getDvInfo(0).m_acMvCandNoRef[0];
     1167#else
     1168    cDistparity.m_acMvCand[0] = pcCU->getDvInfo(0).m_acMvCand[0];
     1169#endif
     1170    assert(pcCU->getDvInfo(uiPartAddr).bDV ==  pcCU->getDvInfo(0).bDV);
     1171    cDistparity.m_aVIdxCan[0] = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan[0];
     1172    cDistparity.iN            = pcCU->getDvInfo(uiPartAddr).iN;
     1173  }
     1174  else
     1175    cDistparity.iN    =  0;
     1176#else
     1177  pcCU->getDisMvpCandNBDV( iPartIdx, uiPartAddr,  &cDistparity, false );
     1178#endif
     1179
     1180  dW = !cDistparity.iN ? 0: dW;
     1181  if( cDistparity.iN )
     1182  {
     1183    if(dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC()!= pcCU->getSlice()->getPOC())
     1184      bTobeScaled = true;
     1185    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan[0] );
     1186    pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC(), cDistparity.m_aVIdxCan[0] );
     1187    if( (!pcPicYuvBaseCol || pcPicYuvBaseCol->getPOC() != pcCU->getSlice()->getPOC()) || (!pcPicYuvBaseRef || pcPicYuvBaseRef->getPOC() != pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() ))
     1188    {
     1189      dW = 0;
     1190      bTobeScaled = false;
     1191    }
     1192    else
     1193      assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() );
     1194    if(bTobeScaled)
     1195    {     
     1196      Int iCurrPOC = pcCU->getSlice()->getPOC();
     1197      Int iColRefPOC  = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx );
     1198      Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList,  0);
     1199      Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC);
     1200      if ( iScale != 4096 )
     1201        cMv = cMv.scaleMv( iScale );
     1202      iRefIdx = 0;
     1203    }
     1204  }
     1205  pcCU->clipMv(cMv);
     1206  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
     1207  xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
     1208#if LGE_ILLUCOMP_B0045
     1209    , false
     1210#endif
     1211    , true
     1212    );
     1213  xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
     1214#if LGE_ILLUCOMP_B0045
     1215    , false
     1216#endif
     1217    , true
     1218    );
     1219  if( dW > 0 )
     1220  {
     1221    TComYuv * pYuvmB0 = &m_acYuvPredBase[0];
     1222    TComYuv * pYuvB1  = &m_acYuvPredBase[1];
     1223    assert ( cDistparity.iN == 1 );
     1224    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
     1225    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acMvCand[0], iWidth, iHeight, pYuvB1, bi
     1226#if LGE_ILLUCOMP_B0045
     1227      , false
     1228#endif
     1229      ,  true
     1230      );
     1231    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acMvCand[0], iWidth, iHeight, pYuvB1, bi
     1232#if LGE_ILLUCOMP_B0045
     1233      , false
     1234#endif
     1235      , true
     1236      );
     1237    pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
     1238    TComMv cMVwithDisparity = cMv + cDistparity.m_acMvCand[0];
     1239    pcCU->clipMv(cMVwithDisparity);
     1240    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvmB0, bi
     1241#if LGE_ILLUCOMP_B0045
     1242      , false
     1243#endif
     1244      , true
     1245      );
     1246    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvmB0, bi
     1247#if LGE_ILLUCOMP_B0045
     1248      , false
     1249#endif
     1250      , true
     1251      );
     1252    pYuvB1->subtractARP( pYuvB1 , pYuvmB0 , uiPartAddr , iWidth , iHeight );
     1253    if(dW == 2)
     1254      pYuvB1->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
     1255    rpcYuvPred->addARP( rpcYuvPred , pYuvB1 , uiPartAddr , iWidth , iHeight , !bi );
     1256  }
     1257}
     1258#endif
    9151259
    9161260#if MERL_VSP_C0152
     
    9231267  Int      iRefIdx[2] = {-1, -1};
    9241268
     1269#if MERL_Bi_VSP_D0166
     1270  Bool biDecision = 0;
     1271  Int  predDirVSP = 0;
     1272#if QC_BVSP_CleanUP_D0191
     1273  RefPicList privateRefPicList = REF_PIC_LIST_0;
     1274#endif
     1275  if (pcCU->getVSPIndex(uiPartAddr) != 0) // is VSP
     1276  {
     1277    Int biVSPAvail = 0;
     1278    //test whether VSP is Bi or Uni
     1279    //Step1. Get derived DV view id
     1280#if QC_BVSP_CleanUP_D0191
     1281    RefPicList otherRefPicList = REF_PIC_LIST_1;
     1282    Int refIdxList0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
     1283    Int refIdxList1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
     1284    privateRefPicList = refIdxList0 != NOT_VALID ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
     1285    if(privateRefPicList == REF_PIC_LIST_1 && refIdxList1==NOT_VALID )
     1286    {
     1287      assert(0);
     1288    }
     1289    Int privateRefIdx = privateRefPicList == REF_PIC_LIST_0 ? refIdxList0 : refIdxList1;
     1290    Int viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, privateRefIdx);
     1291    Int refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, privateRefIdx);
     1292#else
     1293    Int  refIdx = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
     1294    RefPicList privateRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
     1295    RefPicList otherRefPicList = privateRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
     1296    assert(privateRefPicList == REF_PIC_LIST_0 || privateRefPicList == REF_PIC_LIST_1);
     1297    Int  refIdx = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
     1298    assert(refIdx >= 0);
     1299    Int  viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, refIdx);
     1300    Int  refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, refIdx);
     1301#endif
     1302    assert(refPoc == pcCU->getSlice()->getPOC());
     1303//    if(refPoc != pcCU->getSlice()->getPOC() )
     1304//    {
     1305//      printf("refPOC= %d, and current POC=%d\n", refPoc, pcCU->getSlice()->getPOC() );
     1306//    }
     1307    //Step 2. Get initial prediction direction value according to reference picture list availability
     1308    Int iInterDir = ((pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 0) ? 3 :
     1309      (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 0 ? 1 : 2));
     1310    //Step 3.  Check the availability of Bi VSP by checking the interview reference availability in the other reference list
     1311    if(iInterDir == 3)
     1312    {
     1313      for (Int jRefIdx = 0; jRefIdx <pcCU->getSlice()->getNumRefIdx(otherRefPicList); jRefIdx++ )
     1314      {
     1315        Int refViewIdx  = pcCU->getSlice()->getRefViewId( otherRefPicList, jRefIdx);
     1316        if ( (refViewIdx != pcCU->getSlice()->getViewId()) && (refViewIdx != viewId ) )
     1317        {
     1318          biVSPAvail = 1;
     1319          break;
     1320        }
     1321      }
     1322    }
     1323    //Step 4. Update the Bi VSP prediction direction
     1324    if ( iInterDir == 3 && biVSPAvail == 1)
     1325    {
     1326      biDecision   = 1;
     1327      predDirVSP = 3;
     1328    }
     1329    else
     1330    {
     1331      biDecision = 0;
     1332      if ( privateRefPicList == REF_PIC_LIST_0 )
     1333        predDirVSP = 1;
     1334      else
     1335        predDirVSP = 2;
     1336    }
     1337  }
     1338  else
     1339  {//not VSP
     1340    if( ( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) )
     1341      biDecision = 1;
     1342    else
     1343      biDecision = 0;
     1344  }
     1345#endif
     1346
    9251347  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
    9261348  {
     
    9381360    else
    9391361    {
    940       if ( iRefList== REF_PIC_LIST_1 && iRefIdx[iRefList] < 0 ) // iRefIdx[iRefList] ==NOT_VALID
     1362
     1363#if !MERL_Bi_VSP_D0166 //both lists should go
     1364      if ( iRefList == REF_PIC_LIST_1 && iRefIdx[iRefList] < 0 ) // iRefIdx[iRefList] ==NOT_VALID
    9411365      {
    9421366        continue;
    9431367      }
     1368#else
     1369      //Reference list loop termination
     1370#if QC_BVSP_CleanUP_D0191
     1371      RefPicList privateVSPRefPicList = privateRefPicList;
     1372#else
     1373      RefPicList privateVSPRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
     1374#endif
     1375      if( (pcCU->getVSPIndex(uiPartAddr)!=0) &&  iRefList != privateVSPRefPicList && !biDecision  )
     1376      {//when VSP mode, if it is uni prediction, the other reference list should skip
     1377        continue;
     1378      }
     1379#endif
     1380
    9441381    }
    9451382#else
     
    9531390
    9541391    pcMbYuv = &m_acYuvPred[iRefList];
     1392
     1393#if MERL_Bi_VSP_D0166
     1394    if(biDecision == 1)
     1395#else
    9551396    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
     1397#endif
    9561398    {
    9571399#if MERL_VSP_C0152
     
    9931435  {
    9941436#if MERL_VSP_C0152
     1437#if !MERL_Bi_VSP_D0166
    9951438    if(pcCU->getVSPIndex(uiPartAddr))
    9961439      m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight );
    9971440    else
    9981441#endif
     1442#endif
    9991443    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
    10001444  }
     
    10041448  {
    10051449#if MERL_VSP_C0152
     1450#if !MERL_Bi_VSP_D0166
    10061451    if(pcCU->getVSPIndex(uiPartAddr))
    10071452      m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight );
    10081453    else
    10091454#endif
     1455#endif
    10101456      xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred, iPartIdx );
    10111457  }
     
    10201466    {
    10211467#if MERL_VSP_C0152
     1468#if !MERL_Bi_VSP_D0166
    10221469      if(pcCU->getVSPIndex(uiPartAddr))
    10231470        m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight );
    10241471      else
    1025 #endif
     1472        xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
     1473#else
     1474      xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, predDirVSP );
     1475#endif
     1476#else
    10261477      xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
     1478#endif
    10271479    }
    10281480  }
     
    11081560 */
    11091561#if LGE_ILLUCOMP_B0045
    1110 Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag)
    1111 #else
    1112 Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi )
     1562Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag
     1563#if QC_ARP_D0177
     1564    ,
     1565    Int filterType
     1566#endif
     1567    )
     1568#else
     1569Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
     1570#if QC_ARP_D0177
     1571    ,
     1572    Int filterType
     1573#endif
     1574    )
    11131575#endif
    11141576{
     
    11291591  if ( yFrac == 0 )
    11301592  {
    1131     m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi );
     1593    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
     1594#if QC_ARP_D0177
     1595    ,
     1596    filterType
     1597#endif
     1598    );
    11321599  }
    11331600  else if ( xFrac == 0 )
    11341601  {
    1135     m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi );
     1602    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
     1603#if QC_ARP_D0177
     1604    ,
     1605    filterType
     1606#endif
     1607    );
    11361608  }
    11371609  else
     
    11431615    Int halfFilterSize = ( filterSize >> 1 );
    11441616
    1145     m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     );
    1146     m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi);   
     1617    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
     1618 #if QC_ARP_D0177
     1619    ,
     1620    filterType
     1621#endif
     1622    );
     1623    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
     1624 #if QC_ARP_D0177
     1625    ,
     1626    filterType
     1627#endif
     1628    );   
    11471629  }
    11481630
     
    11851667 */
    11861668#if LGE_ILLUCOMP_B0045
    1187 Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag )
    1188 #else
    1189 Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi )
     1669Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag
     1670#if QC_ARP_D0177
     1671    ,
     1672    Int filterType
     1673#endif   
     1674    )
     1675#else
     1676Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
     1677#if QC_ARP_D0177
     1678  , Int filterType
     1679#endif
     1680  )
    11901681#endif
    11911682{
     
    12151706  if ( yFrac == 0 )
    12161707  {
    1217     m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi);   
    1218     m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi);   
     1708    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
     1709#if QC_ARP_D0177
     1710    ,
     1711    filterType
     1712#endif   
     1713    );   
     1714    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
     1715#if QC_ARP_D0177
     1716    ,
     1717    filterType
     1718#endif   
     1719    );   
    12191720  }
    12201721  else if ( xFrac == 0 )
    12211722  {
    1222     m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi);   
    1223     m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi);   
     1723    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
     1724 #if QC_ARP_D0177
     1725    ,
     1726    filterType
     1727#endif   
     1728    );   
     1729    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
     1730 #if QC_ARP_D0177
     1731    ,
     1732    filterType
     1733#endif   
     1734    );   
    12241735  }
    12251736  else
    12261737  {
    1227     m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false);
    1228     m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi);
     1738    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
     1739#if QC_ARP_D0177
     1740    ,
     1741    filterType
     1742#endif   
     1743    );
     1744    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
     1745#if QC_ARP_D0177
     1746    ,
     1747    filterType
     1748#endif   
     1749    );
    12291750   
    1230     m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false);
    1231     m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi);   
     1751    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
     1752#if QC_ARP_D0177
     1753    ,
     1754    filterType
     1755#endif   
     1756    );
     1757    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
     1758#if QC_ARP_D0177
     1759    ,
     1760    filterType
     1761#endif   
     1762    );   
    12321763  }
    12331764#if LGE_ILLUCOMP_B0045
     
    12741805// refPic: Ref picture. Full picture, with padding
    12751806// posX, posY:     PU position, texture
    1276 // size_x, size_y: PU size
     1807// sizeX, sizeY: PU size
    12771808// partAddr: z-order index
    12781809// mv: disparity vector. derived from neighboring blocks
    12791810//
    12801811// Output: dstPic, PU predictor 64x64
    1281 Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv* mv, UInt partAddr,Int posX, Int posY, Int size_x, Int size_y, Bool isDepth, Int vspIdx
    1282                                             , TComYuv *&dstPic )
     1812Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv* mv, UInt partAddr,Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth
     1813#if !MERL_Bi_VSP_D0166
     1814                                            , Int vspIdx
     1815#endif
     1816                                            , TComYuv *&dstPic
     1817#if MERL_Bi_VSP_D0166
     1818                                            , Bool bi
     1819#endif         
     1820                                            )
    12831821{
    12841822  Int widthLuma;
     
    13011839#endif
    13021840
     1841#if MERL_CVSP_D0165
     1842  Int widthDepth  = pPicBaseDepth->getWidth();
     1843  Int heightDepth = pPicBaseDepth->getHeight();
     1844#endif
     1845
    13031846  Int nTxtPerDepthX = widthLuma  / ( pPicBaseDepth->getWidth() );  // texture pixel # per depth pixel
    13041847  Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() );
     
    13071850  Int dstStride = dstPic->getStride();
    13081851  Int depStride =  pPicBaseDepth->getStride();
    1309   Int depthPosX = Clip3(0,   widthLuma - size_x,  (posX/nTxtPerDepthX) + (mv->getHor()>>2));
    1310   Int depthPosY = Clip3(0,   heightLuma- size_y,  (posY/nTxtPerDepthY) + (mv->getVer()>>2));
     1852#if LGE_ROUND_OFFSET_D0135
     1853  Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + ((mv->getHor()+2)>>2));
     1854  Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + ((mv->getVer()+2)>>2));
     1855#else
     1856  Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + (mv->getHor()>>2));
     1857  Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + (mv->getVer()>>2));
     1858#endif
    13111859  Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
    13121860  Pel *dst    = dstPic->getLumaAddr(partAddr);
     
    13151863#if MERL_VSP_BLOCKSIZE_C0152 != 1
    13161864#if MERL_VSP_BLOCKSIZE_C0152 == 2
    1317   Int  dW = size_x>>1;
    1318   Int  dH = size_y>>1;
     1865  Int  dW = sizeX>>1;
     1866  Int  dH = sizeY>>1;
    13191867#endif
    13201868#if MERL_VSP_BLOCKSIZE_C0152 == 4
    1321   Int  dW = size_x>>2;
    1322   Int  dH = size_y>>2;
     1869  Int  dW = sizeX>>2;
     1870  Int  dH = sizeY>>2;
    13231871#endif
    13241872  {
     
    13421890#endif
    13431891        Int maxV = 0;
     1892#if MTK_DEPTH_TO_DISP_D0138
     1893        for (Int blockj = 0; blockj < MERL_VSP_BLOCKSIZE_C0152; blockj+=(MERL_VSP_BLOCKSIZE_C0152-1))
     1894#else
    13441895        for (Int blockj = 0; blockj < MERL_VSP_BLOCKSIZE_C0152; blockj++)
     1896#endif
    13451897        {
    13461898          Int iX = 0;
     1899#if MTK_DEPTH_TO_DISP_D0138
     1900          for (Int blocki = 0; blocki < MERL_VSP_BLOCKSIZE_C0152; blocki+=(MERL_VSP_BLOCKSIZE_C0152-1))
     1901#else
    13471902          for (Int blocki = 0; blocki < MERL_VSP_BLOCKSIZE_C0152; blocki++)
     1903#endif
    13481904          {
    13491905            if (maxV < depthTmp[iX])
     
    13811937#endif
    13821938 
     1939#if MERL_General_Fix
     1940#if MERL_VSP_BLOCKSIZE_C0152 == 1
     1941#if MERL_CVSP_D0165
     1942  //get LUT based horizontal reference range
     1943  Int range = 0;
     1944  if( sizeX == 4 && sizeY == 8 )
     1945    range = m_iRangeLuma[0];
     1946  else if( sizeX == 8 && sizeY == 4 )
     1947    range = m_iRangeLuma[1];
     1948  else if( sizeX == 8 && sizeY == 8 )
     1949    range = m_iRangeLuma[2];
     1950  else if( sizeX == 8 && sizeY == 16 )
     1951    range = m_iRangeLuma[3];
     1952  else if( sizeX == 16 && sizeY == 8 )
     1953    range = m_iRangeLuma[4];
     1954  else if( sizeX == 16 && sizeY == 16 )
     1955    range = m_iRangeLuma[5];
     1956  else if( sizeX == 16 && sizeY == 32 )
     1957    range = m_iRangeLuma[6];
     1958  else if( sizeX == 32 && sizeY == 16 )
     1959    range = m_iRangeLuma[7];
     1960  else if( sizeX == 32 && sizeY == 32 )
     1961    range = m_iRangeLuma[8];
     1962  else if( sizeX == 32 && sizeY == 64 )
     1963    range = m_iRangeLuma[9];
     1964  else if( sizeX == 64 && sizeY == 32 )
     1965    range = m_iRangeLuma[10];
     1966  else if( sizeX == 64 && sizeY == 64 )
     1967    range = m_iRangeLuma[11];
     1968  else
     1969    assert(0);
     1970
     1971  // The minimum depth value
     1972  Int minRelativePos = 5000;
     1973  Int maxRelativePos = -5000;
     1974
     1975  Pel* depthTemp, *depthInitial=depth;
     1976  for (Int yTxt =0; yTxt<sizeY; yTxt++)
     1977  {
     1978    for (Int xTxt =0; xTxt<sizeX; xTxt++)
     1979    {
     1980      if (depthPosX+xTxt < widthDepth)
     1981        depthTemp = depthInitial + xTxt;
     1982      else
     1983        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
     1984
     1985      Int disparity = pShiftLUT[ *depthTemp ] << iShiftPrec;
     1986      Int disparityInt = disparity >> 2;
     1987
     1988      if( disparity <= 0)
     1989      {
     1990        if (minRelativePos > disparityInt+xTxt)
     1991            minRelativePos = disparityInt+xTxt;
     1992      }
     1993      else
     1994      {
     1995        if (maxRelativePos < disparityInt+xTxt)
     1996            maxRelativePos = disparityInt+xTxt;
     1997      }
     1998    }
     1999    if (depthPosY+yTxt < heightDepth)
     2000      depthInitial = depthInitial + depStride;
     2001  }
     2002
     2003  Int disparity_tmp = pShiftLUT[ *depth ] << iShiftPrec;
     2004  if (disparity_tmp <= 0)
     2005    maxRelativePos = minRelativePos + range -1 ;
     2006  else
     2007    minRelativePos = maxRelativePos - range +1 ;
     2008#endif
     2009#endif
     2010#endif
     2011
    13832012#if MERL_VSP_BLOCKSIZE_C0152 != 1
    13842013  Int yDepth = 0;
    13852014#endif
    1386   for ( Int yTxt = 0; yTxt < size_y; yTxt += nTxtPerDepthY )
    1387   {
    1388     for ( Int xTxt = 0, xDepth = 0; xTxt < size_x; xTxt += nTxtPerDepthX, xDepth++ )
    1389     {
    1390       Pel rep_depth = 0; // to store the depth value used for warping
     2015  for ( Int yTxt = 0; yTxt < sizeY; yTxt += nTxtPerDepthY )
     2016  {
     2017    for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth++ )
     2018    {
     2019      Pel repDepth = 0; // to store the depth value used for warping
    13912020#if MERL_VSP_BLOCKSIZE_C0152 == 1
    1392       rep_depth = depth[xDepth];
     2021      repDepth = depth[xDepth];
    13932022#endif
    13942023#if MERL_VSP_BLOCKSIZE_C0152 == 2
    1395       rep_depth = m_pDepth[(xTxt>>1) + (yTxt>>1)*dW];
     2024      repDepth = m_pDepth[(xTxt>>1) + (yTxt>>1)*dW];
    13962025#endif
    13972026#if MERL_VSP_BLOCKSIZE_C0152 == 4
    1398       rep_depth = m_pDepth[(xTxt>>2) + (yTxt>>2)*dW];
    1399 #endif
    1400 
    1401       assert( rep_depth >= 0 && rep_depth <= 255 );
    1402       Int disparity = pShiftLUT[ rep_depth ] << iShiftPrec;
     2027      repDepth = m_pDepth[(xTxt>>2) + (yTxt>>2)*dW];
     2028#endif
     2029
     2030      assert( repDepth >= 0 && repDepth <= 255 );
     2031      Int disparity = pShiftLUT[ repDepth ] << iShiftPrec;
    14032032      Int refOffset = xTxt + (disparity >> 2);
    14042033      Int xFrac = disparity & 0x3;
     2034#if MERL_CVSP_D0165
     2035      if(refOffset<minRelativePos || refOffset>maxRelativePos)
     2036        xFrac = 0;
     2037      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
     2038#endif
    14052039      Int absX  = posX + refOffset;
    14062040
     
    14132047
    14142048      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
     2049#if MERL_Bi_VSP_D0166
     2050      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi );
     2051#else
    14152052      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true );
     2053#endif
     2054
    14162055    }
    14172056    ref   += refStride*nTxtPerDepthY;
     
    14212060    yDepth++;
    14222061#endif
    1423   }
    1424 }
    1425 
    1426 Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv*mv, UInt partAddr, Int posX, Int posY, Int size_x, Int size_y, Bool isDepth, Int vspIdx
    1427                                                , TComYuv *&dstPic )
     2062
     2063  }
     2064}
     2065
     2066Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv*mv, UInt partAddr, Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth
     2067#if !MERL_Bi_VSP_D0166
     2068                                               , Int vspIdx
     2069#endif
     2070                                               , TComYuv *&dstPic
     2071#if MERL_Bi_VSP_D0166
     2072                                               , Bool bi
     2073#endif
     2074                                               )
    14282075{
    14292076  Int refStride = refPic->getCStride();
     
    14582105    nTxtPerDepthX = widthChroma / widthDepth;
    14592106    nDepthPerTxtX = 1;
     2107#if LGE_ROUND_OFFSET_D0135
     2108    depthPosX = posX / nTxtPerDepthX + ((mv->getHor()+2)>>2);        //mv denotes the disparity for VSP
     2109#else
    14602110    depthPosX = posX / nTxtPerDepthX + (mv->getHor()>>2);        //mv denotes the disparity for VSP
     2111#endif
    14612112  }
    14622113  else
     
    14642115    nTxtPerDepthX = 1;
    14652116    nDepthPerTxtX = widthDepth / widthChroma;
     2117#if LGE_ROUND_OFFSET_D0135
     2118    depthPosX = posX * nDepthPerTxtX + ((mv->getHor()+2)>>2);        //mv denotes the disparity for VSP
     2119#else
    14662120    depthPosX = posX * nDepthPerTxtX + (mv->getHor()>>2);        //mv denotes the disparity for VSP
    1467   }
    1468   depthPosX = Clip3(0, widthDepth - (size_x<<1), depthPosX);
     2121#endif
     2122  }
     2123  depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX);
    14692124  if ( heightChroma > heightDepth )
    14702125  {
    14712126    nTxtPerDepthY = heightChroma / heightDepth;
    14722127    nDepthPerTxtY = 1;
     2128#if LGE_ROUND_OFFSET_D0135
     2129    depthPosY = posY / nTxtPerDepthY + ((mv->getVer()+2)>>2);     //mv denotes the disparity for VSP
     2130#else
    14732131    depthPosY = posY / nTxtPerDepthY + (mv->getVer()>>2);     //mv denotes the disparity for VSP
     2132#endif
    14742133  }
    14752134  else
     
    14772136    nTxtPerDepthY = 1;
    14782137    nDepthPerTxtY = heightDepth / heightChroma;
     2138#if LGE_ROUND_OFFSET_D0135
     2139    depthPosY = posY * nDepthPerTxtY + ((mv->getVer()+2)>>2);     //mv denotes the disparity for VSP
     2140#else
    14792141    depthPosY = posY * nDepthPerTxtY + (mv->getVer()>>2);     //mv denotes the disparity for VSP
    1480   }
    1481   depthPosY = Clip3(0, heightDepth - (size_y<<1), depthPosY);
     2142#endif
     2143  }
     2144  depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY);
    14822145
    14832146  Pel *refCb  = refPic->getCbAddr() + posX + posY * refStride;
     
    14912154  Int depStrideBlock = depStride * nDepthPerTxtY;
    14922155
     2156#if !MERL_Bi_VSP_D0166
    14932157  if (isDepth)
    14942158  {
    14952159     // DT: Since the call for this function is redundant, ..
    1496      for (Int y = 0; y < size_y; y++)
     2160     for (Int y = 0; y < sizeY; y++)
    14972161     {
    1498        for (Int x = 0; x < size_x; x++)
     2162       for (Int x = 0; x < sizeX; x++)
    14992163       {
    15002164         dstCb[x] = 128;
     
    15062170     return;
    15072171  }
    1508  
     2172#endif
     2173
    15092174  if ( widthChroma > widthDepth ) // We assume
    15102175  {
     
    15162181  {
    15172182#if MERL_VSP_BLOCKSIZE_C0152 == 1
    1518   Int  dW = size_x;
    1519   Int  dH = size_y;
     2183  Int  dW = sizeX;
     2184  Int  dH = sizeY;
    15202185  Int  sW = 2; // search window size
    15212186  Int  sH = 2;
    15222187#endif
    15232188#if MERL_VSP_BLOCKSIZE_C0152 == 2
    1524   Int  dW = size_x;
    1525   Int  dH = size_y;
     2189  Int  dW = sizeX;
     2190  Int  dH = sizeY;
    15262191  Int  sW = 2; // search window size
    15272192  Int  sH = 2;
    15282193#endif
    15292194#if MERL_VSP_BLOCKSIZE_C0152 == 4
    1530   Int  dW = size_x>>1;
    1531   Int  dH = size_y>>1;
     2195  Int  dW = sizeX>>1;
     2196  Int  dH = sizeY>>1;
    15322197  Int  sW = 4; // search window size
    15332198  Int  sH = 4;
     
    15942259
    15952260
    1596     // (size_x, size_y) is Chroma block size
    1597     for ( Int yTxt = 0, yDepth = 0; yTxt < size_y; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY )
    1598     {
    1599       for ( Int xTxt = 0, xDepth = 0; xTxt < size_x; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX )
    1600       {
    1601         Pel rep_depth = 0; // to store the depth value used for warping
     2261#if MERL_General_Fix
    16022262#if MERL_VSP_BLOCKSIZE_C0152 == 1
    1603         rep_depth = m_pDepth[(xTxt) + (yTxt)*dW];
     2263#if MERL_CVSP_D0165
     2264  //get LUT based horizontal reference range
     2265  Int range=0;
     2266  if( sizeX == 2 && sizeY == 4 )
     2267    range = m_iRangeChroma[0];
     2268  else if( sizeX == 4 && sizeY == 2 )
     2269    range = m_iRangeChroma[1];
     2270  else if( sizeX == 4 && sizeY == 4 )
     2271    range = m_iRangeChroma[2];
     2272  else if( sizeX == 4 && sizeY == 8 )
     2273    range = m_iRangeChroma[3];
     2274  else if( sizeX == 8 && sizeY == 4 )
     2275    range = m_iRangeChroma[4];
     2276  else if( sizeX == 8 && sizeY == 8 )
     2277    range = m_iRangeChroma[5];
     2278  else if( sizeX == 8 && sizeY == 16 )
     2279    range = m_iRangeChroma[6];
     2280  else if( sizeX == 16 && sizeY == 8 )
     2281    range = m_iRangeChroma[7];
     2282  else if( sizeX == 16 && sizeY == 16 )
     2283    range = m_iRangeChroma[8];
     2284  else if( sizeX == 16 && sizeY == 32 )
     2285    range = m_iRangeChroma[9];
     2286  else if( sizeX == 32 && sizeY == 16 )
     2287    range = m_iRangeChroma[10];
     2288  else if( sizeX == 32 && sizeY == 32 )
     2289    range = m_iRangeChroma[11];
     2290  else
     2291    assert(0);
     2292 
     2293  // The minimum depth value
     2294  Int minRelativePos = 5000;
     2295  Int maxRelativePos = -5000;
     2296
     2297  Int depthTmp;
     2298  for (Int yTxt=0; yTxt<sizeY; yTxt++)
     2299  {
     2300    for (Int xTxt=0; xTxt<sizeX; xTxt++)
     2301    {
     2302      depthTmp = m_pDepth[xTxt+yTxt*dW];
     2303      Int disparity = pShiftLUT[ depthTmp ] << iShiftPrec;
     2304      Int disparityInt = disparity >> 3;//in chroma resolution
     2305
     2306      if (disparityInt < 0)
     2307      {
     2308        if (minRelativePos > disparityInt+xTxt)
     2309            minRelativePos = disparityInt+xTxt;
     2310      }
     2311      else
     2312      {
     2313        if (maxRelativePos < disparityInt+xTxt)
     2314            maxRelativePos = disparityInt+xTxt;
     2315      }
     2316    }
     2317  }
     2318
     2319  depthTmp = m_pDepth[0];
     2320  Int disparity_tmp = pShiftLUT[ depthTmp ] << iShiftPrec;
     2321  if ( disparity_tmp < 0 )
     2322    maxRelativePos = minRelativePos + range - 1;
     2323  else
     2324    minRelativePos = maxRelativePos - range + 1;
     2325
     2326#endif
     2327#endif
     2328#endif
     2329
     2330    // (sizeX, sizeY) is Chroma block size
     2331    for ( Int yTxt = 0, yDepth = 0; yTxt < sizeY; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY )
     2332    {
     2333      for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX )
     2334      {
     2335        Pel repDepth = 0; // to store the depth value used for warping
     2336#if MERL_VSP_BLOCKSIZE_C0152 == 1
     2337        repDepth = m_pDepth[(xTxt) + (yTxt)*dW];
    16042338#endif
    16052339#if MERL_VSP_BLOCKSIZE_C0152 == 2
    1606         rep_depth = m_pDepth[(xTxt) + (yTxt)*dW];
     2340        repDepth = m_pDepth[(xTxt) + (yTxt)*dW];
    16072341#endif
    16082342#if MERL_VSP_BLOCKSIZE_C0152 == 4
    1609         rep_depth = m_pDepth[(xTxt>>1) + (yTxt>>1)*dW];
     2343        repDepth = m_pDepth[(xTxt>>1) + (yTxt>>1)*dW];
    16102344#endif
    16112345
    16122346      // calculate the offset in the reference picture
    1613         Int disparity = pShiftLUT[ rep_depth ] << iShiftPrec;
     2347        Int disparity = pShiftLUT[ repDepth ] << iShiftPrec;
    16142348        Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image
    16152349        Int xFrac = disparity & 0x7;
     2350#if MERL_CVSP_D0165
     2351        if(refOffset < minRelativePos || refOffset > maxRelativePos)
     2352          xFrac = 0;
     2353        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
     2354#endif
    16162355        Int absX  = posX + refOffset;
    16172356
     
    16252364        assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
    16262365        assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
     2366#if MERL_Bi_VSP_D0166
     2367        m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
     2368        m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
     2369#else
    16272370        m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true);
    16282371        m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true);
     2372#endif
     2373
    16292374      }
    16302375      refCb += refStrideBlock;
     
    16352380    }
    16362381  }
     2382
    16372383}
    16382384
     
    16422388Void TComPrediction::xWeightedAveragePdm( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst, UInt uiSubSampExpX, UInt uiSubSampExpY )
    16432389{
     2390
    16442391  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
    16452392  {
     
    16612408#endif
    16622409
    1663 Void TComPrediction::xWeightedAverage( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
    1664 {
     2410Void TComPrediction::xWeightedAverage( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst
     2411#if MERL_Bi_VSP_D0166
     2412                                 , Int predDirVSP
     2413#endif
     2414  )
     2415{
     2416#if MERL_Bi_VSP_D0166
     2417  Bool isVSP = 0;
     2418  if (pcCU->getVSPIndex(uiPartIdx)!=0)//is VSP
     2419  {
     2420    isVSP = 1;
     2421  }
     2422
     2423  if(( !isVSP && iRefIdx0 >= 0 && iRefIdx1 >= 0 ) || ( isVSP && predDirVSP == 3 ))
     2424#else
    16652425  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
     2426#endif
    16662427  {
    16672428    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
    16682429  }
     2430#if MERL_Bi_VSP_D0166
     2431  else if ( ( !isVSP && iRefIdx0 >= 0 && iRefIdx1 <  0 ) || ( isVSP && predDirVSP == 1))
     2432#else
    16692433  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
     2434#endif
    16702435  {
    16712436    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
    16722437  }
     2438#if MERL_Bi_VSP_D0166
     2439  else if (( !isVSP && iRefIdx0 <  0 && iRefIdx1 >= 0 ) || ( isVSP && predDirVSP == 2))
     2440#else
    16732441  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
     2442#endif
    16742443  {
    16752444    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
    16762445  }
     2446#if MERL_Bi_VSP_D0166
     2447  else
     2448  {//for debug test only
     2449    assert(0);
     2450  }
     2451#endif
    16772452}
    16782453
     
    20762851  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
    20772852  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
     2853#if LGE_ROUND_OFFSET_D0135
     2854  iRefX   = iCUPelX + ((pMv->getHor()+2) >> 2);
     2855  iRefY   = iCUPelY + ((pMv->getVer()+2) >> 2);
     2856#else
    20782857  iRefX   = iCUPelX + (pMv->getHor() >> 2);
    20792858  iRefY   = iCUPelY + (pMv->getVer() >> 2);
     2859#endif
    20802860  uiWidth = pcCU->getWidth(0);
    20812861  uiHeight = pcCU->getHeight(0);
     
    20892869  if(pcCU->getPUAbove(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelY > 0 && iRefY > 0)
    20902870  {
     2871#if LGE_ROUND_OFFSET_D0135
     2872    iRefOffset = ( (pMv->getHor()+2) >> 2 ) + ( (pMv->getVer()+2) >> 2 ) * iRefStride - iRefStride;
     2873#else
    20912874    iRefOffset = ( pMv->getHor() >> 2 ) + ( pMv->getVer() >> 2 ) * iRefStride - iRefStride;
     2875#endif
    20922876    pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    20932877    pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
     
    21062890  if(pcCU->getPULeft(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelX > 0 && iRefX > 0)
    21072891  {
     2892#if LGE_ROUND_OFFSET_D0135
     2893    iRefOffset = ( (pMv->getHor()+2) >> 2 ) + ( (pMv->getVer()+2) >> 2 ) * iRefStride - 1;
     2894#else
    21082895    iRefOffset = ( pMv->getHor() >> 2 ) + ( pMv->getVer() >> 2 ) * iRefStride - 1;
     2896#endif
    21092897    pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    21102898    pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
     
    22243012  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
    22253013  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
     3014#if LGE_ROUND_OFFSET_D0135
     3015  iRefX   = iCUPelX + ((pMv->getHor()+2) >> 2);
     3016  iRefY   = iCUPelY + ((pMv->getVer()+2) >> 2);
     3017#else
    22263018  iRefX   = iCUPelX + (pMv->getHor() >> 2);
    22273019  iRefY   = iCUPelY + (pMv->getVer() >> 2);
     3020#endif
    22283021  uiWidth = pcCU->getWidth(0) >> 1;
    22293022  uiHeight = pcCU->getHeight(0) >> 1;
     
    22373030  if(pcCU->getPUAbove(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelY > 0 && iRefY > 0)
    22383031  {
     3032#if LGE_ROUND_OFFSET_D0135
     3033    iRefOffset = ( (pMv->getHor()+4) >> 3 ) + ( (pMv->getVer()+4) >> 3 ) * iRefStride - iRefStride;
     3034#else
    22393035    iRefOffset = ( pMv->getHor() >> 3 ) + ( pMv->getVer() >> 3 ) * iRefStride - iRefStride;
     3036#endif
    22403037    if (iChromaId == 0) // Cb
    22413038    {
     
    22623059  if(pcCU->getPULeft(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelX > 0 && iRefX > 0)
    22633060  {
     3061#if LGE_ROUND_OFFSET_D0135
     3062    iRefOffset = ( (pMv->getHor()+4) >> 3 ) + ( (pMv->getVer()+4) >> 3 ) * iRefStride - 1;
     3063#else
    22643064    iRefOffset = ( pMv->getHor() >> 3 ) + ( pMv->getVer() >> 3 ) * iRefStride - 1;
     3065#endif
    22653066    if (iChromaId == 0) // Cb
    22663067    {
     
    24263227}
    24273228
     3229#if QC_DC_PREDICTOR_D0183
     3230Void TComPrediction::getPredDCs( Bool* pbPattern, Int iStride, Int* piMask, Int iMaskStride, Int& riPredDC1, Int& riPredDC2 )
     3231{
     3232  Int  iDC1, iDC2;
     3233  const Int  iTR = (   iStride - 1        ) - iMaskStride;
     3234  const Int  iTM = ( ( iStride - 1 ) >> 1 ) - iMaskStride;
     3235  const Int  iLB = (   iStride - 1        ) * iMaskStride - 1;
     3236  const Int  iLM = ( ( iStride - 1 ) >> 1 ) * iMaskStride - 1;
     3237  const UInt uiBitDepth = g_uiBitDepth + g_uiBitIncrement;
     3238
     3239  Bool bL = ( pbPattern[0] != pbPattern[(iStride-1)*iStride] );
     3240  Bool bT = ( pbPattern[0] != pbPattern[(iStride-1)]         );
     3241
     3242  if( bL == bT )
     3243  {
     3244    iDC1 = bL ? ( piMask[iTR] + piMask[iLB] )>>1 : 1<<( uiBitDepth - 1 );
     3245    iDC2 =      ( piMask[ -1] + piMask[-iMaskStride] )>>1;
     3246  }
     3247  else
     3248  {
     3249    iDC1 = bL ? piMask[iLB] : piMask[iTR];
     3250    iDC2 = bL ? piMask[iTM] : piMask[iLM];
     3251  }
     3252
     3253  riPredDC1 = pbPattern[0] ? iDC1 : iDC2;
     3254  riPredDC2 = pbPattern[0] ? iDC2 : iDC1;
     3255}
     3256#else
    24283257Void TComPrediction::getWedgePredDCs( TComWedgelet* pcWedgelet, Int* piMask, Int iMaskStride, Int& riPredDC1, Int& riPredDC2, Bool bAbove, Bool bLeft )
    24293258{
     
    25033332  }
    25043333}
     3334#endif
    25053335
    25063336Void TComPrediction::calcWedgeDCs( TComWedgelet* pcWedgelet, Pel* piOrig, UInt uiStride, Int& riDC1, Int& riDC2 )
     
    28703700  Int iMaskStride = ( iWidth<<1 ) + 1;
    28713701  piMask += iMaskStride+1;
     3702#if QC_DC_PREDICTOR_D0183
     3703  getPredDCs( pcWedgelet->getPattern(), pcWedgelet->getStride(), piMask, iMaskStride, iPredDC1, iPredDC2 );
     3704#else
    28723705  getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
     3706#endif
    28733707
    28743708  // assign wedge pred DCs to prediction
    2875   if( bDelta ) { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip ( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); }
    2876   else         { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride,        iPredDC1,                   iPredDC2           ); }
     3709  if( bDelta )
     3710  {
     3711#if HHI_DELTADC_DLT_D0035
     3712    assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, GetIdx2DepthValue( GetDepthValue2Idx(iPredDC1) + iDeltaDC1 ), GetIdx2DepthValue( GetDepthValue2Idx(iPredDC2) + iDeltaDC2 ) );
     3713#else
     3714    assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) );
     3715#endif
     3716  }
     3717  else
     3718  {
     3719    assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1, iPredDC2 );
     3720  }
    28773721}
    28783722
     
    28893733  Int iMaskStride = ( iWidth<<1 ) + 1;
    28903734  piMask += iMaskStride+1;
     3735#if QC_DC_PREDICTOR_D0183
     3736  getPredDCs( pcContourWedge->getPattern(), pcContourWedge->getStride(), piMask, iMaskStride, iPredDC1, iPredDC2 );
     3737#else
    28913738  getWedgePredDCs( pcContourWedge, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
     3739#endif
    28923740
    28933741  // assign wedge pred DCs to prediction
    2894   if( bDelta ) { assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride, Clip ( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); }
    2895   else         { assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride,        iPredDC1,                   iPredDC2           ); }
     3742  if( bDelta )
     3743  {
     3744#if HHI_DELTADC_DLT_D0035
     3745    assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride, GetIdx2DepthValue( GetDepthValue2Idx(iPredDC1) + iDeltaDC1 ), GetIdx2DepthValue( GetDepthValue2Idx(iPredDC2) + iDeltaDC2 ) );
     3746#else
     3747    assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) );
     3748#endif
     3749  }
     3750  else
     3751  {
     3752    assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride, iPredDC1, iPredDC2 );
     3753  }
    28963754
    28973755  pcContourWedge->destroy();
     
    30643922  Int iMaskStride = ( iWidth<<1 ) + 1;
    30653923  piMask += iMaskStride+1;
     3924#if QC_DC_PREDICTOR_D0183
     3925  getPredDCs( pcWedgelet->getPattern(), pcWedgelet->getStride(), piMask, iMaskStride, iPredDC1, iPredDC2 );
     3926#else
    30663927  getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
     3928#endif
    30673929
    30683930  // assign wedge pred DCs to prediction
    3069   if( bDelta ) { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); }
    3070   else         { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1,           iPredDC2           ); }
     3931  if( bDelta )
     3932  {
     3933#if HHI_DELTADC_DLT_D0035
     3934    assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, GetIdx2DepthValue( GetDepthValue2Idx(iPredDC1) + iDeltaDC1 ), GetIdx2DepthValue( GetDepthValue2Idx(iPredDC2) + iDeltaDC2 ) );
     3935#else
     3936    assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) );
     3937#endif
     3938  }
     3939  else
     3940  {
     3941    assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1, iPredDC2 );
     3942  }
    30713943}
    30723944
     
    30993971  Int iMaskStride = ( iWidth<<1 ) + 1;
    31003972  piMask += iMaskStride+1;
     3973#if QC_DC_PREDICTOR_D0183
     3974  getPredDCs( pcWedgelet->getPattern(), pcWedgelet->getStride(), piMask, iMaskStride, iPredDC1, iPredDC2 );
     3975#else
    31013976  getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
     3977#endif
    31023978
    31033979  // assign wedge pred DCs to prediction
    3104   if( bDelta ) { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); }
    3105   else         { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride,       iPredDC1,                   iPredDC2             ); }
     3980  if( bDelta )
     3981  {
     3982#if HHI_DELTADC_DLT_D0035
     3983    assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, GetIdx2DepthValue( GetDepthValue2Idx(iPredDC1) + iDeltaDC1 ), GetIdx2DepthValue( GetDepthValue2Idx(iPredDC2) + iDeltaDC2 ) );
     3984#else
     3985    assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) );
     3986#endif
     3987  }
     3988  else
     3989  {
     3990    assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1, iPredDC2 );
     3991  }
    31063992}
    31073993
  • trunk/source/Lib/TLibCommon/TComPrediction.h

    r332 r443  
    6969  TComYuv   m_acYuvPred[2];
    7070  TComYuv   m_cYuvPredTemp;
     71#if QC_ARP_D0177
     72  TComYuv   m_acYuvPredBase[2];
     73  TComYuv   m_acYuvDiff[2];
     74#endif
    7175  TComYuv m_filteredBlock[4][4];
    7276  TComYuv m_filteredBlockTmp[4];
     
    8084#if MERL_VSP_C0152
    8185  Int*   m_pDepth; ///< Local variable, to store a depth block, just to prevent allocate memory every time
     86
     87#if MERL_CVSP_D0165
     88  static Int m_iRangeLuma[12];
     89  static Int m_iRangeChroma[12];
     90#endif
    8291#endif
    8392
     
    8695 
    8796  // motion compensation functions
     97#if QC_ARP_D0177
     98  Void xPredInterUniARP       ( TComDataCU* pcCU,                          UInt uiPartAddr,               Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bi=false, TComMvField * pNewMvFiled = NULL );
     99#endif
    88100#if MERL_VSP_C0152
    89101  Void xPredInterUni            ( TComDataCU* pcCU,                          UInt uiPartAddr,       UInt uiAbsPartIdx,        Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX = 0, UInt uiSubSampExpY = 0, Bool bi=false );
     
    103115      );
    104116
     117#if !MERL_General_Fix
    105118#if MERL_VSP_C0152
    106119  Void xPredInterUniBWVSP         ( TComDataCU* pcCU,                          UInt uiPartAddr, UInt uiAbsPartIdx,               Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY, Bool bi=false );
    107120  Void xPredInterBiBWVSP          ( TComDataCU* pcCU,                          UInt uiPartAddr, UInt uiAbsPartIdx,               Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap );
    108121#endif
     122#endif
    109123
    110124#if DEPTH_MAP_GENERATION
     
    113127
    114128#if LGE_ILLUCOMP_B0045
    115   Void xPredInterLumaBlk  ( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag = false );
    116   Void xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag = false );
    117 #else
    118   Void xPredInterLumaBlk  ( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi );
    119   Void xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi );
    120 #endif
     129  Void xPredInterLumaBlk  ( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag = false
     130#if QC_ARP_D0177
     131    ,
     132    Int filterType = 0
     133#endif
     134    );
     135  Void xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag = false
     136#if QC_ARP_D0177
     137    ,
     138    Int filterType = 0
     139#endif
     140    );
     141#else
     142  Void xPredInterLumaBlk  ( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
     143#if QC_ARP_D0177
     144    ,
     145    Int filterType = 0
     146#endif
     147    );
     148  Void xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
     149#if QC_ARP_D0177
     150    ,
     151    Int filterType = 0
     152#endif
     153    );
     154#endif
     155
     156#if MERL_Bi_VSP_D0166
     157  Void xWeightedAverage         ( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst,  Int predDir);
     158#else
    121159  Void xWeightedAverage         ( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst );
    122 
    123 #if MERL_VSP_C0152
    124   Void xPredInterLumaBlkFromDM    ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv *mv, UInt partAddr,Int posX, Int posY, Int size_x, Int size_y, Bool isDepth, Int vspIdx
     160#endif
     161
     162#if MERL_VSP_C0152
     163#if !MERL_Bi_VSP_D0166
     164  Void xPredInterLumaBlkFromDM    ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv *mv, UInt partAddr,Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth, Int vspIdx
    125165                                  , TComYuv *&dstPic );
    126   Void xPredInterChromaBlkFromDM  ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv *mv, UInt partAddr,Int posX, Int posY, Int size_x, Int size_y, Bool isDepth, Int vspIdx
     166  Void xPredInterChromaBlkFromDM  ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv *mv, UInt partAddr,Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth, Int vspIdx
    127167                                  , TComYuv *&dstPic );
    128 #endif
     168#else
     169  TComPic*  xGetVspRefTxt(TComDataCU* pcCU, UInt uiPartAddr, RefPicList eRefPicList);
     170  Void xPredInterLumaBlkFromDM    ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv *mv, UInt partAddr,Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth,
     171    TComYuv *&dstPic, Bool bi);
     172  Void xPredInterChromaBlkFromDM  ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv *mv, UInt partAddr,Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth,
     173    TComYuv *&dstPic, Bool bi);
     174#endif
     175#endif
     176
    129177  Void xGetLLSPrediction ( TComPattern* pcPattern, Int* pSrc0, Int iSrcStride, Pel* pDst0, Int iDstStride, UInt uiWidth, UInt uiHeight, UInt uiExt0 );
    130178#if LGE_ILLUCOMP_B0045
     
    134182  Void xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight );
    135183  Bool xCheckIdenticalMotion    ( TComDataCU* pcCU, UInt PartAddr);
     184
     185#if MERL_General_Fix
     186#if MERL_VSP_C0152
     187  Void xPredInterVSPBlk(TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, TComMv cMv, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi
     188#if !MERL_Bi_VSP_D0166
     189                                     , Int vspIdx
     190#endif
     191    );
     192#endif
     193#endif
    136194
    137195#if HHI_DMM_WEDGE_INTRA
     
    169227#endif
    170228
    171 #if H3D_IVRP
     229#if H3D_IVRP & !QC_ARP_D0177
    172230  Void residualPrediction         (TComDataCU* pcCU, TComYuv* pcYuvPred, TComYuv* pcYuvResPred);
    173231#endif
     
    191249#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    192250  Void  predIntraLumaDMM        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder );
    193 
     251#if QC_DC_PREDICTOR_D0183
     252  Void  getPredDCs              ( Bool* pbPattern, Int iPatternStride, Int* piMask, Int iMaskStride, Int& riPredDC1, Int& riPredDC2 );
     253#else
    194254  Void  getWedgePredDCs         ( TComWedgelet* pcWedgelet, Int* piMask, Int iMaskStride, Int& riPredDC1, Int& riPredDC2, Bool bAbove, Bool bLeft );
     255#endif
    195256  Void  calcWedgeDCs            ( TComWedgelet* pcWedgelet, Pel* piOrig, UInt uiStride, Int& riDC1, Int& riDC2 );
    196257  Void  assignWedgeDCs2Pred     ( TComWedgelet* pcWedgelet, Pel* piPred,  UInt uiStride, Int   iDC1, Int   iDC2 );
  • trunk/source/Lib/TLibCommon/TComResidualGenerator.cpp

    r332 r443  
    4444
    4545
    46 #if H3D_IVRP
     46#if H3D_IVRP & !QC_ARP_D0177
    4747
    4848
     
    225225  }
    226226}
    227 
     227#endif
     228
     229#if !QC_ARP_D0177
    228230#if H3D_NBDV
    229231Bool
     
    249251}
    250252 
    251 #if H3D_NBDV
     253#if H3D_NBDV 
    252254Bool
    253255TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, TComMv iDisp, Bool bRecon) 
     
    263265  }
    264266  UInt uiXPosInRefView = uiXPos , uiYPosInRefView = uiYPos;
     267#if QC_ARP_D0177
     268  if(pcPic->getSPS()->getMultiviewResPredMode())
     269  {
     270#endif
    265271#if H3D_NBDV
    266272  xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv, iDisp, &uiXPosInRefView , &uiYPosInRefView , bRecon  );
     
    269275#endif
    270276  return true;
     277#if QC_ARP_D0177
     278  }
     279  else
     280    return true;
     281#endif
    271282}
    272283
     
    345356  UInt        uiCUAddr  = pcCU->getAddr();
    346357  pcSubCU->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
    347 
     358#if QC_CU_NBDV_D0181
     359  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
     360#endif
    348361  //--- set residual ---
    349362  switch( pcSubCU->getPredictionMode( 0 ) )
  • trunk/source/Lib/TLibCommon/TComResidualGenerator.h

    r332 r443  
    5050
    5151
    52 #if H3D_IVRP
     52#if H3D_IVRP & !QC_ARP_D0177
    5353
    5454class TComResidualGenerator
  • trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp

    r296 r443  
    6262TComSampleAdaptiveOffset::TComSampleAdaptiveOffset()
    6363{
     64#if !LGE_SAO_MIGRATION_D0091
    6465  m_pcPic = NULL;
     66#endif
    6567  m_iOffsetBo = NULL;
    6668  m_pClipTable = NULL;
     
    7173  m_iUpBufft = NULL;
    7274  ipSwap = NULL;
     75#if !LGE_SAO_MIGRATION_D0091
    7376  m_pcYuvTmp = NULL;
     77#endif
    7478
    7579  m_pTmpU1 = NULL;
     
    8589}
    8690
     91#if !LGE_SAO_MIGRATION_D0091
    8792const Int TComSampleAdaptiveOffset::m_aiNumPartsInRow[5] =
    8893{
     
    102107  256  //level 4
    103108};
     109#endif
    104110
    105111const Int TComSampleAdaptiveOffset::m_aiNumCulPartsLevel[5] =
     
    124130  0
    125131};
    126 
     132#if !LGE_SAO_MIGRATION_D0091
    127133const UInt TComSampleAdaptiveOffset::m_iWeightSao[MAX_NUM_SAO_TYPE] =
    128134{
     
    146152  6
    147153};
     154#endif
    148155
    149156Int TComSampleAdaptiveOffset::m_iNumClass[MAX_NUM_SAO_TYPE] =
     
    187194  return idx;
    188195}
     196#if !LGE_SAO_MIGRATION_D0091
    189197/** convert quadtree Idx to Level, Row, and Col
    190198 * \param  idx,  *level,  *row,  *col
     
    223231  }
    224232}
     233#endif
    225234/** create SampleAdaptiveOffset memory.
    226235 * \param
     
    317326  }
    318327
    319 
     328#if LGE_SAO_MIGRATION_D0091
     329  if (m_iUpBuff1)
     330  {
     331      m_iUpBuff1--;
     332      delete [] m_iUpBuff1; m_iUpBuff1 = NULL;
     333  }
     334  if (m_iUpBuff2)
     335  {
     336      m_iUpBuff2--;
     337      delete [] m_iUpBuff2; m_iUpBuff2 = NULL;
     338  }
     339  if (m_iUpBufft)
     340  {
     341      m_iUpBufft--;
     342      delete [] m_iUpBufft; m_iUpBufft = NULL;
     343  }
     344#else
    320345  m_iUpBuff1--;
    321346  m_iUpBuff2--;
     
    334359    delete [] m_iUpBufft; m_iUpBufft = NULL;
    335360  }
     361#endif
    336362  if (m_pTmpL1)
    337363  {
     
    368394  initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1,  0, m_iNumCuInHeight-1,1);
    369395  initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1,  0, m_iNumCuInHeight-1,2);
     396#if !LGE_SAO_MIGRATION_D0091
    370397  for(Int j=0;j<MAX_NUM_SAO_TYPE;j++)
    371398  {
    372399    pcSaoParam->iNumClass[j] = m_iNumClass[j];
    373400  }
     401#endif
    374402  pcSaoParam->numCuInWidth  = m_iNumCuInWidth;
    375403  pcSaoParam->numCuInHeight = m_iNumCuInHeight;
     
    405433  pSaoPart->iLength     =  0;
    406434
     435#if LGE_SAO_MIGRATION_D0091
     436  pSaoPart->subTypeIdx = 0;
     437#else
    407438  pSaoPart->bandPosition = 0;
     439#endif
    408440
    409441  for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
     
    514546  for(Int c=0; c<iNumComponet; c++)
    515547  {
     548#if LGE_SAO_MIGRATION_D0091
     549    if (c<2)
     550    {
    516551    pcSaoParam->bSaoFlag[c] = 0;
     552    }
     553#else
     554    pcSaoParam->bSaoFlag[c] = 0;
     555#endif
    517556    for(Int i=0; i< m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; i++)
    518557    {
     
    524563      pcSaoParam->psSaoPart[c][i].iMinDist      = MAX_INT;
    525564      pcSaoParam->psSaoPart[c][i].iMinRate      = MAX_INT;
     565#if LGE_SAO_MIGRATION_D0091
     566      pcSaoParam->psSaoPart[c][i].subTypeIdx    = 0;
     567#else
    526568      pcSaoParam->psSaoPart[c][i].bandPosition = 0;
     569#endif
    527570      for (Int j=0;j<MAX_NUM_SAO_OFFSETS;j++)
    528571      {
     
    557600  m_pcPic   = pcPic;
    558601  m_uiNumSlicesInPic = numSlicesInPic;
     602#if LGE_SAO_MIGRATION_D0091
     603  m_iSGDepth         = 0;
     604#else
    559605  m_iSGDepth         = pcPic->getSliceGranularityForNDBFilter();
     606#endif
    560607  m_bUseNIF = ( pcPic->getIndependentSliceBoundaryForNDBFilter() || pcPic->getIndependentTileBoundaryForNDBFilter() );
    561608  if(m_bUseNIF)
     
    9581005          uiEdgeType = iSignDown + m_iUpBuff1[x] + 2;
    9591006          m_iUpBuff1[x]= -iSignDown;
    960 
    9611007          pRec[x] = m_pClipTable[pRec[x] + m_iOffsetEo[uiEdgeType]];
    9621008        }
     
    10651111Void TComSampleAdaptiveOffset::SAOProcess(TComPic* pcPic, SAOParam* pcSaoParam)
    10661112{
     1113#if LGE_SAO_MIGRATION_D0091
     1114  if (pcSaoParam->bSaoFlag[0] || pcSaoParam->bSaoFlag[1])
     1115#else
    10671116  if (pcSaoParam->bSaoFlag[0])
     1117#endif
    10681118  {
    10691119#if FULL_NBIT
     
    10771127      m_pcPic->getPicYuvRec()->copyToPic(m_pcYuvTmp);
    10781128    }
    1079 
     1129#if LGE_SAO_MIGRATION_D0091
     1130    if (m_saoLcuBasedOptimization)
     1131#else
    10801132    if (m_saoInterleavingFlag)
     1133#endif
    10811134    {
    10821135      pcSaoParam->oneUnitFlag[0] = 0; 
     
    10851138    }
    10861139    Int iY  = 0;
     1140#if LGE_SAO_MIGRATION_D0091
     1141    if (pcSaoParam->bSaoFlag[0])
     1142    {
     1143        processSaoUnitAll( pcSaoParam->saoLcuParam[iY], pcSaoParam->oneUnitFlag[iY], iY);
     1144    }
     1145    if(pcSaoParam->bSaoFlag[1])
     1146    {
     1147        processSaoUnitAll( pcSaoParam->saoLcuParam[1], pcSaoParam->oneUnitFlag[1], 1);//Cb
     1148        processSaoUnitAll( pcSaoParam->saoLcuParam[2], pcSaoParam->oneUnitFlag[2], 2);//Cr
     1149    }
     1150#else
    10871151    processSaoUnitAll( pcSaoParam->saoLcuParam[iY], pcSaoParam->oneUnitFlag[iY], iY);
    10881152
     
    10971161      processSaoUnitAll( pcSaoParam->saoLcuParam[iCr], pcSaoParam->oneUnitFlag[iCr], iCr);
    10981162    }
    1099 
    1100 
     1163#endif
    11011164    m_pcPic = NULL;
    11021165  }
     
    11541217  Int  typeIdx;
    11551218
     1219#if LGE_SAO_MIGRATION_D0091
     1220  Int offset[LUMA_GROUP_NUM+1];
     1221#else
    11561222  static Int offset[LUMA_GROUP_NUM+1];
     1223#endif
    11571224  Int idxX;
    11581225  Int idxY;
     
    11641231  Int isChroma = (yCbCr == 0) ? 0:1;
    11651232  Bool mergeLeftFlag;
    1166 
    1167 
     1233#if LGE_SAO_MIGRATION_D0091
     1234  offset[0] = 0;
     1235#endif
    11681236  for (idxY = 0; idxY< frameHeightInCU; idxY++)
    11691237  {
     
    12011269    {
    12021270      addr = idxY * frameWidthInCU + idxX;
    1203 
    12041271      if (oneUnitFlag)
    12051272      {
     
    12251292            for (i=0; i<saoLcuParam[addr].length; i++)
    12261293            {
     1294#if LGE_SAO_MIGRATION_D0091
     1295              offset[ (saoLcuParam[addr].subTypeIdx +i)%SAO_MAX_BO_CLASSES  +1] = saoLcuParam[addr].offset[i] << m_uiSaoBitIncrease;
     1296#else
    12271297              offset[ (saoLcuParam[addr].bandPosition +i)%SAO_MAX_BO_CLASSES  +1] = saoLcuParam[addr].offset[i] << m_uiSaoBitIncrease;
     1298#endif
    12281299            }
    12291300
     
    13041375      saoLcuParam[i].offset[j] = 0;
    13051376    }
     1377#if LGE_SAO_MIGRATION_D0091
     1378    saoLcuParam[i].subTypeIdx   = 0;
     1379#else
    13061380    saoLcuParam[i].bandPosition = 0;
     1381#endif
    13071382  }
    13081383}
     
    13531428      saoLcuParam[addr].partIdxTmp = (Int)partIdx;
    13541429      saoLcuParam[addr].typeIdx    = saoQTPart[partIdx].iBestType;
     1430#if LGE_SAO_MIGRATION_D0091
     1431      saoLcuParam[addr].subTypeIdx   = saoQTPart[partIdx].subTypeIdx;
     1432#else
    13551433      saoLcuParam[addr].bandPosition = saoQTPart[partIdx].bandPosition;
     1434#endif
    13561435      if (saoLcuParam[addr].typeIdx!=-1)
    13571436      {
     
    13651444      {
    13661445        saoLcuParam[addr].length    = 0;
     1446#if LGE_SAO_MIGRATION_D0091
     1447        saoLcuParam[addr].subTypeIdx = saoQTPart[partIdx].subTypeIdx;
     1448#else
    13671449        saoLcuParam[addr].bandPosition = saoQTPart[partIdx].bandPosition;
     1450#endif
    13681451        for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
    13691452        {
     
    13751458}
    13761459
    1377 
    1378 
     1460#if LGE_SAO_MIGRATION_D0091
     1461Void TComSampleAdaptiveOffset::resetSaoUnit(SaoLcuParam* saoUnit)
     1462{
     1463  saoUnit->partIdx       = 0;
     1464  saoUnit->partIdxTmp    = 0;
     1465  saoUnit->mergeLeftFlag = 0;
     1466  saoUnit->mergeUpFlag   = 0;
     1467  saoUnit->typeIdx       = -1;
     1468  saoUnit->length        = 0;
     1469  saoUnit->subTypeIdx    = 0;
     1470
     1471  for (Int i=0;i<4;i++)
     1472  {
     1473    saoUnit->offset[i] = 0;
     1474  }
     1475}
     1476
     1477Void TComSampleAdaptiveOffset::copySaoUnit(SaoLcuParam* saoUnitDst, SaoLcuParam* saoUnitSrc )
     1478{
     1479  saoUnitDst->mergeLeftFlag = saoUnitSrc->mergeLeftFlag;
     1480  saoUnitDst->mergeUpFlag   = saoUnitSrc->mergeUpFlag;
     1481  saoUnitDst->typeIdx       = saoUnitSrc->typeIdx;
     1482  saoUnitDst->length        = saoUnitSrc->length;
     1483
     1484  saoUnitDst->subTypeIdx  = saoUnitSrc->subTypeIdx;
     1485  for (Int i=0;i<4;i++)
     1486  {
     1487    saoUnitDst->offset[i] = saoUnitSrc->offset[i];
     1488  }
     1489}
     1490
     1491/** PCM LF disable process.
     1492 * \param pcPic picture (TComPic) pointer
     1493 * \returns Void
     1494 *
     1495 * \note Replace filtered sample values of PCM mode blocks with the transmitted and reconstructed ones.
     1496 */
     1497Void TComSampleAdaptiveOffset::PCMLFDisableProcess (TComPic* pcPic)
     1498{
     1499  xPCMRestoration(pcPic);
     1500}
     1501
     1502/** Picture-level PCM restoration.
     1503 * \param pcPic picture (TComPic) pointer
     1504 * \returns Void
     1505 */
     1506Void TComSampleAdaptiveOffset::xPCMRestoration(TComPic* pcPic)
     1507{
     1508  Bool  bPCMFilter = (pcPic->getSlice(0)->getSPS()->getUsePCM() && pcPic->getSlice(0)->getSPS()->getPCMFilterDisableFlag())? true : false;
     1509#if LOSSLESS_CODING
     1510  if(bPCMFilter || pcPic->getSlice(0)->getSPS()->getUseLossless())
     1511#else
     1512  if(bPCMFilter)
     1513#endif
     1514  {
     1515      for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getNumCUsInFrame() ; uiCUAddr++ )
     1516      {
     1517          TComDataCU* pcCU = pcPic->getCU(uiCUAddr);
     1518          xPCMCURestoration(pcCU, 0, 0);
     1519      }
     1520  }
     1521}
     1522
     1523/** PCM CU restoration.
     1524 * \param pcCU pointer to current CU
     1525 * \param uiAbsPartIdx part index
     1526 * \param uiDepth CU depth
     1527 * \returns Void
     1528 */
     1529Void TComSampleAdaptiveOffset::xPCMCURestoration ( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth )
     1530{
     1531  TComPic* pcPic     = pcCU->getPic();
     1532  UInt uiCurNumParts = pcPic->getNumPartInCU() >> (uiDepth<<1);
     1533  UInt uiQNumParts   = uiCurNumParts>>2;
     1534
     1535  // go to sub-CU
     1536  if( pcCU->getDepth(uiAbsZorderIdx) > uiDepth )
     1537  {
     1538    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++, uiAbsZorderIdx+=uiQNumParts )
     1539    {
     1540      UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsZorderIdx] ];
     1541      UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsZorderIdx] ];
     1542      if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
     1543        xPCMCURestoration( pcCU, uiAbsZorderIdx, uiDepth+1 );
     1544    }
     1545    return;
     1546  }
     1547
     1548  // restore PCM samples
     1549  if ((pcCU->getIPCMFlag(uiAbsZorderIdx)&& pcPic->getSlice(0)->getSPS()->getPCMFilterDisableFlag()) || pcCU->isLosslessCoded( uiAbsZorderIdx))
     1550  {
     1551    xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, TEXT_LUMA    );
     1552    xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, TEXT_CHROMA_U);
     1553    xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, TEXT_CHROMA_V);
     1554  }
     1555}
     1556
     1557/** PCM sample restoration.
     1558 * \param pcCU pointer to current CU
     1559 * \param uiAbsPartIdx part index
     1560 * \param uiDepth CU depth
     1561 * \param ttText texture component type
     1562 * \returns Void
     1563 */
     1564Void TComSampleAdaptiveOffset::xPCMSampleRestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText)
     1565{
     1566  TComPicYuv* pcPicYuvRec = pcCU->getPic()->getPicYuvRec();
     1567  Pel* piSrc;
     1568  Pel* piPcm;
     1569  UInt uiStride;
     1570  UInt uiWidth;
     1571  UInt uiHeight;
     1572  UInt uiPcmLeftShiftBit;
     1573  UInt uiX, uiY;
     1574  UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
     1575  UInt uiLumaOffset   = uiMinCoeffSize*uiAbsZorderIdx;
     1576  UInt uiChromaOffset = uiLumaOffset>>2;
     1577
     1578  if( ttText == TEXT_LUMA )
     1579  {
     1580    piSrc = pcPicYuvRec->getLumaAddr( pcCU->getAddr(), uiAbsZorderIdx);
     1581    piPcm = pcCU->getPCMSampleY() + uiLumaOffset;
     1582    uiStride  = pcPicYuvRec->getStride();
     1583    uiWidth  = (g_uiMaxCUWidth >> uiDepth);
     1584    uiHeight = (g_uiMaxCUHeight >> uiDepth);
     1585    if ( pcCU->isLosslessCoded(uiAbsZorderIdx) )
     1586    {
     1587      uiPcmLeftShiftBit = 0;
     1588    }
     1589    else
     1590    {
     1591        uiPcmLeftShiftBit = g_uiBitDepth + g_uiBitIncrement - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
     1592    }
     1593  }
     1594  else
     1595  {
     1596    if( ttText == TEXT_CHROMA_U )
     1597    {
     1598      piSrc = pcPicYuvRec->getCbAddr( pcCU->getAddr(), uiAbsZorderIdx );
     1599      piPcm = pcCU->getPCMSampleCb() + uiChromaOffset;
     1600    }
     1601    else
     1602    {
     1603      piSrc = pcPicYuvRec->getCrAddr( pcCU->getAddr(), uiAbsZorderIdx );
     1604      piPcm = pcCU->getPCMSampleCr() + uiChromaOffset;
     1605    }
     1606
     1607    uiStride = pcPicYuvRec->getCStride();
     1608    uiWidth  = ((g_uiMaxCUWidth >> uiDepth)/2);
     1609    uiHeight = ((g_uiMaxCUWidth >> uiDepth)/2);
     1610    if ( pcCU->isLosslessCoded(uiAbsZorderIdx) )
     1611    {
     1612      uiPcmLeftShiftBit = 0;
     1613    }
     1614    else
     1615    {
     1616      uiPcmLeftShiftBit = g_uiBitDepth + g_uiBitIncrement - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
     1617    }
     1618  }
     1619
     1620  for( uiY = 0; uiY < uiHeight; uiY++ )
     1621  {
     1622    for( uiX = 0; uiX < uiWidth; uiX++ )
     1623    {
     1624      piSrc[uiX] = (piPcm[uiX] << uiPcmLeftShiftBit);
     1625    }
     1626    piPcm += uiWidth;
     1627    piSrc += uiStride;
     1628  }
     1629}
     1630#endif
    13791631//! \}
  • trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h

    r296 r443  
    6565
    6666  static UInt m_uiMaxDepth;
     67#if !LGE_SAO_MIGRATION_D0091
    6768  static const Int m_aiNumPartsInRow[5];
    6869  static const Int m_aiNumPartsLevel[5];
     70#endif
    6971  static const Int m_aiNumCulPartsLevel[5];
    7072  static const UInt m_auiEoTable[9];
     73#if !LGE_SAO_MIGRATION_D0091
    7174  static const UInt m_auiEoTable2D[9];
    7275  static const UInt m_iWeightSao[MAX_NUM_SAO_TYPE];
     76#endif
    7377  Int *m_iOffsetBo;
    7478  Int m_iOffsetEo[LUMA_GROUP_NUM];
     
    107111  Int* m_iLcuPartIdx;
    108112  Int     m_maxNumOffsetsPerPic;
     113#if LGE_SAO_MIGRATION_D0091
     114  Bool    m_saoLcuBoundary;
     115  Bool    m_saoLcuBasedOptimization;
     116
     117  Void xPCMRestoration        (TComPic* pcPic);
     118  Void xPCMCURestoration      (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth);
     119  Void xPCMSampleRestoration  (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText);
     120#else
    109121  Bool    m_saoInterleavingFlag;
     122#endif
    110123public:
    111124  TComSampleAdaptiveOffset         ();
     
    116129
    117130  Int  convertLevelRowCol2Idx(int level, int row, int col);
     131#if !LGE_SAO_MIGRATION_D0091
    118132  void convertIdx2LevelRowCol(int idx, int *level, int *row, int *col);
     133#endif
    119134
    120135  Void initSAOParam   (SAOParam *pcSaoParam, Int iPartLevel, Int iPartRow, Int iPartCol, Int iParentPartIdx, Int StartCUX, Int EndCUX, Int StartCUY, Int EndCUY, Int iYCbCr);
    121136  Void allocSaoParam  (SAOParam* pcSaoParam);
    122137  Void resetSAOParam  (SAOParam *pcSaoParam);
     138#if LGE_SAO_MIGRATION_D0091
     139  static Void freeSaoParam   (SAOParam *pcSaoParam);
     140#else
    123141  Void freeSaoParam   (SAOParam *pcSaoParam);
     142#endif
     143 
    124144
    125145  Void SAOProcess(TComPic* pcPic, SAOParam* pcSaoParam);
    126146  Void processSaoCu(Int iAddr, Int iSaoType, Int iYCbCr);
     147#if !LGE_SAO_MIGRATION_D0091
    127148  Void processSaoOnePart(SAOQTPart *psQTPart, UInt uiPartIdx, Int iYCbCr);
    128149  Void processSaoQuadTree(SAOQTPart *psQTPart, UInt uiPartIdx, Int iYCbCr);
     150#endif
    129151  Pel* getPicYuvAddr(TComPicYuv* pcPicYuv, Int iYCbCr,Int iAddr = 0);
    130152
     
    138160  Void convertOnePart2SaoUnit(SAOParam *saoParam, UInt partIdx, Int yCbCr);
    139161  Void processSaoUnitAll(SaoLcuParam* saoLcuParam, Bool oneUnitFlag, Int yCbCr);
     162#if LGE_SAO_MIGRATION_D0091
     163  Void setSaoLcuBoundary (Bool bVal)  {m_saoLcuBoundary = bVal;}
     164  Bool getSaoLcuBoundary ()           {return m_saoLcuBoundary;}
     165  Void setSaoLcuBasedOptimization (Bool bVal)  {m_saoLcuBasedOptimization = bVal;}
     166  Bool getSaoLcuBasedOptimization ()           {return m_saoLcuBasedOptimization;}
     167  Void resetSaoUnit(SaoLcuParam* saoUnit);
     168  Void copySaoUnit(SaoLcuParam* saoUnitDst, SaoLcuParam* saoUnitSrc );
     169  Void PCMLFDisableProcess    ( TComPic* pcPic);                        ///< interface function for ALF process
     170#else
    140171  Void setSaoInterleavingFlag (Bool bVal)  {m_saoInterleavingFlag = bVal;}
    141172  Bool getSaoInterleavingFlag ()           {return m_saoInterleavingFlag;}
     173#endif
    142174};
    143175
  • trunk/source/Lib/TLibCommon/TComSlice.cpp

    r332 r443  
    113113#if LGE_ILLUCOMP_B0045
    114114, m_bApplyIC                      ( false )
     115#if SHARP_ILLUCOMP_PARSE_D0060
     116, m_icSkipParseFlag               ( false )
     117#endif
    115118#endif
    116119#if INTER_VIEW_VECTOR_SCALING_C0115
     
    119122#endif
    120123{
     124#if MERL_VSP_NBDV_RefVId_Fix_D0166
     125  for(Int iNumCount = 0; iNumCount < MAX_VIEW_NUM; iNumCount++)
     126    m_pcListDepthPic[iNumCount] =NULL;
     127#endif
    121128  m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0;
    122129
     
    818825
    819826  m_saoEnabledFlag = pSrc->m_saoEnabledFlag;
     827#if LGE_SAO_MIGRATION_D0091
     828  m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma;
     829#else
    820830  m_saoInterleavingFlag = pSrc->m_saoInterleavingFlag;
    821831  m_saoEnabledFlagCb = pSrc->m_saoEnabledFlagCb;
    822832  m_saoEnabledFlagCr = pSrc->m_saoEnabledFlagCr;
     833#endif
    823834#if CABAC_INIT_FLAG
    824835  m_cabacInitFlag                = pSrc->m_cabacInitFlag;
     
    827838
    828839  m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero;
     840#if SHARP_ILLUCOMP_PARSE_D0060
     841  m_bApplyIC = pSrc->m_bApplyIC;
     842  m_icSkipParseFlag = pSrc->m_icSkipParseFlag;
     843#endif
    829844}
    830845
     
    13871402#endif
    13881403
     1404#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1405TComPic* TComSlice::getDepthRefPic(Int viewId, Int poc)
     1406{
     1407  TComPic* pPic = NULL;
     1408
     1409  if (m_pcListDepthPic[viewId] == NULL)
     1410    return NULL;
     1411
     1412  for( TComList<TComPic*>::iterator it = m_pcListDepthPic[viewId]->begin(); it != m_pcListDepthPic[viewId]->end(); it++ )
     1413  {
     1414    TComPic* currPic = *it;
     1415    TComSlice* currSlice = currPic->getCurrSlice();
     1416    Bool isDepth = currSlice->getIsDepth();
     1417    //assert(isDepth);
     1418    if( isDepth && currPic->getPOC() == poc && currPic->getViewId() == viewId ) // (*it)->getSPS()->isDepth()
     1419    {
     1420      pPic = *it;
     1421      break;
     1422    }
     1423  }
     1424
     1425  return pPic;
     1426}
     1427#endif
     1428
     1429
     1430#if QC_ARP_D0177
     1431Void TComSlice::setARPStepNum()                                 
     1432{
     1433  Bool bAllIvRef = false;
     1434  if(!getSPS()->getUseAdvRP())
     1435    m_nARPStepNum = 0;
     1436  else
     1437  {
     1438    for( Int iRefListId = 0; iRefListId < 2; iRefListId++ )
     1439    {
     1440      RefPicList  eRefPicList = RefPicList( iRefListId );
     1441      Int iNumRefIdx = getNumRefIdx(eRefPicList);
     1442      if( iNumRefIdx <= 0 )
     1443        continue;
     1444      for (Int i = 0; i < iNumRefIdx; i++)
     1445      {
     1446        if(getRefPic( REF_PIC_LIST_0, i)->getPOC() != getPOC())
     1447        {
     1448          bAllIvRef = true;
     1449          break;
     1450        }
     1451      }
     1452      if( bAllIvRef == true )
     1453        break;
     1454    }
     1455    if(bAllIvRef== true)
     1456      m_nARPStepNum = getSPS()->getARPStepNum();
     1457    else
     1458      m_nARPStepNum = 0;
     1459  }
     1460}
     1461#endif
    13891462// ------------------------------------------------------------------------------------------------
    13901463// Video parameter set (VPS)
     
    15761649  m_uiMultiviewMvPredMode    = 0;
    15771650#endif
    1578 
     1651#if QC_ARP_D0177
     1652  m_nUseAdvResPred           = 0;
     1653  m_nARPStepNum              = 1;
     1654#endif
    15791655  ::memset( m_aiUsableInterViewRefs, 0, sizeof( m_aiUsableInterViewRefs ) );
    15801656 
     
    20442120  m_scalingList = src.m_scalingList;
    20452121  m_scalingListEnabled = src.m_scalingListEnabled;
     2122#if !LGE_SAO_MIGRATION_D0091
    20462123  m_saoInterleavingFlag = src.m_saoInterleavingFlag;
     2124#endif
    20472125
    20482126  return *this;
  • trunk/source/Lib/TLibCommon/TComSlice.h

    r332 r443  
    5454class TComDepthMapGenerator;
    5555#endif
    56 #if H3D_IVRP
     56#if H3D_IVRP & !QC_ARP_D0177
    5757class TComResidualGenerator;
    5858#endif
     
    180180  Bool          m_bIVScalingFlag;
    181181#endif
     182
     183#if MTK_D0156
     184#if MERL_VSP_COMPENSATION_C0152
     185  Bool      m_abUseVSPCompensation[ MAX_TLAYER ];
     186#endif
     187  Bool      m_abUseDVPRefine[ MAX_TLAYER ];
     188#endif
     189
    182190public:
    183191  TComVPS();
     
    245253 
    246254#endif
     255
     256#if MTK_D0156
     257#if MERL_VSP_COMPENSATION_C0152
     258  Bool    getUseVSPCompensation( UInt tLayer ){  return m_abUseVSPCompensation[ tLayer ];}
     259  Void    setUseVSPCompensation( Bool bValue, UInt tLayer ){ m_abUseVSPCompensation[ tLayer ] = bValue;}
     260#endif
     261  Bool    getUseDVPRefine( UInt tLayer ){  return m_abUseDVPRefine[ tLayer ];}
     262  Void    setUseDVPRefine( Bool bValue, UInt tLayer ){ m_abUseDVPRefine[ tLayer ] = bValue;}
     263#endif
    247264};
    248265
     
    390407#endif
    391408#if H3D_IVRP
     409#if QC_ARP_D0177
     410  UInt         m_nUseAdvResPred;
     411  UInt         m_nARPStepNum;
     412#else
    392413  UInt  m_uiMultiviewResPredMode;
     414#endif
    393415#endif
    394416
     
    396418  TComDepthMapGenerator* m_pcDepthMapGenerator;
    397419#endif
    398 #if H3D_IVRP
     420#if H3D_IVRP & !QC_ARP_D0177
    399421  TComResidualGenerator* m_pcResidualGenerator;
     422#endif
     423
     424#if MTK_D0156
     425#if MERL_VSP_COMPENSATION_C0152
     426  Bool      m_bUseVSPCompensation;
     427#endif
     428  Bool      m_bUseDVPRefine;
    400429#endif
    401430
     
    643672  Void setPredDepthMapGeneration( UInt uiViewId, Bool bIsDepth, UInt uiPdmGenMode = 0, UInt uiPdmMvPredMode = 0, UInt uiPdmPrec = 0, Int** aaiPdmScaleNomDelta = 0, Int** aaiPdmOffset = 0 );
    644673#endif
    645 #if H3D_IVRP
     674#if H3D_IVRP & !QC_ARP_D0177
    646675  Void  setMultiviewResPredMode  ( UInt uiResPrdMode ) { m_uiMultiviewResPredMode = uiResPrdMode; }
    647676#endif
     
    658687#endif
    659688#if H3D_IVRP
     689#if QC_ARP_D0177
     690  UInt  getUseAdvRP()              { return m_nUseAdvResPred;   }
     691  Void  setUseAdvRP(UInt n)        { m_nUseAdvResPred = n;      }
     692  UInt  getARPStepNum()            { return m_nARPStepNum;      }
     693  Void  setARPStepNum(UInt n)      { m_nARPStepNum = n;         }
     694#else
    660695  UInt  getMultiviewResPredMode  ()          { return m_uiMultiviewResPredMode;   }
     696#endif
    661697#endif
    662698
     
    665701  TComDepthMapGenerator*  getDepthMapGenerator()                                              { return m_pcDepthMapGenerator; }
    666702#endif
    667 #if H3D_IVRP
     703#if H3D_IVRP & !QC_ARP_D0177
    668704  Void                    setResidualGenerator( TComResidualGenerator* pcResidualGenerator )  { m_pcResidualGenerator = pcResidualGenerator; }
    669705  TComResidualGenerator*  getResidualGenerator()                                              { return m_pcResidualGenerator; }
     706#endif
     707
     708#if MTK_D0156
     709
     710#if MERL_VSP_COMPENSATION_C0152
     711  Bool    getUseVSPCompensation( ){  return m_bUseVSPCompensation;}
     712  Void    setUseVSPCompensation( Bool bValue ){ m_bUseVSPCompensation = bValue;}
     713#endif
     714
     715  Bool    getUseDVPRefine( ){  return m_bUseDVPRefine;}
     716  Void    setUseDVPRefine( Bool bValue ){ m_bUseDVPRefine = bValue;}
     717
    670718#endif
    671719};
     
    928976  Bool      getScalingListEnabled ()          { return m_scalingListEnabled; }  //!< get ScalingList enabled/disabled in APS
    929977  TComScalingList* getScalingList ()          { return m_scalingList; }         //!< get ScalingList class pointer in APS
     978#if !LGE_SAO_MIGRATION_D0091
    930979  Bool     getSaoInterleavingFlag() {return m_saoInterleavingFlag;}             //!< get SAO interleaving flag in APS
    931980  Void     setSaoInterleavingFlag(Bool bVal) {m_saoInterleavingFlag = bVal;}    //!< set SAO interleaving flag in APS
     981#endif
    932982
    933983private:
     
    943993  Bool        m_scalingListEnabled;     //!< ScalingList enabled/disabled in APS (true for enabled)
    944994  TComScalingList*     m_scalingList;   //!< ScalingList class pointer
     995#if !LGE_SAO_MIGRATION_D0091
    945996  Bool        m_saoInterleavingFlag;    //!< SAO interleaving flag
     997#endif
    946998
    947999public:
     
    9751027  bool       m_alfEnabledFlag;
    9761028  bool       m_saoEnabledFlag;
     1029#if LGE_SAO_MIGRATION_D0091
     1030  bool       m_saoEnabledFlagChroma;      ///< SAO Cb&Cr enabled flag
     1031#else
    9771032  bool       m_saoInterleavingFlag;   ///< SAO interleaving flag
    9781033  bool       m_saoEnabledFlagCb;      ///< SAO Cb enabled flag
    9791034  bool       m_saoEnabledFlagCr;      ///< SAO Cr enabled flag
     1035#endif
    9801036  Int         m_iPPSId;               ///< picture parameter set ID
    9811037  Bool        m_PicOutputFlag;        ///< pic_output_flag
     
    11061162#if LGE_ILLUCOMP_B0045
    11071163  Bool        m_bApplyIC;
     1164#if SHARP_ILLUCOMP_PARSE_D0060
     1165  Bool        m_icSkipParseFlag;
     1166#endif
     1167#endif
     1168#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1169  TComList<TComPic*>*  m_pcListDepthPic[MAX_VIEW_NUM]; // For encoder, the list may also include texture pictures. Three views with ViewIdx = 0, 1, 2
     1170#endif
     1171#if QC_ARP_D0177
     1172  TComList<TComPic*> * m_pBaseViewRefPicList[MAX_VIEW_NUM];
     1173  UInt                 m_nARPStepNum;
    11081174#endif
    11091175#if INTER_VIEW_VECTOR_SCALING_C0115|QC_MVHEVC_B0046
     
    11151181  TComPic*     m_apcRefPicBaseTxt;
    11161182  TComPic*     m_apcRefPicBaseDepth;
     1183#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1184  Int*         m_aiShiftLUT[2]; // For reference views
     1185#else
    11171186  Int*         m_aiShiftLUT;
     1187#endif
    11181188  Int          m_iShiftPrec;
    11191189#endif
     
    11581228  Void      setSaoEnabledFlag(Bool s) {m_saoEnabledFlag =s; }
    11591229  Bool      getSaoEnabledFlag() { return m_saoEnabledFlag; }
     1230#if LGE_SAO_MIGRATION_D0091
     1231  Void      setSaoEnabledFlagChroma(Bool s) {m_saoEnabledFlagChroma =s; }       //!< set SAO Cb&Cr enabled flag
     1232  Bool      getSaoEnabledFlagChroma() { return m_saoEnabledFlagChroma; }        //!< get SAO Cb&Cr enabled flag
     1233#else
    11601234  Void      setSaoInterleavingFlag(Bool s) {m_saoInterleavingFlag =s; } //!< set SAO interleaving flag
    11611235  Bool      getSaoInterleavingFlag() { return m_saoInterleavingFlag;  } //!< get SAO interleaving flag
     
    11641238  Void      setSaoEnabledFlagCr(Bool s) {m_saoEnabledFlagCr =s; }       //!< set SAO Cr enabled flag
    11651239  Bool      getSaoEnabledFlagCr() { return m_saoEnabledFlagCr; }        //!< get SAO Cr enabled flag
     1240#endif
    11661241  Void      setRPS          ( TComReferencePictureSet *pcRPS ) { m_pcRPS = pcRPS; }
    11671242  TComReferencePictureSet*  getRPS          () { return m_pcRPS; }
     
    12531328  Void      setRefPicListMvc    ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& rapcInterViewRefPics );
    12541329  Void      setRefPOCnViewListsMvc();
    1255 
     1330#if QC_ARP_D0177
     1331  Void      setBaseViewRefPicList( TComList<TComPic*> *pListPic, Int iViewIdx )      { m_pBaseViewRefPicList[iViewIdx] = pListPic; }
     1332  TComPic*  getBaseViewRefPic    ( UInt uiPOC , Int iViewIdx )                       { return xGetRefPic( *m_pBaseViewRefPicList[iViewIdx], uiPOC ); }
     1333  Void      setARPStepNum();                                 
     1334  UInt      getARPStepNum( )                                      { return m_nARPStepNum;      } 
     1335#endif
    12561336  Void      setColDir           ( UInt uiDir ) { m_uiColDir = uiDir; }
    12571337#if COLLOCATED_REF_IDX
     
    14011481  Bool      getApplyIC            ()  { return m_bApplyIC; }
    14021482  Void      xSetApplyIC           ();
     1483#if SHARP_ILLUCOMP_PARSE_D0060
     1484  Void      setIcSkipParseFlag( Bool b ) { m_icSkipParseFlag = b; }
     1485  Bool      getIcSkipParseFlag() { return m_icSkipParseFlag; }
     1486#endif
    14031487#endif
    14041488#if QC_TMVP_MRG_REFIDX_C0047
     
    14181502  TComPic*     getRefPicBaseDepth        ()                        { return  m_apcRefPicBaseDepth; }
    14191503  Void         setRefPicBaseDepth        ( TComPic* RefPic)        { m_apcRefPicBaseDepth = RefPic; }
    1420 
     1504#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1505  Void setBWVSPLUTParam( Int *pShiftLUT, Int iLoG2LUTPrec, Int iNeighborViewId) { m_aiShiftLUT[iNeighborViewId] = pShiftLUT; m_iShiftPrec = iLoG2LUTPrec; }
     1506  Void getBWVSPLUTParam( Int*&pShiftLUT, Int&iLoG2LUTPrec, Int iNeighborViewId) { pShiftLUT = m_aiShiftLUT[iNeighborViewId]; iLoG2LUTPrec = m_iShiftPrec; }
     1507#else
    14211508  Void setBWVSPLUTParam( Int *pShiftLUT, Int iLoG2LUTPrec) { m_aiShiftLUT = pShiftLUT; m_iShiftPrec = iLoG2LUTPrec; }
    14221509  Void getBWVSPLUTParam( Int*&pShiftLUT, Int&iLoG2LUTPrec) { pShiftLUT = m_aiShiftLUT; iLoG2LUTPrec = m_iShiftPrec; }
     1510#endif
     1511#endif
     1512
     1513#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1514  Void setListDepthPic( TComList<TComPic*>* pListDepthPic, Int viewId) { m_pcListDepthPic[viewId] = pListDepthPic; }
     1515  TComList<TComPic*>* getListDepthPic(Int viewId) { return m_pcListDepthPic[viewId]; }
     1516  TComPic*            getDepthRefPic(Int viewId, Int poc);
     1517  TComPic*            getDepthRefPic(Int refIdx);
    14231518#endif
    14241519
  • trunk/source/Lib/TLibCommon/TComWedgelet.cpp

    r296 r443  
    783783  Int deltax = x1 - x0;
    784784  Int deltay = abs(y1 - y0);
     785#if FIX_WEDGE_NOFLOAT_D0036
     786  Int error = 0;
     787  Int deltaerr = (deltay<<1);
     788#else
    785789  double error = 0.0;
    786790  double deltaerr = (double)deltay / (double)deltax;
     791#endif
    787792
    788793  Int ystep;
     
    797802
    798803    error += deltaerr;
     804#if FIX_WEDGE_NOFLOAT_D0036
     805    if( error >= deltax )
     806#else
    799807    if( error >= 0.5)
     808#endif   
    800809    {
    801810      y += ystep;
     811#if FIX_WEDGE_NOFLOAT_D0036
     812      error = error - (deltax<<1);
     813#else
    802814      error = error - 1.0;
     815#endif   
    803816    }
    804817  }
  • trunk/source/Lib/TLibCommon/TComYuv.cpp

    r332 r443  
    741741  }
    742742}
     743#if QC_ARP_D0177
     744Void TComYuv::addARP(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip )
     745{
     746  addARPLuma   ( pcYuvSrc0, pcYuvSrc1, uiAbsPartIdx, uiWidth   , uiHeight    , bClip );
     747  addARPChroma ( pcYuvSrc0, pcYuvSrc1, uiAbsPartIdx, uiWidth>>1, uiHeight>>1 , bClip );
     748}
     749
     750Void TComYuv::addARPLuma(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip )
     751{
     752  Int x, y;
     753
     754  Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiAbsPartIdx );
     755  Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiAbsPartIdx );
     756  Pel* pDst  = getLumaAddr( uiAbsPartIdx );
     757
     758  UInt iSrc0Stride = pcYuvSrc0->getStride();
     759  UInt iSrc1Stride = pcYuvSrc1->getStride();
     760  UInt iDstStride  = getStride();
     761  for ( y = uiHeight-1; y >= 0; y-- )
     762  {
     763    for ( x = uiWidth-1; x >= 0; x-- )
     764    {
     765      pDst[x] = pSrc0[x] + pSrc1[x];
     766      if( bClip )
     767        pDst[x] = Clip( pDst[x] );
     768    }
     769    pSrc0 += iSrc0Stride;
     770    pSrc1 += iSrc1Stride;
     771    pDst  += iDstStride;
     772  }
     773}
     774
     775Void TComYuv::addARPChroma(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip )
     776{
     777  Int x, y;
     778
     779  Pel* pSrcU0 = pcYuvSrc0->getCbAddr( uiAbsPartIdx );
     780  Pel* pSrcU1 = pcYuvSrc1->getCbAddr( uiAbsPartIdx );
     781  Pel* pSrcV0 = pcYuvSrc0->getCrAddr( uiAbsPartIdx );
     782  Pel* pSrcV1 = pcYuvSrc1->getCrAddr( uiAbsPartIdx );
     783  Pel* pDstU = getCbAddr( uiAbsPartIdx );
     784  Pel* pDstV = getCrAddr( uiAbsPartIdx );
     785
     786  UInt  iSrc0Stride = pcYuvSrc0->getCStride();
     787  UInt  iSrc1Stride = pcYuvSrc1->getCStride();
     788  UInt  iDstStride  = getCStride();
     789  for ( y = uiHeight-1; y >= 0; y-- )
     790  {
     791    for ( x = uiWidth-1; x >= 0; x-- )
     792    {
     793      pDstU[x] = pSrcU0[x] + pSrcU1[x];
     794      pDstV[x] = pSrcV0[x] + pSrcV1[x];
     795      if( bClip )
     796      {
     797        pDstU[x] = Clip( pDstU[x] );
     798        pDstV[x] = Clip( pDstV[x] );
     799      }
     800    }
     801
     802    pSrcU0 += iSrc0Stride;
     803    pSrcU1 += iSrc1Stride;
     804    pSrcV0 += iSrc0Stride;
     805    pSrcV1 += iSrc1Stride;
     806    pDstU  += iDstStride;
     807    pDstV  += iDstStride;
     808  }
     809}
     810
     811Void TComYuv::subtractARP(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight)
     812{
     813  subtractARPLuma  ( pcYuvSrc0, pcYuvSrc1,  uiAbsPartIdx, uiWidth    , uiHeight    );
     814  subtractARPChroma( pcYuvSrc0, pcYuvSrc1,  uiAbsPartIdx, uiWidth>>1 , uiHeight>>1 );
     815}
     816
     817Void TComYuv::subtractARPLuma(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight)
     818{
     819  Int x, y;
     820
     821  Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiAbsPartIdx );
     822  Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiAbsPartIdx );
     823  Pel* pDst  = getLumaAddr( uiAbsPartIdx );
     824
     825  Int  iSrc0Stride = pcYuvSrc0->getStride();
     826  Int  iSrc1Stride = pcYuvSrc1->getStride();
     827  Int  iDstStride  = getStride();
     828  for ( y = uiHeight-1; y >= 0; y-- )
     829  {
     830    for ( x = uiWidth-1; x >= 0; x-- )
     831    {
     832      pDst[x] = pSrc0[x] - pSrc1[x];
     833    }
     834    pSrc0 += iSrc0Stride;
     835    pSrc1 += iSrc1Stride;
     836    pDst  += iDstStride;
     837  }
     838}
     839
     840Void TComYuv::subtractARPChroma(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight)
     841{
     842  Int x, y;
     843
     844  Pel* pSrcU0 = pcYuvSrc0->getCbAddr( uiAbsPartIdx );
     845  Pel* pSrcU1 = pcYuvSrc1->getCbAddr( uiAbsPartIdx );
     846  Pel* pSrcV0 = pcYuvSrc0->getCrAddr( uiAbsPartIdx );
     847  Pel* pSrcV1 = pcYuvSrc1->getCrAddr( uiAbsPartIdx );
     848  Pel* pDstU  = getCbAddr( uiAbsPartIdx );
     849  Pel* pDstV  = getCrAddr( uiAbsPartIdx );
     850
     851  Int  iSrc0Stride = pcYuvSrc0->getCStride();
     852  Int  iSrc1Stride = pcYuvSrc1->getCStride();
     853  Int  iDstStride  = getCStride();
     854  for ( y = uiHeight-1; y >= 0; y-- )
     855  {
     856    for ( x = uiWidth-1; x >= 0; x-- )
     857    {
     858      pDstU[x] = pSrcU0[x] - pSrcU1[x];
     859      pDstV[x] = pSrcV0[x] - pSrcV1[x];
     860    }
     861    pSrcU0 += iSrc0Stride;
     862    pSrcU1 += iSrc1Stride;
     863    pSrcV0 += iSrc0Stride;
     864    pSrcV1 += iSrc1Stride;
     865    pDstU  += iDstStride;
     866    pDstV  += iDstStride;
     867  }
     868}
     869
     870Void TComYuv::multiplyARP( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW )
     871{
     872  multiplyARPLuma( uiAbsPartIdx , uiWidth , uiHeight , dW );
     873  multiplyARPChroma( uiAbsPartIdx , uiWidth >> 1 , uiHeight >> 1 , dW );
     874}
     875
     876Void TComYuv::xxMultiplyLine( Pel * pSrcDst , UInt uiWidth , UChar dW )
     877{
     878  assert( dW == 2 );
     879  for( UInt x = 0 ; x < uiWidth ; x++ )
     880    pSrcDst[x] =  pSrcDst[x] >> 1;
     881}
     882
     883Void TComYuv::multiplyARPLuma( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW )
     884{
     885  Pel* pDst  = getLumaAddr( uiAbsPartIdx );
     886  Int  iDstStride  = getStride();
     887  for ( Int y = uiHeight-1; y >= 0; y-- )
     888  {
     889    xxMultiplyLine( pDst , uiWidth , dW );
     890    pDst  += iDstStride;
     891  }
     892}
     893
     894Void TComYuv::multiplyARPChroma( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW )
     895{
     896  Pel* pDstU  = getCbAddr( uiAbsPartIdx );
     897  Pel* pDstV  = getCrAddr( uiAbsPartIdx );
     898
     899  Int  iDstStride  = getCStride();
     900  for ( Int y = uiHeight-1; y >= 0; y-- )
     901  {
     902    xxMultiplyLine( pDstU , uiWidth , dW );
     903    xxMultiplyLine( pDstV , uiWidth , dW );
     904    pDstU  += iDstStride;
     905    pDstV  += iDstStride;
     906  }
     907}
     908#endif
    743909//! \}
  • trunk/source/Lib/TLibCommon/TComYuv.h

    r332 r443  
    199199
    200200  __inline Pel  xClip  (Pel x )      { return ( (x < 0) ? 0 : (x > (Pel)g_uiIBDI_MAX) ? (Pel)g_uiIBDI_MAX : x ); }
     201#if QC_ARP_D0177
     202  Void    addARP           ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip );
     203  Void    addARPLuma       ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip );
     204  Void    addARPChroma     ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip );
     205  Void    subtractARP      ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight );
     206  Void    subtractARPLuma  ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight );
     207  Void    subtractARPChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight );
     208  Void    multiplyARP      ( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW );
     209  Void    multiplyARPLuma  ( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW );
     210  Void    multiplyARPChroma( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW );
     211private:
     212  Void    xxMultiplyLine( Pel * pSrcDst , UInt uiWidth , UChar dW );
     213#endif
    201214};// END CLASS DEFINITION TComYuv
    202215
  • trunk/source/Lib/TLibCommon/TypeDef.h

    r332 r443  
    5959                                              // HHI_DMM_DELTADC_Q1_C0034   JCT3V-C0034: no quantization and fast encoder search for DMM delta DC values
    6060                                              // FIX_DMM_CTX_INIT_C0034 JCT3V-C0034 fix for wrong init type of DMM contexts (UChar instead of Short)
     61#define FIX_WEDGE_NOFLOAT_D0036           1   // JCT3V-D0036: Fix for aligning SW and spec (Wedgelet segmentation line generation without float)
    6162
    6263#define LGE_EDGE_INTRA_A0070              1   // JCT3V-A0070
    6364#define LGE_DMM3_SIMP_C0044               1
     65
     66#define QC_DC_PREDICTOR_D0183             1   // JCT3V-D0183: Simplified DC predictor for depth intra modes
    6467
    6568///// ***** SDC *********
     
    6770                                              // SAIT_SDC_C0096 JCT3V-C0096: Improved Simple Depth Coding(removal of DMM2 among four SDC modes(DC, Planar, DMM1 and DMM2))
    6871                                              // FIX_SDC_ENC_C0143, JCT3V-C0143 fix for unnecessary encoder checks in case of SDC
    69 
     72#if RWTH_SDC_DLT_B0036
     73#define HHI_DELTADC_DLT_D0035             1   // JCT3V-D0035: DLT for DMM deltaDC coding
     74#define INTEL_SDC64_D0193                 1   // JCT3V-D0193: SDC binary clean up (use a 1 bit binary code to signal sdc_pred_mode when CU size is 64x64)
     75#define RWTH_SDC_CTX_SIMPL_D0032          1   // JCT3V-D0032: CABAC Context Reduction for Simplified Depth Coding
     76#define LGE_CONCATENATE_D0141                 1 // JCT3V-D0141: concatenate binarization for residual index coding
     77#endif
     78#define FIX_SDC_ENC_RD_WVSO_D0163         1   // JCT3V-D0163: fix for SDC encoder rd-cost (VSO -> WVSO)
     79
     80#define PKU_QC_DEPTH_INTRA_UNI_D0195      1   // JCT3V-D0195: unified syntax table for depth intra coding tools
     81#define MTK_SAMPLE_BASED_SDC_D0110        1   // JCT3V-D0110: sample based SDC
    7082///// ***** TMVP/AMVP *********
    7183#define TMVP_DEPTH_SWITCH                 1   // JCT3V-B0092 additional encoder option only
     
    8496                                              // QC_C0051_FIXED_BY_MTK             1   // Bug fix for C0051 implementation
    8597                                              // QC_AMVP_MRG_UNIFY_IVCAN_C0051     1
     98#define SEC_TWO_CANDIDATES_FOR_AMVP_D0122 1   // SEC_TWO_CANDIDATES_FOR_AMVP_D0122, fixing # of AMVP candidates 3 to 2
    8699
    87100
     
    95108                                              // FIX_LG_RESTRICTEDRESPRED_M24766   1
    96109
     110#define QC_ARP_D0177            1             ////< advanced residual prediction
     111#if QC_ARP_D0177
     112#define QC_ARP_WFNR                       3
     113#define QC_ARP_WARNING_FIX                1   // Fix warning message for ARP
     114#endif
    97115///// ***** DISPARITY VECTOR DERIVATION *********
    98116#define H3D_NBDV                          1   // Neighboring block disparity derivation
     
    111129                                              // MTK_SIMPLIFY_DVTC_C0135           
    112130                                              // FIX_CHROMA_RESIDUAL_C0129         
     131#define QC_CU_NBDV_D0181                  1
     132
     133#define SEC_DEFAULT_DV_D0112              1
    113134
    114135///// ***** MOTION PARAMETER INHERITANCE  *********
     
    143164#endif
    144165
     166#define SHARP_ILLUCOMP_PARSE_D0060        1   // JCT3V-D0060 Removal of IC's parsing dependency
     167
    145168///// ***** INTERVIEW SKIP *********
    146169#define HHI_INTERVIEW_SKIP                1
     
    159182#define FIX_APPENCTOP_T_ONLY              1   // For Texture-only coding
    160183
     184#define LGE_ROUND_OFFSET_D0135            1   // JCT3V-D0135 Rounding offset
     185#define LGE_SAO_MIGRATION_D0091           1
     186#if LGE_SAO_MIGRATION_D0091
     187#define SAO_SKIP_RIGHT                   1  ///< H1101: disallow using unavailable pixel during RDO
     188#define SAO_ENCODING_CHOICE              1  ///< I0184: picture early termination
     189#if SAO_ENCODING_CHOICE
     190#define SAO_ENCODING_RATE                0.75
     191#define SAO_ENCODING_CHOICE_CHROMA       1 ///< J0044: picture early termination Luma and Chroma are handled separatenly
     192#if SAO_ENCODING_CHOICE_CHROMA
     193#define SAO_ENCODING_RATE_CHROMA         0.5
     194#define SAO_ENCODING_CHOICE_CHROMA_BF    1 ///  K0156: Bug fix for SAO selection consistency
     195#endif
     196#endif
     197#endif
     198
    161199///// ***** FCO  *********
    162200#define FLEX_CODING_ORDER_M23723          1
     
    174212
    175213///// ***** VSP *********
    176 #define MERL_VSP_C0152                    1 // JCT3V-C0152: 1: enable VSP-related tools; 0: disable VSP-related tools
    177                                             // LGE_SIMP_DVP_REFINE_C0112           
    178                                             // MERL_MTK_VSP_DVP_REFINE_C0152_C0131
     214#define MERL_VSP_C0152                       1 // JCT3V-C0152: 1: enable VSP-related tools; 0: disable VSP-related tools
     215                                               // LGE_SIMP_DVP_REFINE_C0112
     216                                               // MERL_MTK_VSP_DVP_REFINE_C0152_C0131
    179217#if MERL_VSP_C0152
    180 #define MERL_VSP_C0152_BugFix_ForNoDepthCase     1// MERL bugfix for test condition of no depth
    181 /*
    182  * Two macros are used to configure combinations of JCT3V-C0152 and JCT3V-C0131
    183  *
    184  *   a) (full) A full JCT3V-C0152 implementation, including JCT3V-C0131
    185  *      #define MERL_VSP_COMPENSATION_C0152          1
    186  *      #define MERL_MTK_VSP_DVP_REFINE_C0152_C0131  1
    187  *
    188  *   b) (mvp2off) For partial JCT3V-C0152 excluding overlaps from JCT3V-C0131
    189  *      #define MERL_VSP_COMPENSATION_C0152          1
    190  *      #define MERL_MTK_VSP_DVP_REFINE_C0152_C0131  0
    191  *
    192  *   c) (nocand) For JCT3V-C0131 only
    193  *      #define MERL_VSP_COMPENSATION_C0152          0
    194  *      #define MERL_MTK_VSP_DVP_REFINE_C0152_C0131  1
    195  */
    196 
    197 #define MERL_VSP_COMPENSATION_C0152          1 // JCT3V-C0152: 1: add VSP merge candidate to merging candidate list; 0: not to add   (nocand).
    198 
     218
     219
     220#define FIX_MERGE_D                          1 // Fix to compile merged version
     221
     222
     223#define MERL_General_Fix                     1// General fix by MERL
     224#define MERL_VSP_C0152_BugFix_ForNoDepthCase 1 // MERL bugfix for test condition of no depth
     225#define QC_BVSP_CleanUP_D0191                    1
     226
     227#define MTK_D0156                 1
     228#define LGE_VSP_INHERIT_D0092     1
     229
     230#define MERL_VSP_COMPENSATION_C0152          1 // JCT3V-C0152: 1: add VSP merge candidate to merging candidate list; 0: not to add (nocand).
    199231
    200232#define MERL_VSP_BLOCKSIZE_C0152             4 // JCT3V-C0152: VSP block size, supported values: 1, 2 and 4.
     233#if MERL_VSP_BLOCKSIZE_C0152 == 1
     234#define MERL_CVSP_D0165                      1 // JCT3V-D0165: 1: enable CVSP; 0: disable CVSP.
     235#else
     236#define MERL_CVSP_D0165                      0 // JCT3V-D0165: 1: enable CVSP; 0: disable CVSP.
     237#endif
     238#if LGE_VSP_INHERIT_D0092
     239#define VSP_MERGE_POS                        3 // JCT3V-C0152: fixed position of VSP candidate in merge list, supported values: 3.
     240#else
    201241#define VSP_MERGE_POS                        5 // JCT3V-C0152: fixed position of VSP candidate in merge list, supported values: 5.
    202                                                //MTK_DVPREFINE_BVSP_BUG_FIX               1
     242#endif                                               // MTK_DVPREFINE_BVSP_BUG_FIX               1
     243#define MTK_DEPTH_TO_DISP_D0138              1 // JCT3V-D0138: Use max among four corners for DoNBDV and BVSP
     244
     245#if MERL_General_Fix
     246#define MTK_LGE_VSP_DEPTH_OFF_D0105_D0139    1 // JCT3V-D0105/JCT3V-D0139: disable VSP for depth map
     247#define MTK_VSP_USING_NBDV_D0105             1 // JCT3V-D0105: use NBDV instead of DoNBDV for BVSP
     248#endif
     249
     250#if MERL_General_Fix
     251#define MERL_VSP_NBDV_RefVId_Fix_D0166       1 // JCT3V-D0166: 1: fix the NBDV with ref view selectioin; 0: always use base view with refViewIdx=0
     252#else
     253#define MERL_VSP_NBDV_RefVId_Fix_D0166       0
     254#endif
     255
     256#if MERL_VSP_NBDV_RefVId_Fix_D0166
     257#define MERL_Bi_VSP_D0166                    1 // JCT3V-D0166: 1: add supporting for Bi-VSP, the code under the macro can also handle uni-direction VSP
     258#else
     259#define MERL_Bi_VSP_D0166                    0
     260#endif
    203261
    204262#else // !MERL_VSP_C0152
    205263#define MERL_VSP_COMPENSATION_C0152          0 // JCT3V-C0152: 1: add VSP merge candidate to merging candidate list; 0: not to add
    206264#define MERL_VSP_BLOCKSIZE_C0152             4 // JCT3V-C0152: VSP block size, supported values: 1, 2 and 4.
    207 #endif
    208 
     265#define MERL_VSP_C0152_BugFix_ForNoDepthCase 0 // MERL bugfix for test condition of no depth
     266#define MERL_CVSP_D0165                      0 // JCT3V-D0165: 1: enable CVSP; 0: disable CVSP.
     267#define MERL_VSP_NBDV_RefVId_Fix_D0166       0 // JCT3V-D0166: 1: fix the NBDV with ref view selectioin; 0: always use base view with refViewIdx=0
     268#define MERL_Bi_VSP_D0166                    0 // JCT3V-D0166: 1: add supporting for Bi-VSP, the code under the macro can also handle uni-direction VSP
     269#define MTK_VSP_USING_NBDV_D0105             0
     270#define MERL_General_Fix                     0
     271#endif
     272
     273#if !MERL_General_Fix
     274#define MTK_LGE_VSP_DEPTH_OFF_D0105_D0139    1 // JCT3V-D0105/JCT3V-D0139: disable VSP for depth map
     275#define MTK_VSP_USING_NBDV_D0105             1 // JCT3V-D0105: use NBDV instead of DoNBDV for BVSP
     276#endif
    209277
    210278///// ***** DERIVED PARAMETERS *********
     
    342410#define C2FLAG_NUMBER               1 // maximum number of largerThan2 flag coded in one chunk:  16 in HM5
    343411
     412#if !LGE_SAO_MIGRATION_D0091
    344413#define REMOVE_SAO_LCU_ENC_CONSTRAINTS_1 0  ///< disable the encoder constraint that does not test SAO/BO mode for chroma in interleaved mode
    345414#define REMOVE_SAO_LCU_ENC_CONSTRAINTS_2 0  ///< disable the encoder constraint that reduce the range of SAO/EO for chroma in interleaved mode
     415#endif
    346416#define REMOVE_SAO_LCU_ENC_CONSTRAINTS_3 0  ///< disable the encoder constraint that conditionally disable SAO for chroma for entire slice in interleaved mode
    347417#define COLLOCATED_REF_IDX      1           ///< H0442: signal collocated reference index
     
    616686  Int         iBestType;
    617687  Int         iLength;
     688#if LGE_SAO_MIGRATION_D0091
     689  Int         subTypeIdx ;                 ///< indicates EO class or BO band position
     690#else
    618691  Int         bandPosition ;
     692#endif
    619693  Int         iOffset[4];
    620694  Int         StartCUX;
     
    646720  Bool       mergeLeftFlag;
    647721  Int        typeIdx;
     722#if LGE_SAO_MIGRATION_D0091
     723  Int        subTypeIdx;
     724#else
    648725  Int        bandPosition;
     726#endif
    649727  Int        offset[4];
     728#if !LGE_SAO_MIGRATION_D0091
    650729  Int        runDiff;
    651730  Int        run;
     731#endif
    652732  Int        partIdx;
    653733  Int        partIdxTmp;
  • trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp

    r332 r443  
    265265    xParseDblParam( aps );   
    266266  }
     267#if !LGE_SAO_MIGRATION_D0091
    267268  READ_FLAG(uiCode, "aps_sao_interleaving_flag");      aps->setSaoInterleavingFlag( (uiCode==1)?true:false );
    268269  if(!aps->getSaoInterleavingFlag())
     
    275276  }
    276277  }
     278#endif
    277279  READ_FLAG(uiCode, "aps_adaptive_loop_filter_flag");      aps->setAlfEnabled( (uiCode==1)?true:false );
    278280  if(aps->getAlfEnabled())
     
    307309  }
    308310}
     311#if !LGE_SAO_MIGRATION_D0091
    309312/** parse SAO parameters
    310313 * \param pSaoParam
     
    532535  }
    533536}
    534 
     537#endif
    535538
    536539Void TDecCavlc::xParseAlfParam(AlfParamSet* pAlfParamSet, Bool bSentInAPS, Int firstLCUAddr, Bool acrossSlice, Int numLCUInWidth, Int numLCUInHeight)
     
    14931496#endif
    14941497#if H3D_IVRP
    1495     pcSPS->setMultiviewResPredMode  ( 0 );
    1496 #endif
     1498#if QC_ARP_D0177
     1499     pcSPS->setUseAdvRP  ( 0 );
     1500     pcSPS->setARPStepNum( 1 );
     1501#else
     1502     pcSPS->setMultiviewResPredMode  ( 0 );
     1503#endif
     1504#endif
     1505
    14971506    }
    14981507    else
     
    15441553#endif
    15451554#if H3D_IVRP
     1555#if QC_ARP_D0177
     1556      pcSPS->setUseAdvRP  ( 0 );
     1557      pcSPS->setARPStepNum( 1 );
     1558#else
    15461559      pcSPS->setMultiviewResPredMode  ( 0 );
    15471560#endif
     1561#endif
     1562
    15481563      }
    15491564      else
     
    15731588        UInt uiMultiviewMvPredMode = 0;
    15741589#endif
    1575 #if H3D_IVRP
     1590#if H3D_IVRP & !QC_ARP_D0177
    15761591      UInt uiMultiviewResPredMode = 0;
    15771592#endif
     
    15881603          READ_UVLC( uiMultiviewMvPredMode, "multi_view_mv_pred_mode" );
    15891604#endif
    1590 #if H3D_IVRP
     1605#if H3D_IVRP & !QC_ARP_D0177
    15911606          READ_FLAG( uiMultiviewResPredMode, "multi_view_residual_pred_mode" );
    15921607#endif
     
    15991614#endif
    16001615#if H3D_IVRP
     1616#if QC_ARP_D0177
     1617      READ_FLAG( uiCode , "advanced_residual_pred_flag" );           pcSPS->setUseAdvRP( uiCode );
     1618      if( pcSPS->getUseAdvRP()  )
     1619          pcSPS->setARPStepNum( QC_ARP_WFNR );
     1620      else
     1621       pcSPS->setARPStepNum( 1 );
     1622#else
    16011623      pcSPS->setMultiviewResPredMode  ( uiMultiviewResPredMode );
    16021624#endif
    1603       }
     1625#endif
     1626
     1627      }
     1628
     1629#if MTK_D0156
     1630
     1631      pcSPS->setUseVSPCompensation( false );
     1632      pcSPS->setUseDVPRefine( false );
     1633
     1634      //Comments: Currently, BVSP and DoNBDV are not used for depth coding
     1635#if MERL_VSP_COMPENSATION_C0152
     1636      READ_FLAG( uiCode, "view_synthesis_pred_flag" );pcSPS->setUseVSPCompensation( uiCode ? true : false );
     1637#endif
     1638      READ_FLAG( uiCode, "dv_refine_flag" );          pcSPS->setUseDVPRefine( uiCode ? true : false );
     1639#endif
    16041640    }
    16051641    READ_FLAG( uiCode, "sps_extension2_flag");
     
    16651701    }
    16661702    rpcSlice->setApplyIC(uiCodeTmp);
     1703#if SHARP_ILLUCOMP_PARSE_D0060
     1704    if (rpcSlice->getApplyIC())
     1705    {
     1706      READ_FLAG (uiCodeTmp, "ic_skip_mergeidx0");
     1707      rpcSlice->setIcSkipParseFlag(uiCodeTmp);
     1708    }
     1709#endif
    16671710  }
    16681711#endif
     
    18471890      if (sps->getUseSAO())
    18481891      {
     1892#if LGE_SAO_MIGRATION_D0091
     1893        READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
     1894        READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
     1895#else
    18491896        READ_FLAG(uiCode, "slice_sao_interleaving_flag");        rpcSlice->setSaoInterleavingFlag(uiCode);
    18501897        READ_FLAG(uiCode, "slice_sample_adaptive_offset_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
     
    18591906          rpcSlice->setSaoEnabledFlagCr(0);
    18601907        }
     1908#endif
    18611909      }
    18621910      READ_UVLC (    uiCode, "aps_id" );  rpcSlice->setAPSId(uiCode);
     
    24242472}
    24252473#endif
    2426 
     2474#if QC_ARP_D0177
     2475Void TDecCavlc::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2476{
     2477  assert( false );
     2478}
     2479#endif
    24272480#if RWTH_SDC_DLT_B0036
     2481#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    24282482Void TDecCavlc::parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    24292483{
     
    24342488  assert(0);
    24352489}
     2490#endif
    24362491Void TDecCavlc::parseSDCResidualData     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart )
    24372492{
  • trunk/source/Lib/TLibDecoder/TDecCAVLC.h

    r332 r443  
    144144  Void parseResPredFlag     ( TComDataCU* pcCU, Bool& rbResPredFlag, UInt uiAbsPartIdx, UInt uiDepth );
    145145#endif
     146#if QC_ARP_D0177
     147  Void parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx,UInt uiDepth );
     148#endif
    146149  Void parseSplitFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    147150  Void parsePartSize        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     
    171174  Void parseDFSvlc         ( Int&  riVal,  const Char *pSymbolName  );
    172175#if RWTH_SDC_DLT_B0036
     176#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    173177  Void parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    174178  Void parseSDCPredMode    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     179#endif
    175180  Void parseSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart );
    176181#endif
    177182protected:
    178183  Void  xParseDblParam       ( TComAPS* aps );
     184#if !LGE_SAO_MIGRATION_D0091
    179185  Void  xParseSaoParam       ( SAOParam* pSaoParam );
    180186  Void  xParseSaoOffset      (SaoLcuParam* saoLcuParam);
    181187  Void  xParseSaoUnit        (Int rx, Int ry, Int compIdx, SAOParam* saoParam, Bool& repeatedRow );
     188#endif
    182189  Void  xParseAlfParam(AlfParamSet* pAlfParamSet, Bool bSentInAPS = true, Int firstLCUAddr = 0, Bool acrossSlice = true, Int numLCUInWidth= -1, Int numLCUInHeight= -1);
    183190  Void  parseAlfParamSet(AlfParamSet* pAlfParamSet, Int firstLCUAddr, Bool alfAcrossSlice);
  • trunk/source/Lib/TLibDecoder/TDecCu.cpp

    r332 r443  
    5454  m_ppcYuvResi = NULL;
    5555  m_ppcYuvReco = NULL;
    56 #if H3D_IVRP
     56#if H3D_IVRP & !QC_ARP_D0177
    5757  m_ppcYuvResPred = NULL;
    5858#endif
     
    8282  m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
    8383  m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
    84 #if H3D_IVRP
     84#if H3D_IVRP & !QC_ARP_D0177
    8585  m_ppcYuvResPred = new TComYuv*   [m_uiMaxDepth-1];
    8686#endif
     
    9696    m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight );
    9797    m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight );
    98 #if H3D_IVRP
     98#if H3D_IVRP & !QC_ARP_D0177
    9999    m_ppcYuvResPred[ui] = new TComYuv;    m_ppcYuvResPred[ui]->create( uiWidth, uiHeight );
    100100#endif
     
    120120    m_ppcYuvResi[ui]->destroy(); delete m_ppcYuvResi[ui]; m_ppcYuvResi[ui] = NULL;
    121121    m_ppcYuvReco[ui]->destroy(); delete m_ppcYuvReco[ui]; m_ppcYuvReco[ui] = NULL;
    122 #if H3D_IVRP
     122#if H3D_IVRP & !QC_ARP_D0177
    123123    m_ppcYuvResPred[ui]->destroy(); delete m_ppcYuvResPred[ui]; m_ppcYuvResPred[ui] = NULL;
    124124#endif
     
    128128  delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
    129129  delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
    130 #if H3D_IVRP
     130#if H3D_IVRP & !QC_ARP_D0177
    131131  delete [] m_ppcYuvResPred; m_ppcYuvResPred = NULL;
    132132#endif
     
    312312    pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
    313313  }
    314 
     314#if QC_CU_NBDV_D0181
     315      DisInfo DvInfo;
     316      DvInfo.bDV = false;
     317      if(!pcCU->getSlice()->isIntra())
     318      {
     319#if QC_ARP_D0177
     320        if(( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() || pcCU->getSlice()->getSPS()->getUseAdvRP())             && pcCU->getSlice()->getViewId())
     321#else
     322        if(( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() || pcCU->getSlice()->getSPS()->getMultiviewResPredMode()) && pcCU->getSlice()->getViewId())
     323#endif
     324        { 
     325          m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, true );
     326          m_ppcCU[uiDepth]->copyDVInfoFrom( pcCU, uiAbsPartIdx);
     327          PartSize ePartTemp = m_ppcCU[uiDepth]->getPartitionSize(0);
     328          UChar cWidTemp     = m_ppcCU[uiDepth]->getWidth(0);
     329          UChar cHeightTemp  = m_ppcCU[uiDepth]->getHeight(0);
     330          m_ppcCU[uiDepth]->setWidth  ( 0, pcCU->getSlice()->getSPS()->getMaxCUWidth ()/(1<<uiDepth)  );
     331          m_ppcCU[uiDepth]->setHeight ( 0, pcCU->getSlice()->getSPS()->getMaxCUHeight()/(1<<uiDepth)  );
     332          m_ppcCU[uiDepth]->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
     333  #if MERL_VSP_C0152
     334          DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(0, 0, &DvInfo, false, true);
     335  #else
     336          DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(0, 0, &DvInfo, false);
     337  #endif
     338          pcCU->setDvInfoSubParts(DvInfo, uiAbsPartIdx, uiDepth);
     339          m_ppcCU[uiDepth]->setPartSizeSubParts( ePartTemp, 0, uiDepth );
     340          m_ppcCU[uiDepth]->setWidth  ( 0, cWidTemp );
     341          m_ppcCU[uiDepth]->setHeight ( 0, cHeightTemp );
     342        }
     343        if(DvInfo.bDV==false)
     344        {
     345          DvInfo.iN=1;
     346#if !SEC_DEFAULT_DV_D0112
     347          DvInfo.m_acMvCand[0].setHor(0);
     348          DvInfo.m_acMvCand[0].setVer(0);
     349          DvInfo.m_aVIdxCan[0] = 0;
     350#endif
     351          pcCU->setDvInfoSubParts(DvInfo, uiAbsPartIdx, uiDepth);
     352        }
     353      }
     354#endif
    315355  // decode CU mode and the partition size
    316356  if( !pcCU->getSlice()->isIntra() && pcCU->getNumSucIPCM() == 0 )
     
    353393        const UChar uhNewDepth = max<UInt>( uiDepth, pcTextureCU->getDepth( uiAbsPartIdx + ui ) );
    354394#if MERL_VSP_C0152
    355         Int vspIdx = pcTextureCU->getVSPIndex( uiAbsPartIdx + ui);
    356         pcCU->setVSPIndex( uiAbsPartIdx + ui, vspIdx);
     395        Int vspIdx = pcTextureCU->getVSPIndex( uiAbsPartIdx + ui );
     396        pcCU->setVSPIndex( uiAbsPartIdx + ui, vspIdx );
     397#endif
     398#if MERL_VSP_NBDV_RefVId_Fix_D0166
     399        Int vspDir = pcTextureCU->getVSPDir( uiAbsPartIdx + ui );
     400        pcCU->setVSPDir( uiAbsPartIdx + ui, vspDir );
    357401#endif
    358402        pcCU->setPredictionMode( uiAbsPartIdx + ui, MODE_SKIP );
     
    371415    UInt uiMergeIndex = pcCU->getMergeIndex(uiAbsPartIdx);
    372416#if MERL_VSP_C0152
     417#if LGE_VSP_INHERIT_D0092
     418    Int iVSPIndexTrue[MRG_MAX_NUM_CANDS_MEM];
     419    for (Int i=0; i<MRG_MAX_NUM_CANDS_MEM; i++)
     420    {
     421        iVSPIndexTrue[i] = 0;
     422    }
     423#else
    373424    Int iVSPIndexTrue[3] = {-1, -1, -1};
     425#endif
     426#if MERL_VSP_NBDV_RefVId_Fix_D0166
     427    Int iVSPDirTrue[3]   = {-1, -1, -1};
     428    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue, iVSPDirTrue, uiMergeIndex );
     429#else
    374430    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue, uiMergeIndex );
     431#endif
     432#if MTK_D0156
     433    if( !pcCU->getSlice()->getSPS()->getUseVSPCompensation() )
     434    {
     435        pcCU->setVSPIndexSubParts( 0, uiAbsPartIdx, 0, uiDepth );
     436    }
     437    else
     438#endif
    375439    {
    376440      Int iVSPIdx = 0;
     441#if LGE_VSP_INHERIT_D0092
     442      if (iVSPIndexTrue[uiMergeIndex] == 1)
     443      {
     444          iVSPIdx = 1;
     445      }
     446#else
    377447      Int numVspIdx;
    378448      numVspIdx = 3;
     
    385455          }
    386456      }
    387       pcCU->setVSPIndexSubParts( iVSPIdx, uiAbsPartIdx, 0, uiDepth );  //Initialize the VSP, may change later in get InterMergeCandidates()
     457#endif
     458      pcCU->setVSPIndexSubParts( iVSPIdx, uiAbsPartIdx, 0, uiDepth );  // Initialize
     459#if MERL_VSP_NBDV_RefVId_Fix_D0166
     460      pcCU->setVSPDirSubParts( 0, uiAbsPartIdx, 0, uiDepth );
     461#endif
     462#if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
     463      if(iVSPIdx != 0)
     464      {
     465        Int iIVCIdx = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==pcCU->getSlice()->getPOC() ? 0: pcCU->getSlice()->getNewRefIdx(REF_PIC_LIST_0);
     466       cMvFieldNeighbours[ 2*uiMergeIndex].setRefIdx(iIVCIdx);
     467      }
     468#endif
    388469    }
    389470#else
     
    409490    }
    410491#endif
     492#if QC_ARP_D0177
     493    if( pcCU->getSlice()->getSPS()->getUseAdvRP() )
     494    {
     495      pcCU->setResPredAvailSubParts ( false, uiAbsPartIdx, 0, uiDepth );
     496      pcCU->setResPredFlagSubParts  ( false, uiAbsPartIdx, 0, uiDepth );
     497      m_pcEntropyDecoder->decodeARPW( pcCU , uiAbsPartIdx , uiDepth, m_ppcCU[uiDepth], 0 );
     498    }
     499#endif
    411500    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
    412501    return;
     
    460549  }
    461550#endif
    462 
     551#if QC_ARP_D0177
     552  if (pcCU->getSlice()->getSPS()->getUseAdvRP() && pcCU->isIntra( uiAbsPartIdx ) )
     553  {
     554    pcCU->setResPredAvailSubParts ( 0, uiAbsPartIdx, 0, uiDepth );
     555    pcCU->setResPredFlagSubParts  ( 0, uiAbsPartIdx, 0, uiDepth );
     556  }
     557#endif
    463558#if HHI_MPI
    464559    if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == uiDepth )
     
    476571        Int vspIdx = pcTextureCU->getVSPIndex( uiAbsPartIdx + ui);
    477572        pcCU->setVSPIndex( uiAbsPartIdx + ui, vspIdx);
     573#endif
     574#if MERL_VSP_NBDV_RefVId_Fix_D0166
     575        if (pcCU->getSlice()->getIsDepth()) {
     576          pcCU->setVSPDir( uiAbsPartIdx + ui, 0);
     577        }
     578        else {
     579          Int vspDir = pcTextureCU->getVSPDir( uiAbsPartIdx + ui);
     580          pcCU->setVSPDir( uiAbsPartIdx + ui, vspDir);
     581        }
    478582#endif
    479583        pcCU->setPredictionMode( uiAbsPartIdx + ui, MODE_INTER );
     
    670774  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
    671775#endif
    672 #if H3D_IVRP
     776#if H3D_IVRP & !QC_ARP_D0177
    673777  if (pcCU->getMergeFlag(0) && pcCU->getMergeIndex(0)==0 && pcCU->getResPredAvail(0))
    674778  {
     
    10321136  // reconstruct residual based on mask + DC residuals
    10331137  Pel apDCResiValues[2];
     1138#if !MERL_General_Fix
    10341139  Pel apDCRecoValues[2];
     1140#endif
    10351141  for( UInt ui = 0; ui < uiNumSegments; ui++ )
    10361142  {
     
    10391145    Pel   pRecoValue  = GetIdx2DepthValue( pPredIdx + pResiIdx );
    10401146   
     1147#if !MERL_General_Fix
    10411148    apDCRecoValues[ui]  = pRecoValue;
     1149#endif
    10421150    apDCResiValues[ui]  = pRecoValue - apDCPredValues[ui];
    10431151  }
     
    10561164      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
    10571165      assert( ucSegment < uiNumSegments );
     1166#if MTK_SAMPLE_BASED_SDC_D0110     
     1167      Pel pResiDC = apDCResiValues[ucSegment];
    10581168     
     1169      pReco    [ uiX ] = Clip( pPred[ uiX ] + pResiDC );
     1170#else
    10591171      Pel pPredVal= apDCPredValues[ucSegment];
    10601172      Pel pResiDC = apDCResiValues[ucSegment];
    10611173     
    10621174      pReco    [ uiX ] = Clip( pPredVal + pResiDC );
     1175#endif
    10631176      pRecIPred[ uiX ] = pReco[ uiX ];
    10641177    }
  • trunk/source/Lib/TLibDecoder/TDecCu.h

    r296 r443  
    6161  TComYuv**           m_ppcYuvResi;       ///< array of residual buffer
    6262  TComYuv**           m_ppcYuvReco;       ///< array of prediction & reconstruction buffer
    63 #if H3D_IVRP
     63#if H3D_IVRP & !QC_ARP_D0177
    6464  TComYuv**           m_ppcYuvResPred;    ///< residual prediction buffer
    6565#endif
  • trunk/source/Lib/TLibDecoder/TDecEntropy.cpp

    r332 r443  
    108108}
    109109
     110#if QC_ARP_D0177
     111Void TDecEntropy::decodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU, UInt uiPUIdx )
     112{
     113  if( pcCU->getSlice()->getViewId() == 0 || pcCU->getSlice()->getIsDepth() == true || !pcCU->getSlice()->getARPStepNum() )
     114    return;
     115  assert( !pcCU->isIntra( uiAbsPartIdx ) );
     116  Bool bResPredAvailable = !pcCU->getSlice()->getARPStepNum() ? false: ((pcCU->getPartitionSize(uiAbsPartIdx)==SIZE_2Nx2N || pcCU->isSkipped(uiAbsPartIdx)) ? true: false);
     117  if(!bResPredAvailable)
     118    pcCU->setARPWSubParts( 0 , uiAbsPartIdx, uiDepth ); 
     119  else
     120    m_pcEntropyDecoderIf->parseARPW( pcCU , uiAbsPartIdx , uiDepth );
     121}
     122#endif
    110123Void TDecEntropy::decodeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    111124{
     
    117130  m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth );
    118131 
     132#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    119133#if RWTH_SDC_DLT_B0036
    120134  // if B-Slice, code SDC flag later
     
    125139  }
    126140#endif
     141#endif
    127142}
    128143
    129144Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    130145{
     146#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    131147#if RWTH_SDC_DLT_B0036
    132148  if( !pcCU->getSlice()->isInterB() && pcCU->isIntra(uiAbsPartIdx) && pcCU->getSDCFlag(uiAbsPartIdx)  )
     
    137153  }
    138154#endif
     155#endif
    139156 
    140157  m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth );
    141158 
     159#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    142160#if RWTH_SDC_DLT_B0036
    143161  if( pcCU->getSlice()->isInterB() && pcCU->getSlice()->getSPS()->isDepth() && pcCU->isIntra(uiAbsPartIdx) )
     
    154172  }
    155173#endif
     174#endif
    156175}
    157176
    158177Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
    159178{
     179#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    160180#if RWTH_SDC_DLT_B0036
    161181  if( pcCU->getSDCFlag(uiAbsPartIdx) )
     
    164184    return;
    165185  }
     186#endif
    166187#endif
    167188 
     
    178199      decodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*2, uiDepth+1 );
    179200      decodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*3, uiDepth+1 );
     201#if PKU_QC_DEPTH_INTRA_UNI_D0195
     202      if(!pcCU->getSDCFlag(uiAbsPartIdx))
     203#endif
    180204      decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
    181205    }
     
    183207    {
    184208      decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
     209#if PKU_QC_DEPTH_INTRA_UNI_D0195
     210      if(!pcCU->getSDCFlag(uiAbsPartIdx))
     211#endif
    185212      decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
    186213    }
     
    189216  {
    190217    decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU );
     218#if QC_ARP_D0177
     219    if( pcCU->getSlice()->getSPS()->getUseAdvRP() )
     220    {
     221      decodeARPW( pcCU , uiAbsPartIdx , uiDepth, pcSubCU, 0  );
     222    }
     223#endif
    191224  }
    192225}
     
    301334      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
    302335#if MERL_VSP_C0152
     336#if LGE_VSP_INHERIT_D0092
     337      Int iVSPIndexTrue[MRG_MAX_NUM_CANDS_MEM];
     338      for (Int i=0; i<MRG_MAX_NUM_CANDS_MEM; i++)
     339      {
     340          iVSPIndexTrue[i] = 0;
     341      }
     342#else
    303343      Int iVSPIndexTrue[3] = {-1, -1, -1};
     344#endif
     345#if MERL_VSP_NBDV_RefVId_Fix_D0166
     346      Int iVSPDirTrue[3]   = {-1, -1, -1};
     347      pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue, iVSPDirTrue, uiMergeIndex );
     348#else
    304349      pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue, uiMergeIndex );
    305 
     350#endif
    306351#if HHI_MPI
    307352      if(pcCU->getTextureModeDepth( uiSubPartIdx ) == uiDepth)//MPI is used
     
    311356        for( UInt ui = 0; ui < uiCurrPartNumb; ui++ )
    312357        {
    313           Int vspIdx = pcTextureCU->getVSPIndex( uiAbsPartIdx + ui);
     358          Int vspIdx = pcTextureCU->getVSPIndex( uiAbsPartIdx + ui );
    314359          pcCU->setVSPIndex( uiAbsPartIdx + ui, vspIdx);
     360#if MERL_VSP_NBDV_RefVId_Fix_D0166
     361          Int vspDir = pcTextureCU->getVSPDir( uiAbsPartIdx + ui );
     362          pcCU->setVSPDir( uiAbsPartIdx + ui, vspDir);
     363#endif
    315364        }
    316365      }
    317366      else // MPI not used
    318367#endif
     368#if MTK_D0156
     369          if( !pcCU->getSlice()->getSPS()->getUseVSPCompensation() )
     370          {
     371              pcCU->setVSPIndexSubParts( 0, uiSubPartIdx, uiPartIdx, uiDepth );
     372          }
     373          else
     374#endif
    319375      {
    320376        Int iVSPIdx = 0;
     377#if LGE_VSP_INHERIT_D0092
     378        if (iVSPIndexTrue[uiMergeIndex] == 1)
     379        {
     380            iVSPIdx = 1;
     381        }
     382#else
    321383        Int numVspIdx;
    322384        numVspIdx = 3;
     
    329391            }
    330392        }
    331         pcCU->setVSPIndexSubParts( iVSPIdx, uiSubPartIdx, uiPartIdx, uiDepth );  //Initialize the VSP, may change later in get InterMergeCandidates()
     393#endif
     394        pcCU->setVSPIndexSubParts( iVSPIdx, uiSubPartIdx, uiPartIdx, uiDepth );               // Initialize
     395#if MERL_VSP_NBDV_RefVId_Fix_D0166
     396        pcCU->setVSPDirSubParts( 0, uiSubPartIdx, uiPartIdx, uiDepth );  // Initialize
     397#endif
     398#if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
     399       if(iVSPIdx != 0)
     400       {
     401         Int iIVCIdx = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==pcCU->getSlice()->getPOC() ? 0: pcCU->getSlice()->getNewRefIdx(REF_PIC_LIST_0);
     402         cMvFieldNeighbours[ 2*uiMergeIndex].setRefIdx(iIVCIdx);
     403       }
     404#endif
    332405      }
    333406
     
    479552  {
    480553#if H3D_IVMP
     554#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     555    const Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     556#else
    481557    const Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcSubCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     558#endif
    482559    m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx, iNumAMVPCands );
    483560#else
     
    789866    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
    790867    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
    791    
     868#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    792869    decodeSDCResidualData(pcCU, uiAbsPartIdx, uiDepth);
     870#endif
    793871    return;
    794872  }
     
    847925
    848926#if RWTH_SDC_DLT_B0036
     927#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    849928Void TDecEntropy::decodeSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    850929{
     
    861940  m_pcEntropyDecoderIf->parseSDCFlag(pcCU, uiAbsPartIdx, uiDepth );
    862941}
    863 
     942#endif
    864943Void TDecEntropy::decodeSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    865944{
  • trunk/source/Lib/TLibDecoder/TDecEntropy.h

    r332 r443  
    106106  virtual Void parseResPredFlag   ( TComDataCU* pcCU, Bool& rbResPredFlag, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
    107107#endif
     108#if QC_ARP_D0177
     109  virtual Void parseARPW         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
     110#endif
    108111  virtual Void parsePartSize      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
    109112  virtual Void parsePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
     
    137140 
    138141#if RWTH_SDC_DLT_B0036
     142#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    139143  virtual Void parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
    140144  virtual Void parseSDCPredMode     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
     145#endif
    141146  virtual Void parseSDCResidualData     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart ) = 0;
    142147#endif
     
    198203  Void decodeMergeFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx );
    199204  Void decodeMergeIndex        ( TComDataCU* pcSubCU, UInt uiPartIdx, UInt uiPartAddr, PartSize eCUMode, UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, UInt uiDepth );
     205#if QC_ARP_D0177
     206  Void decodeARPW              ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU, UInt uiPUIdx );
     207#endif
    200208  Void decodePredMode          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    201209  Void decodePartSize          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     
    225233  Void setSliceGranularity (Int iSliceGranularity) {m_pcEntropyDecoderIf->setSliceGranularity(iSliceGranularity);}
    226234
     235#if !LGE_SAO_MIGRATION_D0091
    227236  Void decodeSaoParam         (SAOParam* saoParam);
    228237  void decodeSaoLcu(Int rx, Int ry, Int compIdx, SAOParam* saoParam, Bool &repeatedRow );
    229238  Void decodeSaoOneLcu(SaoLcuParam* saoLcuParam);
     239#endif
    230240
    231241  Void decodeFlush() { m_pcEntropyDecoderIf->decodeFlush(); }
    232242 
    233243#if RWTH_SDC_DLT_B0036
     244#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    234245  Void decodeSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    235246  Void decodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     247#endif
    236248  Void decodeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    237249#endif
  • trunk/source/Lib/TLibDecoder/TDecGop.cpp

    r296 r443  
    9393                   ,TComDepthMapGenerator*  pcDepthMapGenerator
    9494#endif
    95 #if H3D_IVRP
     95#if H3D_IVRP & !QC_ARP_D0177
    9696                  ,TComResidualGenerator*  pcResidualGenerator
    9797#endif
     
    109109  m_pcDepthMapGenerator   = pcDepthMapGenerator;
    110110#endif
    111 #if H3D_IVRP
     111#if H3D_IVRP & !QC_ARP_D0177
    112112  m_pcResidualGenerator   = pcResidualGenerator;
    113113#endif
     
    298298      m_pcDepthMapGenerator->predictDepthMap  ( rpcPic );
    299299#endif
    300 #if H3D_IVRP
     300#if H3D_IVRP & !QC_ARP_D0177
    301301      m_pcResidualGenerator->initViewComponent( rpcPic );
    302302#endif
     
    331331  else
    332332  {
    333 #if H3D_IVRP
     333#if H3D_IVRP & !QC_ARP_D0177
    334334    // set residual picture
    335335    m_pcResidualGenerator->setRecResidualPic( rpcPic );
     
    372372    if( pcSlice->getSPS()->getUseSAO() )
    373373    {
     374#if LGE_SAO_MIGRATION_D0091
     375        if(pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma())
     376        {
     377            SAOParam *saoParam = pcSlice->getAPS()->getSaoParam();
     378            saoParam->bSaoFlag[0] = pcSlice->getSaoEnabledFlag();
     379            saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagChroma();
     380            m_pcSAO->setSaoLcuBasedOptimization(1);
     381            m_pcSAO->createPicSaoInfo(rpcPic, m_uiILSliceCount);
     382            m_pcSAO->SAOProcess(rpcPic, saoParam);
     383            m_pcSAO->PCMLFDisableProcess(rpcPic);
     384            m_pcSAO->destroyPicSaoInfo();
     385        }
     386#else
    374387      if(pcSlice->getSaoEnabledFlag())
    375388      {
     
    388401        m_pcSAO->destroyPicSaoInfo();
    389402      }
     403#endif
    390404    }
    391405
  • trunk/source/Lib/TLibDecoder/TDecGop.h

    r296 r443  
    9090  TComDepthMapGenerator*  m_pcDepthMapGenerator;
    9191#endif
    92 #if H3D_IVRP
     92#if H3D_IVRP & !QC_ARP_D0177
    9393  TComResidualGenerator*  m_pcResidualGenerator;
    9494#endif
     
    118118                 ,TComDepthMapGenerator*  pcDepthMapGenerator
    119119#endif
    120 #if H3D_IVRP
     120#if H3D_IVRP & !QC_ARP_D0177
    121121                ,TComResidualGenerator*  pcResidualGenerator
    122122#endif
  • trunk/source/Lib/TLibDecoder/TDecSbac.cpp

    r332 r443  
    3838#include "TDecSbac.h"
    3939
    40 #if RWTH_SDC_DLT_B0036
    41 #define GetNumDepthValues()     (pcCU->getSlice()->getSPS()->getNumDepthValues())
    42 #define GetBitsPerDepthValue()  (pcCU->getSlice()->getSPS()->getBitsPerDepthValue())
    43 #endif
    44 
    4540//! \ingroup TLibDecoder
    4641//! \{
     
    6459#if H3D_IVRP
    6560, 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)
    6664#endif
    6765, m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
     
    8886, m_cALFSvlcSCModel           ( 1,             1,               NUM_ALF_SVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    8987, 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)
     90, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     91#else
    9092, m_cSaoFlagSCModel           ( 1,             1,               NUM_SAO_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    9193, m_cSaoUvlcSCModel           ( 1,             1,               NUM_SAO_UVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
     
    9496, m_cSaoMergeUpSCModel        ( 1,             1,               NUM_SAO_MERGE_UP_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
    9597, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     98#endif
    9699#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     100#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    97101, m_cDmmFlagSCModel           ( 1,             1,               NUM_DMM_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    98102, m_cDmmModeSCModel           ( 1,             1,               NUM_DMM_MODE_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
     103#endif
    99104, m_cDmmDataSCModel           ( 1,             1,               NUM_DMM_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    100105#endif
     
    106111#endif
    107112#if RWTH_SDC_DLT_B0036
     113#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    108114, 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
    109124, m_cSDCResidualFlagSCModel     ( 1,             2,  SDC_NUM_RESIDUAL_FLAG_CTX  , m_contextModels + m_numContextModels, m_numContextModels)
    110125, m_cSDCResidualSignFlagSCModel ( 1,             2,  SDC_NUM_SIGN_FLAG_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
    111126, m_cSDCResidualSCModel         ( 1,             2,  SDC_NUM_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
    112127, m_cSDCPredModeSCModel             ( 1,             3,                 SDC_NUM_PRED_MODE_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
     128#endif
    113129#endif
    114130{
     
    161177#if H3D_IVRP
    162178  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 );
    163182#endif
    164183  m_cCUAlfCtrlFlagSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_ALF_CTRL_FLAG );
     
    184203  m_cALFUvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_ALF_UVLC );
    185204  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 );
     207  m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
     208#else
    186209  m_cSaoFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_SAO_FLAG );
    187210  m_cSaoUvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_SAO_UVLC );
     
    190213  m_cSaoMergeUpSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
    191214  m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
     215#endif
    192216
    193217  m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
     
    200224  m_uiLastDQpNonZero  = 0;
    201225#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     226#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    202227  m_cDmmFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMM_FLAG );
    203228  m_cDmmModeSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMM_MODE );
     229#endif
    204230  m_cDmmDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DMM_DATA );
    205231#endif
    206232#if RWTH_SDC_DLT_B0036
     233#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    207234  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
    208239  m_cSDCResidualFlagSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
    209240  m_cSDCResidualSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
     241#if !RWTH_SDC_CTX_SIMPL_D0032
    210242  m_cSDCResidualSignFlagSCModel.initBuffer  ( sliceType, qp, (UChar*)INIT_SDC_SIGN_FLAG );
     243#endif
    211244  m_cSDCPredModeSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_SDC_PRED_MODE );
    212245#endif
     
    248281#if H3D_IVRP
    249282  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 );
    250286#endif
    251287  m_cCUAlfCtrlFlagSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG );
     
    271307  m_cALFUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_UVLC );
    272308  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 );
     311  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
     312#else
    273313  m_cSaoFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG );
    274314  m_cSaoUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC );
     
    277317  m_cSaoMergeUpSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
    278318  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
     319#endif
    279320  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
    280321#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     322#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    281323  m_cDmmFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG );
    282324  m_cDmmModeSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_MODE );
     325#endif
    283326  m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
    284327#endif
    285328#if RWTH_SDC_DLT_B0036
     329#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    286330  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
    287335  m_cSDCResidualFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
    288336  m_cSDCResidualSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
     337#if !RWTH_SDC_CTX_SIMPL_D0032
    289338  m_cSDCResidualSignFlagSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG );
     339#endif
    290340  m_cSDCPredModeSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE );
    291341#endif
     
    869919  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
    870920}
    871  
     921#if PKU_QC_DEPTH_INTRA_UNI_D0195
     922Void 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)
     969      {
     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}
     1011Void 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 
     1029  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
    8721123Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    8731124{
    8741125  UInt uiSymbol;
    8751126  Int  intraPredMode;
    876 
     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
    8771135#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    8781136  UInt uiFlag = 0;
     
    9281186    }
    9291187#endif
    930 
     1188#endif
    9311189    Int uiPreds[3] = {-1, -1, -1};
    9321190    Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); 
     1191#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    9331192#if LGE_EDGE_INTRA_A0070
    9341193    UInt uiCheckBit = 0;
    9351194#endif
     1195#endif
    9361196
    9371197    m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
     
    9531213
    9541214      m_pcTDecBinIf->decodeBinsEP( uiSymbol, 5 );
     1215#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    9551216#if LGE_EDGE_INTRA_A0070
    9561217      if (bCodeEdgeIntra)
     
    9631224        }
    9641225      }
     1226#endif
    9651227#endif
    9661228      intraPredMode = uiSymbol;
     
    9791241        std::swap(uiPreds[1], uiPreds[2]);
    9801242      }
     1243#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    9811244#if LGE_EDGE_INTRA_A0070
    9821245      if ( intraPredMode != EDGE_INTRA_IDX)
    9831246      {
    9841247#endif
     1248#endif
    9851249        for ( Int i = 0; i < uiPredNum; i++ )
    9861250        {
    9871251          intraPredMode += ( intraPredMode >= uiPreds[i] );
    9881252        }
     1253#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    9891254#if LGE_EDGE_INTRA_A0070
    9901255      }
    9911256#endif
    992     }
    993 
     1257#endif
     1258    }
     1259
     1260#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    9941261#if LGE_EDGE_INTRA_A0070
    9951262    if( intraPredMode == EDGE_INTRA_IDX )
     
    10351302  }
    10361303#endif
    1037 
    10381304  pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, uiAbsPartIdx, uiDepth );
     1305#else
     1306  pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, uiAbsPartIdx, uiDepth );
     1307}
     1308#endif
    10391309}
    10401310
     
    16721942}
    16731943
    1674 
     1944#if LGE_SAO_MIGRATION_D0091
     1945Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
     1946{
     1947    if (maxSymbol == 0)
     1948    {
     1949        val = 0;
     1950        return;
     1951    }
     1952
     1953    UInt code;
     1954    Int  i;
     1955    m_pcTDecBinIf->decodeBinEP( code );
     1956    if ( code == 0 )
     1957    {
     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
     1980Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
     1981{
     1982    m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
     1983}
     1984
     1985Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
     1986{
     1987    UInt uiCode;
     1988    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
     1989    ruiVal = (Int)uiCode;
     1990}
     1991
     1992Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
     1993{
     1994    UInt uiCode;
     1995    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
     1996    if (uiCode == 0)
     1997    {
     1998        ruiVal = 0;
     1999    }
     2000    else
     2001    {
     2002        m_pcTDecBinIf->decodeBinEP( uiCode );
     2003        if (uiCode == 0)
     2004        {
     2005            ruiVal = 5;
     2006        }
     2007        else
     2008        {
     2009            ruiVal = 1;
     2010        }
     2011    }
     2012}
     2013
     2014inline 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
     2038Void 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
     2110Void 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
    16752190Void TDecSbac::parseSaoUvlc (UInt& ruiVal)
    16762191{
     
    19092424  }
    19102425}
    1911 
     2426#endif
    19122427/**
    19132428 - Initialize our contexts from the nominated source.
     
    22352750}
    22362751#endif
    2237 
     2752#if QC_ARP_D0177
     2753Void 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
    22382778#if LGE_EDGE_INTRA_A0070
    22392779Void TDecSbac::xParseEdgeIntraInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     
    23352875 
    23362876#if RWTH_SDC_DLT_B0036
     2877#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    23372878Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    23382879{
     
    23672908  {
    23682909    UInt uiIsMostProb = 0;
     2910#if INTEL_SDC64_D0193
     2911    if( !(pcCU->getWidth(uiAbsPartIdx) == 64 && i == 1))
     2912#endif
    23692913    m_pcTDecBinIf->decodeBin( uiIsMostProb, m_cSDCPredModeSCModel.get( 0, i, uiCtx ) );
    23702914   
     
    23852929  pcCU->setLumaIntraDirSubParts((UChar)intraPredMode, uiAbsPartIdx, uiDepth);
    23862930}
     2931#endif
    23872932
    23882933Void TDecSbac::parseSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSegment )
     
    23982943  Int  iIdx       = 0;
    23992944 
    2400   UInt uiMaxResidualBits  = GetBitsPerDepthValue();
     2945  UInt uiMaxResidualBits  = pcCU->getSlice()->getSPS()->getBitsPerDepthValue();
    24012946  assert( uiMaxResidualBits <= g_uiBitDepth );
    24022947 
     2948#if RWTH_SDC_CTX_SIMPL_D0032
     2949  m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
     2950#else
    24032951  m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, uiSegment, 0 ) );
     2952#endif
    24042953 
    24052954  if (uiResidual)
    24062955  {
    24072956    // decode residual sign bit
     2957#if RWTH_SDC_CTX_SIMPL_D0032
     2958    m_pcTDecBinIf->decodeBinEP(uiSign);
     2959#else
    24082960    m_pcTDecBinIf->decodeBin(uiSign, m_cSDCResidualSignFlagSCModel.get( 0, uiSegment, 0 ) );
     2961#endif
    24092962   
    24102963    // 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
    24112990    for (Int i=0; i<uiMaxResidualBits; i++)
    24122991    {
     2992#if RWTH_SDC_CTX_SIMPL_D0032
     2993      m_pcTDecBinIf->decodeBin(uiBit, m_cSDCResidualSCModel.get( 0, 0, i ) );
     2994#else
    24132995      m_pcTDecBinIf->decodeBin(uiBit, m_cSDCResidualSCModel.get( 0, uiSegment, i ) );
     2996#endif
    24142997      uiAbsIdx |= uiBit << i;
    24152998    }
     2999#endif
    24163000   
    24173001    uiAbsIdx += 1;
  • trunk/source/Lib/TLibDecoder/TDecSbac.h

    r332 r443  
    110110#endif
    111111 
     112#if LGE_SAO_MIGRATION_D0091
     113  Void  parseSaoMaxUvlc           ( UInt& val, UInt maxSymbol );
     114  Void  parseSaoMerge             ( UInt&  ruiVal   );
     115  Void  parseSaoTypeIdx           ( UInt&  ruiVal  );
     116  Void  parseSaoUflc              ( UInt uiLength, UInt& ruiVal     );
     117  Void  parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);
     118  Void  parseSaoOffset            (SaoLcuParam* psSaoLcuParam, UInt compIdx);
     119#else
    112120  Void  parseSaoUvlc              ( UInt& ruiVal           );
    113121  Void  parseSaoSvlc              ( Int&  riVal            );
     
    118126  Void  parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Bool bLFCrossSliceBoundaryFlag);
    119127  Void  parseSaoOffset            (SaoLcuParam* psSaoLcuParam);
     128#endif
    120129 
    121130#if RWTH_SDC_DLT_B0036
     131#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    122132  Void parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    123133  Void parseSDCPredMode    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     134#endif
    124135  Void parseSDCResidualData     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart );
    125136#endif
     
    176187  Void parseResPredFlag   ( TComDataCU* pcCU, Bool& rbResPredFlag, UInt uiAbsPartIdx, UInt uiDepth );
    177188#endif
     189#if QC_ARP_D0177
     190  Void parseARPW          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     191#endif
    178192  Void parsePartSize      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    179193  Void parsePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    180  
     194#if PKU_QC_DEPTH_INTRA_UNI_D0195
     195  Void parseDepthIntraMode  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     196  Void parseDepthModelingTable( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     197#endif
    181198  Void parseIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    182199 
     
    218235#if H3D_IVRP
    219236  ContextModel3DBuffer m_cResPredFlagSCModel;
     237#endif
     238#if QC_ARP_D0177
     239  ContextModel3DBuffer m_cCUPUARPW;
    220240#endif
    221241  ContextModel3DBuffer m_cCUPartSizeSCModel;
     
    245265  ContextModel3DBuffer m_cALFSvlcSCModel;
    246266  ContextModel3DBuffer m_cCUAMPSCModel;
     267#if LGE_SAO_MIGRATION_D0091
     268  ContextModel3DBuffer m_cSaoMergeSCModel;
     269  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
     270#else
    247271  ContextModel3DBuffer m_cSaoFlagSCModel;
    248272  ContextModel3DBuffer m_cSaoUvlcSCModel;
     
    251275  ContextModel3DBuffer m_cSaoMergeUpSCModel;
    252276  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
     277#endif
    253278
    254279#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     280#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    255281  ContextModel3DBuffer m_cDmmFlagSCModel;
    256282  ContextModel3DBuffer m_cDmmModeSCModel;
     283#endif
    257284  ContextModel3DBuffer m_cDmmDataSCModel;
    258285#endif
     
    265292 
    266293#if RWTH_SDC_DLT_B0036
     294#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    267295  ContextModel3DBuffer m_cSDCFlagSCModel;
     296#else
     297  ContextModel3DBuffer m_cDepthModeModel;
     298  ContextModel3DBuffer m_cDmmDeltaFlagModel;
     299#endif
    268300 
    269301  ContextModel3DBuffer m_cSDCResidualFlagSCModel;
     302#if !RWTH_SDC_CTX_SIMPL_D0032
    270303  ContextModel3DBuffer m_cSDCResidualSignFlagSCModel;
     304#endif
    271305  ContextModel3DBuffer m_cSDCResidualSCModel;
    272306 
  • trunk/source/Lib/TLibDecoder/TDecSlice.cpp

    r296 r443  
    286286    g_bJustDoIt = g_bEncDecTraceEnable;
    287287#endif
     288#if LGE_SAO_MIGRATION_D0091
     289    if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
     290    {
     291        SAOParam *saoParam =  pcSlice->getAPS()->getSaoParam();
     292        saoParam->bSaoFlag[0] = pcSlice->getSaoEnabledFlag();
     293    if (iCUAddr == iStartCUAddr)
     294    {
     295        saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagChroma();
     296    }
     297    Int numCuInWidth     = saoParam->numCuInWidth;
     298    Int cuAddrInSlice = iCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU());
     299    Int cuAddrUpInSlice  = cuAddrInSlice - numCuInWidth;
     300    Int rx = iCUAddr % numCuInWidth;
     301    Int ry = iCUAddr / numCuInWidth;
     302    Int allowMergeLeft = 1;
     303    Int allowMergeUp   = 1;
     304    if (rx!=0)
     305    {
     306        if (rpcPic->getPicSym()->getTileIdxMap(iCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr))
     307        {
     308            allowMergeLeft = 0;
     309        }
     310    }
     311    if (ry!=0)
     312    {
     313        if (rpcPic->getPicSym()->getTileIdxMap(iCUAddr-numCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr))
     314        {
     315        allowMergeUp = 0;
     316        }
     317    }
     318    pcSbacDecoder->parseSaoOneLcuInterleaving(rx, ry, saoParam,pcCU, cuAddrInSlice, cuAddrUpInSlice, allowMergeLeft, allowMergeUp);
     319    }
     320#else
    288321    if ( pcSlice->getSPS()->getUseSAO() && pcSlice->getSaoInterleavingFlag() && pcSlice->getSaoEnabledFlag() )
    289322    {
     
    301334      pcSbacDecoder->parseSaoOneLcuInterleaving(rx, ry, pcSlice->getAPS()->getSaoParam(),pcCU, cuAddrInSlice, cuAddrUpInSlice, pcSlice->getSPS()->getLFCrossSliceBoundaryFlag() );
    302335    }
     336#endif
    303337
    304338    m_pcCuDecoder->decodeCU     ( pcCU, uiIsLast );
  • trunk/source/Lib/TLibDecoder/TDecTop.cpp

    r332 r443  
    403403  m_cDepthMapGenerator.destroy();
    404404#endif
    405 #if H3D_IVRP
     405#if H3D_IVRP & !QC_ARP_D0177
    406406  m_cResidualGenerator.destroy();
    407407#endif
     
    420420                    , &m_cDepthMapGenerator
    421421#endif
    422 #if H3D_IVRP
     422#if H3D_IVRP & !QC_ARP_D0177
    423423                    , &m_cResidualGenerator
    424424#endif
     
    434434#endif
    435435#endif
    436 #if H3D_IVRP
     436#if H3D_IVRP & !QC_ARP_D0177
    437437  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
    438438#endif
     
    860860    }
    861861#endif
    862 #if H3D_IVRP
     862#if H3D_IVRP & !QC_ARP_D0177
    863863    m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
    864864#endif
     
    10831083    std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
    10841084    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics );
    1085 
     1085#if QC_ARP_D0177
     1086    //pcSlice->setBaseViewRefPicList( m_tAppDecTop->getTDecTop( 0 , false )->getListPic() );
     1087    pcSlice->setARPStepNum();
     1088    if(pcSlice->getARPStepNum() > 1)
     1089    {
     1090      for(Int iViewIdx = 0; iViewIdx < pcSlice->getViewId(); iViewIdx ++ )
     1091        pcSlice->setBaseViewRefPicList( m_tAppDecTop->getTDecTop( iViewIdx, false )->getListPic(), iViewIdx );
     1092    }
     1093#endif
    10861094    // For generalized B
    10871095    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
     
    12141222     pcSlice->setRefPicBaseDepth(pcBaseDepthPic);
    12151223  }
     1224#if !MERL_VSP_NBDV_RefVId_Fix_D0166
    12161225  getTAppDecTop()->setBWVSPLUT( pcSlice, pcSlice->getViewId(),  pcSlice->getPOC() ); // get the LUT for backward warping
     1226#else
     1227  if (pcSlice->getViewId() != 0)
     1228  {
     1229    Bool isDepth = true;
     1230    for(Int refviewId = 0; refviewId < (pcSlice->getViewId()); refviewId++)
     1231    {
     1232      if (m_tAppDecTop->getTDecTop( refviewId, isDepth ))
     1233      {
     1234        pcSlice->setListDepthPic(m_tAppDecTop->getTDecTop( refviewId, isDepth )->getListPic(), refviewId); // The list will store only the depth pictures
     1235      }
     1236      getTAppDecTop()->setBWVSPLUT( refviewId, pcSlice, pcSlice->getViewId(),  pcSlice->getPOC() ); // get the LUT for backward warping
     1237    }
     1238  }
     1239#endif
    12171240#endif
    12181241
  • trunk/source/Lib/TLibDecoder/TDecTop.h

    r296 r443  
    213213  TComDepthMapGenerator   m_cDepthMapGenerator;
    214214#endif
    215 #if H3D_IVRP
     215#if H3D_IVRP & !QC_ARP_D0177
    216216  TComResidualGenerator   m_cResidualGenerator;
    217217#endif
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r332 r443  
    711711        WRITE_UVLC( pcSPS->getMultiviewMvPredMode(), "multi_view_mv_pred_mode" );
    712712#endif
    713 #if H3D_IVRP
     713#if H3D_IVRP & !QC_ARP_D0177
    714714        WRITE_FLAG  ( pcSPS->getMultiviewResPredMode(), "multi_view_residual_pred_mode" );
    715715#endif
    716716      }
    717717#endif
    718     }
     718#if QC_ARP_D0177
     719      WRITE_FLAG( pcSPS->getUseAdvRP () ? 1 : 0,       "advanced_residual_pred_flag"  );
     720#endif
     721    }
     722
     723#if MTK_D0156
     724#if MERL_VSP_COMPENSATION_C0152
     725    WRITE_FLAG( pcSPS->getUseVSPCompensation() ? 1 : 0,              "view_synthesis_pred_flag" );
     726#endif
     727
     728    WRITE_FLAG( pcSPS->getUseDVPRefine() ? 1 : 0,                    "dv_refine_flag" );
     729#endif
    719730  }
    720731  else
     
    790801      WRITE_FLAG( pcSlice->getApplyIC() ? 1 : 0, "applying IC flag" );
    791802    }
     803#if SHARP_ILLUCOMP_PARSE_D0060
     804    if (pcSlice->getApplyIC())
     805    {
     806      WRITE_FLAG( pcSlice->getIcSkipParseFlag() ? 1 : 0, "ic_skip_mergeidx0" );
     807    }
     808#endif
    792809  }
    793810#endif
     
    957974      if (pcSlice->getSPS()->getUseSAO())
    958975      {
     976#if LGE_SAO_MIGRATION_D0091
     977        WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );
     978        {
     979            SAOParam *saoParam = pcSlice->getAPS()->getSaoParam();
     980            WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
     981        }
     982#else
    959983        WRITE_FLAG( pcSlice->getSaoInterleavingFlag(), "SAO interleaving flag" );
    960984         assert (pcSlice->getSaoEnabledFlag() == pcSlice->getAPS()->getSaoEnabled());
     
    965989           WRITE_FLAG( pcSlice->getAPS()->getSaoParam()->bSaoFlag[2], "SAO on/off flag for Cr in slice header" );
    966990         }
     991#endif
    967992      }
    968993      WRITE_UVLC( pcSlice->getAPS()->getAPSID(), "aps_id");
     
    13211346}
    13221347#endif
    1323 
     1348#if QC_ARP_D0177
     1349Void TEncCavlc::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1350{
     1351  assert( false );
     1352}
     1353#endif
    13241354Void TEncCavlc::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
    13251355
     
    14061436}
    14071437
    1408 Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1438Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx
     1439#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1440                                    , Bool bSdcRD
     1441#endif
     1442                                    )
    14091443{
    14101444  assert(0);
     
    14911525  }
    14921526}
    1493 
     1527#if !LGE_SAO_MIGRATION_D0091
    14941528Void TEncCavlc::codeSaoFlag( UInt uiCode )
    14951529{
     
    15291563  WRITE_CODE( uiCode, uiLength, "sao_run_diff");
    15301564}
     1565#endif
    15311566
    15321567Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, Int width, Int height, TextType eTType )
     
    18841919
    18851920#if RWTH_SDC_DLT_B0036
     1921#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    18861922Void TEncCavlc::codeSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    18871923{
    18881924  assert(0);
    18891925}
    1890 
     1926#endif
    18911927Void TEncCavlc::codeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment )
    18921928{
    18931929  assert(0);
    18941930}
    1895 
     1931#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    18961932Void TEncCavlc::codeSDCPredMode ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    18971933{
     
    18991935}
    19001936#endif
     1937#endif
    19011938//! \}
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r332 r443  
    142142  Void codeAPSAlflag(UInt uiCode);
    143143  Void codeAlfFixedLengthIdx( UInt idx, UInt numFilterSetsInBuffer);
     144#if LGE_SAO_MIGRATION_D0091
     145  Void codeSAOSign       ( UInt code   ) { printf("Not supported\n"); assert (0); }
     146  Void codeSaoMaxUvlc    ( UInt   code, UInt maxSymbol ){printf("Not supported\n"); assert (0);}
     147  Void codeSaoMerge  ( UInt uiCode ){printf("Not supported\n"); assert (0);}
     148  Void codeSaoTypeIdx    ( UInt uiCode ){printf("Not supported\n"); assert (0);}
     149  Void codeSaoUflc       ( UInt uiLength, UInt   uiCode ){ assert(uiCode < 32); printf("Not supported\n"); assert (0);}
     150#else
    144151  Void codeSaoFlag       ( UInt uiCode );
    145152  Void codeSaoUvlc       ( UInt uiCode );
     
    150157  Void codeSaoTypeIdx    ( UInt uiCode ){ xWriteUvlc(uiCode   );}
    151158  Void codeSaoUflc       ( UInt uiCode ){ assert(uiCode < 32); xWriteCode(uiCode, 5);}
     159#endif
    152160
    153161  Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     
    160168  Void codeResPredFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    161169#endif
     170#if QC_ARP_D0177
     171  virtual Void codeARPW ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     172#endif
    162173  Void codeAlfCtrlFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    163174
     
    183194  Void codeQtRootCbf     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    184195 
    185   Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx );
     196  Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx
     197#if PKU_QC_DEPTH_INTRA_UNI_D0195
     198    , Bool bSdcRD = false
     199#endif
     200    );
    186201 
    187202  Void codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx );
     
    209224 
    210225#if RWTH_SDC_DLT_B0036
     226#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    211227  Void codeSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     228#endif
    212229  Void codeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment );
     230#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    213231  Void codeSDCPredMode          ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    214232#endif
     233#endif
    215234
    216235};
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r332 r443  
    160160#endif
    161161  Int       m_maxNumOffsetsPerPic;
     162#if LGE_SAO_MIGRATION_D0091
     163  Bool      m_saoLcuBoundary;
     164  Bool      m_saoLcuBasedOptimization;
     165#else
    162166  Bool      m_saoInterleavingFlag;
     167#endif
    163168
    164169  //====== Lossless ========
     
    333338#endif
    334339#if H3D_IVRP
     340#if QC_ARP_D0177
     341  UInt      m_nUseAdvResPred;
     342  UInt      m_nARPStepNum;
     343#else
    335344  UInt        m_uiMultiviewResPredMode;
     345#endif
     346#endif
     347
     348#if MTK_D0156
     349#if MERL_VSP_COMPENSATION_C0152
     350  Bool      m_bUseVSPCompensation;
     351#endif
     352  Bool      m_bUseDVPRefine;
    336353#endif
    337354
     
    414431#endif
    415432#if H3D_IVRP
     433#if QC_ARP_D0177
     434  UInt       getUseAdvRP                    ()                  { return m_nUseAdvResPred; }
     435  Void       setUseAdvRP                    ( UInt  u )         { m_nUseAdvResPred = u;    }
     436  UInt       getARPStepNum                  ()                  { return m_nARPStepNum;    }
     437  Void       setARPStepNum                  ( UInt  u )         { m_nARPStepNum = u;       }
     438#else
    416439  Void      setMultiviewResPredMode         ( UInt  u )      { m_uiMultiviewResPredMode     = u; }
     440#endif
    417441#endif
    418442 
     
    661685  Void  setMaxNumOffsetsPerPic                   (Int iVal)            { m_maxNumOffsetsPerPic = iVal; }
    662686  Int   getMaxNumOffsetsPerPic                   ()                    { return m_maxNumOffsetsPerPic; }
     687#if LGE_SAO_MIGRATION_D0091
     688  Void  setSaoLcuBoundary              (Bool val)      { m_saoLcuBoundary = val; }
     689  Bool  getSaoLcuBoundary              ()              { return m_saoLcuBoundary; }
     690  Void  setSaoLcuBasedOptimization               (Bool val)            { m_saoLcuBasedOptimization = val; }
     691  Bool  getSaoLcuBasedOptimization               ()                    { return m_saoLcuBasedOptimization; }
     692#else
    663693  Void  setSaoInterleavingFlag                   (bool bVal)           { m_saoInterleavingFlag = bVal; }
    664694  Bool  getSaoInterleavingFlag                   ()                    { return m_saoInterleavingFlag; }
     695#endif
    665696  Void  setTileBehaviorControlPresentFlag        ( Int i )             { m_iTileBehaviorControlPresentFlag = i;    }
    666697  Int   getTileBehaviorControlPresentFlag        ()                    { return m_iTileBehaviorControlPresentFlag; }
     
    809840  Int       getViewOrderIdx                 ()      { return  m_iViewOrderIdx; }    // will be changed to view_id
    810841#endif
     842
     843#if MTK_D0156
     844
     845#if MERL_VSP_COMPENSATION_C0152
     846  Bool    getUseVSPCompensation( ){  return m_bUseVSPCompensation;}
     847  Void    setUseVSPCompensation( Bool bValue ){ m_bUseVSPCompensation = bValue;}
     848#endif
     849
     850
     851  Bool    getUseDVPRefine( ){  return m_bUseDVPRefine;}
     852  Void    setUseDVPRefine( Bool bValue ){ m_bUseDVPRefine = bValue;}
     853#endif
     854
    811855};
    812856
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r332 r443  
    6464  m_ppcBestCU      = new TComDataCU*[m_uhTotalDepth-1];
    6565  m_ppcTempCU      = new TComDataCU*[m_uhTotalDepth-1];
    66  
     66#if QC_ARP_D0177
     67  m_ppcWeightedTempCU = new TComDataCU*[m_uhTotalDepth-1];
     68#endif
    6769  m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1];
    6870  m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1];
     
    9193    m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
    9294    m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
    93    
     95#if QC_ARP_D0177
     96    m_ppcWeightedTempCU[i] = new TComDataCU; m_ppcWeightedTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
     97#endif   
    9498    m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight);
    9599    m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight);
     
    170174    {
    171175      m_ppcResPredTmp [i]->destroy(); delete m_ppcResPredTmp[i];  m_ppcResPredTmp[i] = NULL;
     176    }
     177#endif
     178#if QC_ARP_D0177
     179    if(m_ppcWeightedTempCU[i])
     180    {
     181      m_ppcWeightedTempCU[i]->destroy(); delete m_ppcWeightedTempCU[i]; m_ppcWeightedTempCU[i] = NULL;
    172182    }
    173183#endif
     
    591601      }
    592602#endif
    593 
     603#if QC_CU_NBDV_D0181
     604      DisInfo DvInfo;
     605      DvInfo.bDV = false;
     606      if( rpcTempCU->getSlice()->getSliceType() != I_SLICE )
     607      {
     608#if QC_ARP_D0177
     609        if(( rpcTempCU->getSlice()->getSPS()->getMultiviewMvPredMode() || rpcTempCU->getSlice()->getSPS()->getUseAdvRP()) && rpcTempCU->getSlice()->getViewId())
     610#else
     611        if(( rpcTempCU->getSlice()->getSPS()->getMultiviewMvPredMode() || rpcTempCU->getSlice()->getSPS()->getMultiviewResPredMode()) && rpcTempCU->getSlice()->getViewId())
     612#endif
     613        { 
     614          PartSize ePartTemp = rpcTempCU->getPartitionSize(0);
     615          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
     616#if MERL_VSP_C0152
     617          DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(0, 0, &DvInfo, false, true);
     618#else
     619          DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(0, 0, &DvInfo, false);
     620#endif
     621          rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     622          rpcBestCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     623          rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth );
     624        }
     625
     626        if(DvInfo.bDV==false)
     627        {
     628          DvInfo.iN=1;
     629#if !SEC_DEFAULT_DV_D0112
     630          DvInfo.m_acMvCand[0].setHor(0);
     631          DvInfo.m_acMvCand[0].setVer(0);
     632          DvInfo.m_aVIdxCan[0] = 0;
     633#endif
     634          rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     635          rpcBestCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     636         }
     637       }
     638#endif
    594639      // do inter modes, SKIP and 2Nx2N
    595640      if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
    596641      {
    597642#if H3D_IVRP
     643#if QC_ARP_D0177
     644        Bool  bResPredAvailable   = false;
     645        Bool  bResPredAllowed     =                    (!rpcBestCU->getSlice()->getSPS()->isDepth                () );
     646        bResPredAllowed           = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId              () );
     647        if( bResPredAllowed )
     648        {
     649          bResPredAvailable       = rpcBestCU->getResidualSamples( 0, true, m_ppcResPredTmp[uiDepth] );
     650        }
     651        for( UInt uiResPrdId = 0; uiResPrdId < (rpcBestCU->getSlice()->getSPS()->getUseAdvRP()? 1: ( bResPredAvailable ? 2 : 1 )); uiResPrdId++ )
     652#else
    598653        Bool  bResPredAvailable   = false;
    599654        UInt uiResPrdId = 0;
     655#endif
    600656        {
    601657          Bool bResPredFlag  = ( uiResPrdId > 0 );
     
    665721
    666722#if LGE_ILLUCOMP_B0045
     723#if SHARP_ILLUCOMP_PARSE_D0060
     724    bICEnabled = false;
     725#else
    667726    bICEnabled = rpcBestCU->getICFlag(0);
     727#endif
    668728#endif
    669729
     
    715775      {
    716776#if H3D_IVRP
     777#if QC_ARP_D0177
     778        Bool  bResPredAvailable   = false;
     779        Bool  bResPredAllowed     =                    (!rpcBestCU->getSlice()->getSPS()->isDepth                () );
     780        bResPredAllowed           = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId              () );
     781        if( bResPredAllowed )
     782        {
     783          bResPredAvailable       = rpcBestCU->getResidualSamples( 0, true, m_ppcResPredTmp[uiDepth] );
     784        }
     785        for( UInt uiResPrdId = 0; uiResPrdId < (rpcBestCU->getSlice()->getSPS()->getUseAdvRP()? 1: ( bResPredAvailable ? 2 : 1 )); uiResPrdId++ )
     786#else
    717787        Bool  bResPredAvailable   = false;
    718788        UInt uiResPrdId = 0;
     789#endif
    719790        {
    720791          Bool bResPredFlag  = ( uiResPrdId > 0 );
    721792#if LGE_ILLUCOMP_B0045
     793#if SHARP_ILLUCOMP_PARSE_D0060
     794          {
     795            Bool bICFlag = false;
     796            rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
     797#else
    722798          for(UInt uiICId = 0; uiICId < (bICEnabled ? 2 : 1); uiICId++)
    723799          {
    724800            Bool bICFlag = (uiICId ? true : false);
    725801            rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
     802#endif
    726803#endif
    727804#endif
     
    16481725  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    16491726  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
    1650  
     1727
    16511728  if( getCheckBurstIPCMFlag() )
    16521729  {
     
    17601837  {
    17611838    m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 );
     1839
    17621840#if LGE_ILLUCOMP_B0045
    17631841    m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx
     
    17671845        );
    17681846#endif
     1847#if QC_ARP_D0177
     1848    m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx, 0, uiDepth);
     1849#endif
    17691850    finishCU(pcCU,uiAbsPartIdx,uiDepth);
    17701851    return;
     
    17751856#endif
    17761857  m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx );
    1777  
     1858
    17781859  m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth );
    1779  
     1860
    17801861  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
    17811862  {
     
    17921873  // prediction Info ( Intra : direction mode, Inter : Mv, reference idx )
    17931874  m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
     1875
    17941876#if LGE_ILLUCOMP_B0045
    17951877    m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx
     
    18331915  Int numValidMergeCand = 0;
    18341916
     1917#if QC_ARP_D0177
     1918  Bool  bResPrdAvail  = rpcTempCU->getResPredAvail( 0 );
     1919  Bool  bResPrdFlag   = rpcTempCU->getResPredFlag ( 0 );
     1920#endif
    18351921#if LGE_ILLUCOMP_B0045
    18361922  Bool  bICFlag = rpcTempCU->getICFlag(0);
     
    18601946  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    18611947#if MERL_VSP_C0152
     1948#if LGE_VSP_INHERIT_D0092
     1949  Int iVSPIndexTrue[MRG_MAX_NUM_CANDS_MEM];
     1950  for (Int i=0; i<MRG_MAX_NUM_CANDS_MEM; i++)
     1951  {
     1952     iVSPIndexTrue[i] = 0;
     1953  }
     1954#else
    18621955  Int iVSPIndexTrue[3] = {-1, -1, -1};
     1956#endif
     1957#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1958  Int iVSPDirTrue[3]   = {-1, -1, -1};
     1959  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue, iVSPDirTrue );
     1960#else
    18631961  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue );
     1962#endif
    18641963#else
    18651964  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
    18661965#endif
    1867 #if H3D_IVRP
     1966#if H3D_IVRP & !QC_ARP_D0177
    18681967  Bool bResPredAvail = rpcTempCU->getResPredAvail(0);
    18691968#endif
    18701969
    18711970  Bool bestIsSkip = false;
    1872  
     1971#if QC_ARP_D0177
     1972  Int nGRPW = rpcTempCU->getSlice()->getARPStepNum() - 1;
     1973  if(nGRPW < 0 || !bResPrdAvail )
     1974    nGRPW = 0;
     1975  for( ; nGRPW >= 0 ; nGRPW-- )
     1976  {
     1977#endif 
    18731978  for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
    18741979  {
    18751980    {
    18761981      TComYuv* pcPredYuvTemp = NULL;
     1982#if SHARP_ILLUCOMP_PARSE_D0060
     1983      if (rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag())
     1984      {
     1985        if (bICFlag && uiMergeCand == 0)
     1986        {
     1987          continue;
     1988        }
     1989      }
     1990#endif
    18771991#if LOSSLESS_CODING
    18781992      UInt iteration;
     
    19042018          rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); // interprets depth relative to LCU level
    19052019          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
     2020#if QC_ARP_D0177
     2021          if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2022            rpcTempCU->setARPWSubParts( ( UChar )nGRPW , 0 , uhDepth );
     2023#endif
    19062024          rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level
    19072025          rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level
    19082026#if MERL_VSP_C0152
     2027
     2028#if MTK_D0156
     2029          if( !rpcTempCU->getSlice()->getSPS()->getUseVSPCompensation() )
     2030          {
     2031              rpcTempCU->setVSPIndexSubParts( 0, 0, 0, uhDepth );
     2032          }
     2033          else
     2034#endif
    19092035          {
    19102036            Int iVSPIdx = 0;
     2037#if LGE_VSP_INHERIT_D0092
     2038            if (iVSPIndexTrue[uiMergeCand] == 1)
     2039            {
     2040                iVSPIdx = 1;
     2041            }
     2042#else
    19112043            Int numVSPIdx;
    19122044            numVSPIdx = 3;
     
    19192051                }
    19202052            }
     2053#endif
    19212054            rpcTempCU->setVSPIndexSubParts( iVSPIdx, 0, 0, uhDepth );
     2055#if MERL_VSP_NBDV_RefVId_Fix_D0166
     2056            rpcTempCU->setVSPDirSubParts(0, 0, 0, uhDepth ); // interprets depth relative to LCU level
     2057#endif
     2058#if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
     2059           if(iVSPIdx != 0)
     2060           {
     2061             Int iIVCIdx = rpcTempCU->getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==rpcTempCU->getSlice()->getPOC() ? 0: rpcTempCU->getSlice()->getNewRefIdx(REF_PIC_LIST_0);
     2062             cMvFieldNeighbours[2*uiMergeCand].setRefIdx(iIVCIdx);
     2063           }
     2064#endif
    19222065          }
    19232066#endif
     
    19272070
    19282071#if H3D_IVRP
     2072#if !QC_ARP_D0177
    19292073          rpcTempCU->setResPredAvailSubParts(bResPredAvail, 0, 0, uhDepth);
     2074#else
     2075          rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth );
     2076          rpcTempCU->setResPredFlagSubParts ( bResPrdFlag,  0, 0, uhDepth );
     2077#endif 
    19302078#endif
    19312079#if LGE_ILLUCOMP_B0045
    19322080          rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uhDepth);
    19332081#endif
    1934 
     2082#if QC_ARP_D0177
     2083          if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2084          {
     2085            bool bSignalflag[2] = {true, true};
     2086            for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ )
     2087            {
     2088              Int iRefIdx = cMvFieldNeighbours[uiRefListIdx + 2*uiMergeCand].getRefIdx();
     2089              RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
     2090              if(iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx))
     2091                bSignalflag[uiRefListIdx] = false;
     2092            }
     2093            if(!bSignalflag[0]&& !bSignalflag[1])
     2094            {
     2095              rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth );
     2096            }
     2097          }
     2098#endif
    19352099          // do MC
    19362100#if HHI_INTERVIEW_SKIP
     
    19452109            m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
    19462110#endif
    1947 #if H3D_IVRP
     2111#if H3D_IVRP & !QC_ARP_D0177
    19482112            if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0))
    19492113            {
     
    19642128              m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
    19652129#endif
    1966 #if H3D_IVRP
     2130#if H3D_IVRP & !QC_ARP_D0177
    19672131              if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0))
    19682132              {
     
    20212185    }
    20222186  }
     2187#if QC_ARP_D0177
     2188  }
     2189#endif
    20232190}
    20242191
     
    20382205{
    20392206  UChar uhDepth = rpcTempCU->getDepth( 0 );
    2040  
     2207#if QC_ARP_D0177
     2208  Bool bFirstTime = true;
     2209  Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1;
     2210  if(nARPWMax < 0 || !rpcTempCU->getResPredAvail( 0 ) )
     2211    nARPWMax = 0;
     2212  if( ePartSize != SIZE_2Nx2N)
     2213    nARPWMax = 0;
     2214  Int nARPWStart = 0 , nARPWStep = 1;
     2215  for( Int nCount = 0 , nGRPW = nARPWStart ; nCount <= nARPWMax ; nCount++ , nGRPW += nARPWStep )
     2216  {
     2217    if( bFirstTime == false && rpcTempCU->getSlice()->getSPS()->getUseAdvRP() )
     2218      rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0) );
     2219#endif 
    20412220#if HHI_VSO
    20422221  if( m_pcRdCost->getUseRenModel() )
     
    20652244  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
    20662245
     2246#if QC_ARP_D0177
     2247  if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2248    rpcTempCU->setARPWSubParts( ( UChar )nGRPW , 0 , uhDepth );
     2249#endif
     2250#if QC_ARP_D0177
     2251  if( bFirstTime == false && rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2252  {
     2253    assert(!rpcTempCU->getSlice()->getSPS()->isDepth());
     2254    rpcTempCU->copyPartFrom( m_ppcWeightedTempCU[uhDepth] , 0 , uhDepth, true );
     2255    rpcTempCU->setARPWSubParts( ( UChar )nGRPW , 0 , uhDepth );
     2256#if MERL_VSP_C0152
     2257    m_pcPredSearch->motionCompensation( rpcTempCU , m_ppcPredYuvTemp[uhDepth], 0);
     2258#else
     2259    m_pcPredSearch->motionCompensation( rpcTempCU , m_ppcPredYuvTemp[uhDepth] );
     2260#endif
     2261    if(rpcTempCU->getPartitionSize(0)==SIZE_2Nx2N)
     2262    {
     2263      bool bSignalflag[2] = {true, true};
     2264      for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ )
     2265      {
     2266        RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
     2267        Int iRefIdx = rpcTempCU->getCUMvField(eRefList)->getRefIdx(0);
     2268        if(iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx))
     2269          bSignalflag[uiRefListIdx] = false;
     2270      }
     2271      if(!bSignalflag[0]&& !bSignalflag[1])
     2272        rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth );
     2273    }
     2274  }
     2275  else
     2276  {
     2277    bFirstTime = false;
     2278#endif
    20672279#if AMP_MRG
    20682280  rpcTempCU->setMergeAMP (true);
     
    20792291#endif
    20802292#endif
     2293#if QC_ARP_D0177
     2294   if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2295   {
     2296     m_ppcWeightedTempCU[uhDepth]->copyPartFrom( rpcTempCU , 0 , uhDepth );
     2297     if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP() && rpcTempCU->getPartitionSize(0)==SIZE_2Nx2N)
     2298     {
     2299       bool bSignalflag[2] = {true, true};
     2300       for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ )
     2301       {
     2302         RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
     2303         Int iRefIdx = rpcTempCU->getCUMvField(eRefList)->getRefIdx(0);
     2304         if(iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx))
     2305           bSignalflag[uiRefListIdx] = false;
     2306       }
     2307       if(!bSignalflag[0]&& !bSignalflag[1])
     2308         rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth );
     2309     }
     2310   }
     2311  }
     2312#endif
    20812313
    20822314#if AMP_MRG
    20832315  if ( !rpcTempCU->getMergeAMP() )
    20842316  {
     2317#if QC_ARP_D0177
     2318    if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2319      continue;
     2320    else
     2321#endif
    20852322    return;
    20862323  }
     
    21232360  xCheckDQP( rpcTempCU );
    21242361  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
     2362#if QC_ARP_D0177
     2363  }
     2364#endif
    21252365}
    21262366
     
    27582998      assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE );
    27592999#if MERL_VSP_C0152
    2760       Int vspIdx = pcTextureCU->getVSPIndex( rpcTempCU->getZorderIdxInCU() + ui);
     3000      Int vspIdx = pcTextureCU->getVSPIndex( rpcTempCU->getZorderIdxInCU() + ui );
    27613001      rpcTempCU->setVSPIndex( ui , vspIdx);
     3002#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3003      Int vspDir = pcTextureCU->getVSPDir  ( rpcTempCU->getZorderIdxInCU() + ui );
     3004      rpcTempCU->setVSPDir( ui, vspDir);
     3005#endif
    27623006#endif
    27633007    }
  • trunk/source/Lib/TLibEncoder/TEncCu.h

    r296 r443  
    6969  TComDataCU**            m_ppcBestCU;      ///< Best CUs in each depth
    7070  TComDataCU**            m_ppcTempCU;      ///< Temporary CUs in each depth
     71#if QC_ARP_D0177
     72  TComDataCU**            m_ppcWeightedTempCU;   
     73#endif
    7174  UChar                   m_uhTotalDepth;
    7275 
  • trunk/source/Lib/TLibEncoder/TEncEntropy.cpp

    r332 r443  
    5454  if (pcSlice->getSPS()->getUseSAO())
    5555  {
     56#if LGE_SAO_MIGRATION_D0091
     57    if (pcSlice->getSPS()->getUseSAO())
     58    {
     59        SAOParam *saoParam = pcSlice->getAPS()->getSaoParam();
     60        pcSlice->setSaoEnabledFlag     (saoParam->bSaoFlag[0]);
     61        {
     62            pcSlice->setSaoEnabledFlagChroma   (saoParam->bSaoFlag[1]);
     63        }
     64    }
     65#else
    5666    pcSlice->setSaoInterleavingFlag(pcSlice->getAPS()->getSaoInterleavingFlag());
    5767    pcSlice->setSaoEnabledFlag     (pcSlice->getAPS()->getSaoParam()->bSaoFlag[0]);
     
    6676      pcSlice->setSaoEnabledFlagCr   (0);
    6777    }
     78#endif
    6879  }
    6980
     
    456467
    457468
     469#if QC_ARP_D0177
     470Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD, UInt uiDepth)
     471{
     472  if( pcCU->getSlice()->getViewId() == 0 || pcCU->getSlice()->getIsDepth() == true || !pcCU->getSlice()->getARPStepNum() )
     473  {
     474    return;
     475  }
     476  assert( pcCU->isIntra( uiAbsPartIdx ) == false );
     477  if( bRD )
     478  {
     479    uiAbsPartIdx = 0;
     480  }
     481  bool bSignalflag[2] = {true, true};
     482  if (!(pcCU->getPartitionSize(uiAbsPartIdx)==SIZE_2Nx2N || pcCU->isSkipped(uiAbsPartIdx)))
     483  {
     484    assert(pcCU->getARPW (uiAbsPartIdx) == 0);
     485    bSignalflag[0] = false;
     486    bSignalflag[1] = false;
     487 }
     488  if (!(bSignalflag[0]|| bSignalflag[1]))
     489  {
     490    assert(pcCU->getARPW (uiAbsPartIdx) == 0);
     491    if (uiDepth != -1)
     492      pcCU->setARPWSubParts(0, uiAbsPartIdx, uiDepth);
     493  }
     494  else
     495     m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx );
     496 
     497}
     498#endif
    458499/** parse the fixed length code (smaller than one max value) in ALF
    459500 * \param run: coded value
     
    828869  m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
    829870 
     871#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    830872#if RWTH_SDC_DLT_B0036
    831873  // if B-Slice, code SDC flag later
     
    835877    encodeSDCFlag(pcCU, uiAbsPartIdx, bRD);
    836878  }
     879#endif
    837880#endif
    838881}
     
    876919    }
    877920  }
     921#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    878922#if RWTH_SDC_DLT_B0036
    879923  if( !pcCU->getSlice()->isInterB() && pcCU->isIntra(uiAbsPartIdx) && pcCU->getSDCFlag(uiAbsPartIdx)  )
     
    883927  }
    884928#endif
     929#endif
    885930 
    886931  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
    887932 
     933#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    888934#if RWTH_SDC_DLT_B0036
    889935  // code SDC flag now!
     
    899945    }
    900946  }
     947#endif
    901948#endif
    902949}
     
    11791226
    11801227// Intra direction for Luma
    1181 Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    1182 {
    1183   m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, uiAbsPartIdx );
     1228Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx
     1229#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1230                                           ,Bool bSdcRD
     1231#endif
     1232                                           )
     1233{
     1234  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, uiAbsPartIdx
     1235#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1236    ,bSdcRD
     1237#endif
     1238    );
    11841239}
    11851240
     
    11951250}
    11961251
    1197 Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
     1252Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD
     1253#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1254                                 ,Bool bSdcRD
     1255#endif
     1256                                 )
    11981257{
    11991258  if( bRD )
     
    12021261  }
    12031262
     1263#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    12041264#if RWTH_SDC_DLT_B0036
    12051265  if( pcCU->getSDCFlag(uiAbsPartIdx) )
     
    12081268    return;
    12091269  }
     1270#endif
    12101271#endif
    12111272
     
    12221283      encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*2 );
    12231284      encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*3 );
     1285#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1286      if(!pcCU->getSDCFlag(uiAbsPartIdx))
     1287#endif
    12241288      encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
    12251289    }
    12261290    else                                                              // if it is not NxN size, encode 1 intra directions
    12271291    {
    1228       encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx );
     1292      encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx
     1293#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1294        ,bSdcRD
     1295#endif
     1296        );
     1297#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1298      if(!pcCU->getSDCFlag(uiAbsPartIdx))
     1299#endif
    12291300      encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
    12301301    }
     
    12331304  {
    12341305    encodePUWise( pcCU, uiAbsPartIdx, bRD );
     1306#if QC_ARP_D0177
     1307    encodeARPW( pcCU , uiAbsPartIdx , bRD );
     1308#endif
    12351309  }
    12361310}
     
    13511425  {
    13521426#if H3D_IVMP
     1427#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     1428    const Int iNumCands = AMVP_MAX_NUM_CANDS;
     1429#else
    13531430    const Int iNumCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     1431#endif
    13541432    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList, iNumCands );
    13551433#else
     
    14171495    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
    14181496    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
    1419    
     1497#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    14201498    encodeSDCResidualData(pcCU, uiAbsPartIdx);
     1499#endif
    14211500    return;
    14221501  }
     
    14951574}
    14961575
     1576#if LGE_SAO_MIGRATION_D0091
     1577Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx)
     1578{
     1579    UInt uiSymbol;
     1580    Int i;
     1581
     1582    uiSymbol = saoLcuParam->typeIdx + 1;
     1583    if (compIdx!=2)
     1584    {
     1585        m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol);
     1586    }
     1587
     1588    if (uiSymbol)
     1589    {
     1590        if (saoLcuParam->typeIdx < 4 && compIdx != 2)
     1591        {
     1592            saoLcuParam->subTypeIdx = saoLcuParam->typeIdx;
     1593        }
     1594#if FULL_NBIT
     1595        Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + (g_uiBitDepth-8)-5),5) );
     1596#else
     1597        Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + g_uiBitIncrement-5),5) );
     1598#endif
     1599        if( saoLcuParam->typeIdx == SAO_BO )
     1600        {
     1601            for( i=0; i< saoLcuParam->length; i++)
     1602            {
     1603                UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]);
     1604                m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1);
     1605            } 
     1606            for( i=0; i< saoLcuParam->length; i++)
     1607            {
     1608                if (saoLcuParam->offset[i] != 0)
     1609                {
     1610                    UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ;
     1611                    m_pcEntropyCoderIf->codeSAOSign(sign);
     1612                }
     1613            }
     1614            uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
     1615            m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol);
     1616        }
     1617        else if( saoLcuParam->typeIdx < 4 )
     1618        {
     1619            m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1);
     1620            m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1);
     1621            m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1);
     1622            m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1);
     1623
     1624            if (compIdx!=2)
     1625            {
     1626                uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
     1627                m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol);
     1628            }
     1629        }
     1630    }
     1631}
     1632
     1633/** Encode SAO unit interleaving
     1634* \param  rx
     1635* \param  ry
     1636* \param  pSaoParam
     1637* \param  pcCU
     1638* \param  iCUAddrInSlice
     1639* \param  iCUAddrUpInSlice
     1640* \param  bLFCrossSliceBoundaryFlag
     1641 */
     1642Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
     1643{
     1644    if (saoFlag)
     1645    {
     1646        if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft)
     1647        {
     1648            m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag);
     1649        }
     1650        else
     1651        {
     1652            saoLcuParam->mergeLeftFlag = 0;
     1653        }
     1654       
     1655        if (saoLcuParam->mergeLeftFlag == 0)
     1656        {
     1657            if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp )
     1658            {
     1659                m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag);
     1660            }
     1661            else
     1662            {
     1663                saoLcuParam->mergeUpFlag = 0;
     1664            }
     1665
     1666            if (!saoLcuParam->mergeUpFlag)
     1667            {
     1668                encodeSaoOffset(saoLcuParam, compIdx);
     1669            }
     1670        }
     1671    }
     1672}
     1673#else
    14971674/** Encode SAO Offset
    14981675 * \param  saoLcuParam SAO LCU paramters
     
    16821859  }
    16831860}
     1861#endif
    16841862
    16851863Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
     
    17151893
    17161894#if RWTH_SDC_DLT_B0036
     1895#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    17171896Void TEncEntropy::encodeSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    17181897{
     
    17341913  m_pcEntropyCoderIf->codeSDCFlag(pcCU, uiAbsPartIdx);
    17351914}
    1736 
     1915#endif
    17371916Void TEncEntropy::encodeSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    17381917{
  • trunk/source/Lib/TLibEncoder/TEncEntropy.h

    r332 r443  
    117117  virtual Void codeResPredFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
    118118#endif
     119#if QC_ARP_D0177
     120  virtual Void codeARPW         ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
     121#endif
    119122  virtual Void codeSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
    120123 
     
    123126 
    124127#if RWTH_SDC_DLT_B0036
     128#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    125129  virtual Void codeSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
     130#endif
    126131  virtual Void codeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) = 0;
     132#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    127133  virtual Void codeSDCPredMode          ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
     134#endif
    128135#endif
    129136 
     
    133140  virtual Void codeQtCbf         ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) = 0;
    134141  virtual Void codeQtRootCbf     ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
    135   virtual Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
     142  virtual Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx
     143#if PKU_QC_DEPTH_INTRA_UNI_D0195
     144    , Bool bSdcRD = false
     145#endif
     146    ) = 0;
    136147 
    137148  virtual Void codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
     
    154165
    155166  virtual Void codeAlfCtrlFlag      ( UInt uiSymbol ) = 0;
     167#if LGE_SAO_MIGRATION_D0091
     168  virtual Void codeSAOSign          ( UInt code   ) = 0;
     169  virtual Void codeSaoMaxUvlc       ( UInt code, UInt maxSymbol ) = 0;
     170  virtual Void codeSaoMerge         ( UInt   uiCode  ) = 0;
     171  virtual Void codeSaoTypeIdx       ( UInt   uiCode) = 0;
     172  virtual Void codeSaoUflc          ( UInt uiLength, UInt   uiCode ) = 0;
     173#else
    156174  virtual Void codeSaoFlag          ( UInt uiCode ) = 0;
    157175  virtual Void codeSaoUvlc          ( UInt uiCode ) = 0;
     
    162180  virtual Void codeSaoTypeIdx      ( UInt   uiCode) = 0;
    163181  virtual Void codeSaoUflc         ( UInt   uiCode) = 0;
     182#endif
    164183  virtual Void estBit               (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0;
    165184 
     
    250269  Void encodeMergeFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx );
    251270  Void encodeMergeIndex   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD = false );
     271#if QC_ARP_D0177
     272  Void encodeARPW              ( TComDataCU* pcCU, UInt uiAbspartIdx , Bool bRD = false, UInt uiDepth = -1);
     273#endif
    252274  Void encodeAlfCtrlFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
    253275
     
    265287  Void encodePartSize          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD = false );
    266288  Void encodeIPCMInfo          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
    267   Void encodePredInfo          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
    268   Void encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     289  Void encodePredInfo          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false
     290#if PKU_QC_DEPTH_INTRA_UNI_D0195
     291    ,Bool bSdcRD = false
     292#endif
     293    );
     294  Void encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx
     295#if PKU_QC_DEPTH_INTRA_UNI_D0195
     296 ,Bool bSdcRD = false
     297#endif
     298    );
    269299 
    270300  Void encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
     
    284314 
    285315#if RWTH_SDC_DLT_B0036
     316#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    286317  Void encodeSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
     318#endif
    287319  Void encodeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
     320#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    288321  Void encodeSDCPredMode   ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
     322#endif
    289323#endif
    290324
     
    310344  Int golombEncode(int coeff, int k);
    311345  Int lengthGolomb(int coeffVal, int k);
     346#if LGE_SAO_MIGRATION_D0091
     347  Void    encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx);
     348  Void    encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);
     349#else
    312350  Void    encodeSaoUnit(Int rx, Int ry, Int compIdx, SAOParam* saoParam, Int repeatedRow);
    313351  Void    encodeSaoOffset(SaoLcuParam* saoLcuParam);
    314352  Void    encodeSaoUnitInterleaving(Int rx, Int ry, SAOParam* saoParam, TComDataCU* cu, Int cuAddrInSlice, Int cuAddrUpInSlice, Bool lfCrossSliceBoundaryFlag);
    315353  Void    encodeSaoParam         (TComAPS*  aps);
     354#endif
    316355
    317356  static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize );
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r332 r443  
    7878  m_pcDepthMapGenerator = NULL;
    7979#endif
    80 #if H3D_IVRP
     80#if H3D_IVRP & !QC_ARP_D0177
    8181  m_pcResidualGenerator = NULL;
    8282#endif
     
    131131  m_pcDepthMapGenerator  = pcTEncTop->getDepthMapGenerator();
    132132#endif
    133 #if H3D_IVRP
     133#if H3D_IVRP & !QC_ARP_D0177
    134134  m_pcResidualGenerator  = pcTEncTop->getResidualGenerator();
    135135#endif
     
    390390      std::vector<TComPic*> apcInterViewRefPics = tAppEncTop->getInterViewRefPics( m_pcEncTop->getViewId(), pcSlice->getPOC(), m_pcEncTop->getIsDepth(), pcSlice->getSPS() );
    391391      pcSlice->setRefPicListMvc( rcListPic, apcInterViewRefPics );
    392 
     392#if QC_ARP_D0177
     393      pcSlice->setARPStepNum();
     394      if(pcSlice->getARPStepNum() > 1)
     395      {
     396        for(Int iViewIdx = 0; iViewIdx < pcSlice->getViewId(); iViewIdx ++ )
     397          pcSlice->setBaseViewRefPicList( tAppEncTop->getTEncTop( iViewIdx , false )->getListPic(), iViewIdx );
     398      }
     399#endif
    393400      //  Slice info. refinement
    394401      if( pcSlice->getSliceType() == B_SLICE )
     
    754761      m_pcDepthMapGenerator->covertOrgDepthMap( pcPic );
    755762#endif
    756 #if H3D_IVRP
     763#if H3D_IVRP & !QC_ARP_D0177
    757764      m_pcResidualGenerator->initViewComponent( pcPic );
    758765#endif
     
    818825      pcSlice = pcPic->getSlice(0);
    819826
    820 #if H3D_IVRP
     827#if H3D_IVRP & !QC_ARP_D0177
    821828      // set residual picture
    822829      m_pcResidualGenerator->setRecResidualPic( pcPic );
     
    12571264            TComAPS cAPS;
    12581265            allocAPS(&cAPS, pcSlice->getSPS());
     1266#if !LGE_SAO_MIGRATION_D0091
    12591267            cAPS.setSaoInterleavingFlag(m_pcCfg->getSaoInterleavingFlag());
     1268#endif
    12601269            // set entropy coder for RD
    12611270            m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
     
    12651274              m_pcEntropyCoder->resetEntropy();
    12661275              m_pcEntropyCoder->setBitstream( m_pcBitCounter );
     1276#if LGE_SAO_MIGRATION_D0091
     1277              m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder());
     1278#else
    12671279              m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), NULL);
     1280#endif
    12681281              SAOParam& cSaoParam = *(cAPS.getSaoParam());
    12691282
    12701283#if SAO_CHROMA_LAMBDA
     1284#if LGE_SAO_MIGRATION_D0091
     1285#if SAO_ENCODING_CHOICE
     1286              m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth());
     1287#else
    12711288              m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma());
     1289#endif
     1290#else
     1291              m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma());
     1292#endif
    12721293#else
    12731294#if ALF_CHROMA_LAMBDA
     
    15541575    m_pcEntropyCoder->encodeDFParams(pcAPS);
    15551576  }
     1577#if !LGE_SAO_MIGRATION_D0091
    15561578  m_pcEntropyCoder->encodeSaoParam(pcAPS);
     1579#endif
    15571580  m_pcEntropyCoder->encodeAPSAlfFlag( pcAPS->getAlfEnabled()?1:0);
    15581581  if(pcAPS->getAlfEnabled())
  • trunk/source/Lib/TLibEncoder/TEncGOP.h

    r296 r443  
    9797  TComDepthMapGenerator*  m_pcDepthMapGenerator;
    9898#endif
    99 #if H3D_IVRP
     99#if H3D_IVRP & !QC_ARP_D0177
    100100  TComResidualGenerator*  m_pcResidualGenerator;
    101101#endif
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp

    r296 r443  
    4343//! \ingroup TLibEncoder
    4444//! \{
    45 
     45#if LGE_SAO_MIGRATION_D0091
    4646TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
    4747{
    48   m_pcEntropyCoder = NULL;
    49   m_pppcRDSbacCoder = NULL;
    50   m_pcRDGoOnSbacCoder = NULL;
    51   m_pppcBinCoderCABAC = NULL;           
    52   m_iCount = NULL;     
    53   m_iOffset = NULL;     
    54   m_iOffsetOrg = NULL; 
    55   m_iRate = NULL;       
    56   m_iDist = NULL;       
    57   m_dCost = NULL;       
    58   m_dCostPartBest = NULL;
    59   m_iDistOrg = NULL;     
    60   m_iTypePartBest = NULL;
    61 }
     48    m_pcEntropyCoder= NULL;
     49    m_pppcRDSbacCoder = NULL;
     50    m_pcRDGoOnSbacCoder = NULL;
     51    m_pppcBinCoderCABAC = NULL;
     52    m_iCount = NULL;
     53    m_iOffset = NULL;
     54    m_iOffsetOrg = NULL;
     55    m_iRate = NULL;
     56    m_iDist = NULL;
     57    m_dCost = NULL;
     58    m_dCostPartBest = NULL;
     59    m_iDistOrg = NULL;
     60    m_iTypePartBest = NULL;
     61#if SAO_ENCODING_CHOICE_CHROMA
     62    m_depthSaoRate[0][0] = 0;
     63    m_depthSaoRate[0][1] = 0;
     64    m_depthSaoRate[0][2] = 0;
     65    m_depthSaoRate[0][3] = 0;
     66    m_depthSaoRate[1][0] = 0;
     67    m_depthSaoRate[1][1] = 0;
     68    m_depthSaoRate[1][2] = 0;
     69    m_depthSaoRate[1][3] = 0;
     70#endif
     71}
     72
    6273TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()
    6374{
     
    7687{
    7788#if FULL_NBIT
    78   Int bitDepthMinus8 = g_uiBitDepth - 8;
    79   return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)) : ((Int)(((Int)(x)-(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)));
     89    Int bitDepthMinus8 = g_uiBitDepth - 8;
     90    return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)) : ((Int)(((Int)(x)-(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)));
    8091#else
    81   return ((x)>0) ? (Int)(((Int)(x)+(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)) : ((Int)(((Int)(x)-(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)));
     92    return ((x)>0) ? (Int)(((Int)(x)+(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)) : ((Int)(((Int)(x)-(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)));
    8293#endif
    8394}
     
    89100{
    90101#if FULL_NBIT
    91   return (g_uiBitDepth > 8 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
     102    return (g_uiBitDepth > 8 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
    92103#else
    93   return (g_uiBitIncrement >0 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
    94 #endif
    95 }
    96 
    97 
     104    return (g_uiBitIncrement >0 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
     105#endif
     106}
    98107
    99108/** process SAO for one partition
    100109 * \param  *psQTPart, iPartIdx, dLambda
    101110 */
    102 Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda)
    103 {
    104   Int iTypeIdx;
    105   Int iNumTotalType = MAX_NUM_SAO_TYPE;
    106   SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
    107 
    108   Int64 iEstDist;
    109   Int64 iOffsetOrg;
    110   Int64 iOffset;
    111   Int64 iCount;
    112   Int iClassIdx;
    113   Int uiShift = g_uiBitIncrement << 1;
    114   UInt uiDepth = pOnePart->PartLevel;
    115 
    116   m_iDistOrg [iPartIdx] =  0;
    117 
    118   Double  bestRDCostTableBo = MAX_DOUBLE;
    119   Int     bestClassTableBo    = 0;
    120   Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
    121   Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
    122 
    123 #if HHI_INTERVIEW_SKIP
    124   Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU();
    125   Int LcuIdxX = psQTPart->StartCUX;
    126   Int LcuIdxY = psQTPart->StartCUY;
    127   Int iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
    128   TComDataCU *pcCU = m_pcPic->getCU(iAddr);
    129   Bool bRenderable = pcCU->getRenderable(0) ;
    130 
    131 #endif
    132   for (iTypeIdx=-1; iTypeIdx<iNumTotalType; iTypeIdx++)
    133   {
    134     if( m_bUseSBACRD )
    135     {
    136       m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    137       m_pcRDGoOnSbacCoder->resetBits();
     111Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr)
     112{
     113    Int iTypeIdx;
     114    Int iNumTotalType = MAX_NUM_SAO_TYPE;
     115    SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
     116
     117    Int64 iEstDist;
     118    Int iClassIdx;
     119    Int uiShift = g_uiBitIncrement << 1;
     120    UInt uiDepth = pOnePart->PartLevel;
     121
     122    m_iDistOrg [iPartIdx] =  0;
     123
     124    Double  bestRDCostTableBo = MAX_DOUBLE;
     125    Int     bestClassTableBo    = 0;
     126    Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
     127    Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
     128
     129    Int addr;
     130    Int allowMergeLeft;
     131    Int allowMergeUp;
     132    Int frameWidthInCU = m_pcPic->getFrameWidthInCU();
     133    SaoLcuParam  saoLcuParamRdo;
     134
     135    for (iTypeIdx=-1; iTypeIdx<iNumTotalType; iTypeIdx++)
     136    {
     137        if( m_bUseSBACRD )
     138        {
     139            m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     140            m_pcRDGoOnSbacCoder->resetBits();
     141        }
     142        else
     143        {
     144            m_pcEntropyCoder->resetEntropy();
     145            m_pcEntropyCoder->resetBits();
     146        }
     147
     148        iEstDist = 0;
     149
     150        if (iTypeIdx == -1)
     151        {     
     152            for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++)
     153            {
     154                for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++)
     155                {
     156                    addr = ry * frameWidthInCU + rx;
     157                    // get bits for iTypeIdx = -1
     158                    allowMergeLeft = 1;
     159                    allowMergeUp   = 1;
     160                    if (rx != 0)
     161                    {
     162                        // check tile id and slice id
     163                        if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     164                        {
     165                            allowMergeLeft = 0;
     166                        }
     167                    }
     168                    if (ry!=0)
     169                    {
     170                        if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     171                        {
     172                            allowMergeUp = 0;
     173                        }
     174                    }
     175
     176                    // reset
     177                    resetSaoUnit(&saoLcuParamRdo);
     178       
     179                    // set merge flag
     180                    saoLcuParamRdo.mergeUpFlag   = 1;
     181                    saoLcuParamRdo.mergeLeftFlag = 1;
     182       
     183                    if (ry == pOnePart->StartCUY)
     184                    {
     185                        saoLcuParamRdo.mergeUpFlag = 0;
     186                    }
     187
     188                    if (rx == pOnePart->StartCUX)
     189                    {
     190                        saoLcuParamRdo.mergeLeftFlag = 0;
     191                    }
     192
     193                    m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry,  &saoLcuParamRdo, 1,  1,  allowMergeLeft, allowMergeUp);
     194
     195                }
     196            }
     197        }
     198
     199        if (iTypeIdx>=0)
     200        {
     201            iEstDist = estSaoTypeDist(iPartIdx, iTypeIdx, uiShift, dLambda, currentDistortionTableBo, currentRdCostTableBo);
     202            if( iTypeIdx == SAO_BO )
     203            {
     204                // Estimate Best Position
     205                Double currentRDCost = 0.0;
     206   
     207                for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
     208                {
     209                    currentRDCost = 0.0;
     210                    for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
     211                    {
     212                        currentRDCost += currentRdCostTableBo[uj];
     213                    }
     214
     215                    if( currentRDCost < bestRDCostTableBo)
     216                    {
     217                        bestRDCostTableBo = currentRDCost;
     218                        bestClassTableBo  = i;
     219                    }
     220                }
     221
     222                // Re code all Offsets
     223                // Code Center
     224                for(iClassIdx = bestClassTableBo; iClassIdx < bestClassTableBo+SAO_BO_LEN; iClassIdx++)
     225                {
     226                    iEstDist += currentDistortionTableBo[iClassIdx];
     227                }
     228            }
     229
     230            for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++)
     231            {
     232                for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++)
     233                {
     234                    addr = ry * frameWidthInCU + rx;         
     235       
     236                    // get bits for iTypeIdx = -1
     237                    allowMergeLeft = 1;
     238                    allowMergeUp   = 1;
     239                    if (rx != 0)
     240                    {
     241                        // check tile id and slice id
     242                        if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     243                        {
     244                            allowMergeLeft = 0;
     245                        }
     246                    }
     247                    if (ry!=0)
     248                    {
     249                        if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     250                        {
     251                            allowMergeUp = 0;
     252                        }
     253                    }
     254   
     255                    // reset
     256                    resetSaoUnit(&saoLcuParamRdo);
     257
     258                    // set merge flag
     259                    saoLcuParamRdo.mergeUpFlag   = 1;
     260                    saoLcuParamRdo.mergeLeftFlag = 1;
     261   
     262                    if (ry == pOnePart->StartCUY)
     263                    {
     264                        saoLcuParamRdo.mergeUpFlag = 0;
     265                    }
     266   
     267                    if (rx == pOnePart->StartCUX)
     268                    {
     269                        saoLcuParamRdo.mergeLeftFlag = 0;
     270                    }
     271
     272                    // set type and offsets
     273                    saoLcuParamRdo.typeIdx = iTypeIdx;
     274                    saoLcuParamRdo.subTypeIdx = (iTypeIdx==SAO_BO)?bestClassTableBo:0;
     275                    saoLcuParamRdo.length = m_iNumClass[iTypeIdx];
     276                    for (iClassIdx = 0; iClassIdx < saoLcuParamRdo.length; iClassIdx++)
     277                    {
     278                        saoLcuParamRdo.offset[iClassIdx] = (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx+saoLcuParamRdo.subTypeIdx+1];
     279                    }
     280
     281                    m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry,  &saoLcuParamRdo, 1,  1,  allowMergeLeft, allowMergeUp);
     282
     283                }
     284            }
     285
     286            m_iDist[iPartIdx][iTypeIdx] = iEstDist;
     287            m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder->getNumberOfWrittenBits();
     288
     289            m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]);
     290
     291            if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx])
     292            {
     293                m_iDistOrg [iPartIdx] = 0;
     294                m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx];
     295                m_iTypePartBest[iPartIdx] = iTypeIdx;
     296                if( m_bUseSBACRD )
     297                    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
     298            }
     299        }
     300        else
     301        {
     302            if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] )
     303            {
     304                m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder->getNumberOfWrittenBits()*dLambda ;
     305                m_iTypePartBest[iPartIdx] = -1;
     306                if( m_bUseSBACRD )
     307                    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
     308            }
     309        }
     310    }
     311
     312    pOnePart->bProcessed = true;
     313    pOnePart->bSplit     = false;
     314    pOnePart->iMinDist   =        m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx];
     315    pOnePart->iMinRate   = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0);
     316    pOnePart->dMinCost   = pOnePart->iMinDist + dLambda * pOnePart->iMinRate;
     317    pOnePart->iBestType  = m_iTypePartBest[iPartIdx];
     318    if (pOnePart->iBestType != -1)
     319    {
     320        //     pOnePart->bEnableFlag =  1;
     321        pOnePart->iLength = m_iNumClass[pOnePart->iBestType];
     322        Int minIndex = 0;
     323        if( pOnePart->iBestType == SAO_BO )
     324        {
     325            pOnePart->subTypeIdx = bestClassTableBo;
     326            minIndex = pOnePart->subTypeIdx;
     327        }
     328        for (Int i=0; i< pOnePart->iLength ; i++)
     329        {
     330            pOnePart->iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart->iBestType][minIndex+i+1];
     331        }
     332
    138333    }
    139334    else
    140335    {
    141       m_pcEntropyCoder->resetEntropy();
    142       m_pcEntropyCoder->resetBits();
    143     }
    144 
    145     iEstDist = 0;
    146 
    147     m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoTypeIdx(iTypeIdx+1);
    148 
    149     if (iTypeIdx>=0)
    150     {
    151 
    152       for(iClassIdx=1; iClassIdx < ( (iTypeIdx < SAO_BO) ?  m_iNumClass[iTypeIdx]+1 : SAO_MAX_BO_CLASSES+1); iClassIdx++)
    153       {
    154         if( iTypeIdx == SAO_BO)
    155         {
    156           currentDistortionTableBo[iClassIdx-1] = 0;
    157           currentRdCostTableBo[iClassIdx-1] = dLambda;
    158         }
    159 #if HHI_INTERVIEW_SKIP
    160         if(m_iCount [iPartIdx][iTypeIdx][iClassIdx] && !bRenderable)
    161 #else
    162         if(m_iCount [iPartIdx][iTypeIdx][iClassIdx])
    163 #endif
    164         {
    165 #if FULL_NBIT
    166           m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]<<g_uiBitDepth-8) / (Double)(m_iCount [iPartIdx][iTypeIdx][iClassIdx]<<m_uiSaoBitIncrease));
    167 #else
    168           m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]<<g_uiBitIncrement) / (Double)(m_iCount [iPartIdx][iTypeIdx][iClassIdx]<<m_uiSaoBitIncrease));
    169 #endif
    170           m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = Clip3(-m_iOffsetTh, m_iOffsetTh-1, (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
    171 
    172           if (iTypeIdx < 4)
    173           {
    174             if ( m_iOffset[iPartIdx][iTypeIdx][iClassIdx]<0 && iClassIdx<3 )
    175             {
    176               m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
    177             }
    178             if ( m_iOffset[iPartIdx][iTypeIdx][iClassIdx]>0 && iClassIdx>=3)
    179             {
    180               m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
    181             }
    182           }
    183           {
    184             //Clean up, best_q_offset.
    185             Int64 iIterOffset, iTempOffset;
    186             Int64 iTempDist, iTempRate;
    187             Double dTempCost, dTempMinCost;
    188             UInt uiLength, uiTemp;
    189 
    190             iIterOffset = m_iOffset[iPartIdx][iTypeIdx][iClassIdx];
    191             m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
    192             dTempMinCost = dLambda; // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here.
    193 
    194             while (iIterOffset != 0)
    195             {
    196               // Calculate the bits required for signalling the offset
    197               uiLength = 1;
    198               uiTemp = (UInt)((iIterOffset <= 0) ? ( (-iIterOffset<<1) + 1 ) : (iIterOffset<<1));
    199               while( 1 != uiTemp )
    200               {
    201                 uiTemp >>= 1;
    202                 uiLength += 2;
    203               }
    204               iTempRate = (uiLength >> 1) + ((uiLength+1) >> 1);
    205 
    206               // Do the dequntization before distorion calculation
    207               iTempOffset    =  iIterOffset << m_uiSaoBitIncrease;
    208               iTempDist  = (( m_iCount [iPartIdx][iTypeIdx][iClassIdx]*iTempOffset*iTempOffset-m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]*iTempOffset*2 ) >> uiShift);
    209 
    210               dTempCost = ((Double)iTempDist + dLambda * (Double) iTempRate);
    211               if(dTempCost < dTempMinCost)
    212               {
    213                 dTempMinCost = dTempCost;
    214                 m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = iIterOffset;
    215                 if(iTypeIdx == SAO_BO)
    216                 {
    217                   currentDistortionTableBo[iClassIdx-1] = (Int) iTempDist;
    218                   currentRdCostTableBo[iClassIdx-1] = dTempCost;
    219                 }
    220               }
    221               iIterOffset = (iIterOffset > 0) ? (iIterOffset-1):(iIterOffset+1);
    222             }
    223 
    224           }
    225         }
    226         else
    227         {
    228           m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] = 0;
    229           m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
    230         }
    231         if( iTypeIdx != SAO_BO )
    232         {
    233           iCount     =  m_iCount [iPartIdx][iTypeIdx][iClassIdx];
    234           iOffset    =  m_iOffset[iPartIdx][iTypeIdx][iClassIdx] << m_uiSaoBitIncrease;
    235           iOffsetOrg =  m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx];
    236           iEstDist   += (( iCount*iOffset*iOffset-iOffsetOrg*iOffset*2 ) >> uiShift);
    237           if (iTypeIdx < 4)
    238           {
    239             if (iClassIdx<3)
    240             {
    241               m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
    242             }
    243             else
    244             {
    245               m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUvlc((Int)-m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
    246             }
    247           }
    248           else
    249           {
    250             m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoSvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
    251           }
    252         }
    253       }
    254 
    255       if( iTypeIdx == SAO_BO )
    256       {
    257         // Estimate Best Position
    258         Double currentRDCost = 0.0;
    259 
    260         for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
    261         {
    262           currentRDCost = 0.0;
    263           for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
    264           {
    265             currentRDCost += currentRdCostTableBo[uj];
    266           }
    267 
    268           if( currentRDCost < bestRDCostTableBo)
    269           {
    270             bestRDCostTableBo = currentRDCost;
    271             bestClassTableBo  = i;
    272           }
    273         }
    274 
    275         // Re code all Offsets
    276         // Code Center
    277         m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUflc( (UInt) (bestClassTableBo) );
    278 
    279         for(iClassIdx = bestClassTableBo; iClassIdx < bestClassTableBo+SAO_BO_LEN; iClassIdx++)
    280         {
    281           m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoSvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx+1]);
    282           iEstDist += currentDistortionTableBo[iClassIdx];
    283         }
    284       }
    285 
    286       m_iDist[iPartIdx][iTypeIdx] = iEstDist;
    287       m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder->getNumberOfWrittenBits();
    288 
    289       m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]);
    290 
    291       if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx])
    292       {
    293         m_iDistOrg [iPartIdx] = 0;
    294         m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx];
    295         m_iTypePartBest[iPartIdx] = iTypeIdx;
    296         if( m_bUseSBACRD )
    297           m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
    298       }
    299     }
    300     else
    301     {
    302       if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] )
    303       {
    304         m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder->getNumberOfWrittenBits()*dLambda ;
    305         m_iTypePartBest[iPartIdx] = -1;
    306         if( m_bUseSBACRD )
    307           m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
    308       }
    309     }
    310   }
    311 
    312   pOnePart->bProcessed = true;
    313   pOnePart->bSplit     = false;
    314   pOnePart->iMinDist   =        m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx];
    315   pOnePart->iMinRate   = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0);
    316   pOnePart->dMinCost   = pOnePart->iMinDist + dLambda * pOnePart->iMinRate;
    317   pOnePart->iBestType  = m_iTypePartBest[iPartIdx];
    318   if (pOnePart->iBestType != -1)
    319   {
    320     //     pOnePart->bEnableFlag =  1;
    321     pOnePart->iLength = m_iNumClass[pOnePart->iBestType];
    322     Int minIndex = 0;
    323     if( pOnePart->iBestType == SAO_BO )
    324     {
    325       pOnePart->bandPosition = bestClassTableBo;
    326       minIndex = pOnePart->bandPosition;
    327     }
    328     for (Int i=0; i< pOnePart->iLength ; i++)
    329     {
    330       pOnePart->iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart->iBestType][minIndex+i+1];
    331     }
    332 
    333   }
    334   else
    335   {
    336     //     pOnePart->bEnableFlag = 0;
    337     pOnePart->iLength     = 0;
    338   }
     336        //     pOnePart->bEnableFlag = 0;
     337        pOnePart->iLength     = 0;
     338    }
    339339}
    340340
     
    343343Void TEncSampleAdaptiveOffset::disablePartTree(SAOQTPart *psQTPart, Int iPartIdx)
    344344{
    345   SAOQTPart*  pOnePart= &(psQTPart[iPartIdx]);
    346   pOnePart->bSplit      = false;
    347   pOnePart->iLength     =  0;
    348   pOnePart->iBestType   = -1;
    349 
    350   if (pOnePart->PartLevel < m_uiMaxSplitLevel)
    351   {
    352     for (Int i=0; i<NUM_DOWN_PART; i++)
    353     {
    354       disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
    355     }
    356   }
     345    SAOQTPart*  pOnePart= &(psQTPart[iPartIdx]);
     346    pOnePart->bSplit      = false;
     347    pOnePart->iLength     =  0;
     348    pOnePart->iBestType   = -1;
     349
     350    if (pOnePart->PartLevel < m_uiMaxSplitLevel)
     351    {
     352        for (Int i=0; i<NUM_DOWN_PART; i++)
     353        {
     354            disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
     355        }
     356    }
    357357}
    358358
     
    360360 * \param  iPartIdx, pcPicOrg, pcPicDec, pcPicRest, &dCostFinal
    361361 */
    362 Void TEncSampleAdaptiveOffset::runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda)
    363 {
    364   SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
    365 
    366   UInt uiDepth = pOnePart->PartLevel;
    367   UInt uhNextDepth = uiDepth+1;
    368 
    369   if (iPartIdx == 0)
    370   {
    371     dCostFinal = 0;
    372   }
    373 
    374   //SAO for this part
    375   if(!pOnePart->bProcessed)
    376   {
    377     rdoSaoOnePart (psQTPart, iPartIdx, dLambda);
    378   }
    379 
    380   //SAO for sub 4 parts
    381   if (pOnePart->PartLevel < iMaxLevel)
    382   {
    383     Double      dCostNotSplit = dLambda + pOnePart->dMinCost;
    384     Double      dCostSplit    = dLambda;
    385 
    386     for (Int i=0; i< NUM_DOWN_PART ;i++)
    387     {
    388       if( m_bUseSBACRD ) 
    389       {
    390         if ( 0 == i) //initialize RD with previous depth buffer
    391         {
    392           m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     362Void TEncSampleAdaptiveOffset::runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr)
     363{
     364    SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
     365
     366    UInt uiDepth = pOnePart->PartLevel;
     367    UInt uhNextDepth = uiDepth+1;
     368
     369    if (iPartIdx == 0)
     370    {
     371        dCostFinal = 0;
     372    }
     373
     374    //SAO for this part
     375    if(!pOnePart->bProcessed)
     376    {
     377        rdoSaoOnePart (psQTPart, iPartIdx, dLambda, yCbCr);
     378    }
     379
     380    //SAO for sub 4 parts
     381    if (pOnePart->PartLevel < iMaxLevel)
     382    {
     383        Double      dCostNotSplit = dLambda + pOnePart->dMinCost;
     384        Double      dCostSplit    = dLambda;
     385
     386        for (Int i=0; i< NUM_DOWN_PART ;i++)
     387        {
     388            if( m_bUseSBACRD )
     389            {
     390                if ( 0 == i) //initialize RD with previous depth buffer
     391                {
     392                    m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     393                }
     394                else
     395                {
     396                    m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
     397                }
     398            }
     399            runQuadTreeDecision(psQTPart, pOnePart->DownPartsIdx[i], dCostFinal, iMaxLevel, dLambda, yCbCr);
     400            dCostSplit += dCostFinal;
     401            if( m_bUseSBACRD )
     402            {
     403                m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_TEMP_BEST]);
     404            }
     405        }
     406
     407        if(dCostSplit < dCostNotSplit)
     408        {
     409            dCostFinal = dCostSplit;
     410            pOnePart->bSplit      = true;
     411            pOnePart->iLength     =  0;
     412            pOnePart->iBestType   = -1;
     413            if( m_bUseSBACRD )
     414            {
     415                m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
     416            }
    393417        }
    394418        else
    395419        {
    396           m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    397         }
    398       } 
    399       runQuadTreeDecision(psQTPart, pOnePart->DownPartsIdx[i], dCostFinal, iMaxLevel, dLambda);
    400       dCostSplit += dCostFinal;
    401       if( m_bUseSBACRD )
    402       {
    403         m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_TEMP_BEST]);
    404       }
    405     }
    406 
    407     if(dCostSplit < dCostNotSplit)
    408     {
    409       dCostFinal = dCostSplit;
    410       pOnePart->bSplit      = true;
    411       pOnePart->iLength     =  0;
    412       pOnePart->iBestType   = -1;
    413       if( m_bUseSBACRD )
    414       {
    415         m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    416       }
     420            dCostFinal = dCostNotSplit;
     421            pOnePart->bSplit = false;
     422            for (Int i=0; i<NUM_DOWN_PART; i++)
     423            {
     424                disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
     425            }
     426            if( m_bUseSBACRD )
     427            {
     428                m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     429            }
     430        }
    417431    }
    418432    else
    419433    {
    420       dCostFinal = dCostNotSplit;
    421       pOnePart->bSplit = false;
    422       for (Int i=0; i<NUM_DOWN_PART; i++)
    423       {
    424         disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
    425       }
    426       if( m_bUseSBACRD )
    427       {
    428         m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    429       }
    430     }
    431   }
    432   else
    433   {
    434     dCostFinal = pOnePart->dMinCost;
    435   }
     434        dCostFinal = pOnePart->dMinCost;
     435    }
    436436}
    437437
     
    446446      if (m_iCount [i][j])
    447447      {
    448         delete [] m_iCount [i][j]; 
     448        delete [] m_iCount [i][j];
    449449      }
    450450      if (m_iOffset[i][j])
     
    454454      if (m_iOffsetOrg[i][j])
    455455      {
    456         delete [] m_iOffsetOrg[i][j]; 
     456        delete [] m_iOffsetOrg[i][j];
    457457      }
    458458    }
     
    463463    if (m_iDist[i])
    464464    {
    465       delete [] m_iDist[i]; 
     465      delete [] m_iDist[i];
    466466    }
    467467    if (m_dCost[i])
     
    471471    if (m_iCount [i])
    472472    {
    473       delete [] m_iCount [i]; 
     473      delete [] m_iCount [i];
    474474    }
    475475    if (m_iOffset[i])
     
    479479    if (m_iOffsetOrg[i])
    480480    {
    481       delete [] m_iOffsetOrg[i];
    482     }
    483 
     481      delete [] m_iOffsetOrg[i];
     482    }
    484483  }
    485484  if (m_iDistOrg)
     
    518517  {
    519518    delete [] m_iOffsetOrg ; m_iOffsetOrg = NULL;
     519  }
     520  Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight;
     521
     522  for (Int i=0;i<numLcu;i++)
     523  {
     524    for (Int j=0;j<3;j++)
     525    {
     526      for (Int k=0;k<MAX_NUM_SAO_TYPE;k++)
     527      {
     528        if (m_count_PreDblk [i][j][k])
     529        {
     530          delete [] m_count_PreDblk [i][j][k];
     531        }
     532        if (m_offsetOrg_PreDblk[i][j][k])
     533        {
     534          delete [] m_offsetOrg_PreDblk[i][j][k];
     535        }
     536      }
     537      if (m_count_PreDblk [i][j])
     538      {
     539        delete [] m_count_PreDblk [i][j];
     540      }
     541      if (m_offsetOrg_PreDblk[i][j])
     542      {
     543        delete [] m_offsetOrg_PreDblk[i][j];
     544      }
     545    }
     546    if (m_count_PreDblk [i])
     547    {
     548      delete [] m_count_PreDblk [i];
     549    }
     550    if (m_offsetOrg_PreDblk[i])
     551    {
     552      delete [] m_offsetOrg_PreDblk[i];
     553    }
     554  }
     555  if (m_count_PreDblk)
     556  {
     557    delete [] m_count_PreDblk  ; m_count_PreDblk = NULL;
     558  }
     559  if (m_offsetOrg_PreDblk)
     560  {
     561    delete [] m_offsetOrg_PreDblk ; m_offsetOrg_PreDblk = NULL;
    520562  }
    521563
     
    546588Void TEncSampleAdaptiveOffset::createEncBuffer()
    547589{
    548   m_iDistOrg = new Int64 [m_iNumTotalParts]; 
    549   m_dCostPartBest = new Double [m_iNumTotalParts]; 
    550   m_iTypePartBest = new Int [m_iNumTotalParts]; 
     590  m_iDistOrg = new Int64 [m_iNumTotalParts];
     591  m_dCostPartBest = new Double [m_iNumTotalParts];
     592  m_iTypePartBest = new Int [m_iNumTotalParts];
    551593
    552594  m_iRate = new Int64* [m_iNumTotalParts];
     
    561603  {
    562604    m_iRate[i] = new Int64  [MAX_NUM_SAO_TYPE];
    563     m_iDist[i] = new Int64  [MAX_NUM_SAO_TYPE]; 
    564     m_dCost[i] = new Double [MAX_NUM_SAO_TYPE]; 
    565 
    566     m_iCount [i] = new Int64 *[MAX_NUM_SAO_TYPE]; 
    567     m_iOffset[i] = new Int64 *[MAX_NUM_SAO_TYPE]; 
    568     m_iOffsetOrg[i] = new Int64 *[MAX_NUM_SAO_TYPE]; 
     605    m_iDist[i] = new Int64  [MAX_NUM_SAO_TYPE];
     606    m_dCost[i] = new Double [MAX_NUM_SAO_TYPE];
     607
     608    m_iCount [i] = new Int64 *[MAX_NUM_SAO_TYPE];
     609    m_iOffset[i] = new Int64 *[MAX_NUM_SAO_TYPE];
     610    m_iOffsetOrg[i] = new Int64 *[MAX_NUM_SAO_TYPE];
    569611
    570612    for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
    571613    {
    572       m_iCount [i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
    573       m_iOffset[i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
    574       m_iOffsetOrg[i][j]= new Int64 [MAX_NUM_SAO_CLASS];
     614      m_iCount [i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
     615      m_iOffset[i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
     616      m_iOffsetOrg[i][j]= new Int64 [MAX_NUM_SAO_CLASS];
     617    }
     618  }
     619  Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight;
     620  m_count_PreDblk  = new Int64 ***[numLcu];
     621  m_offsetOrg_PreDblk = new Int64 ***[numLcu];
     622  for (Int i=0; i<numLcu; i++)
     623  {
     624    m_count_PreDblk[i]  = new Int64 **[3];
     625    m_offsetOrg_PreDblk[i] = new Int64 **[3];
     626
     627    for (Int j=0;j<3;j++)
     628    {
     629      m_count_PreDblk [i][j] = new Int64 *[MAX_NUM_SAO_TYPE];
     630      m_offsetOrg_PreDblk[i][j] = new Int64 *[MAX_NUM_SAO_TYPE];
     631
     632      for (Int k=0;k<MAX_NUM_SAO_TYPE;k++)
     633      {
     634        m_count_PreDblk [i][j][k]   = new Int64 [MAX_NUM_SAO_CLASS];
     635        m_offsetOrg_PreDblk[i][j][k]= new Int64 [MAX_NUM_SAO_CLASS];
     636      }
    575637    }
    576638  }
     
    606668
    607669/** Start SAO encoder
    608  * \param pcPic, pcEntropyCoder, pppcRDSbacCoder, pcRDGoOnSbacCoder 
     670 * \param pcPic, pcEntropyCoder, pppcRDSbacCoder, pcRDGoOnSbacCoder
    609671 */
    610672Void TEncSampleAdaptiveOffset::startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder)
    611673{
    612   if( pcRDGoOnSbacCoder )
    613     m_bUseSBACRD = true;
    614   else
    615     m_bUseSBACRD = false;
    616 
     674  m_bUseSBACRD = true;
    617675  m_pcPic = pcPic;
    618676  m_pcEntropyCoder = pcEntropyCoder;
    619677
    620678  m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder;
     679  m_pcEntropyCoder->setEntropyCoder(m_pcRDGoOnSbacCoder, pcPic->getSlice(0));
    621680  m_pcEntropyCoder->resetEntropy();
    622681  m_pcEntropyCoder->resetBits();
     
    672731      if (classIdx)
    673732      {
    674         stats[classIdx] += (pOrg[x] - pRec[x]); 
     733        stats[classIdx] += (pOrg[x] - pRec[x]);
    675734        count[classIdx] ++;
    676735      }
     
    685744  pRec   = pRecStart;
    686745
    687 
    688746  startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
    689747  endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
     
    693751    for (x=startX; x< endX; x++)
    694752    {
    695       signRight =  xSign(pRec[x] - pRec[x+1]); 
     753      signRight =  xSign(pRec[x] - pRec[x+1]);
    696754      edgeType =  signRight + signLeft + 2;
    697755      signLeft  = -signRight;
     
    726784    for (x=0; x< width; x++)
    727785    {
    728       signDown     =  xSign(pRec[x] - pRec[x+stride]); 
     786      signDown     =  xSign(pRec[x] - pRec[x+stride]);
    729787      edgeType    =  signDown + m_iUpBuff1[x] + 2;
    730788      m_iUpBuff1[x] = -signDown;
     
    785843      count[m_auiEoTable[edgeType]] ++;
    786844
    787       m_iUpBufft[x+1] = -signDown1; 
     845      m_iUpBufft[x+1] = -signDown1;
    788846    }
    789847    m_iUpBufft[startX] = xSign(pRec[stride+startX] - pRec[startX-1]);
     
    931989      posOffset = (yPos* stride) + xPos;
    932990
    933 #if HHI_INTERVIEW_SKIP
    934       if( !m_pcPic->getCU(iAddr)->getRenderable(0 ))
    935       {
    936991      calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail);
    937       }
    938 #else
    939       calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail);
    940 #endif
    941     }
    942   }
    943 
     992    }
     993  }
    944994}
    945995
     
    9741024  Int iIsChroma = (iYCbCr!=0)? 1:0;
    9751025  Int numSkipLine = iIsChroma? 2:4;
     1026  if (m_saoLcuBasedOptimization == 0)
     1027  {
     1028    numSkipLine = 0;
     1029  }
     1030
     1031#if SAO_SKIP_RIGHT
     1032  Int numSkipLineRight = iIsChroma? 3:5;
     1033  if (m_saoLcuBasedOptimization == 0)
     1034  {
     1035    numSkipLineRight = 0;
     1036  }
     1037#endif
     1038
     1039  iPicWidthTmp  = m_iPicWidth  >> iIsChroma;
     1040  iPicHeightTmp = m_iPicHeight >> iIsChroma;
     1041  iLcuWidth     = iLcuWidth    >> iIsChroma;
     1042  iLcuHeight    = iLcuHeight   >> iIsChroma;
     1043  uiLPelX       = uiLPelX      >> iIsChroma;
     1044  uiTPelY       = uiTPelY      >> iIsChroma;
     1045  uiRPelX       = uiLPelX + iLcuWidth  ;
     1046  uiBPelY       = uiTPelY + iLcuHeight ;
     1047  uiRPelX       = uiRPelX > iPicWidthTmp  ? iPicWidthTmp  : uiRPelX;
     1048  uiBPelY       = uiBPelY > iPicHeightTmp ? iPicHeightTmp : uiBPelY;
     1049  iLcuWidth     = uiRPelX - uiLPelX;
     1050  iLcuHeight    = uiBPelY - uiTPelY;
     1051
     1052  iStride    =  (iYCbCr == 0)? m_pcPic->getStride(): m_pcPic->getCStride();
     1053
     1054//if(iSaoType == BO_0 || iSaoType == BO_1)
     1055  {
     1056    if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     1057    {
     1058      numSkipLine = iIsChroma? 1:3;
     1059      numSkipLineRight = iIsChroma? 2:4;
     1060    }
     1061    iStats = m_iOffsetOrg[iPartIdx][SAO_BO];
     1062    iCount = m_iCount    [iPartIdx][SAO_BO];
     1063
     1064    pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
     1065    pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
     1066
     1067#if SAO_SKIP_RIGHT
     1068    iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight;
     1069#endif
     1070
     1071    iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight : iLcuHeight-numSkipLine;
     1072    for (y=0; y<iEndY; y++)
     1073    {
     1074#if SAO_SKIP_RIGHT
     1075      for (x=0; x<iEndX; x++)
     1076#else
     1077      for (x=0; x<iLcuWidth; x++)
     1078#endif
     1079      {
     1080        iClassIdx = m_lumaTableBo[pRec[x]];
     1081        if (iClassIdx)
     1082        {
     1083          iStats[iClassIdx] += (pOrg[x] - pRec[x]);
     1084          iCount[iClassIdx] ++;
     1085        }
     1086      }
     1087      pOrg += iStride;
     1088      pRec += iStride;
     1089    }
     1090
     1091  }
     1092  Int iSignLeft;
     1093  Int iSignRight;
     1094  Int iSignDown;
     1095  Int iSignDown1;
     1096  Int iSignDown2;
     1097
     1098  UInt uiEdgeType;
     1099
     1100//if (iSaoType == EO_0  || iSaoType == EO_1 || iSaoType == EO_2 || iSaoType == EO_3)
     1101  {
     1102  //if (iSaoType == EO_0)
     1103    {
     1104      if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     1105      {
     1106        numSkipLine = iIsChroma? 1:3;
     1107        numSkipLineRight = iIsChroma? 3:5;
     1108      }
     1109      iStats = m_iOffsetOrg[iPartIdx][SAO_EO_0];
     1110      iCount = m_iCount    [iPartIdx][SAO_EO_0];
     1111
     1112      pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
     1113      pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
     1114
     1115      iStartX = (uiLPelX == 0) ? 1 : 0;
     1116#if SAO_SKIP_RIGHT
     1117      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
     1118#else
     1119      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
     1120#endif
     1121      for (y=0; y<iLcuHeight-numSkipLine; y++)
     1122      {
     1123        iSignLeft = xSign(pRec[iStartX] - pRec[iStartX-1]);
     1124        for (x=iStartX; x< iEndX; x++)
     1125        {
     1126          iSignRight =  xSign(pRec[x] - pRec[x+1]);
     1127          uiEdgeType =  iSignRight + iSignLeft + 2;
     1128          iSignLeft  = -iSignRight;
     1129
     1130          iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1131          iCount[m_auiEoTable[uiEdgeType]] ++;
     1132        }
     1133        pOrg += iStride;
     1134        pRec += iStride;
     1135      }
     1136    }
     1137
     1138  //if (iSaoType == EO_1)
     1139    {
     1140      if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     1141      {
     1142        numSkipLine = iIsChroma? 2:4;
     1143        numSkipLineRight = iIsChroma? 2:4;
     1144      }
     1145      iStats = m_iOffsetOrg[iPartIdx][SAO_EO_1];
     1146      iCount = m_iCount    [iPartIdx][SAO_EO_1];
     1147
     1148      pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
     1149      pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
     1150
     1151      iStartY = (uiTPelY == 0) ? 1 : 0;
     1152#if SAO_SKIP_RIGHT
     1153      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight;
     1154#endif
     1155      iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
     1156      if (uiTPelY == 0)
     1157      {
     1158        pOrg += iStride;
     1159        pRec += iStride;
     1160      }
     1161
     1162      for (x=0; x< iLcuWidth; x++)
     1163      {
     1164        m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride]);
     1165      }
     1166      for (y=iStartY; y<iEndY; y++)
     1167      {
     1168#if SAO_SKIP_RIGHT
     1169        for (x=0; x<iEndX; x++)
     1170#else
     1171        for (x=0; x<iLcuWidth; x++)
     1172#endif
     1173        {
     1174          iSignDown     =  xSign(pRec[x] - pRec[x+iStride]);
     1175          uiEdgeType    =  iSignDown + m_iUpBuff1[x] + 2;
     1176          m_iUpBuff1[x] = -iSignDown;
     1177
     1178          iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1179          iCount[m_auiEoTable[uiEdgeType]] ++;
     1180        }
     1181        pOrg += iStride;
     1182        pRec += iStride;
     1183      }
     1184    }
     1185  //if (iSaoType == EO_2)
     1186    {
     1187      if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     1188      {
     1189        numSkipLine = iIsChroma? 2:4;
     1190        numSkipLineRight = iIsChroma? 3:5;
     1191      }
     1192      iStats = m_iOffsetOrg[iPartIdx][SAO_EO_2];
     1193      iCount = m_iCount    [iPartIdx][SAO_EO_2];
     1194
     1195      pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
     1196      pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
     1197
     1198      iStartX = (uiLPelX == 0) ? 1 : 0;
     1199#if SAO_SKIP_RIGHT
     1200      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
     1201#else
     1202      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
     1203#endif
     1204
     1205      iStartY = (uiTPelY == 0) ? 1 : 0;
     1206      iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
     1207      if (uiTPelY == 0)
     1208      {
     1209        pOrg += iStride;
     1210        pRec += iStride;
     1211      }
     1212
     1213      for (x=iStartX; x<iEndX; x++)
     1214      {
     1215        m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride-1]);
     1216      }
     1217      for (y=iStartY; y<iEndY; y++)
     1218      {
     1219        iSignDown2 = xSign(pRec[iStride+iStartX] - pRec[iStartX-1]);
     1220        for (x=iStartX; x<iEndX; x++)
     1221        {
     1222          iSignDown1      =  xSign(pRec[x] - pRec[x+iStride+1]) ;
     1223          uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
     1224          m_iUpBufft[x+1] = -iSignDown1;
     1225          iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1226          iCount[m_auiEoTable[uiEdgeType]] ++;
     1227        }
     1228        m_iUpBufft[iStartX] = iSignDown2;
     1229        ipSwap     = m_iUpBuff1;
     1230        m_iUpBuff1 = m_iUpBufft;
     1231        m_iUpBufft = ipSwap;
     1232
     1233        pRec += iStride;
     1234        pOrg += iStride;
     1235      }
     1236    }
     1237  //if (iSaoType == EO_3  )
     1238    {
     1239      if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     1240      {
     1241        numSkipLine = iIsChroma? 2:4;
     1242        numSkipLineRight = iIsChroma? 3:5;
     1243      }
     1244      iStats = m_iOffsetOrg[iPartIdx][SAO_EO_3];
     1245      iCount = m_iCount    [iPartIdx][SAO_EO_3];
     1246
     1247      pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
     1248      pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
     1249
     1250      iStartX = (uiLPelX == 0) ? 1 : 0;
     1251#if SAO_SKIP_RIGHT
     1252      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
     1253#else
     1254      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
     1255#endif
     1256
     1257      iStartY = (uiTPelY == 0) ? 1 : 0;
     1258      iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
     1259      if (iStartY == 1)
     1260      {
     1261        pOrg += iStride;
     1262        pRec += iStride;
     1263      }
     1264
     1265      for (x=iStartX-1; x<iEndX; x++)
     1266      {
     1267        m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride+1]);
     1268      }
     1269
     1270      for (y=iStartY; y<iEndY; y++)
     1271      {
     1272        for (x=iStartX; x<iEndX; x++)
     1273        {
     1274          iSignDown1      =  xSign(pRec[x] - pRec[x+iStride-1]) ;
     1275          uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
     1276          m_iUpBuff1[x-1] = -iSignDown1;
     1277          iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1278          iCount[m_auiEoTable[uiEdgeType]] ++;
     1279        }
     1280        m_iUpBuff1[iEndX-1] = xSign(pRec[iEndX-1 + iStride] - pRec[iEndX]);
     1281
     1282        pRec += iStride;
     1283        pOrg += iStride;
     1284      }
     1285    }
     1286  }
     1287}
     1288
     1289
     1290Void TEncSampleAdaptiveOffset::calcSaoStatsCu_BeforeDblk( TComPic* pcPic )
     1291{
     1292  Int addr, yCbCr;
     1293  Int x,y;
     1294  TComSPS *pTmpSPS =  pcPic->getSlice(0)->getSPS();
     1295
     1296  Pel* pOrg;
     1297  Pel* pRec;
     1298  Int stride;
     1299  Int lcuWidth  = pTmpSPS->getMaxCUHeight();
     1300  Int lcuHeight = pTmpSPS->getMaxCUWidth();
     1301  UInt rPelX;
     1302  UInt bPelY;
     1303  Int64* stats;
     1304  Int64* count;
     1305  Int classIdx;
     1306  Int picWidthTmp = 0;
     1307  Int picHeightTmp = 0;
     1308  Int startX;
     1309  Int startY;
     1310  Int endX;
     1311  Int endY;
     1312  Int firstX, firstY;
     1313
     1314  Int idxY;
     1315  Int idxX;
     1316  Int frameHeightInCU = m_iNumCuInHeight;
     1317  Int frameWidthInCU  = m_iNumCuInWidth;
     1318  Int j, k;
     1319
     1320  Int isChroma;
     1321  Int numSkipLine, numSkipLineRight;
     1322
     1323  UInt lPelX, tPelY;
     1324  TComDataCU *pTmpCu;
     1325
     1326  for (idxY = 0; idxY< frameHeightInCU; idxY++)
     1327  {
     1328    for (idxX = 0; idxX< frameWidthInCU; idxX++)
     1329    {
     1330      lcuWidth  = pTmpSPS->getMaxCUHeight();
     1331      lcuHeight = pTmpSPS->getMaxCUWidth();
     1332      addr     = idxX  + frameWidthInCU*idxY;
     1333      pTmpCu = pcPic->getCU(addr);
     1334      lPelX   = pTmpCu->getCUPelX();
     1335      tPelY   = pTmpCu->getCUPelY();
     1336      for( yCbCr = 0; yCbCr < 3; yCbCr++ )
     1337      {
     1338        isChroma = (yCbCr!=0)? 1:0;
     1339
     1340        for ( j=0;j<MAX_NUM_SAO_TYPE;j++)
     1341        {
     1342          for ( k=0;k< MAX_NUM_SAO_CLASS;k++)
     1343          {
     1344            m_count_PreDblk    [addr][yCbCr][j][k] = 0;
     1345            m_offsetOrg_PreDblk[addr][yCbCr][j][k] = 0;
     1346          } 
     1347        }
     1348        if( yCbCr == 0 )
     1349        {
     1350          picWidthTmp  = m_iPicWidth;
     1351          picHeightTmp = m_iPicHeight;
     1352        }
     1353        else if( yCbCr == 1 )
     1354        {
     1355          picWidthTmp  = m_iPicWidth  >> isChroma;
     1356          picHeightTmp = m_iPicHeight >> isChroma;
     1357          lcuWidth     = lcuWidth    >> isChroma;
     1358          lcuHeight    = lcuHeight   >> isChroma;
     1359          lPelX       = lPelX      >> isChroma;
     1360          tPelY       = tPelY      >> isChroma;
     1361        }
     1362        rPelX       = lPelX + lcuWidth  ;
     1363        bPelY       = tPelY + lcuHeight ;
     1364        rPelX       = rPelX > picWidthTmp  ? picWidthTmp  : rPelX;
     1365        bPelY       = bPelY > picHeightTmp ? picHeightTmp : bPelY;
     1366        lcuWidth     = rPelX - lPelX;
     1367        lcuHeight    = bPelY - tPelY;
     1368
     1369        stride    =  (yCbCr == 0)? pcPic->getStride(): pcPic->getCStride();
     1370
     1371        //if(iSaoType == BO)
     1372
     1373        numSkipLine = isChroma? 1:3;
     1374        numSkipLineRight = isChroma? 2:4;
     1375
     1376        stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_BO];
     1377        count = m_count_PreDblk[addr][yCbCr][SAO_BO];
     1378
     1379        pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
     1380        pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
     1381
     1382        startX   = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight;
     1383        startY   = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine;
     1384
     1385        for (y=0; y<lcuHeight; y++)
     1386        {
     1387          for (x=0; x<lcuWidth; x++)
     1388          {
     1389            if( x < startX && y < startY )
     1390              continue;
     1391
     1392            classIdx = m_lumaTableBo[pRec[x]];
     1393            if (classIdx)
     1394            {
     1395              stats[classIdx] += (pOrg[x] - pRec[x]);
     1396              count[classIdx] ++;
     1397            }
     1398          }
     1399          pOrg += stride;
     1400          pRec += stride;
     1401        }
     1402
     1403        Int signLeft;
     1404        Int signRight;
     1405        Int signDown;
     1406        Int signDown1;
     1407        Int signDown2;
     1408
     1409        UInt uiEdgeType;
     1410
     1411        //if (iSaoType == EO_0)
     1412
     1413        numSkipLine = isChroma? 1:3;
     1414        numSkipLineRight = isChroma? 3:5;
     1415
     1416        stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_0];
     1417        count = m_count_PreDblk[addr][yCbCr][SAO_EO_0];
     1418
     1419        pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
     1420        pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
     1421
     1422        startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
     1423        startY   = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine;
     1424        firstX   = (lPelX == 0) ? 1 : 0;
     1425        endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
     1426
     1427        for (y=0; y<lcuHeight; y++)
     1428        {
     1429          signLeft = xSign(pRec[firstX] - pRec[firstX-1]);
     1430          for (x=firstX; x< endX; x++)
     1431          {
     1432            signRight =  xSign(pRec[x] - pRec[x+1]);
     1433            uiEdgeType =  signRight + signLeft + 2;
     1434            signLeft  = -signRight;
     1435
     1436            if( x < startX && y < startY )
     1437              continue;
     1438
     1439            stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1440            count[m_auiEoTable[uiEdgeType]] ++;
     1441          }
     1442          pOrg += stride;
     1443          pRec += stride;
     1444        }
     1445
     1446        //if (iSaoType == EO_1)
     1447
     1448        numSkipLine = isChroma? 2:4;
     1449        numSkipLineRight = isChroma? 2:4;
     1450
     1451        stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_1];
     1452        count = m_count_PreDblk[addr][yCbCr][SAO_EO_1];
     1453
     1454        pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
     1455        pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
     1456
     1457        startX   = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight;
     1458        startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
     1459        firstY = (tPelY == 0) ? 1 : 0;
     1460        endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
     1461        if (firstY == 1)
     1462        {
     1463          pOrg += stride;
     1464          pRec += stride;
     1465        }
     1466
     1467        for (x=0; x< lcuWidth; x++)
     1468        {
     1469          m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]);
     1470        }
     1471        for (y=firstY; y<endY; y++)
     1472        {
     1473          for (x=0; x<lcuWidth; x++)
     1474          {
     1475            signDown     =  xSign(pRec[x] - pRec[x+stride]);
     1476            uiEdgeType    =  signDown + m_iUpBuff1[x] + 2;
     1477            m_iUpBuff1[x] = -signDown;
     1478
     1479            if( x < startX && y < startY )
     1480              continue;
     1481
     1482            stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1483            count[m_auiEoTable[uiEdgeType]] ++;
     1484          }
     1485          pOrg += stride;
     1486          pRec += stride;
     1487        }
     1488
     1489        //if (iSaoType == EO_2)
     1490
     1491        numSkipLine = isChroma? 2:4;
     1492        numSkipLineRight = isChroma? 3:5;
     1493
     1494        stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_2];
     1495        count = m_count_PreDblk[addr][yCbCr][SAO_EO_2];
     1496
     1497        pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
     1498        pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
     1499
     1500        startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
     1501        startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
     1502        firstX   = (lPelX == 0) ? 1 : 0;
     1503        firstY = (tPelY == 0) ? 1 : 0;
     1504        endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
     1505        endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
     1506        if (firstY == 1)
     1507        {
     1508          pOrg += stride;
     1509          pRec += stride;
     1510        }
     1511
     1512        for (x=firstX; x<endX; x++)
     1513        {
     1514          m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride-1]);
     1515        }
     1516        for (y=firstY; y<endY; y++)
     1517        {
     1518          signDown2 = xSign(pRec[stride+startX] - pRec[startX-1]);
     1519          for (x=firstX; x<endX; x++)
     1520          {
     1521            signDown1      =  xSign(pRec[x] - pRec[x+stride+1]) ;
     1522            uiEdgeType      =  signDown1 + m_iUpBuff1[x] + 2;
     1523            m_iUpBufft[x+1] = -signDown1;
     1524
     1525            if( x < startX && y < startY )
     1526              continue;
     1527
     1528            stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1529            count[m_auiEoTable[uiEdgeType]] ++;
     1530          }
     1531          m_iUpBufft[firstX] = signDown2;
     1532          ipSwap     = m_iUpBuff1;
     1533          m_iUpBuff1 = m_iUpBufft;
     1534          m_iUpBufft = ipSwap;
     1535
     1536          pRec += stride;
     1537          pOrg += stride;
     1538        }
     1539
     1540        //if (iSaoType == EO_3)
     1541
     1542        numSkipLine = isChroma? 2:4;
     1543        numSkipLineRight = isChroma? 3:5;
     1544
     1545        stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_3];
     1546        count = m_count_PreDblk[addr][yCbCr][SAO_EO_3];
     1547
     1548        pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
     1549        pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
     1550
     1551        startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
     1552        startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
     1553        firstX   = (lPelX == 0) ? 1 : 0;
     1554        firstY = (tPelY == 0) ? 1 : 0;
     1555        endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
     1556        endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
     1557        if (firstY == 1)
     1558        {
     1559          pOrg += stride;
     1560          pRec += stride;
     1561        }
     1562
     1563        for (x=firstX-1; x<endX; x++)
     1564        {
     1565          m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride+1]);
     1566        }
     1567
     1568        for (y=firstY; y<endY; y++)
     1569        {
     1570          for (x=firstX; x<endX; x++)
     1571          {
     1572            signDown1      =  xSign(pRec[x] - pRec[x+stride-1]) ;
     1573            uiEdgeType      =  signDown1 + m_iUpBuff1[x] + 2;
     1574            m_iUpBuff1[x-1] = -signDown1;
     1575
     1576            if( x < startX && y < startY )
     1577              continue;
     1578
     1579            stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1580            count[m_auiEoTable[uiEdgeType]] ++;
     1581          }
     1582          m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]);
     1583
     1584          pRec += stride;
     1585          pOrg += stride;
     1586        }
     1587      }
     1588    }
     1589  }
     1590}
     1591
     1592
     1593/** get SAO statistics
     1594 * \param  *psQTPart,  iYCbCr
     1595 */
     1596Void TEncSampleAdaptiveOffset::getSaoStats(SAOQTPart *psQTPart, Int iYCbCr)
     1597{
     1598  Int iLevelIdx, iPartIdx, iTypeIdx, iClassIdx;
     1599  Int i;
     1600  Int iNumTotalType = MAX_NUM_SAO_TYPE;
     1601  Int LcuIdxX;
     1602  Int LcuIdxY;
     1603  Int iAddr;
     1604  Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU();
     1605  Int iDownPartIdx;
     1606  Int iPartStart;
     1607  Int iPartEnd;
     1608  SAOQTPart*  pOnePart;
     1609
     1610  if (m_uiMaxSplitLevel == 0)
     1611  {
     1612    iPartIdx = 0;
     1613    pOnePart = &(psQTPart[iPartIdx]);
     1614    for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++)
     1615    {
     1616      for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++)
     1617      {
     1618        iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
     1619        calcSaoStatsCu(iAddr, iPartIdx, iYCbCr);
     1620      }
     1621    }
     1622  }
     1623  else
     1624  {
     1625    for(iPartIdx=m_aiNumCulPartsLevel[m_uiMaxSplitLevel-1]; iPartIdx<m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; iPartIdx++)
     1626    {
     1627      pOnePart = &(psQTPart[iPartIdx]);
     1628      for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++)
     1629      {
     1630        for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++)
     1631        {
     1632          iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
     1633          calcSaoStatsCu(iAddr, iPartIdx, iYCbCr);
     1634        }
     1635      }
     1636    }
     1637    for (iLevelIdx = m_uiMaxSplitLevel-1; iLevelIdx>=0; iLevelIdx-- )
     1638    {
     1639      iPartStart = (iLevelIdx > 0) ? m_aiNumCulPartsLevel[iLevelIdx-1] : 0;
     1640      iPartEnd   = m_aiNumCulPartsLevel[iLevelIdx];
     1641
     1642      for(iPartIdx = iPartStart; iPartIdx < iPartEnd; iPartIdx++)
     1643      {
     1644        pOnePart = &(psQTPart[iPartIdx]);
     1645        for (i=0; i< NUM_DOWN_PART; i++)
     1646        {
     1647          iDownPartIdx = pOnePart->DownPartsIdx[i];
     1648          for (iTypeIdx=0; iTypeIdx<iNumTotalType; iTypeIdx++)
     1649          {
     1650            for (iClassIdx=0; iClassIdx< (iTypeIdx < SAO_BO ? m_iNumClass[iTypeIdx] : SAO_MAX_BO_CLASSES) +1; iClassIdx++)
     1651            {
     1652              m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] += m_iOffsetOrg[iDownPartIdx][iTypeIdx][iClassIdx];
     1653              m_iCount [iPartIdx][iTypeIdx][iClassIdx]    += m_iCount [iDownPartIdx][iTypeIdx][iClassIdx];
     1654            }
     1655          }
     1656        }
     1657      }
     1658    }
     1659  }
     1660}
     1661
     1662/** reset offset statistics
     1663 * \param
     1664 */
     1665Void TEncSampleAdaptiveOffset::resetStats()
     1666{
     1667  for (Int i=0;i<m_iNumTotalParts;i++)
     1668  {
     1669    m_dCostPartBest[i] = MAX_DOUBLE;
     1670    m_iTypePartBest[i] = -1;
     1671    m_iDistOrg[i] = 0;
     1672    for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
     1673    {
     1674      m_iDist[i][j] = 0;
     1675      m_iRate[i][j] = 0;
     1676      m_dCost[i][j] = 0;
     1677      for (Int k=0;k<MAX_NUM_SAO_CLASS;k++)
     1678      {
     1679        m_iCount [i][j][k] = 0;
     1680        m_iOffset[i][j][k] = 0;
     1681        m_iOffsetOrg[i][j][k] = 0;
     1682      } 
     1683    }
     1684  }
     1685}
     1686
     1687#if SAO_CHROMA_LAMBDA
     1688/** Sample adaptive offset process
     1689 * \param pcSaoParam
     1690 * \param dLambdaLuma
     1691 * \param dLambdaChroma
     1692 */
     1693#if SAO_ENCODING_CHOICE
     1694Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma, Int depth)
     1695#else
     1696Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma)
     1697#endif
     1698#else
     1699/** Sample adaptive offset process
     1700 * \param dLambda
     1701 */
     1702Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambda)
     1703#endif
     1704{
     1705    m_eSliceType          =  m_pcPic->getSlice(0)->getSliceType();
     1706    m_iPicNalReferenceIdc = (m_pcPic->getSlice(0)->isReferenced() ? 1 :0);
     1707
     1708#if SAO_CHROMA_LAMBDA
     1709    m_dLambdaLuma    = dLambdaLuma;
     1710    m_dLambdaChroma  = dLambdaChroma;
     1711#else
     1712    m_dLambdaLuma    = dLambda;
     1713    m_dLambdaChroma  = dLambda;
     1714#endif
     1715
     1716    if(m_bUseNIF)
     1717    {
     1718        m_pcPic->getPicYuvRec()->copyToPic(m_pcYuvTmp);
     1719    }
     1720
     1721#if FULL_NBIT
     1722    m_uiSaoBitIncrease = g_uiBitDepth + (g_uiBitDepth-8) - min((Int)(g_uiBitDepth + (g_uiBitDepth-8)), 10);
     1723#else
     1724    m_uiSaoBitIncrease = g_uiBitDepth + g_uiBitIncrement - min((Int)(g_uiBitDepth + g_uiBitIncrement), 10);
     1725#endif
     1726
     1727#if FULL_NBIT
     1728    m_iOffsetTh = 1 << ( min((Int)(g_uiBitDepth + (g_uiBitDepth-8)-5),5) );
     1729#else
     1730    m_iOffsetTh = 1 << ( min((Int)(g_uiBitDepth + g_uiBitIncrement-5),5) );
     1731#endif
     1732
     1733    resetSAOParam(pcSaoParam);
     1734    if( !m_saoLcuBasedOptimization || !m_saoLcuBoundary )
     1735    {
     1736        resetStats();
     1737    }
     1738    Double dCostFinal = 0;
     1739    if ( m_saoLcuBasedOptimization)
     1740    {
     1741#if SAO_ENCODING_CHOICE
     1742        rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma, depth);
     1743#else
     1744        rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma);
     1745#endif
     1746    }
     1747    else
     1748    {
     1749        pcSaoParam->bSaoFlag[0] = 1;
     1750        pcSaoParam->bSaoFlag[1] = 0;
     1751        dCostFinal = 0;
     1752        Double lambdaRdo =  dLambdaLuma;
     1753        resetStats();
     1754        getSaoStats(pcSaoParam->psSaoPart[0], 0);
     1755        runQuadTreeDecision(pcSaoParam->psSaoPart[0], 0, dCostFinal, m_uiMaxSplitLevel, lambdaRdo, 0);
     1756        pcSaoParam->bSaoFlag[0] = dCostFinal < 0 ? 1:0;
     1757        if(pcSaoParam->bSaoFlag[0])
     1758        {
     1759            convertQT2SaoUnit(pcSaoParam, 0, 0);
     1760            assignSaoUnitSyntax(pcSaoParam->saoLcuParam[0],  pcSaoParam->psSaoPart[0], pcSaoParam->oneUnitFlag[0], 0);
     1761        }
     1762    }
     1763
     1764    if (pcSaoParam->bSaoFlag[0])
     1765    {
     1766        processSaoUnitAll( pcSaoParam->saoLcuParam[0], pcSaoParam->oneUnitFlag[0], 0);
     1767    }
     1768    if (pcSaoParam->bSaoFlag[1])
     1769    {
     1770        processSaoUnitAll( pcSaoParam->saoLcuParam[1], pcSaoParam->oneUnitFlag[1], 1);
     1771        processSaoUnitAll( pcSaoParam->saoLcuParam[2], pcSaoParam->oneUnitFlag[2], 2);
     1772    }
     1773}
     1774/** Check merge SAO unit
     1775* \param saoUnitCurr current SAO unit
     1776* \param saoUnitCheck SAO unit tobe check
     1777* \param dir direction
     1778*/
     1779Void TEncSampleAdaptiveOffset::checkMerge(SaoLcuParam * saoUnitCurr, SaoLcuParam * saoUnitCheck, Int dir)
     1780{
     1781    Int i ;
     1782    Int countDiff = 0;
     1783    if (saoUnitCurr->partIdx != saoUnitCheck->partIdx)
     1784    {
     1785        if (saoUnitCurr->typeIdx !=-1)
     1786        {
     1787            if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx)
     1788            {
     1789                for (i=0;i<saoUnitCurr->length;i++)
     1790                {
     1791                    countDiff += (saoUnitCurr->offset[i] != saoUnitCheck->offset[i]);
     1792                }
     1793                countDiff += (saoUnitCurr->subTypeIdx != saoUnitCheck->subTypeIdx);
     1794                if (countDiff ==0)
     1795                {
     1796                    saoUnitCurr->partIdx = saoUnitCheck->partIdx;
     1797                    if (dir == 1)
     1798                    {
     1799                        saoUnitCurr->mergeUpFlag = 1;
     1800                        saoUnitCurr->mergeLeftFlag = 0;
     1801                    }
     1802                    else
     1803                    {
     1804                        saoUnitCurr->mergeUpFlag = 0;
     1805                        saoUnitCurr->mergeLeftFlag = 1;
     1806                    }
     1807                }
     1808            }
     1809        }
     1810        else
     1811        {
     1812            if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx)
     1813            {
     1814                saoUnitCurr->partIdx = saoUnitCheck->partIdx;
     1815                if (dir == 1)
     1816                {
     1817                    saoUnitCurr->mergeUpFlag = 1;
     1818                    saoUnitCurr->mergeLeftFlag = 0;
     1819                }
     1820                else
     1821                {
     1822                    saoUnitCurr->mergeUpFlag = 0;
     1823                    saoUnitCurr->mergeLeftFlag = 1;
     1824                }
     1825            }
     1826        }
     1827    }
     1828}
     1829/** Assign SAO unit syntax from picture-based algorithm
     1830* \param saoLcuParam SAO LCU parameters
     1831* \param saoPart SAO part
     1832* \param oneUnitFlag SAO one unit flag
     1833* \param iYCbCr color component Index
     1834*/
     1835Void TEncSampleAdaptiveOffset::assignSaoUnitSyntax(SaoLcuParam* saoLcuParam,  SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr)
     1836{
     1837    if (saoPart->bSplit == 0)
     1838    {
     1839        oneUnitFlag = 1;
     1840    }
     1841    else
     1842    {
     1843        Int i,j, addr, addrUp, addrLeft,  idx, idxUp, idxLeft,  idxCount;
     1844   
     1845        oneUnitFlag = 0;
     1846       
     1847        idxCount = -1;
     1848        saoLcuParam[0].mergeUpFlag = 0;
     1849        saoLcuParam[0].mergeLeftFlag = 0;
     1850       
     1851        for (j=0;j<m_iNumCuInHeight;j++)
     1852        {
     1853            for (i=0;i<m_iNumCuInWidth;i++)
     1854            {
     1855                addr     = i + j*m_iNumCuInWidth;
     1856                addrLeft = (addr%m_iNumCuInWidth == 0) ? -1 : addr - 1;
     1857                addrUp   = (addr<m_iNumCuInWidth)      ? -1 : addr - m_iNumCuInWidth;
     1858                idx      = saoLcuParam[addr].partIdxTmp;
     1859                idxLeft  = (addrLeft == -1) ? -1 : saoLcuParam[addrLeft].partIdxTmp;
     1860                idxUp    = (addrUp == -1)   ? -1 : saoLcuParam[addrUp].partIdxTmp;
     1861
     1862                if(idx!=idxLeft && idx!=idxUp)
     1863                {
     1864                    saoLcuParam[addr].mergeUpFlag   = 0; idxCount++;
     1865                    saoLcuParam[addr].mergeLeftFlag = 0;
     1866                    saoLcuParam[addr].partIdx = idxCount;
     1867                }
     1868                else if (idx==idxLeft)
     1869                {       
     1870                    saoLcuParam[addr].mergeUpFlag   = 1;
     1871                    saoLcuParam[addr].mergeLeftFlag = 1;
     1872                    saoLcuParam[addr].partIdx = saoLcuParam[addrLeft].partIdx;
     1873                }
     1874                else if (idx==idxUp)
     1875                {
     1876                    saoLcuParam[addr].mergeUpFlag   = 1;
     1877                    saoLcuParam[addr].mergeLeftFlag = 0;
     1878                    saoLcuParam[addr].partIdx = saoLcuParam[addrUp].partIdx;
     1879                }
     1880                if (addrUp != -1)
     1881                {
     1882                    checkMerge(&saoLcuParam[addr], &saoLcuParam[addrUp], 1);
     1883                }
     1884                if (addrLeft != -1)
     1885                {
     1886                    checkMerge(&saoLcuParam[addr], &saoLcuParam[addrLeft], 0);
     1887                }
     1888            }
     1889        }
     1890    }
     1891}
     1892/** rate distortion optimization of all SAO units
     1893* \param saoParam SAO parameters
     1894* \param lambda
     1895* \param lambdaChroma
     1896*/
     1897#if SAO_ENCODING_CHOICE
     1898Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth)
     1899#else
     1900Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma)
     1901#endif
     1902{
     1903    Int idxY;
     1904    Int idxX;
     1905    Int frameHeightInCU = saoParam->numCuInHeight;
     1906    Int frameWidthInCU  = saoParam->numCuInWidth;
     1907    Int j, k;
     1908    Int addr = 0;
     1909    Int addrUp = -1;
     1910    Int addrLeft = -1;
     1911    Int compIdx = 0;
     1912    SaoLcuParam mergeSaoParam[3][2];
     1913    Double compDistortion[3];
     1914
     1915    saoParam->bSaoFlag[0] = true;
     1916    saoParam->bSaoFlag[1] = true;
     1917    saoParam->oneUnitFlag[0] = false;
     1918    saoParam->oneUnitFlag[1] = false;
     1919    saoParam->oneUnitFlag[2] = false;
     1920
     1921#if SAO_ENCODING_CHOICE
     1922#if SAO_ENCODING_CHOICE_CHROMA
     1923    Int numNoSao[2];
     1924    numNoSao[0] = 0;// Luma
     1925    numNoSao[1] = 0;// Chroma
     1926    if( depth > 0 && m_depthSaoRate[0][depth-1] > SAO_ENCODING_RATE )
     1927    {
     1928        saoParam->bSaoFlag[0] = false;
     1929    }
     1930
     1931    if( depth > 0 && m_depthSaoRate[1][depth-1] > SAO_ENCODING_RATE_CHROMA )
     1932    {
     1933        saoParam->bSaoFlag[1] = false;
     1934    }
     1935#else
     1936    Int numNoSao = 0;
     1937
     1938    if( depth > 0 && m_depth0SaoRate > SAO_ENCODING_RATE )
     1939    {
     1940        saoParam->bSaoFlag[0] = false;
     1941        saoParam->bSaoFlag[1] = false;
     1942    }
     1943#endif
     1944#endif
     1945
     1946    for (idxY = 0; idxY< frameHeightInCU; idxY++)
     1947    {
     1948        for (idxX = 0; idxX< frameWidthInCU; idxX++)
     1949        {
     1950            addr     = idxX  + frameWidthInCU*idxY;
     1951            addrUp   = addr < frameWidthInCU ? -1:idxX   + frameWidthInCU*(idxY-1);
     1952            addrLeft = idxX == 0               ? -1:idxX-1 + frameWidthInCU*idxY;
     1953            Int allowMergeLeft = 1;
     1954            Int allowMergeUp   = 1;
     1955            UInt rate;
     1956            Double bestCost, mergeCost;
     1957
     1958            if (idxX!=0)
     1959            {
     1960                // check tile id and slice id
     1961                if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     1962                {
     1963                    allowMergeLeft = 0;
     1964                }
     1965            }
     1966            else
     1967            {
     1968                allowMergeLeft = 0;
     1969            }
     1970            if (idxY!=0)
     1971            {
     1972                if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     1973                {
     1974                    allowMergeUp = 0;
     1975                }
     1976            }
     1977            else
     1978            {
     1979                allowMergeUp = 0;
     1980            }
     1981
     1982            compDistortion[0] = 0;
     1983            compDistortion[1] = 0;
     1984            compDistortion[2] = 0;
     1985            m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
     1986
     1987            if (allowMergeLeft)
     1988            {
     1989                m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
     1990            }
     1991            if (allowMergeUp)
     1992            {
     1993                m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
     1994            }
     1995
     1996            m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
     1997
     1998            // reset stats Y, Cb, Cr
     1999            for ( compIdx=0;compIdx<3;compIdx++)
     2000            {
     2001                for ( j=0;j<MAX_NUM_SAO_TYPE;j++)
     2002                {
     2003                    for ( k=0;k< MAX_NUM_SAO_CLASS;k++)
     2004                    {
     2005                        m_iOffset   [compIdx][j][k] = 0;
     2006                        if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     2007                        {
     2008                            m_iCount    [compIdx][j][k] = m_count_PreDblk    [addr][compIdx][j][k];
     2009                            m_iOffsetOrg[compIdx][j][k] = m_offsetOrg_PreDblk[addr][compIdx][j][k];
     2010                        }
     2011                        else
     2012                        {
     2013                            m_iCount    [compIdx][j][k] = 0;
     2014                            m_iOffsetOrg[compIdx][j][k] = 0;
     2015                        }
     2016                    } 
     2017                }
     2018                saoParam->saoLcuParam[compIdx][addr].typeIdx       =  -1;
     2019                saoParam->saoLcuParam[compIdx][addr].mergeUpFlag   = 0;
     2020                saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag = 0;
     2021                saoParam->saoLcuParam[compIdx][addr].subTypeIdx    = 0;
     2022#if SAO_ENCODING_CHOICE
     2023                if( (compIdx ==0 && saoParam->bSaoFlag[0])|| (compIdx >0 && saoParam->bSaoFlag[1]) )
     2024#endif
     2025                {
     2026                    calcSaoStatsCu(addr, compIdx,  compIdx);
     2027                }
     2028            }
     2029            saoComponentParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, 0,  lambda, &mergeSaoParam[0][0], &compDistortion[0]);
     2030            sao2ChromaParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, lambdaChroma, &mergeSaoParam[1][0], &mergeSaoParam[2][0], &compDistortion[0]);
     2031            if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] )
     2032            {
     2033                // Cost of new SAO_params
     2034                m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
     2035                m_pcRDGoOnSbacCoder->resetBits();
     2036                if (allowMergeLeft)
     2037                {
     2038                    m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
     2039                }
     2040                if (allowMergeUp)
     2041                {
     2042                    m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
     2043                }
     2044                for ( compIdx=0;compIdx<3;compIdx++)
     2045                {
     2046                    if( (compIdx ==0 && saoParam->bSaoFlag[0]) || (compIdx >0 && saoParam->bSaoFlag[1]))
     2047                    {
     2048                        m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx);
     2049                    }
     2050                }
     2051   
     2052                rate = m_pcEntropyCoder->getNumberOfWrittenBits();
     2053                bestCost = compDistortion[0] + (Double)rate;
     2054                m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2055   
     2056                // Cost of Merge
     2057                for(Int mergeUp=0; mergeUp<2; ++mergeUp)
     2058                {
     2059                    if ( (allowMergeLeft && (mergeUp==0)) || (allowMergeUp && (mergeUp==1)) )
     2060                    {
     2061                        m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
     2062                        m_pcRDGoOnSbacCoder->resetBits();
     2063                        if (allowMergeLeft)
     2064                        {
     2065                            m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1-mergeUp);
     2066                        }
     2067                        if ( allowMergeUp && (mergeUp==1) )
     2068                        {
     2069                            m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1);
     2070                        }
     2071   
     2072                        rate = m_pcEntropyCoder->getNumberOfWrittenBits();
     2073                        mergeCost = compDistortion[mergeUp+1] + (Double)rate;
     2074                        if (mergeCost < bestCost)
     2075                        {
     2076                            bestCost = mergeCost;
     2077                            m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);             
     2078                            for ( compIdx=0;compIdx<3;compIdx++)
     2079                            {
     2080                                mergeSaoParam[compIdx][mergeUp].mergeLeftFlag = 1-mergeUp;
     2081                                mergeSaoParam[compIdx][mergeUp].mergeUpFlag = mergeUp;
     2082                                if( (compIdx==0 && saoParam->bSaoFlag[0]) || (compIdx>0 && saoParam->bSaoFlag[1]))
     2083                                {
     2084                                    copySaoUnit(&saoParam->saoLcuParam[compIdx][addr], &mergeSaoParam[compIdx][mergeUp] );             
     2085                                }
     2086                            }
     2087                        }
     2088                    }
     2089                }
     2090#if SAO_ENCODING_CHOICE
     2091#if SAO_ENCODING_CHOICE_CHROMA
     2092                if( saoParam->saoLcuParam[0][addr].typeIdx == -1)
     2093                {
     2094                    numNoSao[0]++;
     2095                }
     2096                if( saoParam->saoLcuParam[1][addr].typeIdx == -1)
     2097                {
     2098                    numNoSao[1]+=2;
     2099                }
     2100#else
     2101                for ( compIdx=0;compIdx<3;compIdx++)
     2102                {
     2103                    if( depth == 0 && saoParam->saoLcuParam[compIdx][addr].typeIdx == -1)
     2104                    {
     2105                        numNoSao++;
     2106                    }
     2107                }
     2108#endif
     2109#endif
     2110                m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2111                m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
     2112            }
     2113        }
     2114    }
     2115#if SAO_ENCODING_CHOICE
     2116#if SAO_ENCODING_CHOICE_CHROMA
     2117#if SAO_ENCODING_CHOICE_CHROMA_BF
     2118    if( !saoParam->bSaoFlag[0])
     2119    {
     2120        m_depthSaoRate[0][depth] = 1.0;
     2121    }
     2122    else
     2123    {
     2124        m_depthSaoRate[0][depth] = numNoSao[0]/((Double) frameHeightInCU*frameWidthInCU);
     2125    }
     2126    if( !saoParam->bSaoFlag[1])
     2127    {
     2128        m_depthSaoRate[1][depth] = 1.0;
     2129    }
     2130    else
     2131    {
     2132        m_depthSaoRate[1][depth] = numNoSao[1]/((Double) frameHeightInCU*frameWidthInCU*2);
     2133    }
     2134#else
     2135    m_depthSaoRate[0][depth] = numNoSao[0]/((Double) frameHeightInCU*frameWidthInCU);
     2136    m_depthSaoRate[1][depth] = numNoSao[1]/((Double) frameHeightInCU*frameWidthInCU*2);
     2137#endif
     2138#else
     2139    if( depth == 0)
     2140    {
     2141        // update SAO Rate
     2142        m_depth0SaoRate = numNoSao/((Double) frameHeightInCU*frameWidthInCU*3);
     2143    }
     2144#endif
     2145#endif
     2146}
     2147/** rate distortion optimization of SAO unit
     2148* \param saoParam SAO parameters
     2149* \param addr address
     2150* \param addrUp above address
     2151* \param addrLeft left address
     2152* \param yCbCr color component index
     2153* \param lambda
     2154*/
     2155inline Int64 TEncSampleAdaptiveOffset::estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo)
     2156{
     2157    Int64 estDist = 0;
     2158    Int classIdx;
     2159    for(classIdx=1; classIdx < ( (typeIdx < SAO_BO) ?  m_iNumClass[typeIdx]+1 : SAO_MAX_BO_CLASSES+1); classIdx++)
     2160    {
     2161        if( typeIdx == SAO_BO)
     2162        {
     2163            currentDistortionTableBo[classIdx-1] = 0;
     2164            currentRdCostTableBo[classIdx-1] = lambda;
     2165        }
     2166        if(m_iCount [compIdx][typeIdx][classIdx])
     2167        {
     2168#if FULL_NBIT
     2169            m_iOffset[compIdx][typeIdx][classIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[compIdx][typeIdx][classIdx]<<g_uiBitDepth-8)   / (Double)(m_iCount [compIdx][typeIdx][classIdx]<<m_uiSaoBitIncrease));
     2170#else
     2171            m_iOffset[compIdx][typeIdx][classIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[compIdx][typeIdx][classIdx]<<g_uiBitIncrement) / (Double)(m_iCount [compIdx][typeIdx][classIdx]<<m_uiSaoBitIncrease));
     2172#endif
     2173            m_iOffset[compIdx][typeIdx][classIdx] = Clip3(-m_iOffsetTh+1, m_iOffsetTh-1, (Int)m_iOffset[compIdx][typeIdx][classIdx]);
     2174            if (typeIdx < 4)
     2175            {
     2176                if ( m_iOffset[compIdx][typeIdx][classIdx]<0 && classIdx<3 )
     2177                {
     2178                    m_iOffset[compIdx][typeIdx][classIdx] = 0;
     2179                }
     2180                if ( m_iOffset[compIdx][typeIdx][classIdx]>0 && classIdx>=3)
     2181                {
     2182                    m_iOffset[compIdx][typeIdx][classIdx] = 0;
     2183                }
     2184            }
     2185            m_iOffset[compIdx][typeIdx][classIdx] = estIterOffset( typeIdx, classIdx, lambda, m_iOffset[compIdx][typeIdx][classIdx], m_iCount [compIdx][typeIdx][classIdx], m_iOffsetOrg[compIdx][typeIdx][classIdx], shift, m_uiSaoBitIncrease, currentDistortionTableBo, currentRdCostTableBo );
     2186        }
     2187        else
     2188        {
     2189            m_iOffsetOrg[compIdx][typeIdx][classIdx] = 0;
     2190            m_iOffset[compIdx][typeIdx][classIdx] = 0;
     2191        }
     2192        if( typeIdx != SAO_BO )
     2193        {
     2194            estDist   += estSaoDist( m_iCount [compIdx][typeIdx][classIdx], m_iOffset[compIdx][typeIdx][classIdx] << m_uiSaoBitIncrease, m_iOffsetOrg[compIdx][typeIdx][classIdx], shift);
     2195        }
     2196    }
     2197    return estDist;
     2198}
     2199
     2200inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift)
     2201{
     2202    return (( count*offset*offset-offsetOrg*offset*2 ) >> shift);
     2203}
     2204inline Int64 TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Int classIdx, double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo )
     2205{
     2206    //Clean up, best_q_offset.
     2207    Int64 iterOffset, tempOffset;
     2208    Int64 tempDist, tempRate;
     2209    Double tempCost, tempMinCost;
     2210    Int64 offsetOutput = 0;
     2211    iterOffset = offsetInput;
     2212    // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here.
     2213    tempMinCost = lambda;
     2214    while (iterOffset != 0)
     2215    {
     2216        // Calculate the bits required for signalling the offset
     2217        tempRate = (typeIdx == SAO_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1);
     2218        if (abs((Int)iterOffset)==m_iOffsetTh-1)
     2219        { 
     2220            tempRate --;
     2221        }
     2222        // Do the dequntization before distorion calculation
     2223        tempOffset  = iterOffset << bitIncrease;
     2224        tempDist    = estSaoDist( count, tempOffset, offsetOrg, shift);
     2225        tempCost    = ((Double)tempDist + lambda * (Double) tempRate);
     2226        if(tempCost < tempMinCost)
     2227        {
     2228            tempMinCost = tempCost;
     2229            offsetOutput = iterOffset;
     2230            if(typeIdx == SAO_BO)
     2231            {
     2232                currentDistortionTableBo[classIdx-1] = (Int) tempDist;
     2233                currentRdCostTableBo[classIdx-1] = tempCost;
     2234            }
     2235        }
     2236        iterOffset = (iterOffset > 0) ? (iterOffset-1):(iterOffset+1);
     2237    }
     2238    return offsetOutput;
     2239}
     2240
     2241Void TEncSampleAdaptiveOffset::saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *compDistortion)
     2242{
     2243    Int typeIdx;
     2244    Int64 estDist;
     2245    Int classIdx;
     2246
     2247    Int shift = g_uiBitIncrement << 1;
     2248
     2249    Int64 bestDist;
     2250
     2251    SaoLcuParam*  saoLcuParam = &(saoParam->saoLcuParam[yCbCr][addr]);
     2252    SaoLcuParam*  saoLcuParamNeighbor = NULL;
     2253
     2254    resetSaoUnit(saoLcuParam);
     2255    resetSaoUnit(&compSaoParam[0]);
     2256    resetSaoUnit(&compSaoParam[1]);
     2257
     2258    Double dCostPartBest = MAX_DOUBLE;
     2259
     2260    Double  bestRDCostTableBo = MAX_DOUBLE;
     2261    Int     bestClassTableBo    = 0;
     2262    Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
     2263    Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
     2264
     2265    SaoLcuParam   saoLcuParamRdo;   
     2266    Double   estRate = 0;
     2267
     2268    resetSaoUnit(&saoLcuParamRdo);
     2269
     2270    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2271    m_pcRDGoOnSbacCoder->resetBits();
     2272    m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr);
     2273    dCostPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ;
     2274
     2275    copySaoUnit(saoLcuParam, &saoLcuParamRdo );
     2276
     2277    bestDist = 0;
     2278
     2279    for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++)
     2280    {
     2281        estDist = estSaoTypeDist(yCbCr, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
     2282        if( typeIdx == SAO_BO )
     2283        {
     2284            // Estimate Best Position
     2285            Double currentRDCost = 0.0;
     2286
     2287            for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
     2288            {
     2289                currentRDCost = 0.0;
     2290                for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
     2291                {
     2292                    currentRDCost += currentRdCostTableBo[uj];
     2293                }
     2294
     2295                if( currentRDCost < bestRDCostTableBo)
     2296                {
     2297                    bestRDCostTableBo = currentRDCost;
     2298                    bestClassTableBo  = i;
     2299                }
     2300            }
     2301
     2302            // Re code all Offsets
     2303            // Code Center
     2304            estDist = 0;
     2305            for(classIdx = bestClassTableBo; classIdx < bestClassTableBo+SAO_BO_LEN; classIdx++)
     2306            {
     2307                estDist += currentDistortionTableBo[classIdx];
     2308            }
     2309        }
     2310        resetSaoUnit(&saoLcuParamRdo);
     2311        saoLcuParamRdo.length = m_iNumClass[typeIdx];
     2312        saoLcuParamRdo.typeIdx = typeIdx;
     2313        saoLcuParamRdo.mergeLeftFlag = 0;
     2314        saoLcuParamRdo.mergeUpFlag   = 0;
     2315        saoLcuParamRdo.subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo : 0;
     2316        for (classIdx = 0; classIdx < saoLcuParamRdo.length; classIdx++)
     2317        {
     2318            saoLcuParamRdo.offset[classIdx] = (Int)m_iOffset[yCbCr][typeIdx][classIdx+saoLcuParamRdo.subTypeIdx+1];
     2319        }
     2320        m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2321        m_pcRDGoOnSbacCoder->resetBits();
     2322        m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr);
     2323
     2324        estRate = m_pcEntropyCoder->getNumberOfWrittenBits();
     2325        m_dCost[yCbCr][typeIdx] = (Double)((Double)estDist + lambda * (Double) estRate);
     2326
     2327        if(m_dCost[yCbCr][typeIdx] < dCostPartBest)
     2328        {
     2329            dCostPartBest = m_dCost[yCbCr][typeIdx];
     2330            copySaoUnit(saoLcuParam, &saoLcuParamRdo );
     2331            bestDist = estDist;       
     2332        }
     2333    }
     2334
     2335    compDistortion[0] += ((Double)bestDist/lambda);
     2336    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2337    m_pcEntropyCoder->encodeSaoOffset(saoLcuParam, yCbCr);
     2338    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
     2339
     2340    // merge left or merge up
     2341    for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++)
     2342    {
     2343        saoLcuParamNeighbor = NULL;
     2344        if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0)
     2345        {
     2346            saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrLeft]);
     2347        }
     2348        else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1)
     2349        {
     2350            saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrUp]);
     2351        }
     2352        if (saoLcuParamNeighbor!=NULL)
     2353        {
     2354            estDist = 0;
     2355            typeIdx = saoLcuParamNeighbor->typeIdx;
     2356            if (typeIdx>=0)
     2357            {
     2358                Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor->subTypeIdx:0;
     2359                Int   merge_iOffset;
     2360                for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++)
     2361                {
     2362                    merge_iOffset = saoLcuParamNeighbor->offset[classIdx];
     2363                    estDist   += estSaoDist(m_iCount [yCbCr][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[yCbCr][typeIdx][classIdx+mergeBandPosition+1],  shift);
     2364                }
     2365            }
     2366            else
     2367            {
     2368                estDist = 0;
     2369            }
     2370
     2371            copySaoUnit(&compSaoParam[idxNeighbor], saoLcuParamNeighbor );
     2372            compSaoParam[idxNeighbor].mergeUpFlag   = idxNeighbor;
     2373            compSaoParam[idxNeighbor].mergeLeftFlag = !idxNeighbor;
     2374
     2375            compDistortion[idxNeighbor+1] += ((Double)estDist/lambda);
     2376        }
     2377    }
     2378}
     2379
     2380Void TEncSampleAdaptiveOffset::sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion)
     2381{
     2382    Int typeIdx;
     2383
     2384    Int64 estDist[2];
     2385    Int classIdx;
     2386    Int shift = g_uiBitIncrement << 1;
     2387    Int64 bestDist = 0;
     2388
     2389    SaoLcuParam*  saoLcuParam[2] = {&(saoParam->saoLcuParam[1][addr]), &(saoParam->saoLcuParam[2][addr])};
     2390    SaoLcuParam*  saoLcuParamNeighbor[2] = {NULL, NULL};
     2391    SaoLcuParam*  saoMergeParam[2][2];
     2392    saoMergeParam[0][0] = &crSaoParam[0];
     2393    saoMergeParam[0][1] = &crSaoParam[1];
     2394    saoMergeParam[1][0] = &cbSaoParam[0];
     2395    saoMergeParam[1][1] = &cbSaoParam[1];
     2396
     2397    resetSaoUnit(saoLcuParam[0]);
     2398    resetSaoUnit(saoLcuParam[1]);
     2399    resetSaoUnit(saoMergeParam[0][0]);
     2400    resetSaoUnit(saoMergeParam[0][1]);
     2401    resetSaoUnit(saoMergeParam[1][0]);
     2402    resetSaoUnit(saoMergeParam[1][1]);
     2403
     2404    Double costPartBest = MAX_DOUBLE;
     2405
     2406    Double  bestRDCostTableBo;
     2407    Int     bestClassTableBo[2]    = {0, 0};
     2408    Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
     2409    Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
     2410
     2411    SaoLcuParam   saoLcuParamRdo[2];   
     2412    Double   estRate = 0;
     2413
     2414    resetSaoUnit(&saoLcuParamRdo[0]);
     2415    resetSaoUnit(&saoLcuParamRdo[1]);
     2416
     2417    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2418    m_pcRDGoOnSbacCoder->resetBits();
     2419    m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[0], 1);
     2420    m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[1], 2);
     2421
     2422    costPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ;
     2423    copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] );
     2424    copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] );
     2425
     2426    for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++)
     2427    {
     2428        if( typeIdx == SAO_BO )
     2429        {
     2430            // Estimate Best Position
     2431            for(Int compIdx = 0; compIdx < 2; compIdx++)
     2432            {
     2433                Double currentRDCost = 0.0;
     2434                bestRDCostTableBo = MAX_DOUBLE;
     2435                estDist[compIdx] = estSaoTypeDist(compIdx+1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
     2436
     2437                for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
     2438                {
     2439                    currentRDCost = 0.0;
     2440                    for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
     2441                    {
     2442                        currentRDCost += currentRdCostTableBo[uj];
     2443                    }
     2444
     2445                    if( currentRDCost < bestRDCostTableBo)
     2446                    {
     2447                        bestRDCostTableBo = currentRDCost;
     2448                        bestClassTableBo[compIdx]  = i;
     2449                    }
     2450                }
     2451
     2452                // Re code all Offsets
     2453                // Code Center
     2454                estDist[compIdx] = 0;
     2455                for(classIdx = bestClassTableBo[compIdx]; classIdx < bestClassTableBo[compIdx]+SAO_BO_LEN; classIdx++)
     2456                {
     2457                    estDist[compIdx] += currentDistortionTableBo[classIdx];
     2458                }
     2459            }
     2460        }
     2461        else
     2462        {
     2463            estDist[0] = estSaoTypeDist(1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
     2464            estDist[1] = estSaoTypeDist(2, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
     2465        }
     2466
     2467        m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2468        m_pcRDGoOnSbacCoder->resetBits();
     2469
     2470        for(Int compIdx = 0; compIdx < 2; compIdx++)
     2471        {
     2472            resetSaoUnit(&saoLcuParamRdo[compIdx]);
     2473            saoLcuParamRdo[compIdx].length = m_iNumClass[typeIdx];
     2474            saoLcuParamRdo[compIdx].typeIdx = typeIdx;
     2475            saoLcuParamRdo[compIdx].mergeLeftFlag = 0;
     2476            saoLcuParamRdo[compIdx].mergeUpFlag   = 0;
     2477            saoLcuParamRdo[compIdx].subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo[compIdx] : 0;
     2478            for (classIdx = 0; classIdx < saoLcuParamRdo[compIdx].length; classIdx++)
     2479            {
     2480                saoLcuParamRdo[compIdx].offset[classIdx] = (Int)m_iOffset[compIdx+1][typeIdx][classIdx+saoLcuParamRdo[compIdx].subTypeIdx+1];
     2481            }
     2482            m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[compIdx], compIdx+1);
     2483        }
     2484        estRate = m_pcEntropyCoder->getNumberOfWrittenBits();
     2485        m_dCost[1][typeIdx] = (Double)((Double)(estDist[0] + estDist[1])  + lambda * (Double) estRate);
     2486
     2487        if(m_dCost[1][typeIdx] < costPartBest)
     2488        {
     2489            costPartBest = m_dCost[1][typeIdx];
     2490            copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] );
     2491            copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] );
     2492            bestDist = (estDist[0]+estDist[1]);       
     2493        }
     2494    }
     2495
     2496    distortion[0] += ((Double)bestDist/lambda);
     2497    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2498    m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[0], 1);
     2499    m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[1], 2);
     2500    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
     2501
     2502    // merge left or merge up
     2503
     2504    for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++)
     2505    {
     2506        for(Int compIdx = 0; compIdx < 2; compIdx++)
     2507        {
     2508            saoLcuParamNeighbor[compIdx] = NULL;
     2509            if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0)
     2510            {
     2511                saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrLeft]);
     2512            }
     2513            else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1)
     2514            {
     2515                saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrUp]);
     2516            }
     2517            if (saoLcuParamNeighbor[compIdx]!=NULL)
     2518            {
     2519                estDist[compIdx] = 0;
     2520                typeIdx = saoLcuParamNeighbor[compIdx]->typeIdx;
     2521                if (typeIdx>=0)
     2522                {
     2523                    Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor[compIdx]->subTypeIdx:0;
     2524                    Int   merge_iOffset;
     2525                    for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++)
     2526                    {
     2527                        merge_iOffset = saoLcuParamNeighbor[compIdx]->offset[classIdx];
     2528                        estDist[compIdx]   += estSaoDist(m_iCount [compIdx+1][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[compIdx+1][typeIdx][classIdx+mergeBandPosition+1],  shift);
     2529                    }
     2530                }
     2531                else
     2532                {
     2533                    estDist[compIdx] = 0;
     2534                }
     2535
     2536                copySaoUnit(saoMergeParam[compIdx][idxNeighbor], saoLcuParamNeighbor[compIdx] );
     2537                saoMergeParam[compIdx][idxNeighbor]->mergeUpFlag   = idxNeighbor;
     2538                saoMergeParam[compIdx][idxNeighbor]->mergeLeftFlag = !idxNeighbor;
     2539                distortion[idxNeighbor+1] += ((Double)estDist[compIdx]/lambda);
     2540            }
     2541        }
     2542    }
     2543}
     2544#else
     2545TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
     2546{
     2547  m_pcEntropyCoder = NULL;
     2548  m_pppcRDSbacCoder = NULL;
     2549  m_pcRDGoOnSbacCoder = NULL;
     2550  m_pppcBinCoderCABAC = NULL;           
     2551  m_iCount = NULL;     
     2552  m_iOffset = NULL;     
     2553  m_iOffsetOrg = NULL; 
     2554  m_iRate = NULL;       
     2555  m_iDist = NULL;       
     2556  m_dCost = NULL;       
     2557  m_dCostPartBest = NULL;
     2558  m_iDistOrg = NULL;     
     2559  m_iTypePartBest = NULL;
     2560}
     2561TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()
     2562{
     2563
     2564}
     2565// ====================================================================================================================
     2566// Constants
     2567// ====================================================================================================================
     2568
     2569
     2570// ====================================================================================================================
     2571// Tables
     2572// ====================================================================================================================
     2573
     2574inline Double xRoundIbdi2(Double x)
     2575{
     2576#if FULL_NBIT
     2577  Int bitDepthMinus8 = g_uiBitDepth - 8;
     2578  return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)) : ((Int)(((Int)(x)-(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)));
     2579#else
     2580  return ((x)>0) ? (Int)(((Int)(x)+(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)) : ((Int)(((Int)(x)-(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)));
     2581#endif
     2582}
     2583
     2584/** rounding with IBDI
     2585 * \param  x
     2586 */
     2587inline Double xRoundIbdi(Double x)
     2588{
     2589#if FULL_NBIT
     2590  return (g_uiBitDepth > 8 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
     2591#else
     2592  return (g_uiBitIncrement >0 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
     2593#endif
     2594}
     2595
     2596
     2597
     2598/** process SAO for one partition
     2599 * \param  *psQTPart, iPartIdx, dLambda
     2600 */
     2601Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda)
     2602{
     2603  Int iTypeIdx;
     2604  Int iNumTotalType = MAX_NUM_SAO_TYPE;
     2605  SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
     2606
     2607  Int64 iEstDist;
     2608  Int64 iOffsetOrg;
     2609  Int64 iOffset;
     2610  Int64 iCount;
     2611  Int iClassIdx;
     2612  Int uiShift = g_uiBitIncrement << 1;
     2613  UInt uiDepth = pOnePart->PartLevel;
     2614
     2615  m_iDistOrg [iPartIdx] =  0;
     2616
     2617  Double  bestRDCostTableBo = MAX_DOUBLE;
     2618  Int     bestClassTableBo    = 0;
     2619  Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
     2620  Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
     2621
     2622#if HHI_INTERVIEW_SKIP
     2623  Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU();
     2624  Int LcuIdxX = psQTPart->StartCUX;
     2625  Int LcuIdxY = psQTPart->StartCUY;
     2626  Int iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
     2627  TComDataCU *pcCU = m_pcPic->getCU(iAddr);
     2628  Bool bRenderable = pcCU->getRenderable(0) ;
     2629
     2630#endif
     2631  for (iTypeIdx=-1; iTypeIdx<iNumTotalType; iTypeIdx++)
     2632  {
     2633    if( m_bUseSBACRD )
     2634    {
     2635      m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     2636      m_pcRDGoOnSbacCoder->resetBits();
     2637    }
     2638    else
     2639    {
     2640      m_pcEntropyCoder->resetEntropy();
     2641      m_pcEntropyCoder->resetBits();
     2642    }
     2643
     2644    iEstDist = 0;
     2645
     2646    m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoTypeIdx(iTypeIdx+1);
     2647
     2648    if (iTypeIdx>=0)
     2649    {
     2650
     2651      for(iClassIdx=1; iClassIdx < ( (iTypeIdx < SAO_BO) ?  m_iNumClass[iTypeIdx]+1 : SAO_MAX_BO_CLASSES+1); iClassIdx++)
     2652      {
     2653        if( iTypeIdx == SAO_BO)
     2654        {
     2655          currentDistortionTableBo[iClassIdx-1] = 0;
     2656          currentRdCostTableBo[iClassIdx-1] = dLambda;
     2657        }
     2658#if HHI_INTERVIEW_SKIP
     2659        if(m_iCount [iPartIdx][iTypeIdx][iClassIdx] && !bRenderable)
     2660#else
     2661        if(m_iCount [iPartIdx][iTypeIdx][iClassIdx])
     2662#endif
     2663        {
     2664#if FULL_NBIT
     2665          m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]<<g_uiBitDepth-8) / (Double)(m_iCount [iPartIdx][iTypeIdx][iClassIdx]<<m_uiSaoBitIncrease));
     2666#else
     2667          m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]<<g_uiBitIncrement) / (Double)(m_iCount [iPartIdx][iTypeIdx][iClassIdx]<<m_uiSaoBitIncrease));
     2668#endif
     2669          m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = Clip3(-m_iOffsetTh, m_iOffsetTh-1, (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
     2670
     2671          if (iTypeIdx < 4)
     2672          {
     2673            if ( m_iOffset[iPartIdx][iTypeIdx][iClassIdx]<0 && iClassIdx<3 )
     2674            {
     2675              m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
     2676            }
     2677            if ( m_iOffset[iPartIdx][iTypeIdx][iClassIdx]>0 && iClassIdx>=3)
     2678            {
     2679              m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
     2680            }
     2681          }
     2682          {
     2683            //Clean up, best_q_offset.
     2684            Int64 iIterOffset, iTempOffset;
     2685            Int64 iTempDist, iTempRate;
     2686            Double dTempCost, dTempMinCost;
     2687            UInt uiLength, uiTemp;
     2688
     2689            iIterOffset = m_iOffset[iPartIdx][iTypeIdx][iClassIdx];
     2690            m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
     2691            dTempMinCost = dLambda; // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here.
     2692
     2693            while (iIterOffset != 0)
     2694            {
     2695              // Calculate the bits required for signalling the offset
     2696              uiLength = 1;
     2697              uiTemp = (UInt)((iIterOffset <= 0) ? ( (-iIterOffset<<1) + 1 ) : (iIterOffset<<1));
     2698              while( 1 != uiTemp )
     2699              {
     2700                uiTemp >>= 1;
     2701                uiLength += 2;
     2702              }
     2703              iTempRate = (uiLength >> 1) + ((uiLength+1) >> 1);
     2704
     2705              // Do the dequntization before distorion calculation
     2706              iTempOffset    =  iIterOffset << m_uiSaoBitIncrease;
     2707              iTempDist  = (( m_iCount [iPartIdx][iTypeIdx][iClassIdx]*iTempOffset*iTempOffset-m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]*iTempOffset*2 ) >> uiShift);
     2708
     2709              dTempCost = ((Double)iTempDist + dLambda * (Double) iTempRate);
     2710              if(dTempCost < dTempMinCost)
     2711              {
     2712                dTempMinCost = dTempCost;
     2713                m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = iIterOffset;
     2714                if(iTypeIdx == SAO_BO)
     2715                {
     2716                  currentDistortionTableBo[iClassIdx-1] = (Int) iTempDist;
     2717                  currentRdCostTableBo[iClassIdx-1] = dTempCost;
     2718                }
     2719              }
     2720              iIterOffset = (iIterOffset > 0) ? (iIterOffset-1):(iIterOffset+1);
     2721            }
     2722
     2723          }
     2724        }
     2725        else
     2726        {
     2727          m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] = 0;
     2728          m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
     2729        }
     2730        if( iTypeIdx != SAO_BO )
     2731        {
     2732          iCount     =  m_iCount [iPartIdx][iTypeIdx][iClassIdx];
     2733          iOffset    =  m_iOffset[iPartIdx][iTypeIdx][iClassIdx] << m_uiSaoBitIncrease;
     2734          iOffsetOrg =  m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx];
     2735          iEstDist   += (( iCount*iOffset*iOffset-iOffsetOrg*iOffset*2 ) >> uiShift);
     2736          if (iTypeIdx < 4)
     2737          {
     2738            if (iClassIdx<3)
     2739            {
     2740              m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
     2741            }
     2742            else
     2743            {
     2744              m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUvlc((Int)-m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
     2745            }
     2746          }
     2747          else
     2748          {
     2749            m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoSvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
     2750          }
     2751        }
     2752      }
     2753
     2754      if( iTypeIdx == SAO_BO )
     2755      {
     2756        // Estimate Best Position
     2757        Double currentRDCost = 0.0;
     2758
     2759        for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
     2760        {
     2761          currentRDCost = 0.0;
     2762          for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
     2763          {
     2764            currentRDCost += currentRdCostTableBo[uj];
     2765          }
     2766
     2767          if( currentRDCost < bestRDCostTableBo)
     2768          {
     2769            bestRDCostTableBo = currentRDCost;
     2770            bestClassTableBo  = i;
     2771          }
     2772        }
     2773
     2774        // Re code all Offsets
     2775        // Code Center
     2776        m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUflc( (UInt) (bestClassTableBo) );
     2777
     2778        for(iClassIdx = bestClassTableBo; iClassIdx < bestClassTableBo+SAO_BO_LEN; iClassIdx++)
     2779        {
     2780          m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoSvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx+1]);
     2781          iEstDist += currentDistortionTableBo[iClassIdx];
     2782        }
     2783      }
     2784
     2785      m_iDist[iPartIdx][iTypeIdx] = iEstDist;
     2786      m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder->getNumberOfWrittenBits();
     2787
     2788      m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]);
     2789
     2790      if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx])
     2791      {
     2792        m_iDistOrg [iPartIdx] = 0;
     2793        m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx];
     2794        m_iTypePartBest[iPartIdx] = iTypeIdx;
     2795        if( m_bUseSBACRD )
     2796          m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
     2797      }
     2798    }
     2799    else
     2800    {
     2801      if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] )
     2802      {
     2803        m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder->getNumberOfWrittenBits()*dLambda ;
     2804        m_iTypePartBest[iPartIdx] = -1;
     2805        if( m_bUseSBACRD )
     2806          m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
     2807      }
     2808    }
     2809  }
     2810
     2811  pOnePart->bProcessed = true;
     2812  pOnePart->bSplit     = false;
     2813  pOnePart->iMinDist   =        m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx];
     2814  pOnePart->iMinRate   = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0);
     2815  pOnePart->dMinCost   = pOnePart->iMinDist + dLambda * pOnePart->iMinRate;
     2816  pOnePart->iBestType  = m_iTypePartBest[iPartIdx];
     2817  if (pOnePart->iBestType != -1)
     2818  {
     2819    //     pOnePart->bEnableFlag =  1;
     2820    pOnePart->iLength = m_iNumClass[pOnePart->iBestType];
     2821    Int minIndex = 0;
     2822    if( pOnePart->iBestType == SAO_BO )
     2823    {
     2824      pOnePart->bandPosition = bestClassTableBo;
     2825      minIndex = pOnePart->bandPosition;
     2826    }
     2827    for (Int i=0; i< pOnePart->iLength ; i++)
     2828    {
     2829      pOnePart->iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart->iBestType][minIndex+i+1];
     2830    }
     2831
     2832  }
     2833  else
     2834  {
     2835    //     pOnePart->bEnableFlag = 0;
     2836    pOnePart->iLength     = 0;
     2837  }
     2838}
     2839
     2840/** Run partition tree disable
     2841 */
     2842Void TEncSampleAdaptiveOffset::disablePartTree(SAOQTPart *psQTPart, Int iPartIdx)
     2843{
     2844  SAOQTPart*  pOnePart= &(psQTPart[iPartIdx]);
     2845  pOnePart->bSplit      = false;
     2846  pOnePart->iLength     =  0;
     2847  pOnePart->iBestType   = -1;
     2848
     2849  if (pOnePart->PartLevel < m_uiMaxSplitLevel)
     2850  {
     2851    for (Int i=0; i<NUM_DOWN_PART; i++)
     2852    {
     2853      disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
     2854    }
     2855  }
     2856}
     2857
     2858/** Run quadtree decision function
     2859 * \param  iPartIdx, pcPicOrg, pcPicDec, pcPicRest, &dCostFinal
     2860 */
     2861Void TEncSampleAdaptiveOffset::runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda)
     2862{
     2863  SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
     2864
     2865  UInt uiDepth = pOnePart->PartLevel;
     2866  UInt uhNextDepth = uiDepth+1;
     2867
     2868  if (iPartIdx == 0)
     2869  {
     2870    dCostFinal = 0;
     2871  }
     2872
     2873  //SAO for this part
     2874  if(!pOnePart->bProcessed)
     2875  {
     2876    rdoSaoOnePart (psQTPart, iPartIdx, dLambda);
     2877  }
     2878
     2879  //SAO for sub 4 parts
     2880  if (pOnePart->PartLevel < iMaxLevel)
     2881  {
     2882    Double      dCostNotSplit = dLambda + pOnePart->dMinCost;
     2883    Double      dCostSplit    = dLambda;
     2884
     2885    for (Int i=0; i< NUM_DOWN_PART ;i++)
     2886    {
     2887      if( m_bUseSBACRD ) 
     2888      {
     2889        if ( 0 == i) //initialize RD with previous depth buffer
     2890        {
     2891          m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     2892        }
     2893        else
     2894        {
     2895          m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
     2896        }
     2897      } 
     2898      runQuadTreeDecision(psQTPart, pOnePart->DownPartsIdx[i], dCostFinal, iMaxLevel, dLambda);
     2899      dCostSplit += dCostFinal;
     2900      if( m_bUseSBACRD )
     2901      {
     2902        m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_TEMP_BEST]);
     2903      }
     2904    }
     2905
     2906    if(dCostSplit < dCostNotSplit)
     2907    {
     2908      dCostFinal = dCostSplit;
     2909      pOnePart->bSplit      = true;
     2910      pOnePart->iLength     =  0;
     2911      pOnePart->iBestType   = -1;
     2912      if( m_bUseSBACRD )
     2913      {
     2914        m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
     2915      }
     2916    }
     2917    else
     2918    {
     2919      dCostFinal = dCostNotSplit;
     2920      pOnePart->bSplit = false;
     2921      for (Int i=0; i<NUM_DOWN_PART; i++)
     2922      {
     2923        disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
     2924      }
     2925      if( m_bUseSBACRD )
     2926      {
     2927        m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     2928      }
     2929    }
     2930  }
     2931  else
     2932  {
     2933    dCostFinal = pOnePart->dMinCost;
     2934  }
     2935}
     2936
     2937/** delete allocated memory of TEncSampleAdaptiveOffset class.
     2938 */
     2939Void TEncSampleAdaptiveOffset::destroyEncBuffer()
     2940{
     2941  for (Int i=0;i<m_iNumTotalParts;i++)
     2942  {
     2943    for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
     2944    {
     2945      if (m_iCount [i][j])
     2946      {
     2947        delete [] m_iCount [i][j];
     2948      }
     2949      if (m_iOffset[i][j])
     2950      {
     2951        delete [] m_iOffset[i][j];
     2952      }
     2953      if (m_iOffsetOrg[i][j])
     2954      {
     2955        delete [] m_iOffsetOrg[i][j];
     2956      }
     2957    }
     2958    if (m_iRate[i])
     2959    {
     2960      delete [] m_iRate[i];
     2961    }
     2962    if (m_iDist[i])
     2963    {
     2964      delete [] m_iDist[i];
     2965    }
     2966    if (m_dCost[i])
     2967    {
     2968      delete [] m_dCost[i];
     2969    }
     2970    if (m_iCount [i])
     2971    {
     2972      delete [] m_iCount [i];
     2973    }
     2974    if (m_iOffset[i])
     2975    {
     2976      delete [] m_iOffset[i];
     2977    }
     2978    if (m_iOffsetOrg[i])
     2979    {
     2980      delete [] m_iOffsetOrg[i];
     2981    }
     2982
     2983  }
     2984  if (m_iDistOrg)
     2985  {
     2986    delete [] m_iDistOrg ; m_iDistOrg = NULL;
     2987  }
     2988  if (m_dCostPartBest)
     2989  {
     2990    delete [] m_dCostPartBest ; m_dCostPartBest = NULL;
     2991  }
     2992  if (m_iTypePartBest)
     2993  {
     2994    delete [] m_iTypePartBest ; m_iTypePartBest = NULL;
     2995  }
     2996  if (m_iRate)
     2997  {
     2998    delete [] m_iRate ; m_iRate = NULL;
     2999  }
     3000  if (m_iDist)
     3001  {
     3002    delete [] m_iDist ; m_iDist = NULL;
     3003  }
     3004  if (m_dCost)
     3005  {
     3006    delete [] m_dCost ; m_dCost = NULL;
     3007  }
     3008  if (m_iCount)
     3009  {
     3010    delete [] m_iCount  ; m_iCount = NULL;
     3011  }
     3012  if (m_iOffset)
     3013  {
     3014    delete [] m_iOffset ; m_iOffset = NULL;
     3015  }
     3016  if (m_iOffsetOrg)
     3017  {
     3018    delete [] m_iOffsetOrg ; m_iOffsetOrg = NULL;
     3019  }
     3020
     3021  Int iMaxDepth = 4;
     3022  Int iDepth;
     3023  for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
     3024  {
     3025    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
     3026    {
     3027      delete m_pppcRDSbacCoder[iDepth][iCIIdx];
     3028      delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
     3029    }
     3030  }
     3031
     3032  for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
     3033  {
     3034    delete [] m_pppcRDSbacCoder[iDepth];
     3035    delete [] m_pppcBinCoderCABAC[iDepth];
     3036  }
     3037
     3038  delete [] m_pppcRDSbacCoder;
     3039  delete [] m_pppcBinCoderCABAC;
     3040}
     3041
     3042/** create Encoder Buffer for SAO
     3043 * \param
     3044 */
     3045Void TEncSampleAdaptiveOffset::createEncBuffer()
     3046{
     3047  m_iDistOrg = new Int64 [m_iNumTotalParts];
     3048  m_dCostPartBest = new Double [m_iNumTotalParts];
     3049  m_iTypePartBest = new Int [m_iNumTotalParts];
     3050
     3051  m_iRate = new Int64* [m_iNumTotalParts];
     3052  m_iDist = new Int64* [m_iNumTotalParts];
     3053  m_dCost = new Double*[m_iNumTotalParts];
     3054
     3055  m_iCount  = new Int64 **[m_iNumTotalParts];
     3056  m_iOffset = new Int64 **[m_iNumTotalParts];
     3057  m_iOffsetOrg = new Int64 **[m_iNumTotalParts];
     3058
     3059  for (Int i=0;i<m_iNumTotalParts;i++)
     3060  {
     3061    m_iRate[i] = new Int64  [MAX_NUM_SAO_TYPE];
     3062    m_iDist[i] = new Int64  [MAX_NUM_SAO_TYPE];
     3063    m_dCost[i] = new Double [MAX_NUM_SAO_TYPE];
     3064
     3065    m_iCount [i] = new Int64 *[MAX_NUM_SAO_TYPE];
     3066    m_iOffset[i] = new Int64 *[MAX_NUM_SAO_TYPE];
     3067    m_iOffsetOrg[i] = new Int64 *[MAX_NUM_SAO_TYPE];
     3068
     3069    for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
     3070    {
     3071      m_iCount [i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
     3072      m_iOffset[i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
     3073      m_iOffsetOrg[i][j]= new Int64 [MAX_NUM_SAO_CLASS];
     3074    }
     3075  }
     3076
     3077  Int iMaxDepth = 4;
     3078  m_pppcRDSbacCoder = new TEncSbac** [iMaxDepth+1];
     3079#if FAST_BIT_EST
     3080  m_pppcBinCoderCABAC = new TEncBinCABACCounter** [iMaxDepth+1];
     3081#else
     3082  m_pppcBinCoderCABAC = new TEncBinCABAC** [iMaxDepth+1];
     3083#endif
     3084
     3085  for ( Int iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
     3086  {
     3087    m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
     3088#if FAST_BIT_EST
     3089    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
     3090#else
     3091    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
     3092#endif
     3093    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
     3094    {
     3095      m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
     3096#if FAST_BIT_EST
     3097      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
     3098#else
     3099      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
     3100#endif
     3101      m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
     3102    }
     3103  }
     3104}
     3105
     3106/** Start SAO encoder
     3107 * \param pcPic, pcEntropyCoder, pppcRDSbacCoder, pcRDGoOnSbacCoder
     3108 */
     3109Void TEncSampleAdaptiveOffset::startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder)
     3110{
     3111  if( pcRDGoOnSbacCoder )
     3112    m_bUseSBACRD = true;
     3113  else
     3114    m_bUseSBACRD = false;
     3115
     3116  m_pcPic = pcPic;
     3117  m_pcEntropyCoder = pcEntropyCoder;
     3118
     3119  m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder;
     3120  m_pcEntropyCoder->resetEntropy();
     3121  m_pcEntropyCoder->resetBits();
     3122
     3123  if( m_bUseSBACRD )
     3124  {
     3125    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_NEXT_BEST]);
     3126    m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_NEXT_BEST]);
     3127  }
     3128}
     3129
     3130/** End SAO encoder
     3131 */
     3132Void TEncSampleAdaptiveOffset::endSaoEnc()
     3133{
     3134  m_pcPic = NULL;
     3135  m_pcEntropyCoder = NULL;
     3136}
     3137
     3138inline int xSign(int x)
     3139{
     3140  return ((x >> 31) | ((int)( (((unsigned int) -x)) >> 31)));
     3141}
     3142
     3143/** Calculate SAO statistics for non-cross-slice or non-cross-tile processing
     3144 * \param  pRecStart to-be-filtered block buffer pointer
     3145 * \param  pOrgStart original block buffer pointer
     3146 * \param  stride picture buffer stride
     3147 * \param  ppStat statistics buffer
     3148 * \param  ppCount counter buffer
     3149 * \param  width block width
     3150 * \param  height block height
     3151 * \param  pbBorderAvail availabilities of block border pixels
     3152 */
     3153Void TEncSampleAdaptiveOffset::calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail)
     3154{
     3155  Int64 *stats, *count;
     3156  Int classIdx, posShift, startX, endX, startY, endY, signLeft,signRight,signDown,signDown1;
     3157  Pel *pOrg, *pRec;
     3158  UInt edgeType;
     3159  Int x, y;
     3160
     3161  //--------- Band offset-----------//
     3162  stats = ppStats[SAO_BO];
     3163  count = ppCount[SAO_BO];
     3164  pOrg   = pOrgStart;
     3165  pRec   = pRecStart;
     3166  for (y=0; y< height; y++)
     3167  {
     3168    for (x=0; x< width; x++)
     3169    {
     3170      classIdx = m_lumaTableBo[pRec[x]];
     3171      if (classIdx)
     3172      {
     3173        stats[classIdx] += (pOrg[x] - pRec[x]);
     3174        count[classIdx] ++;
     3175      }
     3176    }
     3177    pOrg += stride;
     3178    pRec += stride;
     3179  }
     3180  //---------- Edge offset 0--------------//
     3181  stats = ppStats[SAO_EO_0];
     3182  count = ppCount[SAO_EO_0];
     3183  pOrg   = pOrgStart;
     3184  pRec   = pRecStart;
     3185
     3186
     3187  startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
     3188  endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
     3189  for (y=0; y< height; y++)
     3190  {
     3191    signLeft = xSign(pRec[startX] - pRec[startX-1]);
     3192    for (x=startX; x< endX; x++)
     3193    {
     3194      signRight =  xSign(pRec[x] - pRec[x+1]);
     3195      edgeType =  signRight + signLeft + 2;
     3196      signLeft  = -signRight;
     3197
     3198      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3199      count[m_auiEoTable[edgeType]] ++;
     3200    }
     3201    pRec  += stride;
     3202    pOrg += stride;
     3203  }
     3204
     3205  //---------- Edge offset 1--------------//
     3206  stats = ppStats[SAO_EO_1];
     3207  count = ppCount[SAO_EO_1];
     3208  pOrg   = pOrgStart;
     3209  pRec   = pRecStart;
     3210
     3211  startY = (pbBorderAvail[SGU_T]) ? 0 : 1;
     3212  endY   = (pbBorderAvail[SGU_B]) ? height : height-1;
     3213  if (!pbBorderAvail[SGU_T])
     3214  {
     3215    pRec  += stride;
     3216    pOrg  += stride;
     3217  }
     3218
     3219  for (x=0; x< width; x++)
     3220  {
     3221    m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]);
     3222  }
     3223  for (y=startY; y<endY; y++)
     3224  {
     3225    for (x=0; x< width; x++)
     3226    {
     3227      signDown     =  xSign(pRec[x] - pRec[x+stride]);
     3228      edgeType    =  signDown + m_iUpBuff1[x] + 2;
     3229      m_iUpBuff1[x] = -signDown;
     3230
     3231      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3232      count[m_auiEoTable[edgeType]] ++;
     3233    }
     3234    pOrg += stride;
     3235    pRec += stride;
     3236  }
     3237  //---------- Edge offset 2--------------//
     3238  stats = ppStats[SAO_EO_2];
     3239  count = ppCount[SAO_EO_2];
     3240  pOrg   = pOrgStart;
     3241  pRec   = pRecStart;
     3242
     3243  posShift= stride + 1;
     3244
     3245  startX = (pbBorderAvail[SGU_L]) ? 0 : 1 ;
     3246  endX   = (pbBorderAvail[SGU_R]) ? width : (width-1);
     3247
     3248  //prepare 2nd line upper sign
     3249  pRec += stride;
     3250  for (x=startX; x< endX+1; x++)
     3251  {
     3252    m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]);
     3253  }
     3254
     3255  //1st line
     3256  pRec -= stride;
     3257  if(pbBorderAvail[SGU_TL])
     3258  {
     3259    x= 0;
     3260    edgeType      =  xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2;
     3261    stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3262    count[m_auiEoTable[edgeType]] ++;
     3263  }
     3264  if(pbBorderAvail[SGU_T])
     3265  {
     3266    for(x= 1; x< endX; x++)
     3267    {
     3268      edgeType      =  xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2;
     3269      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3270      count[m_auiEoTable[edgeType]] ++;
     3271    }
     3272  }
     3273  pRec   += stride;
     3274  pOrg   += stride;
     3275
     3276  //middle lines
     3277  for (y= 1; y< height-1; y++)
     3278  {
     3279    for (x=startX; x<endX; x++)
     3280    {
     3281      signDown1      =  xSign(pRec[x] - pRec[x+ posShift]) ;
     3282      edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
     3283      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3284      count[m_auiEoTable[edgeType]] ++;
     3285
     3286      m_iUpBufft[x+1] = -signDown1;
     3287    }
     3288    m_iUpBufft[startX] = xSign(pRec[stride+startX] - pRec[startX-1]);
     3289
     3290    ipSwap     = m_iUpBuff1;
     3291    m_iUpBuff1 = m_iUpBufft;
     3292    m_iUpBufft = ipSwap;
     3293
     3294    pRec  += stride;
     3295    pOrg  += stride;
     3296  }
     3297
     3298  //last line
     3299  if(pbBorderAvail[SGU_B])
     3300  {
     3301    for(x= startX; x< width-1; x++)
     3302    {
     3303      edgeType =  xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
     3304      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3305      count[m_auiEoTable[edgeType]] ++;
     3306    }
     3307  }
     3308  if(pbBorderAvail[SGU_BR])
     3309  {
     3310    x= width -1;
     3311    edgeType =  xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
     3312    stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3313    count[m_auiEoTable[edgeType]] ++;
     3314  }
     3315
     3316  //---------- Edge offset 3--------------//
     3317
     3318  stats = ppStats[SAO_EO_3];
     3319  count = ppCount[SAO_EO_3];
     3320  pOrg   = pOrgStart;
     3321  pRec   = pRecStart;
     3322
     3323  posShift     = stride - 1;
     3324  startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
     3325  endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
     3326
     3327  //prepare 2nd line upper sign
     3328  pRec += stride;
     3329  for (x=startX-1; x< endX; x++)
     3330  {
     3331    m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]);
     3332  }
     3333
     3334
     3335  //first line
     3336  pRec -= stride;
     3337  if(pbBorderAvail[SGU_T])
     3338  {
     3339    for(x= startX; x< width -1; x++)
     3340    {
     3341      edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2;
     3342      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3343      count[m_auiEoTable[edgeType]] ++;
     3344    }
     3345  }
     3346  if(pbBorderAvail[SGU_TR])
     3347  {
     3348    x= width-1;
     3349    edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2;
     3350    stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3351    count[m_auiEoTable[edgeType]] ++;
     3352  }
     3353  pRec  += stride;
     3354  pOrg  += stride;
     3355
     3356  //middle lines
     3357  for (y= 1; y< height-1; y++)
     3358  {
     3359    for(x= startX; x< endX; x++)
     3360    {
     3361      signDown1      =  xSign(pRec[x] - pRec[x+ posShift]) ;
     3362      edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
     3363
     3364      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3365      count[m_auiEoTable[edgeType]] ++;
     3366      m_iUpBuff1[x-1] = -signDown1;
     3367
     3368    }
     3369    m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]);
     3370
     3371    pRec  += stride;
     3372    pOrg  += stride;
     3373  }
     3374
     3375  //last line
     3376  if(pbBorderAvail[SGU_BL])
     3377  {
     3378    x= 0;
     3379    edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
     3380    stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3381    count[m_auiEoTable[edgeType]] ++;
     3382
     3383  }
     3384  if(pbBorderAvail[SGU_B])
     3385  {
     3386    for(x= 1; x< endX; x++)
     3387    {
     3388      edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
     3389      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3390      count[m_auiEoTable[edgeType]] ++;
     3391    }
     3392  }
     3393}
     3394
     3395/** Calculate SAO statistics for current LCU
     3396 * \param  iAddr,  iPartIdx,  iYCbCr
     3397 */
     3398Void TEncSampleAdaptiveOffset::calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr)
     3399{
     3400  if(!m_bUseNIF)
     3401  {
     3402    calcSaoStatsCuOrg( iAddr, iPartIdx, iYCbCr);
     3403  }
     3404  else
     3405  {
     3406    Int64** ppStats = m_iOffsetOrg[iPartIdx];
     3407    Int64** ppCount = m_iCount    [iPartIdx];
     3408
     3409    //parameters
     3410    Int  isChroma = (iYCbCr != 0)? 1:0;
     3411    Int  stride   = (iYCbCr != 0)?(m_pcPic->getCStride()):(m_pcPic->getStride());
     3412    Pel* pPicOrg = getPicYuvAddr (m_pcPic->getPicYuvOrg(), iYCbCr);
     3413    Pel* pPicRec  = getPicYuvAddr(m_pcYuvTmp, iYCbCr);
     3414
     3415    std::vector<NDBFBlockInfo>& vFilterBlocks = *(m_pcPic->getCU(iAddr)->getNDBFilterBlocks());
     3416
     3417    //variables
     3418    UInt  xPos, yPos, width, height;
     3419    Bool* pbBorderAvail;
     3420    UInt  posOffset;
     3421
     3422    for(Int i=0; i< vFilterBlocks.size(); i++)
     3423    {
     3424      xPos        = vFilterBlocks[i].posX   >> isChroma;
     3425      yPos        = vFilterBlocks[i].posY   >> isChroma;
     3426      width       = vFilterBlocks[i].width  >> isChroma;
     3427      height      = vFilterBlocks[i].height >> isChroma;
     3428      pbBorderAvail = vFilterBlocks[i].isBorderAvailable;
     3429
     3430      posOffset = (yPos* stride) + xPos;
     3431
     3432#if HHI_INTERVIEW_SKIP
     3433      if( !m_pcPic->getCU(iAddr)->getRenderable(0 ))
     3434      {
     3435      calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail);
     3436      }
     3437#else
     3438      calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail);
     3439#endif
     3440    }
     3441  }
     3442
     3443}
     3444
     3445/** Calculate SAO statistics for current LCU without non-crossing slice
     3446 * \param  iAddr,  iPartIdx,  iYCbCr
     3447 */
     3448Void TEncSampleAdaptiveOffset::calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr)
     3449{
     3450  Int x,y;
     3451  TComDataCU *pTmpCu = m_pcPic->getCU(iAddr);
     3452  TComSPS *pTmpSPS =  m_pcPic->getSlice(0)->getSPS();
     3453
     3454  Pel* pOrg;
     3455  Pel* pRec;
     3456  Int iStride;
     3457  Int iLcuWidth  = pTmpSPS->getMaxCUHeight();
     3458  Int iLcuHeight = pTmpSPS->getMaxCUWidth();
     3459  UInt uiLPelX   = pTmpCu->getCUPelX();
     3460  UInt uiTPelY   = pTmpCu->getCUPelY();
     3461  UInt uiRPelX;
     3462  UInt uiBPelY;
     3463  Int64* iStats;
     3464  Int64* iCount;
     3465  Int iClassIdx;
     3466  Int iPicWidthTmp;
     3467  Int iPicHeightTmp;
     3468  Int iStartX;
     3469  Int iStartY;
     3470  Int iEndX;
     3471  Int iEndY;
     3472
     3473  Int iIsChroma = (iYCbCr!=0)? 1:0;
     3474  Int numSkipLine = iIsChroma? 2:4;
    9763475  if (m_saoInterleavingFlag == 0)
    9773476  {
     
    19744473
    19754474}
     4475#endif
    19764476
    19774477
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h

    r296 r443  
    7171  Int64  ***m_iOffset;     //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
    7272  Int64  ***m_iOffsetOrg;  //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
     73#if LGE_SAO_MIGRATION_D0091
     74  Int64  ****m_count_PreDblk;      //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
     75  Int64  ****m_offsetOrg_PreDblk;  //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
     76#endif
    7377  Int64  **m_iRate;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
    7478  Int64  **m_iDist;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
     
    7983  Int     m_iOffsetTh;
    8084  Bool    m_bUseSBACRD;
     85#if SAO_ENCODING_CHOICE
     86#if SAO_ENCODING_CHOICE_CHROMA
     87  Double  m_depthSaoRate[2][4];
     88#else
     89  Double  m_depth0SaoRate;
     90#endif
     91#endif
    8192
    8293public:
     
    8899  Void resetStats();
    89100#if SAO_CHROMA_LAMBDA
     101#if SAO_ENCODING_CHOICE
     102  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth);
     103#else
    90104  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma);
     105#endif
    91106#else
    92107  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda);
    93108#endif
     109
     110#if LGE_SAO_MIGRATION_D0091
     111  Void runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr);
     112  Void rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr);
     113#else
    94114  Void runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda);
    95115  Void rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda);
     116#endif
     117 
    96118  Void disablePartTree(SAOQTPart *psQTPart, Int iPartIdx);
    97119  Void getSaoStats(SAOQTPart *psQTPart, Int iYCbCr);
     
    99121  Void calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail);
    100122  Void calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr);
     123#if LGE_SAO_MIGRATION_D0091
     124  Void calcSaoStatsCu_BeforeDblk( TComPic* pcPic );
     125#endif
    101126  Void destroyEncBuffer();
    102127  Void createEncBuffer();
    103128  Void assignSaoUnitSyntax(SaoLcuParam* saoLcuParam,  SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr);
    104129  Void checkMerge(SaoLcuParam * lcuParamCurr,SaoLcuParam * lcuParamCheck, Int dir);
     130#if SAO_ENCODING_CHOICE
     131  Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth);
     132#else
    105133  Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma);
     134#endif
     135#if LGE_SAO_MIGRATION_D0091
     136  Void saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *distortion);
     137  Void sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion);
     138  inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift);
     139  inline Int64 estIterOffset(Int typeIdx, Int classIdx, double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo );
     140  inline Int64 estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo);
     141#else
    106142  Void rdoSaoUnit(SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda);
     143#endif
    107144  Void setMaxNumOffsetsPerPic(Int iVal) {m_maxNumOffsetsPerPic = iVal; }
    108145  Int  getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; }
  • trunk/source/Lib/TLibEncoder/TEncSbac.cpp

    r332 r443  
    4242#include <algorithm>
    4343
    44 #if RWTH_SDC_DLT_B0036
    45 #define GetNumDepthValues()     (pcCU->getSlice()->getSPS()->getNumDepthValues())
    46 #define GetBitsPerDepthValue()  (pcCU->getSlice()->getSPS()->getBitsPerDepthValue())
    47 #endif
    48 
    4944//! \ingroup TLibEncoder
    5045//! \{
     
    7267#if H3D_IVRP
    7368, m_cResPredFlagSCModel       ( 1,             1,               NUM_RES_PRED_FLAG_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
     69#endif
     70#if QC_ARP_D0177
     71, m_cCUPUARPW                 ( 1,             1,               NUM_ARPW_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
    7472#endif
    7573, m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
     
    9694, m_cALFSvlcSCModel           ( 1,             1,               NUM_ALF_SVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    9795, m_cCUAMPSCModel             ( 1,             1,               NUM_CU_AMP_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
     96#if LGE_SAO_MIGRATION_D0091
     97, m_cSaoMergeSCModel          ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
     98, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     99#else
    98100, m_cSaoFlagSCModel           ( 1,             1,               NUM_SAO_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    99101, m_cSaoUvlcSCModel           ( 1,             1,               NUM_SAO_UVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
     
    102104, m_cSaoMergeUpSCModel        ( 1,             1,               NUM_SAO_MERGE_UP_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
    103105, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     106#endif
    104107#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     108#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    105109, m_cDmmFlagSCModel           ( 1,             1,               NUM_DMM_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    106110, m_cDmmModeSCModel           ( 1,             1,               NUM_DMM_MODE_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
     111#endif
    107112, m_cDmmDataSCModel           ( 1,             1,               NUM_DMM_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    108113#endif
     
    114119#endif
    115120#if RWTH_SDC_DLT_B0036
     121#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    116122, m_cSDCFlagSCModel             ( 1,             1,                 SDC_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     123#else
     124, m_cDepthModeModel             ( 1,             1,                 DEPTH_MODE_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     125, m_cDmmDeltaFlagModel             ( 1,             1,                 DMM_DELTA_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     126#endif
     127#if RWTH_SDC_CTX_SIMPL_D0032
     128, m_cSDCResidualFlagSCModel     ( 1,             1,  SDC_NUM_RESIDUAL_FLAG_CTX  , m_contextModels + m_numContextModels, m_numContextModels)
     129, m_cSDCResidualSCModel         ( 1,             1,  SDC_NUM_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
     130, m_cSDCPredModeSCModel             ( 1,             3,                 SDC_NUM_PRED_MODE_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
     131#else
    117132, m_cSDCResidualFlagSCModel     ( 1,             2,  SDC_NUM_RESIDUAL_FLAG_CTX  , m_contextModels + m_numContextModels, m_numContextModels)
    118133, m_cSDCResidualSignFlagSCModel ( 1,             2,  SDC_NUM_SIGN_FLAG_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
    119134, m_cSDCResidualSCModel         ( 1,             2,  SDC_NUM_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
    120135, m_cSDCPredModeSCModel             ( 1,             3,                 SDC_NUM_PRED_MODE_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
     136#endif
    121137#endif
    122138{
     
    157173#if H3D_IVRP
    158174  m_cResPredFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_RES_PRED_FLAG );
     175#endif
     176#if QC_ARP_D0177
     177  m_cCUPUARPW.initBuffer                 ( eSliceType, iQp, (UChar*)INIT_ARPW );
    159178#endif
    160179  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
     
    180199  m_cALFSvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC );
    181200  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
     201#if LGE_SAO_MIGRATION_D0091
     202  m_cSaoMergeSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
     203  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
     204#else
    182205  m_cSaoFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG );
    183206  m_cSaoUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC );
     
    186209  m_cSaoMergeUpSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
    187210  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
     211#endif
    188212#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     213#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    189214  m_cDmmFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG );
    190215  m_cDmmModeSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_MODE );
     216#endif
    191217  m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
    192218#endif
     
    198224#endif
    199225#if RWTH_SDC_DLT_B0036
     226#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    200227  m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
     228#else
     229  m_cDepthModeModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DEPTHMODE_FLAG );
     230  m_cDmmDeltaFlagModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMMDELTA_FLAG );
     231#endif
    201232  m_cSDCResidualFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
    202233  m_cSDCResidualSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
     234#if !RWTH_SDC_CTX_SIMPL_D0032
    203235  m_cSDCResidualSignFlagSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG );
     236#endif
    204237  m_cSDCPredModeSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE );
    205238#endif
     
    266299      curCost += m_cALFSvlcSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_ALF_SVLC );
    267300      curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
     301#if LGE_SAO_MIGRATION_D0091
     302      curCost += m_cSaoMergeSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
     303      curCost += m_cSaoTypeIdxSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
     304#else
    268305      curCost += m_cSaoFlagSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_SAO_FLAG );
    269306      curCost += m_cSaoUvlcSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_SAO_UVLC );
     
    272309      curCost += m_cSaoMergeUpSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
    273310      curCost += m_cSaoTypeIdxSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
     311#endif
    274312
    275313      if (curCost < bestCost)
     
    310348#if H3D_IVRP
    311349  m_cResPredFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_RES_PRED_FLAG );
     350#endif
     351#if QC_ARP_D0177
     352  m_cCUPUARPW.initBuffer                 ( eSliceType, iQp, (UChar*)INIT_ARPW );
    312353#endif
    313354  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
     
    333374  m_cALFSvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC );
    334375  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
     376#if LGE_SAO_MIGRATION_D0091
     377  m_cSaoMergeSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
     378  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
     379#else
    335380  m_cSaoFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG );
    336381  m_cSaoUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC );
     
    339384  m_cSaoMergeUpSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
    340385  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
     386#endif
    341387#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     388#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    342389  m_cDmmFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG );
    343390  m_cDmmModeSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_MODE );
     391#endif
    344392  m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
    345393#endif
    346394#if RWTH_SDC_DLT_B0036
     395#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    347396  m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
     397#else
     398  m_cDepthModeModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DEPTHMODE_FLAG );
     399  m_cDmmDeltaFlagModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMMDELTA_FLAG );
     400#endif
    348401  m_cSDCResidualFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
    349402  m_cSDCResidualSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
     403#if !RWTH_SDC_CTX_SIMPL_D0032
    350404  m_cSDCResidualSignFlagSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG );
     405#endif
    351406  m_cSDCPredModeSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE );
    352407#endif
     
    542597}
    543598
    544 
     599#if PKU_QC_DEPTH_INTRA_UNI_D0195
     600Void TEncSbac::loadDepthMode( TEncSbac* pSrc)
     601{
     602  m_pcBinIf->copyState( pSrc->m_pcBinIf );
     603
     604  this->m_cDepthModeModel      .copyFrom( &pSrc->m_cDepthModeModel       );
     605  this->m_cDmmDeltaFlagModel   .copyFrom( &pSrc->m_cDmmDeltaFlagModel       );
     606}
     607#endif
    545608Void  TEncSbac::store( TEncSbac* pDest)
    546609{
     
    840903}
    841904#endif
    842 
     905#if QC_ARP_D0177
     906Void TEncSbac::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
     907{
     908  Int nW = pcCU->getARPW( uiAbsPartIdx );
     909  Int nMaxW = pcCU->getSlice()->getARPStepNum() - 1;
     910  assert( 0 <= nW && nW <= nMaxW );
     911  assert(nMaxW > 0);
     912  if( nMaxW > 0 )
     913  {
     914    Int nOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
     915    assert( 0 <= nOffset && nOffset <= 2 );
     916    Int nBinNum = nW + ( nW != nMaxW );
     917    m_pcBinIf->encodeBin( nW != 0 , m_cCUPUARPW.get( 0, 0, 0 + nOffset ) );
     918    if( nBinNum > 1 )
     919       m_pcBinIf->encodeBin( nW == nMaxW , m_cCUPUARPW.get( 0, 0, 3 ) );
     920  }
     921}
     922#endif
    843923Void TEncSbac::codeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    844924{
     
    9661046}
    9671047#endif
    968 
    969 Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1048#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1049Void TEncSbac::codeDepthIntraMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1050{
     1051  UInt uiCodeWordTable[3][9] =    {{0, 0, 0, 2, 0,6, 0, 0, 7},{0, 2, 3, 4, 5, 6, 14, 31, 30},{0, 2, 0, 0, 0, 0, 3, 0, 0}};
     1052  UInt uiCodeWordLenTable[3][9] = {{0, 1, 0, 2, 0,3, 0, 0, 3},{2, 3, 3, 3, 3, 3,  4,  5,  5},{1, 2, 0, 0, 0, 0, 2, 0, 0}};
     1053  UInt uiDir = pcCU->getLumaIntraDir(uiAbsPartIdx);
     1054  Bool bSdcFlag = pcCU->getSDCFlag(uiAbsPartIdx);
     1055  UInt uiPuIdx = ( pcCU->getWidth(uiAbsPartIdx) == 64 )? 2 : ( ( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && pcCU->getWidth(uiAbsPartIdx) == 8 ) ? 0 : 1 );
     1056  UInt uiCodeIdx = 0;
     1057  if ( bSdcFlag )
     1058  {
     1059    switch(uiDir)
     1060    {
     1061      case PLANAR_IDX: uiCodeIdx = 0; break;
     1062      case DC_IDX:     uiCodeIdx = 6; break;
     1063      default:         uiCodeIdx = 2;
     1064    }
     1065  }
     1066  else if ( uiDir>=EDGE_INTRA_IDX )
     1067  {
     1068    uiCodeIdx = 8;
     1069  }
     1070  else if ( uiDir<NUM_INTRA_MODE ) 
     1071  {
     1072    uiCodeIdx = 1;
     1073  }
     1074  else
     1075  {
     1076    if (uiDir== DMM_WEDGE_FULL_IDX     || uiDir==DMM_WEDGE_FULL_D_IDX     )     {uiCodeIdx = 3;}
     1077    if (uiDir== DMM_CONTOUR_PREDTEX_IDX|| uiDir==DMM_CONTOUR_PREDTEX_D_IDX)     {uiCodeIdx = 4;}
     1078    if (uiDir== DMM_WEDGE_PREDTEX_IDX  || uiDir==DMM_WEDGE_PREDTEX_D_IDX  )     {uiCodeIdx = 5;}
     1079    if (uiDir== DMM_WEDGE_PREDDIR_IDX  || uiDir==DMM_WEDGE_PREDDIR_D_IDX  )     {uiCodeIdx = 7;}
     1080  }
     1081  //mode coding
     1082  for (UInt i=0; i<uiCodeWordLenTable[uiPuIdx][uiCodeIdx]; i++)
     1083  {
     1084    UInt uiBit = uiCodeWordTable[uiPuIdx][uiCodeIdx] & ( 1<<(uiCodeWordLenTable[uiPuIdx][uiCodeIdx]-i-1) );
     1085    UInt uiCtxDepthMode = uiPuIdx*3 + ( i >= 2? 2 : i );
     1086    m_pcBinIf->encodeBin( uiBit!=0 , m_cDepthModeModel.get(0, 0, uiCtxDepthMode) );
     1087  }
     1088}
     1089Void TEncSbac::codeDepthModelingTable( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bSdcRD)
     1090{
     1091  UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx );
     1092  Bool bSdcFlag =  pcCU->getSDCFlag(uiAbsPartIdx);
     1093  Bool bDmmFlag = (uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX &&(!bSdcFlag))? 1:0;
     1094
     1095  codeDepthIntraMode(pcCU,uiAbsPartIdx);
     1096 
     1097  if (uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX )//DMM modes or SDC DMM1
     1098  {
     1099    assert(pcCU->getWidth(uiAbsPartIdx)<64);
     1100    assert(pcCU->getWidth(uiAbsPartIdx)<64);
     1101    if( uiDir == DMM_WEDGE_FULL_IDX || uiDir == DMM_WEDGE_FULL_D_IDX)             { xCodeWedgeFullInfo     ( pcCU, uiAbsPartIdx ); }
     1102    else if( uiDir == DMM_WEDGE_PREDTEX_IDX || uiDir == DMM_WEDGE_PREDTEX_D_IDX ) { xCodeWedgePredTexInfo  ( pcCU, uiAbsPartIdx ); }
     1103    else if( uiDir == DMM_WEDGE_PREDDIR_IDX || uiDir == DMM_WEDGE_PREDDIR_D_IDX)  { xCodeWedgePredDirInfo  ( pcCU, uiAbsPartIdx ); }
     1104  }
     1105  else if(uiDir >= EDGE_INTRA_IDX)//CCM mode
     1106  {
     1107    assert(pcCU->getWidth(uiAbsPartIdx)<64);
     1108    xCodeEdgeIntraInfo( pcCU, uiAbsPartIdx );
     1109  }
     1110
     1111  if (bDmmFlag)
     1112  {
     1113    m_pcBinIf->encodeBin( (uiDir&1) , m_cDmmDeltaFlagModel.get(0, 0, 0) );
     1114    if (uiDir&1)
     1115    {
     1116      Int iDeltaDC1 = 0,iDeltaDC2 = 0;
     1117      if ( uiDir == DMM_WEDGE_FULL_D_IDX )
     1118      {
     1119        iDeltaDC1 = pcCU->getWedgeFullDeltaDC1( uiAbsPartIdx );
     1120        iDeltaDC2 = pcCU->getWedgeFullDeltaDC2( uiAbsPartIdx );
     1121      }
     1122      else if ( uiDir == DMM_WEDGE_PREDTEX_D_IDX )
     1123      {
     1124        iDeltaDC1 = pcCU->getWedgePredTexDeltaDC1( uiAbsPartIdx );
     1125        iDeltaDC2 = pcCU->getWedgePredTexDeltaDC2( uiAbsPartIdx );
     1126      }
     1127      else if ( uiDir == DMM_WEDGE_PREDDIR_D_IDX )
     1128      {
     1129        iDeltaDC1 = pcCU->getWedgePredDirDeltaDC1( uiAbsPartIdx );
     1130        iDeltaDC2 = pcCU->getWedgePredDirDeltaDC2( uiAbsPartIdx );
     1131      }
     1132      else if ( uiDir == DMM_CONTOUR_PREDTEX_D_IDX )
     1133      {
     1134        iDeltaDC1 = pcCU->getContourPredTexDeltaDC1( uiAbsPartIdx );
     1135        iDeltaDC2 = pcCU->getContourPredTexDeltaDC2( uiAbsPartIdx );
     1136
     1137      }
     1138
     1139      for ( Int i = 0; i < 2; i++ )
     1140      {
     1141        Int iDeltaDC = (i==0)? iDeltaDC1 : iDeltaDC2;
     1142        xWriteExGolombLevel( UInt( abs( iDeltaDC ) ), m_cDmmDataSCModel.get(0, 0, 1) );
     1143        if ( iDeltaDC != 0 )
     1144        {
     1145          UInt uiSign = iDeltaDC > 0 ? 0 : 1;
     1146          m_pcBinIf->encodeBinEP( uiSign );
     1147        }
     1148      }
     1149    }
     1150  }
     1151  else if (uiDir>=EDGE_INTRA_IDX)
     1152  {
     1153    m_pcBinIf->encodeBin( (uiDir == EDGE_INTRA_DELTA_IDX), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
     1154    if( uiDir == EDGE_INTRA_DELTA_IDX )
     1155    {
     1156      Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx );
     1157      Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx );
     1158
     1159      for ( Int i = 0; i < 2; i++ )
     1160      {
     1161        Int iDeltaDC = (i==0)? iDeltaDC0 : iDeltaDC1;
     1162        xWriteExGolombLevel( UInt( abs( iDeltaDC ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
     1163        if ( iDeltaDC != 0 )
     1164        {
     1165          UInt uiSign = iDeltaDC > 0 ? 0 : 1;
     1166          m_pcBinIf->encodeBinEP( uiSign );
     1167        }
     1168      }
     1169    }
     1170  }
     1171  if (pcCU->getSDCFlag(uiAbsPartIdx))//SDC mode
     1172  {
     1173    assert(pcCU->getPartitionSize(uiAbsPartIdx)==SIZE_2Nx2N);
     1174    UInt uiNumSegments = ( uiDir == DC_IDX || uiDir == PLANAR_IDX )? 1 : 2;
     1175    if(!bSdcRD)
     1176    {
     1177      for (int uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
     1178      {
     1179        codeSDCResidualData(pcCU, uiAbsPartIdx, uiSeg);
     1180      }
     1181    }
     1182  }
     1183}
     1184#endif
     1185Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx
     1186#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1187                                   , Bool bSdcRD
     1188#endif
     1189                                   )
    9701190{
    9711191  UInt uiDir         = pcCU->getLumaIntraDir( uiAbsPartIdx );
    9721192
     1193#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    9731194#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    9741195  if( pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE )
     
    10701291  }
    10711292#endif
    1072  
     1293#else
     1294  if (pcCU->getSlice()->getSPS()->isDepth())
     1295  {
     1296    codeDepthModelingTable(pcCU, uiAbsPartIdx, bSdcRD);
     1297  }
     1298  if (pcCU->getLumaIntraDir(uiAbsPartIdx)<NUM_INTRA_MODE && !pcCU->getSDCFlag(uiAbsPartIdx))
     1299  {
     1300#endif
    10731301  Int uiPreds[3] = {-1, -1, -1};
    10741302  Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); 
     
    11161344
    11171345    m_pcBinIf->encodeBinsEP( uiDir, 5 );
     1346#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    11181347#if LGE_EDGE_INTRA_A0070
    11191348  if (bCodeEdgeIntra)
    11201349    if (uiDir == 31) m_pcBinIf->encodeBinsEP(0,1);
    11211350#endif
     1351#endif
    11221352   }
     1353#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1354   }
     1355#else
    11231356#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    11241357  }
    11251358#endif
     1359#endif
     1360
    11261361  return;
    11271362}
     
    18872122  }
    18882123}
    1889 
     2124#if LGE_SAO_MIGRATION_D0091
     2125Void TEncSbac::codeSAOSign( UInt code )
     2126{
     2127  m_pcBinIf->encodeBinEP( code );
     2128}
     2129
     2130Void TEncSbac::codeSaoMaxUvlc    ( UInt code, UInt maxSymbol )
     2131{
     2132  if (maxSymbol == 0)
     2133  {
     2134    return;
     2135  }
     2136
     2137  Int i;
     2138  Bool bCodeLast = ( maxSymbol > code );
     2139
     2140  if ( code == 0 )
     2141  {
     2142    m_pcBinIf->encodeBinEP( 0 );
     2143  }
     2144  else
     2145  {
     2146    m_pcBinIf->encodeBinEP( 1 );
     2147    for ( i=0; i<code-1; i++ )
     2148    {
     2149      m_pcBinIf->encodeBinEP( 1 );
     2150    }
     2151    if( bCodeLast )
     2152    {
     2153      m_pcBinIf->encodeBinEP( 0 );
     2154    }
     2155  }
     2156}
     2157
     2158/** Code SAO EO class or BO band position
     2159 * \param uiLength
     2160 * \param uiCode
     2161 */
     2162Void TEncSbac::codeSaoUflc       ( UInt uiLength, UInt uiCode )
     2163{
     2164   m_pcBinIf->encodeBinsEP ( uiCode, uiLength );
     2165}
     2166/** Code SAO merge flags
     2167 * \param uiCode
     2168 * \param uiCompIdx
     2169 */
     2170Void TEncSbac::codeSaoMerge       ( UInt uiCode )
     2171{
     2172  if (uiCode == 0)
     2173  {
     2174    m_pcBinIf->encodeBin(0,  m_cSaoMergeSCModel.get( 0, 0, 0 ));
     2175  }
     2176  else
     2177  {
     2178    m_pcBinIf->encodeBin(1,  m_cSaoMergeSCModel.get( 0, 0, 0 ));
     2179  }
     2180}
     2181/** Code SAO type index
     2182 * \param uiCode
     2183 */
     2184Void TEncSbac::codeSaoTypeIdx       ( UInt uiCode)
     2185{
     2186  if (uiCode == 0)
     2187  {
     2188    m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
     2189  }
     2190  else
     2191  {
     2192    m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
     2193    m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 ); //determine edge or band
     2194  }
     2195}
     2196#else
    18902197Void TEncSbac::codeSaoFlag       ( UInt uiCode )
    18912198{
     
    20032310  }
    20042311}
     2312#endif
    20052313/*!
    20062314 ****************************************************************************
     
    23972705
    23982706#if RWTH_SDC_DLT_B0036
     2707#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    23992708Void TEncSbac::codeSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
    24002709{
     
    24112720  {
    24122721    UInt uiBit = (uiPredMode == g_auiSDCPredModes[uiMPModeIdx]) ? 1 : 0;
     2722#if INTEL_SDC64_D0193
     2723    if( !(pcCU->getWidth(uiAbsPartIdx) == 64 && i == 1))
     2724#endif
    24132725    m_pcBinIf->encodeBin( uiBit, m_cSDCPredModeSCModel.get( 0, i, uiCtx ) );
    24142726   
     
    24372749 
    24382750}
     2751#endif
    24392752
    24402753Void TEncSbac::codeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment )
     
    24502763  UInt uiSign     = segmentDCOffset < 0 ? 1 : 0;
    24512764  UInt uiAbsIdx   = abs(segmentDCOffset);
     2765#if !LGE_CONCATENATE_D0141
    24522766  UInt uiBit = 0;
    2453  
    2454   UInt uiMaxResidualBits  = GetBitsPerDepthValue();
     2767#endif
     2768 
     2769  UInt uiMaxResidualBits  = pcCU->getSlice()->getSPS()->getBitsPerDepthValue();
    24552770  assert( uiMaxResidualBits <= g_uiBitDepth );
    24562771 
    24572772  // residual flag
     2773#if RWTH_SDC_CTX_SIMPL_D0032
     2774  m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
     2775#else
    24582776  m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, uiSegment, 0 ) ); //TODO depthmap: more sophisticated context selection
     2777#endif
    24592778 
    24602779  if (uiResidual)
    24612780  {
    24622781    // encode sign bit of residual
     2782#if RWTH_SDC_CTX_SIMPL_D0032
     2783    m_pcBinIf->encodeBinEP( uiSign );
     2784#else
    24632785    m_pcBinIf->encodeBin( uiSign, m_cSDCResidualSignFlagSCModel.get( 0, uiSegment, 0 ) ); //TODO depthmap: more sophisticated context selection
     2786#endif
    24642787       
    2465     assert(uiAbsIdx < GetNumDepthValues());
     2788    UInt uiNumDepthValues = pcCU->getSlice()->getSPS()->getNumDepthValues();
     2789    assert(uiAbsIdx < uiNumDepthValues);
    24662790   
    24672791    // encode residual magnitude
    24682792    uiAbsIdx -= 1;
     2793#if LGE_CONCATENATE_D0141
     2794    //prefix part
     2795    if ( uiAbsIdx == 0 )
     2796        m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) );
     2797    else
     2798    {
     2799        UInt l = uiAbsIdx;
     2800        UInt k = 0;
     2801        UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2);
     2802        while ( l > 0 && k < uiPrefixThreshold )
     2803        {
     2804            m_pcBinIf->encodeBin( 1, m_cSDCResidualSCModel.get(0, 0, 0) );
     2805            l--;
     2806            k++;
     2807        }
     2808        if ( uiAbsIdx < uiPrefixThreshold )
     2809            m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) );
     2810        //suffix part
     2811        else
     2812        {
     2813            uiAbsIdx -= uiPrefixThreshold;
     2814            UInt uiSuffixLength = ( (UInt)ceil( Log2(uiNumDepthValues - uiPrefixThreshold) ) );
     2815            UInt uiBitInfo = 0;
     2816            for ( Int i = 0; i < uiSuffixLength; i++)
     2817            {
     2818                uiBitInfo = ( uiAbsIdx & ( 1 << i ) ) >> i;
     2819                m_pcBinIf->encodeBinEP( uiBitInfo);
     2820            }
     2821        }
     2822    }
     2823#else
    24692824    for (Int i=0; i<uiMaxResidualBits; i++)
    24702825    {
    24712826      uiBit = (uiAbsIdx & (1<<i))>>i;
    24722827     
     2828#if RWTH_SDC_CTX_SIMPL_D0032
     2829      m_pcBinIf->encodeBin( uiBit, m_cSDCResidualSCModel.get( 0, 0, i ) );
     2830#else
    24732831      m_pcBinIf->encodeBin( uiBit, m_cSDCResidualSCModel.get( 0, uiSegment, i ) ); //TODO depthmap: more sophisticated context selection
    2474     }
     2832#endif
     2833    }
     2834#endif
    24752835   
    24762836  }
  • trunk/source/Lib/TLibEncoder/TEncSbac.h

    r332 r443  
    9292  Void  load                   ( TEncSbac* pScr  );
    9393  Void  loadIntraDirModeLuma   ( TEncSbac* pScr  );
     94#if PKU_QC_DEPTH_INTRA_UNI_D0195
     95  Void  loadDepthMode          ( TEncSbac* pSrc  );
     96#endif
    9497  Void  store                  ( TEncSbac* pDest );
    9598  Void  loadContexts           ( TEncSbac* pScr  );
     
    126129  Void codeAlfCtrlFlag       ( UInt uiSymbol );
    127130  Void  codeApsExtensionFlag () { assert (0); return; };
     131#if LGE_SAO_MIGRATION_D0091
     132  Void  codeSaoMaxUvlc    ( UInt code, UInt maxSymbol );
     133  Void  codeSaoMerge      ( UInt  uiCode );
     134  Void  codeSaoTypeIdx    ( UInt  uiCode);
     135  Void  codeSaoUflc       ( UInt uiLength, UInt  uiCode );
     136  Void  codeSAOSign       ( UInt  uiCode);  //<! code SAO offset sign
     137#else
    128138  Void  codeSaoFlag       ( UInt uiCode );
    129139  Void  codeSaoUvlc       ( UInt uiCode );
     
    134144  Void  codeSaoTypeIdx    ( UInt  uiCode);
    135145  Void  codeSaoUflc       ( UInt  uiCode);
     146#endif
    136147  Void  codeScalingList      ( TComScalingList* scalingList     ){ assert (0);  return;};
    137148 
    138149#if RWTH_SDC_DLT_B0036
     150#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    139151  Void codeSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     152#endif
    140153  Void codeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment );
     154#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    141155  Void codeSDCPredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     156#endif
    142157#endif
    143158
     
    209224  Void codeResPredFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    210225#endif
     226#if QC_ARP_D0177
     227  virtual Void codeARPW ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     228#endif
    211229  Void codeSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    212230#if H3D_IVMP
     
    222240  Void codeQtCbf               ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth );
    223241  Void codeQtRootCbf           ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    224  
    225   Void codeIntraDirLumaAng     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     242#if PKU_QC_DEPTH_INTRA_UNI_D0195
     243  Void codeDepthIntraMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     244  Void codeDepthModelingTable  ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bSdcRD = false );
     245#endif
     246  Void codeIntraDirLumaAng     ( TComDataCU* pcCU, UInt uiAbsPartIdx
     247#if PKU_QC_DEPTH_INTRA_UNI_D0195
     248    , Bool bSdcRD = false
     249#endif
     250    );
    226251 
    227252  Void codeIntraDirChroma      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     
    265290#if H3D_IVRP
    266291  ContextModel3DBuffer m_cResPredFlagSCModel;
     292#endif
     293#if QC_ARP_D0177
     294  ContextModel3DBuffer m_cCUPUARPW;
    267295#endif
    268296  ContextModel3DBuffer m_cCUPartSizeSCModel;
     
    292320  ContextModel3DBuffer m_cALFSvlcSCModel;
    293321  ContextModel3DBuffer m_cCUAMPSCModel;
     322#if LGE_SAO_MIGRATION_D0091
     323  ContextModel3DBuffer m_cSaoMergeSCModel;
     324  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
     325#else
    294326  ContextModel3DBuffer m_cSaoFlagSCModel;
    295327  ContextModel3DBuffer m_cSaoUvlcSCModel;
     
    298330  ContextModel3DBuffer m_cSaoMergeUpSCModel;
    299331  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
     332#endif
    300333
    301334#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     335#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    302336  ContextModel3DBuffer m_cDmmFlagSCModel;
    303337  ContextModel3DBuffer m_cDmmModeSCModel;
     338#endif
    304339  ContextModel3DBuffer m_cDmmDataSCModel;
    305340#endif
     
    312347 
    313348#if RWTH_SDC_DLT_B0036
     349#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    314350  ContextModel3DBuffer m_cSDCFlagSCModel;
     351#else
     352  ContextModel3DBuffer m_cDepthModeModel;
     353  ContextModel3DBuffer m_cDmmDeltaFlagModel;
     354#endif
    315355 
    316356  ContextModel3DBuffer m_cSDCResidualFlagSCModel;
     357#if !RWTH_SDC_CTX_SIMPL_D0032
    317358  ContextModel3DBuffer m_cSDCResidualSignFlagSCModel;
     359#endif
    318360  ContextModel3DBuffer m_cSDCResidualSCModel;
    319361 
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r332 r443  
    206206 
    207207#if H3D_IVMP
     208#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     209  const Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     210#else
    208211  const Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + 1;
     212#endif
    209213  for( Int iNum = 0; iNum < iNumAMVPCands+1; iNum++)
    210214    for( Int iIdx = 0; iIdx < iNumAMVPCands; iIdx++)
     
    908912      if( uiAbsPartIdx == 0 )
    909913      {
    910         m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, 0 );
     914        m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, 0
     915#if PKU_QC_DEPTH_INTRA_UNI_D0195
     916         ,true
     917#endif
     918          );
    911919      }
    912920    }
     
    17011709      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
    17021710      assert( ucSegment < uiNumSegments );
     1711#if MTK_SAMPLE_BASED_SDC_D0110     
     1712      Pel pResiDC = apDCResiValues[ucSegment];
    17031713     
     1714      pReco    [ uiX ] = Clip( pPred[ uiX ] + pResiDC );
     1715#else
    17041716      Pel pPredVal= apDCPredValues[ucSegment];
    17051717      Pel pResiDC = apDCResiValues[ucSegment];
    17061718     
    17071719      pReco    [ uiX ] = Clip( pPredVal + pResiDC );
     1720#endif
    17081721      pRecIPred[ uiX ] = pReco[ uiX ];
    17091722    }
     
    17351748  if ( m_pcRdCost->getUseVSO() )
    17361749  {
     1750#if FIX_SDC_ENC_RD_WVSO_D0163 && LGE_WVSO_A0119
     1751    if ( m_pcRdCost->getUseWVSO() )
     1752    {   
     1753      Int iDWeight = m_pcRdCost->getDWeight() * m_pcRdCost->getDWeight();
     1754      Int iVSOWeight = m_pcRdCost->getVSOWeight() * m_pcRdCost->getVSOWeight();
     1755      Dist iD = (Dist) m_pcRdCost->getDistPart( piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );
     1756      Dist iVSO = m_pcRdCost->getDistVS  ( pcCU, uiAbsPartIdx, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, false, 0 );
     1757      ruiDist += (iDWeight * iD + iVSOWeight * iVSO) / ( iDWeight + iVSOWeight);
     1758    }
     1759    else
     1760#endif
    17371761    ruiDist = m_pcRdCost->getDistVS  ( pcCU, uiAbsPartIdx, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, false, 0 );
    17381762  }
     
    17511775 
    17521776  // encode pred direction + residual data
    1753   m_pcEntropyCoder->encodePredInfo( pcCU, 0, true );
    1754  
     1777  m_pcEntropyCoder->encodePredInfo( pcCU, 0, true
     1778#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1779    ,true
     1780#endif
     1781    );
    17551782  UInt   uiBits = m_pcEntropyCoder->getNumberOfWrittenBits();
    17561783 
     
    29212948                                 , Int* iVSPIndexTrue
    29222949#endif
     2950#if MERL_VSP_NBDV_RefVId_Fix_D0166
     2951                                 , Int* iVSPDirTrue
     2952#endif
    29232953                                 )
    29242954{
     
    29622992  }
    29632993#else
     2994
    29642995#if MERL_VSP_C0152
    2965   pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, uiDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue );
    2966 #else
    2967   pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, uiDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
    2968 #endif
    2969 #endif
    2970 
     2996  pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, uiDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue
     2997#if MERL_VSP_NBDV_RefVId_Fix_D0166
     2998                               , iVSPDirTrue
     2999#endif
     3000  );
     3001
     3002#else
     3003  pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, uiDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand
     3004#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3005                               , iVSPDirTrue
     3006#endif
     3007  );
     3008#endif
     3009
     3010#endif
    29713011
    29723012#if H3D_IVMP
     
    29853025      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
    29863026#if MERL_VSP_C0152
     3027#if MTK_D0156
     3028      if( !pcCU->getSlice()->getSPS()->getUseVSPCompensation() )
     3029      {
     3030          pcCU->setVSPIndexSubParts( 0, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
     3031      }
     3032      else
     3033#endif
    29873034      {
    29883035        Int iVSPIdx = 0;
     3036#if LGE_VSP_INHERIT_D0092
     3037        if (iVSPIndexTrue[uiMergeCand] == 1)
     3038        {
     3039            iVSPIdx = 1;
     3040        }
     3041#else
    29893042        Int numVSPIdx;
    29903043        numVSPIdx = 3;
     
    29973050            }
    29983051        }
     3052#endif
    29993053        pcCU->setVSPIndexSubParts( iVSPIdx, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
     3054#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3055        pcCU->setVSPDirSubParts(0, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
     3056#endif
     3057#if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
     3058       if(iVSPIdx != 0)
     3059       {
     3060        Int iIVCIdx = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==pcCU->getSlice()->getPOC() ? 0: pcCU->getSlice()->getNewRefIdx(REF_PIC_LIST_0);
     3061        cMvFieldNeighbours[ 2*uiMergeIndex].setRefIdx(iIVCIdx);
     3062      }
     3063#endif
    30003064      }
    30013065#endif
     
    31093173
    31103174#if H3D_IVMP
     3175#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     3176  Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     3177#else
    31113178  Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     3179#endif
    31123180#endif
    31133181
     
    31383206    //reset the VSP flag to be 0
    31393207    pcCU->setVSPIndexSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
     3208#endif
     3209#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3210    pcCU->setVSPDirSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
    31403211#endif
    31413212#if AMP_MRG
     
    33773448        iNumIter = 1;
    33783449      }
    3379      
     3450
    33803451      for ( Int iIter = 0; iIter < iNumIter; iIter++ )
    33813452      {
     
    36573728      UInt uiMRGIndex = 0;
    36583729#if MERL_VSP_C0152
     3730#if LGE_VSP_INHERIT_D0092
     3731      Int iVSPIndexTrue[MRG_MAX_NUM_CANDS_MEM];
     3732      for (Int i=0; i<MRG_MAX_NUM_CANDS_MEM; i++)
     3733      {
     3734          iVSPIndexTrue[i] = 0;
     3735      }
     3736#else
    36593737      Int iVSPIndexTrue[3] = {-1, -1, -1};
     3738#endif
     3739#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3740      Int iVSPDirTrue[3]   = {-1, -1, -1};
     3741#endif
    36603742#endif
    36613743      UInt uiMEInterDir = 0;
     
    36883770
    36893771
    3690 xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost
     3772      xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost
    36913773#if CU_BASED_MRG_CAND_LIST
    36923774                 , cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand,
     
    36943776#if MERL_VSP_C0152
    36953777                 , iVSPIndexTrue
     3778#endif
     3779#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3780                 , iVSPDirTrue
    36963781#endif
    36973782        );
     
    37033788        pcCU->setMergeIndexSubParts( uiMRGIndex,    uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    37043789#if MERL_VSP_C0152
     3790
     3791#if MTK_D0156
     3792        if( !pcCU->getSlice()->getSPS()->getUseVSPCompensation() )
     3793        {
     3794            pcCU->setVSPIndexSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     3795        }
     3796        else
     3797#endif
    37053798        {
    37063799          Int iVSPIdx = 0;
     3800#if LGE_VSP_INHERIT_D0092
     3801          if (iVSPIndexTrue[uiMRGIndex] == 1)
     3802          {
     3803              iVSPIdx = 1;
     3804          }
     3805#else
    37073806          Int numVSPIdx;
    37083807          numVSPIdx = 3;
     
    37153814              }
    37163815          }
     3816#endif
    37173817          pcCU->setVSPIndexSubParts( iVSPIdx, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     3818#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3819          pcCU->setVSPDirSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     3820#endif
     3821#if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
     3822         if(iVSPIdx != 0)
     3823         {
     3824           Int iIVCIdx = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==pcCU->getSlice()->getPOC() ? 0: pcCU->getSlice()->getNewRefIdx(REF_PIC_LIST_0);
     3825           cMRGMvField[ 0].setRefIdx(iIVCIdx);
     3826         }
     3827#endif
    37183828        }
    37193829#endif
     
    37383848        pcCU->setInterDirSubParts ( uiMEInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    37393849#if MERL_VSP_C0152
    3740         pcCU->setVSPIndexSubParts ( 0 ,           uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     3850        pcCU->setVSPIndexSubParts ( 0,            uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     3851#endif
     3852#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3853        pcCU->setVSPDirSubParts   ( 0,            uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    37413854#endif
    37423855        {
     
    37993912    {
    38003913#if H3D_IVMP
     3914#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     3915      Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     3916#else
    38013917      Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     3918#endif
    38023919#if ZERO_MVD_EST
    38033920      (*puiDistBiP) = xGetTemplateCost( pcCU, uiPartIdx, uiPartAddr, pcOrgYuv, &m_cYuvPredTemp, rcMvPred, 0, iNumAMVPCands, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight, uiDist );
     
    38343951      UInt uiTmpCost;
    38353952#if H3D_IVMP
     3953#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     3954      Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     3955#else
    38363956      Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     3957#endif
    38373958#if ZERO_MVD_EST
    38383959      uiTmpCost = xGetTemplateCost( pcCU, uiPartIdx, uiPartAddr, pcOrgYuv, &m_cYuvPredTemp, pcAMVPInfo->m_acMvCand[i], i, iNumAMVPCands, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight, uiDist );
     
    39674088 
    39684089#if H3D_IVMP
     4090#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     4091  Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     4092#else
    39694093  Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     4094#endif
    39704095#endif
    39714096 
     
    46744799#endif
    46754800      );
     4801#if QC_ARP_D0177
     4802    m_pcEntropyCoder->encodeARPW       ( pcCU , 0 , true );
     4803#endif
    46764804#endif
    46774805#if HHI_MPI
     
    58926020    // Reload only contexts required for coding intra mode information
    58936021    m_pcRDGoOnSbacCoder->loadIntraDirModeLuma( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
     6022#if PKU_QC_DEPTH_INTRA_UNI_D0195
     6023    m_pcRDGoOnSbacCoder->loadDepthMode( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
     6024#endif
    58946025  }
    58956026 
     
    58976028 
    58986029  m_pcEntropyCoder->resetBits();
    5899   m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, uiPartOffset);
     6030  m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, uiPartOffset
     6031#if PKU_QC_DEPTH_INTRA_UNI_D0195
     6032    ,true
     6033#endif
     6034    );
    59006035 
    59016036  return m_pcEntropyCoder->getNumberOfWrittenBits();
     
    59546089      );
    59556090#endif
     6091#if QC_ARP_D0177
     6092    m_pcEntropyCoder->encodeARPW( pcCU , 0 , true );
     6093#endif
    59566094    ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits();
    59576095  }
     
    59776115#endif
    59786116      );
     6117#if QC_ARP_D0177
     6118    m_pcEntropyCoder->encodeARPW( pcCU , 0 , true );
     6119#endif
    59796120#endif
    59806121#if HHI_MPI
     
    63016442  Int iMaskStride = ( uiWidth<<1 ) + 1;
    63026443  piMask += iMaskStride+1;
     6444#if QC_DC_PREDICTOR_D0183
     6445  getPredDCs( pcWedgelet->getPattern(), pcWedgelet->getStride(), piMask, iMaskStride, iPredDC1, iPredDC2 );
     6446#else
    63036447  getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAboveAvail, bLeftAvail );
     6448#endif
    63046449
    63056450  riDeltaDC1 = iDC1 - iPredDC1;
     
    64786623#endif
    64796624
     6625#if HHI_DELTADC_DLT_D0035
     6626  riDeltaDC1 = (Int)GetDepthValue2Idx( Clip(iPredDC1 + riDeltaDC1) ) - (Int)GetDepthValue2Idx( iPredDC1 );
     6627  riDeltaDC2 = (Int)GetDepthValue2Idx( Clip(iPredDC2 + riDeltaDC2) ) - (Int)GetDepthValue2Idx( iPredDC2 );
     6628#endif
    64806629}
    64816630#endif
     
    78628011
    78638012  // PredDC Calculation
     8013#if QC_DC_PREDICTOR_D0183
     8014  getPredDCs( pbRegion, uiWidth, piMask+iMaskStride+1, iMaskStride, iPredDC0, iPredDC1 );
     8015#else
    78648016  {
    78658017    UInt uiSum0 = 0;
     
    79018053    iPredDC1 = uiSum1 / uiCount1;
    79028054  }
     8055#endif
    79038056
    79048057  iDeltaDC0 = iDC0 - iPredDC0;
  • trunk/source/Lib/TLibEncoder/TEncSearch.h

    r332 r443  
    511511                                  , Int* iVSPIndexTrue
    512512#endif
     513#if MERL_VSP_NBDV_RefVId_Fix_D0166
     514                                  , Int* iVSPDirTrue
     515#endif
    513516                                   );
    514517  // -------------------------------------------------------------------------------------------------------------------
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r332 r443  
    6060  m_pcBufferLowLatSbacCoders    = NULL;
    6161  m_pcBufferLowLatBinCoderCABACs  = NULL;
     62#if MERL_VSP_NBDV_RefVId_Fix_D0166
     63  for(Int iNumCount = 0; iNumCount < MAX_VIEW_NUM; iNumCount++)
     64    m_pcListDepthPic[iNumCount] = NULL;
     65#endif
    6266#if FCO_DVP_REFINE_C0132_C0170
    6367  m_pPicBaseTxt = NULL;
     
    148152  m_pdRdPicQp         = (Double*)xMalloc( Double, m_pcCfg->getDeltaQpRD() * 2 + 1 );
    149153  m_piRdPicQp         = (Int*   )xMalloc( Int,    m_pcCfg->getDeltaQpRD() * 2 + 1 );
     154
     155#if MERL_VSP_NBDV_RefVId_Fix_D0166
     156  for(Int iNumCount = 0; iNumCount < MAX_VIEW_NUM; iNumCount++)
     157    m_pcListDepthPic[iNumCount] = NULL;
     158#endif
    150159}
    151160
     
    778787  {
    779788    pcSlice ->xSetApplyIC();
     789#if SHARP_ILLUCOMP_PARSE_D0060
     790    if (pcSlice->getApplyIC())
     791    {
     792      pcSlice->setIcSkipParseFlag(rpcPic->getCurrSlice()->getPOC() % m_pcCfg->getIntraPeriod() != 0);
     793    }
     794#endif
    780795  }
    781796#endif
     
    819834#if MERL_VSP_C0152
    820835  // Send Depth/Texture pointers to slice level
     836#if !MERL_VSP_NBDV_RefVId_Fix_D0166
    821837  pcSlice->setBWVSPLUTParam(m_aiShiftLUT, m_iShiftPrec);
     838#endif
    822839  pcSlice->setRefPicBaseTxt(m_pPicBaseTxt);
    823840  pcSlice->setRefPicBaseDepth(m_pPicBaseDepth);
     841#if MERL_VSP_NBDV_RefVId_Fix_D0166
     842  for (Int refViewId=0; refViewId < pcSlice->getViewId(); refViewId++)
     843  {
     844    assert( m_pcListDepthPic[refViewId] );
     845    pcSlice->setListDepthPic(m_pcListDepthPic[refViewId], refViewId);
     846    pcSlice->setBWVSPLUTParam(m_aiShiftLUT[refViewId], m_iShiftPrec, refViewId);
     847  }
     848#endif
    824849#endif
    825850
     
    11991224    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );   
    12001225
     1226#if LGE_SAO_MIGRATION_D0091
     1227    if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
     1228    {
     1229        SAOParam *saoParam =  pcSlice->getAPS()->getSaoParam();
     1230        Int iNumCuInWidth     = saoParam->numCuInWidth;
     1231        Int iCUAddrInSlice    = uiCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU());
     1232        Int iCUAddrUpInSlice  = iCUAddrInSlice - iNumCuInWidth;
     1233        Int rx = uiCUAddr % iNumCuInWidth;
     1234        Int ry = uiCUAddr / iNumCuInWidth;
     1235        Int allowMergeLeft = 1;
     1236        Int allowMergeUp   = 1;
     1237
     1238        if (rx!=0)
     1239        {
     1240            if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))
     1241            {
     1242                allowMergeLeft = 0;
     1243            }
     1244        }
     1245        if (ry!=0)
     1246        {
     1247            if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-iNumCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))
     1248            {
     1249                allowMergeUp = 0;
     1250            }
     1251        }
     1252
     1253        Int addr = pcCU->getAddr();
     1254        allowMergeLeft = allowMergeLeft && (rx>0) && (iCUAddrInSlice!=0);
     1255        allowMergeUp = allowMergeUp && (ry>0) && (iCUAddrUpInSlice>=0);
     1256
     1257        if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] )
     1258        {
     1259            Int mergeLeft = saoParam->saoLcuParam[0][addr].mergeLeftFlag;
     1260            Int mergeUp = saoParam->saoLcuParam[0][addr].mergeUpFlag;
     1261
     1262            if (allowMergeLeft)
     1263            {
     1264                m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft);
     1265            }
     1266            else
     1267            {
     1268                mergeLeft = 0;
     1269            }
     1270            if(mergeLeft == 0)
     1271            {
     1272                if (allowMergeUp)
     1273                {
     1274                    m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeUp);
     1275                }
     1276                else
     1277                {
     1278                    mergeUp = 0;
     1279                }
     1280                if(mergeUp == 0)
     1281                {
     1282                    for (Int compIdx=0;compIdx<3;compIdx++)
     1283                    {
     1284                        if( (compIdx == 0 && saoParam->bSaoFlag[0]) || (compIdx > 0 && saoParam->bSaoFlag[1]))
     1285                        {
     1286                            m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx);
     1287                        }
     1288                    }
     1289                }
     1290            }
     1291        }
     1292    }
     1293#else
    12011294    if ( pcSlice->getSPS()->getUseSAO() && pcSlice->getAPS()->getSaoInterleavingFlag() && pcSlice->getSaoEnabledFlag() )
    12021295    {
     
    12081301      m_pcEntropyCoder->encodeSaoUnitInterleaving( rx, ry, pcSlice->getAPS()->getSaoParam(),pcCU, iCUAddrInSlice, iCUAddrUpInSlice, pcSlice->getSPS()->getLFCrossSliceBoundaryFlag());
    12091302    }
     1303#endif
    12101304#if ENC_DEC_TRACE
    12111305    g_bJustDoIt = g_bEncDecTraceEnable;
  • trunk/source/Lib/TLibEncoder/TEncSlice.h

    r296 r443  
    106106  TComPic* m_pPicBaseTxt;
    107107  TComPic* m_pPicBaseDepth;
     108#if MERL_VSP_NBDV_RefVId_Fix_D0166
     109  Int*     m_aiShiftLUT[2]; ///< For reference views from LIST0 and LIST1
     110#else
    108111  Int*     m_aiShiftLUT;
     112#endif
    109113  Int      m_iShiftPrec;
    110114#endif
    111 
     115#if MERL_VSP_NBDV_RefVId_Fix_D0166
     116  TComList<TComPic*>*  m_pcListDepthPic[MAX_VIEW_NUM]; ///< For three views in total, indexed as viewId = 0, 1, 2
     117#endif
    112118public:
    113119  TEncSlice();
     
    143149
    144150#if MERL_VSP_C0152
    145    Void     setBWVSPLUTParam    ( Int *pShiftLUT, Int iLoG2LUTPrec ) { m_aiShiftLUT = pShiftLUT; m_iShiftPrec = 2-iLoG2LUTPrec; }
     151#if MERL_VSP_NBDV_RefVId_Fix_D0166
     152  Void     setBWVSPLUTParam  ( Int *pShiftLUT, Int iLoG2LUTPrec, Int iNeighborViewId ) { m_aiShiftLUT[iNeighborViewId] = pShiftLUT; m_iShiftPrec = 2-iLoG2LUTPrec; }
     153#else
     154  Void     setBWVSPLUTParam    ( Int *pShiftLUT, Int iLoG2LUTPrec ) { m_aiShiftLUT = pShiftLUT; m_iShiftPrec = 2-iLoG2LUTPrec; }
     155#endif
    146156   Void     setRefPicBaseTxt    ( TComPic*pPicTxt   ) { m_pPicBaseTxt = pPicTxt;    }
    147157   Void     setRefPicBaseDepth  ( TComPic*pPicDepth ) { m_pPicBaseDepth = pPicDepth;}
     158#if MERL_VSP_NBDV_RefVId_Fix_D0166
     159   Void     getBWVSPLUTParam  ( Int*& pShiftLUT, Int& iShiftPrec, Int iNeighborViewId ) { pShiftLUT = m_aiShiftLUT[iNeighborViewId]; iShiftPrec = m_iShiftPrec; }
     160#else
    148161   Void     getBWVSPLUTParam    ( Int*& pShiftLUT, Int& iShiftPrec ) { pShiftLUT = m_aiShiftLUT; iShiftPrec = m_iShiftPrec; }
     162#endif
    149163   TComPic* getRefPicBaseTxt    () { return m_pPicBaseTxt;   }
    150164   TComPic* getRefPicBaseDepth  () { return m_pPicBaseDepth; }
     165#if MERL_VSP_NBDV_RefVId_Fix_D0166
     166   Void     setListDepthPic     ( TComList<TComPic*>* pListDepthPic, Int viewId ) { m_pcListDepthPic[viewId] = pListDepthPic; }
     167   TComList<TComPic*>* getListDepthPic(Int viewId)  { return m_pcListDepthPic[viewId]; }
     168#endif
    151169#endif
    152170};
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r332 r443  
    103103  if (m_bUseSAO)
    104104  {
     105#if LGE_SAO_MIGRATION_D0091
     106    m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary());
     107    m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization());
     108#else
    105109    m_cEncSAO.setSaoInterleavingFlag(getSaoInterleavingFlag());
     110#endif
    106111    m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic());
    107112    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     
    120125  m_cDepthMapGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
    121126#endif
    122 #if H3D_IVRP
     127#if H3D_IVRP & !QC_ARP_D0177
    123128  m_cResidualGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
    124129#endif
     
    251256  m_cDepthMapGenerator. destroy();
    252257#endif
    253 #if H3D_IVRP
     258#if H3D_IVRP & !QC_ARP_D0177
    254259  m_cResidualGenerator. destroy();
    255260#endif
     
    347352#endif
    348353#endif
    349 #if H3D_IVRP
     354#if H3D_IVRP & !QC_ARP_D0177
    350355  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
    351356#endif
     
    710715#endif
    711716
     717
     718#if MTK_D0156
     719#if MERL_VSP_COMPENSATION_C0152
     720  m_cSPS.setUseVSPCompensation           ( m_bUseVSPCompensation );
     721#endif
     722  m_cSPS.setUseDVPRefine                 ( m_bUseDVPRefine       );
     723#endif
     724
    712725  if( m_isDepth )
    713726  {
     
    722735#endif
    723736#if H3D_IVRP
     737#if QC_ARP_D0177
     738    m_cSPS.setUseAdvRP              ( 0 );
     739    m_cSPS.setARPStepNum            ( 1 );
     740#else
    724741    m_cSPS.setMultiviewResPredMode  ( 0 );
    725742#endif
     743#endif
     744
    726745  }
    727746  else
     
    742761#endif
    743762#if H3D_IVRP
    744       m_cSPS.setMultiviewResPredMode  ( m_uiMultiviewResPredMode );
     763#if QC_ARP_D0177
     764     m_cSPS.setUseAdvRP  ( m_viewId > 0   ? m_nUseAdvResPred : 0 );
     765     m_cSPS.setARPStepNum( m_viewId > 0   ? QC_ARP_WFNR      : 1 );
     766#else
     767     m_cSPS.setMultiviewResPredMode  ( m_uiMultiviewResPredMode );
     768#endif
    745769#endif
    746770    }
     
    751775#endif
    752776#if H3D_IVRP
     777#if QC_ARP_D0177
     778      m_cSPS.setUseAdvRP              ( 0 );
     779      m_cSPS.setARPStepNum            ( 1 );
     780#else
    753781      m_cSPS.setMultiviewResPredMode  ( 0 );
     782#endif
    754783#endif
    755784    }
  • trunk/source/Lib/TLibEncoder/TEncTop.h

    r296 r443  
    103103  TComDepthMapGenerator   m_cDepthMapGenerator;           ///< depth map generator
    104104#endif
    105 #if H3D_IVRP
     105#if H3D_IVRP & !QC_ARP_D0177
    106106  TComResidualGenerator   m_cResidualGenerator;           ///< generator for residual pictures
    107107#endif
     
    234234  TComDepthMapGenerator*  getDepthMapGenerator  () { return  &m_cDepthMapGenerator;   }
    235235#endif
    236 #if H3D_IVRP
     236#if H3D_IVRP & !QC_ARP_D0177
    237237  TComResidualGenerator*  getResidualGenerator  () { return  &m_cResidualGenerator;   }
    238238#endif
Note: See TracChangeset for help on using the changeset viewer.