Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 332)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 443)
@@ -735,5 +735,10 @@
 
 #if MERL_VSP_C0152
-Void TAppDecTop::setBWVSPLUT(TComSlice* pcSlice,  Int iCodedViewIdx,  Int iCurPoc)
+Void TAppDecTop::setBWVSPLUT(
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+    Int iNeighborViewId,
+#endif
+    TComSlice* pcSlice,  Int iCodedViewIdx,  Int iCurPoc)
+
 {
   //first view does not have VSP 
@@ -742,8 +747,14 @@
   AOT( iCodedViewIdx <= 0);
   //AOT( iCodedViewIdx >= m_iNumberOfViews );
+#if !MERL_VSP_NBDV_RefVId_Fix_D0166
   Int iNeighborViewId = 0;
+#endif
   //  Int* piShiftLUT = bRenderFromLeft ? m_cCamParsCollector.getBaseViewShiftLUTI()[iCodedViewIdx][iNeighborViewId][0] : m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
   Int* piShiftLUT = m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+  pcSlice->setBWVSPLUTParam(piShiftLUT, 2-LOG2_DISP_PREC_LUT, iNeighborViewId );
+#else
   pcSlice->setBWVSPLUTParam(piShiftLUT, 2-LOG2_DISP_PREC_LUT );
+#endif
 }
 #endif
Index: trunk/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 332)
+++ trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 443)
@@ -113,5 +113,9 @@
 
 #if MERL_VSP_C0152
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+  Void  setBWVSPLUT( Int iNeighborViewId, TComSlice* pcSlice, Int iCodedViewIdx, Int iCurPoc );
+#else
   Void  setBWVSPLUT( TComSlice* pcSlice, Int iCodedViewIdx, Int iCurPoc   );
+#endif
 #endif
 
Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 332)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 443)
@@ -383,5 +383,13 @@
 #endif
 #if H3D_IVRP
+#if QC_ARP_D0177
+  ("MultiviewResPred", m_nUseAdvResPred,           (UInt)0, "usage of Advanced residual prediction" )
+#else
   ("MultiviewResPred", m_uiMultiviewResPredMode,   (UInt)0, "usage of inter-view residual prediction" )
+#endif
+#endif
+#if MTK_D0156
+  ("UseVSPCompensation", m_bUseVSPCompensation,   true, "Depth dependent tools: BVSP" )
+  ("UseDVPRefine", m_bUseDVPRefine,   true, "Depth dependent tools: DoNBDV" )
 #endif
 
@@ -392,5 +400,10 @@
   ("SAO", m_abUseSAO, std::vector<Bool>(1, true), "SAO")
   ("MaxNumOffsetsPerPic", m_maxNumOffsetsPerPic, 2048, "2048: default")   
+#if LGE_SAO_MIGRATION_D0091
+  ("SAOLcuBoundary",          m_saoLcuBoundary,          false, "0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas")
+  ("SAOLcuBasedOptimization", m_saoLcuBasedOptimization, true, "0: SAO picture-based optimization, 1: SAO LCU-based optimization ")
+#else
   ("SAOInterleaving", m_saoInterleavingFlag, false, "0: SAO Picture Mode, 1: SAO Interleaving ")   
+#endif
 
   ("ALFEncodePassReduction", m_iALFEncodePassReduction, 0, "0:Original 16-pass, 1: 1-pass, 2: 2-pass encoding")
@@ -917,6 +930,14 @@
 #endif
 #if H3D_IVRP
+#if QC_ARP_D0177
+#if QC_ARP_WARNING_FIX
+  xConfirmPara    ( m_nUseAdvResPred > 1 , "0<=ARP<=1" );
+#else
+  xConfirmPara    ( m_nUseAdvResPred < 0 || m_nUseAdvResPred > 1 , "0<=ARP<=1" );
+#endif
+#else
   xConfirmPara    ( m_uiMultiviewResPredMode > 1,                                     "MultiviewResPred must be less than or equal to 1" );
   xConfirmPara    ( m_uiMultiviewResPredMode > 0 && m_uiPredDepthMapGeneration == 0 , "MultiviewResPred > 0 requires PredDepthMapGen > 0" );
+#endif
 #endif
   if( m_bUsingDepthMaps )
@@ -1625,5 +1646,9 @@
   printf("CIP:%d ", m_bUseConstrainedIntraPred);
   printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
+#if LGE_SAO_MIGRATION_D0091
+  printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0));
+#else
   printf("SAOInterleaving:%d ", (m_saoInterleavingFlag)?(1):(0));
+#endif
 #if LOSSLESS_CODING
   printf("LosslessCuEnabled:%d ", (m_useLossless)? 1:0 );
@@ -1672,4 +1697,7 @@
   printf("IVSEnable: %d ", m_bUseIVS);
 #endif
+#if QC_ARP_D0177
+  printf(" ARP:%d  " , m_nUseAdvResPred  );
+#endif
   printf("\n");
 
@@ -1708,4 +1736,10 @@
   printf("DLT:%d ", m_bUseDLT ? 1 : 0 );
 #endif
+
+#if MTK_D0156
+  printf("BVSP:%d ", m_bUseVSPCompensation ? 1 : 0 );
+  printf("DoNBDV:%d ",  m_bUseDVPRefine ? 1 : 0 );
+#endif
+
 #if LGE_WVSO_A0119
   if ( m_bUseWVSO )
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 332)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 443)
@@ -165,5 +165,10 @@
 #endif
   Int       m_maxNumOffsetsPerPic;                            ///< SAO maximun number of offset per picture
+#if LGE_SAO_MIGRATION_D0091
+  Bool      m_saoLcuBoundary;                                 ///< SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
+  Bool      m_saoLcuBasedOptimization;                        ///< SAO LCU-based optimization
+#else
   Bool      m_saoInterleavingFlag;                            ///< SAO interleaving flag
+#endif
   // coding tools (loop filter)
   vector<Bool> m_abUseALF;                                    ///< flag for using adaptive loop filter [0] - video, [1] - depth
@@ -217,6 +222,10 @@
   Double    m_dMultiviewMvRegLambdaScale;                     ///< lambda scale for multiview motion vectors regularization
 #endif
-#if H3D_IVRP
+#if H3D_IVRP 
+#if QC_ARP_D0177
+  UInt      m_nUseAdvResPred;
+#else
   UInt      m_uiMultiviewResPredMode;          ///< using multiview residual prediction
+#endif
 #endif
 
@@ -317,4 +326,13 @@
 #endif
 
+#if MTK_D0156
+
+#if MERL_VSP_COMPENSATION_C0152
+  Bool      m_bUseVSPCompensation;
+#endif
+
+  Bool      m_bUseDVPRefine;
+#endif
+
   // internal member functions
   Void  xSetGlobal      ();                                   ///< set global variables
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 332)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 443)
@@ -223,5 +223,16 @@
 #endif
 #if H3D_IVRP
+#if QC_ARP_D0177
+    m_acTEncTopList[iViewIdx]->setUseAdvRP                     ( iViewIdx ? m_nUseAdvResPred             : 0   );
+    m_acTEncTopList[iViewIdx]->setARPStepNum                   ( iViewIdx ? QC_ARP_WFNR                  : 1   );
+#else
     m_acTEncTopList[iViewIdx]->setMultiviewResPredMode         ( m_uiMultiviewResPredMode );
+#endif
+#endif
+#if MTK_D0156
+#if MERL_VSP_COMPENSATION_C0152
+    m_acTEncTopList[iViewIdx]->setUseVSPCompensation           ( iViewIdx ? m_bUseVSPCompensation : 0 );
+#endif
+    m_acTEncTopList[iViewIdx]->setUseDVPRefine                  ( iViewIdx ? m_bUseDVPRefine : 0 );
 #endif
 
@@ -303,5 +314,10 @@
 #endif
     m_acTEncTopList[iViewIdx]->setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
+#if LGE_SAO_MIGRATION_D0091
+    m_acTEncTopList[iViewIdx]->setSaoLcuBoundary (m_saoLcuBoundary);
+    m_acTEncTopList[iViewIdx]->setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
+#else
     m_acTEncTopList[iViewIdx]->setSaoInterleavingFlag (m_saoInterleavingFlag);
+#endif
     m_acTEncTopList[iViewIdx]->setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
     m_acTEncTopList[iViewIdx]->setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
@@ -560,6 +576,19 @@
       m_acTEncDepthTopList[iViewIdx]->setMultiviewMvRegLambdaScale    ( 0.0 );
 #endif
-#if H3D_IVRP
-      m_acTEncDepthTopList[iViewIdx]->setMultiviewResPredMode         ( 0 );
+#if H3D_IVRP 
+#if QC_ARP_D0177
+    m_acTEncDepthTopList[iViewIdx]->setUseAdvRP                          ( 0 );
+    m_acTEncDepthTopList[iViewIdx]->setARPStepNum                        ( 1 );
+#else
+    m_acTEncDepthTopList[iViewIdx]->setMultiviewResPredMode         ( 0 );
+#endif
+#endif
+#if MTK_D0156
+
+#if MERL_VSP_COMPENSATION_C0152
+      m_acTEncDepthTopList[iViewIdx]->setUseVSPCompensation           ( iViewIdx ? true : false );
+#endif
+
+      m_acTEncDepthTopList[iViewIdx]->setUseDVPRefine                 ( iViewIdx ? true : false );
 #endif
 
@@ -605,5 +634,10 @@
 #endif
       m_acTEncDepthTopList[iViewIdx]->setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
+#if LGE_SAO_MIGRATION_D0091
+      m_acTEncDepthTopList[iViewIdx]->setSaoLcuBoundary (m_saoLcuBoundary);
+      m_acTEncDepthTopList[iViewIdx]->setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
+#else
       m_acTEncDepthTopList[iViewIdx]->setSaoInterleavingFlag (m_saoInterleavingFlag);
+#endif
       m_acTEncDepthTopList[iViewIdx]->setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
       m_acTEncDepthTopList[iViewIdx]->setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
@@ -1076,5 +1110,5 @@
 #if MERL_VSP_C0152
 #if MERL_VSP_C0152_BugFix_ForNoDepthCase
-        if(m_bUsingDepthMaps) //VSP can be used only when depth is available as input
+        if(m_bUsingDepthMaps) // VSP can be used only when depth is available as input
         {
 #endif
@@ -1087,6 +1121,17 @@
           pEncSlice->setRefPicBaseTxt(pcBaseTxtPic);
           pEncSlice->setRefPicBaseDepth(pcBaseDepthPic);
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+          for (Int refViewId=0; refViewId < iViewIdx; refViewId++ )
+          {
+            pEncSlice->setListDepthPic(m_acTEncDepthTopList[refViewId]->getListPic(), refViewId ); // The list will store only the depth pictures
+            setBWVSPLUT(refViewId, iViewIdx, gopId, false);
+          } 
+#endif
         }
+#if !MERL_VSP_NBDV_RefVId_Fix_D0166
         setBWVSPLUT( iViewIdx, gopId, false);
+#endif
+#endif
+
 #if MERL_VSP_C0152_BugFix_ForNoDepthCase
         }
@@ -1103,5 +1148,4 @@
 #endif
 
-#endif
         // call encoding function for one frame
         m_acTEncTopList[iViewIdx]->encode( eos[iViewIdx], pcPicYuvOrg, *m_picYuvRec[iViewIdx], outputAccessUnits, iNumEncoded, gopId );
@@ -1118,6 +1162,15 @@
           TEncSlice* pcSlice = (TEncSlice*) m_acTEncDepthTopList[iViewIdx]->getSliceEncoder();
           pcSlice->setRefPicBaseDepth(pcBaseDepthPic);
+#if  MERL_VSP_NBDV_RefVId_Fix_D0166
+          for (Int refViewId=0; refViewId < iViewIdx; refViewId++ )
+          {
+            pcSlice->setListDepthPic(m_acTEncDepthTopList[refViewId]->getListPic(), refViewId ); // The list will store only the depth pictures
+            setBWVSPLUT( refViewId, iViewIdx, gopId, true);
+          } 
+#endif
         }
+#if !MERL_VSP_NBDV_RefVId_Fix_D0166
         setBWVSPLUT( iViewIdx, gopId, true);
+#endif
 #endif
 
@@ -1636,5 +1689,10 @@
 
 #if MERL_VSP_C0152
-Void TAppEncTop::setBWVSPLUT(Int iCodedViewIdx, Int gopId, Bool isDepth)
+
+Void TAppEncTop::setBWVSPLUT(
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+        Int iNeighborViewId,
+#endif
+        Int iCodedViewIdx, Int gopId, Bool isDepth)
 {
   //first view does not have VSP 
@@ -1643,6 +1701,7 @@
   AOT( iCodedViewIdx <= 0);
   AOT( iCodedViewIdx >= m_iNumberOfViews );
-
+#if !MERL_VSP_NBDV_RefVId_Fix_D0166
   Int iNeighborViewId = 0;
+#endif
   //setting look-up table
   Int* piShiftLUT = m_cCameraData.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
@@ -1651,10 +1710,18 @@
   {
     TEncSlice* pcEncSlice = (TEncSlice*) m_acTEncDepthTopList[iCodedViewIdx]->getSliceEncoder();
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+    pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT, iNeighborViewId );
+#else
     pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT );
+#endif
   }
   else
   {
     TEncSlice* pcEncSlice = (TEncSlice*) m_acTEncTopList[iCodedViewIdx]->getSliceEncoder();
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+    pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT, iNeighborViewId );
+#else
     pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT );
+#endif
   }
 
Index: trunk/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 332)
+++ trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 443)
@@ -167,5 +167,9 @@
 
 #if MERL_VSP_C0152
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+  Void setBWVSPLUT( Int refViewIdx, Int iCodedViewIdx, Int gopId, Bool isDepth);
+#else
   Void setBWVSPLUT( Int iCodedViewIdx, Int gopId, Bool isDepth);
+#endif
 #endif
 };// END CLASS DEFINITION TAppEncTop
