Index: branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComDataCU.cpp	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComDataCU.cpp	(revision 244)
@@ -3272,5 +3272,5 @@
 #endif
 
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
 Int TComDataCU::getResiPredMode(UInt uiPartAddr)
 {
@@ -3676,4 +3676,8 @@
 #endif
 
+#if MTK_MDIVRP_C0138
+  Bool bDVAvail = true;
+#endif
+
 #if QC_MULTI_DIS_CAN_A0097
   DisInfo cDisInfo;
@@ -3702,4 +3706,7 @@
     cDisInfo.m_acMvCand[0].setVer(0);
     cDisInfo.m_aVIdxCan[0] = 0;
+#if MTK_MDIVRP_C0138
+    bDVAvail = false;
+#endif
   }
 #if QC_MRG_CANS_B0048
@@ -3719,4 +3726,11 @@
   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
+
 #if QC_MRG_CANS_B0048
   if( iPdmDir[0] && !bNoPdmMerge && PDM_MERGE_POS == 0 )
Index: branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComDataCU.h	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComDataCU.h	(revision 244)
@@ -607,5 +607,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-dev2-Mediatek/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComPrediction.cpp	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComPrediction.cpp	(revision 244)
@@ -754,5 +754,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-dev2-Mediatek/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComPrediction.h	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComPrediction.h	(revision 244)
@@ -151,4 +151,8 @@
 #endif
   
+#if MTK_MDIVRP_C0138
+  Void residualPrediction         (TComDataCU* pcCU, TComYuv* pcYuvPred, TComYuv* pcYuvResPred);
+#endif
+
   // motion vector prediction
   Void getMvPredAMVP              ( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMvPred );
Index: branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComResidualGenerator.cpp
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComResidualGenerator.cpp	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComResidualGenerator.cpp	(revision 244)
@@ -184,4 +184,11 @@
   AOF  ( pcPic );
 
+#if MTK_MDIVRP_C0138
+  if (pcPic->getSPS()->getViewId() != 0)
+  {
+    return;
+  }
+#endif
+
   if( pcPic->getPOC() == 0 )
   {
@@ -296,8 +303,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
 }
@@ -419,5 +430,5 @@
   Pel*    pRes      = pcCUResidual->getLumaAddr();
   UInt    uiLumaTrMode, uiChromaTrMode;
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766  && !MTK_MDIVRP_C0138
   Int     iPUPredResiShift[4];
 #endif
@@ -445,4 +456,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 ) )
   {
@@ -461,4 +473,5 @@
 #endif
   }
+#endif
 
   //===== clear inter-view predicted parts =====
Index: branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComYuv.cpp	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComYuv.cpp	(revision 244)
@@ -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-dev2-Mediatek/source/Lib/TLibCommon/TComYuv.h
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComYuv.h	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComYuv.h	(revision 244)
@@ -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-dev2-Mediatek/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TypeDef.h	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TypeDef.h	(revision 244)
@@ -99,4 +99,5 @@
 #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 LG_RESTRICTEDRESPRED_M24766       1   // restricted inter-view residual prediction
 #define QC_SIMPLIFIEDIVRP_M24938          1
Index: branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibDecoder/TDecCu.cpp	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibDecoder/TDecCu.cpp	(revision 244)
@@ -400,5 +400,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
@@ -452,5 +452,5 @@
 #endif
 
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
   if( !pcCU->isIntra( uiAbsPartIdx ) )
   {
@@ -660,4 +660,11 @@
   m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
   
+#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 )
@@ -665,5 +672,5 @@
 #endif
 
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
   if( pcCU->getResPredFlag( 0 ) )
   {
@@ -696,5 +703,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 ) );
Index: branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 244)
@@ -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 )
Index: branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibDecoder/TDecEntropy.h	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibDecoder/TDecEntropy.h	(revision 244)
@@ -210,5 +210,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-dev2-Mediatek/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibEncoder/TEncCu.cpp	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibEncoder/TEncCu.cpp	(revision 244)
@@ -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 );
@@ -1891,4 +1901,8 @@
   rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
   rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
+
+#if MTK_MDIVRP_C0138
+  Bool bResPredAvail = rpcTempCU->getResPredAvail(0);
+#endif
 
 #if FAST_DECISION_FOR_MRG_RD_COST
@@ -1938,6 +1952,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
@@ -1953,4 +1971,10 @@
         {
             m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
+#if MTK_MDIVRP_C0138
+            if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0))
+            {
+              m_pcPredSearch->residualPrediction(rpcTempCU, m_ppcPredYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth]);
+            }
+#endif
             // save pred adress
             pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth];
@@ -1963,4 +1987,10 @@
             {
               m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
+#if MTK_MDIVRP_C0138
+              if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0))
+              {
+                m_pcPredSearch->residualPrediction(rpcTempCU, m_ppcPredYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth]);
+              }
+#endif
               // save pred adress
               pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth];
@@ -2083,5 +2113,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-dev2-Mediatek/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 244)
@@ -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-dev2-Mediatek/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibEncoder/TEncEntropy.h	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibEncoder/TEncEntropy.h	(revision 244)
@@ -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-dev2-Mediatek/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 244)
@@ -2942,5 +2942,5 @@
 #endif
 #else
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
 Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, TComYuv* rpcResiPredYuv, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost )
 #else
@@ -2994,5 +2994,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;
@@ -3009,5 +3009,5 @@
       pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
       pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
       Int iAddResiShift;
       UInt uiPartAddr;
@@ -3059,5 +3059,5 @@
     }
   }
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
   if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
   {
@@ -3078,5 +3078,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
@@ -3185,5 +3185,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
@@ -3203,5 +3203,5 @@
     {
 #endif
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
       Bool bLastResiFlag = false;
 #endif
@@ -3213,5 +3213,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 ))
         {
@@ -3393,5 +3393,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
@@ -3402,5 +3402,5 @@
     if ( pcCU->getSlice()->isInterB() )
     {
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
       Int iLastAddResiShift = -1000;
 #endif
@@ -3507,5 +3507,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);
@@ -3592,5 +3592,5 @@
         }
       } // for loop-iter
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
       if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
       {
@@ -3805,5 +3805,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] = \
@@ -3816,5 +3816,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)
         {
@@ -3843,5 +3843,5 @@
 #endif
 #else
-#if LG_RESTRICTEDRESPRED_M24766
+#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
       xMergeEstimation( pcCU, pcOrgYuv, rpcResiPredYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost );
 #else
@@ -4754,5 +4754,5 @@
   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
@@ -4764,4 +4764,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
@@ -4776,4 +4782,5 @@
       rpcYuvRec->clip( uiWidth, uiHeight );
     }
+#endif
 #endif
 
@@ -4821,5 +4828,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
@@ -4899,5 +4906,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 );
@@ -4905,5 +4912,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 ) )
@@ -5127,5 +5134,5 @@
 #endif
   }
-#if HHI_INTER_VIEW_RESIDUAL_PRED
+#if HHI_INTER_VIEW_RESIDUAL_PRED && !MTK_MDIVRP_C0138
   // add residual prediction
   if( pcCU->getResPredFlag( 0 ) )
@@ -6204,5 +6211,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
@@ -6227,5 +6234,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-dev2-Mediatek/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibEncoder/TEncSearch.h	(revision 243)
+++ branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibEncoder/TEncSearch.h	(revision 244)
@@ -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
