Index: branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view+depth.cfg
===================================================================
--- branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view+depth.cfg	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view+depth.cfg	(revision 486)
@@ -196,4 +196,6 @@
 #========== multiview coding tools ==========
 IvMvPred           : 1                                 # Inter-view motion prediction
+ViewSynthesisPred  : 0                                 # View synthesis prediction 
+DepthRefinement    : 1                                 # Dispary refined by depth DoNBDV
 
 #========== depth coding tools ==========
Index: branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view.cfg
===================================================================
--- branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view.cfg	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view.cfg	(revision 486)
@@ -151,4 +151,7 @@
 #========== multiview coding tools ==========
 IvMvPred           : 1                                 # Inter-view motion prediction
+ViewSynthesisPred  : 0                                 # View synthesis prediction 
+DepthRefinement    : 0                                 # Dispary refined by depth DoNBDV
+
 ### DO NOT ADD ANYTHING BELOW THIS LINE ###
 ### DO NOT DELETE THE EMPTY LINE BELOW ###
Index: branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view+depth.cfg
===================================================================
--- branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view+depth.cfg	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view+depth.cfg	(revision 486)
@@ -195,4 +195,7 @@
 #========== multiview coding tools ==========
 IvMvPred           : 1                                 # Inter-view motion prediction
+ViewSynthesisPred  : 0                                 # View synthesis prediction 
+DepthRefinement    : 1                                 # Dispary refined by depth DoNBDV
+
 
 #========== depth coding tools ==========
Index: branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view.cfg
===================================================================
--- branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view.cfg	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view.cfg	(revision 486)
@@ -161,4 +161,7 @@
 #========== multiview coding tools ==========
 IvMvPred           : 1                                 # Inter-view motion prediction
+ViewSynthesisPred  : 0                                 # View synthesis prediction 
+DepthRefinement    : 0                                 # Dispary refined by depth DoNBDV
+
 ### DO NOT ADD ANYTHING BELOW THIS LINE ###
 ### DO NOT DELETE THE EMPTY LINE BELOW ###
Index: branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/fullCfg.cfg
===================================================================
--- branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/fullCfg.cfg	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/fullCfg.cfg	(revision 486)
@@ -201,4 +201,7 @@
 #========== multiview coding tools ==========
 IvMvPred           : 1                                 # Inter-view motion prediction
+ViewSynthesisPred  : 1                                 # View synthesis prediction 
+DepthRefinement    : 1                                 # Dispary refined by depth DoNBDV
+
 #========== depth coding tools ==========
 VSO                       : 1                                      # use of view synthesis optimization for depth coding
Index: branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 486)
@@ -718,5 +718,11 @@
 #endif //HHI_VSO
 #if H_3D_IV_MERGE
-  ("IvMvPred",                       m_ivMvPredFlag,           false           , "inter view motion prediction " )  
+  ("IvMvPred",                        m_ivMvPredFlag,           false           , "inter view motion prediction " )  
+#endif
+#if H_3D_NBDV_REF
+  ("DepthRefinement",                 m_depthRefinementFlag,    false           , "depth refinement by DoNBDV" )  
+#endif
+#if H_3D_VSP
+  ("ViewSynthesisPred",               m_viewSynthesisPredFlag,  false           , "view synthesis prediction " )  
 #endif
 #endif //H_3D
@@ -2282,5 +2288,11 @@
 #endif
 #if H_3D_IV_MERGE
-  printf("IvMvPred:%d", m_ivMvPredFlag );
+  printf("IvMvPred:%d ", m_ivMvPredFlag );
+#endif
+#if H_3D_NBDV_REF
+  printf("DepthRefinement:%d ", m_depthRefinementFlag );  
+#endif
+#if H_3D_VSP
+  printf("ViewSynthesisPred:%d ", m_viewSynthesisPredFlag );
 #endif
   printf("\n\n");  
Index: branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.h	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.h	(revision 486)
@@ -88,4 +88,10 @@
 #if H_3D_IV_MERGE
   Bool                   m_ivMvPredFlag;                      ///< Interview motion vector prediction 
+#endif
+#if H_3D_NBDV_REF
+  Bool m_depthRefinementFlag;  
+#endif
+#if H_3D_VSP
+  Bool m_viewSynthesisPredFlag;
 #endif
 #endif
Index: branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncTop.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncTop.cpp	(revision 486)
@@ -1045,5 +1045,11 @@
       {
 #if H_3D_IV_MERGE
-        vps.setIvMvPredFlag( layer, m_ivMvPredFlag ); 
+        vps.setIvMvPredFlag       ( layer, m_ivMvPredFlag ); 
+#endif
+#if H_3D_NBDV_REF
+        vps.setDepthRefinementFlag( layer, m_depthRefinementFlag );         
+#endif
+#if H_3D_VSP
+        vps.setViewSynthesisPredFlag( layer, m_viewSynthesisPredFlag );         
 #endif
       }
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp	(revision 486)
@@ -2469,4 +2469,7 @@
 
   cDisInfo.bDV = getDvInfo(uiAbsPartIdx).bDV;
+#if H_3D_NBDV_REF
+  cDisInfo.m_acDoNBDV = getDvInfo(uiAbsPartIdx).m_acDoNBDV;
+#endif //H_3D_NBDV_REF
   cDisInfo.m_acNBDV = getDvInfo(uiAbsPartIdx).m_acNBDV;
   cDisInfo.m_aVIdxCan = getDvInfo(uiAbsPartIdx).m_aVIdxCan;
@@ -4182,4 +4185,10 @@
     }
   }
+#if H_3D_NBDV_REF
+  if( !m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ) )
+  {
+    bDepthRefine = false;
+  }
+#endif
   // Get Positions  
   PartSize eCUMode    = getPartitionSize( uiPartAddr );    
@@ -4241,7 +4250,22 @@
 
 #if H_3D_NBDV_REF
-          /*Place DoNBDV*/ 
+          TComPic* picDepth = NULL;          
+          picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
+          assert(picDepth != NULL);
+          if (picDepth && bDepthRefine)
+            estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
+
+          //Notes from MTK: Please uncomment the following parts while integrating VSP
+#if H_3D_VSP
+          Int refFrmIdx = 0;
+          RefPicList privateRefPicList = REF_PIC_LIST_0;
+          //getRefListAndRefFrmIdx(iTargetViewIdx, privateRefPicList, refFrmIdx);
+
+          //pDInfo->m_aListIdx[ pDInfo->iN ]  = privateRefPicList;
+          //pDInfo->m_aRefIdx [ pDInfo->iN ]  = -1-refFrmIdx;
+          assert(pDInfo->m_aRefIdx [ pDInfo->iN ] < 0);
+#endif //H_3D_VSP
           pDInfo->m_acDoNBDV  = cColMv;
-#endif
+#endif //H_3D_NBDV_REF
           return true;
         }
@@ -4332,7 +4356,21 @@
           pDInfo->m_aVIdxCan = 0;
 #if H_3D_NBDV_REF
-          /*Place DoNBDV*/
+          TComPic* picDepth = getSlice()->getIvPic( true, 0 );
+          assert(picDepth!=NULL);
+
+          if (picDepth && bDepthRefine)
+            estimateDVFromDM(0, uiPartIdx, picDepth, uiPartAddr, &cDispVec ); // from base view
 
           pDInfo->m_acDoNBDV = cDispVec;
+          
+#if H_3D_VSP
+          Int refFrmIdx = 0;
+          RefPicList privateRefPicList = REF_PIC_LIST_0 ;
+          getRefListAndRefFrmIdx(0, privateRefPicList, refFrmIdx); // find the reference picture from base view
+
+          pDInfo->m_aListIdx[ pDInfo->iN ]  = privateRefPicList;
+          pDInfo->m_aRefIdx [ pDInfo->iN ]  = -1-refFrmIdx;
+          assert(pDInfo->m_aRefIdx [ pDInfo->iN ] < 0);
+#endif //H_3D_VSP
           
 #endif
@@ -4347,10 +4385,72 @@
   pDInfo->m_aVIdxCan = 0;
 #if H_3D_NBDV_REF
-  /*Place DoNBDV*/
-  
+  TComPic* picDepth = NULL;
+  picDepth = getSlice()->getIvPic( true, 0 );
+  assert(picDepth!=NULL);
+
+  if (picDepth && bDepthRefine)
+  {
+    estimateDVFromDM(0, uiPartIdx, picDepth, uiPartAddr, &defaultDV ); // from base view
+  }
   pDInfo->m_acDoNBDV = defaultDV;
+
+#if H_3D_VSP
+  Int refFrmIdx = 0;
+  RefPicList privateRefPicList = REF_PIC_LIST_0 ;
+  getRefListAndRefFrmIdx(0, privateRefPicList, refFrmIdx); // find the reference picture from base view
+
+  pDInfo->m_aListIdx[ pDInfo->iN ]  = privateRefPicList;
+  pDInfo->m_aRefIdx [ pDInfo->iN ]  = -1-refFrmIdx;
+  assert(pDInfo->m_aRefIdx [ pDInfo->iN ] < 0);
+#endif
 #endif
   return false; 
 }
+
+#if H_3D_NBDV_REF
+Pel TComDataCU::getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iBlkWidth, Int iBlkHeight, Int* aiShiftLUT )
+{
+  Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth();
+  Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
+  
+
+  Int depthStartPosX = Clip3(0,   iPictureWidth - iBlkWidth,  iBlkX + ((mv->getHor()+2)>>2));
+  Int depthStartPosY = Clip3(0,   iPictureHeight- iBlkHeight,  iBlkY + ((mv->getVer()+2)>>2));
+  Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
+  Int depthEndPosY   = Clip3(0,   iPictureHeight - 1,  iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
+
+  Pel* depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
+  Int depStride =  pcBaseViewDepthPicYuv->getStride();
+
+  Pel  maxDepthVal = 0;
+  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthStartPosX ]);      // Left Top
+  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthStartPosX ]);      // Left Bottom
+  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthEndPosX   ]);      // Right Top
+  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthEndPosX   ]);      // Right Bottom
+
+  return aiShiftLUT[ maxDepthVal ];
+}
+
+Void TComDataCU::estimateDVFromDM(Int refViewIdx, UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred )
+{
+  if (picDepth)
+  {
+    UInt uiAbsPartAddrCurrCU = m_uiAbsIdxInLCU + uiPartAddr;
+    Int iWidth, iHeight;
+    getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); // The modified value of uiPartAddr won't be used any more
+
+    TComPicYuv* pcBaseViewDepthPicYuv = picDepth->getPicYuvRec();
+    Int iBlkX = ( getAddr() % picDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
+    Int iBlkY = ( getAddr() / picDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
+    
+    Int* aiShiftLUT = getSlice()->getDepthToDisparityB(refViewIdx );
+
+    Pel iDisp = getMcpFromDM( pcBaseViewDepthPicYuv, cMvPred, iBlkX, iBlkY, iWidth, iHeight, aiShiftLUT );
+    cMvPred->setHor( iDisp );
+    clipMv(*cMvPred);
+  }
+}
+#endif //H_3D_NBDV_REF
+
 
 Bool TComDataCU::xCheckSpatialNBDV( TComDataCU* pcTmpCU, UInt uiIdx, DisInfo* pNbDvInfo, Bool bSearchForMvpDv, IDVInfo* paIDVInfo, UInt uiMvpDvPos
@@ -4378,5 +4478,15 @@
           pNbDvInfo->m_aVIdxCan = refViewIdx;
 #if H_3D_NBDV_REF
-          /*Place DoNBDV*/
+          TComPic* picDepth = NULL;          
+          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());          
+          picDepth   = getSlice()->getIvPic (true, refViewIdx );          
+          assert(picDepth != NULL);
+
+          UInt uiPartIdx = 0;   //Notes from MTK: Please confirm that using 0 as partition index and partition address is correct for CU-level DoNBDV
+          UInt uiPartAddr = 0;
+
+          if (picDepth && bDepthRefine)
+            estimateDVFromDM(refViewIdx, uiPartIdx, picDepth, uiPartAddr, &cMvPred );
+
           
           pNbDvInfo->m_acDoNBDV = cMvPred;
@@ -4548,6 +4658,13 @@
   iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
 
-  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acNBDV.getHor() + 2 ) >> 2 ) );
-  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acNBDV.getVer() + 2 ) >> 2 )); 
+  Bool depthRefineFlag = false; 
+#if H_3D_NBDV_REF
+  depthRefineFlag = m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ); 
+#endif // H_3D_NBDV_REF
+
+  TComMv      cDv = depthRefineFlag ? pDInfo->m_acNBDV : pDInfo->m_acDoNBDV; 
+
+  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
+  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
 
   Int         iBaseCUAddr;
@@ -4611,5 +4728,7 @@
         paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
 
-        TComMv cMv = pDInfo->m_acNBDV; 
+#if H_3D_NBDV_REF
+        TComMv cMv = depthRefineFlag ? pDInfo->m_acNBDV : pDInfo->m_acDoNBDV; 
+#endif // H_3D_NBDV_REF
         cMv.setVer(0);
         clipMv( cMv );
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.h	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.h	(revision 486)
@@ -433,4 +433,8 @@
    ); 
    
+#if H_3D_NBDV_REF
+  Pel           getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iWidth, Int iHeight, Int* aiShiftLUT );
+  Void          estimateDVFromDM(Int refViewIdx, UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred );
+#endif //H_3D_NBDV_REF
 #endif
 #if H_3D_IV_MERGE
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.cpp	(revision 486)
@@ -114,4 +114,8 @@
 , m_isDepth                       (false)
 #endif
+#if H_3D_GEN
+, m_depthToDisparityB             ( NULL )
+, m_depthToDisparityF             ( NULL )
+#endif
 #endif
 {
@@ -160,4 +164,24 @@
   delete[] m_puiSubstreamSizes;
   m_puiSubstreamSizes = NULL;
+#if H_3D_GEN    
+  for( UInt i = 0; i < getViewIndex(); i++ )
+  {
+    if ( m_depthToDisparityB && m_depthToDisparityB[ i ] )
+      delete[] m_depthToDisparityB [ i ];
+
+    if ( m_depthToDisparityF && m_depthToDisparityF[ i ] ) 
+      delete[] m_depthToDisparityF [ i ];
+  }
+
+  if ( m_depthToDisparityF )
+    delete[] m_depthToDisparityF; 
+
+  m_depthToDisparityF = NULL;
+
+  if ( m_depthToDisparityB )
+    delete[] m_depthToDisparityB; 
+
+  m_depthToDisparityB = NULL;
+#endif
 }
 
@@ -837,4 +861,5 @@
 #if H_MV
   m_layerId              = pSrc->m_layerId;
+  // GT: Copying of several other values might be be missing here, or is above not necessary? 
 #endif
   m_eSliceType           = pSrc->m_eSliceType;
@@ -1491,8 +1516,15 @@
     }
   }
+#if H_3D_GEN
+  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )  {
 #if H_3D_IV_MERGE
-  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
-  {
-    m_ivMvPredFlag[ i ] = false;
+    m_ivMvPredFlag         [ i ] = false;
+#endif
+#if H_3D_VSP
+    m_viewSynthesisPredFlag[ i ] = false;
+#endif
+#if H_3D_NBDV_REF
+    m_depthRefinementFlag  [ i ] = false;
+#endif
   }
 #endif
@@ -2278,4 +2310,65 @@
   }  
 }
+Void TComSlice::setDepthToDisparityLUTs()
+{ 
+  Bool setupLUT = false; 
+  Int layerIdInVPS = getVPS()->getLayerIdInNuh( m_layerId ); 
+
+#if H_3D_VSP
+  setupLUT = setupLUT || getVPS()->getViewSynthesisPredFlag( layerIdInVPS); 
+#endif
+
+#if H_3D_NBDV_REF
+  setupLUT = setupLUT || getVPS()->getDepthRefinementFlag( layerIdInVPS );
+#endif 
+
+  if( !setupLUT )
+    return; 
+
+  /// GT: Allocation should be moved to a better place later; 
+  if ( m_depthToDisparityB == NULL )
+  {
+    m_depthToDisparityB = new Int*[ getViewIndex() ];
+    for ( Int i = 0; i < getViewIndex(); i++ )
+    {
+      m_depthToDisparityB[ i ] = new Int[ Int(1 << g_bitDepthY) ]; 
+    }
+  }
+
+  if ( m_depthToDisparityF == NULL )
+  {
+    m_depthToDisparityF= new Int*[ getViewIndex() ];
+    for ( Int i = 0; i < getViewIndex(); i++ )
+    {
+      m_depthToDisparityF[ i ] = new Int[ Int(1 << g_bitDepthY) ]; 
+    }
+  }
+
+  assert( m_depthToDisparityB != NULL ); 
+  assert( m_depthToDisparityF != NULL ); 
+
+  TComSPS* sps = getSPS(); 
+
+  Int log2Div = g_bitDepthY - 1 + sps->getCamParPrecision();
+
+  Bool camParaSH = m_pcSPS->hasCamParInSliceHeader();
+
+  Int* codScale     = camParaSH ? m_aaiCodedScale [ 0 ] : sps->getCodedScale    (); 
+  Int* codOffset    = camParaSH ? m_aaiCodedOffset[ 0 ] : sps->getCodedOffset   (); 
+  Int* invCodScale  = camParaSH ? m_aaiCodedScale [ 1 ] : sps->getInvCodedScale (); 
+  Int* invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : sps->getInvCodedOffset(); 
+
+  for (Int i = 0; i <= ( getViewIndex() - 1); i++)
+  {
+    for ( Int d = 0; d <= ( ( 1 << g_bitDepthY ) - 1 ); d++ )
+    {
+      Int offset =    ( codOffset  [ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
+      m_depthToDisparityB[ i ][ d ] = ( codScale [ i ] * d + offset ) >> log2Div; 
+
+      Int invOffset = ( invCodOffset[ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
+      m_depthToDisparityF[ i ][ d ] = ( invCodScale[ i ] * d + invOffset ) >> log2Div; 
+    }
+  }
+}
 #endif
 #endif
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.h	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.h	(revision 486)
@@ -540,4 +540,10 @@
   Bool        m_ivMvPredFlag             [ MAX_NUM_LAYERS ]; 
 #endif
+#if H_3D_VSP
+  Bool        m_viewSynthesisPredFlag    [ MAX_NUM_LAYERS ]; 
+#endif
+#if H_3D_NBDV_REF
+  Bool        m_depthRefinementFlag      [ MAX_NUM_LAYERS ]; 
+#endif
 #endif
 public:
@@ -676,4 +682,12 @@
   Void    setIvMvPredFlag     ( Int layerIdInVps, Bool val )  { m_ivMvPredFlag[ layerIdInVps ] = val; }
   Bool    getIvMvPredFlag     ( Int layerIdInVps )            { return m_ivMvPredFlag[ layerIdInVps ]; }; 
+#endif
+#if H_3D_VSP
+  Void    setViewSynthesisPredFlag  ( Int layerIdInVps, Bool val )  { m_viewSynthesisPredFlag[ layerIdInVps ] = val; }
+  Bool    getViewSynthesisPredFlag  ( Int layerIdInVps )            { return m_viewSynthesisPredFlag[ layerIdInVps ]; }; 
+#endif
+#if H_3D_NBDV_REF
+  Void    setDepthRefinementFlag  ( Int layerIdInVps, Bool val )  { m_depthRefinementFlag[ layerIdInVps ] = val; }
+  Bool    getDepthRefinementFlag  ( Int layerIdInVps )            { return m_depthRefinementFlag[ layerIdInVps ]; }; 
 #endif
 #endif
@@ -1495,4 +1509,6 @@
 #if H_3D_GEN
   TComPic*   m_ivPicsCurrPoc [2][MAX_NUM_LAYERS];  
+  Int**      m_depthToDisparityB; 
+  Int**      m_depthToDisparityF; 
 #endif
 #endif
@@ -1776,4 +1792,9 @@
 #if H_3D_GEN
   Void    setIvPicLists( TComPicLists* m_ivPicLists );
+  Void    setDepthToDisparityLUTs();
+
+  Int* getDepthToDisparityB( Int refViewIdx ) { return m_depthToDisparityB[ refViewIdx ]; }; 
+  Int* getDepthToDisparityF( Int refViewIdx ) { return m_depthToDisparityF[ refViewIdx ]; }; 
+  
 #endif
 
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TypeDef.h	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TypeDef.h	(revision 486)
@@ -88,4 +88,8 @@
                                               // QC_CU_NBDV_D0181
                                               // SEC_DEFAULT_DV_D0112
+#define H_3D_NBDV_REF                     1   // Depth oriented neighboring block disparity derivation
+                                              // MTK_D0156
+                                              // MERL_VSP_NBDV_RefVId_Fix_D0166
+#define H_3D_VSP                          0   // Depth oriented neighboring block disparity derivation
 
 #define H_3D_IV_MERGE                     1   // Inter-view motion merge candidate
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 486)
@@ -954,5 +954,5 @@
     {
 #if H_3D
-#if H_3D_IV_MERGE
+#if H_3D_GEN
       for( Int layer = 0; layer <= pcVPS->getMaxLayers() - 1; layer++ )
       {
@@ -961,5 +961,13 @@
           if ( !( pcVPS->getDepthId( layer ) == 1 ) )
           {
-            READ_FLAG( uiCode, "ivMvPredFlag[i]"); pcVPS->setIvMvPredFlag( layer, uiCode == 1 ? true : false );
+#if H_3D_IV_MERGE
+            READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( layer, uiCode == 1 ? true : false );
+#endif
+#if H_3D_NBDV_REF
+            READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( layer, uiCode == 1 ? true : false );
+#endif
+#if H_3D_VSP
+            READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( layer, uiCode == 1 ? true : false );
+#endif
           }          
         }        
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCu.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCu.cpp	(revision 486)
@@ -292,5 +292,5 @@
       m_ppcCU[uiDepth]->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
 #if H_3D_NBDV_REF
-      if(pcCU->getSlice()->getSPS()->getUseDVPRefine())  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
+      if(pcCU->getSlice()->getVPS()->getDepthRefinementFlag( pcCU->getSlice()->getLayerIdInVps() ))  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
         DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo, true);
       else
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.cpp	(revision 486)
@@ -159,4 +159,7 @@
   }
 #endif
+#if H_3D_GEN
+  pcSlice->setDepthToDisparityLUTs(); 
+#endif
   m_pcSbacDecoders[0].load(m_pcSbacDecoder);
   m_pcSliceDecoder->decompressSlice( ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders);
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 486)
@@ -750,5 +750,11 @@
       {
 #if H_3D_IV_MERGE
-        WRITE_FLAG( pcVPS->getIvMvPredFlag(layer) ? 1 : 0 , "ivMvPredFlag[i]");
+        WRITE_FLAG( pcVPS->getIvMvPredFlag         (layer) ? 1 : 0 , "iv_mv_pred_flag[i]");
+#endif
+#if H_3D_NBDV_REF
+        WRITE_FLAG( pcVPS->getDepthRefinementFlag  (layer) ? 1 : 0 , "depth_refinement_flag[i]");
+#endif
+#if H_3D_VSP
+        WRITE_FLAG( pcVPS->getViewSynthesisPredFlag(layer) ? 1 : 0 , "view_synthesis_pred_flag[i]");
 #endif
       }          
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp	(revision 486)
@@ -473,5 +473,5 @@
           rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
 #if H_3D_NBDV_REF
-          if(m_pcSlice->getSPS()->getUseDVPRefine())  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
+          if(rpcTempCU->getSlice()->getVPS()->getDepthRefinementFlag( rpcTempCU->getSlice()->getLayerIdInVps()))
             DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(&DvInfo, true);
           else
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 486)
@@ -1048,4 +1048,8 @@
         pcPic->setNumDdvCandPics(pcPic->getDisCandRefPictures(iColPoc));
       }
+#if H_3D_GEN
+      pcSlice->setDepthToDisparityLUTs(); 
+
+#endif
 #endif
     while(nextCUAddr<uiRealEndAddress) // determine slice boundaries
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 485)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 486)
@@ -544,5 +544,5 @@
   rpcSlice->setSliceSegmentArgument ( m_pcCfg->getSliceSegmentArgument() );
 #if H_3D_IV_MERGE
-  rpcSlice->setMaxNumMergeCand      ( m_pcCfg->getMaxNumMergeCand()   + ( rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ? 1 : 0 ) );
+   rpcSlice->setMaxNumMergeCand      ( m_pcCfg->getMaxNumMergeCand()   + ( rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ? 1 : 0 ) );
 #else
   rpcSlice->setMaxNumMergeCand        ( m_pcCfg->getMaxNumMergeCand()        );
