Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDataCU.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDataCU.cpp	(revision 280)
@@ -3397,5 +3397,5 @@
 #endif
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
 Int TComDataCU::getResiPredMode(UInt uiPartAddr)
 {
@@ -3753,5 +3753,9 @@
 {
 #if HHI_INTER_VIEW_MOTION_PRED
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  const Int extraMergeCand = ( ( getSlice()->getIsDepth() || getSlice()->getSPS()->getMultiviewMvPredMode() )? 1 : 0 );
+#else
   const Int extraMergeCand = ( getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
+#endif
 #endif
 
@@ -3784,4 +3788,48 @@
   deriveLeftRightTopIdxGeneral( cCurPS, uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
   deriveLeftBottomIdxGeneral( cCurPS, uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
+
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  if( m_pcSlice->getIsDepth())
+  {
+    UInt uiPartIdxCenter;
+    xDeriveCenterIdx( cCurPS, uiPUIdx, uiPartIdxCenter );    
+    TComDataCU *pcTextureCU = m_pcSlice->getTexturePic()->getCU( getAddr() );
+    if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdxCenter ) )
+    {
+      abCandIsInter[iCount] = true;      
+      puhInterDirNeighbours[iCount] = pcTextureCU->getInterDir( uiPartIdxCenter );
+      if( ( puhInterDirNeighbours[iCount] & 1 ) == 1 )
+      {
+        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
+        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,pcMvFieldNeighbours[iCount<<1].getRefIdx());
+      }
+      if ( getSlice()->isInterB() )
+      {
+        if( ( puhInterDirNeighbours[iCount] & 2 ) == 2 )
+        {
+          pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
+          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,pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx());
+        }
+      }
+#if SIMP_MRG_PRUN
+      if ( mrgCandIdx == iCount )
+      {
+        return;
+      }
+#endif
+      iCount ++;
+    }
+  }
+#endif
 
 #if HHI_INTER_VIEW_MOTION_PRED
@@ -3809,4 +3857,8 @@
 #endif
 
+#if MTK_MDIVRP_C0138
+  Bool bDVAvail = true;
+#endif
+
 #if QC_MULTI_DIS_CAN_A0097
   DisInfo cDisInfo;
@@ -3837,8 +3889,15 @@
     cDisInfo.m_acMvCand[0].setVer(0);
     cDisInfo.m_aVIdxCan[0] = 0;
+#if MTK_MDIVRP_C0138
+    bDVAvail = false;
+#endif
   }
 #if QC_MRG_CANS_B0048
   Int iPdmDir[2] = {0, 0};
 #endif
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+  getUnifiedMvPredCan(uiPUIdx, REF_PIC_LIST_0, 0, aiPdmRefIdx, acPdmMv, &cDisInfo, iPdmDir, true);
+  Int iPdmInterDir;
+#else
   Int     iPdmInterDir      = cDisInfo.iN==0? 0:getPdmMergeCandidateDisCan ( uiPUIdx, aiPdmRefIdx, acPdmMv, &cDisInfo  
 #if QC_MRG_CANS_B0048
@@ -3846,6 +3905,13 @@
 #endif
     );
+#endif
 #else
   Int     iPdmInterDir      = getPdmMergeCandidate( uiPUIdx, aiPdmRefIdx, acPdmMv );
+#endif
+#if MTK_MDIVRP_C0138
+  if (m_pcSlice->getSPS()->getMultiviewResPredMode()==1 && iPdmDir[0] && !bNoPdmMerge && cCurPS == SIZE_2Nx2N && bDVAvail)
+  {
+    setResPredAvailSubParts(true, 0, 0, uiDepth);
+  }
 #endif
 
@@ -4645,8 +4711,16 @@
     UInt uiCurLCUIdx = getAddr();
     xDeriveCenterIdx( eCUMode, uiPUIdx, uiPartIdxCenter );
-    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
+    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx 
+#if QC_TMVP_MRG_REFIDX_C0047
+    , 1
+#endif
+    );
     if( bExistMV == false )
     {
-      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx );
+      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx 
+#if QC_TMVP_MRG_REFIDX_C0047
+    , 1
+#endif
+    );
     }
     if( bExistMV )
@@ -4663,8 +4737,16 @@
         iRefIdx = 0;
 #endif
-        bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
+        bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx
+#if QC_TMVP_MRG_REFIDX_C0047
+        , 1
+#endif
+        );
         if( bExistMV == false )
         {
-          bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx );
+          bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx 
+#if QC_TMVP_MRG_REFIDX_C0047
+        , 1
+#endif  
+        );
         }
         if( bExistMV )
@@ -6895,4 +6977,15 @@
         cDisInfo.m_aVIdxCan[0] = 0;
       }
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+      Int paiPdmRefIdx[4] = {-1, -1, -1, -1};
+      Int iPdmDir[4] = {-1, -1, -1, -1};
+#if QC_C0051_FIXED_BY_MTK
+      TComMv cPdmMvPred[4];
+#else
+      TComMv cPdmMvPred[2];
+#endif
+      cPdmMvPred[0].m_bDvMcp = cPdmMvPred[1].m_bDvMcp = false; 
+      if(getUnifiedMvPredCan(uiPartIdx, eRefPicList, iRefIdx, paiPdmRefIdx, cPdmMvPred, &cDisInfo, iPdmDir, false))
+#else
       TComMv  cPdmMvPred;
 #if QC_MULTI_DIS_CAN_A0097
@@ -6901,4 +6994,15 @@
       if( getPdmMvPred( uiPartIdx, eRefPicList, iRefIdx, cPdmMvPred ) )
 #endif
+#endif
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+      {
+        clipMv( cPdmMvPred[0] );
+        pInfo->m_acMvCand[0] = cPdmMvPred[0];
+      }
+      else
+      {
+        pInfo->m_acMvCand[0].set(0,0);
+      }
+#else
       {
         clipMv( cPdmMvPred );
@@ -6909,4 +7013,5 @@
         pInfo->m_acMvCand[0].set(0,0);
       }
+#endif
     }
   }
@@ -7575,5 +7680,10 @@
   Int iNeibPOC = iCurrPOC;
   Int iNeibRefPOC;
-
+#if INTER_VIEW_VECTOR_SCALING_C0116
+  Int iCurrViewId = m_pcSlice->getViewOrderIdx(); // will be changed to view_id
+  Int iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, iRefIdx)->getViewOrderIdx(); // will be changed to view_id
+  Int iNeibViewId = iCurrViewId;
+  Int iNeibRefViewId;
+#endif
 #if QC_IV_AS_LT_B0046
   Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
@@ -7583,7 +7693,14 @@
   {
     iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
+#if INTER_VIEW_VECTOR_SCALING_C0116
+    iNeibRefViewId = pcTmpCU->getSlice()->getRefPic(eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx))->getViewOrderIdx(); // will be changed to view_id
+#endif
 #if QC_IV_AS_LT_B0046
     bIsNeibRefLongTerm = m_pcSlice->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx))->getIsLongTerm() ;
+#if INTER_VIEW_VECTOR_SCALING_C0116
+    if ( (bIsCurrRefLongTerm == bIsNeibRefLongTerm) && ((iNeibRefPOC == iCurrRefPOC) && (iNeibRefViewId == iCurrRefViewId)))
+#else
     if ( (bIsCurrRefLongTerm == bIsNeibRefLongTerm) && (iNeibRefPOC == iCurrRefPOC) )
+#endif
 #else
     if( pcTmpCU->getSlice()->getRefViewId( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) ) != m_pcSlice->getRefViewId( eRefPicList, iRefIdx ) )
@@ -7606,4 +7723,7 @@
   {
     iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
+#if INTER_VIEW_VECTOR_SCALING_C0116
+    iNeibRefViewId = pcTmpCU->getSlice()->getRefPic(eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx))->getViewOrderIdx(); // will be changed to view_id
+#endif
     TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     TComMv rcMv;
@@ -7618,5 +7738,13 @@
     }
 #endif
+#if INTER_VIEW_VECTOR_SCALING_C0116
+    Int iScale = 4096;
+    if((iCurrRefPOC != iNeibRefPOC)  )    // inter & inter
+        iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
+    else if(m_pcSlice->getIVScalingFlag())    // inter-view & inter-view
+        iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iNeibViewId, iNeibRefViewId );
+#else
     Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
+#endif
     if ( iScale == 4096 )
     {
@@ -7640,4 +7768,7 @@
   {
     iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
+#if INTER_VIEW_VECTOR_SCALING_C0116
+    iNeibRefViewId = pcTmpCU->getSlice()->getRefPic(eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx))->getViewOrderIdx(); // will be changed to view_id
+#endif
     TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
     TComMv rcMv;
@@ -7652,5 +7783,13 @@
     }
 #endif
+#if INTER_VIEW_VECTOR_SCALING_C0116
+    Int iScale = 4096;
+    if((iCurrRefPOC != iNeibRefPOC))    // inter & inter
+        iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
+    else if(m_pcSlice->getIVScalingFlag())    // inter-view & inter-view
+        iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iNeibViewId, iNeibRefViewId );
+#else
     Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
+#endif
     if ( iScale == 4096 )
     {
@@ -7782,5 +7921,10 @@
  * \returns Bool
  */
-Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx )
+Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx 
+#if QC_TMVP_MRG_REFIDX_C0047
+  ,
+  Bool bMRG
+#endif
+)
 {
   UInt uiAbsPartAddr = uiPartUnitIdx;
@@ -7788,17 +7932,9 @@
   RefPicList  eColRefPicList;
   Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
-#if SONY_COLPIC_AVAILABILITY
-#if QC_IV_AS_LT_B0046
-  Int iColViewOrderIdx, iCurrViewOrderIdx, iCurrRefViewOrderIdx;
-#else
-  Int iColViewOrderIdx, iColRefViewOrderIdx, iCurrViewOrderIdx, iCurrRefViewOrderIdx;
-#endif
-#endif
   TComMv cColMv;
-
-#if SONY_COLPIC_AVAILABILITY
-  iCurrViewOrderIdx    = m_pcSlice->getViewOrderIdx();
-  iCurrRefViewOrderIdx = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewOrderIdx();
-#endif
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  Int iColViewId, iColRefViewId, iCurrViewId, iCurrRefViewId;
+#endif
+
   // use coldir.
 #if COLLOCATED_REF_IDX
@@ -7815,6 +7951,8 @@
   iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
   iColPOC = pColCU->getSlice()->getPOC();  
-#if SONY_COLPIC_AVAILABILITY
-  iColViewOrderIdx = pColCU->getSlice()->getViewOrderIdx();
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  iCurrViewId = m_pcSlice->getViewOrderIdx(); // will be changed to view_id    
+  iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewOrderIdx(); // will be changed to view_id
+  iColViewId = pColCU->getSlice()->getViewOrderIdx(); // will be changed to view_id
 #endif
 
@@ -7824,5 +7962,5 @@
   }
 
-#if !SONY_COLPIC_AVAILABILITY&!QC_IV_AS_LT_B0046
+#if !INTER_VIEW_VECTOR_SCALING_C0115&!QC_IV_AS_LT_B0046
   if( m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewId() != m_pcSlice->getViewId() )
     return false;
@@ -7851,14 +7989,12 @@
   // Scale the vector.
   iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
-
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  iColRefViewId = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewOrderIdx(); // will be changed to view_id 
+#endif
 #if !QC_IV_AS_LT_B0046
-#if SONY_COLPIC_AVAILABILITY
-  iColRefViewOrderIdx = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewOrderIdx();
-#else
   if( pColCU->getSlice()->getRefViewId( eColRefPicList, iColRefIdx ) != pColCU->getSlice()->getViewId() )
   {
     return false;
   }
-#endif
 #else
   Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
@@ -7866,6 +8002,29 @@
   if(bIsCurrRefLongTerm != bIsColRefLongTerm) 
   {
+#if QC_TMVP_MRG_REFIDX_C0047
+    cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
+    iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
+    if(bMRG )
+    {
+      Int iUpdRefIdx  = m_pcSlice->getNewRefIdx(eRefPicList);
+      if(iUpdRefIdx > 0 )
+      {
+        riRefIdx = iUpdRefIdx;
+        bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
+        iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
+#if INTER_VIEW_VECTOR_SCALING_C0115
+        iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewOrderIdx(); // will be changed to view_id
+#endif
+      }
+      else
+        return false;
+    }else
+    {
+#endif
     assert( ((iColPOC == iColRefPOC)&&(iCurrPOC != iCurrRefPOC))||((iColPOC != iColRefPOC)&&(iCurrPOC == iCurrRefPOC)));
     return false;
+#if QC_TMVP_MRG_REFIDX_C0047
+    }
+#endif
   }
 #endif
@@ -7888,11 +8047,10 @@
       }
     }else
-#if QC_MVHEVC_B0046
-      rcMv = cColMv; //inter-view
-#else
-    {
-#if SONY_COLPIC_AVAILABILITY
-      Int iColRefViewOrderIdx = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewOrderIdx();
-      iScale = xGetDistScaleFactor(iCurrViewOrderIdx, iCurrRefViewOrderIdx, iColViewOrderIdx, iColRefViewOrderIdx);
+#if INTER_VIEW_VECTOR_SCALING_C0115
+    {
+        if((iCurrPOC == iCurrRefPOC) && m_pcSlice->getIVScalingFlag())    // inter-view & inter-view
+            iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iColViewId, iColRefViewId );
+        else
+            iScale = 4096;            // inter & inter
       if ( iScale == 4096 )
       {
@@ -7903,33 +8061,11 @@
         rcMv = cColMv.scaleMv( iScale );
       }
-#else
-      return false;
-#endif
-    }
-#endif
-  }
-#else
-#if SONY_COLPIC_AVAILABILITY
-  iScale = 0;
-  iCurrRefViewOrderIdx = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewOrderIdx();
-  if((iColPOC != iColRefPOC)&&(iCurrPOC != iCurrRefPOC))
-    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
-  else if((iColPOC == iColRefPOC)&&(iCurrPOC == iCurrRefPOC))
-    iScale = xGetDistScaleFactor(iCurrViewOrderIdx, iCurrRefViewOrderIdx, iColViewOrderIdx, iColRefViewOrderIdx);
-  else
-    return false; 
-
-#else
-  iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
-#endif
-  if ( iScale == 4096 )
-  {
-    rcMv = cColMv;
-  }
-  else
-  {
-    rcMv = cColMv.scaleMv( iScale );
-  }
-#endif
+  }
+#else
+    rcMv = cColMv; //inter-view
+#endif
+  }
+#endif
+
   return true;
 }
@@ -8906,4 +9042,15 @@
 }
 #else
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+Bool
+TComDataCU::getUnifiedMvPredCan(UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge )
+{
+  TComDepthMapGenerator* pcDepthMapGenerator = m_pcSlice->getSPS()->getDepthMapGenerator();
+  ROFRS( pcDepthMapGenerator, false );
+  if (pDInfo->iN > 0 && pcDepthMapGenerator->getPdmCandidate(this, uiPartIdx, eRefPicList, iRefIdx, paiPdmRefIdx, pacPdmMv, pDInfo, iPdm, bMerge))
+    return true;
+  return false;
+}
+#else
 Int
 TComDataCU::getPdmMergeCandidateDisCan( UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo 
@@ -8931,5 +9078,5 @@
 }
 #endif
-
+#endif
 
 Bool      
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDataCU.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDataCU.h	(revision 280)
@@ -289,5 +289,10 @@
 #endif
   Void          deriveRightBottomIdx        ( PartSize eCUMode, UInt uiPartIdx, UInt& ruiPartIdxRB );
-  Bool          xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx );
+  Bool          xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx 
+#if QC_TMVP_MRG_REFIDX_C0047
+  ,
+  Bool bMRG = 0
+#endif
+  );
 #if QC_MULTI_DIS_CAN_A0097
   Bool          xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int & iTargetViewIdx, Int & iStartViewIdx );
@@ -560,4 +565,7 @@
   Bool          getPdmMvPred( UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, Bool bMerge = false );
 #else
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+  Bool getUnifiedMvPredCan(UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge );
+#else
   Bool          getPdmMvPredDisCan( UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge = false );
   Int           getPdmMergeCandidateDisCan( UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo 
@@ -566,4 +574,5 @@
 #endif
   );
+#endif
   Void          getDisMvpCand        ( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo );
 #if LGE_DVMCP_A0126
@@ -627,5 +636,5 @@
   Void          getPartIndexAndSize   ( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight );
 #endif
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   Int           getResiPredMode(UInt uiPartAddr);
   Void          getPUResiPredShift (Int *iPUPredResiShift, UInt uiAbsPartIndex);
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 280)
@@ -606,4 +606,202 @@
 
 #if HHI_INTER_VIEW_MOTION_PRED
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+Bool
+TComDepthMapGenerator::getPdmCandidate(TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge )
+{
+  AOF  ( m_bCreated && m_bInit );
+  TComSlice*    pcSlice     = pcCU->getSlice ();
+  TComSPS*      pcSPS       = pcSlice->getSPS();
+  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
+
+  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
+  UInt          uiRefViewId = pcRefPic->getSPS()->getViewId();
+  Bool          bInterview  = ( uiRefViewId < m_uiCurrViewId );
+  Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
+  Bool          bPdmInter   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER );
+  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
+  if(!bMerge)
+  {
+    ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false );
+    ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false );
+    ROTRS(                  bMerge   && !bPdmMerge, false );
+  }
+  else
+    ROTRS( !bPdmMerge, 0 );
+
+#if QC_MRG_CANS_B0048
+  Bool abPdmAvailable[4] = {false, false, false, false};
+#else
+  Bool abPdmAvailable[2] = {false,false};
+#endif
+
+  Int iValid = 0;
+  Int iViewId = 0;
+  for( UInt uiBId = 0; uiBId < m_uiCurrViewId && iValid==0; uiBId++ )
+  {
+#if MTK_C0138_FIXED
+    UInt        uiBaseId    = uiBId;
+#else
+    UInt        uiBaseId    = m_auiBaseIdList[ uiBId ];
+#endif
+    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseId );
+    for( Int iRefListId = 0; iRefListId < 2 && iValid==0; iRefListId++ )
+    {
+      RefPicList  eRefPicListTest = RefPicList( iRefListId );
+      Int         iNumRefPics = pcSlice->getNumRefIdx( eRefPicListTest ) ;
+      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
+      { 
+        if(pcBasePic->getPOC() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
+          && pcBasePic->getViewId() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getViewId())
+        {
+          iValid=1;
+          iViewId = uiBaseId;
+          break;
+        }
+      }
+    }
+  }
+  if (iValid == 0)
+    return false;
+
+  //--- get base CU/PU and check prediction mode ---
+  TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( iViewId );
+  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
+  if(bMerge || !bInterview)
+  {
+#if QC_MULTI_DIS_CAN_A0097
+    Int  iCurrPosX, iCurrPosY;
+    UInt          uiPartAddr;
+    Int           iWidth;
+    Int           iHeight;
+
+    pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
+    pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
+    iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
+    iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
+
+    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acMvCand[0].getHor() + 2 ) >> 2 ) );
+    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acMvCand[0].getVer() + 2 ) >> 2 )); 
+    Int         iBaseCUAddr;
+    Int         iBaseAbsPartIdx;
+    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
+#else
+    Int  iPrdDepth, iCurrPosX, iCurrPosY;
+    Bool bAvailable  = xGetPredDepth( pcCU, uiPartIdx, iPrdDepth, &iCurrPosX, &iCurrPosY );
+    AOF( bAvailable );
+    TComPicYuv* pcBasePdm   = pcBasePic->getPredDepthMap();
+    Int         iDisparity  = xGetDisparityFromVirtDepth( iViewId, iPrdDepth );
+    Int         iShiftX     = m_uiSubSampExpX + 2;
+    Int         iAddX       = ( 1 << iShiftX ) >> 1;
+    Int         iBasePosX   = Clip3( 0, pcBasePdm->getWidth () - 1, iCurrPosX + ( ( iDisparity + iAddX ) >> iShiftX ) );
+    Int         iBasePosY   = Clip3( 0, pcBasePdm->getHeight() - 1, iCurrPosY                               );
+    Int         iBaseCUAddr;
+    Int         iBaseAbsPartIdx;
+    pcBaseRec->getCUAddrAndPartIdx( iBasePosX<< m_uiSubSampExpX , iBasePosY<< m_uiSubSampExpY , iBaseCUAddr, iBaseAbsPartIdx );
+#endif 
+    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
+    if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTER || pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_SKIP )
+    {
+      for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
+      {
+        RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
+        if(!bMerge && eCurrRefPicList != eRefPicList)
+          continue;
+        Bool bLoop_stop = false;
+        for(Int iLoop = 0; iLoop < 2 && !bLoop_stop; ++iLoop)
+        {
+          RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
+          TComMvField cBaseMvField;
+          pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
+          Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
+          if (iBaseRefIdx >= 0)
+          {
+            Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
+            if (iBaseRefPOC != pcSlice->getPOC())    
+            {
+              for (Int iPdmRefIdx = (bMerge?0: iRefIdx); iPdmRefIdx < (bMerge? pcSlice->getNumRefIdx( eCurrRefPicList ): (iRefIdx+1)); iPdmRefIdx++)
+              {
+                if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
+                {
+                  abPdmAvailable[ uiCurrRefListId ] = true;
+                  TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
+#if LGE_DVMCP_A0126
+                  if( bMerge )
+                  {
+                    cMv.m_bDvMcp = true;
+                    cMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor();
+                  }
+#endif
+                  pcCU->clipMv( cMv );
+                  if(bMerge)
+                  {
+                    paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
+                    pacPdmMv      [ uiCurrRefListId ] = cMv;
+                    bLoop_stop = true;
+                    break;
+                  }else
+                  {
+                    pacPdmMv  [0] = cMv;
+                    return true;
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+    if( bMerge )
+      iPdm[0] = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
+  }
+  if(bMerge || bInterview)
+  {
+    for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
+    {
+      RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
+      Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
+      for( Int iPdmRefIdx = (bMerge ? 0: iRefIdx); iPdmRefIdx < (bMerge ? iNumRefPics: (iRefIdx+1) ); iPdmRefIdx++ )
+      {
+        if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
+        {
+#if QC_MRG_CANS_B0048
+          abPdmAvailable[ iRefListId+2 ] = true;
+          paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
+#else
+          abPdmAvailable[ iRefListId ] = true;
+          paiPdmRefIdx  [ iRefListId ] = iPdmRefIdx;
+#endif
+#if QC_MULTI_DIS_CAN_A0097
+          TComMv cMv = pDInfo->m_acMvCand[0]; 
+          cMv.setVer(0);
+#else
+          TComMv cMv(iDisparity, 0);
+#endif
+          pcCU->clipMv( cMv );
+#if QC_MRG_CANS_B0048
+          pacPdmMv      [ iRefListId + 2] = cMv;
+#else
+          pacPdmMv      [ iRefListId ] = cMv;
+#endif
+          if(bMerge)
+            break;
+          else
+          {
+            pacPdmMv [0] = cMv;
+            return true;
+          }
+        }
+      }
+    }
+#if QC_MRG_CANS_B0048
+    iPdm[1] = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 );
+#else
+    iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 ) ;
+   }
+#endif
+  }
+  return false;
+}
+#else
 #if QC_MULTI_DIS_CAN_A0097
 Int
@@ -1021,4 +1219,5 @@
   return false;
 }
+#endif
 #endif
 
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.h	(revision 280)
@@ -152,4 +152,7 @@
 #if HHI_INTER_VIEW_MOTION_PRED
 #if QC_MULTI_DIS_CAN_A0097
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+  Bool getPdmCandidate ( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge );
+#else
   Int   getPdmMergeCandidate ( TComDataCU*   pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo 
 #if QC_MRG_CANS_B0048
@@ -160,4 +163,5 @@
   Bool  getPdmMvPredDisCan    ( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge );
   Bool  getDisCanPdmMvPred    ( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge );
+#endif
 #else
   Int   getPdmMergeCandidate  ( TComDataCU*   pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv );
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPic.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPic.cpp	(revision 280)
@@ -76,6 +76,6 @@
   m_pcUsedPelsMap     = NULL;
 #endif
-#if SONY_COLPIC_AVAILABILITY
-  m_iViewOrderIdx     = 0;
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  m_iViewOrderIdx     = 0;    // will be changed to view_id
 #endif
   m_aaiCodedScale     = 0;
@@ -703,3 +703,4 @@
 }
 
+
 //! \}
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPic.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPic.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPic.h	(revision 280)
@@ -112,6 +112,6 @@
   TComPicYuv*           m_pcUsedPelsMap;
 #endif
-#if SONY_COLPIC_AVAILABILITY
-  Int                   m_iViewOrderIdx;
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  Int                   m_iViewOrderIdx;    // will be changed to view_id
 #endif
   Int**                 m_aaiCodedScale;
@@ -188,7 +188,7 @@
 #endif
 
-#if SONY_COLPIC_AVAILABILITY
-  Void          setViewOrderIdx(Int i)                        { m_iViewOrderIdx = i; }
-  Int           getViewOrderIdx()                             { return m_iViewOrderIdx; }
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  Void          setViewOrderIdx(Int i)                        { m_iViewOrderIdx = i; }        // will be changed to view_id
+  Int           getViewOrderIdx()                             { return m_iViewOrderIdx; }    // will be changed to view_id
 #endif
 
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPrediction.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPrediction.cpp	(revision 280)
@@ -847,5 +847,26 @@
 }
 
-
+#if MTK_MDIVRP_C0138
+Void TComPrediction::residualPrediction(TComDataCU* pcCU, TComYuv* pcYuvPred, TComYuv* pcYuvResPred)
+{
+  Int         iWidth;
+  Int         iHeight;
+  UInt        uiPartAddr;
+
+  pcCU->getPartIndexAndSize( 0, uiPartAddr, iWidth, iHeight );
+
+  Bool bResAvail = false;
+
+  bResAvail = pcCU->getResidualSamples( 0, 
+#if QC_SIMPLIFIEDIVRP_M24938
+    true,
+#endif
+    pcYuvResPred );
+
+  assert (bResAvail);
+
+  pcYuvPred->add(pcYuvResPred, iWidth, iHeight);
+}
+#endif
 
 #if DEPTH_MAP_GENERATION
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPrediction.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComPrediction.h	(revision 280)
@@ -189,4 +189,7 @@
 #endif
 
+#if MTK_MDIVRP_C0138
+  Void residualPrediction         (TComDataCU* pcCU, TComYuv* pcYuvPred, TComYuv* pcYuvResPred);
+#endif
 
   // motion vector prediction
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComResidualGenerator.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComResidualGenerator.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComResidualGenerator.cpp	(revision 280)
@@ -184,4 +184,11 @@
   AOF  ( pcPic );
 
+#if MTK_MDIVRP_C0138
+  if (pcPic->getSPS()->getViewId() != 0)
+  {
+    return;
+  }
+#endif
+
   if( pcPic->getPOC() == 0 )
   {
@@ -300,6 +307,9 @@
 #endif
 {
+#if MTK_C0138_FIXED
+  UInt  uiBaseViewId  = 0;
+#else
   UInt  uiBaseViewId  = m_pcDepthMapGenerator->getBaseViewId( 0 );
-
+#endif
   if( !pcYuv )
   {
@@ -330,8 +340,12 @@
     );
 #endif
+#if MTK_MDIVRP_C0138
+  return true;
+#else
 #if QC_SIMPLIFIEDIVRP_M24938
   return xIsNonZeroByCBF( uiBaseViewId , uiXPosInRefView , uiYPosInRefView , uiBlkWidth , uiBlkHeight );
 #else
   return xIsNonZero( pcYuv, uiBlkWidth, uiBlkHeight );
+#endif
 #endif
 }
@@ -453,5 +467,5 @@
   Pel*    pRes      = pcCUResidual->getLumaAddr();
   UInt    uiLumaTrMode, uiChromaTrMode;
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766  && !MTK_MDIVRP_C0138
   Int     iPUPredResiShift[4];
 #endif
@@ -479,4 +493,5 @@
   m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
 
+#if !MTK_MDIVRP_C0138
   if( pcCU->getResPredFlag( 0 ) )
   {
@@ -495,4 +510,5 @@
 #endif
   }
+#endif
 
   //===== clear inter-view predicted parts =====
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 280)
@@ -113,9 +113,10 @@
 , m_numEntryPointOffsets          ( 0 )
 #endif
-#if SONY_COLPIC_AVAILABILITY
-, m_iViewOrderIdx                 ( 0 )
-#endif
 #if LGE_ILLUCOMP_B0045
 , m_bApplyIC                      ( false )
+#endif
+#if INTER_VIEW_VECTOR_SCALING_C0115
+, m_bIVScalingFlag                (false)
+, m_iViewOrderIdx                 ( 0 )        // will be changed to view_id
 #endif
 {
@@ -198,4 +199,8 @@
 #if TILES_WPP_ENTRY_POINT_SIGNALLING
   m_numEntryPointOffsets = 0;
+#endif
+#if QC_TMVP_MRG_REFIDX_C0047
+  m_aiNewRefIdx[0]                  = -1;
+  m_aiNewRefIdx[1]                  = -1;
 #endif
 }
@@ -419,4 +424,24 @@
     }
   }
+#if QC_TMVP_MRG_REFIDX_C0047
+  Int  iCurrPOC = this->getPOC();
+  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )//just to get one updated ref idx for merge in each L0/L1 direction, if it is not avaialbe, it is still -1 
+  {        
+    if ( this->getNumRefIdx( RefPicList( uiRefListIdx ) ) == 0)
+        continue;
+
+    Bool bZeroIdxInterViewFlag =  ( this->getRefPic(RefPicList(uiRefListIdx), 0)->getPOC() == iCurrPOC ) ? true : false;
+    for(Int i = 1; i < this->getNumRefIdx(RefPicList(uiRefListIdx)); i++ )
+    {
+      if ( (bZeroIdxInterViewFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getPOC() != iCurrPOC ) ||
+           (!bZeroIdxInterViewFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getPOC() == iCurrPOC ) )
+      {
+        this->setNewRefIdx(RefPicList(uiRefListIdx),i);
+        break;
+      }
+    }
+  }
+
+#endif
 }
 
@@ -698,6 +723,7 @@
   m_iPOC                 = pSrc->m_iPOC;
   m_viewId               = pSrc->m_viewId;
-#if SONY_COLPIC_AVAILABILITY
-  m_iViewOrderIdx        = pSrc->m_iViewOrderIdx;
+#if INTER_VIEW_VECTOR_SCALING_C0115    
+  m_iViewOrderIdx        = pSrc->m_iViewOrderIdx;// will be changed to view_id
+  m_bIVScalingFlag       = pSrc->m_bIVScalingFlag;
 #endif
   m_eNalUnitType         = pSrc->m_eNalUnitType;
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 280)
@@ -179,5 +179,7 @@
   UInt        m_uiMaxDecPicBuffering[MAX_TLAYER]; 
   UInt        m_uiMaxLatencyIncrease[MAX_TLAYER];
-  
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  Bool          m_bIVScalingFlag;
+#endif
 public:
   TComVPS();
@@ -213,4 +215,8 @@
   Void    setDependentLayer(UInt v, UInt layer)                     { m_uiDependentLayer[layer] = v;    }
   UInt    getDependentLayer(UInt layer)                             { return m_uiDependentLayer[layer]; }
+#endif
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  Bool getIVScalingFlag( )                                   { return m_bIVScalingFlag; }
+  Void setIVScalingFlag(Bool b)                              { m_bIVScalingFlag = b;    }
 #endif
   Void    setNumReorderPics(UInt v, UInt tLayer)                { m_numReorderPics[tLayer] = v;    }
@@ -1248,4 +1254,7 @@
 
   Bool        m_bCheckLDC;
+#if QC_TMVP_MRG_REFIDX_C0047
+  Int         m_aiNewRefIdx    [2]; 
+#endif
 
   //  Data
@@ -1340,9 +1349,10 @@
   Int        m_aaiCodedOffset[2][MAX_VIEW_NUM];
 
-#if SONY_COLPIC_AVAILABILITY|QC_MVHEVC_B0046
-  Int        m_iViewOrderIdx;
-#endif
 #if LGE_ILLUCOMP_B0045
   Bool        m_bApplyIC;
+#endif
+#if INTER_VIEW_VECTOR_SCALING_C0115|QC_MVHEVC_B0046
+  Bool       m_bIVScalingFlag;
+  Int        m_iViewOrderIdx;    // will be changed to view_id
 #endif
 
@@ -1437,7 +1447,4 @@
   Int       getRefViewId        ( RefPicList e, Int iRefIdx)    { return  m_aiRefViewIdList[e][iRefIdx]; }
   TComPic*  getTexturePic       () const                        { return  m_pcTexturePic; }
-#if SONY_COLPIC_AVAILABILITY
-  Int       getViewOrderIdx     ()                                  { return  m_iViewOrderIdx;              }
-#endif
   Int       getDepth            ()                              { return  m_iDepth;                     }
   UInt      getColDir           ()                              { return  m_uiColDir;                   }
@@ -1489,7 +1496,4 @@
   Void      setRefViewId        ( Int i, RefPicList e, Int iRefIdx ) { m_aiRefViewIdList[e][iRefIdx] = i; }
   Void      setTexturePic       ( TComPic *pcTexturePic )       { m_pcTexturePic = pcTexturePic; }
-#if SONY_COLPIC_AVAILABILITY
-  Void      setViewOrderIdx     ( Int i )                       { m_iViewOrderIdx     = i;      }
-#endif
   Void      setNumRefIdx        ( RefPicList e, Int i )         { m_aiNumRefIdx[e]    = i;      }
   Void      setPic              ( TComPic* p )                  { m_pcPic             = p;      }
@@ -1661,4 +1665,14 @@
   Void      xSetApplyIC           ();
 #endif
+#if QC_TMVP_MRG_REFIDX_C0047
+  Int       getNewRefIdx        ( RefPicList e )                { return  m_aiNewRefIdx[e];     }
+  Void      setNewRefIdx        ( RefPicList e, Int i )         { m_aiNewRefIdx[e]    = i;      }
+#endif
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  Void setIVScalingFlag( Bool val )         { m_bIVScalingFlag = val;     }
+  Bool getIVScalingFlag()                   { return m_bIVScalingFlag;    }
+  Void setViewOrderIdx     ( Int i )        { m_iViewOrderIdx     = i;    }   // will be changed to view_id
+  Int  getViewOrderIdx     ()               { return  m_iViewOrderIdx;    }   // will be changed to view_id
+#endif
 
 #if MERL_VSP_C0152
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComYuv.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComYuv.cpp	(revision 280)
@@ -392,5 +392,5 @@
 }
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766  && !MTK_MDIVRP_C0138
 Void
 TComYuv::add(Int *iPUResiPredShift, PartSize uhPartitionSize,  TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
@@ -408,5 +408,5 @@
 #endif
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
 Void
 TComYuv::getPUXYOffset(PartSize uhPartitionSize, Int iWidth, Int iHeight, Int &iXOffset, Int &iYOffset)
@@ -435,5 +435,5 @@
 #endif
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
 Void 
 TComYuv::addLuma(Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
@@ -449,5 +449,5 @@
   Pel*  pDstSamples = getLumaAddr();
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   Int iXOffset, iYOffset;
 
@@ -502,5 +502,5 @@
 }
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
 Void 
 TComYuv::addChroma(Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
@@ -518,5 +518,5 @@
   Pel*  pDstSamplesCr = getCrAddr();
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   Int iXOffset, iYOffset;
  
@@ -676,5 +676,5 @@
 }
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
 Void TComYuv::subtract(Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
 {
@@ -690,5 +690,5 @@
 #endif
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
 Void TComYuv::subtractLuma(Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
 #else
@@ -706,5 +706,5 @@
   Int  iDstStride  = getStride();
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   Int iXOffset, iYOffset;
 
@@ -814,5 +814,5 @@
 }
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
 Void TComYuv::subtractChroma(Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
 #else
@@ -832,5 +832,5 @@
   Int  iSrc1Stride = pcYuvSrc1->getCStride();
   Int  iDstStride  = getCStride();
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   Int iXOffset, iYOffset;
  
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComYuv.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComYuv.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComYuv.h	(revision 280)
@@ -146,5 +146,5 @@
   Void    addClipPartLuma   ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); //GT
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   //  pcYuvSrc0 - pcYuvSrc1 -> m_apiBuf
   Void    subtract          (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
@@ -166,5 +166,5 @@
   //   Remove High frequency
   Void    removeHighFreq    ( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight );
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   Void    getPUXYOffset     (PartSize uhPartitionSize, Int iWidth, Int iHeight, Int &iXOffset, Int &iYOffset);
   Void    add               (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract = false );
Index: branches/HTM-5.1-dev0/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibCommon/TypeDef.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibCommon/TypeDef.h	(revision 280)
@@ -77,4 +77,5 @@
   #define DISABLE_FCO_FOR_VSO             0 // Optional compile settings to disable VSO with FCO.
 #endif
+#define   QC_TMVP_MRG_REFIDX_C0047        1 //only enabled when QC_TMVP_IDX_MOD_B0046 is enabled.
 
 ///// ***** PATCHES *********
@@ -90,4 +91,6 @@
 ///// ***** INTERVIEW MOTION VECTOR PREDICTION *********
 #define HHI_INTER_VIEW_MOTION_PRED        1   // inter-view motion parameter prediction
+#define QC_AMVP_MRG_UNIFY_IVCAN_C0051     1
+#define QC_C0051_FIXED_BY_MTK             1   // bug fix for C0051 implementation
 #define SHARP_INTERVIEW_DECOUPLE_B0111    1   // JCT3V-B0111 decoupling inter-view candidate
 #define QC_MRG_CANS_B0048                 1   // JCT3V-B0048, B0086, B0069
@@ -105,4 +108,6 @@
 #define HHI_INTER_VIEW_RESIDUAL_PRED      1   // inter-view residual prediction
 #if HHI_INTER_VIEW_RESIDUAL_PRED       
+#define MTK_MDIVRP_C0138                  1   // mode-dependent inter-view residual prediction
+#define MTK_C0138_FIXED                   1   // fix for IBP coding structure in view direction (not CTC)
 #define LG_RESTRICTEDRESPRED_M24766       1   // restricted inter-view residual prediction
 #define QC_SIMPLIFIEDIVRP_M24938          1
@@ -119,5 +124,6 @@
 #define QC_SIMPLE_NBDV_B0047              1   // JCT3V-B0047
 ///// ***** MOTION PARAMETER INHERITANCE  *********
-#define HHI_MPI                           1   // motion parameter inheritance from texture picture for depth map coding
+#define MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137   1   // JCT3V-C0137
+#define HHI_MPI                           0   // motion parameter inheritance from texture picture for depth map coding
 #if HHI_MPI
 #define FIX_MPI_B0065                     1   // JCT3V-B0065, fix the MPI bug when RQT is off
@@ -151,5 +157,6 @@
 ///// ***** OTHERS *********
 #define LG_ZEROINTRADEPTHRESI_A0087       1   // JCT2-A0087
-#define SONY_COLPIC_AVAILABILITY          1
+#define INTER_VIEW_VECTOR_SCALING_C0115   1   // JCT2-C0115 Inter-view vector scaling for TMVP & flag
+#define INTER_VIEW_VECTOR_SCALING_C0116   1   // JCT2-C0116 Inter-view vector scaling for AMVP
 #define HHI_FULL_PEL_DEPTH_MAP_MV_ACC     1   // full-pel mv accuracy for depth maps
 #define VIDYO_VPS_INTEGRATION             1
Index: branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 280)
@@ -1458,4 +1458,7 @@
       }
     }
+#if INTER_VIEW_VECTOR_SCALING_C0115
+    READ_FLAG( uiCode,  "inter_view_vector_scaling_flag" );    pcVPS->setIVScalingFlag( uiCode ? true:false); 
+#endif
   }
   
@@ -1468,5 +1471,5 @@
 #endif
 #endif
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
 Void TDecCavlc::parseSPS(TComSPS* pcSPS, Bool bIsDepth)
 #else
@@ -1892,5 +1895,9 @@
 
 #if LCU_SYNTAX_ALF
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet, bool isDepth)
+#else
 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet)
+#endif
 #else
 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl)
@@ -2495,4 +2502,6 @@
   #elif HHI_MPI
   const int iExtraMergeCandidates = sps->getUseMVI() ? 1 : 0;
+  #elif MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  const int iExtraMergeCandidates = (  (isDepth || sps->getMultiviewMvPredMode()) ) ? 1 : 0;   
   #else
   const int iExtraMergeCandidates = sps->getMultiviewMvPredMode() ? 1 : 0;
Index: branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 280)
@@ -118,5 +118,5 @@
   Void  parseVPS            ( TComVPS* pcVPS );
 #endif
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
   Void  parseSPS            ( TComSPS* pcSPS, Bool bIsDepth );
 #else
@@ -131,5 +131,9 @@
   Void  parseAPS            ( TComAPS* pAPS );
 #if LCU_SYNTAX_ALF
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  Void  parseSliceHeader    ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet, bool isDepth);
+#else
   Void  parseSliceHeader    ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet);
+#endif
 #else
   Void  parseSliceHeader    ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl );
Index: branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecCu.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecCu.cpp	(revision 280)
@@ -424,5 +424,5 @@
     }
 #endif
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
     m_pcEntropyDecoder->decodeResPredFlag( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth], 0 );
 #endif
@@ -476,5 +476,5 @@
 #endif
 
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
   if( !pcCU->isIntra( uiAbsPartIdx ) )
   {
@@ -692,4 +692,11 @@
   m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
 #endif
+#if MTK_MDIVRP_C0138
+  if (pcCU->getMergeFlag(0) && pcCU->getMergeIndex(0)==0 && pcCU->getResPredAvail(0))
+  {
+    m_pcPrediction->residualPrediction(pcCU, m_ppcYuvReco[uiDepth], m_ppcYuvResPred[uiDepth]);
+  }
+#endif
+
 #if HHI_MPI
   if( pcCU->getTextureModeDepth( 0 ) != -1 )
@@ -697,5 +704,5 @@
 #endif
 
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
   if( pcCU->getResPredFlag( 0 ) )
   {
@@ -728,5 +735,9 @@
   {
 #if HHI_INTER_VIEW_RESIDUAL_PRED
+#if MTK_MDIVRP_C0138
+    if (pcCU->getMergeFlag(0) && pcCU->getMergeIndex(0)==0 && pcCU->getResPredAvail(0))
+#else
     if( pcCU->getResPredFlag( 0 ) )
+#endif
     {
       m_ppcYuvReco[uiDepth]->clip( pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
@@ -1079,5 +1090,5 @@
   // reconstruct residual based on mask + DC residuals
   Pel apDCResiValues[2];
-  //Pel apDCRecoValues[2];
+  Pel apDCRecoValues[2];
   for( UInt ui = 0; ui < uiNumSegments; ui++ )
   {
@@ -1086,5 +1097,5 @@
     Pel   pRecoValue  = GetIdx2DepthValue( pPredIdx + pResiIdx );
     
-    //apDCRecoValues[ui]  = pRecoValue;
+    apDCRecoValues[ui]  = pRecoValue;
     apDCResiValues[ui]  = pRecoValue - apDCPredValues[ui];
   }
Index: branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 280)
@@ -100,5 +100,5 @@
 }
 
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
 Void
 TDecEntropy::decodeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU, UInt uiPUIdx )
@@ -341,4 +341,5 @@
       pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue, uiMergeIndex );
 
+#if HHI_MPI
       if(pcCU->getTextureModeDepth( uiSubPartIdx ) == uiDepth)//MPI is used
       {
@@ -352,4 +353,5 @@
       }
       else // MPI not used
+#endif
       {
         Int iVSPIdx = 0;
Index: branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecEntropy.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecEntropy.h	(revision 280)
@@ -74,5 +74,5 @@
   virtual Void  parseVPS                  ( TComVPS* pcVPS )                       = 0;
 #endif
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
   virtual Void  parseSPS                  ( TComSPS* pcSPS, Bool bIsDepth )                       = 0;
 #else
@@ -88,5 +88,9 @@
 
 #if LCU_SYNTAX_ALF
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  virtual Void parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet, bool isDepth)       = 0;
+#else
   virtual Void parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet)       = 0;
+#endif
 #else
   virtual Void parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl )                                = 0;
@@ -179,5 +183,5 @@
 #endif
   
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
   Void    decodeSPS                   ( TComSPS* pcSPS, Bool bIsDepth ) { m_pcEntropyDecoderIf->parseSPS(pcSPS, bIsDepth); }
 #else
@@ -193,5 +197,9 @@
 
 #if LCU_SYNTAX_ALF
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  Void    decodeSliceHeader           ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet, bool isDepth)  { m_pcEntropyDecoderIf->parseSliceHeader(rpcSlice, parameterSetManager, alfCUCtrl, alfParamSet, isDepth);         }
+#else
   Void    decodeSliceHeader           ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet)  { m_pcEntropyDecoderIf->parseSliceHeader(rpcSlice, parameterSetManager, alfCUCtrl, alfParamSet);         }
+#endif
 #else
   Void    decodeSliceHeader           ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl )  { m_pcEntropyDecoderIf->parseSliceHeader(rpcSlice, parameterSetManager, alfCUCtrl);         }
@@ -210,5 +218,5 @@
   Void decodeMergeFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx );
   Void decodeMergeIndex        ( TComDataCU* pcSubCU, UInt uiPartIdx, UInt uiPartAddr, PartSize eCUMode, UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, UInt uiDepth );
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
   Void decodeResPredFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU, UInt uiPUIdx );
 #endif
Index: branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecSbac.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecSbac.h	(revision 280)
@@ -90,5 +90,5 @@
   Void  parseVPS                  ( TComVPS* pcVPS )  {}
 #endif
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
   Void  parseSPS                  ( TComSPS* pcSPS, Bool bIsDepth ) {}
 #else
@@ -104,5 +104,9 @@
 
 #if LCU_SYNTAX_ALF
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  Void  parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet, bool isDepth) {}
+#else
   Void  parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet) {}
+#endif
 #else
   Void  parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl ) {}
Index: branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecTop.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecTop.cpp	(revision 280)
@@ -353,7 +353,4 @@
   m_iMaxRefPicNum = 0;
   m_uiValidPS = 0;
-#if SONY_COLPIC_AVAILABILITY
-  m_iViewOrderIdx = 0;
-#endif
 #if ENC_DEC_TRACE
   if(!g_hTrace) g_hTrace = fopen( "TraceDec.txt", "wb" );
@@ -788,8 +785,4 @@
   }
 
-#if SONY_COLPIC_AVAILABILITY
-  m_apcSlicePilot->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx());
-#endif
-
 #if NAL_REF_FLAG
   m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
@@ -801,5 +794,9 @@
   // ALF CU parameters should be part of the slice header -> needs to be fixed 
 #if LCU_SYNTAX_ALF
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet(),m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId));
+#else
   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet());
+#endif
 #else
   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam() );
@@ -865,8 +862,7 @@
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
 
-#if SONY_COLPIC_AVAILABILITY
-    pcPic->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
-#endif
-
+#if INTER_VIEW_VECTOR_SCALING_C0115
+    pcPic->setViewOrderIdx( m_apcSlicePilot->getVPS()->getViewOrderIdx(nalu.m_layerId) );    // will be changed to view_id
+#endif
     /* transfer any SEI messages that have been received to the picture */
     pcPic->setSEIs(m_SEIs);
@@ -1093,10 +1089,14 @@
 #endif
 
-#if SONY_COLPIC_AVAILABILITY
+#if INTER_VIEW_VECTOR_SCALING_C0115
 #if VIDYO_VPS_INTEGRATION
-    pcSlice->setViewOrderIdx( pcSlice->getVPS()->getViewOrderIdx(nalu.m_layerId) );
+    pcSlice->setViewOrderIdx( pcSlice->getVPS()->getViewOrderIdx(nalu.m_layerId) );        // will be changed to view_id
 #else
     pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
 #endif
+#endif
+
+#if INTER_VIEW_VECTOR_SCALING_C0115
+    pcSlice->setIVScalingFlag( pcSlice->getVPS()->getIVScalingFlag());
 #endif
 
@@ -1269,5 +1269,5 @@
   sps->setRPSList(rps);
 #endif
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
   m_cEntropyDecoder.decodeSPS( sps, m_isDepth );
 #else
Index: branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecTop.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibDecoder/TDecTop.h	(revision 280)
@@ -196,8 +196,4 @@
   SEImessages *m_SEIs; ///< "all" SEI messages.  If not NULL, we own the object.
 
-#if SONY_COLPIC_AVAILABILITY
-  Int                     m_iViewOrderIdx;
-#endif
-
   // functional classes
   TComPrediction          m_cPrediction;
@@ -264,9 +260,4 @@
   Void setIsDepth( Bool isDepth ) { m_isDepth = isDepth; }
 
-#if SONY_COLPIC_AVAILABILITY
-  Void setViewOrderIdx(Int i)     { m_iViewOrderIdx = i ;}
-  Int  getViewOrderIdx()          { return m_iViewOrderIdx ; }
-#endif
-
 #if DEPTH_MAP_GENERATION
   TComDepthMapGenerator*  getDepthMapGenerator  () { return &m_cDepthMapGenerator; }
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 280)
@@ -498,4 +498,7 @@
       }
     }
+#if INTER_VIEW_VECTOR_SCALING_C0115
+      WRITE_FLAG( pcVPS->getIVScalingFlag(),                      "inter_view_vector_scaling_flag" );
+#endif
   }
   
@@ -508,5 +511,5 @@
 #endif
 #endif
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068 
 Void TEncCavlc::codeSPS( TComSPS* pcSPS, Bool bIsDepth )
 #else
@@ -1304,4 +1307,6 @@
   #elif HHI_MPI
   const int iExtraMergeCandidates = pcSlice->getSPS()->getUseMVI() ? 1 : 0;
+  #elif MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  const int iExtraMergeCandidates = ( pcSlice->getIsDepth() || pcSlice->getSPS()->getMultiviewMvPredMode() ) ? 1 : 0;
   #else
   const int iExtraMergeCandidates = pcSlice->getSPS()->getMultiviewMvPredMode() ? 1 : 0;
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCavlc.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCavlc.h	(revision 280)
@@ -118,5 +118,5 @@
 #endif
 
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068 
   Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth );
 #else
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCfg.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCfg.h	(revision 280)
@@ -170,4 +170,7 @@
   Bool      m_bUseIC;
 #endif
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  Bool      m_bUseIVS;
+#endif
 #if SAO_UNIT_INTERLEAVING
   Int       m_maxNumOffsetsPerPic;
@@ -713,4 +716,8 @@
   Void  setUseIC                       ( Bool bVal )   {m_bUseIC = bVal;}
   Bool  getUseIC                       ()              {return m_bUseIC;}
+#endif
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  Void  setUseIVS                       ( Bool bVal )   {m_bUseIVS = bVal;}
+  Bool  getUseIVS                       ()              {return m_bUseIVS;}
 #endif
 #if SAO_UNIT_INTERLEAVING
@@ -869,6 +876,6 @@
   Void      setCodedOffset                  ( Int** p )      { m_aaiCodedOffset         = p; }
 
-#if SONY_COLPIC_AVAILABILITY
-  Int       getViewOrderIdx                 ()      { return  m_iViewOrderIdx; }
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  Int       getViewOrderIdx                 ()      { return  m_iViewOrderIdx; }    // will be changed to view_id
 #endif
 };
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCu.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncCu.cpp	(revision 280)
@@ -636,4 +636,8 @@
       {
 #if HHI_INTER_VIEW_RESIDUAL_PRED
+#if MTK_MDIVRP_C0138
+        Bool  bResPredAvailable   = false;
+        UInt uiResPrdId = 0; 
+#else
         // check availability of residual prediction
         Bool  bResPredAvailable   = false;
@@ -651,4 +655,5 @@
 
         for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ )
+#endif
         {
           Bool bResPredFlag  = ( uiResPrdId > 0 );
@@ -764,4 +769,8 @@
       {
 #if HHI_INTER_VIEW_RESIDUAL_PRED
+#if MTK_MDIVRP_C0138
+        Bool  bResPredAvailable   = false;
+        UInt uiResPrdId = 0; 
+#else
         // check availability of residual prediction
         Bool  bResPredAvailable   = false;
@@ -779,4 +788,5 @@
 
         for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ )
+#endif
         {
           Bool bResPredFlag  = ( uiResPrdId > 0 );
@@ -1789,5 +1799,5 @@
     m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx );
 #endif
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
     m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 );
 #endif
@@ -1820,5 +1830,5 @@
     m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx );
 #endif
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
     if( !pcCU->isIntra( uiAbsPartIdx ) )
     {
@@ -1860,5 +1870,5 @@
   Int numValidMergeCand = 0;
 
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
   Bool  bResPrdAvail  = rpcTempCU->getResPredAvail( 0 );
   Bool  bResPrdFlag   = rpcTempCU->getResPredFlag ( 0 );
@@ -1896,4 +1906,8 @@
   rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
 #endif
+#if MTK_MDIVRP_C0138
+  Bool bResPredAvail = rpcTempCU->getResPredAvail(0);
+#endif
+
 #if FAST_DECISION_FOR_MRG_RD_COST
   Bool bestIsSkip = false;
@@ -1958,6 +1972,10 @@
 
 #if HHI_INTER_VIEW_RESIDUAL_PRED
+#if MTK_MDIVRP_C0138
+          rpcTempCU->setResPredAvailSubParts(bResPredAvail, 0, 0, uhDepth);
+#else
           rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth );
           rpcTempCU->setResPredFlagSubParts ( bResPrdFlag,  0, 0, uhDepth );
+#endif
 #endif
 #if LGE_ILLUCOMP_B0045
@@ -1976,4 +1994,10 @@
 #else
             m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
+#endif
+#if MTK_MDIVRP_C0138
+            if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0))
+            {
+              m_pcPredSearch->residualPrediction(rpcTempCU, m_ppcPredYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth]);
+            }
 #endif
             // save pred adress
@@ -1990,4 +2014,10 @@
 #else
               m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
+#endif
+#if MTK_MDIVRP_C0138
+              if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0))
+              {
+                m_pcPredSearch->residualPrediction(rpcTempCU, m_ppcPredYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth]);
+              }
 #endif
               // save pred adress
@@ -2112,5 +2142,5 @@
   rpcTempCU->setMergeAMP (true);
   #if HHI_INTERVIEW_SKIP
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcResPredTmp[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG);
 #else
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 280)
@@ -133,5 +133,5 @@
 #endif
 
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068 
 Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Bool bIsDepth )
 {
@@ -489,5 +489,5 @@
 }
 
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
 Void
 TEncEntropy::encodeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD )
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncEntropy.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncEntropy.h	(revision 280)
@@ -80,5 +80,5 @@
 #endif
 
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068 
   virtual Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth )                       = 0;
 #else
@@ -246,5 +246,5 @@
 #endif
   // SPS
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068 
   Void encodeSPS               ( TComSPS* pcSPS, Bool bIsDepth );
 #else
@@ -270,5 +270,5 @@
   Void encodeMergeFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx );
   Void encodeMergeIndex   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD = false );
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
   Void encodeResPredFlag  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD = false );
 #endif
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 280)
@@ -247,5 +247,9 @@
       std::vector<TComAPS>& vAPS = m_pcEncTop->getAPS();
 #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getEncTop()->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getIsDepth() );
+#else
     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getEncTop()->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
+#endif
 #else
       m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
@@ -255,4 +259,7 @@
       pcSlice->setViewId( m_pcEncTop->getViewId() );
       pcSlice->setIsDepth( m_pcEncTop->getIsDepth() );
+#if INTER_VIEW_VECTOR_SCALING_C0115
+      pcSlice->setIVScalingFlag( m_pcEncTop->getUseIVS() );
+#endif
 
       m_pcEncTop->getSPS()->setDisInter4x4(m_pcEncTop->getDisInter4x4());
@@ -340,9 +347,9 @@
       pcSlice->setNumRefIdx( REF_PIC_LIST_1, min( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) );
 #else
+
       Bool bNalRAP = ((getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_CRA) || (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDR)) && (pcSlice->getSPS()->getViewId())  ? 1: 0;
       pcSlice->setNumRefIdx( REF_PIC_LIST_0, min( m_pcCfg->getGOPEntry( bNalRAP ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) );
       pcSlice->setNumRefIdx( REF_PIC_LIST_1, min( m_pcCfg->getGOPEntry( bNalRAP ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) );
 #endif
-      
       TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
       refPicListModification->setRefPicListModificationFlagL0( false );
@@ -906,5 +913,5 @@
         pcSlice->getSPS()->setNumSubstreams( pcSlice->getPPS()->getNumSubstreams() );
 #endif
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
         m_pcEntropyCoder->encodeSPS(pcSlice->getSPS(), m_pcEncTop->getIsDepth());
 #else
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 280)
@@ -404,5 +404,5 @@
 #endif
 
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068 
 Void TEncSbac::codeSPS( TComSPS* pcSPS, Bool bIsDepth )
 #else
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSbac.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSbac.h	(revision 280)
@@ -102,5 +102,5 @@
 #endif
   
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068 
   Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth );
 #else
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 280)
@@ -2947,6 +2947,14 @@
 #else
 #if LG_RESTRICTEDRESPRED_M24766
-#if MERL_VSP_C0152
+#if MERL_VSP_C0152 || MTK_MDIVRP_C0138
+#if !MTK_MDIVRP_C0138
 Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, TComYuv* rpcResiPredYuv, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost, Int* iVSPIndexTrue )
+#endif
+#if !MERL_VSP_C0152
+Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost )
+#endif
+#if MERL_VSP_C0152 && MTK_MDIVRP_C0138
+Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost, Int* iVSPIndexTrue  )
+#endif
 #else
 Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, TComYuv* rpcResiPredYuv, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost )
@@ -3007,5 +3015,5 @@
   const int maxNumMergeCand = MRG_MAX_NUM_CANDS_SIGNALED + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
 #endif
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   Int iPUResiPredShift[4];
   Int iLastAddResiShift = -1000;
@@ -3038,5 +3046,5 @@
       }
 #endif
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766  && !MTK_MDIVRP_C0138
       Int iAddResiShift;
       UInt uiPartAddr;
@@ -3088,5 +3096,5 @@
     }
   }
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
   {
@@ -3107,5 +3115,5 @@
  */
 #if AMP_MRG
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
 Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv* rpcResiPredYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes, Bool bUseMRG )
 #else
@@ -3214,6 +3222,5 @@
     for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) uiCostTempL0[iNumRef] = MAX_UINT;
     UInt          uiBitsTempL0[MAX_NUM_REF];
-
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
     Int iPUResiPredShift[4] = {0, 0, 0, 0};
 #endif
@@ -3236,5 +3243,5 @@
     {
 #endif
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
       Bool bLastResiFlag = false;
 #endif
@@ -3247,5 +3254,5 @@
       for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
       {
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
         if( pcCU->getResPredFlag( 0 ))
         {
@@ -3435,5 +3442,5 @@
       }
     }
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
     if( pcCU->getResPredFlag( 0 ) && bLastResiFlag)
     { // subtract residual prediction from original in motion search
@@ -3444,5 +3451,5 @@
     if ( pcCU->getSlice()->isInterB() )
     {
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
       Int iLastAddResiShift = -1000;
 #endif
@@ -3552,5 +3559,5 @@
           uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdxBi[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
 #endif
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
           Int iAddResiShift = -1, iPredFrom = 0;
           Int iBestRefIdx = pcCU->getCUMvField(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0)->getRefIdx(uiPartAddr);
@@ -3641,5 +3648,5 @@
         }
       } // for loop-iter
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
       if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
       {
@@ -3856,5 +3863,5 @@
       if (bTestNormalMC)
       {
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
         Int iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
         iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = \
@@ -3867,5 +3874,5 @@
         xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiMEError, m_pcEncCfg->getUseHADME() );
         uiMECost = uiMEError + m_pcRdCost->getCost( uiMEBits );
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
         if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
         {
@@ -3895,9 +3902,23 @@
 #else
 #if LG_RESTRICTEDRESPRED_M24766
-#if MERL_VSP_C0152
+#if MERL_VSP_C0152 || MTK_MDIVRP_C0138
+
+#if !MTK_MDIVRP_C0138
       xMergeEstimation( pcCU, pcOrgYuv, rpcResiPredYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost,  iVSPIndexTrue );
+#endif
+
+#if !MERL_VSP_C0152
+      xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost );
+#endif
+
+#if MERL_VSP_C0152 && MTK_MDIVRP_C0138
+      xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost,  iVSPIndexTrue );
+#endif
+
 #else
       xMergeEstimation( pcCU, pcOrgYuv, rpcResiPredYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost );
 #endif
+
+
 #else
       xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost );
@@ -4833,9 +4854,9 @@
   UInt      uiWidth      = pcCU->getWidth ( 0 );
   UInt      uiHeight     = pcCU->getHeight( 0 );
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   Int       iPUResiPredShift[4];
 #endif
   //  No residual coding : SKIP mode
-  if ( (ePredMode == MODE_SKIP && bSkipRes) )
+  if ( ePredMode == MODE_SKIP && bSkipRes )
   {
     rpcYuvResi->clear();
@@ -4843,4 +4864,10 @@
     pcYuvPred->copyToPartYuv( rpcYuvRec, 0 );
     
+#if MTK_MDIVRP_C0138
+    if (pcCU->getMergeFlag(0) && pcCU->getMergeIndex(0)==0 && pcCU->getResPredAvail(0))
+    {
+      rpcYuvRec->clip( uiWidth, uiHeight );
+    }
+#else
 #if HHI_INTER_VIEW_RESIDUAL_PRED
     // add residual prediction
@@ -4855,4 +4882,5 @@
       rpcYuvRec->clip( uiWidth, uiHeight );
     }
+#endif
 #endif
 
@@ -4900,5 +4928,5 @@
     m_pcEntropyCoder->encodeICFlag(pcCU, 0, true);
 #endif
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
     m_pcEntropyCoder->encodeResPredFlag( pcCU, 0, 0, true );
 #endif
@@ -4978,5 +5006,5 @@
   else
   {
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
     iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
     rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), pcYuvOrg, pcYuvPred, 0, uiWidth );
@@ -4984,5 +5012,5 @@
   rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );
 #endif
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
     // subtract residual prediction
     if( pcCU->getResPredFlag( 0 ) )
@@ -5206,5 +5234,5 @@
 #endif
   }
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
   // add residual prediction
   if( pcCU->getResPredFlag( 0 ) )
@@ -6283,5 +6311,5 @@
     m_pcEntropyCoder->encodeICFlag(pcCU, 0, true);
 #endif
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
     m_pcEntropyCoder->encodeResPredFlag( pcCU, 0, 0, true );
 #endif
@@ -6306,5 +6334,5 @@
     m_pcEntropyCoder->encodeICFlag(pcCU, 0, true);
 #endif
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
     m_pcEntropyCoder->encodeResPredFlag( pcCU, 0, 0, true );
 #endif
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSearch.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSearch.h	(revision 280)
@@ -196,5 +196,5 @@
   Void predInterSearch          ( TComDataCU* pcCU,
                                   TComYuv*    pcOrgYuv,
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
                                   TComYuv*    rpcResiPredYuv,
 #endif
@@ -500,5 +500,5 @@
   Void xMergeEstimation           ( TComDataCU*     pcCU,
                                     TComYuv*        pcYuvOrg,
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
                                     TComYuv*        rpcResiPredYuv, 
 #endif
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 280)
@@ -163,5 +163,9 @@
  */
 #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS * pVPS, TComSPS* pSPS, TComPPS *pPPS, bool isDepth )
+#else
 Void TEncSlice::initEncSlice( TComPic* pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS * pVPS, TComSPS* pSPS, TComPPS *pPPS )
+#endif
 #else
 Void TEncSlice::initEncSlice( TComPic* pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
@@ -186,6 +190,6 @@
   rpcSlice->setPOC( uiPOCCurr );
   
-#if SONY_COLPIC_AVAILABILITY
-  rpcSlice->setViewOrderIdx(m_pcCfg->getViewOrderIdx());
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  rpcSlice->setViewOrderIdx(m_pcCfg->getViewOrderIdx());    // will be changed to view_id
 #endif 
 #if LGE_ILLUCOMP_B0045
@@ -470,4 +474,6 @@
   #elif HHI_MPI
   const int iExtraMergeCandidates = pSPS->getUseMVI() ? 1 : 0;
+  #elif MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  const int iExtraMergeCandidates = ( isDepth || pSPS->getMultiviewMvPredMode() ) ? 1 : 0;
   #else
   const int iExtraMergeCandidates = pSPS->getMultiviewMvPredMode() ? 1 : 0;
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSlice.h	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncSlice.h	(revision 280)
@@ -120,5 +120,9 @@
   /// preparation of slice encoding (reference marking, QP and lambda)
 #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
+#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+  Void    initEncSlice        ( TComPic*  pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, bool isDepth );
+#else
   Void    initEncSlice        ( TComPic*  pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS );
+#endif
 #else
   Void    initEncSlice        ( TComPic*  pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
Index: branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncTop.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibEncoder/TEncTop.cpp	(revision 280)
@@ -404,6 +404,6 @@
   pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
 
-#if SONY_COLPIC_AVAILABILITY
-  pcPicCurr->setViewOrderIdx(m_iViewOrderIdx);
+#if INTER_VIEW_VECTOR_SCALING_C0115
+  pcPicCurr->setViewOrderIdx(m_iViewOrderIdx);    // will be changed to view_id
 #endif
   pcPicCurr->setScaleOffset( m_aaiCodedScale, m_aaiCodedOffset );
Index: branches/HTM-5.1-dev0/source/Lib/TLibExtractor/TExtrTop.cpp
===================================================================
--- branches/HTM-5.1-dev0/source/Lib/TLibExtractor/TExtrTop.cpp	(revision 279)
+++ branches/HTM-5.1-dev0/source/Lib/TLibExtractor/TExtrTop.cpp	(revision 280)
@@ -81,5 +81,5 @@
      cSPS.setRPSList( &cRPS );
 #endif
-#if HHI_MPI
+#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
 #if VIDYO_VPS_INTEGRATION
      m_cEntropyDecoder.decodeSPS( &cSPS, m_cVPS.getDepthFlag(uiLayerId) );
