Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComDataCU.cpp	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComDataCU.cpp	(revision 597)
@@ -144,4 +144,7 @@
 #if H_3D_VSP
   m_piVSPFlag            = NULL;
+#if MTK_VSP_FIX_E0172
+  m_piVSPDir             = NULL;
+#endif
 #endif
 #if H_3D_ARP
@@ -187,4 +190,7 @@
 #if H_3D_VSP
     m_piVSPFlag          = (Char*  )xMalloc(Char,   uiNumPartition);
+#if MTK_VSP_FIX_E0172
+    m_piVSPDir           = (Char*  )xMalloc(Char,   uiNumPartition);
+#endif
 #endif
     m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
@@ -336,4 +342,7 @@
 #if H_3D_VSP
     if ( m_piVSPFlag          ) { xFree(m_piVSPFlag);           m_piVSPFlag         = NULL; }
+#if MTK_VSP_FIX_E0172
+    if ( m_piVSPDir           ) { xFree(m_piVSPDir  );          m_piVSPDir          = NULL; }
+#endif
 #endif
     if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
@@ -532,4 +541,7 @@
 #if H_3D_VSP
     m_piVSPFlag[ui] = pcFrom->m_piVSPFlag[ui];
+#if MTK_VSP_FIX_E0172
+    m_piVSPDir  [ui] = pcFrom->m_piVSPDir[ui];
+#endif
 #endif
     m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
@@ -571,4 +583,7 @@
 #if H_3D_VSP
     memset( m_piVSPFlag         + firstElement, 0,                        numElements * sizeof( *m_piVSPFlag ) );
+#if MTK_VSP_FIX_E0172
+    memset( m_piVSPDir          + firstElement, 0,                        numElements * sizeof( *m_piVSPDir   ) );
+#endif
 #endif
     memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
@@ -743,4 +758,7 @@
 #if H_3D_VSP
       m_piVSPFlag[ui] = 0;
+#if MTK_VSP_FIX_E0172
+      m_piVSPDir  [ui] = 0;
+#endif
 #endif
       m_puhLumaIntraDir[ui] = DC_IDX;
@@ -835,4 +853,7 @@
 #if H_3D_VSP
   memset( m_piVSPFlag,          0, sizeof( Char  ) * m_uiNumPartition );
+#if MTK_VSP_FIX_E0172
+  memset( m_piVSPDir  ,         0, sizeInChar );
+#endif
 #endif
   memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
@@ -922,4 +943,10 @@
 #if H_3D_VSP
       m_piVSPFlag[ui]=pcCU->m_piVSPFlag[uiPartOffset+ui];
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+      m_pDvInfo[ ui ] = pcCU->m_pDvInfo[uiPartOffset+ui];
+#endif
+#if MTK_VSP_FIX_E0172
+      m_piVSPDir[ui]=pcCU->m_piVSPDir[uiPartOffset+ui];
+#endif
 #endif
       m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
@@ -1064,4 +1091,7 @@
 #if H_3D_VSP
   m_piVSPFlag           = pcCU->getVSPFlag()          + uiPart;
+#if MTK_VSP_FIX_E0172
+  m_piVSPDir            = pcCU->getVSPDir  ()         + uiPart;
+#endif
 #endif
 
@@ -1211,4 +1241,10 @@
 #if H_3D_VSP
   m_piVSPFlag          = pcCU->getVSPFlag()               + uiAbsPartIdx;
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+  m_pDvInfo            = pcCU->getDvInfo()                + uiAbsPartIdx;
+#endif
+#if MTK_VSP_FIX_E0172
+  m_piVSPDir           = pcCU->getVSPDir  ()              + uiAbsPartIdx;
+#endif
 #endif
 
@@ -1258,4 +1294,10 @@
 #if H_3D_VSP
   memcpy( m_piVSPFlag           + uiOffset, pcCU->getVSPFlag(),           sizeof( Char ) * uiNumPartition );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+  memcpy( m_pDvInfo             + uiOffset, pcCU->getDvInfo(),            sizeof( *m_pDvInfo ) * uiNumPartition );
+#endif
+#if MTK_VSP_FIX_E0172
+  memcpy( m_piVSPDir            + uiOffset, pcCU->getVSPDir  (),          sizeInChar );
+#endif
 #endif
   memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
@@ -1378,4 +1420,10 @@
 #if H_3D_VSP
   memcpy( rpcCU->getVSPFlag()           + m_uiAbsIdxInLCU, m_piVSPFlag,           sizeof( Char ) * m_uiNumPartition );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+  memcpy( rpcCU->getDvInfo()            + m_uiAbsIdxInLCU, m_pDvInfo,             sizeof( *m_pDvInfo ) * m_uiNumPartition );
+#endif
+#if MTK_VSP_FIX_E0172
+  memcpy( rpcCU->getVSPDir  ()          + m_uiAbsIdxInLCU, m_piVSPDir  ,          sizeInChar );
+#endif
 #endif
   memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
@@ -1486,4 +1534,7 @@
 #if H_3D_VSP
   memcpy( rpcCU->getVSPFlag()           + uiPartOffset, m_piVSPFlag,           sizeof(Char) * uiQNumPart );
+#if MTK_VSP_FIX_E0172
+  memcpy( rpcCU->getVSPDir  ()          + uiPartOffset, m_piVSPDir  ,          sizeInChar );
+#endif
 #endif
   memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
@@ -2489,4 +2540,146 @@
   setSubPart<Char>( iVSPFlag, m_piVSPFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
 }
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+template<typename T>
+Void TComDataCU::setSubPartT( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
+{
+  UInt uiCurrPartNumQ = (m_pcPic->getNumPartInCU() >> (2 * uiCUDepth)) >> 2;
+  switch ( m_pePartSize[ uiCUAddr ] )
+  {
+  case SIZE_2Nx2N:
+    for (UInt ui = 0; ui < 4 * uiCurrPartNumQ; ui++)
+      puhBaseLCU[uiCUAddr + ui] = uiParameter;
+
+    break;
+  case SIZE_2NxN:
+    for (UInt ui = 0; ui < 2 * uiCurrPartNumQ; ui++)
+      puhBaseLCU[uiCUAddr + ui] = uiParameter;
+    break;
+  case SIZE_Nx2N:
+    for (UInt ui = 0; ui < uiCurrPartNumQ; ui++)
+      puhBaseLCU[uiCUAddr + ui] = uiParameter;
+    for (UInt ui = 0; ui < uiCurrPartNumQ; ui++)
+      puhBaseLCU[uiCUAddr + 2 * uiCurrPartNumQ + ui] = uiParameter;
+    break;
+  case SIZE_NxN:
+    for (UInt ui = 0; ui < uiCurrPartNumQ; ui++)
+      puhBaseLCU[uiCUAddr + ui] = uiParameter;
+    break;
+  case SIZE_2NxnU:
+    if ( uiPUIdx == 0 )
+    {
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 1); ui++)
+        puhBaseLCU[uiCUAddr + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 1); ui++)
+        puhBaseLCU[uiCUAddr + uiCurrPartNumQ + ui] = uiParameter;
+
+    }
+    else if ( uiPUIdx == 1 )
+    {
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 1); ui++)
+        puhBaseLCU[uiCUAddr + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1); ui++)
+        puhBaseLCU[uiCUAddr + uiCurrPartNumQ + ui] = uiParameter;
+
+    }
+    else
+    {
+      assert(0);
+    }
+    break;
+  case SIZE_2NxnD:
+    if ( uiPUIdx == 0 )
+    {
+      for (UInt ui = 0; ui < ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)); ui++)
+        puhBaseLCU[uiCUAddr + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 1); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + ui] = uiParameter;
+
+    }
+    else if ( uiPUIdx == 1 )
+    {
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 1); ui++)
+        puhBaseLCU[uiCUAddr + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 1); ui++)
+        puhBaseLCU[uiCUAddr + uiCurrPartNumQ + ui] = uiParameter;
+
+    }
+    else
+    {
+      assert(0);
+    }
+    break;
+  case SIZE_nLx2N:
+    if ( uiPUIdx == 0 )
+    {
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ >> 1) + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ << 1) + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1) + ui] = uiParameter;
+
+    }
+    else if ( uiPUIdx == 1 )
+    {
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ >> 1) + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ << 1) + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1) + ui] = uiParameter;
+
+    }
+    else
+    {
+      assert(0);
+    }
+    break;
+  case SIZE_nRx2N:
+    if ( uiPUIdx == 0 )
+    {
+      for (UInt ui = 0; ui < (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)); ui++)
+        puhBaseLCU[uiCUAddr + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1) + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ << 1) + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1) + ui] = uiParameter;
+
+    }
+    else if ( uiPUIdx == 1 )
+    {
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ >> 1) + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ << 1) + ui] = uiParameter;
+      for (UInt ui = 0; ui < (uiCurrPartNumQ >> 2); ui++)
+        puhBaseLCU[uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1) + ui] = uiParameter;
+
+    }
+    else
+    {
+      assert(0);
+    }
+    break;
+  default:
+    assert( 0 );
+  }
+
+}
+#endif
+#if MTK_VSP_FIX_E0172
+Void TComDataCU::setVSPDirSubParts ( Char iVSPDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
+{
+  setSubPart<Char>( iVSPDir, m_piVSPDir, uiAbsPartIdx, uiDepth, uiPartIdx );
+}
+#endif
 #endif
 Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
@@ -2941,6 +3134,11 @@
  *   false: otherwise
  */
+#if MTK_VSP_FIX_E0172
+inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
+                                    Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag, Int* vspDir )
+#else
 inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
                                      Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag )
+#endif
 {
   if ( ucVspMergePos != H_3D_VSP_POSITION || 0 == m_pcSlice->getViewIndex() || !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) || m_pcSlice->getIsDepth() )
@@ -2957,5 +3155,14 @@
   Int  iRefListIdY = 0;
   Int  i;
-
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+  Int currViewId = m_pcSlice->getViewId();
+  Int derivedViewId = -1;
+  Int otherViewId = -1;
+#endif
+#if MTK_VSP_FIX_E0172
+  Int currViewId = m_pcSlice->getViewId();
+  Int derivedViewId = -1;
+  Int otherViewId = -1;
+#endif
   for( iRefListIdX = 0; iRefListIdX < 2 && !refViewAvailFlag; iRefListIdX++ )
   {
@@ -2968,6 +3175,17 @@
         refViewAvailFlag = true;
         predFlag[iRefListIdX] = 1;
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+        derivedViewId = m_pcSlice->getRefPic(eRefPicList, i)->getViewId();
+#endif
+#if MTK_VSP_FIX_E0172
+        vspDir[iCount] = iRefListIdX;
+        derivedViewId = m_pcSlice->getRefPic(eRefPicList, i)->getViewId(); 
+#endif
         iRefListIdY = 1 - iRefListIdX;
+#if H_3D_BVSP_FIX
+        pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].setMvField( pDInfo->m_acNBDV, i );
+#else
         pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].setMvField( pDInfo->m_acDoNBDV, i );
+#endif
 #if H_3D_NBDV
         pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].getMv().setIDVFlag (false);
@@ -2988,5 +3206,30 @@
         refViewAvailFlag = true;
         predFlag[iRefListIdY] = 1;
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_BVSP_FIX
+        TComMv  cMv = pDInfo->m_acNBDV;
+#else
+        TComMv  cMv = pDInfo->m_acDoNBDV;
+#endif
+        otherViewId = m_pcSlice->getRefPic( eRefPicList, i)->getViewId();
+        Int iScale = xGetDistScaleFactor( currViewId, otherViewId, currViewId, derivedViewId );
+        if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
+        {
+          cMv = cMv.scaleMv( iScale );
+        }
+        else
+        {
+
+          cMv = cMv;
+        }
+        clipMv( cMv );
+        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( cMv, i );
+#else
+#if H_3D_BVSP_FIX
+        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( pDInfo->m_acNBDV, i );
+#else
         pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( pDInfo->m_acDoNBDV, i );
+#endif
+#endif
 #if H_3D_NBDV
         pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].getMv().setIDVFlag (false);
@@ -3009,4 +3252,101 @@
 }
 
+#endif
+
+#if QC_INRIA_MTK_MRG_E0126
+inline Bool TComDataCU::xAddIvMRGCand( Int mrgCandIdx, Int& iCount, Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int*   iPdmDir, TComMv* acPdmMv, 
+                                       Int* aiPdmRefIdx, Int iPosDmv, Int* vspFlag )
+{
+  for(Int iLoop = 0; iLoop  < 2; iLoop ++ ) 
+  {
+    if( iLoop == 1 )
+    {
+      Int iFirDispCand = -1;
+      if (xFirstDmvAvai(iCount, pcMvFieldNeighbours, iPdmDir, iPosDmv, vspFlag, iFirDispCand))
+      {
+        TComMv cMv;
+        cMv = pcMvFieldNeighbours[(iFirDispCand<<1)].getMv();
+        cMv.setHor(cMv.getHor()+4);
+        if(m_pcSlice->getVPS()->getViewSynthesisPredFlag(m_pcSlice->getLayerIdInVps()))
+        {
+          cMv.setVer(0);
+        }
+        clipMv( cMv );
+        abCandIsInter[ iCount ] = true;
+        puhInterDirNeighbours[ iCount ] = puhInterDirNeighbours[iFirDispCand];
+        pcMvFieldNeighbours[ iCount<<1  ].setMvField(cMv, pcMvFieldNeighbours[( iFirDispCand << 1)].getRefIdx() );
+        pcMvFieldNeighbours[ (iCount<<1)+1 ].setMvField(pcMvFieldNeighbours[(iFirDispCand << 1) + 1].getMv(), pcMvFieldNeighbours[( iFirDispCand << 1) + 1].getRefIdx() );
+        if( mrgCandIdx == iCount ) 
+        {
+          return true;
+        }
+        iCount++;
+        break;
+      }
+    }
+    if(iPdmDir[iLoop + 2])
+    {
+      abCandIsInter[ iCount ] = true;
+      puhInterDirNeighbours[ iCount ] = iPdmDir[iLoop + 2];
+      if( ( iPdmDir[iLoop + 2] & 1 ) == 1 )
+      {
+        pcMvFieldNeighbours[ iCount<<1 ].setMvField( acPdmMv[ (iLoop<<1) + 4 ], aiPdmRefIdx[ (iLoop<<1) + 4 ] ); 
+      }
+      if( ( iPdmDir[iLoop + 2] & 2 ) == 2 )
+      {
+        pcMvFieldNeighbours[ (iCount<<1)+1 ].setMvField( acPdmMv[ (iLoop<<1) + 5 ], aiPdmRefIdx[ (iLoop<<1) + 5 ] );
+      }
+     
+      bool bRemove = false;
+      if(!iLoop && iPdmDir[0] > 0)
+      {
+        if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[0] && pcMvFieldNeighbours[0]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[1]==pcMvFieldNeighbours[(iCount<<1)+1])
+        {
+            bRemove                      = true;
+            abCandIsInter        [ iCount ] = false;  
+            puhInterDirNeighbours[iCount]   = 0;
+            TComMv  cZeroMv;
+            pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
+            pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
+        }
+      }
+      if(!bRemove)
+      {
+#if H_3D_NBDV
+        if(iLoop)
+        {
+          pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
+          pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
+        }
+#endif
+        if( mrgCandIdx == iCount )
+        {
+          return true;
+        }
+        iCount++;
+      }
+      break;
+    }
+  }
+  return false;
+} 
+
+inline Bool TComDataCU::xFirstDmvAvai( Int& iCount, TComMvField* pcMvFieldNeighbours, Int* iPdmDir, Int iPosDmv, Int* vspFlag, Int& iFirDispCand )
+{
+  for ( Int i = (iPdmDir[0] ? 1: 0); i < iCount; i++ )
+  {
+    if ( ( i == iPosDmv ) || ( vspFlag[ i ] == 1 ) )
+    {
+      continue;
+    }
+    else if((pcMvFieldNeighbours[i<<1].getRefIdx()!=-1) && (getSlice()->getViewIndex() != getSlice()->getRefPic(RefPicList(0), pcMvFieldNeighbours[i<<1].getRefIdx())->getViewIndex()))
+    {
+      iFirDispCand = i;
+      return true;
+    }
+  }
+ return false;  
+}
+                                      
 #endif
 /** Constructs a list of merging candidates
@@ -3021,4 +3361,10 @@
 #if H_3D_VSP
       , Int* vspFlag
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+      , InheritedVSPDisInfo*  inheritedVSPDisInfo
+#endif
+#if MTK_VSP_FIX_E0172
+      , Int* vspDir
+#endif
 #endif
       , Int& numValidMergeCand, Int mrgCandIdx
@@ -3058,6 +3404,12 @@
 
   //===== add merge with predicted depth maps =====
+#if QC_INRIA_MTK_MRG_E0126
+  TComMv acPdmMv         [8];
+  Int aiPdmRefIdx        [8] = {-1, -1, -1, -1, -1, -1, -1, -1};
+  Int iPosDmv                = -1;
+#else 
   TComMv  acPdmMv       [4];
   Int     aiPdmRefIdx   [4] = {-1, -1, -1, -1};
+#endif
   Bool    bLeftAvai         = false;
   Int     iPosLeftAbove[2]  = {-1, -1};
@@ -3072,5 +3424,10 @@
   cDisInfo.m_acNBDV = getDvInfo(uiAbsPartIdx).m_acNBDV;
   cDisInfo.m_aVIdxCan = getDvInfo(uiAbsPartIdx).m_aVIdxCan;
-
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+  for(Int i = 0; i < MRG_MAX_NUM_CANDS_MEM; i++)
+  {
+    inheritedVSPDisInfo[i].m_acDvInfo = cDisInfo;
+  }
+#endif
   if( m_pcSlice->getIsDepth())
   {
@@ -3081,4 +3438,45 @@
     if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdxCenter ) )
     {
+#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
+      pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
+      Int iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1].getRefIdx() );
+      if( (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0) && ( iValidDepRef >= 0 ) )
+      {
+        TComMv cMvPred = pcMvFieldNeighbours[iCount<<1].getMv();
+        const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
+        cMvPred+=cAdd;
+        cMvPred>>=2;
+        clipMv(cMvPred);
+        pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,iValidDepRef);
+      }
+
+      if ( getSlice()->isInterB() )
+      {
+        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
+        iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx() );
+        if( (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0) && ( iValidDepRef >= 0) )
+        {
+          TComMv cMvPred = pcMvFieldNeighbours[(iCount<<1)+1].getMv();
+          const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
+          cMvPred+=cAdd;
+          cMvPred>>=2;
+          clipMv(cMvPred);
+          pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,iValidDepRef);
+        }
+      }
+
+      puhInterDirNeighbours[iCount] = (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0)?1:0;
+      puhInterDirNeighbours[iCount] += (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0)?2:0;
+
+      if( puhInterDirNeighbours[iCount] != 0 )
+      {
+        abCandIsInter[iCount] = true;
+        if ( mrgCandIdx == iCount )
+        {
+          return;
+        }
+        iCount ++;
+      }
+#else
       abCandIsInter[iCount] = true;      
       puhInterDirNeighbours[iCount] = pcTextureCU->getInterDir( uiPartIdxCenter );
@@ -3124,8 +3522,13 @@
       }
       iCount ++;
-    }
-  }
-
+#endif//Bug fix
+    }
+  }
+
+#if QC_INRIA_MTK_MRG_E0126
+  Int iPdmDir[4] = {0, 0, 0, 0};
+#else
   Int iPdmDir[2] = {0, 0};
+#endif
   
   if ( ivMvPredFlag )
@@ -3210,5 +3613,16 @@
 #if H_3D_VSP
       if (pcCULeft->getVSPFlag(uiLeftPartIdx) == 1)
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+      {
+#endif
         vspFlag[iCount] = 1;
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+        xInheritVSPDisInfo(pcCULeft,uiLeftPartIdx,iCount,inheritedVSPDisInfo);
+      }
+#endif
+#if MTK_VSP_FIX_E0172
+        vspDir[iCount] = pcCULeft->getVSPDir( uiLeftPartIdx );
+      }
+#endif
 #endif
       if ( mrgCandIdx == iCount )
@@ -3278,5 +3692,16 @@
 #if H_3D_VSP
       if (pcCUAbove->getVSPFlag(uiAbovePartIdx) == 1)
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+      {
+#endif
         vspFlag[iCount] = 1;
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+        xInheritVSPDisInfo(pcCUAbove,uiAbovePartIdx,iCount,inheritedVSPDisInfo);
+      }
+#endif
+#if MTK_VSP_FIX_E0172
+        vspDir[iCount] = pcCUAbove->getVSPDir( uiAbovePartIdx );
+      }
+#endif
 #endif
       if ( mrgCandIdx == iCount )
@@ -3324,5 +3749,16 @@
 #if H_3D_VSP
     if (pcCUAboveRight->getVSPFlag(uiAboveRightPartIdx) == 1)
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+    {
+#endif
       vspFlag[iCount] = 1;
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+      xInheritVSPDisInfo(pcCUAboveRight,uiAboveRightPartIdx,iCount,inheritedVSPDisInfo);
+    }
+#endif
+#if MTK_VSP_FIX_E0172
+      vspDir[iCount] = pcCUAboveRight->getVSPDir( uiAboveRightPartIdx);
+    }
+#endif
 #endif
     if ( mrgCandIdx == iCount )
@@ -3376,4 +3812,7 @@
       pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
 #endif
+#if QC_INRIA_MTK_MRG_E0126
+      iPosDmv  = iCount;
+#endif
       if ( mrgCandIdx == iCount )
         return;
@@ -3390,5 +3829,9 @@
 
 #if H_3D_VSP
+#if MTK_VSP_FIX_E0172
+  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, vspDir ) )
+#else
   if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag ) )
+#endif
     return;
   // early termination
@@ -3421,5 +3864,16 @@
 #if H_3D_VSP
     if (pcCULeftBottom->getVSPFlag(uiLeftBottomPartIdx) == 1)
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+    {
+#endif
       vspFlag[iCount] = 1;
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+      xInheritVSPDisInfo(pcCULeftBottom,uiLeftBottomPartIdx,iCount,inheritedVSPDisInfo);
+    }
+#endif
+#if MTK_VSP_FIX_E0172
+      vspDir[iCount] = pcCULeftBottom->getVSPDir( uiLeftBottomPartIdx);
+    }
+#endif
 #endif
     if ( mrgCandIdx == iCount )
@@ -3461,5 +3915,16 @@
 #if H_3D_VSP
       if (pcCUAboveLeft->getVSPFlag(uiAboveLeftPartIdx) == 1)
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+      {
+#endif
         vspFlag[iCount] = 1;
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+        xInheritVSPDisInfo(pcCUAboveLeft,uiAboveLeftPartIdx,iCount,inheritedVSPDisInfo);
+      }
+#endif
+#if MTK_VSP_FIX_E0172
+        vspDir[iCount] = pcCUAboveLeft->getVSPDir( uiAboveLeftPartIdx);
+      }
+#endif
 #endif
       if ( mrgCandIdx == iCount )
@@ -3475,4 +3940,18 @@
     return;
   }
+#if QC_INRIA_MTK_MRG_E0126
+  if(  ivMvPredFlag  ) 
+  {
+    if(xAddIvMRGCand( mrgCandIdx,  iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, iPdmDir, acPdmMv, aiPdmRefIdx, iPosDmv, vspFlag))
+    {
+      return;
+    }
+    //early termination
+    if (iCount == getSlice()->getMaxNumMergeCand()) 
+    {
+      return;
+    }
+  }
+#endif
   if ( getSlice()->getEnableTMVPFlag())
   {
@@ -3656,5 +4135,11 @@
   numValidMergeCand = uiArrayAddr;
 }
-
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+inline Void TComDataCU::xInheritVSPDisInfo(TComDataCU* pcCURef, UInt uiAbsPartIdx, Int iCount, InheritedVSPDisInfo*  inheritedVSPDisInfo)
+{
+  inheritedVSPDisInfo[iCount].m_acDvInfo.m_acNBDV   = pcCURef->getDvInfo(uiAbsPartIdx).m_acNBDV;
+  inheritedVSPDisInfo[iCount].m_acDvInfo.m_aVIdxCan = pcCURef->getDvInfo(uiAbsPartIdx).m_aVIdxCan;
+}
+#endif
 /** Check whether the current PU and a spatial neighboring PU are in a same ME region.
  * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
@@ -4888,7 +5373,9 @@
 
     ///*** Derive bottom right neighbour position ***
+#if !SEC_SIMPLIFIED_NBDV_E0142
     Int iLCUIdxRBNb  = -1;    
     Int iPartIdxRBNb = -1;
     xDeriveRightBottomNbIdx(iLCUIdxRBNb, iPartIdxRBNb );
+#endif
 
     ///*** Search temporal candidate pictures for disparity vector ***
@@ -4909,13 +5396,25 @@
       }
 
+#if !SEC_SIMPLIFIED_NBDV_E0142
       // Check BR and Center       
       for(Int curPosition = 0; curPosition < 2; curPosition++) 
       {
+#endif
         Bool bCheck = false; 
+#if !SEC_SIMPLIFIED_NBDV_E0142
         if ( curPosition == 0 && iLCUIdxRBNb >= 0 )
+#if MTK_NBDV_TN_FIX_E0172
+          bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
+#else
           bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
+#endif
 
         if (curPosition == 1 )
+#endif
+#if MTK_NBDV_TN_FIX_E0172
+          bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
+#else
           bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
+#endif
 
         if( bCheck )
@@ -4936,5 +5435,7 @@
           return true;
         }
+#if !SEC_SIMPLIFIED_NBDV_E0142
       } 
+#endif
     }
   } 
@@ -4967,4 +5468,5 @@
   }
 
+#if !SEC_SIMPLIFIED_NBDV_E0142
   //// ******* Get disparity from above right block ******* /////
   pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true);
@@ -5007,4 +5509,5 @@
       return true;
   }
+#endif
 
   //// ******* Search MCP blocks ******* /////
@@ -5021,5 +5524,7 @@
           pDInfo->m_acNBDV = cDispVec;
           pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
+#if !MTK_DVMCP_FIX_E0172
           assert(pDInfo->m_aVIdxCan == 0); //Notes from QC: only works for CTC
+#endif
 #if H_3D_NBDV_REF
           TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
@@ -5040,4 +5545,43 @@
   TComMv defaultDV(0, 0);
   pDInfo->m_acNBDV = defaultDV;
+#if NBDV_DEFAULT_VIEWIDX_BUGFIX
+  Int valid = 0;
+  Int viewIndex = 0;
+  for( UInt uiBId = 0; uiBId < getSlice()->getViewIndex() && valid==0; uiBId++ )
+  {
+    UInt        uiBaseId    = uiBId;
+    TComPic*    pcBasePic   = getSlice()->getIvPic( false, uiBaseId );
+    for( Int iRefListId = 0; ( iRefListId < (getSlice()->isInterB()? 2:1) ) && !getSlice()->isIntra() && valid==0; iRefListId++ )
+    {
+      RefPicList  eRefPicListTest = RefPicList( iRefListId );
+      Int         iNumRefPics = getSlice()->getNumRefIdx( eRefPicListTest ) ;
+      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
+      { 
+        if(pcBasePic->getPOC() == getSlice()->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
+          && pcBasePic->getViewIndex() == getSlice()->getRefPic( eRefPicListTest, iRefIndex )->getViewIndex())
+        {
+          valid=1;
+          viewIndex = uiBaseId;
+          break;
+        }
+      }
+    }
+  }
+  if(valid)
+  {
+    pDInfo->m_aVIdxCan = viewIndex;
+#if H_3D_NBDV_REF
+    TComPic* picDepth = NULL;
+    picDepth = getSlice()->getIvPic( true, viewIndex );
+    assert(picDepth!=NULL);
+
+    if (picDepth && bDepthRefine)
+    {
+      estimateDVFromDM(viewIndex, uiPartIdx, picDepth, uiPartAddr, &defaultDV ); // from base view
+    }
+    pDInfo->m_acDoNBDV = defaultDV;
+#endif
+  }
+#else
   pDInfo->m_aVIdxCan = 0;
 #if H_3D_NBDV_REF
@@ -5052,5 +5596,5 @@
   pDInfo->m_acDoNBDV = defaultDV;
 #endif
-
+#endif
   return false; 
 }
@@ -5061,9 +5605,16 @@
   Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth();
   Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
-
+  
+#if NTT_DoNBDV_VECTOR_CLIP_E0141
+  Int depthStartPosX = Clip3(0,   iPictureWidth - 1,  iBlkX + ((mv->getHor()+2)>>2));
+  Int depthStartPosY = Clip3(0,   iPictureHeight - 1, 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));
+#else
   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));
+#endif
 
   Pel* depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
@@ -5144,6 +5695,10 @@
           assert( uiMvpDvPos < IDV_CANDS );
           paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
-          //Notes from QC: DvMCP is implemented in a way that doesn�t carry the reference view identifier as NBDV. It only works for CTC and needs to be fixed to be aligned with other part of the NBDV design.
+          //Notes from QC: DvMCP is implemented in a way that doesnE½t carry the reference view identifier as NBDV. It only works for CTC and needs to be fixed to be aligned with other part of the NBDV design.
+#if MTK_DVMCP_FIX_E0172
+          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = cMvPred.getIDVVId();
+#else  
           paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = 0; 
+#endif
           paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
           paIDVInfo->m_bFound                        = true; 
@@ -5210,6 +5765,15 @@
   }
 }
-
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth )
+{
+  setSubPartT<DisInfo>( cDvInfo, m_pDvInfo, uiAbsPartIdx, uiDepth, uiPUIdx );
+}
+#endif
+#if MTK_NBDV_TN_FIX_E0172
+Bool TComDataCU::xGetColDisMV( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
+#else
 Bool TComDataCU::xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
+#endif
 {
 
@@ -5245,4 +5809,8 @@
     else 
     {
+#if MTK_NBDV_TN_FIX_E0172
+      if(getPic()->isTempIVRefValid(currCandPic, ilist,  iColRefIdx))
+      {
+#endif
       rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
       rcMv.setIDVFlag(0);
@@ -5250,4 +5818,7 @@
       iStartViewIdx   = iColViewIdx   ;
       return true;    
+#if MTK_NBDV_TN_FIX_E0172
+      }
+#endif
     }
   }
@@ -5284,4 +5855,5 @@
   TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
   
+#if !QC_INRIA_MTK_MRG_E0126
   Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
   Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
@@ -5292,11 +5864,34 @@
 
   TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
-
+#endif
+#if QC_INRIA_MTK_MRG_E0126
+  Bool abPdmAvailable[8] =  {false, false, false, false, false, false, false, false};
+#else
   Bool abPdmAvailable[4] = {false, false, false, false};
+#endif
 #if H_3D_NBDV
+#if QC_INRIA_MTK_MRG_E0126
+  for( Int i = 0; i < 8; i++)
+#else
   for( Int i = 0; i < 4; i++)
+#endif
   {
     pacPdmMv[i].setIDVFlag   (false);
   }
+#endif
+#if QC_INRIA_MTK_MRG_E0126
+  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
+  {
+    Int         iBaseCUAddr;
+    Int         iBaseAbsPartIdx;
+
+    Int offsetW = (iLoopCan == 0) ? 0 : ( ((iWidth/2)*4)  + 4 );
+    Int offsetH = (iLoopCan == 0) ? 0 : ( ((iHeight/2)*4) + 4 );
+    
+    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + offsetW + 2 ) >> 2 ) );
+    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + offsetH + 2 ) >> 2 ) ); 
+    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
+
+    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
 #endif
   if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
@@ -5322,4 +5917,19 @@
               if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
               {
+#if QC_INRIA_MTK_MRG_E0126
+                  abPdmAvailable[ (uiCurrRefListId + (iLoopCan<<2)) ] = true;
+                  TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
+#if H_3D_NBDV 
+                  cMv.setIDVFlag   (true);
+                  cMv.setIDVHor    (cDv.getHor());                  
+                  cMv.setIDVVer    (cDv.getVer());  
+#if MTK_DVMCP_FIX_E0172
+                  cMv.setIDVVId    (iViewIndex); 
+#endif
+#endif
+                  clipMv( cMv );
+                  paiPdmRefIdx  [ (uiCurrRefListId + (iLoopCan<<2)) ] = iPdmRefIdx;
+                  pacPdmMv      [ (uiCurrRefListId + (iLoopCan<<2)) ] = cMv;
+#else
                 abPdmAvailable[ uiCurrRefListId ] = true;
                 TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
@@ -5328,8 +5938,12 @@
                 cMv.setIDVHor    (cDv.getHor());                  
                 cMv.setIDVVer    (cDv.getVer());  
+#if MTK_DVMCP_FIX_E0172
+                cMv.setIDVVId    (iViewIndex); 
+#endif
 #endif
                 clipMv( cMv );
                 paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
                 pacPdmMv      [ uiCurrRefListId ] = cMv;
+#endif
                 stopLoop = true;
                 break;
@@ -5341,5 +5955,15 @@
     }
   }
+#if QC_INRIA_MTK_MRG_E0126
+  }
+#endif
+#if QC_INRIA_MTK_MRG_E0126
+  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
+  {
+    availableMcDc[(iLoopCan << 1)] = ( abPdmAvailable[(iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[1 + (iLoopCan<<2)] ? 2 : 0);
+  }
+#else
   availableMcDc[0] = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
+#endif
   for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
   {
@@ -5348,6 +5972,26 @@
     for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
     {
+#if MTK_DIVMC_FIX_E0172
+      if(( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC()) && (pcSlice->getRefPic( eRefPicListDMV, iPdmRefIdx )->getViewIndex() == pDInfo->m_aVIdxCan))
+#else
       if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
-      {
+#endif
+      {
+#if QC_INRIA_MTK_MRG_E0126
+        for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
+        {
+          Int ioffsetDV = (iLoopCan == 0) ? 0 : 4;
+          abPdmAvailable[ iRefListId + 2 + (iLoopCan<<2) ] = true;
+          paiPdmRefIdx  [ iRefListId + 2 + (iLoopCan<<2) ] = iPdmRefIdx;
+#if H_3D_NBDV_REF
+          TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
+#endif
+          cMv.setHor( cMv.getHor() + ioffsetDV );
+          cMv.setVer( 0 );
+          clipMv( cMv );
+          pacPdmMv      [iRefListId + 2 + (iLoopCan<<2)] = cMv;
+        }
+        break;
+#else
         abPdmAvailable[ iRefListId+2 ] = true;
         paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
@@ -5360,8 +6004,16 @@
         pacPdmMv      [ iRefListId + 2] = cMv;
         break;
-      }
-    }
-  }
+#endif
+      }
+    }
+  }
+#if QC_INRIA_MTK_MRG_E0126
+  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
+  {
+    availableMcDc[1 + (iLoopCan << 1)] = ( abPdmAvailable[2 + (iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[3 + (iLoopCan<<2)] ? 2 : 0 );
+  }
+#else
   availableMcDc[1] = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 );
+#endif
   return false;
 }
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComDataCU.h	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComDataCU.h	(revision 597)
@@ -197,4 +197,7 @@
   Char*         m_piVSPFlag;          ///< array of VSP flags to indicate whehter a block uses VSP or not
                                       ///< 0: non-VSP; 1: VSP
+#if MTK_VSP_FIX_E0172
+  Char*         m_piVSPDir;           ///< 0: LIST0; 1: LIST1
+#endif
 #endif
 #if H_3D_ARP
@@ -246,6 +249,16 @@
   Bool          xAddMVPCandOrder      ( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir );
 #if H_3D_VSP
+#if MTK_VSP_FIX_E0172
+  Bool          xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
+                             Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag, Int* vspDir );
+#else
   Bool          xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
                              Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag );
+#endif
+#endif
+#if QC_INRIA_MTK_MRG_E0126
+  Bool          xAddIvMRGCand( Int mrgCandIdx, Int& iCount, Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int*   iPdmDir, TComMv* acPdmMv, 
+                               Int* aiPdmRefIdx, Int iPosDmv, Int* vspFlag ); 
+  Bool          xFirstDmvAvai( Int& iCount, TComMvField* pcMvFieldNeighbours, Int*  iPdmDir, Int iPosDmv, Int* vspFlag, Int& iFirDispCand );
 #endif
 
@@ -422,5 +435,8 @@
   template <typename T>
   Void          setSubPart            ( T bParameter, T* pbBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx );
-
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+  template<typename T>
+  Void          setSubPartT           ( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx );
+#endif
 #if AMP_MRG
   Void          setMergeAMP( Bool b )      { m_bIsMergeAMP = b; }
@@ -448,4 +464,7 @@
 #if H_3D_NBDV
   Void          setDvInfoSubParts     ( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+  Void          setDvInfoSubParts     ( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth);
+#endif
   DisInfo*      getDvInfo             ()                        { return m_pDvInfo;                 }
   DisInfo       getDvInfo             (UInt uiIdx)              { return m_pDvInfo[uiIdx];          }
@@ -473,5 +492,9 @@
 #endif
   );
+#if MTK_NBDV_TN_FIX_E0172
+  Bool          xGetColDisMV      ( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int & iTargetViewIdx, Int & iStartViewIdx );
+#else
   Bool          xGetColDisMV      ( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int & iTargetViewIdx, Int & iStartViewIdx );
+#endif
   Bool          getDisMvpCandNBDV ( DisInfo* pDInfo
 #if H_3D_NBDV_REF
@@ -632,6 +655,15 @@
 #if H_3D_VSP
                                             , Int* vspFlag
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                                            , InheritedVSPDisInfo*  inheritedVSPDisInfo
+#endif
+#if MTK_VSP_FIX_E0172
+                                            , Int* vspDir
+#endif
 #endif
                                             , Int& numValidMergeCand, Int mrgCandIdx = -1 );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+  inline Void xInheritVSPDisInfo(TComDataCU* pcCURef, UInt uiAbsPartIdx, Int iCount,  InheritedVSPDisInfo*  inheritedVSPDisInfo);
+#endif
 #if H_3D_VSP
   Char*         getVSPFlag        ()                        { return m_piVSPFlag;          }
@@ -639,4 +671,10 @@
   Void          setVSPFlag        ( UInt uiIdx, Int n )     { m_piVSPFlag[uiIdx] = n;      }
   Void          setVSPFlagSubParts( Char iVSPFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
+#if MTK_VSP_FIX_E0172
+  Char*         getVSPDir          ()                        { return m_piVSPDir;                           }
+  Char          getVSPDir          ( UInt uiIdx )            { return m_piVSPDir[uiIdx];                  }
+  Void          setVSPDir          ( UInt uiIdx, Int n )     { m_piVSPDir[uiIdx] = n;  }
+  Void          setVSPDirSubParts  ( Char iVSPDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
+#endif
 #endif
   Void          deriveLeftRightTopIdxGeneral  ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT );
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComMotionInfo.h	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComMotionInfo.h	(revision 597)
@@ -76,4 +76,10 @@
   Bool   m_bFound;                                
 } IDVInfo;
+#endif
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+typedef struct _InheritedVSPDisCand 
+{
+  DisInfo m_acDvInfo;
+} InheritedVSPDisInfo;
 #endif
 // ====================================================================================================================
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComMv.h
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComMv.h	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComMv.h	(revision 597)
@@ -58,4 +58,7 @@
   Short m_iIDVHor;    
   Short m_iIDVVer;   
+#if MTK_DVMCP_FIX_E0172
+  Short m_iIDVVId;  //view index of the IDV
+#endif
 #endif
 public:
@@ -72,4 +75,7 @@
   , m_iIDVHor(0)
   , m_iIDVVer(0)
+#if MTK_DVMCP_FIX_E0172
+  , m_iIDVVId(0) 
+#endif
 #endif
   {
@@ -83,4 +89,7 @@
   , m_iIDVHor(0)
   , m_iIDVVer(0)
+#if MTK_DVMCP_FIX_E0172
+  , m_iIDVVId(0) 
+#endif
 #endif
   {
@@ -97,4 +106,7 @@
  #if H_3D_NBDV
    m_bIDV = false; m_iIDVHor = m_iIDVVer = 0;
+#if MTK_DVMCP_FIX_E0172
+   m_iIDVVId = 0; 
+#endif
 #endif
   }
@@ -103,4 +115,7 @@
   Void   setIDVVer  (Short i)                    {m_iIDVVer = i;}
   Void   setIDVFlag (Bool b )                    {m_bIDV    = b;}
+#if MTK_DVMCP_FIX_E0172
+  Void   setIDVVId  (Short i)                    {m_iIDVVId = i;}
+#endif
 #endif
   // ------------------------------------------------------------------------------------------------------------------
@@ -116,4 +131,7 @@
   Short getIDVVer () const { return m_iIDVVer;       }
   Bool  getIDVFlag() const { return m_bIDV;          }
+#if MTK_DVMCP_FIX_E0172
+  Short getIDVVId () const { return m_iIDVVId;       }
+#endif
 #endif
   // ------------------------------------------------------------------------------------------------------------------
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPic.cpp	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPic.cpp	(revision 597)
@@ -655,3 +655,91 @@
 }
 #endif
+#if MTK_NBDV_TN_FIX_E0172
+Void TComPic::checkTemporalIVRef()
+{
+  TComSlice* currSlice = getSlice(getCurrSliceIdx());
+  const Int numCandPics = this->getNumDdvCandPics();
+  for(Int curCandPic = 0; curCandPic < numCandPics; curCandPic++)
+  {
+    RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
+    Int        curCandPicRefIdx = 0;
+    if( curCandPic == 0 ) 
+    { 
+      eCurRefPicList   = RefPicList(currSlice->isInterB() ? 1-currSlice->getColFromL0Flag() : 0);
+      curCandPicRefIdx = currSlice->getColRefIdx();
+    }
+    else                 
+    {
+      eCurRefPicList   = this->getRapRefList();
+      curCandPicRefIdx = this->getRapRefIdx();
+    }
+    TComPic* pcCandColPic = currSlice->getRefPic( eCurRefPicList, curCandPicRefIdx);
+    TComSlice* pcCandColSlice = pcCandColPic->getSlice(0);// currently only support single slice
+
+    if(!pcCandColSlice->isIntra())
+    {
+      for( Int iColRefDir = 0; iColRefDir < (pcCandColSlice->isInterB() ? 2: 1); iColRefDir ++ )
+      {
+        for( Int iColRefIdx =0; iColRefIdx < pcCandColSlice->getNumRefIdx(( RefPicList )iColRefDir ); iColRefIdx++)
+        {
+          m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = false;
+          Int iColViewIdx    = pcCandColSlice->getViewIndex();
+          Int iColRefViewIdx = pcCandColSlice->getRefPic( ( RefPicList )iColRefDir, iColRefIdx)->getViewIndex();
+          if(iColViewIdx == iColRefViewIdx)
+            continue;
+
+          for(Int iCurrRefDir = 0;(iCurrRefDir < (currSlice->isInterB() ? 2: 1)) && (m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] == false ); iCurrRefDir++)
+          {
+            for( Int iCurrRefIdx =0; iCurrRefIdx < currSlice->getNumRefIdx(( RefPicList )iCurrRefDir ); iCurrRefIdx++)
+            {
+              if( currSlice->getRefPic( ( RefPicList )iCurrRefDir, iCurrRefIdx )->getViewIndex() == iColRefViewIdx )
+              {  
+                m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = true;
+                break;
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
+Bool TComPic::isTempIVRefValid(Int currCandPic, Int iColRefDir, Int iColRefIdx)
+{
+  return m_abTIVRINCurrRL[currCandPic][iColRefDir][iColRefIdx];
+}
+#endif
+#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
+Void TComPic::checkTextureRef(  )
+{
+  TComSlice* pcCurrSlice = getSlice(getCurrSliceIdx());
+  TComPic* pcTextPic = pcCurrSlice->getTexturePic();
+  TComSlice* pcTextSlice = pcTextPic->getSlice(0); // currently only support single slice
+
+  for( Int iTextRefDir = 0; (iTextRefDir < (pcTextSlice->isInterB()? 2:1) ) && !pcTextSlice->isIntra(); iTextRefDir ++ )
+  {
+    for( Int iTextRefIdx =0; iTextRefIdx<pcTextSlice->getNumRefIdx(( RefPicList )iTextRefDir ); iTextRefIdx++)
+    {
+      Int iTextRefPOC    = pcTextSlice->getRefPOC( ( RefPicList )iTextRefDir, iTextRefIdx);
+      Int iTextRefViewId = pcTextSlice->getRefPic( ( RefPicList )iTextRefDir, iTextRefIdx)->getViewIndex();
+      m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = -1;
+      Int iCurrRefDir = iTextRefDir;
+      for( Int iCurrRefIdx =0; ( iCurrRefIdx<pcCurrSlice->getNumRefIdx(( RefPicList )iCurrRefDir ) ) && ( m_aiTexToDepRef[iTextRefDir][iTextRefIdx] < 0 ) ; iCurrRefIdx++)
+      {
+        if( pcCurrSlice->getRefPOC( ( RefPicList )iCurrRefDir, iCurrRefIdx ) == iTextRefPOC && 
+          pcCurrSlice->getRefPic( ( RefPicList )iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId )
+        {  
+          m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;
+        }
+      }
+    }
+
+  }
+}
+
+Int TComPic::isTextRefValid(Int iTextRefDir, Int iTextRefIdx)
+{
+  return m_aiTexToDepRef[iTextRefDir][iTextRefIdx];
+}
+#endif
 //! \}
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPic.h
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPic.h	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPic.h	(revision 597)
@@ -104,4 +104,10 @@
   Int         m_iNumDdvCandPics;
 #endif
+#if MTK_NBDV_TN_FIX_E0172 
+  Bool        m_abTIVRINCurrRL  [2][2][MAX_NUM_REF]; //whether an inter-view reference picture with the same view index of the inter-view reference picture of temporal reference picture of current picture exists in current reference picture lists
+#endif
+#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182  
+  Int         m_aiTexToDepRef  [2][MAX_NUM_REF];
+#endif
 public:
   TComPic();
@@ -215,4 +221,12 @@
   RefPicList    getRapRefList()                        {return m_eRapRefList;       }
 #endif
+#if MTK_NBDV_TN_FIX_E0172
+  Void      checkTemporalIVRef();
+  Bool      isTempIVRefValid(Int currCandPic, Int iTempRefDir, Int iTempRefIdx);
+#endif
+#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
+  Void      checkTextureRef(  );
+  Int       isTextRefValid(Int iTextRefDir, Int iTextRefIdx);
+#endif
   /** transfer ownership of seis to this picture */
   void setSEIs(SEIMessages& seis) { m_SEIs = seis; }
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPrediction.cpp	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPrediction.cpp	(revision 597)
@@ -63,4 +63,7 @@
   if (m_pDepthBlock != NULL)
       free(m_pDepthBlock);
+#if NTT_VSP_COMMON_E0207_E0208
+  m_cYuvDepthOnVsp.destroy();
+#endif
 #endif
 
@@ -119,4 +122,7 @@
     m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
     m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
+#endif
+#if NTT_VSP_COMMON_E0207_E0208
+    m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
 #endif
   }
@@ -697,5 +703,12 @@
 {
   // Get depth reference
+#if MTK_VSP_FIX_E0172 
+  Int vspDir = pcCU->getVSPDir( uiPartAddr );
+  RefPicList privateRefPicList = (vspDir == 0) ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
+  Int privateRefIdx = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
+  Int depthRefViewIdx = pcCU->getSlice()->getRefPic(privateRefPicList, privateRefIdx)->getViewIndex();
+#else
   Int depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
+#endif
   TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
   assert(pRefPicBaseDepth != NULL);
@@ -716,6 +729,25 @@
 
   // Do compensation
+#if MTK_VSP_FIX_ALIGN_WD_E0172 
+  TComMv cDv  = pcCU->getDvInfo(uiPartAddr).m_acNBDV;
+#else
+#if MTK_VSP_FIX_E0172
+  TComMv cDv  = pcCU->getCUMvField( privateRefPicList )->getMv( uiPartAddr );
+#else
   TComMv cDv  = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); // cDv is the disparity vector derived from the neighbors
+#endif
+#endif // end of MTK_VSP_FIX_ALIGN_WD_E0172 
   pcCU->clipMv(cDv);
+
+#if NTT_VSP_COMMON_E0207_E0208
+  // fetch virtual depth map
+#if NTT_VSP_VECTOR_CLIP_E0208
+  pcBaseViewDepthPicYuv->extendPicBorder();
+#endif
+  xGetVirtualDepth( pcCU, pcBaseViewDepthPicYuv, &cDv, uiPartAddr, iWidth, iHeight, &m_cYuvDepthOnVsp );
+  // sub-PU based compensation
+  xPredInterLumaBlkFromDM   ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
+  xPredInterChromaBlkFromDM ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
+#else
   UInt uiAbsPartIdx = pcCU->getZorderIdxInCU();
   Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
@@ -723,4 +755,6 @@
   xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
   xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
+#endif
+
 }
 #endif
@@ -1502,4 +1536,535 @@
 
 #if H_3D_VSP
+
+#if NTT_VSP_COMMON_E0207_E0208
+// not fully support iRatioTxtPerDepth* != 1
+Void TComPrediction::xGetVirtualDepth( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *mv, UInt partAddr, Int width, Int height, TComYuv *yuvDepth, Int ratioTxtPerDepthX, Int ratioTxtPerDepthY )
+{
+  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
+  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
+
+  Int refDepStride = picRefDepth->getStride();
+
+#if NTT_VSP_VECTOR_CLIP_E0208
+
+  Int refDepOffset  = ( (mv->getHor()+2) >> 2 ) + ( (mv->getVer()+2) >> 2 ) * refDepStride;
+  Pel *refDepth     = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
+
+  if( ratioTxtPerDepthX!=1 || ratioTxtPerDepthY!=1 )
+  {
+    Int posX, posY;
+    refDepth    = picRefDepth->getLumaAddr( );
+    cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
+    posX /= ratioTxtPerDepthX; // texture position -> depth postion
+    posY /= ratioTxtPerDepthY;
+    refDepOffset += posX + posY * refDepStride;
+
+    width  /= ratioTxtPerDepthX; // texture size -> depth size
+    height /= ratioTxtPerDepthY;
+  }
+
+  refDepth += refDepOffset;
+
+#else // NTT_VSP_VECTOR_CLIP_E0208
+
+  Int widthDepth = picRefDepth->getWidth();
+  Int heightDepth = picRefDepth->getHeight();
+  Int posX, posY;
+  cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
+  posX /= ratioTxtPerDepthX; // texture position -> depth postion
+  posY /= ratioTxtPerDepthY;
+  
+  posX = Clip3(0, widthDepth-width,   posX + ((mv->getHor()+2)>>2));
+  posY = Clip3(0, heightDepth-height, posY + ((mv->getVer()+2)>>2));
+  
+  Pel *refDepth  = picRefDepth->getLumaAddr() + posX + posY * refDepStride;
+
+#endif // NTT_VSP_VECTOR_CLIP_E0208
+
+  Int depStride = yuvDepth->getStride();
+  Pel *depth = yuvDepth->getLumaAddr();
+
+#if NTT_VSP_ADAPTIVE_SPLIT_E0207
+
+  if( width<8 || height<8 )
+  { // no split
+    Int rightOffset = width - 1;
+    Int depStrideBlock = depStride * nTxtPerDepthY;
+    Pel *refDepthTop = refDepth;
+    Pel *refDepthBot = refDepthTop + (height-1)*refDepStride;
+
+    Pel maxDepth = refDepthTop[0] > refDepthBot[0] ? refDepthTop[0] : refDepthBot[0];
+    if( maxDepth < refDepthTop[rightOffset] ) { maxDepth = refDepthTop[rightOffset]; }
+    if( maxDepth < refDepthBot[rightOffset] ) { maxDepth = refDepthBot[rightOffset]; }
+
+    for( Int sY=0; sY<height; sY+=nTxtPerDepthY )
+    {
+      for( Int sX=0; sX<width; sX+=nTxtPerDepthX )
+      {
+        depth[sX] = maxDepth;
+      }
+      depth += depStrideBlock;
+    }
+  }
+  else
+  { // split to 4x8, or 8x4
+    Int blocksize    = 8;
+    Int subblocksize = 4;
+    Int depStrideBlock = depStride * blocksize;
+    Pel *depthTmp = NULL;
+    Int depStrideTmp = depStride * nTxtPerDepthY;
+    Int offset[4] = { 0, subblocksize-1, subblocksize, blocksize-1 };
+    Pel *refDepthTmp[4] = { NULL, NULL, NULL, NULL };
+    Pel repDepth4x8[2] = {0, 0};
+    Pel repDepth8x4[2] = {0, 0};
+
+    Int refDepStrideBlock    = refDepStride * blocksize;
+    Int refDepStrideSubBlock = refDepStride * subblocksize;
+
+    refDepthTmp[0] = refDepth;
+    refDepthTmp[2] = refDepthTmp[0] + refDepStrideSubBlock;
+    refDepthTmp[1] = refDepthTmp[2] - refDepStride;
+    refDepthTmp[3] = refDepthTmp[1] + refDepStrideSubBlock;
+
+    for( Int y=0; y<height; y+=blocksize )
+    {
+      for( Int x=0; x<width; x+=blocksize )
+      {
+        Bool ULvsBR = false, URvsBL = false;
+
+        ULvsBR = refDepthTmp[0][x+offset[0]] < refDepthTmp[3][x+offset[3]];
+        URvsBL = refDepthTmp[0][x+offset[3]] < refDepthTmp[3][x+offset[0]];
+
+        if( ULvsBR ^ URvsBL )
+        { // 4x8
+          repDepth4x8[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[1]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[1]];
+          if( repDepth4x8[0] < refDepthTmp[3][x+offset[0]] )
+          {
+            repDepth4x8[0] = refDepthTmp[3][x+offset[0]];
+          }
+          if( repDepth4x8[0] < refDepthTmp[3][x+offset[1]] )
+          {
+            repDepth4x8[0] = refDepthTmp[3][x+offset[1]];
+          }
+          repDepth4x8[1] = refDepthTmp[0][x+offset[2]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[2]] : refDepthTmp[0][x+offset[3]];
+          if( repDepth4x8[1] < refDepthTmp[3][x+offset[2]] )
+          {
+            repDepth4x8[1] = refDepthTmp[3][x+offset[2]];
+          }
+          if( repDepth4x8[1] < refDepthTmp[3][x+offset[3]] )
+          {
+            repDepth4x8[1] = refDepthTmp[3][x+offset[3]];
+          }
+
+          depthTmp = &depth[x];
+          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
+          {
+            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
+            {
+              depthTmp[sX] = repDepth4x8[0];
+            }
+            depthTmp += depStrideTmp;
+          }
+          depthTmp = &depth[x+subblocksize];
+          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
+          {
+            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
+            {
+              depthTmp[sX] = repDepth4x8[1];
+            }
+            depthTmp += depStrideTmp;
+          }
+        }
+        else
+        { // 8x4
+          repDepth8x4[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[3]];
+          if( repDepth8x4[0] < refDepthTmp[1][x+offset[0]] )
+          {
+            repDepth8x4[0] = refDepthTmp[1][x+offset[0]];
+          }
+          if( repDepth8x4[0] < refDepthTmp[1][x+offset[3]] )
+          {
+            repDepth8x4[0] = refDepthTmp[1][x+offset[3]];
+          }
+          repDepth8x4[1] = refDepthTmp[2][x+offset[0]] > refDepthTmp[2][x+offset[3]] ? refDepthTmp[2][x+offset[0]] : refDepthTmp[2][x+offset[3]];
+          if( repDepth8x4[1] < refDepthTmp[3][x+offset[0]] )
+          {
+            repDepth8x4[1] = refDepthTmp[3][x+offset[0]];
+          }
+          if( repDepth8x4[1] < refDepthTmp[3][x+offset[3]] )
+          {
+            repDepth8x4[1] = refDepthTmp[3][x+offset[3]];
+          }
+          
+          depthTmp = &depth[x];
+          for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
+          {
+            for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
+            {
+              depthTmp[sX] = repDepth8x4[0];
+            }
+            depthTmp += depStrideTmp;
+          }
+          for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
+          {
+            for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
+            {
+              depthTmp[sX] = repDepth8x4[1];
+            }
+            depthTmp += depStrideTmp;
+          }
+        }
+      }
+      refDepthTmp[0] += refDepStrideBlock;
+      refDepthTmp[1] += refDepStrideBlock;
+      refDepthTmp[2] += refDepStrideBlock;
+      refDepthTmp[3] += refDepStrideBlock;
+      depth       += depStrideBlock;
+    }
+  }
+
+#else // NTT_VSP_ADAPTIVE_SPLIT_E0207
+
+  Int rightOffset = nTxtPerDepthX - 1;
+  Int depStrideBlock = depStride * nTxtPerDepthY;
+  Int refDepStrideBlock = refDepStride * nTxtPerDepthY;
+  Pel *refDepthTop = refDepth;
+  Pel *refDepthBot = refDepthTop + (nTxtPerDepthY-1)*refDepStride;
+
+  for( Int y=0; y<height; y+= nTxtPerDepthY )
+  {
+    for( Int x=0; x<width; x+=nTxtPerDepthX )
+    {
+      Pel maxDepth = refDepthTop[x] > refDepthBot[x] ? refDepthTop[x] : refDepthBot[x]; 
+
+      if( maxDepth < refDepthTop[x+rightOffset] )
+      {
+        maxDepth = refDepthTop[x+rightOffset];
+      }
+      if( maxDepth < refDepthBot[x+rightOffset] )
+      {
+        maxDepth = refDepthBot[x+rightOffset];
+      }
+
+      depth[x] = maxDepth;
+
+    }
+    refDepthTop += refDepStrideBlock;
+    refDepthBot += refDepStrideBlock;
+    depth       += depStrideBlock;
+  }
+
+#endif // NTT_VSP_ADAPTIVE_SPLIT_E0207
+}
+
+Void TComPrediction::xPredInterLumaBlkFromDM( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi )
+{
+  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
+  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
+  
+  Int refStride = picRef->getStride();
+  Int dstStride = yuvDst->getStride();
+  Int depStride = yuvDepth->getStride();
+  Int refStrideBlock = refStride  * nTxtPerDepthY;
+  Int dstStrideBlock = dstStride * nTxtPerDepthY;
+  Int depStrideBlock = depStride * nTxtPerDepthY;
+
+  Pel *ref    = picRef->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
+  Pel *dst    = yuvDst->getLumaAddr(partAddr);
+  Pel *depth  = yuvDepth->getLumaAddr();
+  
+#if !(NTT_VSP_DC_BUGFIX_E0208)
+  Int widthLuma = picRef->getWidth();
+  Int posX, posY;
+  cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
+#endif
+
+#if H_3D_VSP_BLOCKSIZE == 1
+#if H_3D_VSP_CONSTRAINED
+  //get LUT based horizontal reference range
+  Int range = xGetConstrainedSize(width, height);
+
+  // The minimum depth value
+  Int minRelativePos = MAX_INT;
+  Int maxRelativePos = MIN_INT;
+
+  Pel* depthTemp, *depthInitial=depth;
+  for (Int yTxt = 0; yTxt < height; yTxt++)
+  {
+    for (Int xTxt = 0; xTxt < width; xTxt++)
+    {
+      if (depthPosX+xTxt < widthDepth)
+      {
+        depthTemp = depthInitial + xTxt;
+      }
+      else
+      {
+        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
+      }
+
+      Int disparity = shiftLUT[ *depthTemp ]; // << iShiftPrec;
+      Int disparityInt = disparity >> 2;
+
+      if( disparity <= 0)
+      {
+        if (minRelativePos > disparityInt+xTxt)
+        {
+          minRelativePos = disparityInt+xTxt;
+        }
+      }
+      else
+      {
+        if (maxRelativePos < disparityInt+xTxt)
+        {
+          maxRelativePos = disparityInt+xTxt;
+        }
+      }
+    }
+    if (depthPosY+yTxt < heightDepth)
+    {
+      depthInitial = depthInitial + depStride;
+    }
+  }
+
+  Int disparity_tmp = shiftLUT[ *depth ]; // << iShiftPrec;
+  if (disparity_tmp <= 0)
+  {
+    maxRelativePos = minRelativePos + range -1 ;
+  }
+  else
+  {
+    minRelativePos = maxRelativePos - range +1 ;
+  }
+#endif
+#endif // H_3D_VSP_BLOCKSIZE == 1
+
+  TComMv dv(0, 0);
+
+  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
+  {
+    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
+    {
+      Pel repDepth = depth[ xTxt ];
+      assert( repDepth >= 0 && repDepth <= 255 );
+
+      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec ??
+      Int xFrac = disparity & 0x3;
+
+#if NTT_VSP_DC_BUGFIX_E0208
+
+      dv.setHor( disparity );
+      cu->clipMv( dv );
+
+      Int refOffset = xTxt + (dv.getHor() >> 2);
+      
+#if H_3D_VSP_CONSTRAINED
+      if(refOffset<minRelativePos || refOffset>maxRelativePos)
+      {
+        xFrac = 0;
+      }
+      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
+#endif
+
+      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
+      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
+
+#else // NTT_VSP_DC_BUGFIX_E0208
+
+      for( Int j=0; j < nTxtPerDepthX; j++ )
+      {
+        Int refOffset = xTxt+j + (disparity >> 2);
+#if H_3D_VSP_CONSTRAINED
+        if(refOffset<minRelativePos || refOffset>maxRelativePos)
+        {
+          xFrac = 0;
+        }
+        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
+#endif
+        Int absX  = posX + refOffset;
+
+        if (xFrac == 0)
+        {
+          absX = Clip3(0, widthLuma-1, absX);
+        }
+        else
+        {
+          absX = Clip3(4, widthLuma-5, absX);
+        }
+
+        refOffset = absX - posX;
+        assert( ref[refOffset] >= 0 && ref[refOffset] <= 255 );
+        
+        m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !isBi );
+      }
+
+#endif // NTT_VSP_DC_BUGFIX_E0208
+
+    }
+    ref   += refStrideBlock;
+    dst   += dstStrideBlock;
+    depth += depStrideBlock;
+  }
+
+}
+
+Void TComPrediction::xPredInterChromaBlkFromDM  ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi )
+{
+#if (H_3D_VSP_BLOCKSIZE==1)
+  Int nTxtPerDepthX = 1;
+  Int nTxtPerDepthY = 1;
+#else
+  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE >> 1;
+  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE >> 1;
+#endif
+
+  Int refStride = picRef->getCStride();
+  Int dstStride = yuvDst->getCStride();
+  Int depStride = yuvDepth->getStride();
+  Int refStrideBlock = refStride * nTxtPerDepthY;
+  Int dstStrideBlock = dstStride * nTxtPerDepthY;
+  Int depStrideBlock = depStride * (nTxtPerDepthY<<1);
+
+  Pel *refCb  = picRef->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
+  Pel *refCr  = picRef->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
+  Pel *dstCb  = yuvDst->getCbAddr(partAddr);
+  Pel *dstCr  = yuvDst->getCrAddr(partAddr);
+  Pel *depth  = yuvDepth->getLumaAddr();
+
+#if !(NTT_VSP_DC_BUGFIX_E0208)
+  Int widthChroma = picRef->getWidth() >> 1;
+  Int posX, posY;
+  cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
+  posX >>= 1;
+  posY >>= 1;
+#endif
+  
+#if H_3D_VSP_BLOCKSIZE == 1
+#if H_3D_VSP_CONSTRAINED
+  //get LUT based horizontal reference range
+  Int range = xGetConstrainedSize(width, height, false);
+
+  // The minimum depth value
+  Int minRelativePos = MAX_INT;
+  Int maxRelativePos = MIN_INT;
+
+  Int depthTmp;
+  for (Int yTxt=0; yTxt<height; yTxt++)
+  {
+    for (Int xTxt=0; xTxt<width; xTxt++)
+    {
+      depthTmp = m_pDepthBlock[xTxt+yTxt*width];
+      Int disparity = shiftLUT[ depthTmp ]; // << iShiftPrec;
+      Int disparityInt = disparity >> 3;//in chroma resolution
+
+      if (disparityInt < 0)
+      {
+        if (minRelativePos > disparityInt+xTxt)
+        {
+          minRelativePos = disparityInt+xTxt;
+        }
+      }
+      else
+      {
+        if (maxRelativePos < disparityInt+xTxt)
+        {
+          maxRelativePos = disparityInt+xTxt;
+        }
+      }
+    }
+  }
+
+  depthTmp = m_pDepthBlock[0];
+  Int disparity_tmp = shiftLUT[ depthTmp ]; // << iShiftPrec;
+  if ( disparity_tmp < 0 )
+  {
+    maxRelativePos = minRelativePos + range - 1;
+  }
+  else
+  {
+    minRelativePos = maxRelativePos - range + 1;
+  }
+
+#endif // H_3D_VSP_CONSTRAINED
+#endif // H_3D_VSP_BLOCKSIZE == 1
+
+  TComMv dv(0, 0);
+  // luma size -> chroma size
+  height >>= 1;
+  width  >>= 1;
+
+  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
+  {
+    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
+    {
+      Pel repDepth = depth[ xTxt<<1 ];
+      assert( repDepth >= 0 && repDepth <= 255 );
+
+      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec;
+      Int xFrac = disparity & 0x7;
+      
+#if NTT_VSP_DC_BUGFIX_E0208
+
+      dv.setHor( disparity );
+      cu->clipMv( dv );
+
+      Int refOffset = xTxt + (dv.getHor() >> 3);
+
+#if H_3D_VSP_CONSTRAINED
+      if(refOffset<minRelativePos || refOffset>maxRelativePos)
+      {
+        xFrac = 0;
+      }
+      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
+#endif
+
+      assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
+      assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
+
+      m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
+      m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
+
+#else // NTT_VSP_DC_BUGFIX_E0208
+      
+      for( Int j=0; j < nTxtPerDepthX; j++ )
+      {
+        Int refOffset = xTxt+j + (disparity >> 3);
+#if H_3D_VSP_CONSTRAINED
+        if(refOffset<minRelativePos || refOffset>maxRelativePos)
+        {
+          xFrac = 0;
+        }
+        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
+#endif
+        Int absX  = posX + refOffset;
+
+        if (xFrac == 0)
+        {
+          absX = Clip3(0, widthChroma-1, absX);
+        }
+        else
+        {
+          absX = Clip3(4, widthChroma-5, absX);
+        }
+
+        refOffset = absX - posX;
+        assert( refCb[refOffset] >= 0 && refCb[refOffset] <= 255 );
+        assert( refCr[refOffset] >= 0 && refCr[refOffset] <= 255 );
+
+        m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !isBi );
+        m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !isBi );
+      }
+
+#endif // NTT_VSP_DC_BUGFIX_E0208
+    }
+    refCb += refStrideBlock;
+    refCr += refStrideBlock;
+    dstCb += dstStrideBlock;
+    dstCr += dstStrideBlock;
+    depth += depStrideBlock;
+  }
+
+}
+#else // NTT_VSP_COMMON_E0207_E0208
+
 // Input:
 // refPic: Ref picture. Full picture, with padding
@@ -1955,4 +2520,6 @@
 }
 
+#endif // NTT_VSP_COMMON_E0207_E0208
+
 #if H_3D_VSP_CONSTRAINED
 Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPrediction.h	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPrediction.h	(revision 597)
@@ -84,4 +84,7 @@
   Int  xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma = true);
 #endif
+#if NTT_VSP_COMMON_E0207_E0208
+  TComYuv   m_cYuvDepthOnVsp;
+#endif
 #endif
 
@@ -119,6 +122,12 @@
 
 #if H_3D_VSP
+#if NTT_VSP_COMMON_E0207_E0208
+  Void xGetVirtualDepth           ( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *dv, UInt partAddr, Int width, Int height, TComYuv *yuvDepth, Int txtPerDepthX=1, Int txtPerDepthY=1 );
+  Void xPredInterLumaBlkFromDM    ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&pcYuvDst, Bool isBi );
+  Void xPredInterChromaBlkFromDM  ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&pcYuvDst, Bool isBi );
+#else
   Void xPredInterLumaBlkFromDM  ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr, Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi );
   Void xPredInterChromaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr, Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi );
+#endif
 #endif
 
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 597)
@@ -1510,5 +1510,7 @@
     }
 #endif
+#if H_3D_TMVP
     m_ivMvScalingFlag = true; 
+#endif
 #endif
 
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TypeDef.h	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TypeDef.h	(revision 597)
@@ -101,4 +101,21 @@
                                               // MERL_D0166: Reference view selection in NBDV & Bi-VSP
                                               // MERL_C0152: Basic VSP
+
+#define NBDV_DEFAULT_VIEWIDX_BUGFIX       1  // Bug fix for invalid default view index for NBDV
+#define MTK_RVS_BUGFIX_E0172              1  // Bug fix for issues caused by reference view selection, JCT3V-E0172
+#if MTK_RVS_BUGFIX_E0172
+#define MTK_DVMCP_FIX_E0172                  1 // fix the mismatch between software and WD for DV derivation from DVMCP blocks, issue 2 in JCT3V-E0172
+#define MTK_VSP_FIX_ALIGN_WD_E0172           1 // fix the issues related to VSP merge candidate, issue 3, 4 in JCT3V-E0172, using an implementation aligned with WD
+#if !MTK_VSP_FIX_ALIGN_WD_E0172
+#define MTK_VSP_FIX_E0172                    1 // fix the issues related to VSP merge candidate, issue 3, 4 in JCT3V-E0172
+#endif
+#define MTK_DIVMC_FIX_E0172                  1 // fix the issue of derivation of disparity inter-view merge candidate, issue 5 in JCT3V-E0172
+#define MTK_NBDV_TN_FIX_E0172                1 // fix the issue of DV derivation from the temporal neighboring blocks, issue 7 in JCT3V-E0172
+#endif
+#define MTK_TEXTURE_MRGCAND_BUGFIX_E0182  1   // Bugfix for TEXTURE MERGING CANDIDATE     , JCT3V-E0182
+#if H_3D_NBDV_REF
+#define NTT_DoNBDV_VECTOR_CLIP_E0141      1   // disparity vector clipping in DoNBDV, JCT3V-E0141 and JCT3V-E0209
+#define SEC_SIMPLIFIED_NBDV_E0142         1   // Simplified NBDV, JCT3V-E0142 and JCT3V-E0190
+#endif
 #endif
 #define H_3D_VSP                          1   // View synthesis prediction
@@ -135,5 +152,9 @@
                                               // FIX_SDC_ENC_RD_WVSO_D0163
                                               // MTK_SAMPLE_BASED_SDC_D0110
-
+#define H_3D_FIX                             1
+#if H_3D_FIX
+#define H_3D_BVSP_FIX                        1  //DV from NBDV instead of DoNBDV should be used
+#define FIX036                               1  // fix for ticket #36
+#endif
 #endif 
 
@@ -156,4 +177,9 @@
 ////   ****** Neighbouring block-based Disparity Vector  *********
 #if H_3D_NBDV
+#if SEC_SIMPLIFIED_NBDV_E0142
+#define DVFROM_LEFT                       0
+#define DVFROM_ABOVE                      1
+#define IDV_CANDS                         2
+#else
 #define DVFROM_LEFTBELOW                  0
 #define DVFROM_LEFT                       1
@@ -162,4 +188,9 @@
 #define DVFROM_ABOVELEFT                  4
 #define IDV_CANDS                         5
+#endif
+#endif
+////   **** Inter-view motion prediction for merge        *********
+#if H_3D_IV_MERGE
+#define QC_INRIA_MTK_MRG_E0126            1   // additional merge candidates JCT3V-E0126
 #endif
 ///// ***** ADVANCED INTERVIEW RESIDUAL PREDICTION *********
@@ -187,4 +218,12 @@
 #define H_3D_VSP_CONSTRAINED              0
 #endif
+
+#define NTT_VSP_COMMON_E0207_E0208        1 // common part of JCT3V-E0207 and JCT3V-E0208
+#if NTT_VSP_COMMON_E0207_E0208
+#define NTT_VSP_DC_BUGFIX_E0208           1 // bugfix for sub-PU based DC in VSP, JCT3V-E0208
+#define NTT_VSP_VECTOR_CLIP_E0208         1 // disparity vector clipping on fetching depth map in VSP, JCT3V-E0208
+#define NTT_VSP_ADAPTIVE_SPLIT_E0207      1 // adaptive sub-PU partitioning in VSP, JCT3V-E0207
+#endif
+
 #endif
 
@@ -398,5 +437,9 @@
 
 #if H_3D_VSO_DIST_INT
+#if FIX036
+typedef       Int64            Dist;       ///< RDO distortion
+#else
 typedef       Int              Dist;       ///< RDO distortion
+#endif
 typedef       Int64            Dist64; 
 #define       RDO_DIST_MIN     MIN_INT
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibDecoder/TDecCu.cpp	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibDecoder/TDecCu.cpp	(revision 597)
@@ -366,11 +366,27 @@
     Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
     memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+    InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
+    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand, uiMergeIndex );
+#else
+#if MTK_VSP_FIX_E0172
+    Int vspDir[MRG_MAX_NUM_CANDS_MEM];
+    memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag,vspDir, numValidMergeCand, uiMergeIndex );
+    pcCU->setVSPDirSubParts( vspDir[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
+#else
     m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand, uiMergeIndex );
+#endif
+#endif// end of MTK_VSP_FIX_ALIGN_WD_E0172
     pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
 #else
     m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
 #endif
-
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+    if(vspFlag[uiMergeIndex])
+    {
+      pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiAbsPartIdx, 0, uiDepth);
+    }
+#endif
     pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
 
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 597)
@@ -243,6 +243,24 @@
           Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
           memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+          InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
+          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand );
+#else
+#if MTK_VSP_FIX_E0172
+          Int vspDir[MRG_MAX_NUM_CANDS_MEM];
+          memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, vspDir, numValidMergeCand );
+          pcCU->setVSPDirSubParts( vspDir[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
+#else
           pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand );
+#endif
+#endif//end of MTK_VSP_FIX_ALIGN_WD_E0172
           pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+          if(vspFlag[uiMergeIndex])
+          {
+            pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
+          }
+#endif
 #else
           pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
@@ -258,6 +276,24 @@
         Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
         memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+        InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
+        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo,numValidMergeCand, uiMergeIndex );
+#else
+#if MTK_VSP_FIX_E0172
+        Int vspDir[MRG_MAX_NUM_CANDS_MEM];
+        memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, vspDir,numValidMergeCand, uiMergeIndex );
+        pcCU->setVSPDirSubParts( vspDir[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
+#else
         pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand, uiMergeIndex );
+#endif
+#endif//end of MTK_VSP_FIX_ALIGN_WD_E0172
         pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+        if(vspFlag[uiMergeIndex])
+        {
+          pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
+        }
+#endif
 #else
         pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
@@ -291,5 +327,9 @@
       }
     }
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == false))
+#else
     if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
+#endif
     {
       pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibDecoder/TDecGop.cpp	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibDecoder/TDecGop.cpp	(revision 597)
@@ -159,4 +159,16 @@
   }
 #endif
+#if MTK_NBDV_TN_FIX_E0172 
+  if(pcSlice->getViewIndex() && !pcSlice->getIsDepth() && !pcSlice->isIntra()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
+  {
+    rpcPic->checkTemporalIVRef();
+  }
+#endif
+#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
+  if(pcSlice->getIsDepth())
+  {
+    rpcPic->checkTextureRef();
+  }
+#endif
 #if H_3D
   pcSlice->setDepthToDisparityLUTs(); 
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncCu.cpp	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncCu.cpp	(revision 597)
@@ -416,5 +416,13 @@
 
   Bool    bTrySplitDQP  = true;
-
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+  DisInfo DvInfo; 
+  DvInfo.bDV = false;
+  DvInfo.m_acNBDV.setZero();
+  DvInfo.m_aVIdxCan = 0;
+#if H_3D_NBDV_REF
+  DvInfo.m_acDoNBDV.setZero();
+#endif
+#endif
   static  Double  afCost[ MAX_CU_DEPTH ];
   static  Int      aiNum [ MAX_CU_DEPTH ];
@@ -517,4 +525,5 @@
 
 #if H_3D_NBDV
+#if !MTK_VSP_FIX_ALIGN_WD_E0172
       DisInfo DvInfo; 
       DvInfo.bDV = false;
@@ -524,5 +533,5 @@
       DvInfo.m_acDoNBDV.setZero();
 #endif
-
+#endif
       if( rpcTempCU->getSlice()->getSliceType() != I_SLICE )
       {
@@ -571,4 +580,7 @@
 #endif
           xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+          rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
         }
         // SKIP
@@ -578,5 +590,7 @@
         xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
         rpcTempCU->initEstData( uiDepth, iQP );
-
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+        rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
         // fast encoder decision for early skip
         if ( m_pcEncCfg->getUseFastEnc() )
@@ -599,4 +613,7 @@
 #endif
             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
             if(m_pcEncCfg->getUseCbfFastMode())
             {
@@ -679,4 +696,7 @@
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
                 rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
               }
             }
@@ -692,4 +712,7 @@
             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N  );
             rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
             if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
             {
@@ -705,4 +728,7 @@
             xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN  );
             rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
             if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN)
             {
@@ -737,4 +763,7 @@
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
                 rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
                 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
                 {
@@ -750,4 +779,7 @@
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
                 rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
                 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
                 {
@@ -767,4 +799,7 @@
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true );
                 rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
                 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
                 {
@@ -780,4 +815,7 @@
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true );
                 rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
                 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
                 {
@@ -799,4 +837,7 @@
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
                 rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
                 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
                 {
@@ -812,4 +853,7 @@
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
                 rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
               }
             }
@@ -825,4 +869,7 @@
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true );
                 rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
                 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
                 {
@@ -838,4 +885,7 @@
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true );
                 rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
               }
             }
@@ -849,6 +899,12 @@
               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
               rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
               rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
 #if H_3D_QTLPC
             }
@@ -858,6 +914,12 @@
               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
               rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
               rpcTempCU->initEstData( uiDepth, iQP );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+#endif
 #if H_3D_QTLPC
             }
@@ -1615,5 +1677,16 @@
   Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
   memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+  InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
+  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,inheritedVSPDisInfo, numValidMergeCand );
+#else
+#if MTK_VSP_FIX_E0172
+  Int vspDir[MRG_MAX_NUM_CANDS_MEM];
+  memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,vspDir, numValidMergeCand );
+#else
   rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag, numValidMergeCand );
+#endif
+#endif//end of MTK_VSP_FIX_ALIGN_WD_E0172
 #else
   rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
@@ -1683,4 +1756,10 @@
 #if H_3D_VSP
           rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+          rpcTempCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, 0, 0, uhDepth );
+#endif
+#if MTK_VSP_FIX_E0172
+          rpcTempCU->setVSPDirSubParts( vspDir[uiMergeCand], 0, 0, uhDepth );
+#endif
 #endif
           rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 597)
@@ -1078,4 +1078,16 @@
 #endif
 #endif
+#if MTK_NBDV_TN_FIX_E0172 
+      if(pcSlice->getViewIndex() && !pcSlice->getIsDepth() && !pcSlice->isIntra()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
+      {
+        pcPic->checkTemporalIVRef();
+      }
+#endif
+#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
+      if(pcSlice->getIsDepth())
+      {
+        pcPic->checkTextureRef();
+      }
+#endif
     while(nextCUAddr<uiRealEndAddress) // determine slice boundaries
     {
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 597)
@@ -3550,4 +3550,10 @@
 #if H_3D_VSP
                                  , Int* vspFlag
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                                 , InheritedVSPDisInfo*  inheritedVSPDisInfo
+#endif
+#if MTK_VSP_FIX_E0172
+                                 , Int* vspDir
+#endif
 #endif
                                  , Int& numValidMergeCand
@@ -3569,4 +3575,10 @@
 #if H_3D_VSP
                                    , vspFlag
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                                   , inheritedVSPDisInfo
+#endif
+#if MTK_VSP_FIX_E0172
+                                   , vspDir
+#endif
 #endif
                                    , numValidMergeCand
@@ -3580,9 +3592,19 @@
 #if H_3D_VSP
                                  , vspFlag
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                                 , inheritedVSPDisInfo
+#endif
+#if MTK_VSP_FIX_E0172
+                                 , vspDir
+#endif
 #endif
                                  , numValidMergeCand
                                  );
   }
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+  xRestrictBipredMergeCand( pcCU, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours,vspFlag, numValidMergeCand );
+#else
   xRestrictBipredMergeCand( pcCU, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
+#endif
 
   ruiCost = MAX_UINT;
@@ -3600,4 +3622,10 @@
 #if H_3D_VSP
       pcCU->setVSPFlagSubParts( vspFlag[uiMergeCand], uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+      pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
+#endif
+#if MTK_VSP_FIX_E0172
+      pcCU->setVSPDirSubParts( vspDir[uiMergeCand], uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
+#endif
 #endif
 
@@ -3629,5 +3657,9 @@
  * \returns Void
  */
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+Void TEncSearch::xRestrictBipredMergeCand( TComDataCU* pcCU, UInt puIdx, TComMvField* mvFieldNeighbours, UChar* interDirNeighbours, Int* vspFlag, Int numValidMergeCand )
+#else
 Void TEncSearch::xRestrictBipredMergeCand( TComDataCU* pcCU, UInt puIdx, TComMvField* mvFieldNeighbours, UChar* interDirNeighbours, Int numValidMergeCand )
+#endif
 {
   if ( pcCU->isBipredRestriction(puIdx) )
@@ -3635,5 +3667,9 @@
     for( UInt mergeCand = 0; mergeCand < numValidMergeCand; ++mergeCand )
     {
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+      if ( (interDirNeighbours[mergeCand] == 3) && (vspFlag[mergeCand] == false) )
+#else
       if ( interDirNeighbours[mergeCand] == 3 )
+#endif
       {
         interDirNeighbours[mergeCand] = 1;
@@ -3758,4 +3794,7 @@
 #if H_3D_VSP
     pcCU->setVSPFlagSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
+#if MTK_VSP_FIX_E0172
+    pcCU->setVSPDirSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
+#endif
 #endif
     
@@ -4250,4 +4289,16 @@
       Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
       memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+      InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
+      UInt uiAbsPartIdx = 0;
+      Int iWidth = 0;
+      Int iHeight = 0; 
+      pcCU->getPartIndexAndSize( iPartIdx, uiAbsPartIdx, iWidth, iHeight );
+      DisInfo OriginalDvInfo = pcCU->getDvInfo(uiAbsPartIdx);
+#endif
+#if MTK_VSP_FIX_E0172
+      Int vspDir[MRG_MAX_NUM_CANDS_MEM];
+      memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+#endif
 #endif
 
@@ -4255,4 +4306,10 @@
 #if H_3D_VSP
                       , vspFlag
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                      , inheritedVSPDisInfo
+#endif
+#if MTK_VSP_FIX_E0172
+                      , vspDir
+#endif
 #endif
                       , numValidMergeCand
@@ -4265,4 +4322,10 @@
 #if H_3D_VSP
         pcCU->setVSPFlagSubParts( vspFlag[uiMRGIndex], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+        pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMRGIndex].m_acDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#endif
+#if MTK_VSP_FIX_E0172
+        pcCU->setVSPDirSubParts( vspDir[uiMRGIndex], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#endif
 #endif
         pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
@@ -4287,4 +4350,10 @@
 #if H_3D_VSP
         pcCU->setVSPFlagSubParts ( 0,             uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+        pcCU->setDvInfoSubParts(OriginalDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#endif
+#if MTK_VSP_FIX_E0172
+        pcCU->setVSPDirSubParts ( 0,             uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#endif
 #endif
         {
Index: /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncSearch.h	(revision 596)
+++ /branches/HTM-DEV-2.0-dev0/source/Lib/TLibEncoder/TEncSearch.h	(revision 597)
@@ -415,4 +415,10 @@
 #if H_3D_VSP
                                   , Int* vspFlag
+#if MTK_VSP_FIX_ALIGN_WD_E0172
+                                  , InheritedVSPDisInfo*  inheritedVSPDisInfo
+#endif
+#if MTK_VSP_FIX_E0172
+                                  , Int* vspDir
+#endif
 #endif
                                   , Int& numValidMergeCand
@@ -423,4 +429,7 @@
                                     TComMvField*    mvFieldNeighbours, 
                                     UChar*          interDirNeighbours, 
+#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+                                    Int* vspFlag,
+#endif
                                     Int             numValidMergeCand );
 
