Index: trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 21)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 28)
@@ -600,4 +600,11 @@
 #endif
   WRITE_FLAG( pcSPS->getTMVPFlagsPresent()  ? 1 : 0,           "sps_temporal_mvp_enable_flag" );
+#if REF_IDX_MFM
+  if( pcSPS->getLayerId() > 0 )
+  {
+	  assert(pcSPS->getMFMEnabledFlag());
+	  WRITE_FLAG( pcSPS->getMFMEnabledFlag() ? 1 : 0,          "sps_enh_mfm_enable_flag" );
+  }
+#endif
 #if SUPPORT_FOR_VUI
   WRITE_FLAG( pcSPS->getVuiParametersPresentFlag(),             "vui_parameters_present_flag" );
Index: trunk/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 21)
+++ trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 28)
@@ -1351,4 +1351,9 @@
     for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
     {
+#if REF_IDX_ME_ZEROMV
+		Bool bZeroMVILR = rpcTempCU->xCheckZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]);
+		if(bZeroMVILR)
+		{
+#endif
         if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
         {
@@ -1402,4 +1407,7 @@
     }
     }
+#if REF_IDX_ME_ZEROMV 
+	}
+#endif
    }
 
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 21)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 28)
@@ -465,4 +465,9 @@
 #endif 
 
+#if REF_IDX_FRAMEWORK
+    if (pcSlice->getSliceType() == B_SLICE) 
+      pcSlice->setColFromL0Flag(1-uiColDir);
+#endif
+
     //  Set reference list
     pcSlice->setRefPicList ( rcListPic );
@@ -471,5 +476,44 @@
     {
       m_pcEncTop->setILRPic(pcPic);
+
+#if REF_IDX_MFM
+      pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic());
+#endif
       pcSlice->addRefPicList ( m_pcEncTop->getIlpList(), 1);
+
+#if REF_IDX_MFM
+      Bool found         = false;
+      UInt ColFromL0Flag = pcSlice->getColFromL0Flag();
+      UInt ColRefIdx     = pcSlice->getColRefIdx();
+      for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 
+      { 
+        if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getIsILR() ) 
+        { 
+          ColRefIdx = colIdx; 
+          found = true;
+          break; 
+        }
+      }
+
+      if( found == false )
+      {
+        ColFromL0Flag = 1 - ColFromL0Flag;
+        for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 
+        { 
+          if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getIsILR() ) 
+          { 
+            ColRefIdx = colIdx; 
+            found = true; 
+            break; 
+          } 
+        }
+      }
+
+      if(found == true)
+      {
+        pcSlice->setColFromL0Flag(ColFromL0Flag);
+        pcSlice->setColRefIdx(ColRefIdx);
+      }
+#endif
     }
 #endif
@@ -495,5 +539,7 @@
     if (pcSlice->getSliceType() == B_SLICE)
     {
+#if !REF_IDX_FRAMEWORK
       pcSlice->setColFromL0Flag(1-uiColDir);
+#endif
       Bool bLowDelay = true;
       Int  iCurrPOC  = pcSlice->getPOC();
Index: trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 21)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 28)
@@ -3211,4 +3211,9 @@
   for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
   {
+#if REF_IDX_ME_ZEROMV
+	  Bool bZeroMVILR = pcCU->xCheckZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]);
+	  if(bZeroMVILR)
+	  {
+#endif
       UInt uiCostCand = MAX_UINT;
       UInt uiBitsCand = 0;
@@ -3234,4 +3239,7 @@
         uiMergeIndex = uiMergeCand;
       }
+#if REF_IDX_ME_ZEROMV
+	  }
+#endif
     }
 }
@@ -3420,7 +3428,15 @@
         if(pcCU->getSlice()->getMvdL1ZeroFlag() && iRefList==1 && biPDistTemp < bestBiPDist)
         {
+#if REF_IDX_ME_ZEROMV 
+		  Bool bZeroMVILR = pcCU->xCheckZeroMVILRMvdL1Zero(iRefList, iRefIdxTemp, aaiMvpIdx[iRefList][iRefIdxTemp]);
+		  if(bZeroMVILR)
+		  {
+#endif
           bestBiPDist = biPDistTemp;
           bestBiPMvpL1 = aaiMvpIdx[iRefList][iRefIdxTemp];
           bestBiPRefIdxL1 = iRefIdxTemp;
+#if REF_IDX_ME_ZEROMV
+		  }
+#endif
         }
 
@@ -3560,5 +3576,9 @@
     }
     //  Bi-directional prediction
+#if REF_IDX_ME_ZEROMV
+	if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) && !(pcCU->getSlice()->getMvdL1ZeroFlag() && bestBiPDist == MAX_INT) )
+#else
     if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) )
+#endif
     {
       
Index: trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 21)
+++ trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 28)
@@ -85,4 +85,7 @@
   memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
 #endif
+#if REF_IDX_MFM
+  m_bMFMEnabledFlag = false;
+#endif
 }
 
@@ -394,5 +397,5 @@
         m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
 #endif
-#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
         m_cIlpPic[j]->setIsILR(true);
 #endif
@@ -599,4 +602,5 @@
   // mark it should be extended
   rpcPic->getPicYuvRec()->setBorderExtension(false);
+
 }
 
@@ -605,4 +609,7 @@
 #if SVC_EXTENSION
   m_cSPS.setLayerId(m_layerId);
+#endif
+#if REF_IDX_MFM
+  m_cSPS.setMFMEnabledFlag(m_bMFMEnabledFlag);
 #endif
 
Index: trunk/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 21)
+++ trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 28)
@@ -140,4 +140,7 @@
   TComPic*                m_cIlpPic[MAX_NUM_REF];                    ///<  Inter layer Prediction picture =  upsampled picture 
 #endif
+#if REF_IDX_MFM
+  Bool                    m_bMFMEnabledFlag;
+#endif
 protected:
   Void  xGetNewPicBuffer  ( TComPic*& rpcPic );           ///< get picture buffer which will be processed
@@ -228,4 +231,8 @@
   Void setILRPic(TComPic *pcPic);
 #endif
+#if REF_IDX_MFM
+  Void setMFMEnabledFlag       (Bool flag)   {m_bMFMEnabledFlag = flag;}
+  Bool getMFMEnabledFlag()                   {return m_bMFMEnabledFlag;}    
+#endif
 
 };
