Index: /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TComDataCU.cpp	(revision 586)
+++ /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TComDataCU.cpp	(revision 587)
@@ -3085,4 +3085,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
  * \param uiAbsPartIdx
@@ -3136,6 +3233,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};
@@ -3247,5 +3350,9 @@
   }
 
+#if QC_INRIA_MTK_MRG_E0126
+  Int iPdmDir[4] = {0, 0, 0, 0};
+#else
   Int iPdmDir[2] = {0, 0};
+#endif
   
   if ( ivMvPredFlag )
@@ -3517,4 +3624,7 @@
       pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
 #endif
+#if QC_INRIA_MTK_MRG_E0126
+      iPosDmv  = iCount;
+#endif
       if ( mrgCandIdx == iCount )
         return;
@@ -3634,4 +3744,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())
   {
@@ -5513,4 +5637,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 )); 
@@ -5521,11 +5646,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 ))
@@ -5551,4 +5699,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());
@@ -5564,4 +5727,5 @@
                 paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
                 pacPdmMv      [ uiCurrRefListId ] = cMv;
+#endif
                 stopLoop = true;
                 break;
@@ -5573,5 +5737,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++ )
   {
@@ -5586,4 +5760,20 @@
 #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;
@@ -5596,8 +5786,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-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TComDataCU.h	(revision 586)
+++ /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TComDataCU.h	(revision 587)
@@ -257,4 +257,9 @@
 #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
 
   Void          deriveRightBottomIdx        ( UInt uiPartIdx, UInt& ruiPartIdxRB );
Index: /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TComSlice.cpp	(revision 586)
+++ /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TComSlice.cpp	(revision 587)
@@ -1510,5 +1510,7 @@
     }
 #endif
+#if H_3D_TMVP
     m_ivMvScalingFlag = true; 
+#endif
 #endif
 
Index: /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TypeDef.h	(revision 586)
+++ /branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TypeDef.h	(revision 587)
@@ -175,4 +175,8 @@
 #define DVFROM_ABOVELEFT                  4
 #define IDV_CANDS                         5
+#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 *********
