Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 625)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 655)
@@ -60,5 +60,4 @@
 #endif
 {
-  ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag));
 #if H_MV
   for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++) m_layerIdToDecIdx[i] = -1; 
@@ -148,5 +147,5 @@
 
   // main decoder loop
-  Bool recon_opened = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
+  Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
 #else
 #if H_3D
@@ -176,8 +175,4 @@
 #endif
     AnnexBStats stats = AnnexBStats();
-#if !H_MV
-    Bool bPreviousPictureDecoded = false;
-#endif
-
     vector<uint8_t> nalUnit;
     InputNALUnit nalu;
@@ -246,18 +241,8 @@
 #endif
         }
-
-        
 #else
       if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
       {
-        if(bPreviousPictureDecoded)
-        {
-          bNewPicture = true;
-          bPreviousPictureDecoded = false;
-        }
-        else
-        {
-          bNewPicture = false;
-        }
+        bNewPicture = false;
       }
       else
@@ -290,7 +275,4 @@
 #endif
         }
-#if !H_MV
-        bPreviousPictureDecoded = true; 
-#endif
       }
     }
@@ -311,9 +293,5 @@
         TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic );
         assert( picLastCoded != NULL );        
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
         picLastCoded->compressMotion(1);
-#else
-        picLastCoded->compressMotion();         
-#endif
       }
     }
@@ -325,5 +303,5 @@
       if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] )
 #else
-      if ( m_pchReconFile && !recon_opened )
+      if ( m_pchReconFile && !openedReconFile  )
 #endif
       {
@@ -338,5 +316,5 @@
 #else
         m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
-        recon_opened = true;
+        openedReconFile  = true;
       }
       if ( bNewPicture && 
@@ -466,86 +444,179 @@
 {
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
-  Int not_displayed = 0;
-
-  while (iterPic != pcListPic->end())
-  {
-    TComPic* pcPic = *(iterPic);
-#if H_MV
-    if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx])
-#else
-    if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay)
-#endif
-    {
-       not_displayed++;
-    }
-    iterPic++;
-  }
-  iterPic   = pcListPic->begin();
+  Int numPicsNotYetDisplayed = 0;
   
   while (iterPic != pcListPic->end())
   {
     TComPic* pcPic = *(iterPic);
-    
-#if H_MV
-    if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx]))
-#else
-    if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
-#endif
-    {
-      // write to file
-       not_displayed--;
+#if H_MV
+    if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx])
+#else
+    if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay)
+#endif
+    {
+      numPicsNotYetDisplayed++;
+    }
+    iterPic++;
+  }
+  iterPic   = pcListPic->begin();
+  if (numPicsNotYetDisplayed>2)
+  {
+    iterPic++;
+  }
+  
+  TComPic* pcPic = *(iterPic);
+  if (numPicsNotYetDisplayed>2 && pcPic->isField()) //Field Decoding
+  {
+    TComList<TComPic*>::iterator endPic   = pcListPic->end();
+    endPic--;
+    iterPic   = pcListPic->begin();
+    while (iterPic != endPic)
+    {
+      TComPic* pcPicTop = *(iterPic);
+      iterPic++;
+      TComPic* pcPicBottom = *(iterPic);
+      
+#if H_MV
+      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
+          && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_pocLastDisplay[decIdx]+1 || m_pocLastDisplay[decIdx]<0)))
+#else
+      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
+          && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay<0)))
+#endif
+      {
+        // write to file
+        numPicsNotYetDisplayed = numPicsNotYetDisplayed-2;
 #if H_MV
       if ( m_pchReconFiles[decIdx] )
 #else
-      if ( m_pchReconFile )
-#endif
-      {
-        const Window &conf = pcPic->getConformanceWindow();
-        const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-#if H_MV
-#if H_MV5
+        if ( m_pchReconFile )
+#endif
+        {
+          const Window &conf = pcPicTop->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
+
+          const Bool isTff = pcPicTop->isTopField();
+#if H_MV
         assert( conf   .getScaledFlag() );
         assert( defDisp.getScaledFlag() );
-#endif
+        m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+#else
+          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+#endif
+                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
+        }
+        
+        // update POC of display order
+#if H_MV
+        m_pocLastDisplay[decIdx] = pcPic->getPOC();
+#else
+        m_iPOCLastDisplay = pcPicBottom->getPOC();
+#endif
+        
+        // erase non-referenced picture in the reference picture list after display
+        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPicTop->setReconMark(false);
+          
+          // mark it should be extended later
+          pcPicTop->getPicYuvRec()->setBorderExtension( false );
+          
+#else
+          pcPicTop->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPicBottom->setReconMark(false);
+          
+          // mark it should be extended later
+          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
+          
+#else
+          pcPicBottom->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        pcPicTop->setOutputMark(false);
+        pcPicBottom->setOutputMark(false);
+      }
+    }
+  }
+  else if (!pcPic->isField()) //Frame Decoding
+  {
+    iterPic = pcListPic->begin();
+    while (iterPic != pcListPic->end())
+    {
+      pcPic = *(iterPic);
+
+#if H_MV
+      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx]))
+#else      
+      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
+#endif
+      {
+        // write to file
+        numPicsNotYetDisplayed--;
+#if H_MV
+      if ( m_pchReconFiles[decIdx] )
+#else
+        if ( m_pchReconFile )
+#endif
+        {
+          const Window &conf = pcPic->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+#if H_MV
+        assert( conf   .getScaledFlag() );
+        assert( defDisp.getScaledFlag() );
         m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
 #else
-        m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
-#endif
-                                       conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-                                       conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-                                       conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-                                       conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
+#endif
+                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+        }
+        
+        // update POC of display order
+#if H_MV
+        m_pocLastDisplay[decIdx] = pcPic->getPOC();
+#else
+        m_iPOCLastDisplay = pcPic->getPOC();
+#endif
+        
+        // erase non-referenced picture in the reference picture list after display
+        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPic->setReconMark(false);
+          
+          // mark it should be extended later
+          pcPic->getPicYuvRec()->setBorderExtension( false );
+          
+#else
+          pcPic->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        pcPic->setOutputMark(false);
       }
       
-      // update POC of display order
-#if H_MV
-      m_pocLastDisplay[decIdx] = pcPic->getPOC();
-#else
-      m_iPOCLastDisplay = pcPic->getPOC();
-#endif
-      
-      // erase non-referenced picture in the reference picture list after display
-      if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
-      {
-#if !DYN_REF_FREE
-        pcPic->setReconMark(false);
-        
-        // mark it should be extended later
-        pcPic->getPicYuvRec()->setBorderExtension( false );
-        
-#else
-        pcPic->destroy();
-        pcListPic->erase( iterPic );
-        iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
-        continue;
-#endif
-      }
-      pcPic->setOutputMark(false);
-    }
-    
-    iterPic++;
-  }
-}
-
+      iterPic++;
+    }
+  }
+}
 /** \param pcListPic list of pictures to be written to file
     \todo            DYN_REF_FREE should be revised
@@ -560,75 +631,170 @@
   {
     return;
-  } 
+  }
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
-
+  
   iterPic   = pcListPic->begin();
+  TComPic* pcPic = *(iterPic);
   
-  while (iterPic != pcListPic->end())
-  {
-    TComPic* pcPic = *(iterPic);
-
-    if ( pcPic->getOutputMark() )
-    {
-      // write to file
+  if (pcPic->isField()) //Field Decoding
+  {
+    TComList<TComPic*>::iterator endPic   = pcListPic->end();
+    endPic--;
+    TComPic *pcPicTop, *pcPicBottom = NULL;
+    while (iterPic != endPic)
+    {
+      pcPicTop = *(iterPic);
+      iterPic++;
+      pcPicBottom = *(iterPic);
+      
+      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) )
+      {
+        // write to file
 #if H_MV
       if ( m_pchReconFiles[decIdx] )
 #else
-      if ( m_pchReconFile )
-#endif
-      {
-        const Window &conf = pcPic->getConformanceWindow();
-        const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-#if H_MV
-#if H_MV5
+        if ( m_pchReconFile )
+#endif
+        {
+          const Window &conf = pcPicTop->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
+          const Bool isTff = pcPicTop->isTopField();
+#if H_MV
         assert( conf   .getScaledFlag() );
         assert( defDisp.getScaledFlag() );
-#endif
+        m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+#else
+          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+#endif
+                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
+        }
+        
+        // update POC of display order
+#if H_MV
+      m_pocLastDisplay[decIdx] = pcPic->getPOC();
+#else
+      m_iPOCLastDisplay = pcPicBottom->getPOC();
+#endif        
+        // erase non-referenced picture in the reference picture list after display
+        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPicTop->setReconMark(false);
+          
+          // mark it should be extended later
+          pcPicTop->getPicYuvRec()->setBorderExtension( false );
+          
+#else
+          pcPicTop->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPicBottom->setReconMark(false);
+          
+          // mark it should be extended later
+          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
+          
+#else
+          pcPicBottom->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        pcPicTop->setOutputMark(false);
+        pcPicBottom->setOutputMark(false);
+        
+#if !DYN_REF_FREE
+        if(pcPicTop)
+        {
+          pcPicTop->destroy();
+          delete pcPicTop;
+          pcPicTop = NULL;
+        }
+#endif
+      }
+    }
+    if(pcPicBottom)
+    {
+      pcPicBottom->destroy();
+      delete pcPicBottom;
+      pcPicBottom = NULL;
+    }
+  }
+  else //Frame decoding
+  {
+    while (iterPic != pcListPic->end())
+    {
+      pcPic = *(iterPic);
+      
+      if ( pcPic->getOutputMark() )
+      {
+        // write to file
+#if H_MV
+      if ( m_pchReconFiles[decIdx] )
+#else
+        if ( m_pchReconFile )
+#endif
+        {
+          const Window &conf = pcPic->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+#if H_MV
+        assert( conf   .getScaledFlag() );
+        assert( defDisp.getScaledFlag() );
         m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
 #else
-        m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
-#endif
-                                       conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-                                       conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-                                       conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-                                       conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
-      }
-      
-      // update POC of display order
+          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
+#endif
+                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+        }
+        
+        // update POC of display order
 #if H_MV
       m_pocLastDisplay[decIdx] = pcPic->getPOC();
 #else
-      m_iPOCLastDisplay = pcPic->getPOC();
-#endif
-      
-      // erase non-referenced picture in the reference picture list after display
-      if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
-      {
+        m_iPOCLastDisplay = pcPic->getPOC();
+#endif
+        
+        // erase non-referenced picture in the reference picture list after display
+        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
+        {
 #if !DYN_REF_FREE
-        pcPic->setReconMark(false);
-        
-        // mark it should be extended later
-        pcPic->getPicYuvRec()->setBorderExtension( false );
-        
-#else
-        pcPic->destroy();
-        pcListPic->erase( iterPic );
-        iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
-        continue;
-#endif
-      }
-      pcPic->setOutputMark(false);
-    }
+          pcPic->setReconMark(false);
+          
+          // mark it should be extended later
+          pcPic->getPicYuvRec()->setBorderExtension( false );
+          
+#else
+          pcPic->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        pcPic->setOutputMark(false);
+      }
 #if !H_MV
 #if !DYN_REF_FREE
-    if(pcPic)
-    {
-      pcPic->destroy();
-      delete pcPic;
-      pcPic = NULL;
-    }
-#endif 
-#endif
-    iterPic++;
+      if(pcPic)
+      {
+        pcPic->destroy();
+        delete pcPic;
+        pcPic = NULL;
+      }
+#endif    
+#endif
+      iterPic++;
+    }
   }
 #if H_MV
Index: trunk/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 625)
+++ trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 655)
@@ -72,5 +72,4 @@
 #endif
     // for output control
-  Bool                            m_abDecFlag[ MAX_GOP ];         ///< decoded flag in one GOP
 #if H_MV
   Int                             m_pocLastDisplay      [ MAX_NUM_LAYERS ]; ///< last POC in display order
Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 625)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 655)
@@ -82,4 +82,8 @@
   m_codedPivotValue = NULL;
   m_targetPivotValue = NULL;
+
+#if KWU_RC_MADPRED_E0227
+  m_depthMADPred = 0;
+#endif
 }
 
@@ -224,10 +228,4 @@
     in>>entry.m_interViewRefPosL[1][i];
   }
-#if !H_MV5
-  if (entry.m_numActiveRefLayerPics > 0 )
-  {
-    in>>entry.m_collocatedRefLayerIdx; 
-  }
-#endif
 #endif
   return in;
@@ -369,19 +367,11 @@
   ("NumberOfLayers",        m_numberOfLayers     , 1,                     "Number of layers")
 #if !H_3D
-#if H_MV5
   ("ScalabilityMask",       m_scalabilityMask    , 2                    , "Scalability Mask")    
-#else
-  ("ScalabilityMask",       m_scalabilityMask    , 1                    , "Scalability Mask")    
-#endif
 #else
   ("ScalabilityMask",       m_scalabilityMask    , 3                    , "Scalability Mask, 1: Texture 3: Texture + Depth ")    
 #endif  
   ("DimensionIdLen",        m_dimensionIdLen     , cfg_dimensionLength  , "Number of bits used to store dimensions Id")
-#if H_MV5
   ("ViewOrderIndex",        m_viewOrderIndex     , std::vector<Int>(1,0), "View Order Index per layer")
   ("ViewId",                m_viewId             , std::vector<Int>(1,0), "View Id per View Order Index")
-#else
-  ("ViewId",                m_viewId             , std::vector<Int>(1,0), "View Id")
-#endif
 #if H_3D
   ("DepthFlag",             m_depthFlag          , std::vector<Int>(1,0), "Depth Flag")
@@ -428,4 +418,8 @@
   ("FramesToBeEncoded,f",   m_framesToBeEncoded,   0, "Number of frames to be encoded (default=all)")
 
+  //Field coding parameters
+  ("FieldCoding", m_isField, false, "Signals if it's a field based coding")
+  ("TopFieldFirst, Tff", m_isTopFieldFirst, false, "In case of field based coding, signals whether if it's a top field first or not")
+  
   // Profile and level
   ("Profile", m_profile,   Profile::NONE, "Profile to be used when encoding (Incomplete)")
@@ -517,5 +511,5 @@
   ("IlluCompEnable",           m_abUseIC, std::vector<Bool>(2, true), "Enable illumination compensation")
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   ("InterSDC",                 m_bDepthInterSDCFlag,        true, "Enable depth inter SDC")
 #endif
@@ -594,11 +588,26 @@
   ( "InitialQP",           m_RCInitialQP,               0, "Rate control: initial QP" )
   ( "RCForceIntraQP",      m_RCForceIntraQP,        false, "Rate control: force intra QP to be equal to initial QP" )
+
+#if KWU_RC_VIEWRC_E0227
+  ("ViewWiseTargetBits, -vtbr" ,  m_viewTargetBits,  std::vector<Int>(1, 32), "View-wise target bit-rate setting")
+  ("TargetBitAssign, -ta", m_viewWiseRateCtrl, false, "View-wise rate control on/off")
+#endif
+#if KWU_RC_MADPRED_E0227
+  ("DepthMADPred, -dm", m_depthMADPred, (UInt)0, "Depth based MAD prediction on/off")
+#endif
 #else
   ("RateCtrl,-rc", m_enableRateCtrl, false, "Rate control on/off")
   ("TargetBitrate,-tbr", m_targetBitrate, 0, "Input target bitrate")
   ("NumLCUInUnit,-nu", m_numLCUInUnit, 0, "Number of LCUs in an Unit")
-#endif
-
-#if H_MV5
+
+#if KWU_RC_VIEWRC_E0227
+  ("ViewWiseTargetBits, -vtbr" ,  m_viewTargetBits,  std::vector<Int>(1, 32), "View-wise target bit-rate setting")
+  ("TargetBitAssign, -ta", m_viewWiseRateCtrl, false, "View-wise rate control on/off")
+#endif
+#if KWU_RC_MADPRED_E0227
+  ("DepthMADPred, -dm", m_depthMADPred, (UInt)0, "Depth based MAD prediction on/off")
+#endif
+#endif
+
 #if H_MV
   // VPS VUI
@@ -617,5 +626,4 @@
   ("CtuBasedOffsetEnabledFlag"   , m_ctuBasedOffsetEnabledFlag   , std::vector< Bool >(1,0)  ,MAX_NUM_LAYERS       , "CtuBasedOffsetEnabledFlag    per direct reference for the N-th layer")
   ("MinHorizontalCtuOffsetPlus1" , m_minHorizontalCtuOffsetPlus1 , std::vector< Int  >(1,0)  ,MAX_NUM_LAYERS       , "MinHorizontalCtuOffsetPlus1  per direct reference for the N-th layer")
-#endif
 #endif
 
@@ -762,7 +770,5 @@
     if( k == 0 )
     {
-#if H_MV5
       m_GOPListMvc[0][0].m_sliceType = 'I'; 
-#endif
       for( Int i = 1; i < MAX_GOP + 1; i++ ) 
       {
@@ -810,4 +816,14 @@
   const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
 
+  if(m_isField)
+  {
+    //Frame height
+    m_iSourceHeightOrg = m_iSourceHeight;
+    //Field height
+    m_iSourceHeight = m_iSourceHeight >> 1;
+    //number of fields to encode
+    m_framesToBeEncoded *= 2;
+  }
+  
   for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
   {
@@ -928,4 +944,9 @@
         m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
         m_iSourceHeight += m_confBottom;
+        if ( m_isField )
+        {
+          m_iSourceHeightOrg += m_confBottom << 1;
+          m_aiPad[1] = m_confBottom << 1;
+        }
       }
       if (m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0)
@@ -968,5 +989,4 @@
   // allocate slice-based dQP values
 #if H_MV
-#if H_MV5
   xResizeVector( m_viewOrderIndex    ); 
 
@@ -988,26 +1008,4 @@
 #if H_3D
   xResizeVector( m_depthFlag ); 
-#endif
-#else
-  xResizeVector( m_viewId    ); 
-#if H_3D
-  xResizeVector( m_depthFlag ); 
-
-  std::vector<Int> uniqueViewIds; 
-  for( Int layer = 0; layer < m_numberOfLayers; layer++ )
-  {    
-    Bool isIn = false; 
-    for ( Int i = 0 ; i < uniqueViewIds.size(); i++ )
-    {
-      isIn = isIn || ( m_viewId[ layer ] == uniqueViewIds[ i ] ); 
-    }
-    if ( !isIn ) 
-    {
-      uniqueViewIds.push_back( m_viewId[ layer ] ); 
-    } 
-  }
-  m_iNumberOfViews = (Int) uniqueViewIds.size(); 
-#endif
-
 #endif
   xResizeVector( m_fQP ); 
@@ -1283,5 +1281,4 @@
   xConfirmPara( (m_layerIdInNuh.size()!=1) && (m_layerIdInNuh.size() < m_numberOfLayers) , "LayerIdInNuh must be given for all layers. ");
   
-#if H_MV5
 #if H_3D
   xConfirmPara( m_scalabilityMask != 2 && m_scalabilityMask != 3, "Scalability Mask must be equal to 2 or 3. ");
@@ -1298,19 +1295,4 @@
 
   m_dimIds.push_back( m_viewOrderIndex );   
-#else
-#if H_3D
-  xConfirmPara( m_scalabilityMask != 1 && m_scalabilityMask != 3, "Scalability Mask must be equal to 1 or 3. ");
-#else
-  xConfirmPara( m_scalabilityMask != 1 , "Scalability Mask must be equal to 1. ");
-#endif
- 
-  m_dimIds.push_back( m_viewId ); 
-  const Int viewDimPosition = 0; 
-#if H_3D
-  if ( m_scalabilityMask & ( 1 << DEPTH_ID ) )
-    m_dimIds.push_back( m_depthFlag ); 
-#endif
-
-#endif
   xConfirmPara(  m_dimensionIdLen.size() < m_dimIds.size(), "DimensionIdLen must be given for all dimensions. "   );   Int dimBitOffset[MAX_NUM_SCALABILITY_TYPES+1]; 
 
@@ -1329,9 +1311,5 @@
   {    
     xConfirmPara( m_dimIds[j].size() < m_numberOfLayers,  "DimensionId must be given for all layers and all dimensions. ");   
-#if H_MV5   
     xConfirmPara( (m_dimIds[j][0] != 0)                 , "DimensionId of layer 0 must be 0. " );
-#else
-    xConfirmPara( ( j != viewDimPosition ) &&  (m_dimIds[j][0] != 0), "DimensionId of layer 0 must be 0. " );
-#endif
     xConfirmPara( m_dimensionIdLen[j] < 1 || m_dimensionIdLen[j] > 8, "DimensionIdLen must be greater than 0 and less than 9 in all dimensions. " ); 
      
@@ -1372,26 +1350,19 @@
      xConfirmPara( allEqual , "Each layer shall have a different position in scalability space." );
 
+#if !H_3D_FCO
      if ( numDiff  == 1 ) 
      {
        Bool inc = m_dimIds[ lastDiff ][ i ] > m_dimIds[ lastDiff ][ j ]; 
-#if H_MV5
        Bool shallBeButIsNotIncreasing = ( !inc  ) ; 
-#else
-       Bool shallBeButIsNotIncreasing = ( !inc && ( lastDiff != viewDimPosition ) ) ; 
-#endif
        if ( shallBeButIsNotIncreasing )
        {       
          printf( "\nError: Positions of Layers %d and %d is not increasing in dimension %d \n", i, j, lastDiff);        
        }
-#if H_MV5
        xConfirmPara( shallBeButIsNotIncreasing,  "DimensionIds shall be increasing within one dimension. " );
-#else
-       xConfirmPara( shallBeButIsNotIncreasing && ( lastDiff != viewDimPosition ),  "DimensionIds shall be increasing within one dimension. " );
-#endif
      }
+#endif
    }
  }
 
-#if H_MV5
  /// ViewId 
  xConfirmPara( m_viewId.size() != m_iNumberOfViews, "The number of ViewIds must be equal to the number of views." ); 
@@ -1399,7 +1370,4 @@
   /// Layer sets
   xConfirmPara( m_vpsNumLayerSets < 0 || m_vpsNumLayerSets > 1024, "VpsNumLayerSets must be greater than 0 and less than 1025. ") ; 
-#else
-  xConfirmPara( m_vpsNumLayerSets < 0 || m_vpsNumLayerSets > 1024, "VpsNumLayerSets must be greater than 0 and less than 1025") ; 
-#endif
   for( Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++ )
   {
@@ -1743,7 +1711,11 @@
   Bool errorGOP=false;
   Int checkGOP=1;
-  Int numRefs = 1;
+  Int numRefs = m_isField ? 2 : 1;
   Int refList[MAX_NUM_REF_PICS+1];
   refList[0]=0;
+  if(m_isField)
+  {
+    refList[1] = 1;
+  }
   Bool isOK[MAX_GOP];
   for(Int i=0; i<MAX_GOP; i++) 
@@ -2157,9 +2129,10 @@
     xConfirmPara( (numLCUInPic % m_numLCUInUnit) != 0, "total number of LCUs in a frame should be completely divided by NumLCUInUnit" );
 
+#if !KWU_FIX_URQ
     m_iMaxDeltaQP       = MAX_DELTA_QP;
+#endif
     m_iMaxCuDQPDepth    = MAX_CUDQP_DEPTH;
   }
 #endif
-#if H_MV5
 #if H_MV
   // VPS VUI
@@ -2184,5 +2157,4 @@
   }
 #endif
-#endif
 
   xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagValue, "CUTransquantBypassFlagValue cannot be 1 when TransquantBypassEnableFlag is 0");
@@ -2250,10 +2222,6 @@
 #endif
 #if H_MV
-#if H_MV5
   xPrintParaVector( "ViewIdVal"     , m_viewId ); 
   xPrintParaVector( "ViewOrderIndex", m_viewOrderIndex ); 
-#else
-  xPrintParaVector( "ViewId", m_viewId ); 
-#endif
 #endif
 #if H_3D
@@ -2268,5 +2236,22 @@
   printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
   printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
+  if (m_isField)
+  {
+    printf("Frame/Field          : Field based coding\n");
+    printf("Field index          : %u - %d (%d fields)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
+    if (m_isTopFieldFirst)
+    {
+      printf("Field Order            : Top field first\n");
+    }
+    else
+    {
+      printf("Field Order            : Bottom field first\n");
+    }
+  }
+  else
+  {
+    printf("Frame/Field                  : Frame based coding\n");
   printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
+  }
   printf("CU size / depth              : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
   printf("RQT trans. size (min / max)  : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
@@ -2299,4 +2284,23 @@
     printf("InitialQP                    : %d\n", m_RCInitialQP );
     printf("ForceIntraQP                 : %d\n", m_RCForceIntraQP );
+
+#if KWU_RC_MADPRED_E0227
+    printf("Depth based MAD prediction   : %d\n", m_depthMADPred);
+#endif
+#if KWU_RC_VIEWRC_E0227
+    printf("View-wise Rate control       : %d\n", m_viewWiseRateCtrl);
+    if(m_viewWiseRateCtrl)
+    {
+
+      printf("ViewWiseTargetBits           : ");
+      for (Int i = 0 ; i < m_iNumberOfViews ; i++)
+        printf("%d ", m_viewTargetBits[i]);
+      printf("\n");
+    }
+    else
+    {
+      printf("TargetBitrate                : %d\n", m_RCTargetBitrate );
+    }
+#endif
   }
 #else
@@ -2306,4 +2310,23 @@
     printf("TargetBitrate                : %d\n", m_targetBitrate);
     printf("NumLCUInUnit                 : %d\n", m_numLCUInUnit);
+
+#if KWU_RC_MADPRED_E0227
+    printf("Depth based MAD prediction   : %d\n", m_depthMADPred);
+#endif
+#if KWU_RC_VIEWRC_E0227
+    printf("View-wise Rate control       : %d\n", m_viewWiseRateCtrl);
+    if(m_viewWiseRateCtrl)
+    {
+
+      printf("ViewWiseTargetBits           : ");
+      for (Int i = 0 ; i < m_iNumberOfViews ; i++)
+        printf("%d ", m_viewTargetBits[i]);
+      printf("\n");
+    }
+    else
+    {
+      printf("TargetBitrate                : %d\n", m_targetBitrate );
+    }
+#endif
   }
 #endif
@@ -2414,5 +2437,5 @@
   printf("DLT:%d ", m_useDLT );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   printf( "interSDC: %d ", m_bDepthInterSDCFlag ? 1 : 0 );
 #endif
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 625)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 655)
@@ -69,11 +69,5 @@
   std::vector<char*>     m_pchReconFileList;                  ///< output reconstruction file names
   Int                    m_numberOfLayers;                    ///< number of Layers to Encode
-#if H_MV5
   Int                    m_iNumberOfViews;                    ///< number of Layers that are views
-#else
-#if H_3D
-  Int                    m_iNumberOfViews;                    ///< number of Layers that are views
-#endif
-#endif
 #else
   Char*     m_pchReconFile;                                   ///< output reconstruction file
@@ -83,7 +77,5 @@
   std::vector< std::vector<Int> > m_dimIds;                   ///< dimension ids ( pointers to m_viewId and m_depthFlag 
   std::vector<Int>       m_viewId;                            ///< view id
-#if H_MV5
   std::vector<Int>       m_viewOrderIndex;                    ///< view order index  
-#endif
 #if H_3D
   std::vector<Int>       m_depthFlag;                         ///< depth flag
@@ -106,5 +98,4 @@
   std::vector< std::vector<Int> > m_dependencyTypes;          ///< Dependency types of direct reference layers
 
-#if H_MV5
   // VPS VUI
   Bool m_vpsVuiPresentFlag;
@@ -122,5 +113,4 @@
   std::vector< std::vector<Bool > > m_ctuBasedOffsetEnabledFlag;
   std::vector< std::vector<Int  > > m_minHorizontalCtuOffsetPlus1;
-#endif
 
 #if H_3D_IV_MERGE
@@ -149,5 +139,11 @@
   UInt      m_FrameSkip;                                      ///< number of skipped frames from the beginning
   Int       m_iSourceWidth;                                   ///< source width in pixel
-  Int       m_iSourceHeight;                                  ///< source height in pixel
+  Int       m_iSourceHeight;                                  ///< source height in pixel (when interlaced = field height)
+  
+  Int       m_iSourceHeightOrg;                               ///< original source height in pixel (when interlaced = frame height)
+  
+  bool      m_isField;                                        ///< enable field coding
+  bool      m_isTopFieldFirst;
+  
   Int       m_conformanceMode;
   Int       m_confLeft;
@@ -367,8 +363,24 @@
   Int       m_RCInitialQP;                        ///< inital QP for rate control
   Bool      m_RCForceIntraQP;                     ///< force all intra picture to use initial QP or not
+
+#if KWU_RC_VIEWRC_E0227
+  vector<Int>     m_viewTargetBits;
+  Bool      m_viewWiseRateCtrl;                              ///< Flag for using view-wise rate control
+#endif
+#if KWU_RC_MADPRED_E0227
+  UInt       m_depthMADPred;
+#endif
 #else
   Bool      m_enableRateCtrl;                                   ///< Flag for using rate control algorithm
   Int       m_targetBitrate;                                 ///< target bitrate
   Int       m_numLCUInUnit;                                  ///< Total number of LCUs in a frame should be completely divided by the NumLCUInUnit
+
+#if KWU_RC_VIEWRC_E0227
+  vector<Int>     m_viewTargetBits;
+  Bool      m_viewWiseRateCtrl;                              ///< Flag for using view-wise rate control
+#endif
+#if KWU_RC_MADPRED_E0227
+  UInt       m_depthMADPred;
+#endif
 #endif
   Int       m_useScalingListId;                               ///< using quantization matrix
@@ -457,5 +469,5 @@
   Bool      m_bUsePC;                                         ///< flag for using Predictive Coding with QTL
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Bool m_bDepthInterSDCFlag;                                ///< flag for inter SDC of depth map coding
 #endif
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 625)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 655)
@@ -88,9 +88,5 @@
     vps.setTemporalNestingFlag(true);
   }
-#if H_MV5
   vps.setMaxLayersMinus1( m_numberOfLayers - 1);
-#else
-  vps.setMaxLayers( m_numberOfLayers );
-#endif
   for(Int i = 0; i < MAX_TLAYER; i++)
   {
@@ -124,15 +120,8 @@
   xSetDependencies( vps );
   xSetProfileTierLevel     ( vps ); 
-#if H_MV5
   xSetRepFormat            ( vps ); 
-#endif
   xSetLayerSets            ( vps ); 
-#if H_MV5
   xSetVPSVUI               ( vps ); 
-#endif
 #if H_3D
-#if !H_MV5
-  vps.initViewIndex(); 
-#endif
   xSetVPSExtension2        ( vps ); 
   m_ivPicLists.setVPS      ( &vps ); 
@@ -140,9 +129,5 @@
 
 
-#if H_MV5
   for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++)
-#else 
-  for(Int layer = 0; layer < m_numberOfLayers; layer++)
-#endif
   {
     m_frameRcvd                 .push_back(0);
@@ -151,5 +136,4 @@
     m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
     m_picYuvRec                 .push_back(new TComList<TComPicYuv*>) ;
-#if H_MV5   
     m_ivPicLists.push_back( m_acTEncTopList[ layerIdInVps ]->getListPic()  ); 
     TEncTop& m_cTEncTop = *m_acTEncTopList[ layerIdInVps ];  // It is not a member, but this name helps avoiding code duplication !!!
@@ -160,20 +144,6 @@
     m_cTEncTop.setViewId                       ( vps.getViewId      (  layerId ) );
     m_cTEncTop.setViewIndex                    ( vps.getViewIndex   (  layerId ) );
-#else
-    m_ivPicLists.push_back( m_acTEncTopList[ layer ]->getListPic()  ); 
-    TEncTop& m_cTEncTop = *m_acTEncTopList[ layer ];  // It is not a member, but this name helps avoiding code duplication !!!
-    
-    m_cTEncTop.setLayerIdInVps                 ( layer ); 
-    m_cTEncTop.setLayerId                      ( vps.getLayerIdInNuh( layer ) );    
-    m_cTEncTop.setViewId                       ( vps.getViewId      ( layer ) );
-
-#endif
 #if H_3D
-#if H_MV5
     Bool isDepth = ( vps.getDepthId     ( layerId ) != 0 ) ;
-#else
-    Bool isDepth = ( vps.getDepthId     ( layer ) != 0 ) ;
-    m_cTEncTop.setViewIndex                    ( vps.getViewIndex   ( layer ) );
-#endif
     m_cTEncTop.setIsDepth                      ( isDepth );
     //====== Camera Parameters =========
@@ -201,5 +171,4 @@
     m_cTEncTop.setDWeight                      ( isDepth ? m_iDWeight             : 0     );
 #endif // H_3D_VSO
-#if H_MV5
 #if H_3D_ARP
     //====== Advanced Inter-view Residual Prediction =========
@@ -209,14 +178,4 @@
 #if H_3D_IC
     m_cTEncTop.setUseIC                        ( vps.getViewIndex( layerId ) == 0 ? false : m_abUseIC[isDepth ? 1 : 0] );
-#endif
-#else
-#if H_3D_ARP
-    //====== Advanced Inter-view Residual Prediction =========
-    m_cTEncTop.setUseAdvRP                     ( ( isDepth || 0==layer ) ? 0 : m_uiUseAdvResPred );
-    m_cTEncTop.setARPStepNum                   ( ( isDepth || 0==layer ) ? 1 : H_3D_ARP_WFNR     );
-#endif
-#if H_3D_IC
-    m_cTEncTop.setUseIC                        ( vps.getViewIndex( layer ) == 0 ? false : m_abUseIC[isDepth ? 1 : 0] );
-#endif
 #endif
   //========== Depth intra modes ==========
@@ -232,5 +191,5 @@
 #endif
     //====== Depth Inter SDC =========
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
     m_cTEncTop.setInterSDCEnable               ( isDepth ? m_bDepthInterSDCFlag    : false );
 #endif
@@ -260,5 +219,4 @@
   m_cTEncTop.setGOPSize                      ( m_iGOPSize );
 #if H_MV
-#if H_MV5
 m_cTEncTop.setGopList                      ( m_GOPListMvc[layerIdInVps] );
   m_cTEncTop.setExtraRPSs                    ( m_extraRPSsMvc[layerIdInVps] );
@@ -269,13 +227,4 @@
   }
 #else
-  m_cTEncTop.setGopList                      ( m_GOPListMvc[layer] );
-  m_cTEncTop.setExtraRPSs                    ( m_extraRPSsMvc[layer] );
-  for(Int i = 0; i < MAX_TLAYER; i++)
-  {
-    m_cTEncTop.setNumReorderPics             ( m_numReorderPicsMvc[layer][i], i );
-    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBufferingMvc[layer][i], i );
-  }
-#endif
-#else
   m_cTEncTop.setGopList                      ( m_GOPList );
   m_cTEncTop.setExtraRPSs                    ( m_extraRPSs );
@@ -291,10 +240,6 @@
   }
 #if H_MV
-#if H_MV5
   m_cTEncTop.setQP                           ( m_iQP[layerIdInVps] );
 #else
-  m_cTEncTop.setQP                           ( m_iQP[layer] );
-#endif
-#else
   m_cTEncTop.setQP                           ( m_iQP );
 #endif
@@ -303,10 +248,6 @@
 
 #if H_MV
-#if H_MV5
   m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayerMvc[layerIdInVps] );
 #else
-  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayerMvc[layer] );
-#endif
-#else
   m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayer );
 #endif
@@ -317,9 +258,5 @@
   //====== Loop/Deblock Filter ========
 #if H_MV
-#if H_MV5
   m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable[layerIdInVps]);
-#else
-  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable[layer]);
-#endif
 #else
   m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable       );
@@ -351,9 +288,5 @@
 
 #if H_MV
-#if H_MV5
   if ((m_iMaxDeltaQP == 0 ) && (m_iQP[layerIdInVps] == lowestQP) && (m_useLossless == true))
-#else
-  if ((m_iMaxDeltaQP == 0 ) && (m_iQP[layer] == lowestQP) && (m_useLossless == true))
-#endif
 #else
   if ((m_iMaxDeltaQP == 0 ) && (m_iQP == lowestQP) && (m_useLossless == true))
@@ -372,9 +305,5 @@
   m_cTEncTop.setUseLossless                  ( m_useLossless );
 #if H_MV
-#if H_MV5
   m_cTEncTop.setdQPs                         ( m_aidQP[layerIdInVps]   );
-#else
-  m_cTEncTop.setdQPs                         ( m_aidQP[layer]   );
-#endif
 #else
   m_cTEncTop.setdQPs                         ( m_aidQP        );
@@ -435,9 +364,5 @@
   m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
 #if H_MV
-#if H_MV5
   m_cTEncTop.setUseSAO ( m_bUseSAO[layerIdInVps] );
-#else
-  m_cTEncTop.setUseSAO ( m_bUseSAO[layer] );
-#endif
 #else
   m_cTEncTop.setUseSAO ( m_bUseSAO );
@@ -512,6 +437,19 @@
   m_cTEncTop.setSignHideFlag(m_signHideFlag);
 #if RATE_CONTROL_LAMBDA_DOMAIN
-  m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
+#if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227
+  if(!m_cTEncTop.getIsDepth())    //only for texture
+  {
+    m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
+  }
+  else
+  {
+    m_cTEncTop.setUseRateCtrl         ( 0 );
+  }
+#else
+    m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
+#endif
+#if !KWU_RC_VIEWRC_E0227
   m_cTEncTop.setTargetBitrate       ( m_RCTargetBitrate );
+#endif
   m_cTEncTop.setKeepHierBit         ( m_RCKeepHierarchicalBit );
   m_cTEncTop.setLCULevelRC          ( m_RCLCULevelRC );
@@ -519,8 +457,162 @@
   m_cTEncTop.setInitialQP           ( m_RCInitialQP );
   m_cTEncTop.setForceIntraQP        ( m_RCForceIntraQP );
-#else
-  m_cTEncTop.setUseRateCtrl     ( m_enableRateCtrl);
-  m_cTEncTop.setTargetBitrate   ( m_targetBitrate);
-  m_cTEncTop.setNumLCUInUnit    ( m_numLCUInUnit);
+
+#if KWU_RC_MADPRED_E0227
+  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
+  {
+    m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred       : 0);
+
+    if(m_cTEncTop.getUseDepthMADPred())
+    {
+      m_cTEncTop.setCamParam(&m_cCameraData);
+    }
+  }
+#endif
+#if KWU_RC_VIEWRC_E0227
+  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
+  {
+    m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl);
+
+    if(m_iNumberOfViews == 1)
+    {
+      if(m_viewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
+      }
+      else
+      {
+        m_cTEncTop.setTargetBitrate       ( m_RCTargetBitrate );
+      }
+    }
+    else
+    {
+      if(m_viewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
+      }
+      else
+      {
+        if(m_iNumberOfViews == 2)
+        {
+          if(m_cTEncTop.getViewId() == 0)
+          {
+            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*80)/100 );
+          }
+          else if(m_cTEncTop.getViewId() == 1)
+          {
+            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*20)/100 );
+          }
+        }
+        else if(m_iNumberOfViews == 3)
+        {
+          if(m_cTEncTop.getViewId() == 0)
+          {
+            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*66)/100 );
+          }
+          else if(m_cTEncTop.getViewId() == 1)
+          {
+            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*17)/100 );
+          }
+          else if(m_cTEncTop.getViewId() == 2)
+          {
+            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*17)/100 );
+          }
+        }
+        else
+        {
+          m_cTEncTop.setTargetBitrate              ( m_RCTargetBitrate );
+        }
+      }
+    }
+  }
+#endif
+#else
+#if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227
+  if(!m_cTEncTop.getIsDepth())    //only for texture
+  {
+    m_cTEncTop.setUseRateCtrl         ( m_enableRateCtrl );
+    m_cTEncTop.setTargetBitrate       ( m_targetBitrate );
+    m_cTEncTop.setNumLCUInUnit        ( m_numLCUInUnit);
+  }
+  else
+  {
+    m_cTEncTop.setUseRateCtrl         ( 0 );
+  }
+#else
+  m_cTEncTop.setUseRateCtrl         ( m_enableRateCtrl );
+  m_cTEncTop.setTargetBitrate       ( m_targetBitrate );
+  m_cTEncTop.setNumLCUInUnit        ( m_numLCUInUnit);
+#endif
+
+  
+#if KWU_RC_MADPRED_E0227
+  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
+  {
+    m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred       : 0);
+
+    if(m_cTEncTop.getUseDepthMADPred())
+    {
+      m_cTEncTop.setCamParam(&m_cCameraData);
+    }
+  }
+#endif
+
+#if KWU_RC_VIEWRC_E0227
+  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
+  {
+    m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl);
+    if(m_iNumberOfViews == 1)
+    {
+      if(m_viewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
+      }
+      else
+      {
+        m_cTEncTop.setTargetBitrate       ( m_targetBitrate );
+      }
+    }
+    else
+    {
+      if(m_viewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
+      }
+      else
+      {
+        if(m_iNumberOfViews == 2)
+        {
+          if(m_cTEncTop.getViewId() == 0)
+          {
+            m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*80)/100 );
+          }
+          else if(m_cTEncTop.getViewId() == 1)
+          {
+            m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*20)/100 );
+          }
+        }
+        else if(m_iNumberOfViews == 3)
+        {
+          if(m_cTEncTop.getViewId() == 0)
+          {
+            m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*66)/100 );
+          }
+          else if(m_cTEncTop.getViewId() == 1)
+          {
+            m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*17)/100 );
+          }
+          else if(m_cTEncTop.getViewId() == 2)
+          {
+            m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*17)/100 );
+          }
+        }
+        else
+        {
+          m_cTEncTop.setTargetBitrate              ( m_targetBitrate );
+        }
+      }
+    }
+  }
+#endif
 #endif
   m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
@@ -664,13 +756,17 @@
 }
 
-Void TAppEncTop::xInitLib()
+Void TAppEncTop::xInitLib(Bool isFieldCoding)
 {
 #if H_MV
   for(Int layer=0; layer<m_numberOfLayers; layer++)
   {
-    m_acTEncTopList[layer]->init( );
-  }
-#else
-  m_cTEncTop.init();
+#if KWU_RC_MADPRED_E0227
+    m_acTEncTopList[layer]->init( isFieldCoding, this );
+#else
+    m_acTEncTopList[layer]->init( isFieldCoding );
+#endif
+  }
+#else
+  m_cTEncTop.init( isFieldCoding );
 #endif
 }
@@ -703,5 +799,5 @@
   xInitLibCfg();
   xCreateLib();
-  xInitLib();
+  xInitLib(m_isField);
   
   // main encoder loop
@@ -728,5 +824,12 @@
 
   // allocate original YUV buffer
+  if( m_isField )
+  {
+    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeightOrg, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+  }
+  else
+  {
   pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+  }
   
 #if H_MV
@@ -789,9 +892,20 @@
       }
     }
+
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
+    for(Int layer=0; layer < m_numberOfLayers; layer++ )
+    {
+      if(m_acTEncTopList[layer]->getUseRateCtrl()  && !m_acTEncTopList[layer]->getIsDepth())
+      {
+        m_acTEncTopList[layer]->getRateCtrl()->updateRCGOPStatus();
+      }
+    }
+#endif
+
     gopSize = maxGopSize;
   }
   for(Int layer=0; layer < m_numberOfLayers; layer++ )
   {
-    m_acTEncTopList[layer]->printSummary( m_acTEncTopList[layer]->getNumAllPicCoded() );
+    m_acTEncTopList[layer]->printSummary( m_acTEncTopList[layer]->getNumAllPicCoded(), m_isField );
   }
 #else
@@ -807,5 +921,5 @@
     m_iFrameRcvd++;
 
-    bEos = (m_iFrameRcvd == m_framesToBeEncoded);
+    bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
 
     Bool flush = 0;
@@ -820,5 +934,12 @@
 
     // call encoding function for one frame
+    if ( m_isField )
+    {
+      m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst);
+    }
+    else
+    {
     m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
+    }
     
     // write bistream to file if necessary
@@ -830,5 +951,5 @@
   }
 
-  m_cTEncTop.printSummary();
+  m_cTEncTop.printSummary(m_isField);
 #endif
 
@@ -941,30 +1062,35 @@
 #endif
 {
-  Int i;
-  
-#if H_MV
-  if( iNumEncoded > 0 )
-  {
-    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_picYuvRec[layerId]->end();
-#else
-  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
-  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
-#endif
-
-  for ( i = 0; i < iNumEncoded; i++ )
-  {
-    --iterPicYuvRec;
-  }
-  
-  for ( i = 0; i < iNumEncoded; i++ )
-  {
-    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+  if (m_isField)
+  {
+    //Reinterlace fields
+    Int i;
+#if H_MV
+    if( iNumEncoded > 0 )
+    {
+      TComList<TComPicYuv*>::iterator iterPicYuvRec = m_picYuvRec[layerId]->end();
+#else
+    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
+    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
+#endif
+
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      --iterPicYuvRec;
+    }
+
+    for ( i = 0; i < iNumEncoded/2; i++ )
+    {
+      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
+      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
+
 #if H_MV
       if (m_pchReconFileList[layerId])
       {
-        m_acTVideoIOYuvReconFileList[layerId]->write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
-      }
-    }
-  }
+        m_acTVideoIOYuvReconFileList[layerId]->write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst );
+      }
+    }
+  }
+
   if( ! accessUnits.empty() )
   {
@@ -972,4 +1098,56 @@
     for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
     {
+      const vector<UInt>& stats = writeAnnexB(bitstreamFile, *aUIter);
+      rateStatsAccum(*aUIter, stats);
+    }
+  }
+#else
+      if (m_pchReconFile)
+      {
+        m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst );
+      }
+
+      const AccessUnit& auTop = *(iterBitstream++);
+      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
+      rateStatsAccum(auTop, statsTop);
+
+      const AccessUnit& auBottom = *(iterBitstream++);
+      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
+      rateStatsAccum(auBottom, statsBottom);
+    }
+#endif
+  }
+  else
+  {
+    Int i;
+#if H_MV
+    if( iNumEncoded > 0 )
+    {
+      TComList<TComPicYuv*>::iterator iterPicYuvRec = m_picYuvRec[layerId]->end();
+#else
+    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
+    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
+#endif
+
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      --iterPicYuvRec;
+    }
+
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+#if H_MV
+      if (m_pchReconFileList[layerId])
+      {
+        m_acTVideoIOYuvReconFileList[layerId]->write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
+      }    
+    }
+  }
+  if( ! accessUnits.empty() )
+  {
+    list<AccessUnit>::iterator aUIter;
+    for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
+    {
       const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter);
       rateStatsAccum(*aUIter, stats);
@@ -977,16 +1155,17 @@
   }
 #else
-    if (m_pchReconFile)
-    {
-      m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
-    }
-
-    const AccessUnit& au = *(iterBitstream++);
-    const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
-    rateStatsAccum(au, stats);
-  }
-#endif
-}
-
+      if (m_pchReconFile)
+      {
+        m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
+      }
+
+      const AccessUnit& au = *(iterBitstream++);
+      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
+      rateStatsAccum(au, stats);   
+    }
+#endif    
+  }
+}
+  
 /**
  *
@@ -1121,17 +1300,9 @@
 Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps )
 {   
-#if H_MV5
   vps.setScalabilityMaskFlag( m_scalabilityMask ); 
-#else
-  vps.setScalabilityMask( m_scalabilityMask ); 
-#endif
   for( Int dim = 0; dim < m_dimIds.size(); dim++ )
   {
     vps.setDimensionIdLen( dim, m_dimensionIdLen[ dim ] );
-#if H_MV5
     for( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ )
-#else
-    for( Int layer = 0; layer < vps.getMaxLayers(); layer++ )
-#endif
 
     {        
@@ -1140,5 +1311,4 @@
   }
 
-#if H_MV5
   Int maxViewId = xGetMax( m_viewId ); 
 
@@ -1153,5 +1323,4 @@
 
   assert( m_iNumberOfViews == vps.getNumViews() ); 
-#endif
 }
 
@@ -1180,7 +1349,5 @@
 
   // Max temporal id for inter layer reference pictures + presence flag
-#if H_MV5
   Bool maxTidRefPresentFlag = false; 
-#endif
   for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++)
     {
@@ -1203,27 +1370,15 @@
     }
     vps.setMaxTidIlRefPicPlus1( refLayerIdInVps, maxTid + 1 );
-#if H_MV5
     maxTidRefPresentFlag = maxTidRefPresentFlag || ( maxTid != 6 );    
-#endif
-  }
-
-#if H_MV5
+  }
+
   vps.setMaxTidRefPresentFlag( maxTidRefPresentFlag );
-#endif
   // Max one active ref layer flag
   Bool maxOneActiveRefLayerFlag = true;  
-#if H_MV5
   for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; layerIdInVps++)
-#else
-  for ( Int currLayerIdInVps = 1; currLayerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; currLayerIdInVps++)
-#endif
   {
     for( Int i = 0; i < ( getGOPSize() + 1) && maxOneActiveRefLayerFlag; i++ ) 
     {        
-#if H_MV5
       GOPEntry ge =  m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
-#else
-      GOPEntry ge =  m_GOPListMvc[currLayerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
-#endif
       maxOneActiveRefLayerFlag =  maxOneActiveRefLayerFlag && (ge.m_numActiveRefLayerPics <= 1); 
     }            
@@ -1233,5 +1388,4 @@
   
   
-#if H_MV5
   // All Ref layers active flag
   Bool allRefLayersActiveFlag = true; 
@@ -1249,9 +1403,7 @@
   // Currently cross layer irap aligned is always true.   
   vps.setCrossLayerIrapAlignedFlag( true ); 
-#endif
   vps.setRefLayers(); 
 }; 
 
-#if H_MV5
 GOPEntry* TAppEncTop::xGetGopEntry( Int layerIdInVps, Int poc )
 {
@@ -1268,5 +1420,4 @@
   return geFound; 
 }
-#endif
 
 Void TAppEncTop::xSetLayerIds( TComVPS& vps )
@@ -1308,5 +1459,4 @@
 }
 
-#if H_MV5
 
 Void TAppEncTop::xSetRepFormat( TComVPS& vps )
@@ -1333,5 +1483,4 @@
   }
 }
-#endif
 
 Void TAppEncTop::xSetLayerSets( TComVPS& vps )
@@ -1386,5 +1535,4 @@
   }
 }
-#if H_MV5
 
 Void TAppEncTop::xSetVPSVUI( TComVPS& vps )
@@ -1478,14 +1626,9 @@
 }
 #endif
-#endif
 #if H_3D
 Void TAppEncTop::xSetVPSExtension2( TComVPS& vps )
 {
-#if H_MV5
 
   for ( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ )
-#else
-  for ( Int layer = 0; layer < vps.getMaxLayers(); layer++ )
-#endif
   {
     Bool isDepth      = ( vps.getDepthId( layer ) == 1 ) ;
@@ -1517,5 +1660,5 @@
     vps.setViewSynthesisPredFlag( layer, !isLayerZero && !isDepth && m_viewSynthesisPredFlag );         
 #endif      
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
     vps.setInterSDCFlag( layer, !isLayerZero && isDepth && m_bDepthInterSDCFlag );
 #endif
Index: trunk/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 625)
+++ trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 655)
@@ -50,4 +50,7 @@
 #endif
 
+#if KWU_RC_MADPRED_E0227
+class TEncTop;
+#endif
 //! \ingroup TAppEncoder
 //! \{
@@ -93,5 +96,5 @@
   Void  xCreateLib        ();                               ///< create files & encoder class
   Void  xInitLibCfg       ();                               ///< initialize internal variables
-  Void  xInitLib          ();                               ///< initialize encoder class
+  Void  xInitLib          (Bool isFieldCoding);             ///< initialize encoder class
   Void  xDestroyLib       ();                               ///< destroy encoder class
   
@@ -121,9 +124,7 @@
   Void xSetLayerSets              ( TComVPS& vps );
   Void xSetProfileTierLevel       ( TComVPS& vps );
-#if H_MV5
   Void xSetRepFormat              ( TComVPS& vps );
   Void xSetVPSVUI                 ( TComVPS& vps );
   GOPEntry* xGetGopEntry( Int layerIdInVps, Int poc );
-#endif
   Int  xGetMax( std::vector<Int>& vec);
 #endif
Index: trunk/source/Lib/TAppCommon/TAppComCamPara.cpp
===================================================================
--- trunk/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 625)
+++ trunk/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 655)
@@ -615,9 +615,5 @@
 {
   UInt uiFoundLine = -1;
-#if H_3D_FIX_REN_WARNING
   if ( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) && xIsIn( m_aiSortedBaseViews, iView ))
-#else  
-  if ( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) )
-#endif
   {
     AOT( m_aadCameraParameters[ uiFoundLine ].size() < 6 );
@@ -635,18 +631,10 @@
     Int  iDummy;
 
-#if H_3D_FIX_REN_WARNING
     if( !xGetLeftRightView( iView, m_aiSortedBaseViews, iLeftView, iRightView, iDummy, iDummy ) ||
-#else
-    if( !xGetLeftRightView( iView, m_aiViewsInCfgFile, iLeftView, iRightView, iDummy, iDummy ) ||
-#endif
          xGetCameraDataRow( iLeftView,  uiFrame, uiLeftViewLine  )                             ||
          xGetCameraDataRow( iRightView, uiFrame, uiRightViewLine )
       )
     {
-#if H_3D_FIX_REN_WARNING
       std::cerr << "No left or no right base view next to view " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl;
-#else
-      std::cerr << "No Left or no Right View next to View " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl;
-#endif
       AOT(true);
       exit( EXIT_FAILURE );
@@ -1352,5 +1340,5 @@
       }
     }
-#if H_3D_FIX_REN_WARNING
+
     Bool bIgnoreFirst = true;     
     for( UInt uiERView = 0; uiERView < m_aiSynthViews.size() && !m_bSetupFromCoded; uiERView++ )
@@ -1371,5 +1359,4 @@
       std::cout << std::endl; 
     }
-#endif
 
     Bool bInterpolateFirst = true; 
@@ -1390,9 +1377,5 @@
         if ( bInterpolateFirst ) 
         {
-#if H_3D_FIX_REN_WARNING                        
           std::cout << "Interpolating camera parameters      for virtual view(s): " ; 
-#else
-          std::cout << "Interpolating Camera Parameters for View(s) " ; 
-#endif
             bInterpolateFirst = false; 
         }          
@@ -1498,5 +1481,4 @@
 }
 
-#if H_3D_FIX_REN_WARNING
 Bool 
   TAppComCamPara::xIsIn( std::vector<Int>& rVec, Int iElem) 
@@ -1509,5 +1491,4 @@
   return bFound;
 }
-#endif
 
 Int TAppComCamPara::getRelDistLeft( Int iSynthViewIdx, Int iLeftViewIdx, Int iRightViewIdx )
Index: trunk/source/Lib/TAppCommon/TAppComCamPara.h
===================================================================
--- trunk/source/Lib/TAppCommon/TAppComCamPara.h	(revision 625)
+++ trunk/source/Lib/TAppCommon/TAppComCamPara.h	(revision 655)
@@ -125,12 +125,11 @@
   Bool  xGetLeftRightView         ( Int iView, std::vector<Int> aiSortedViews, Int& riLeftView, Int& riRightView, Int& riLeftSortedViewIdx, Int& riRightSortedViewIdx );
   Void  xGetPrevAndNextBaseView   ( Int iSourceViewNum, Int iTargetViewNum, Int& riPrevBaseViewNum, Int& riNextBaseViewNum );
+#if !KWU_RC_MADPRED_E0227
   Void  xGetZNearZFar             ( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar );
   Void  xGetGeometryData          ( Int dView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated );
+#endif
   Void  xSetupBaseViewsFromCoded  ();
   Void  xSetupBaseViews           ( Char* pchBaseViewNumbers, UInt uiNumBaseViews );
-#if H_3D_FIX_REN_WARNING
   Bool  xIsIn                     ( std::vector<Int>& rVec, Int iNumber);
-#endif
-
 
   // functions for getting and setting scales and offsets
@@ -220,4 +219,9 @@
   Int**               getCodedScale             ()  { return m_aaiCodedScale;           }
   Int**               getCodedOffset            ()  { return m_aaiCodedOffset;          }
+
+#if KWU_RC_MADPRED_E0227
+  Void  xGetZNearZFar             ( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar );
+  Void  xGetGeometryData          ( Int dView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated );
+#endif
 };
 
Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 655)
@@ -61,7 +61,7 @@
 #if H_MV
 #define NV_VERSION        "8.1"                 ///< Current software version
-#define HM_VERSION        "11.0"                ///< 
+#define HM_VERSION        "12.0"                ///< 
 #else
-#define NV_VERSION        "11.0"                 ///< Current software version
+#define NV_VERSION        "12.0"                 ///< Current software version
 #endif
 
@@ -187,5 +187,4 @@
 }
 
-#if H_MV5
 template <typename T>
 __inline T gCeilLog2( T val )
@@ -196,5 +195,4 @@
   return ceilLog2;
 }
-#endif
 
 #define RemoveBitIncrement( exp ) ( exp >> ( g_bitDepthY - 8 ) )
Index: trunk/source/Lib/TLibCommon/ContextTables.h
===================================================================
--- trunk/source/Lib/TLibCommon/ContextTables.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/ContextTables.h	(revision 655)
@@ -112,7 +112,4 @@
 #if H_3D_DIM_DMM
 #define NUM_DMM1_DATA_CTX             1       ///< number of context models for DMM1 data
-#if !SEC_DMM2_E0146_HHIFIX
-#define NUM_DMM2_DATA_CTX             1       ///< number of context models for DMM2 data
-#endif
 #define NUM_DMM3_DATA_CTX             1       ///< number of context models for DMM3 data
 #endif
@@ -127,5 +124,5 @@
 #endif
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 #define NUM_INTER_SDC_FLAG_CTX        1      ///< number of context models for inter SDC flag
 #define NUM_INTER_SDC_SIGN_FLAG_CTX   1      ///< number of context models for sign of inter SDC residual
@@ -390,5 +387,4 @@
 #endif
 #if H_3D_DIM
-#if ZJU_DEPTH_INTRA_MODE_E0204
 static const UChar
 INIT_DEPTH_INTRA_MODE[3][NUM_DEPTH_INTRA_MODE_CTX] =
@@ -398,13 +394,5 @@
     {64, 0, CNU, CNU, 168, 109,   0, 0}
 };
-#else
-static const UChar 
-INIT_DEPTH_INTRA_MODE[3][NUM_DEPTH_INTRA_MODE_CTX] =
-{
-  {0,  0,  64,   0, CNU,   0, CNU, 0},
-  {0, 64,   0, CNU,   0, CNU,   0, 0},
-  {64, 0, CNU,   0, CNU,   0,   0, 0}
-};
-#endif
+
 static const UChar 
 INIT_DDC_FLAG[3][NUM_DDC_FLAG_CTX] =
@@ -429,13 +417,4 @@
   { CNU }, 
 };
-#if !SEC_DMM2_E0146_HHIFIX
-static const UChar
-INIT_DMM2_DATA[3][NUM_DMM2_DATA_CTX] = 
-{
-  { CNU }, 
-  { CNU }, 
-  { CNU }, 
-};
-#endif
 static const UChar
 INIT_DMM3_DATA[3][NUM_DMM3_DATA_CTX] = 
@@ -473,5 +452,5 @@
 #endif
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 static const UChar 
 INIT_INTER_SDC_FLAG[3][NUM_INTER_SDC_FLAG_CTX] =
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 655)
@@ -120,7 +120,4 @@
     m_dmmWedgeTabIdx[i] = NULL;
   }
-#if !SEC_DMM2_E0146_HHIFIX
-  m_dmm2DeltaEnd    = NULL;
-#endif
   m_dmm3IntraTabIdx = NULL;
 #endif
@@ -153,5 +150,5 @@
   m_pbICFlag             = NULL;
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   m_pbInterSDCFlag       = NULL;
   for( Int i = 0; i < 4; i++ )
@@ -274,7 +271,4 @@
       m_dmmWedgeTabIdx[i]    = (UInt*)xMalloc(UInt, uiNumPartition);
     }
-#if !SEC_DMM2_E0146_HHIFIX
-    m_dmm2DeltaEnd    = (Int* )xMalloc(Int,  uiNumPartition);
-#endif
     m_dmm3IntraTabIdx = (UInt*)xMalloc(UInt, uiNumPartition);
 #endif
@@ -292,5 +286,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
     m_pbInterSDCFlag     = (Bool*  )xMalloc(Bool,   uiNumPartition);
     for( Int i = 0; i < 4; i++ )
@@ -305,5 +299,5 @@
     m_acCUMvField[1].setNumPartition(uiNumPartition );
   }
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   m_pucInterSDCMask     = (UChar*  )xMalloc(UChar,    g_uiMaxCUHeight*g_uiMaxCUWidth);
 #endif
@@ -410,7 +404,4 @@
       if ( m_dmmWedgeTabIdx[i] ) { xFree( m_dmmWedgeTabIdx[i] ); m_dmmWedgeTabIdx[i] = NULL; }
     }
-#if !SEC_DMM2_E0146_HHIFIX
-    if ( m_dmm2DeltaEnd    ) { xFree( m_dmm2DeltaEnd    ); m_dmm2DeltaEnd    = NULL; }
-#endif
     if ( m_dmm3IntraTabIdx ) { xFree( m_dmm3IntraTabIdx ); m_dmm3IntraTabIdx = NULL; }
 #endif
@@ -428,5 +419,5 @@
 #endif
 #endif    
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
     if ( m_pbInterSDCFlag     ) { xFree(m_pbInterSDCFlag);      m_pbInterSDCFlag    = NULL; }
     for(Int i = 0; i < 4; i++ )
@@ -436,5 +427,5 @@
 #endif
   }
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if ( m_pucInterSDCMask     ) { xFree(m_pucInterSDCMask);      m_pucInterSDCMask    = NULL; }
 #endif
@@ -575,5 +566,5 @@
     m_pbSDCFlag[ui] = pcFrom->m_pbSDCFlag[ui];
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
     m_pbInterSDCFlag[ui] = pcFrom->m_pbInterSDCFlag[ui];
 #endif
@@ -631,7 +622,4 @@
       memset( m_dmmWedgeTabIdx[i] + firstElement, 0,                      numElements * sizeof( *m_dmmWedgeTabIdx[i] ) );
     }
-#if !SEC_DMM2_E0146_HHIFIX
-    memset( m_dmm2DeltaEnd      + firstElement, 0,                        numElements * sizeof( *m_dmm2DeltaEnd    ) );
-#endif
     memset( m_dmm3IntraTabIdx   + firstElement, 0,                        numElements * sizeof( *m_dmm3IntraTabIdx ) );
 #endif
@@ -649,5 +637,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
     memset( m_pbInterSDCFlag   + firstElement,     0,                    numElements * sizeof( *m_pbInterSDCFlag ) );
     for( Int i = 0; i < 4; i++ )
@@ -811,7 +799,4 @@
         m_dmmWedgeTabIdx[i] [ui] = 0;
       }
-#if !SEC_DMM2_E0146_HHIFIX
-      m_dmm2DeltaEnd    [ui] = 0;
-#endif
       m_dmm3IntraTabIdx [ui] = 0;
 #endif
@@ -822,5 +807,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
       m_pbInterSDCFlag[ui] = false;
       for( Int i = 0; i < 4; i++ )
@@ -925,7 +910,4 @@
     memset( m_dmmWedgeTabIdx[i], 0, sizeof(UInt) * m_uiNumPartition );
   }
-#if !SEC_DMM2_E0146_HHIFIX
-  memset( m_dmm2DeltaEnd   , 0, sizeof(Int ) * m_uiNumPartition );
-#endif
   memset( m_dmm3IntraTabIdx, 0, sizeof(UInt) * m_uiNumPartition );
 #endif
@@ -943,5 +925,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   memset( m_pbInterSDCFlag,           0, sizeof( Bool ) * m_uiNumPartition );
   for( Int i = 0; i < 4; i++ )
@@ -1010,7 +992,4 @@
         m_dmmWedgeTabIdx[i] [ui] = pcCU->m_dmmWedgeTabIdx[i] [uiPartOffset+ui];
       }
-#if !SEC_DMM2_E0146_HHIFIX
-      m_dmm2DeltaEnd    [ui] = pcCU->m_dmm2DeltaEnd   [uiPartOffset+ui];
-#endif
       m_dmm3IntraTabIdx [ui] = pcCU->m_dmm3IntraTabIdx[uiPartOffset+ui];
 #endif
@@ -1021,5 +1000,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
       m_pbInterSDCFlag      [ui] = pcCU->m_pbInterSDCFlag    [ uiPartOffset + ui ];
       for( Int i = 0; i < 4; i++ )
@@ -1167,7 +1146,4 @@
     m_dmmWedgeTabIdx[i] = pcCU->getDmmWedgeTabIdx( i ) + uiPart;
   }
-#if !SEC_DMM2_E0146_HHIFIX
-  m_dmm2DeltaEnd    = pcCU->getDmm2DeltaEnd()    + uiPart;
-#endif
   m_dmm3IntraTabIdx = pcCU->getDmm3IntraTabIdx() + uiPart;
 #endif
@@ -1185,5 +1161,5 @@
 #endif
 #endif  
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   m_pbInterSDCFlag          = pcCU->getInterSDCFlag()       + uiPart;
   for( Int i = 0; i < 4; i++ )
@@ -1366,7 +1342,4 @@
     memcpy( m_dmmWedgeTabIdx[i] + uiOffset, pcCU->getDmmWedgeTabIdx( i ), sizeof(UInt) * uiNumPartition );
   }
-#if !SEC_DMM2_E0146_HHIFIX
-  memcpy( m_dmm2DeltaEnd    + uiOffset, pcCU->getDmm2DeltaEnd()   , sizeof(Int ) * uiNumPartition );
-#endif
   memcpy( m_dmm3IntraTabIdx + uiOffset, pcCU->getDmm3IntraTabIdx(), sizeof(UInt) * uiNumPartition );
 #endif
@@ -1384,5 +1357,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   memcpy( m_pbInterSDCFlag  + uiOffset, pcCU->getInterSDCFlag(),      iSizeInBool  );
   for( Int i = 0; i < 4; i++ )
@@ -1496,7 +1469,4 @@
     memcpy( rpcCU->getDmmWedgeTabIdx( i ) + m_uiAbsIdxInLCU, m_dmmWedgeTabIdx[i], sizeof(UInt) * m_uiNumPartition );
   }
-#if !SEC_DMM2_E0146_HHIFIX
-  memcpy( rpcCU->getDmm2DeltaEnd()    + m_uiAbsIdxInLCU, m_dmm2DeltaEnd   , sizeof(Int ) * m_uiNumPartition );
-#endif
   memcpy( rpcCU->getDmm3IntraTabIdx() + m_uiAbsIdxInLCU, m_dmm3IntraTabIdx, sizeof(UInt) * m_uiNumPartition );
 #endif
@@ -1514,5 +1484,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   memcpy( rpcCU->getInterSDCFlag() + m_uiAbsIdxInLCU, m_pbInterSDCFlag,      iSizeInBool  );
   for( Int i = 0;i < 4; i++ )
@@ -1612,7 +1582,4 @@
     memcpy( rpcCU->getDmmWedgeTabIdx( i ) + uiPartOffset, m_dmmWedgeTabIdx[i], sizeof(UInt) * uiQNumPart );
   }
-#if !SEC_DMM2_E0146_HHIFIX
-  memcpy( rpcCU->getDmm2DeltaEnd()    + uiPartOffset, m_dmm2DeltaEnd   , sizeof(Int ) * uiQNumPart );
-#endif
   memcpy( rpcCU->getDmm3IntraTabIdx() + uiPartOffset, m_dmm3IntraTabIdx, sizeof(UInt) * uiQNumPart );
 #endif
@@ -1630,5 +1597,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   memcpy( rpcCU->getInterSDCFlag() + uiPartOffset, m_pbInterSDCFlag,      iSizeInBool  );
   for( Int i = 0; i < 4; i++ )
@@ -2351,5 +2318,5 @@
 #endif
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 Void TComDataCU::setInterSDCFlagSubParts ( Bool bInterSDCFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
 {
@@ -2689,9 +2656,5 @@
   // check prediction mode
   UInt uiLumaPredMode = getLumaIntraDir( uiAbsPartIdx );  
-#if LGE_SDC_REMOVE_DC_E0158
   if( uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX && !isDimDeltaDC( uiLumaPredMode ) ) )
-#else
-  if( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX && !isDimDeltaDC( uiLumaPredMode ) ) )
-#endif
     return true;
   
@@ -3569,7 +3532,18 @@
     UInt uiPartIdxCenter;
     xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );    
+#if H_3D_FCO
+    TComPic * pcTexturePic = m_pcSlice->getTexturePic();
+    TComDataCU *pcTextureCU = 0;
+    if ( pcTexturePic )
+        pcTextureCU = pcTexturePic->getCU( getAddr() );
+#else
     TComDataCU *pcTextureCU = m_pcSlice->getTexturePic()->getCU( getAddr() );
+#endif
  
+#if H_3D_FCO
+    if ( pcTextureCU && pcTexturePic->getReconMark() && !pcTextureCU->isIntra( uiPartIdxCenter ) )
+#else
     if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdxCenter ) )
+#endif
     {
       pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
@@ -4830,21 +4804,5 @@
 
   // use coldir.
-#if H_MV5
   TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
-#else
-#if H_MV
-  TComPic *pColPic;  
-  if (getSlice()->getAltCollocatedIndicationFlag() )
-  {
-    pColPic = getSlice()->getPicFromRefPicSetInterLayer( getSlice()->getActiveMotionPredRefLayerId( getSlice()->getCollocatedRefLayerIdx() )); 
-  }
-  else
-  {
-    pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());  
-  }  
-#else
-  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
-#endif
-#endif
   TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
   if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
@@ -4996,11 +4954,11 @@
                                         + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
 }
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
-Void TComDataCU::compressMV(int scale)
+#if H_3D
+Void TComDataCU::compressMV(Int scale)
 #else
 Void TComDataCU::compressMV()
 #endif
 {
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
+#if H_3D
   Int scaleFactor = (4 / scale ) * AMVP_DECIMATION_FACTOR / m_unitSize;
 #else
@@ -5509,11 +5467,4 @@
     xDeriveCenterIdx(uiPartIdx, uiPartIdxCenter );
 
-    ///*** Derive bottom right neighbour position ***
-#if !SEC_SIMPLIFIED_NBDV_E0142
-    Int iLCUIdxRBNb  = -1;    
-    Int iPartIdxRBNb = -1;
-    xDeriveRightBottomNbIdx(iLCUIdxRBNb, iPartIdxRBNb );
-#endif
-
     ///*** Search temporal candidate pictures for disparity vector ***
     const Int iNumCandPics = getPic()->getNumDdvCandPics();
@@ -5533,46 +5484,37 @@
       }
 
-#if !SEC_SIMPLIFIED_NBDV_E0142
-      // Check BR and Center       
-      for(Int curPosition = 0; curPosition < 2; curPosition++) 
-      {
-#endif
-        Bool bCheck = false; 
-#if !SEC_SIMPLIFIED_NBDV_E0142
-        if ( curPosition == 0 && iLCUIdxRBNb >= 0 )
-#if MTK_NBDV_TN_FIX_E0172
-          bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
+      Bool bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
+
+      if( bCheck )
+      {
+        clipMv(cColMv);
+        pDInfo->m_acNBDV = cColMv;
+        pDInfo->m_aVIdxCan  = iTargetViewIdx;
+
+#if H_3D_NBDV_REF
+        TComPic* picDepth = NULL;   
+#if H_3D_FCO_VSP_DONBDV_E0163
+        picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
+        if ( picDepth->getPicYuvRec() != NULL  )  
+        {
+          cColMv.setZero();
+        }
+        else // Go back with virtual depth
+        {
+          picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
+        }
+
+        assert(picDepth != NULL);
 #else
-          bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
-#endif
-
-        if (curPosition == 1 )
-#endif
-#if MTK_NBDV_TN_FIX_E0172
-          bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
-#else
-          bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
-#endif
-
-        if( bCheck )
-        {
-          clipMv(cColMv);
-          pDInfo->m_acNBDV = cColMv;
-          pDInfo->m_aVIdxCan  = iTargetViewIdx;
-
-#if H_3D_NBDV_REF
-          TComPic* picDepth = NULL;          
-          picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
-          assert(picDepth != NULL);
-          if (picDepth && bDepthRefine)
-            estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
-
-          pDInfo->m_acDoNBDV  = cColMv;
+        picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
+        assert(picDepth != NULL);
+#endif
+        if (picDepth && bDepthRefine)
+          estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
+
+        pDInfo->m_acDoNBDV  = cColMv;
 #endif //H_3D_NBDV_REF
-          return true;
-        }
-#if !SEC_SIMPLIFIED_NBDV_E0142
-      } 
-#endif
+        return true;
+      }
     }
   } 
@@ -5587,5 +5529,5 @@
   if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFT
 #if H_3D_NBDV_REF
-  , bDepthRefine 
+    , bDepthRefine 
 #endif
     ) )
@@ -5599,52 +5541,9 @@
     if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVE
 #if H_3D_NBDV_REF
-  , bDepthRefine 
-#endif
-    ) )
+      , bDepthRefine 
+#endif
+      ) )
       return true;
   }
-
-#if !SEC_SIMPLIFIED_NBDV_E0142
-  //// ******* Get disparity from above right block ******* /////
-  pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true);
-  if(pcTmpCU != NULL )
-  {
-    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
-    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVERIGHT
-#if H_3D_NBDV_REF
-  , bDepthRefine 
-#endif
-    ) )
-      return true;
-  }
-
-  //// ******* Get disparity from below left block ******* /////
-  pcTmpCU = getPUBelowLeft(uiIdx, uiPartIdxLB, true);
-  if( pcTmpCU != NULL )
-  {
-    bCheckMcpDv = true; 
-    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFTBELOW
-#if H_3D_NBDV_REF
-  , bDepthRefine 
-#endif
-    ) )
-      return true;
-  }
-
-  //// ******* Get disparity from above left block ******* /////
-  pcTmpCU = getPUAboveLeft(uiIdx, (m_uiAbsIdxInLCU + uiPartAddr), true);
-  assert(uiPartIdxLT == (m_uiAbsIdxInLCU + uiPartAddr));
-
-  if( pcTmpCU != NULL )
-  {
-    bCheckMcpDv = (( getAddr() - pcTmpCU->getAddr() ) <= 1); 
-    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVELEFT
-#if H_3D_NBDV_REF
-  , bDepthRefine 
-#endif
-    ) )
-      return true;
-  }
-#endif
 
   //// ******* Search MCP blocks ******* /////
@@ -5662,6 +5561,22 @@
           pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
 #if H_3D_NBDV_REF
+#if H_3D_FCO_VSP_DONBDV_E0163
+          TComPic* picDepth  = NULL;
+
+          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
+          if ( picDepth->getPicYuvRec() != NULL )  
+          {
+            cDispVec.setZero();
+          }
+          else // Go back with virtual depth
+          {
+            picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
+          }
+
+          assert(picDepth != NULL);
+#else
           TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
           assert(picDepth!=NULL);
+#endif
 
           if (picDepth && bDepthRefine)
@@ -5679,5 +5594,5 @@
   TComMv defaultDV(0, 0);
   pDInfo->m_acNBDV = defaultDV;
-#if NBDV_DEFAULT_VIEWIDX_BUGFIX
+
   Int valid = 0;
   Int viewIndex = 0;
@@ -5707,7 +5622,20 @@
 #if H_3D_NBDV_REF
     TComPic* picDepth = NULL;
+#if H_3D_FCO_VSP_DONBDV_E0163
+    picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
+    if ( picDepth->getPicYuvRec() != NULL )  
+    {
+      defaultDV.setZero();
+    }
+    else // Go back with virtual depth
+    {
+      picDepth = getSlice()->getIvPic( true, viewIndex );
+    }
+
+    assert(picDepth != NULL);
+#else
     picDepth = getSlice()->getIvPic( true, viewIndex );
     assert(picDepth!=NULL);
-
+#endif
     if (picDepth && bDepthRefine)
     {
@@ -5717,18 +5645,4 @@
 #endif
   }
-#else
-  pDInfo->m_aVIdxCan = 0;
-#if H_3D_NBDV_REF
-  TComPic* picDepth = NULL;
-  picDepth = getSlice()->getIvPic( true, 0 );
-  assert(picDepth!=NULL);
-
-  if (picDepth && bDepthRefine)
-  {
-    estimateDVFromDM(0, uiPartIdx, picDepth, uiPartAddr, &defaultDV ); // from base view
-  }
-  pDInfo->m_acDoNBDV = defaultDV;
-#endif
-#endif
   return false; 
 }
@@ -5740,15 +5654,8 @@
   Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
   
-#if NTT_DoNBDV_VECTOR_CLIP_E0141
   Int depthStartPosX = Clip3(0,   iPictureWidth - 1,  iBlkX + ((mv->getHor()+2)>>2));
   Int depthStartPosY = Clip3(0,   iPictureHeight - 1, iBlkY + ((mv->getVer()+2)>>2));
   Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
   Int depthEndPosY   = Clip3(0,   iPictureHeight - 1, iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
-#else
-  Int depthStartPosX = Clip3(0,   iPictureWidth - iBlkWidth,  iBlkX + ((mv->getHor()+2)>>2));
-  Int depthStartPosY = Clip3(0,   iPictureHeight- iBlkHeight,  iBlkY + ((mv->getVer()+2)>>2));
-  Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
-  Int depthEndPosY   = Clip3(0,   iPictureHeight - 1,  iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
-#endif
 
   Pel* depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
@@ -5812,7 +5719,19 @@
           TComPic* picDepth = NULL;
           assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());          
+#if H_3D_FCO_VSP_DONBDV_E0163
+          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
+          if ( picDepth->getPicYuvRec() != NULL )  
+          {
+            cMvPred.setZero();
+          }
+          else// Go back with virtual depth
+          {
+            picDepth = getSlice()->getIvPic (true, refViewIdx );
+          }
+          assert(picDepth != NULL);
+#else
           picDepth   = getSlice()->getIvPic (true, refViewIdx );
           assert(picDepth != NULL);
-
+#endif
           UInt uiPartIdx = 0;   //Notes from MTK: Please confirm that using 0 as partition index and partition address is correct for CU-level DoNBDV
           UInt uiPartAddr = 0;  //QC: confirmed
@@ -5829,5 +5748,5 @@
           assert( uiMvpDvPos < IDV_CANDS );
           paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
-          //Notes from QC: DvMCP is implemented in a way that doesnE½t carry the reference view identifier as NBDV. It only works for CTC and needs to be fixed to be aligned with other part of the NBDV design.
+          //Notes from QC: DvMCP is implemented in a way that doesnot carry the reference view identifier as NBDV. It only works for CTC and needs to be fixed to be aligned with other part of the NBDV design.
           paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = cMvPred.getIDVVId();
           paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
@@ -5901,9 +5820,6 @@
 }
 #endif
-#if MTK_NBDV_TN_FIX_E0172
+
 Bool TComDataCU::xGetColDisMV( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
-#else
-Bool TComDataCU::xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
-#endif
 {
 
@@ -5921,5 +5837,5 @@
     if(pColCU->getSlice()->isInterB())
     {
-        eColRefPicList = RefPicList(ilist);
+      eColRefPicList = RefPicList(ilist);
     }
 
@@ -5939,16 +5855,12 @@
     else 
     {
-#if MTK_NBDV_TN_FIX_E0172
       if(getPic()->isTempIVRefValid(currCandPic, ilist,  iColRefIdx))
       {
-#endif
-      rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
-      rcMv.setIDVFlag(0);
-      iTargetViewIdx  = iColRefViewIdx ;
-      iStartViewIdx   = iColViewIdx   ;
-      return true;    
-#if MTK_NBDV_TN_FIX_E0172
-      }
-#endif
+        rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
+        rcMv.setIDVFlag(0);
+        iTargetViewIdx  = iColRefViewIdx ;
+        iStartViewIdx   = iColViewIdx   ;
+        return true;    
+      }
     }
   }
@@ -5957,5 +5869,5 @@
 }
 #endif 
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
 Void 
 TComDataCU::getIVNStatus       ( UInt uiPartIdx,  DisInfo* pDInfo, Bool& bIVFMerge, Int& iIVFMaxD)
@@ -6242,11 +6154,4 @@
   for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
 }
-#if !SEC_DMM2_E0146_HHIFIX
-Void  TComDataCU::setDmm2DeltaEndSubParts( Int iDelta, UInt uiAbsPartIdx, UInt uiDepth )
-{
-  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
-  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm2DeltaEnd[uiAbsPartIdx+ui] = iDelta; }
-}
-#endif
 Void  TComDataCU::setDmm3IntraTabIdxSubParts( UInt uiTIdx, UInt uiAbsPartIdx, UInt uiDepth )
 {
Index: trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 655)
@@ -208,7 +208,4 @@
 #if H_3D_DIM_DMM
   UInt*         m_dmmWedgeTabIdx[DMM_NUM_TYPE]; 
-#if !SEC_DMM2_E0146_HHIFIX
-  Int*          m_dmm2DeltaEnd;
-#endif
   UInt*         m_dmm3IntraTabIdx;
 #endif
@@ -225,5 +222,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Bool*         m_pbInterSDCFlag;
   Int*          m_apSegmentInterDCOffset[4];
@@ -489,9 +486,5 @@
 #endif
   );
-#if MTK_NBDV_TN_FIX_E0172
   Bool          xGetColDisMV      ( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int & iTargetViewIdx, Int & iStartViewIdx );
-#else
-  Bool          xGetColDisMV      ( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int & iTargetViewIdx, Int & iStartViewIdx );
-#endif
   Bool          getDisMvpCandNBDV ( DisInfo* pDInfo
 #if H_3D_NBDV_REF
@@ -505,5 +498,5 @@
 #endif //H_3D_NBDV_REF
 #endif
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
   Void          getIVNStatus       ( UInt uiPartIdx,  DisInfo* pDInfo, Bool& bIVFMerge,  Int& iIVFMaxD);
 #endif
@@ -545,11 +538,4 @@
   Void  setDmmWedgeTabIdxSubParts     ( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth );
 
-#if !SEC_DMM2_E0146_HHIFIX
-  Int*  getDmm2DeltaEnd               ()                      { return m_dmm2DeltaEnd;        }
-  Int   getDmm2DeltaEnd               ( UInt uiIdx )          { return m_dmm2DeltaEnd[uiIdx]; }
-  Void  setDmm2DeltaEnd               ( UInt uiIdx, Int iD )  { m_dmm2DeltaEnd[uiIdx] = iD;   }
-  Void  setDmm2DeltaEndSubParts       ( Int iDelta, UInt uiAbsPartIdx, UInt uiDepth );
-#endif
-
   UInt* getDmm3IntraTabIdx            ()                      { return m_dmm3IntraTabIdx;        }
   UInt  getDmm3IntraTabIdx            ( UInt uiIdx )          { return m_dmm3IntraTabIdx[uiIdx]; }
@@ -588,5 +574,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Bool*         getInterSDCFlag     ()                        { return m_pbInterSDCFlag;               }
   Bool          getInterSDCFlag     ( UInt uiIdx )            { return m_pbInterSDCFlag[uiIdx];        }
@@ -626,6 +612,6 @@
   Void          getMvPredAbove        ( TComMv&     rcMvPred )   { rcMvPred = m_cMvFieldB.getMv(); }
   Void          getMvPredAboveRight   ( TComMv&     rcMvPred )   { rcMvPred = m_cMvFieldC.getMv(); }
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
-  Void          compressMV            (int scale);
+#if H_3D
+  Void          compressMV            ( Int scale );
 #else            
   Void          compressMV            ();
Index: trunk/source/Lib/TLibCommon/TComMv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMv.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComMv.h	(revision 655)
@@ -40,4 +40,5 @@
 
 #include "CommonDef.h"
+#include <cstdlib>
 
 //! \ingroup TLibCommon
Index: trunk/source/Lib/TLibCommon/TComPattern.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPattern.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComPattern.h	(revision 655)
@@ -102,5 +102,5 @@
   Bool              m_bICFlag;
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Bool              m_bSDCMRSADFlag;
 #endif
@@ -119,5 +119,5 @@
   Void  setICFlag( Bool bICFlag ) { m_bICFlag = bICFlag; }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Bool  getSDCMRSADFlag()         { return m_bSDCMRSADFlag; }
   Void  setSDCMRSADFlag( Bool bSDCMRSADFlag )    { m_bSDCMRSADFlag = bSDCMRSADFlag; }
Index: trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 655)
@@ -50,5 +50,4 @@
 , m_bUsedByCurr                           (false)
 , m_bIsLongTerm                           (false)
-, m_bIsUsedAsLongTerm                     (false)
 , m_apcPicSym                             (NULL)
 , m_pcPicYuvPred                          (NULL)
@@ -118,4 +117,15 @@
   memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
 
+  /* initialize the texture to depth reference status */
+#if H_3D_FCO
+  for (int j=0; j<2; j++)
+  {
+      for (int i=0; i<MAX_NUM_REF; i++)
+      {
+          m_aiTexToDepRef[j][i] = -1;
+      }
+  }
+#endif
+
   return;
 }
@@ -146,6 +156,6 @@
   deleteSEIs(m_SEIs);
 }
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
-Void TComPic::compressMotion(int scale)
+#if H_3D
+Void TComPic::compressMotion(Int scale)
 #else
 Void TComPic::compressMotion()
@@ -156,5 +166,5 @@
   {
     TComDataCU* pcCU = pPicSym->getCU(uiCUAddr);
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
+#if H_3D
     pcCU->compressMV(scale); 
 #else
@@ -661,6 +671,5 @@
   return numDdvCandPics;
 }
-#endif
-#if MTK_NBDV_TN_FIX_E0172
+
 Void TComPic::checkTemporalIVRef()
 {
@@ -716,10 +725,14 @@
   return m_abTIVRINCurrRL[currCandPic][iColRefDir][iColRefIdx];
 }
-#endif
-#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
+
 Void TComPic::checkTextureRef(  )
 {
   TComSlice* pcCurrSlice = getSlice(getCurrSliceIdx());
   TComPic* pcTextPic = pcCurrSlice->getTexturePic();
+#if H_3D_FCO
+  if ( pcTextPic )
+  {
+#endif
+
   TComSlice* pcTextSlice = pcTextPic->getSlice(0); // currently only support single slice
 
@@ -743,4 +756,8 @@
 
   }
+#if H_3D_FCO
+  }
+#endif
+
 }
 
Index: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 655)
@@ -61,5 +61,4 @@
   Bool                  m_bUsedByCurr;            //  Used by current picture
   Bool                  m_bIsLongTerm;            //  IS long term picture
-  Bool                  m_bIsUsedAsLongTerm;      //  long term picture is used as reference before
   TComPicSym*           m_apcPicSym;              //  Symbol
   
@@ -83,4 +82,7 @@
   Window                m_defaultDisplayWindow;
 
+  bool                  m_isTop;
+  bool                  m_isField;
+  
   std::vector<std::vector<TComDataCU*> > m_vSliceCUDataLink;
 
@@ -104,9 +106,5 @@
   RefPicList  m_eRapRefList;
   Int         m_iNumDdvCandPics;
-#endif
-#if MTK_NBDV_TN_FIX_E0172 
   Bool        m_abTIVRINCurrRL  [2][2][MAX_NUM_REF]; //whether an inter-view reference picture with the same view index of the inter-view reference picture of temporal reference picture of current picture exists in current reference picture lists
-#endif
-#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182  
   Int         m_aiTexToDepRef  [2][MAX_NUM_REF];
 #endif
@@ -186,6 +184,6 @@
   Void          setNumReorderPics(Int i, UInt tlayer) { m_numReorderPics[tlayer] = i;    }
   Int           getNumReorderPics(UInt tlayer)        { return m_numReorderPics[tlayer]; }
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
-  Void          compressMotion(int scale); 
+#if H_3D
+  Void          compressMotion(Int scale); 
 #else   
   Void          compressMotion(); 
@@ -212,4 +210,12 @@
   TComPicYuv*   getYuvPicBufferForIndependentBoundaryProcessing()             {return m_pNDBFilterYuvTmp;}
   std::vector<TComDataCU*>& getOneSliceCUDataForNDBFilter      (Int sliceID) { return m_vSliceCUDataLink[sliceID];}
+
+
+  /* field coding parameters*/
+
+   Void              setTopField(bool b)                  {m_isTop = b;}
+   bool              isTopField()                         {return m_isTop;}
+   Void              setField(bool b)                     {m_isField = b;}
+   bool              isField()                            {return m_isField;}
 
 #if H_MV
@@ -224,12 +230,8 @@
   UInt          getRapRefIdx()                         {return m_uiRapRefIdx;       }
   RefPicList    getRapRefList()                        {return m_eRapRefList;       }
-#endif
-#if MTK_NBDV_TN_FIX_E0172
-  Void      checkTemporalIVRef();
-  Bool      isTempIVRefValid(Int currCandPic, Int iTempRefDir, Int iTempRefIdx);
-#endif
-#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
-  Void      checkTextureRef(  );
-  Int       isTextRefValid(Int iTextRefDir, Int iTextRefIdx);
+  Void          checkTemporalIVRef();
+  Bool          isTempIVRefValid(Int currCandPic, Int iTempRefDir, Int iTempRefIdx);
+  Void          checkTextureRef(  );
+  Int           isTextRefValid(Int iTextRefDir, Int iTextRefIdx);
 #endif
   /** transfer ownership of seis to this picture */
Index: trunk/source/Lib/TLibCommon/TComPicSym.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicSym.cpp	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComPicSym.cpp	(revision 655)
@@ -61,5 +61,4 @@
 ,m_uiNumAllocatedSlice (0)
 ,m_apcTComDataCU (NULL)
-,m_iTileBoundaryIndependenceIdr (0)
 ,m_iNumColumnsMinus1 (0)
 ,m_iNumRowsMinus1(0)
Index: trunk/source/Lib/TLibCommon/TComPicSym.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 655)
@@ -99,6 +99,5 @@
   UInt          m_uiNumAllocatedSlice;
   TComDataCU**  m_apcTComDataCU;        ///< array of CU data
-  
-  Int           m_iTileBoundaryIndependenceIdr;
+    
   Int           m_iNumColumnsMinus1; 
   Int           m_iNumRowsMinus1;
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 655)
@@ -39,10 +39,4 @@
 #include "TComPrediction.h"
 
-#if SHARP_ILLUCOMP_REFINE_E0046
-#define IC_REG_COST_SHIFT 7
-#define IC_CONST_SHIFT 5
-#define IC_SHIFT_DIFF 12
-#endif
-
 //! \ingroup TLibCommon
 //! \{
@@ -69,7 +63,5 @@
   if (m_pDepthBlock != NULL)
       free(m_pDepthBlock);
-#if NTT_VSP_COMMON_E0207_E0208
   m_cYuvDepthOnVsp.destroy();
-#endif
 #endif
 
@@ -129,5 +121,5 @@
     m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
 #endif
-#if NTT_VSP_COMMON_E0207_E0208
+#if H_3D_VSP
     m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
 #endif
@@ -143,5 +135,4 @@
   }
 #if H_3D_IC
-#if SHARP_ILLUCOMP_REFINE_E0046
   m_uiaShift[0] = 0;
   for( Int i = 1; i < 64; i++ )
@@ -149,10 +140,4 @@
     m_uiaShift[i] = ( (1 << 15) + i/2 ) / i;
   }
-#else
-  for( Int i = 1; i < 64; i++ )
-  {
-    m_uiaShift[i-1] = ( (1 << 15) + i/2 ) / i;
-  }
-#endif
 #endif
 }
@@ -456,17 +441,4 @@
         dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
       } break;
-#if !SEC_DMM2_E0146_HHIFIX
-    case( DMM2_IDX ):
-      {
-        UInt uiTabIdx = 0;
-        if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); }
-        else
-        {
-          uiTabIdx = xPredWedgeFromIntra( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm2DeltaEnd( uiAbsPartIdx ) );
-          pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) );
-        }
-        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]);
-      } break;
-#endif
     case( DMM3_IDX ): 
       {
@@ -709,7 +681,5 @@
 #endif
       , bICFlag );
-#if SHARP_ILLUCOMP_REFINE_E0046
     bICFlag = bICFlag && (iWidth > 8);
-#endif
     xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
 #if H_3D_ARP
@@ -731,5 +701,19 @@
   // Get depth reference
   Int       depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
+#if H_3D_FCO_VSP_DONBDV_E0163
+  TComPic* pRefPicBaseDepth = 0;
+  Bool     bIsCurrDepthCoded = false;
+  pRefPicBaseDepth  = pcCU->getSlice()->getIvPic( true, pcCU->getSlice()->getViewIndex() );
+  if ( pRefPicBaseDepth->getPicYuvRec() != NULL  ) 
+  {
+    bIsCurrDepthCoded = true;
+  }
+  else 
+  {
+    pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
+  }
+#else
   TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
+#endif
   assert(pRefPicBaseDepth != NULL);
   TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
@@ -752,21 +736,16 @@
   pcCU->clipMv(cDv);
 
-#if NTT_VSP_COMMON_E0207_E0208
+#if H_3D_FCO_VSP_DONBDV_E0163
+  if ( bIsCurrDepthCoded )
+  {
+      cDv.setZero();
+  }
+#endif
   // fetch virtual depth map
-#if NTT_VSP_VECTOR_CLIP_E0208
   pcBaseViewDepthPicYuv->extendPicBorder();
-#endif
   xGetVirtualDepth( pcCU, pcBaseViewDepthPicYuv, &cDv, uiPartAddr, iWidth, iHeight, &m_cYuvDepthOnVsp );
   // sub-PU based compensation
   xPredInterLumaBlkFromDM   ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
   xPredInterChromaBlkFromDM ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
-#else
-  UInt uiAbsPartIdx = pcCU->getZorderIdxInCU();
-  Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
-  Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
-  xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
-  xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
-#endif
-
 }
 #endif
@@ -984,5 +963,5 @@
   if ( yFrac == 0 )
   {
-#if MTK_CLIPPING_ALIGN_IC_E0168
+#if H_3D_IC
     m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi || bICFlag
 #else
@@ -996,5 +975,5 @@
   else if ( xFrac == 0 )
   {
-#if MTK_CLIPPING_ALIGN_IC_E0168
+#if H_3D_IC
     m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag
 #else
@@ -1019,5 +998,5 @@
 #endif 
       );
-#if MTK_CLIPPING_ALIGN_IC_E0168
+#if H_3D_IC
     m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
 #else
@@ -1033,14 +1012,8 @@
   if( bICFlag )
   {
-#if SHARP_ILLUCOMP_REFINE_E0046
     Int a, b, i, j;
     const Int iShift = IC_CONST_SHIFT;
 
     xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
-#else
-    Int a, b, iShift, i, j;
-
-    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_LUMA );
-#endif
 
 
@@ -1049,17 +1022,9 @@
       for ( j = 0; j < width; j++ )
       {
-#if !MTK_CLIPPING_ALIGN_IC_E0168
-        if( bi )
-        {
-          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthY;
-          dst[j] = ( ( a*dst[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1 << iIFshift ) - IF_INTERNAL_OFFS;
-        }
-        else
-#endif
           dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
       }
       dst += dstStride;
     }
-#if MTK_CLIPPING_ALIGN_IC_E0168
+
     if(bi)
     {
@@ -1076,5 +1041,4 @@
       }
     }
-#endif
   }
 #endif
@@ -1127,5 +1091,5 @@
   if ( yFrac == 0 )
   {
-#if MTK_CLIPPING_ALIGN_IC_E0168
+#if H_3D_IC
     m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
 #else
@@ -1136,5 +1100,5 @@
 #endif
     );    
-#if MTK_CLIPPING_ALIGN_IC_E0168
+#if H_3D_IC
     m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
 #else
@@ -1148,5 +1112,5 @@
   else if ( xFrac == 0 )
   {
-#if MTK_CLIPPING_ALIGN_IC_E0168
+#if H_3D_IC
     m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
 #else
@@ -1157,5 +1121,5 @@
 #endif
     );
-#if MTK_CLIPPING_ALIGN_IC_E0168
+#if H_3D_IC
     m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
 #else
@@ -1174,5 +1138,5 @@
 #endif  
       );
-#if MTK_CLIPPING_ALIGN_IC_E0168
+#if H_3D_IC
     m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
 #else
@@ -1189,5 +1153,5 @@
 #endif 
       );
-#if MTK_CLIPPING_ALIGN_IC_E0168
+#if H_3D_IC
     m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
 #else
@@ -1203,50 +1167,25 @@
   if( bICFlag )
   {
-#if SHARP_ILLUCOMP_REFINE_E0046
     Int a, b, i, j;
     const Int iShift = IC_CONST_SHIFT;
     xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb
-#else
-    Int a, b, iShift, i, j;
-    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_U ); // Cb
-#endif
     for ( i = 0; i < cxHeight; i++ )
     {
       for ( j = 0; j < cxWidth; j++ )
       {
-#if !MTK_CLIPPING_ALIGN_IC_E0168
-        if( bi )
-        {
-          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC;
-          dstCb[j] = ( ( a*dstCb[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS;
-        }
-        else
-#endif
           dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
       }
       dstCb += dstStride;
     }
-#if SHARP_ILLUCOMP_REFINE_E0046
     xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
-#else
-    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_V ); // Cr
-#endif
     for ( i = 0; i < cxHeight; i++ )
     {
       for ( j = 0; j < cxWidth; j++ )
       {
-#if !MTK_CLIPPING_ALIGN_IC_E0168
-        if( bi )
-        {
-          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC;
-          dstCr[j] = ( ( a*dstCr[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS;
-        }
-        else
-#endif
           dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
       }
       dstCr += dstStride;
     }
-#if MTK_CLIPPING_ALIGN_IC_E0168
+
     if(bi)
     {
@@ -1268,5 +1207,4 @@
       }
     }
-#endif
   }
 #endif
@@ -1323,5 +1261,5 @@
   Int k, l, bottomLeft, topRight;
   Int horPred;
-  Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
+  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
   UInt blkSize = width;
   UInt offset2D = width;
@@ -1417,55 +1355,8 @@
 }
 
-#if !SHARP_ILLUCOMP_REFINE_E0046
-/** Function for counting leading number of zeros/ones
- * \param x input value
- \ This function counts leading number of zeros for positive numbers and
- \ leading number of ones for negative numbers. This can be implemented in
- \ single instructure cycle on many processors.
- */
-
-Short CountLeadingZerosOnes (Short x)
-{
-  Short clz;
-  Short i;
-
-  if(x == 0)
-  {
-    clz = 0;
-  }
-  else
-  {
-    if (x == -1)
-    {
-      clz = 15;
-    }
-    else
-    {
-      if(x < 0)
-      {
-        x = ~x;
-      }
-      clz = 15;
-      for(i = 0;i < 15;++i)
-      {
-        if(x) 
-        {
-          clz --;
-        }
-        x = x >> 1;
-      }
-    }
-  }
-  return clz;
-}
-#endif
 
 /** Function for deriving LM illumination compensation.
  */
-#if SHARP_ILLUCOMP_REFINE_E0046
 Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
-#else
-Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift, TextType eType )
-#endif
 {
   TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
@@ -1495,7 +1386,5 @@
 
   Int x = 0, y = 0, xx = 0, xy = 0;
-#if SHARP_ILLUCOMP_REFINE_E0046
   Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
-#endif
 
   if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
@@ -1519,25 +1408,12 @@
     }
 
-#if SHARP_ILLUCOMP_REFINE_E0046
     for( j = 0; j < uiWidth; j+=2 )
-#else
-    for( j = 0; j < uiWidth; j++ )
-#endif
     {
       x += pRef[j];
       y += pRec[j];
-#if SHARP_ILLUCOMP_REFINE_E0046
       xx += (pRef[j] * pRef[j])>>precShift;
       xy += (pRef[j] * pRec[j])>>precShift;
-#else
-      xx += pRef[j] * pRef[j];
-      xy += pRef[j] * pRec[j];
-#endif
-    }
-#if SHARP_ILLUCOMP_REFINE_E0046
+    }
     iCountShift += g_aucConvertToBit[ uiWidth ] + 1;
-#else
-    iCountShift += g_aucConvertToBit[ uiWidth ] + 2;
-#endif
   }
 
@@ -1563,13 +1439,9 @@
     }
 
-#if SHARP_ILLUCOMP_REFINE_E0046
     for( i = 0; i < uiHeight; i+=2 )
-#else
-    for( i = 0; i < uiHeight; i++ )
-#endif
     {
       x += pRef[0];
       y += pRec[0];
-#if SHARP_ILLUCOMP_REFINE_E0046
+
       xx += (pRef[0] * pRef[0])>>precShift;
       xy += (pRef[0] * pRec[0])>>precShift;
@@ -1577,20 +1449,8 @@
       pRef += iRefStride*2;
       pRec += iRecStride*2;
-#else
-      xx += pRef[0] * pRef[0];
-      xy += pRef[0] * pRec[0];
-
-      pRef += iRefStride;
-      pRec += iRecStride;
-#endif
-    }
-#if SHARP_ILLUCOMP_REFINE_E0046
+    }
     iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 );
-#else
-    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 );
-#endif
-  }
-
-#if SHARP_ILLUCOMP_REFINE_E0046
+  }
+
   xy += xx >> IC_REG_COST_SHIFT;
   xx += xx >> IC_REG_COST_SHIFT;
@@ -1599,34 +1459,6 @@
   const Int iShift = IC_CONST_SHIFT;
   {
-#else
-  Int iTempShift = ( ( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC ) + g_aucConvertToBit[ uiWidth ] + 3 - 15;
-
-  if( iTempShift > 0 )
-  {
-    x  = ( x +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
-    y  = ( y +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
-    xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
-    xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
-    iCountShift -= iTempShift;
-  }
-
-  iShift = 13;
-
-  if( iCountShift == 0 )
-  {
-    a = 1;
-    b = 0;
-    iShift = 0;
-  }
-  else
-  {
-    Int a1 = ( xy << iCountShift ) - y * x;
-    Int a2 = ( xx << iCountShift ) - x * x;              
-#endif
     {
       const Int iShiftA2 = 6;
-#if !SHARP_ILLUCOMP_REFINE_E0046
-      const Int iShiftA1 = 15;
-#endif
       const Int iAccuracyShift = 15;
 
@@ -1636,12 +1468,7 @@
       Int a2s = a2;
 
-#if SHARP_ILLUCOMP_REFINE_E0046
       a1 = Clip3(0, 2*a2, a1);
       iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
       iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
-#else
-      iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1;
-      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;  
-#endif
 
       if( iScaleShiftA1 < 0 )
@@ -1662,41 +1489,6 @@
       a1s = a1 >> iScaleShiftA1;
 
-#if SHARP_ILLUCOMP_REFINE_E0046
       a = a1s * m_uiaShift[ a2s ];
       a = a >> iScaleShiftA;
-#else
-      if (a2s >= 1)
-      {
-        a = a1s * m_uiaShift[ a2s - 1];
-      }
-      else
-      {
-        a = 0;
-      }
-
-      if( iScaleShiftA < 0 )
-      {
-        a = a << -iScaleShiftA;
-      }
-      else
-      {
-        a = a >> iScaleShiftA;
-      }
-
-      a = Clip3( -( 1 << 15 ), ( 1 << 15 ) - 1, a ); 
-
-      Int minA = -(1 << (6));
-      Int maxA = (1 << 6) - 1;
-      if( a <= maxA && a >= minA )
-      {
-        // do nothing
-      }
-      else
-      {
-        Short n = CountLeadingZerosOnes( a );
-        a = a >> (9-n);
-        iShift -= (9-n);
-      }
-#endif
       b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
     }
@@ -1706,6 +1498,4 @@
 
 #if H_3D_VSP
-
-#if NTT_VSP_COMMON_E0207_E0208
 // not fully support iRatioTxtPerDepth* != 1
 Void TComPrediction::xGetVirtualDepth( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *mv, UInt partAddr, Int width, Int height, TComYuv *yuvDepth, Int ratioTxtPerDepthX, Int ratioTxtPerDepthY )
@@ -1715,6 +1505,4 @@
 
   Int refDepStride = picRefDepth->getStride();
-
-#if NTT_VSP_VECTOR_CLIP_E0208
 
   Int refDepOffset  = ( (mv->getHor()+2) >> 2 ) + ( (mv->getVer()+2) >> 2 ) * refDepStride;
@@ -1736,24 +1524,6 @@
   refDepth += refDepOffset;
 
-#else // NTT_VSP_VECTOR_CLIP_E0208
-
-  Int widthDepth = picRefDepth->getWidth();
-  Int heightDepth = picRefDepth->getHeight();
-  Int posX, posY;
-  cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
-  posX /= ratioTxtPerDepthX; // texture position -> depth postion
-  posY /= ratioTxtPerDepthY;
-  
-  posX = Clip3(0, widthDepth-width,   posX + ((mv->getHor()+2)>>2));
-  posY = Clip3(0, heightDepth-height, posY + ((mv->getVer()+2)>>2));
-  
-  Pel *refDepth  = picRefDepth->getLumaAddr() + posX + posY * refDepStride;
-
-#endif // NTT_VSP_VECTOR_CLIP_E0208
-
   Int depStride = yuvDepth->getStride();
   Pel *depth = yuvDepth->getLumaAddr();
-
-#if NTT_VSP_ADAPTIVE_SPLIT_E0207
 
   if( width<8 || height<8 )
@@ -1894,36 +1664,5 @@
   }
 
-#else // NTT_VSP_ADAPTIVE_SPLIT_E0207
-
-  Int rightOffset = nTxtPerDepthX - 1;
-  Int depStrideBlock = depStride * nTxtPerDepthY;
-  Int refDepStrideBlock = refDepStride * nTxtPerDepthY;
-  Pel *refDepthTop = refDepth;
-  Pel *refDepthBot = refDepthTop + (nTxtPerDepthY-1)*refDepStride;
-
-  for( Int y=0; y<height; y+= nTxtPerDepthY )
-  {
-    for( Int x=0; x<width; x+=nTxtPerDepthX )
-    {
-      Pel maxDepth = refDepthTop[x] > refDepthBot[x] ? refDepthTop[x] : refDepthBot[x]; 
-
-      if( maxDepth < refDepthTop[x+rightOffset] )
-      {
-        maxDepth = refDepthTop[x+rightOffset];
-      }
-      if( maxDepth < refDepthBot[x+rightOffset] )
-      {
-        maxDepth = refDepthBot[x+rightOffset];
-      }
-
-      depth[x] = maxDepth;
-
-    }
-    refDepthTop += refDepStrideBlock;
-    refDepthBot += refDepStrideBlock;
-    depth       += depStrideBlock;
-  }
-
-#endif // NTT_VSP_ADAPTIVE_SPLIT_E0207
+
 }
 
@@ -1943,10 +1682,4 @@
   Pel *dst    = yuvDst->getLumaAddr(partAddr);
   Pel *depth  = yuvDepth->getLumaAddr();
-  
-#if !(NTT_VSP_DC_BUGFIX_E0208)
-  Int widthLuma = picRef->getWidth();
-  Int posX, posY;
-  cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
-#endif
 
 #if H_3D_VSP_BLOCKSIZE == 1
@@ -2021,6 +1754,4 @@
       Int xFrac = disparity & 0x3;
 
-#if NTT_VSP_DC_BUGFIX_E0208
-
       dv.setHor( disparity );
       cu->clipMv( dv );
@@ -2038,36 +1769,4 @@
       assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
       m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
-
-#else // NTT_VSP_DC_BUGFIX_E0208
-
-      for( Int j=0; j < nTxtPerDepthX; j++ )
-      {
-        Int refOffset = xTxt+j + (disparity >> 2);
-#if H_3D_VSP_CONSTRAINED
-        if(refOffset<minRelativePos || refOffset>maxRelativePos)
-        {
-          xFrac = 0;
-        }
-        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
-#endif
-        Int absX  = posX + refOffset;
-
-        if (xFrac == 0)
-        {
-          absX = Clip3(0, widthLuma-1, absX);
-        }
-        else
-        {
-          absX = Clip3(4, widthLuma-5, absX);
-        }
-
-        refOffset = absX - posX;
-        assert( ref[refOffset] >= 0 && ref[refOffset] <= 255 );
-        
-        m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !isBi );
-      }
-
-#endif // NTT_VSP_DC_BUGFIX_E0208
-
     }
     ref   += refStrideBlock;
@@ -2101,12 +1800,4 @@
   Pel *depth  = yuvDepth->getLumaAddr();
 
-#if !(NTT_VSP_DC_BUGFIX_E0208)
-  Int widthChroma = picRef->getWidth() >> 1;
-  Int posX, posY;
-  cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
-  posX >>= 1;
-  posY >>= 1;
-#endif
-  
 #if H_3D_VSP_BLOCKSIZE == 1
 #if H_3D_VSP_CONSTRAINED
@@ -2173,6 +1864,4 @@
       Int xFrac = disparity & 0x7;
       
-#if NTT_VSP_DC_BUGFIX_E0208
-
       dv.setHor( disparity );
       cu->clipMv( dv );
@@ -2193,37 +1882,4 @@
       m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
       m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
-
-#else // NTT_VSP_DC_BUGFIX_E0208
-      
-      for( Int j=0; j < nTxtPerDepthX; j++ )
-      {
-        Int refOffset = xTxt+j + (disparity >> 3);
-#if H_3D_VSP_CONSTRAINED
-        if(refOffset<minRelativePos || refOffset>maxRelativePos)
-        {
-          xFrac = 0;
-        }
-        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
-#endif
-        Int absX  = posX + refOffset;
-
-        if (xFrac == 0)
-        {
-          absX = Clip3(0, widthChroma-1, absX);
-        }
-        else
-        {
-          absX = Clip3(4, widthChroma-5, absX);
-        }
-
-        refOffset = absX - posX;
-        assert( refCb[refOffset] >= 0 && refCb[refOffset] <= 255 );
-        assert( refCr[refOffset] >= 0 && refCr[refOffset] <= 255 );
-
-        m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !isBi );
-        m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !isBi );
-      }
-
-#endif // NTT_VSP_DC_BUGFIX_E0208
     }
     refCb += refStrideBlock;
@@ -2233,462 +1889,6 @@
     depth += depStrideBlock;
   }
-
-}
-#else // NTT_VSP_COMMON_E0207_E0208
-
-// Input:
-// refPic: Ref picture. Full picture, with padding
-// posX, posY:     PU position, texture
-// sizeX, sizeY: PU size
-// partAddr: z-order index
-// dv: disparity vector. derived from neighboring blocks
-//
-// Output: dstPic, PU predictor 64x64
-Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr,Int posX, Int posY
-                                            , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi )
-{
-  Int widthLuma;
-  Int heightLuma;
-
-  if (isDepth)
-  {
-    widthLuma   =  pPicBaseDepth->getWidth();
-    heightLuma  =  pPicBaseDepth->getHeight();
-  }
-  else
-  {
-    widthLuma   =  refPic->getWidth();
-    heightLuma  =  refPic->getHeight();
-  }
-
-#if H_3D_VSP_BLOCKSIZE != 1
-  Int widthDepth  = pPicBaseDepth->getWidth();
-  Int heightDepth = pPicBaseDepth->getHeight();
-#endif
-
-#if H_3D_VSP_CONSTRAINED
-  Int widthDepth  = pPicBaseDepth->getWidth();
-  Int heightDepth = pPicBaseDepth->getHeight();
-#endif
-
-  Int nTxtPerDepthX = widthLuma  / ( pPicBaseDepth->getWidth() );  // texture pixel # per depth pixel
-  Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() );
-
-  Int refStride = refPic->getStride();
-  Int dstStride = dstPic->getStride();
-  Int depStride =  pPicBaseDepth->getStride();
-  Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + ((dv->getHor()+2)>>2));
-  Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + ((dv->getVer()+2)>>2));
-  Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
-  Pel *dst    = dstPic->getLumaAddr(partAddr);
-  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;
-
-#if H_3D_VSP_BLOCKSIZE != 1
-#if H_3D_VSP_BLOCKSIZE == 2
-  Int  dW = sizeX>>1;
-  Int  dH = sizeY>>1;
-#endif
-#if H_3D_VSP_BLOCKSIZE == 4
-  Int  dW = sizeX>>2;
-  Int  dH = sizeY>>2;
-#endif
-  {
-    Pel* depthi = depth;
-    for (Int j = 0; j < dH; j++)
-    {
-      for (Int i = 0; i < dW; i++)
-      {
-        Pel* depthTmp;
-#if H_3D_VSP_BLOCKSIZE == 2
-        if (depthPosX + (i<<1) < widthDepth)
-          depthTmp = depthi + (i << 1);
-        else
-          depthTmp = depthi + (widthDepth - depthPosX - 1);
-#endif
-#if H_3D_VSP_BLOCKSIZE == 4
-        if (depthPosX + (i<<2) < widthDepth)
-          depthTmp = depthi + (i << 2);
-        else
-          depthTmp = depthi + (widthDepth - depthPosX - 1);
-#endif
-        Int maxV = 0;
-        for (Int blockj = 0; blockj < H_3D_VSP_BLOCKSIZE; blockj+=(H_3D_VSP_BLOCKSIZE-1))
-        {
-          Int iX = 0;
-          for (Int blocki = 0; blocki < H_3D_VSP_BLOCKSIZE; blocki+=(H_3D_VSP_BLOCKSIZE-1))
-          {
-            if (maxV < depthTmp[iX])
-              maxV = depthTmp[iX];
-#if H_3D_VSP_BLOCKSIZE == 2
-            if (depthPosX + (i<<1) + blocki < widthDepth - 1)
-#else // H_3D_VSP_BLOCKSIZE == 4
-            if (depthPosX + (i<<2) + blocki < widthDepth - 1)
-#endif
-              iX = (H_3D_VSP_BLOCKSIZE-1);
-          }
-#if H_3D_VSP_BLOCKSIZE == 2
-          if (depthPosY + (j<<1) + blockj < heightDepth - 1)
-#else // H_3D_VSP_BLOCKSIZE == 4
-          if (depthPosY + (j<<2) + blockj < heightDepth - 1)
-#endif
-            depthTmp += depStride * (H_3D_VSP_BLOCKSIZE-1);
-        }
-        m_pDepthBlock[i+j*dW] = maxV;
-      } // end of i < dW
-#if H_3D_VSP_BLOCKSIZE == 2
-      if (depthPosY + ((j+1)<<1) < heightDepth)
-        depthi += (depStride << 1);
-      else
-        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
-#endif
-#if H_3D_VSP_BLOCKSIZE == 4
-      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
-        depthi += (depStride << 2);
-      else
-        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
-#endif
-    }
-  }
-#endif // H_3D_VSP_BLOCKSIZE != 1
-
-#if H_3D_VSP_BLOCKSIZE == 1
-#if H_3D_VSP_CONSTRAINED
-  //get LUT based horizontal reference range
-  Int range = xGetConstrainedSize(sizeX, sizeY);
-
-  // The minimum depth value
-  Int minRelativePos = MAX_INT;
-  Int maxRelativePos = MIN_INT;
-
-  Pel* depthTemp, *depthInitial=depth;
-  for (Int yTxt = 0; yTxt < sizeY; yTxt++)
-  {
-    for (Int xTxt = 0; xTxt < sizeX; xTxt++)
-    {
-      if (depthPosX+xTxt < widthDepth)
-        depthTemp = depthInitial + xTxt;
-      else
-        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
-
-      Int disparity = pShiftLUT[ *depthTemp ]; // << iShiftPrec;
-      Int disparityInt = disparity >> 2;
-
-      if( disparity <= 0)
-      {
-        if (minRelativePos > disparityInt+xTxt)
-            minRelativePos = disparityInt+xTxt;
-      }
-      else
-      {
-        if (maxRelativePos < disparityInt+xTxt)
-            maxRelativePos = disparityInt+xTxt;
-      }
-    }
-    if (depthPosY+yTxt < heightDepth)
-      depthInitial = depthInitial + depStride;
-  }
-
-  Int disparity_tmp = pShiftLUT[ *depth ]; // << iShiftPrec;
-  if (disparity_tmp <= 0)
-    maxRelativePos = minRelativePos + range -1 ;
-  else
-    minRelativePos = maxRelativePos - range +1 ;
-#endif
-#endif // H_3D_VSP_BLOCKSIZE == 1
-
-#if H_3D_VSP_BLOCKSIZE != 1
-  Int yDepth = 0;
-#endif
-  for ( Int yTxt = 0; yTxt < sizeY; yTxt += nTxtPerDepthY )
-  {
-    for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth++ )
-    {
-      Pel repDepth = 0; // to store the depth value used for warping
-#if H_3D_VSP_BLOCKSIZE == 1
-      repDepth = depth[xDepth];
-#endif
-#if H_3D_VSP_BLOCKSIZE == 2
-      repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
-#endif
-#if H_3D_VSP_BLOCKSIZE == 4
-      repDepth = m_pDepthBlock[(xTxt>>2) + (yTxt>>2)*dW];
-#endif
-
-      assert( repDepth >= 0 && repDepth <= 255 );
-      Int disparity = pShiftLUT[ repDepth ]; // remove << iShiftPrec ??
-      Int refOffset = xTxt + (disparity >> 2);
-      Int xFrac = disparity & 0x3;
-#if H_3D_VSP_CONSTRAINED
-      if(refOffset<minRelativePos || refOffset>maxRelativePos)
-        xFrac = 0;
-      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
-#endif
-      Int absX  = posX + refOffset;
-
-      if (xFrac == 0)
-        absX = Clip3(0, widthLuma-1, absX);
-      else
-        absX = Clip3(4, widthLuma-5, absX);
-
-      refOffset = absX - posX;
-
-      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
-      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi );
-    }
-    ref   += refStride*nTxtPerDepthY;
-    dst   += dstStride*nTxtPerDepthY;
-    depth += depStride;
-#if H_3D_VSP_BLOCKSIZE != 1
-    yDepth++;
-#endif
-
-  }
-}
-
-Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*dv, UInt partAddr, Int posX, Int posY
-                                               , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi)
-{
-  Int refStride = refPic->getCStride();
-  Int dstStride = dstPic->getCStride();
-  Int depStride = pPicBaseDepth->getStride();
-
-  Int widthChroma, heightChroma;
-  if( isDepth)
-  {
-     widthChroma   = pPicBaseDepth->getWidth()>>1;
-     heightChroma  = pPicBaseDepth->getHeight()>>1;
-  }
-  else
-  {
-     widthChroma   = refPic->getWidth()>>1;
-     heightChroma  = refPic->getHeight()>>1;
-  }
-
-  // Below is only for Texture chroma component
-
-  Int widthDepth  = pPicBaseDepth->getWidth();
-  Int heightDepth = pPicBaseDepth->getHeight();
-
-  Int nTxtPerDepthX, nTxtPerDepthY;  // Number of texture samples per one depth sample
-  Int nDepthPerTxtX, nDepthPerTxtY;  // Number of depth samples per one texture sample
-
-  Int depthPosX;  // Starting position in depth image
-  Int depthPosY;
-
-  if ( widthChroma > widthDepth )
-  {
-    nTxtPerDepthX = widthChroma / widthDepth;
-    nDepthPerTxtX = 1;
-    depthPosX = posX / nTxtPerDepthX + ((dv->getHor()+2)>>2);
-  }
-  else
-  {
-    nTxtPerDepthX = 1;
-    nDepthPerTxtX = widthDepth / widthChroma;
-    depthPosX = posX * nDepthPerTxtX + ((dv->getHor()+2)>>2);
-  }
-  depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX);
-  if ( heightChroma > heightDepth )
-  {
-    nTxtPerDepthY = heightChroma / heightDepth;
-    nDepthPerTxtY = 1;
-    depthPosY = posY / nTxtPerDepthY + ((dv->getVer()+2)>>2);
-  }
-  else
-  {
-    nTxtPerDepthY = 1;
-    nDepthPerTxtY = heightDepth / heightChroma;
-    depthPosY = posY * nDepthPerTxtY + ((dv->getVer()+2)>>2);
-  }
-  depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY);
-
-  Pel *refCb  = refPic->getCbAddr() + posX + posY * refStride;
-  Pel *refCr  = refPic->getCrAddr() + posX + posY * refStride;
-  Pel *dstCb  = dstPic->getCbAddr(partAddr);
-  Pel *dstCr  = dstPic->getCrAddr(partAddr);
-  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;  // move the pointer to the current depth pixel position
-
-  Int refStrideBlock = refStride * nTxtPerDepthY;
-  Int dstStrideBlock = dstStride * nTxtPerDepthY;
-  Int depStrideBlock = depStride * nDepthPerTxtY;
-
-  if ( widthChroma > widthDepth ) // We assume
-  {
-    assert( heightChroma > heightDepth );
-    printf("This branch should never been reached.\n");
-    exit(0);
-  }
-  else
-  {
-#if H_3D_VSP_BLOCKSIZE == 1
-  Int  dW = sizeX;
-  Int  dH = sizeY;
-  Int  sW = 2; // search window size
-  Int  sH = 2;
-#endif
-#if H_3D_VSP_BLOCKSIZE == 2
-  Int  dW = sizeX;
-  Int  dH = sizeY;
-  Int  sW = 2; // search window size
-  Int  sH = 2;
-#endif
-#if H_3D_VSP_BLOCKSIZE == 4
-  Int  dW = sizeX>>1;
-  Int  dH = sizeY>>1;
-  Int  sW = 4; // search window size
-  Int  sH = 4;
-#endif
-
-  {
-    Pel* depthi = depth;
-    for (Int j = 0; j < dH; j++)
-    {
-      for (Int i = 0; i < dW; i++)
-      {
-        Pel* depthTmp;
-#if H_3D_VSP_BLOCKSIZE == 1
-        depthTmp = depthi + (i << 1);
-#endif
-#if H_3D_VSP_BLOCKSIZE == 2
-        if (depthPosX + (i<<1) < widthDepth)
-          depthTmp = depthi + (i << 1);
-        else
-          depthTmp = depthi + (widthDepth - depthPosX - 1);
-#endif
-#if H_3D_VSP_BLOCKSIZE == 4
-        if (depthPosX + (i<<2) < widthDepth)
-          depthTmp = depthi + (i << 2);
-        else
-          depthTmp = depthi + (widthDepth - depthPosX - 1);
-#endif
-        Int maxV = 0;
-        for (Int blockj = 0; blockj < sH; blockj+=(sH-1))
-        {
-          Int iX = 0;
-          for (Int blocki = 0; blocki < sW; blocki+=(sW-1))
-          {
-            if (maxV < depthTmp[iX])
-              maxV = depthTmp[iX];
-            if (depthPosX + i*sW + blocki < widthDepth - 1)
-                iX = (sW-1);
-          }
-          if (depthPosY + j*sH + blockj < heightDepth - 1)
-                depthTmp += depStride * (sH-1);
-        }
-        m_pDepthBlock[i+j*dW] = maxV;
-      } // end of i < dW
-#if H_3D_VSP_BLOCKSIZE == 1
-      if (depthPosY + ((j+1)<<1) < heightDepth)
-        depthi += (depStride << 1);
-      else
-        depthi  = depth + (heightDepth-1)*depStride;
-#endif
-#if H_3D_VSP_BLOCKSIZE == 2
-      if (depthPosY + ((j+1)<<1) < heightDepth)
-        depthi += (depStride << 1);
-      else
-        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
-#endif
-#if H_3D_VSP_BLOCKSIZE == 4
-      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
-        depthi += (depStride << 2);
-      else
-        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
-#endif
-    }
-  }
-
-
-#if H_3D_VSP_BLOCKSIZE == 1
-#if H_3D_VSP_CONSTRAINED
-  //get LUT based horizontal reference range
-  Int range = xGetConstrainedSize(sizeX, sizeY, false);
-
-  // The minimum depth value
-  Int minRelativePos = MAX_INT;
-  Int maxRelativePos = MIN_INT;
-
-  Int depthTmp;
-  for (Int yTxt=0; yTxt<sizeY; yTxt++)
-  {
-    for (Int xTxt=0; xTxt<sizeX; xTxt++)
-    {
-      depthTmp = m_pDepthBlock[xTxt+yTxt*dW];
-      Int disparity = pShiftLUT[ depthTmp ]; // << iShiftPrec;
-      Int disparityInt = disparity >> 3;//in chroma resolution
-
-      if (disparityInt < 0)
-      {
-        if (minRelativePos > disparityInt+xTxt)
-            minRelativePos = disparityInt+xTxt;
-      }
-      else
-      {
-        if (maxRelativePos < disparityInt+xTxt)
-            maxRelativePos = disparityInt+xTxt;
-      }
-    }
-  }
-
-  depthTmp = m_pDepthBlock[0];
-  Int disparity_tmp = pShiftLUT[ depthTmp ]; // << iShiftPrec;
-  if ( disparity_tmp < 0 )
-    maxRelativePos = minRelativePos + range - 1;
-  else
-    minRelativePos = maxRelativePos - range + 1;
-
-#endif // H_3D_VSP_CONSTRAINED
-#endif // H_3D_VSP_BLOCKSIZE == 1
-
-    // (sizeX, sizeY) is Chroma block size
-    for ( Int yTxt = 0, yDepth = 0; yTxt < sizeY; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY )
-    {
-      for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX )
-      {
-        Pel repDepth = 0; // to store the depth value used for warping
-#if H_3D_VSP_BLOCKSIZE == 1
-        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
-#endif
-#if H_3D_VSP_BLOCKSIZE == 2
-        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
-#endif
-#if H_3D_VSP_BLOCKSIZE == 4
-        repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
-#endif
-
-      // calculate the offset in the reference picture
-        Int disparity = pShiftLUT[ repDepth ]; // Remove << iShiftPrec;
-        Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image
-        Int xFrac = disparity & 0x7;
-#if H_3D_VSP_CONSTRAINED
-        if(refOffset < minRelativePos || refOffset > maxRelativePos)
-          xFrac = 0;
-        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
-#endif
-        Int absX  = posX + refOffset;
-
-        if (xFrac == 0)
-          absX = Clip3(0, widthChroma-1, absX);
-        else
-          absX = Clip3(4, widthChroma-5, absX);
-
-        refOffset = absX - posX;
-
-        assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
-        assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
-        m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
-        m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
-      }
-      refCb += refStrideBlock;
-      refCr += refStrideBlock;
-      dstCb += dstStrideBlock;
-      dstCr += dstStrideBlock;
-      depth += depStrideBlock;
-    }
-  }
-
-}
-
-#endif // NTT_VSP_COMMON_E0207_E0208
+}
+
 
 #if H_3D_VSP_CONSTRAINED
@@ -2768,75 +1968,4 @@
 
 #if H_3D_DIM_DMM
-#if !SEC_DMM2_E0146_HHIFIX
-UInt TComPrediction::xPredWedgeFromIntra( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd )
-{
-  UInt uiThisBlockSize = uiWidth;
-
-  TComDataCU* pcTempCU;
-  UInt        uiTempPartIdx;
-  // 1st: try continue above wedgelet
-  pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
-  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
-  {
-    UInt dimType =  getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
-    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
-    {
-      // get offset between current and reference block
-      UInt uiOffsetX = 0, uiOffsetY = 0;
-      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
-
-      // get reference wedgelet
-      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
-      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
-
-      // find wedgelet, if direction is suitable for continue wedge
-      if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) )
-      {
-        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
-        pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd );
-        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
-      }
-    }
-  }
-
-  // 2nd: try continue left wedglelet
-  pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
-  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
-  {
-    UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
-    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
-    {
-      // get offset between current and reference block
-      UInt uiOffsetX = 0, uiOffsetY = 0;
-      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
-
-      // get reference wedgelet
-      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
-      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
-
-      // find wedgelet, if direction is suitable for continue wedge
-      if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) )
-      {
-        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
-        pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd );
-        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
-      }
-    }
-  }
-
-  // 3rd: (default) make wedglet from intra dir and max slope point
-  Int iSlopeX = 0, iSlopeY = 0;
-  UInt uiStartPosX = 0, uiStartPosY = 0;
-  if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) )
-  {
-    UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
-    xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd );
-    return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
-  }
-
-  return 0;
-}
-#endif
-
 UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx )
 {
@@ -2847,11 +1976,6 @@
   Int           uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
 
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
   assert( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 );
   return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx);
-#else
-  if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) { return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx); }
-  else                                                     { return g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])].at(intraTabIdx).getPatternIdx(); }
-#endif
 }
 
@@ -2875,10 +1999,7 @@
   }
 
-#if SCU_HS_DMM4_REMOVE_DIV_E0242
-  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;
-  iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2;
-#else
-  iDC /= (uiWidth*uiHeight);
-#endif
+  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;   // 
+  iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2;        //  iDC /= (uiWidth*uiHeight);
+
   piRefBlkY = cTempYuv.getLumaAddr();
 
@@ -2907,395 +2028,6 @@
   }
 }
-
-#if !SEC_DMM2_E0146_HHIFIX
-Void TComPrediction::xGetBlockOffset( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY )
-{
-  ruiOffsetX = 0;
-  ruiOffsetY = 0;
-
-  // get offset between current and above/left block
-  UInt uiThisOriginX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
-  UInt uiThisOriginY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
-
-  UInt uiNumPartInRefCU = pcRefCU->getTotalNumPart();
-  UInt uiMaxDepthRefCU = 0;
-  while( uiNumPartInRefCU > 1 )
-  {
-    uiNumPartInRefCU >>= 2;
-    uiMaxDepthRefCU++;
-  }
-
-  UInt uiDepthRefPU = (pcRefCU->getDepth(uiRefAbsPartIdx)) + (pcRefCU->getPartitionSize(uiRefAbsPartIdx) == SIZE_2Nx2N ? 0 : 1);
-  UInt uiShifts = (uiMaxDepthRefCU - uiDepthRefPU)*2;
-  UInt uiRefBlockOriginPartIdx = (uiRefAbsPartIdx>>uiShifts)<<uiShifts;
-
-  UInt uiRefOriginX = pcRefCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
-  UInt uiRefOriginY = pcRefCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
-
-  if( (uiThisOriginX - uiRefOriginX) > 0 ) { ruiOffsetX = (UInt)(uiThisOriginX - uiRefOriginX); }
-  if( (uiThisOriginY - uiRefOriginY) > 0 ) { ruiOffsetY = (UInt)(uiThisOriginY - uiRefOriginY); }
-}
-
-Bool TComPrediction::xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY )
-{
-  riSlopeX = 0, riSlopeY = 0, ruiStartPosX = 0, ruiStartPosY = 0;
-
-  // 1st step: get wedge start point (max. slope)
-  Int* piSource = pcCU->getPattern()->getAdiOrgBuf( uiBlockSize, uiBlockSize, m_piYuvExt );
-  Int iSourceStride = ( uiBlockSize<<1 ) + 1;
-
-  UInt uiSlopeMaxAbove = 0, uiPosSlopeMaxAbove = 0;
-  for( UInt uiPosHor = 0; uiPosHor < (uiBlockSize-1); uiPosHor++ )
-  {
-    if( abs( piSource[uiPosHor+1] - piSource[uiPosHor] ) > uiSlopeMaxAbove )
-    {
-      uiSlopeMaxAbove = abs( piSource[uiPosHor+1] - piSource[uiPosHor] );
-      uiPosSlopeMaxAbove = uiPosHor;
-    }
-  }
-
-  UInt uiSlopeMaxLeft = 0, uiPosSlopeMaxLeft = 0;
-  for( UInt uiPosVer = 0; uiPosVer < (uiBlockSize-1); uiPosVer++ )
-  {
-    if( abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ) > uiSlopeMaxLeft )
-    {
-      uiSlopeMaxLeft = abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] );
-      uiPosSlopeMaxLeft = uiPosVer;
-    }
-  }
-
-  if( uiSlopeMaxAbove == 0 && uiSlopeMaxLeft == 0 ) 
-  { 
-    return false; 
-  }
-
-  ruiStartPosX = ( uiSlopeMaxAbove >  uiSlopeMaxLeft  ) ? uiPosSlopeMaxAbove : 0;
-  ruiStartPosY = ( uiSlopeMaxLeft  >= uiSlopeMaxAbove ) ? uiPosSlopeMaxLeft  : 0;
-
-  // 2nd step: derive wedge direction
-  Int uiPreds[3] = {-1, -1, -1};
-  Int iMode = -1;
-  Int iPredNum = pcCU->getIntraDirLumaPredictor( uiAbsPartIdx, uiPreds, &iMode );  
-
-  UInt uiDirMode = 0;
-  if( iMode >= 0 ) { iPredNum = iMode; }
-  if( iPredNum == 1 ) { uiDirMode = uiPreds[0]; }
-  if( iPredNum == 2 ) { uiDirMode = uiPreds[1]; }
-
-  if( uiDirMode < 2 ) { return false; } // no planar & DC
-
-  Bool modeHor       = (uiDirMode < 18);
-  Bool modeVer       = !modeHor;
-  Int intraPredAngle = modeVer ? (Int)uiDirMode - VER_IDX : modeHor ? -((Int)uiDirMode - HOR_IDX) : 0;
-  Int absAng         = abs(intraPredAngle);
-  Int signAng        = intraPredAngle < 0 ? -1 : 1;
-  Int angTable[9]    = {0,2,5,9,13,17,21,26,32};
-  absAng             = angTable[absAng];
-  intraPredAngle     = signAng * absAng;
-
-  // 3rd step: set slope for direction
-  if( modeHor )
-  {
-    riSlopeX = ( intraPredAngle > 0 ) ?            -32 :              32;
-    riSlopeY = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
-  }
-  else if( modeVer )
-  {
-    riSlopeX = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
-    riSlopeY = ( intraPredAngle > 0 ) ?            -32 :              32;
-  }
-
-  return true;
-}
-
-Void TComPrediction::xGetWedgeIntraDirStartEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int iDeltaX, Int iDeltaY, UInt uiPMSPosX, UInt uiPMSPosY, UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, Int iDeltaEnd )
-{
-  ruhXs = 0;
-  ruhYs = 0;
-  ruhXe = 0;
-  ruhYe = 0;
-
-  // scaling of start pos and block size to wedge resolution
-  UInt uiScaledStartPosX = 0;
-  UInt uiScaledStartPosY = 0;
-  UInt uiScaledBlockSize = 0;
-  WedgeResolution eWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiBlockSize]];
-  switch( eWedgeRes )
-  {
-  case( DOUBLE_PEL ): { uiScaledStartPosX = (uiPMSPosX>>1); uiScaledStartPosY = (uiPMSPosY>>1); uiScaledBlockSize = (uiBlockSize>>1); break; }
-  case(   FULL_PEL ): { uiScaledStartPosX =  uiPMSPosX;     uiScaledStartPosY =  uiPMSPosY;     uiScaledBlockSize =  uiBlockSize;     break; }
-  case(   HALF_PEL ): { uiScaledStartPosX = (uiPMSPosX<<1); uiScaledStartPosY = (uiPMSPosY<<1); uiScaledBlockSize = (uiBlockSize<<1); break; }
-  }
-  Int iMaxPos = (Int)uiScaledBlockSize - 1;
-
-  // case above
-  if( uiScaledStartPosX > 0 && uiScaledStartPosY == 0 )
-  {
-    ruhXs = (UChar)uiScaledStartPosX;
-    ruhYs = 0;
-
-    if( iDeltaY == 0 )
-    {
-      if( iDeltaX < 0 )
-      {
-        ruhXe = 0;
-        ruhYe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos );
-        return;
-      }
-      else
-      {
-        ruhXe = (UChar)iMaxPos;
-        ruhYe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos );
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-    }
-
-    // regular case
-    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) );
-
-    if( iVirtualEndX < 0 )
-    {
-      Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) + iDeltaEnd;
-      if( iYe < (Int)uiScaledBlockSize )
-      {
-        ruhXe = 0;
-        ruhYe = (UChar)std::max( iYe, 0 );
-        return;
-      }
-      else
-      {
-        ruhXe = (UChar)std::min( (iYe - iMaxPos), iMaxPos );
-        ruhYe = (UChar)iMaxPos;
-        return;
-      }
-    }
-    else if( iVirtualEndX > iMaxPos )
-    {
-      Int iYe = roftoi( (Double)(iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
-      if( iYe < (Int)uiScaledBlockSize )
-      {
-        ruhXe = (UChar)iMaxPos;
-        ruhYe = (UChar)std::max( iYe, 0 );
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-      else
-      {
-        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
-        ruhYe = (UChar)iMaxPos;
-        return;
-      }
-    }
-    else
-    {
-      Int iXe = iVirtualEndX + iDeltaEnd;
-      if( iXe < 0 )
-      {
-        ruhXe = 0;
-        ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 );
-        return;
-      }
-      else if( iXe > iMaxPos )
-      {
-        ruhXe = (UChar)iMaxPos;
-        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-      else
-      {
-        ruhXe = (UChar)iXe;
-        ruhYe = (UChar)iMaxPos;
-        return;
-      }
-    }
-  }
-
-  // case left
-  if( uiScaledStartPosY > 0 && uiScaledStartPosX == 0 )
-  {
-    ruhXs = 0;
-    ruhYs = (UChar)uiScaledStartPosY;
-
-    if( iDeltaX == 0 )
-    {
-      if( iDeltaY < 0 )
-      {
-        ruhXe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos );
-        ruhYe = 0;
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-      else
-      {
-        ruhXe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos );
-        ruhYe = (UChar)iMaxPos;
-        return; 
-      }
-    }
-
-    // regular case
-    Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iMaxPos * ((Double)iDeltaY / (Double)iDeltaX) );
-
-    if( iVirtualEndY < 0 )
-    {
-      Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) - iDeltaEnd;
-      if( iXe < (Int)uiScaledBlockSize )
-      {
-        ruhXe = (UChar)std::max( iXe, 0 );
-        ruhYe = 0;
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-      else
-      {
-        ruhXe = (UChar)iMaxPos;
-        ruhYe = (UChar)std::min( (iXe - iMaxPos), iMaxPos );
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-    }
-    else if( iVirtualEndY > (uiScaledBlockSize-1) )
-    {
-      Int iXe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) + iDeltaEnd;
-      if( iXe < (Int)uiScaledBlockSize )
-      {
-        ruhXe = (UChar)std::max( iXe, 0 );
-        ruhYe = (UChar)(uiScaledBlockSize-1);
-        return;
-      }
-      else
-      {
-        ruhXe = (UChar)iMaxPos;
-        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-    }
-    else
-    {
-      Int iYe = iVirtualEndY - iDeltaEnd;
-      if( iYe < 0 )
-      {
-        ruhXe = (UChar)std::max( (iMaxPos + iYe), 0 );
-        ruhYe = 0;
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-      else if( iYe > iMaxPos )
-      {
-        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
-        ruhYe = (UChar)iMaxPos;
-        return;
-      }
-      else
-      {
-        ruhXe = (UChar)iMaxPos;
-        ruhYe = (UChar)iYe;
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-    }
-  }
-
-  // case origin
-  if( uiScaledStartPosX == 0 && uiScaledStartPosY == 0 )
-  {
-    if( iDeltaX*iDeltaY < 0 )
-    {
-      return;
-    }
-
-    ruhXs = 0;
-    ruhYs = 0;
-
-    if( iDeltaY == 0 )
-    {
-      ruhXe = (UChar)iMaxPos;
-      ruhYe = 0;
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-
-    if( iDeltaX == 0 )
-    {
-      ruhXe = 0;
-      ruhYe = (UChar)iMaxPos;
-      return;
-    }
-
-    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) );
-
-    if( iVirtualEndX > iMaxPos )
-    {
-      Int iYe = roftoi( (Double)((Int)iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
-      if( iYe < (Int)uiScaledBlockSize )
-      {
-        ruhXe = (UChar)(uiScaledBlockSize-1);
-        ruhYe = (UChar)std::max( iYe, 0 );
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-      else
-      {
-        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
-        ruhYe = (UChar)(uiScaledBlockSize-1);
-        return;
-      }
-    }
-    else
-    {
-      Int iXe = iVirtualEndX + iDeltaEnd;
-      if( iXe < 0 )
-      {
-        ruhXe = 0;
-        ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 );
-        return;
-      }
-      else if( iXe > iMaxPos )
-      {
-        ruhXe = (UChar)(uiScaledBlockSize-1);
-        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-      else
-      {
-        ruhXe = (UChar)iXe;
-        ruhYe = (UChar)(uiScaledBlockSize-1);
-        return;
-      }
-    }
-  }
-}
-
-UInt TComPrediction::xGetWedgePatternIdx( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe )
-{
-  WedgeRefList* pcWedgeRefList = &g_dmmWedgeRefLists[(g_aucConvertToBit[uiBlockSize])];
-  for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ )
-  {
-    TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx));
-    if( pcTestWedgeRef->getStartX() == uhXs && pcTestWedgeRef->getStartY() == uhYs && pcTestWedgeRef->getEndX() == uhXe && pcTestWedgeRef->getEndY() == uhYe )
-    {
-      return pcTestWedgeRef->getRefIdx();
-    }
-  }
-  return 0;
-}
-#endif
-#endif
+#endif
+
 #if H_3D_DIM_RBC
 Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC )
@@ -3327,8 +2059,6 @@
 #if H_3D_DIM_SDC
 Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
-#if KWU_SDC_SIMPLE_DC_E0117
                                          ,UInt uiIntraMode
                                          ,Bool orgDC
-#endif
                                         )
 {
@@ -3338,5 +2068,4 @@
   memset(iSumPix, 0, sizeof(Int)*2);
   
-#if KWU_SDC_SIMPLE_DC_E0117
   if (orgDC == false)
   {
@@ -3364,5 +2093,4 @@
     return;
   }
-#endif
 
   Int subSamplePix;
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 655)
@@ -76,9 +76,5 @@
   Int    m_iLumaRecStride;       ///< stride of #m_pLumaRecBuffer array
 #if H_3D_IC
-#if SHARP_ILLUCOMP_REFINE_E0046
   UInt   m_uiaShift[ 64 ];       // Table for multiplication to substitue of division operation
-#else
-  UInt   m_uiaShift[ 63 ];       // Table for multiplication to substitue of division operation
-#endif
 #endif
 
@@ -88,7 +84,5 @@
   Int  xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma = true);
 #endif
-#if NTT_VSP_COMMON_E0207_E0208
   TComYuv   m_cYuvDepthOnVsp;
-#endif
 #endif
 
@@ -126,12 +120,7 @@
 
 #if H_3D_VSP
-#if NTT_VSP_COMMON_E0207_E0208
   Void xGetVirtualDepth           ( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *dv, UInt partAddr, Int width, Int height, TComYuv *yuvDepth, Int txtPerDepthX=1, Int txtPerDepthY=1 );
   Void xPredInterLumaBlkFromDM    ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&pcYuvDst, Bool isBi );
   Void xPredInterChromaBlkFromDM  ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&pcYuvDst, Bool isBi );
-#else
-  Void xPredInterLumaBlkFromDM  ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr, Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi );
-  Void xPredInterChromaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr, Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi );
-#endif
 #endif
 
@@ -140,9 +129,5 @@
   Void xGetLLSPrediction ( TComPattern* pcPattern, Int* pSrc0, Int iSrcStride, Pel* pDst0, Int iDstStride, UInt uiWidth, UInt uiHeight, UInt uiExt0 );
 #if H_3D_IC
-#if SHARP_ILLUCOMP_REFINE_E0046
   Void xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType );
-#else
-  Void xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift, TextType eType );
-#endif
 #endif
   Void xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight );
@@ -154,18 +139,7 @@
   Void xAssignBiSegDCs          ( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel   valDC1, Pel   valDC2 );
 #if H_3D_DIM_DMM
-#if !SEC_DMM2_E0146_HHIFIX
-  UInt xPredWedgeFromIntra      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd = 0 );
-#endif
   UInt xPredWedgeFromTex        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx );
   Void xPredContourFromTex      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge );
-
   Void xCopyTextureLumaBlock    ( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight );
-
-#if !SEC_DMM2_E0146_HHIFIX
-  Void xGetBlockOffset          ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY );
-  Bool xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY );
-  Void xGetWedgeIntraDirStartEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int iDeltaX, Int iDeltaY, UInt uiPMSPosX, UInt uiPMSPosY, UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, Int iDeltaEnd = 0 );
-  UInt xGetWedgePatternIdx      ( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe );
-#endif
 #endif
 #if H_3D_DIM_RBC
@@ -196,8 +170,6 @@
 #if H_3D_DIM_SDC
   Void analyzeSegmentsSDC         ( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
-#if KWU_SDC_SIMPLE_DC_E0117
                                     ,UInt uiIntraMode 
                                     ,Bool orgDC=false
-#endif
     );
 #endif
Index: trunk/source/Lib/TLibCommon/TComRdCost.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 655)
@@ -484,5 +484,5 @@
 }
 
-#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
+#if H_3D_FAST_DEPTH_INTRA
 
 UInt TComRdCost::calcVAR (Pel* pi0, Int stride, Int width, Int height, Int cuDepth)
@@ -542,5 +542,5 @@
   cDtParam.bUseIC       = false;
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   cDtParam.bUseSDCMRSAD = false;
 #endif
@@ -605,14 +605,10 @@
     dist = (Dist) (iDWeight * distDepth + iVSOWeight * dist ) / ( iDWeight + iVSOWeight);
   }
-#if H_3D_FIX_UINT_WARNING
+
   return (UInt) dist; 
-#else
-  return dist; 
-#endif
-
-}
-#endif
-
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+}
+#endif
+
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
 UInt TComRdCost::getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height )
 {
@@ -652,5 +648,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -692,5 +688,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -735,5 +731,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -782,5 +778,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -838,5 +834,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -886,5 +882,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -944,5 +940,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -1016,5 +1012,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -1081,5 +1077,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -1185,5 +1181,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -1261,5 +1257,5 @@
 #endif
 
-#if H_3D_IC || LGE_INTER_SDC_E0156
+#if H_3D_IC || H_3D_INTER_SDC
 UInt TComRdCost::xGetSADic( DistParam* pcDtParam )
 {
@@ -3513,5 +3509,5 @@
   }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcDtParam->bUseSDCMRSAD )
   {
@@ -3616,5 +3612,5 @@
 }
 
-#if H_3D_IC || LGE_INTER_SDC_E0156
+#if H_3D_IC || H_3D_INTER_SDC
 UInt TComRdCost::xGetHADsic( DistParam* pcDtParam )
 {
Index: trunk/source/Lib/TLibCommon/TComRdCost.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCost.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComRdCost.h	(revision 655)
@@ -94,5 +94,5 @@
   Bool  bUseIC;
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Bool  bUseSDCMRSAD;
 #endif
@@ -136,5 +136,5 @@
     iStrideVir = 0;
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
     bUseSDCMRSAD = false;
 #endif
@@ -148,6 +148,4 @@
 private:
   // for distortion
-  Int                     m_iBlkWidth;
-  Int                     m_iBlkHeight;
   
 #if AMP_SAD
@@ -235,5 +233,5 @@
   UInt    calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
   
-#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
+#if H_3D_FAST_DEPTH_INTRA
   UInt    calcVAR(Pel* pi0, Int stride, Int width, Int height, Int cuDepth);
 #endif  
@@ -283,5 +281,5 @@
   static UInt xGetSSE64         ( DistParam* pcDtParam );
   static UInt xGetSSE16N        ( DistParam* pcDtParam );
-#if H_3D_IC || LGE_INTER_SDC_E0156
+#if H_3D_IC || H_3D_INTER_SDC
   static UInt xGetSADic         ( DistParam* pcDtParam );
   static UInt xGetSAD4ic        ( DistParam* pcDtParam );
@@ -311,5 +309,5 @@
 
 #if AMP_SAD
-#if H_3D_IC || LGE_INTER_SDC_E0156
+#if H_3D_IC || H_3D_INTER_SDC
   static UInt xGetSAD12ic       ( DistParam* pcDtParam );
   static UInt xGetSAD24ic       ( DistParam* pcDtParam );
@@ -322,5 +320,5 @@
 #endif
 
-#if H_3D_IC || LGE_INTER_SDC_E0156
+#if H_3D_IC || H_3D_INTER_SDC
   static UInt xGetHADsic          ( DistParam* pcDtParam );
 #endif
@@ -343,5 +341,5 @@
 #endif
 
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
   UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
 #endif
Index: trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 655)
@@ -55,10 +55,9 @@
   ::memset( g_aucConvertToBit,   -1, sizeof( g_aucConvertToBit ) );
   c=0;
-  for ( i=4; i<MAX_CU_SIZE; i*=2 )
+  for ( i=4; i<=MAX_CU_SIZE; i*=2 )
   {
     g_aucConvertToBit[ i ] = c;
     c++;
   }
-  g_aucConvertToBit[ i ] = c;
   
   c=2;
@@ -292,5 +291,5 @@
 
 #if FAST_UDI_USE_MPM
-const UChar g_aucIntraModeNumFast[7] =
+const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] =
 {
   3,  //   2x2
@@ -299,9 +298,8 @@
   3,  //  16x16   
   3,  //  32x32   
-  3,  //  64x64   
-  3   // 128x128  
+  3   //  64x64   
 };
 #else // FAST_UDI_USE_MPM
-const UChar g_aucIntraModeNumFast[7] =
+const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] =
 {
   3,  //   2x2
@@ -310,6 +308,5 @@
   4,  //  16x16   33
   4,  //  32x32   33
-  5,  //  64x64   33
-  4   // 128x128  33
+  5   //  64x64   33
 };
 #endif // FAST_UDI_USE_MPM
@@ -347,13 +344,8 @@
 { //2x2   4x4   8x8 16x16 32x32 64x64
      0,    7,   10,   11,   11,   13 };
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+
 const UChar g_dmm3IntraTabIdxBits[6] =
 { //2x2   4x4   8x8 16x16 32x32 64x64
      0,    4,    7,    8,    8,    0 };
-#else
-const UChar g_dmm3IntraTabIdxBits[6] =
-{ //2x2   4x4   8x8 16x16 32x32 64x64
-     0,    6,    9,    9,    9,    0 };
-#endif
 
 extern std::vector< std::vector<TComWedgelet> >   g_dmmWedgeLists;
@@ -614,9 +606,5 @@
 std::vector< std::vector< std::vector<UInt> > > g_aauiWdgLstM3;
 
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
 Void initWedgeLists( Bool initNodeList )
-#else
-Void initWedgeLists( Bool initRefinements )
-#endif
 {
   if( !g_dmmWedgeLists.empty() ) return;
@@ -631,21 +619,15 @@
     g_dmmWedgeRefLists.push_back( acWedgeRefList );
 
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
     if( initNodeList )
     {
-#endif
-    // create WedgeNodeList
-    std::vector<TComWedgeNode> acWedgeNodeList;
-    for( UInt uiPos = 0; uiPos < acWedgeList.size(); uiPos++ )
-    {
-      if( acWedgeList[uiPos].getIsCoarse() )
-      {
-        TComWedgeNode cWedgeNode;
-        cWedgeNode.setPatternIdx( uiPos );
-
-#if !LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
-        if( initRefinements )
+      // create WedgeNodeList
+      std::vector<TComWedgeNode> acWedgeNodeList;
+      for( UInt uiPos = 0; uiPos < acWedgeList.size(); uiPos++ )
+      {
+        if( acWedgeList[uiPos].getIsCoarse() )
         {
-#endif
+          TComWedgeNode cWedgeNode;
+          cWedgeNode.setPatternIdx( uiPos );
+
           UInt uiRefPos = 0;
           for( Int iOffS = -1; iOffS <= 1; iOffS++ )
@@ -674,7 +656,7 @@
               {
                 if( iSx == (Int)acWedgeRefList[k].getStartX() && 
-                    iSy == (Int)acWedgeRefList[k].getStartY() && 
-                    iEx == (Int)acWedgeRefList[k].getEndX()   && 
-                    iEy == (Int)acWedgeRefList[k].getEndY()      )
+                  iSy == (Int)acWedgeRefList[k].getStartY() && 
+                  iEx == (Int)acWedgeRefList[k].getEndX()   && 
+                  iEy == (Int)acWedgeRefList[k].getEndY()      )
                 {
                   if( acWedgeRefList[k].getRefIdx() != cWedgeNode.getPatternIdx() )
@@ -694,16 +676,10 @@
             }
           }
-#if !LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+          acWedgeNodeList.push_back( cWedgeNode );
         }
-#endif
-        acWedgeNodeList.push_back( cWedgeNode );
-      }
-    }
-    g_dmmWedgeNodeLists.push_back( acWedgeNodeList );
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
-  }
-#endif
-  }
-  return;
+      }
+      g_dmmWedgeNodeLists.push_back( acWedgeNodeList );
+    }
+  }
 }
 
Index: trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComRom.h	(revision 655)
@@ -56,5 +56,5 @@
 // ====================================================================================================================
 
-#define     MAX_CU_DEPTH            7                           // log2(LCUSize)
+#define     MAX_CU_DEPTH            6                           // log2(LCUSize)
 #define     MAX_CU_SIZE             (1<<(MAX_CU_DEPTH))         // maximum allowable size of CU
 #define     MIN_PU_SIZE             4
@@ -136,5 +136,5 @@
 // ====================================================================================================================
 
-extern const UChar  g_aucIntraModeNumFast[7];
+extern const UChar  g_aucIntraModeNumFast[ MAX_CU_DEPTH ];
 
 // ====================================================================================================================
@@ -174,9 +174,5 @@
 extern       std::vector< std::vector< std::vector<UInt> > > g_aauiWdgLstM3;
 
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
 Void initWedgeLists( Bool initNodeList = false );
-#else
-Void initWedgeLists( Bool initRefinements = false );
-#endif
 Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes );
 Void addWedgeletToList( TComWedgelet cWedgelet, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList );
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 655)
@@ -101,32 +101,16 @@
 , m_enableTMVPFlag                ( true )
 #if H_MV
-#if H_MV5
 , m_refPicSetInterLayer0           ( NULL )
 , m_refPicSetInterLayer1           ( NULL )
-#else
-, m_refPicSetInterLayer           ( NULL )
-#endif
 , m_layerId                       (0)
 , m_viewId                        (0)
-#if H_MV5
 , m_viewIndex                     (0)
-#endif
 #if H_3D
-#if !H_MV5
-, m_viewIndex                     (0)
-#endif
 , m_isDepth                       (false)
 #endif
-#if H_MV5
 , m_pocResetFlag                  (false)
-#endif
 , m_discardableFlag               (false)
 , m_interLayerPredEnabledFlag     (false)
 , m_numInterLayerRefPicsMinus1    (0)
-#if !H_MV5
-, m_interLayerSamplePredOnlyFlag  (false)
-, m_altCollocatedIndicationFlag   (0)
-, m_collocatedRefLayerIdx         (0)
-#endif
 #if H_3D_IC
 , m_bApplyIC                      ( false )
@@ -164,9 +148,5 @@
   for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
   {
-#if H_MV5
    m_interLayerPredLayerIdc[ i ] = i;
-#else
-   m_interLayerPredLayerIdc[ i ] = 0;
-#endif
   }
 #endif
@@ -322,5 +302,5 @@
   if (!pocHasMsb)
   {
-    poc = poc % pocCycle;
+    poc = poc & (pocCycle - 1);
   }
   
@@ -333,5 +313,5 @@
       if (!pocHasMsb)
       {
-        picPoc = picPoc % pocCycle;
+        picPoc = picPoc & (pocCycle - 1);
       }
       
@@ -387,5 +367,4 @@
   }
 }
-#if H_MV5
 #if !H_MV
 #if FIX1071
@@ -472,6 +451,6 @@
   {
     // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
-    //  If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    //  Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // ?If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // ?Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if (getRapPicFlag())
     {
@@ -730,256 +709,20 @@
 }
 #endif
-#else
+Int TComSlice::getNumRpsCurrTempList()
+{
+  Int numRpsCurrTempList = 0;
+
+  if (m_eSliceType == I_SLICE) 
+  {
+    return 0;
+  }
+  for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      numRpsCurrTempList++;
+    }
+  }
 #if H_MV
-Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer , Bool checkNumPocTotalCurr)
-#else
-#if FIX1071
-Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
-#else
-Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
-#endif
-#endif
-{
-#if FIX1071
-  if (!checkNumPocTotalCurr)
-#endif
-  {
-    if (m_eSliceType == I_SLICE)
-    {
-      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
-      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
-      
-      return;
-    }
-    
-#if !H_MV
-    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
-    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
-#endif
-  }
-
-  TComPic*  pcRefPic= NULL;
-  TComPic*  RefPicSetStCurr0[16];
-  TComPic*  RefPicSetStCurr1[16];
-  TComPic*  RefPicSetLtCurr[16];
-  UInt NumPocStCurr0 = 0;
-  UInt NumPocStCurr1 = 0;
-  UInt NumPocLtCurr = 0;
-  Int i;
-
-  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
-  {
-    if(m_pcRPS->getUsed(i))
-    {
-      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
-      pcRefPic->setIsLongTerm(0);
-      pcRefPic->getPicYuvRec()->extendPicBorder();
-      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
-      NumPocStCurr0++;
-      pcRefPic->setCheckLTMSBPresent(false);  
-    }
-  }
-  
-  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
-  {
-    if(m_pcRPS->getUsed(i))
-    {
-      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
-      pcRefPic->setIsLongTerm(0);
-      pcRefPic->getPicYuvRec()->extendPicBorder();
-      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
-      NumPocStCurr1++;
-      pcRefPic->setCheckLTMSBPresent(false);  
-    }
-  }
-  
-  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
-  {
-    if(m_pcRPS->getUsed(i))
-    {
-      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
-      pcRefPic->setIsLongTerm(1);
-      pcRefPic->getPicYuvRec()->extendPicBorder();
-      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
-      NumPocLtCurr++;
-    }
-    if(pcRefPic==NULL) 
-    {
-      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
-    }
-    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));  
-  }
-
-  // ref_pic_list_init
-  TComPic*  rpsCurrList0[MAX_NUM_REF+1];
-  TComPic*  rpsCurrList1[MAX_NUM_REF+1];
-#if H_MV
-  Int numPocInterCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; 
-  assert( numPocInterCurr == 0 || getInterRefEnabledInRPLFlag() ); 
-  Int numPocTotalCurr = numPocInterCurr + getNumActiveRefLayerPics( );
-  assert( numPocTotalCurr == getNumRpsCurrTempList() );
-#else
-  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
-#endif
-#if FIX1071
-  if (checkNumPocTotalCurr)
-  {
-    // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
-#if H_MV
-    // â If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // â Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
-    if ( getRapPicFlag() && m_layerId == 0 )
-#else
-    // â If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // â Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
-    if (getRapPicFlag())
-#endif
-    {
-      assert(numPocTotalCurr == 0);
-    }
-
-    if (m_eSliceType == I_SLICE)
-    {
-      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
-      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
-      
-      return;
-    }
-    
-    assert(numPocTotalCurr > 0);
-    
-    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
-    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
-  }
-#endif
-
-  Int cIdx = 0;
-#if H_MV
-  if ( getInterRefEnabledInRPLFlag() )
-  {  
-#endif
-  for ( i=0; i<NumPocStCurr0; i++, cIdx++)
-  {
-    rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
-  }
-  for ( i=0; i<NumPocStCurr1; i++, cIdx++)
-  {
-    rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
-  }
-  for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
-  {
-    rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
-  }
-#if H_MV
-  }
-  for ( i=0; i < getNumActiveRefLayerPics( );  i++, cIdx++)
-    {
-    assert( cIdx < MAX_NUM_REF );    
-      rpsCurrList0[cIdx] = refPicSetInterLayer[i];
-    }
-#endif
-  assert(cIdx == numPocTotalCurr);
-
-  if (m_eSliceType==B_SLICE)
-  {
-    cIdx = 0;
-#if H_MV
-    if ( getInterRefEnabledInRPLFlag() )
-    {  
-#endif
-    for ( i=0; i<NumPocStCurr1; i++, cIdx++)
-    {
-      rpsCurrList1[cIdx] = RefPicSetStCurr1[i];
-    }
-    for ( i=0; i<NumPocStCurr0; i++, cIdx++)
-    {
-      rpsCurrList1[cIdx] = RefPicSetStCurr0[i];
-    }
-    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
-    {
-      rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
-    }
-#if H_MV
-    }
-    for ( i=0; i < getNumActiveRefLayerPics( );  i++, cIdx++)
-      {
-      assert( cIdx < MAX_NUM_REF );    
-        rpsCurrList1[cIdx] = refPicSetInterLayer[i];
-      }
-#endif
-    assert(cIdx == numPocTotalCurr);
-  }
-
-  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
-
-#if H_MV
-  Int numPocSt = NumPocStCurr0 + NumPocStCurr1; 
-  assert(  getInterRefEnabledInRPLFlag( ) || numPocSt == 0 );
-
-  for (Int li = 0; li < 2; li++)
-  {
-    if ( m_eSliceType == P_SLICE && li == 1 )
-    {
-      m_aiNumRefIdx[1] = 0;
-      ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
-    } 
-    else
-    {
-      for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[ li ] - 1 ); rIdx ++)
-      { 
-        Bool listModified             =                m_RefPicListModification.getRefPicListModificationFlagL( li ); 
-        Int orgIdx                    = listModified ? m_RefPicListModification.getRefPicSetIdxL(li, rIdx) : (rIdx % numPocTotalCurr); 
-
-        m_apcRefPicList    [li][rIdx] = ( li == 0 )  ? rpsCurrList0[ orgIdx  ] : rpsCurrList1[ orgIdx  ];
-        m_bIsUsedAsLongTerm[li][rIdx] = ( orgIdx >= numPocSt ) ; 
-      }
-    }
-  }
-#else
-  for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++)
-  {
-    cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr;
-    assert(cIdx >= 0 && cIdx < numPocTotalCurr);
-    m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ];
-    m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
-  }
-  if ( m_eSliceType != B_SLICE )
-  {
-    m_aiNumRefIdx[1] = 0;
-    ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
-  }
-  else
-  {
-    for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++)
-    {
-      cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr;
-      assert(cIdx >= 0 && cIdx < numPocTotalCurr);
-      m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ];
-      m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
-    }
-  }
-#endif
-}
-
-#endif
-Int TComSlice::getNumRpsCurrTempList()
-{
-  Int numRpsCurrTempList = 0;
-
-  if (m_eSliceType == I_SLICE) 
-  {
-    return 0;
-  }
-  for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++)
-  {
-    if(m_pcRPS->getUsed(i))
-    {
-      numRpsCurrTempList++;
-    }
-  }
-#if H_MV
-#if !H_MV5
-  assert( ( numRpsCurrTempList == 0 ) || getInterRefEnabledInRPLFlag() ); 
-#endif
   numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
 #endif
@@ -1063,5 +806,5 @@
 }
 
-Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic)
+Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic)
 {
   for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
@@ -1089,10 +832,10 @@
   {
     pocCRA = getPOC();
-    prevRAPisBLA = false;
+    associatedIRAPType = getNalUnitType();
   }
   else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
   {
     pocCRA = getPOC();
-    prevRAPisBLA = false;
+    associatedIRAPType = getNalUnitType();
   }
   else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
@@ -1101,5 +844,5 @@
   {
     pocCRA = getPOC();
-    prevRAPisBLA = true;
+    associatedIRAPType = getNalUnitType();
   }
 }
@@ -1126,4 +869,5 @@
 {
   TComPic*                 rpcPic;
+  setAssociatedIRAPPOC(pocCRA);
   Int pocCurr = getPOC(); 
 
@@ -1295,7 +1039,5 @@
 #if H_MV
   // Additional slice header syntax elements 
-#if H_MV5
   m_pocResetFlag               = pSrc->m_pocResetFlag; 
-#endif
   m_discardableFlag            = pSrc->m_discardableFlag; 
   m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag; 
@@ -1306,15 +1048,4 @@
     m_interLayerPredLayerIdc[ layer ] = pSrc->m_interLayerPredLayerIdc[ layer ]; 
   }
-#if !H_MV5
-  m_interLayerSamplePredOnlyFlag = pSrc->m_interLayerSamplePredOnlyFlag;
-  m_altCollocatedIndicationFlag  = pSrc->m_altCollocatedIndicationFlag ;   
-  m_collocatedRefLayerIdx        = pSrc->m_collocatedRefLayerIdx       ;
-  m_numActiveMotionPredRefLayers = pSrc->m_numActiveMotionPredRefLayers;
-
-  for (Int layer = 0; layer < MAX_NUM_LAYER_IDS; layer++)
-  {    
-    m_interLayerPredLayerIdc[layer] = pSrc->m_interLayerPredLayerIdc[layer];
-  }
-#endif
 #endif
 #if H_3D_IC
@@ -1324,5 +1055,5 @@
 }
 
-Int TComSlice::m_prevPOC = 0;
+Int TComSlice::m_prevTid0POC = 0;
 
 /** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
@@ -1379,4 +1110,166 @@
 }
 
+
+Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic)
+{
+  TComPic* rpcPic;
+
+  Int nalUnitType = this->getNalUnitType();
+
+  // When a picture is a leading picture, it shall be a RADL or RASL picture.
+  if(this->getAssociatedIRAPPOC() > this->getPOC())
+  {
+    // Do not check IRAP pictures since they may get a POC lower than their associated IRAP
+    if(nalUnitType < NAL_UNIT_CODED_SLICE_BLA_W_LP ||
+       nalUnitType > NAL_UNIT_RESERVED_IRAP_VCL23)
+    {
+      assert(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+             nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
+             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
+             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R);
+    }
+  }
+
+  // When a picture is a trailing picture, it shall not be a RADL or RASL picture.
+  if(this->getAssociatedIRAPPOC() < this->getPOC())
+  {
+    assert(nalUnitType != NAL_UNIT_CODED_SLICE_RASL_N &&
+           nalUnitType != NAL_UNIT_CODED_SLICE_RASL_R &&
+           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_N &&
+           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_R);
+  }
+
+  // No RASL pictures shall be present in the bitstream that are associated
+  // with a BLA picture having nal_unit_type equal to BLA_W_RADL or BLA_N_LP.
+  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
+  {
+    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_W_RADL &&
+           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP);
+  }
+
+  // No RASL pictures shall be present in the bitstream that are associated with
+  // an IDR picture.
+  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
+  {
+    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP   &&
+           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL);
+  }
+
+  // No RADL pictures shall be present in the bitstream that are associated with
+  // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated
+  // with an IDR picture having nal_unit_type equal to IDR_N_LP.
+  if(nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
+     nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
+  {
+    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP   &&
+           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP);
+  }
+
+  // loop through all pictures in the reference picture buffer
+  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
+  while ( iterPic != rcListPic.end())
+  {
+    rpcPic = *(iterPic++);
+    if (rpcPic->getPOC() == this->getPOC())
+    {
+      continue;
+    }
+
+    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
+    // in decoding order shall precede the IRAP picture in output order.
+    // (Note that any picture following in output order would be present in the DPB)
+    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
+    {
+      if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
+         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP    ||
+         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL  ||
+         nalUnitType == NAL_UNIT_CODED_SLICE_CRA         ||
+         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP    ||
+         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
+      {
+        assert(rpcPic->getPOC() < this->getPOC());
+      }
+    }
+
+    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
+    // in decoding order shall precede any RADL picture associated with the IRAP
+    // picture in output order.
+    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
+    {
+      if((nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
+          nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R))
+      {
+        // rpcPic precedes the IRAP in decoding order
+        if(this->getAssociatedIRAPPOC() > rpcPic->getSlice(0)->getAssociatedIRAPPOC())
+        {
+          // rpcPic must not be the IRAP picture
+          if(this->getAssociatedIRAPPOC() != rpcPic->getPOC())
+          {
+            assert(rpcPic->getPOC() < this->getPOC());
+          }
+        }
+      }
+    }
+
+    // When a picture is a leading picture, it shall precede, in decoding order,
+    // all trailing pictures that are associated with the same IRAP picture.
+    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
+       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
+       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
+    {
+      if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC())
+      {
+        // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
+        // rpcPic would violate the constraint if it was a trailing picture
+        assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
+      }
+    }
+
+    // Any RASL picture associated with a CRA or BLA picture shall precede any
+    // RADL picture associated with the CRA or BLA picture in output order
+    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
+    { 
+      if((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
+          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
+          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
+          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)       &&
+          this->getAssociatedIRAPPOC() == rpcPic->getSlice(0)->getAssociatedIRAPPOC())
+      {
+        if(rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N ||
+           rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R)
+        {
+          assert(rpcPic->getPOC() > this->getPOC());
+        }
+      }
+    }
+
+    // Any RASL picture associated with a CRA picture shall follow, in output
+    // order, any IRAP picture that precedes the CRA picture in decoding order.
+    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
+    {
+      if(this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)
+      {
+        if(rpcPic->getSlice(0)->getPOC() < this->getAssociatedIRAPPOC() &&
+           (rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
+            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
+            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
+            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
+            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
+            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
+        {
+          assert(this->getPOC() > rpcPic->getSlice(0)->getPOC());
+        }
+      }
+    }
+  }
+}
+
+
+
 /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
 */
@@ -1385,4 +1278,6 @@
   TComPic* rpcPic;
   Int i, isReference;
+
+  checkLeadingPictureRestrictions(rcListPic);
 
   // loop through all pictures in the reference picture buffer
@@ -1421,5 +1316,8 @@
       else 
       {
-        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()))
+        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
+        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
+        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
+        if(rpcPic->getIsLongTerm() && curPoc == refPoc)
         {
           isReference = 1;
@@ -1481,5 +1379,8 @@
       else 
       {
-        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
+        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
+        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
+        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
+        if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
         {
           isAvailable = 1;
@@ -1500,6 +1401,6 @@
         if (!pReferencePictureSet->getCheckLTMSBPresent(i))
         {
-          curPoc = curPoc % pocCycle;
-          refPoc = refPoc % pocCycle;
+          curPoc = curPoc & (pocCycle - 1);
+          refPoc = refPoc & (pocCycle - 1);
         }
         
@@ -1781,10 +1682,6 @@
 : m_VPSId                     (  0)
 , m_uiMaxTLayers              (  1)
-#if H_MV5
 #if H_MV
 , m_uiMaxLayersMinus1         (  0)
-#else
-, m_uiMaxLayers               (  1)
-#endif
 #else
 , m_uiMaxLayers               (  1)
@@ -1800,8 +1697,6 @@
 , m_hrdOpSetIdx               (NULL)
 , m_cprmsPresentFlag          (NULL)
-#if H_MV5
 #if H_MV
 , m_vpsVUI                 (  NULL )
-#endif
 #endif
 {
@@ -1848,16 +1743,10 @@
 
   m_avcBaseLayerFlag = false;
-#if H_MV5
   m_vpsVuiOffset     = 0; 
-#endif
   m_splittingFlag    = false;
   
   for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ )
   {
-#if H_MV5
     m_scalabilityMaskFlag[i] = false;
-#else
-    m_scalabilityMask[i] = false;
-#endif
     m_dimensionIdLen [i]  = -1; 
   }
@@ -1885,12 +1774,8 @@
     m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1; 
     m_numDirectRefLayers[i] = 0; 
-#if H_MV5
     m_maxTidIlRefPicPlus1[i] = 7;
     m_vpsRepFormatIdx    [i] = 0; 
     m_repFormat          [i] = NULL; 
     m_viewIdVal          [i] = 0; 
-#else
-    m_maxTidIlRefPicPlus1[i] = -1; 
-#endif
 
 #if H_3D
@@ -1935,7 +1820,5 @@
 #endif
   }
-#if H_MV5
   m_vpsVUI = new TComVPSVUI; 
-#endif
 #if H_3D
   for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
@@ -1950,5 +1833,5 @@
     m_depthRefinementFlag  [ i ] = false;
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
     m_bInterSDCFlag        [ i ] = false;
 #endif
@@ -1963,5 +1846,4 @@
   if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
   if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
-#if H_MV5
 #if H_MV
   if ( m_vpsVUI          != NULL )     delete m_vpsVUI; 
@@ -1983,23 +1865,4 @@
 #endif
   }
-#endif
-#else
-#if H_3D_DIM_DLT
-  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
-  {
-    if ( m_iDepthValue2Idx[i] != 0 ) 
-    {
-       xFree( m_iDepthValue2Idx[i] );
-       m_iDepthValue2Idx[i] = 0; 
-    }
-
-    if ( m_iIdx2DepthValue[i] != 0 ) 
-    {
-      xFree( m_iIdx2DepthValue[i] );
-      m_iIdx2DepthValue[i] = 0; 
-
-    }
-  }
-#endif
 #endif
 }
@@ -2072,9 +1935,5 @@
 Bool TComVPS::checkVPSExtensionSyntax()
 {
-#if H_MV5
   for( Int layer = 1; layer <= getMaxLayersMinus1(); layer++ )
-#else
-  for( Int layer = 1; layer < getMaxLayers(); layer++ )
-#endif
   {
     // check layer_id_in_nuh constraint
@@ -2092,17 +1951,9 @@
 {
   assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); 
-#if H_MV5
   assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) );
-#else
-  assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMask( scalType ) );
-#endif
   Int scalIdx = 0; 
   for( Int curScalType = 0; curScalType < scalType; curScalType++ )
   {
-#if H_MV5
     scalIdx += ( getScalabilityMaskFlag( curScalType ) ? 1 : 0 );
-#else
-    scalIdx += ( getScalabilityMask( curScalType ) ? 1 : 0 );
-#endif
 
   }
@@ -2110,5 +1961,4 @@
   return scalIdx; 
 }
-#if H_MV5
 Void TComVPS::setScalabilityMaskFlag( UInt val )
 {
@@ -2118,14 +1968,5 @@
   }
 }
-#else
-Void TComVPS::setScalabilityMask( UInt val )
-{
-  for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) 
-    setScalabilityMask( scalType, ( val & (1 << scalType ) ) != 0 );
-}
-
-#endif
-
-#if H_MV5
+
 Void TComVPS::setRefLayers()
 {
@@ -2176,124 +2017,4 @@
 }
 #endif // H_3D
-#else
-Void TComVPS::setRefLayers()
-{
-  for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) 
-  { 
-    m_numSamplePredRefLayers[ i ] = 0;
-    m_numMotionPredRefLayers[ i ] = 0;
-    m_numDirectRefLayers[ i ] = 0; 
-    for( Int j = 0; j < MAX_NUM_LAYERS; j++ ) {
-      m_samplePredEnabledFlag[ i ][ j ] = 0;
-      m_motionPredEnabledFlag[ i ][ j ] = 0;
-      m_refLayerId[ i ][ j ] = 0;
-      m_samplePredRefLayerId[ i ][ j ] = 0;
-      m_motionPredRefLayerId[ i ][ j ] = 0;
-    }
-  }
-
-  for( Int i = 1; i  <= getMaxLayers()- 1; i++ )
-  {
-    for( Int j = 0; j < i; j++ )
-    {
-      if( getDirectDependencyFlag(i,j) )
-      {
-        m_refLayerId[ i ][m_numDirectRefLayers[ i ]++ ] = getLayerIdInNuh( j );
-
-        m_samplePredEnabledFlag [ i ][ j ]  = ( (   getDirectDependencyType( i , j ) + 1 ) & 1 ) == 1;
-        m_numSamplePredRefLayers[ i ]      += m_samplePredEnabledFlag [ i ][ j ] ? 1 : 0; 
-        m_motionPredEnabledFlag [ i ][ j ]  = ( ( ( getDirectDependencyType( i , j ) + 1 ) & 2 ) >> 1 ) == 1;
-        m_numMotionPredRefLayers[ i ]      += m_motionPredEnabledFlag  [ i][ j ] ? 1 : 0; 
-      }
-    }
-  }
-
-  for( Int i = 1, mIdx = 0, sIdx = 0; i <= getMaxLayers()- 1; i++ )
-  {    
-    for( Int j = 0 ; j < i; j++ )
-    {
-      if( m_motionPredEnabledFlag[ i ][ j ] )
-      {
-        m_motionPredRefLayerId[ i ][ mIdx++ ] = getLayerIdInNuh( j );
-      }
-      
-      if( m_samplePredEnabledFlag[ i ][ j ] )
-      {
-        m_samplePredRefLayerId[ i ][ sIdx++ ] = getLayerIdInNuh( j );
-      }
-    }
-  }
-}
-
-Int TComVPS::getRefLayerId( Int layerIdInVps, Int idx )
-{
-  assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInVps] );     
-  Int layerIdInNuh = m_refLayerId[ layerIdInVps ][ idx ];    
-  assert ( layerIdInNuh >= 0 ); 
-  return layerIdInNuh;
-}
-
-Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
-{
-  return getScalabilityMask( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
-}
-
-#if H_3D
-Void TComVPS::initViewIndex()
-{
-  Int viewIdList   [ MAX_NUM_LAYERS ]; // ed. should be changed to MAX_VIEW_ID
-  Int viewIndexList[ MAX_NUM_LAYERS ]; 
-  Int numViewIds = 0; 
-
-  for ( Int i = 0 ; i  <  m_uiMaxLayers; i++ )
-  {     
-    Int currViewId = getViewId( i ); 
-
-    Bool viewIdInListFlag = false; 
-    for ( Int j = 0; j < numViewIds; j ++ )
-    {
-      viewIdInListFlag  = viewIdInListFlag || ( currViewId  == viewIdList[ j ]  );
-    }
-
-    if ( !viewIdInListFlag ) 
-    {
-      viewIdList   [ numViewIds ] = currViewId;
-      viewIndexList[ currViewId ] = numViewIds;
-
-      numViewIds++;
-    }  
-
-    m_viewIndex[ i ] = viewIndexList[ currViewId ]; 
-  }
-}
-
-Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag )
-{
-  Int foundlayerId = -1; 
-
-  for (Int layer = 0 ; layer < m_uiMaxLayers; layer++ )
-  {
-    if( ( getViewIndex( layer ) == viewIndex ) && ( getDepthId( layer ) == ( depthFlag ? 1 : 0 ) )  )
-    {
-      foundlayerId = layer; 
-      break; 
-    }
-  }
-  assert( foundlayerId != -1 ); 
-
-  return getLayerIdInNuh( foundlayerId );
-}
-
-#endif // H_3D
-
-Int TComVPS::xCeilLog2( Int val )
-{
-  assert( val > 0 ); 
-  Int ceilLog2 = 0;
-  while( val > ( 1 << ceilLog2 ) ) ceilLog2++;
-  return ceilLog2;
-}
-
-#endif // H_MV5
 
 
@@ -2336,5 +2057,4 @@
   return numLayersInIdList;
 }
-#if H_MV5
 Int TComVPS::getNumViews()
 {
@@ -2366,5 +2086,4 @@
   return dependentFlag;
 }
-#endif
 #endif // H_MV
 
@@ -2417,5 +2136,4 @@
 , m_vuiParameters             ()
 #if H_MV
-#if H_MV5
 , m_pcVPS                     ( NULL )
 , m_spsInferScalingListFlag   ( false )
@@ -2423,8 +2141,4 @@
 , m_updateRepFormatFlag       ( true ) 
 , m_interViewMvVertConstraintFlag (false)
-#else
-, m_interViewMvVertConstraintFlag (false)
-, m_numIlpRestrictedRefLayers ( 0 )
-#endif
 #endif
 #if H_3D
@@ -2441,14 +2155,4 @@
   ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
   ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
-#if !H_MV5
-#if H_MV
-  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
-  {
-    m_minSpatialSegmentOffsetPlus1[ i ] = 0;
-    m_ctuBasedOffsetEnabledFlag   [ i ] = false;
-    m_minHorizontalCtuOffsetPlus1 [ i ] = 0;
-  }
-#endif
-#endif
 }
 
@@ -2603,10 +2307,8 @@
 , m_listsModificationPresentFlag(  0)
 , m_numExtraSliceHeaderBits(0)
-#if H_MV5
 #if H_MV
 , m_ppsInferScalingListFlag(false)
 , m_ppsScalingListRefLayerId(0)
 #endif
-#endif
 {
   m_scalingList = new TComScalingList;
@@ -2628,5 +2330,4 @@
 }
 
-#if H_MV5
 #if H_MV
 Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr )
@@ -2679,5 +2380,4 @@
   }
 }
-#endif
 #endif
 #if H_3D
@@ -2908,5 +2608,4 @@
 TComScalingList::TComScalingList()
 {
-  m_useTransformSkip = false;
   init();
 }
@@ -2950,5 +2649,4 @@
 
 #if H_MV
-#if H_MV5
 Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 )
 {
@@ -2982,27 +2680,5 @@
   }
 }
-#else
-Void TComSlice::createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer )
-{
-  refPicSetInterLayer.clear(); 
-
-  for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) 
-  {
-    Int layerIdRef = getRefPicLayerId( i ); 
-    TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; 
-    assert ( picRef != 0 ); 
-
-    picRef->getPicYuvRec()->extendPicBorder(); 
-    picRef->setIsLongTerm( true );        
-    picRef->getSlice(0)->setReferenced( true );       
-
-    // Consider to check here: 
-    // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer that is a RASL picture. "
-    refPicSetInterLayer.push_back( picRef ); 
-  }
-}
-#endif
-
-#if H_MV5
+
 Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 )
 {
@@ -3019,15 +2695,4 @@
 
 }
-#else
-Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer )
-{
-  // Mark as shortterm 
-  for ( Int i = 0; i < refPicSetInterLayer.size(); i++ ) 
-  {
-    refPicSetInterLayer[i]->setIsLongTerm( false ); 
-  }
-}
-
-#endif
 Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc )
 {
@@ -3035,9 +2700,5 @@
   if (targetDecLayerIdSet.size() == 0 )    
   {
-#if H_MV5
     for ( Int layerIdInVps = 0; layerIdInVps <= vps->getMaxLayersMinus1(); layerIdInVps++ )
-#else
-    for ( Int layerIdInVps = 0; layerIdInVps < vps->getMaxLayers(); layerIdInVps++ )
-#endif
     {
       targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) ); 
@@ -3068,14 +2729,7 @@
           if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) )
           {
-#if H_MV5
             for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdSet[ j ] ); k++ )
             {
               if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdSet[ j ],  k  ) )
-#else
-            Int targetDecLayerIdinVPS = vpsSlice->getLayerIdInVps( targetDecLayerIdSet[ j ] ); 
-            for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdinVPS ); k++ )
-            {
-              if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdinVPS,  k  ) )
-#endif
               {
                 remainingInterLayerReferencesFlag = true;
@@ -3093,9 +2747,5 @@
 }
 
-#if H_MV5
 Void TComSlice::printRefPicList()
-#else
-Void TComSlice::xPrintRefPicList()
-#endif
 {  
   for ( Int li = 0; li < 2; li++)
@@ -3110,13 +2760,4 @@
   }
 }
-#if !H_MV5
-Int TComSlice::xCeilLog2( Int val )
-{
-  assert( val > 0 ); 
-  Int ceilLog2 = 0;
-  while( val > ( 1 << ceilLog2 ) ) ceilLog2++;
-  return ceilLog2;
-}
-#endif
 
 Void TComSlice::markCurrPic( TComPic* currPic )
@@ -3133,5 +2774,4 @@
 }
 
-#if H_MV5
 Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1 )
 {
@@ -3158,31 +2798,8 @@
   return pcPic;
 }
-#else
-Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer )
-{
-  m_refPicSetInterLayer = refPicSetInterLayer; 
-}
-
-TComPic* TComSlice::getPicFromRefPicSetInterLayer( Int layerId )
-{
-  assert( m_refPicSetInterLayer != 0 ); 
-  assert( (*m_refPicSetInterLayer).size() == getNumActiveRefLayerPics() ); 
-  TComPic* pcPic = NULL; 
-  for ( Int i = 0; i < getNumActiveRefLayerPics(); i++ )
-  {
-    if ((*m_refPicSetInterLayer)[ i ]->getLayerId() == layerId)
-    {
-      pcPic = (*m_refPicSetInterLayer)[ i ]; 
-    }
-  }
-  assert(pcPic != NULL); 
-  return pcPic;
-}
-#endif
 Int TComSlice::getNumActiveRefLayerPics()
 {
   Int numActiveRefLayerPics; 
 
-#if H_MV5
   if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerId() ) ==  0 )
   {
@@ -3198,11 +2815,4 @@
   }
   else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 )
-#else
-  if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) ==  0 || !getInterLayerPredEnabledFlag() )
-  {
-    numActiveRefLayerPics = 0; 
-  }
-  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) == 1 )
-#endif
   {
     numActiveRefLayerPics = 1; 
@@ -3217,41 +2827,7 @@
 Int TComSlice::getRefPicLayerId( Int i )
 {
-#if H_MV5
   return getVPS()->getRefLayerId( getLayerId(), getInterLayerPredLayerIdc( i ) );
-#else
-  return getVPS()->getRefLayerId( getLayerIdInVps(), getInterLayerPredLayerIdc( i ) );
-#endif
-}
-
-#if !H_MV5
-Void TComSlice::setActiveMotionPredRefLayers()
-{
-  Int j = 0; 
-  for( Int i = 0; i < getNumActiveRefLayerPics(); i++)
-  {
-    if( getVPS()->getMotionPredEnabledFlag( getLayerIdInVps(), getInterLayerPredLayerIdc( i ))  )
-    {
-      m_activeMotionPredRefLayerId[ j++ ] = getVPS()->getRefLayerId( getLayerIdInVps(), i ); 
-    }
-  }
-  m_numActiveMotionPredRefLayers = j;
-
-  // Consider incorporating bitstream conformance tests on derived variables here.
-}
-
-Bool TComSlice::getInterRefEnabledInRPLFlag()
-{
-  Bool interRefEnabledInRPLFlag; 
-  if ( getVPS()->getNumSamplePredRefLayers( getLayerIdInVps() ) > 0 && getNumActiveRefLayerPics() > 0 )
-  {
-    interRefEnabledInRPLFlag = !getInterLayerSamplePredOnlyFlag(); 
-  }
-  else
-  {
-    interRefEnabledInRPLFlag = 1; 
-  }
-  return interRefEnabledInRPLFlag;
-}
-#endif
+}
+
 #if H_3D_ARP
 Void TComSlice::setARPStepNum()                                  
@@ -3531,5 +3107,4 @@
 }
 
-#if H_MV5
 #if H_MV
 Void TComScalingList::inferFrom( TComScalingList* srcScLi )
@@ -3545,5 +3120,4 @@
   }
 }
-#endif
 #endif
 /** initialization process of quantization matrix array
@@ -3636,5 +3210,4 @@
 , m_ppsMap(MAX_NUM_PPS)
 , m_activeVPSId(-1)
-#if H_MV5
 #if !H_MV
 , m_activeSPSId(-1)
@@ -3649,9 +3222,4 @@
   }
 #endif
-#else
-, m_activeSPSId(-1)
-, m_activePPSId(-1)
-{
-#endif
 }
 
@@ -3663,5 +3231,4 @@
 //! activate a SPS from a active parameter sets SEI message
 //! \returns true, if activation is successful
-#if H_MV5
 #if H_MV
 Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId )
@@ -3669,7 +3236,4 @@
 Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
 #endif
-#else
-Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
-#endif
 {
   TComSPS *sps = m_spsMap.getPS(spsId);
@@ -3680,7 +3244,4 @@
     {
       m_activeVPSId = vpsId;
-#if !H_MV5
-      m_activeSPSId = spsId;
-#else
 #if H_MV
       m_activeSPSId[ layerId ] = spsId;
@@ -3688,5 +3249,4 @@
       m_activeSPSId = spsId;
 #endif
-#endif
       return true;
     }
@@ -3705,5 +3265,4 @@
 //! activate a PPS and depending on isIDR parameter also SPS and VPS
 //! \returns true, if activation is successful
-#if H_MV5
 #if H_MV
 Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId )
@@ -3742,35 +3301,4 @@
         m_activeSPSId[ layerId ] = spsId;
 #else
-        m_activePPSId = ppsId;
-        m_activeVPSId = vpsId;
-        m_activeSPSId = spsId;
-#endif
-#else
-Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
-{
-  TComPPS *pps = m_ppsMap.getPS(ppsId);
-  if (pps)
-  {
-    Int spsId = pps->getSPSId();
-#if H_MV
-    // active parameter sets per layer should be used here
-#else
-    if (!isIRAP && (spsId != m_activeSPSId))
-    {
-      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
-      return false;
-    }
-#endif
-    TComSPS *sps = m_spsMap.getPS(spsId);
-    if (sps)
-    {
-      Int vpsId = sps->getVPSId();
-      if (!isIRAP && (vpsId != m_activeVPSId))
-      {
-        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
-        return false;
-      }
-      if (m_vpsMap.getPS(vpsId))
-      {
         m_activePPSId = ppsId;
         m_activeVPSId = vpsId;
@@ -3828,5 +3356,4 @@
 //! \}
 
-#if H_MV5
 #if H_MV
 TComVPSVUI::TComVPSVUI()
@@ -3861,3 +3388,2 @@
 }
 #endif
-#endif
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 655)
@@ -155,6 +155,4 @@
   Void     setScalingListPresentFlag    (Bool b)                               { m_scalingListPresentFlag = b;    }
   Bool     getScalingListPresentFlag    ()                                     { return m_scalingListPresentFlag; }
-  Bool     getUseTransformSkip    ()                                     { return m_useTransformSkip; }      
-  Void     setUseTransformSkip    (Bool b)                               { m_useTransformSkip = b;    }
   Int*     getScalingListAddress          (UInt sizeId, UInt listId)           { return m_scalingListCoef[sizeId][listId]; } //!< get matrix coefficient
   Bool     checkPredMode                  (UInt sizeId, UInt listId);
@@ -169,8 +167,6 @@
   Void     processRefMatrix               (UInt sizeId, UInt listId , UInt refListId );
   Bool     xParseScalingList              (Char* pchFile);
-#if H_MV5
 #if H_MV
   Void     inferFrom                      ( TComScalingList* srcScLi );
-#endif
 #endif
 
@@ -184,5 +180,4 @@
   UInt     m_predMatrixId                [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< reference list index
   Int      *m_scalingListCoef            [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< quantization matrix
-  Bool     m_useTransformSkip;                                                      //!< transform skipping flag for setting default scaling matrix for 4x4
 };
 
@@ -407,5 +402,4 @@
 };
 
-#if H_MV5
 #if H_MV
 class TComVPSVUI
@@ -502,5 +496,4 @@
 };
 #endif
-#endif
 
 class TComVPS
@@ -510,10 +503,6 @@
   UInt        m_uiMaxTLayers;
 
-#if H_MV5
 #if H_MV
   UInt        m_uiMaxLayersMinus1;
-#else
-  UInt        m_uiMaxLayers;
-#endif
 #else
   UInt        m_uiMaxLayers;
@@ -551,29 +540,17 @@
   /// VPS EXTENSION SYNTAX ELEMENTS
   Bool        m_avcBaseLayerFlag;
-#if H_MV5
   Int         m_vpsVuiOffset;
-#endif
   Bool        m_splittingFlag;
-#if H_MV5
   Bool        m_scalabilityMaskFlag          [MAX_NUM_SCALABILITY_TYPES];
-#else
-  Bool        m_scalabilityMask          [MAX_NUM_SCALABILITY_TYPES];
-#endif
   Int         m_dimensionIdLen           [MAX_NUM_SCALABILITY_TYPES];
   Bool        m_vpsNuhLayerIdPresentFlag;
   Int         m_layerIdInNuh             [MAX_NUM_LAYER_IDS];
   Int         m_dimensionId              [MAX_NUM_LAYER_IDS][MAX_NUM_SCALABILITY_TYPES];  
-#if H_MV5
   Int         m_viewIdLenMinus1;
   Int         m_viewIdVal                [MAX_NUM_LAYERS];
-#endif
   Bool        m_directDependencyFlag     [MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];
-#if H_MV5
   Bool        m_maxTidRefPresentFlag;
-#endif
   Int         m_maxTidIlRefPicPlus1      [MAX_NUM_LAYERS];
-#if H_MV5
   Bool        m_allRefLayersActiveFlag;
-#endif
   Int         m_vpsNumberLayerSetsMinus1; 
   Int         m_vpsNumProfileTierLevelMinus1;   
@@ -586,19 +563,13 @@
   Bool        m_outputLayerFlag          [MAX_VPS_OUTPUTLAYER_SETS][MAX_VPS_NUH_LAYER_ID_PLUS1];
   Int         m_profileLevelTierIdx      [MAX_VPS_OUTPUTLAYER_SETS ];
-#if H_MV5
   Bool        m_repFormatIdxPresentFlag;
   Int         m_vpsNumRepFormatsMinus1;
   Int         m_vpsRepFormatIdx          [MAX_NUM_LAYERS];
   TComRepFormat* m_repFormat             [MAX_NUM_LAYERS]; 
-#endif
   Bool        m_maxOneActiveRefLayerFlag;       
-#if H_MV5
   Bool        m_crossLayerIrapAlignedFlag;
-#endif
   Int         m_directDepTypeLenMinus2;         
-#if H_MV5
   Bool        m_vpsVuiPresentFlag;
   TComVPSVUI* m_vpsVUI; 
-#endif
   Int         m_directDependencyType     [MAX_NUM_LAYERS] [MAX_NUM_LAYERS];
 
@@ -616,13 +587,5 @@
   Bool        m_motionPredEnabledFlag    [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
   Int         m_motionPredRefLayerId     [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
-#if H_MV5
   Int         m_viewIndex                [MAX_NUM_LAYERS   ];
-#else
-#if H_3D
-  Int         m_viewIndex                [MAX_NUM_LAYERS   ];
-#endif
-
-  Int         xCeilLog2       ( Int val );
-#endif
   Int         xGetDimBitOffset( Int j );
   
@@ -653,5 +616,5 @@
   Bool        m_ivMvScalingFlag; 
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Bool        m_bInterSDCFlag[MAX_NUM_LAYERS   ];
 #endif
@@ -681,5 +644,4 @@
   Void    setMaxTLayers  (UInt t)             { m_uiMaxTLayers = t; }
   
-#if H_MV5
 #if H_MV    
   UInt    getMaxLayersMinus1()                { return m_uiMaxLayersMinus1;  }; 
@@ -689,8 +651,4 @@
   Void    setMaxLayers   (UInt l)             { m_uiMaxLayers = l; }
 #endif
-#else
-  UInt    getMaxLayers   ()                   { return m_uiMaxLayers;   }
-  Void    setMaxLayers   (UInt l)             { m_uiMaxLayers = l; }
-#endif
 
   Bool    getTemporalNestingFlag   ()         { return m_bTemporalIdNestingFlag;   }
@@ -735,22 +693,13 @@
   Bool    getAvcBaseLayerFlag()                                            { return m_avcBaseLayerFlag; } 
 
-#if H_MV5
   Void    setVpsVuiOffset( Int  val )                                      { m_vpsVuiOffset = val; } 
   Int     getVpsVuiOffset(  )                                              { return m_vpsVuiOffset; } 
-#endif
 
   Void    setSplittingFlag( Bool val )                                     { m_splittingFlag = val;  }
   Bool    getSplittingFlag()                                               { return m_splittingFlag; }
 
-#if H_MV5
   Void    setScalabilityMaskFlag( UInt val );
   Void    setScalabilityMaskFlag( Int scalType, Bool val )                     { m_scalabilityMaskFlag[scalType] = val;  }
   Bool    getScalabilityMaskFlag( Int scalType )                               { return m_scalabilityMaskFlag[scalType]; }
-#else
-  Void    setScalabilityMask( UInt val );
-
-  Void    setScalabilityMask( Int scalType, Bool val )              { m_scalabilityMask[scalType] = val;  }
-  Bool    getScalabilityMask( Int scalType )                        { return m_scalabilityMask[scalType]; }
-#endif
   Int     getNumScalabilityTypes( );
 
@@ -769,5 +718,4 @@
   Int     getDimensionId( Int layerIdInVps, Int scalIdx )                  { return m_dimensionId[layerIdInVps][scalIdx]; }
 
-#if H_MV5
   Void    setViewIdLenMinus1( Int  val )                                   { m_viewIdLenMinus1 = val; } 
   Int     getViewIdLenMinus1(  )                                           { return m_viewIdLenMinus1; } 
@@ -775,18 +723,13 @@
   Void    setViewIdVal( Int viewOrderIndex, Int  val )                     { m_viewIdVal[viewOrderIndex] = val; } 
   Int     getViewIdVal( Int viewOrderIndex )                               { return m_viewIdVal[viewOrderIndex]; } 
-#endif
   Void    setDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Bool val ) { m_directDependencyFlag[depLayeridInVps][refLayeridInVps] = val;  }
   Bool    getDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps )           { return m_directDependencyFlag[depLayeridInVps][refLayeridInVps]; }
 
-#if H_MV5
   Void    setMaxTidRefPresentFlag( Bool flag )                             { m_maxTidRefPresentFlag = flag; } 
   Bool    getMaxTidRefPresentFlag(  )                                      { return m_maxTidRefPresentFlag; } 
-#endif
   Void    setMaxTidIlRefPicPlus1( Int layerIdInVps, Int val )              { m_maxTidIlRefPicPlus1[ layerIdInVps ] = val;  } 
   Int     getMaxTidIlRefPicPlus1( Int layerIdInVps )                       { return m_maxTidIlRefPicPlus1[ layerIdInVps ]; } 
-#if H_MV5
   Void    setAllRefLayersActiveFlag( Bool flag )                           { m_allRefLayersActiveFlag = flag; } 
   Bool    getAllRefLayersActiveFlag(  )                                    { return m_allRefLayersActiveFlag; } 
-#endif
   Void    setVpsNumberLayerSetsMinus1( Int val )                           { m_vpsNumberLayerSetsMinus1 = val;  } 
   Int     getVpsNumberLayerSetsMinus1( )                                   { return m_vpsNumberLayerSetsMinus1; } 
@@ -819,5 +762,4 @@
   Int     getProfileLevelTierIdx( Int outLayerSetIdx )                     { return m_profileLevelTierIdx[ outLayerSetIdx ]; } 
 
-#if H_MV5
   Void    setRepFormatIdxPresentFlag( Bool flag )                          { m_repFormatIdxPresentFlag = flag; } 
   Bool    getRepFormatIdxPresentFlag(  )                                   { return m_repFormatIdxPresentFlag; } 
@@ -831,11 +773,8 @@
   Void    setRepFormat( Int i, TComRepFormat* val )                        { m_repFormat[i] = val;  }
   TComRepFormat* getRepFormat( Int i )                                     { return m_repFormat[i]; }
-#endif
   Void    setMaxOneActiveRefLayerFlag( Bool flag)                          { m_maxOneActiveRefLayerFlag = flag; } 
   Bool    getMaxOneActiveRefLayerFlag( )                                   { return m_maxOneActiveRefLayerFlag; } 
-#if H_MV5
   Void    setCrossLayerIrapAlignedFlag( Bool flag )                        { m_crossLayerIrapAlignedFlag = flag; } 
   Bool    getCrossLayerIrapAlignedFlag(  )                                 { return m_crossLayerIrapAlignedFlag; } 
-#endif
   Void    setDirectDepTypeLenMinus2( Int val)                              { m_directDepTypeLenMinus2 = val; } 
   Int     getDirectDepTypeLenMinus2( )                                     { return m_directDepTypeLenMinus2; } 
@@ -843,10 +782,8 @@
   Void    setDirectDependencyType( Int depLayeridInVps, Int refLayeridInVps, Int val) { m_directDependencyType[ depLayeridInVps ][ refLayeridInVps ] = val; } 
   Int     getDirectDependencyType( Int depLayeridInVps, Int refLayeridInVps)   { return m_directDependencyType[ depLayeridInVps ][ refLayeridInVps ]; } 
-#if H_MV5  
   Void    setVpsVuiPresentFlag( Bool flag )                                { m_vpsVuiPresentFlag = flag; } 
   Bool    getVpsVuiPresentFlag(  )                                         { return m_vpsVuiPresentFlag; } 
 
   TComVPSVUI* getVPSVUI(  )                                                { return m_vpsVUI;  }
-#endif
   // VPS EXTENSION SEMANTICS VARIABLES
   Void    setLayerIdInVps( Int layerIdInNuh, Int val )                     { m_layerIdInVps[layerIdInNuh] = val;  }
@@ -854,13 +791,7 @@
 
   Int     getScalabilityId ( Int layerIdInVps, ScalabilityType scalType );
-#if H_MV5
   Int     getViewId        ( Int layerIdInNuh )                            { return m_viewIdVal[ getViewIndex( getLayerIdInVps( layerIdInNuh) )]; }
-#else
-  Int     getViewId  ( Int layerIdInVps )                                  { return getScalabilityId( layerIdInVps, VIEW_ID  ); }
-
-#endif
   Void    setRefLayers(); 
 
-#if H_MV5
   Int     getViewIndex    ( Int layerIdInNuh )                             { return getScalabilityId( getLayerIdInVps(layerIdInNuh), VIEW_ORDER_INDEX  ); }    
   Int     getNumViews();
@@ -868,24 +799,8 @@
   Int     getNumDirectRefLayers( Int layerIdInNuh )                        { return m_numDirectRefLayers[ layerIdInNuh ];  };                               
   Int     getRefLayerId        ( Int layerIdInNuh, Int idx );; 
-#else
-  Int     getNumDirectRefLayers( Int layerIdInVps )          { return m_numDirectRefLayers[ layerIdInVps ];  };                               
-  Int     getRefLayerId        ( Int layerIdInVps, Int idx );; 
-  
-  Int     getNumSamplePredRefLayers( Int layerIdInVps )          { return m_numSamplePredRefLayers[layerIdInVps]; } 
-  Bool    getSamplePredEnabledFlag ( Int layerIdInVps, Int idx ) { return m_samplePredEnabledFlag [layerIdInVps][idx]; } 
-  Int     getSamplePredRefLayerId  ( Int layerIdInVps, Int idx ) { return m_samplePredRefLayerId  [layerIdInVps][idx]; } 
-
-  Int     getNumMotionPredRefLayers( Int layerIdInVps )          { return m_numMotionPredRefLayers[layerIdInVps]; } 
-  Bool    getMotionPredEnabledFlag ( Int layerIdInVps, Int idx ) { return m_motionPredEnabledFlag [layerIdInVps][idx]; } 
-  Int     getMotionPredRefLayerId  ( Int layerIdInVps, Int idx ) { return m_motionPredRefLayerId  [layerIdInVps][idx]; } 
-#endif  
   Bool    checkVPSExtensionSyntax(); 
   Int     scalTypeToScalIdx   ( ScalabilityType scalType );
 
-  #if H_MV5
 Int     getProfileLevelTierIdxLen()                                      { return gCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 ); };       
-#else
-  Int     getProfileLevelTierIdxLen() { return xCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 ); };       
-#endif
 
   Int     getNumLayersInIdList              ( Int lsIdx );; 
@@ -895,17 +810,9 @@
   Int     inferLastDimsionIdLenMinus1();
 
-#if H_MV5
   // helpers
   Bool    getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth = 0 );
-#endif
   /// VPS EXTENSION 2 SYNTAX ELEMENTS
 #if H_3D  
-#if H_MV5
   Int     getDepthId      ( Int layerIdInNuh)                             { return getScalabilityId( getLayerIdInVps(layerIdInNuh), DEPTH_ID ); }
-#else
-  Void    initViewIndex(); 
-  Int     getViewIndex    ( Int layerIdInVps )                             { return m_viewIndex[ layerIdInVps ]; }    
-  Int     getDepthId      ( Int layerIdInVps )                             { return getScalabilityId( layerIdInVps, DEPTH_ID ); }
-#endif
   Int     getLayerIdInNuh( Int viewIndex, Bool depthFlag );   
 
@@ -943,5 +850,5 @@
   Bool    getIvMvScalingFlag   (  )                       { return m_ivMvScalingFlag; }
   Void    setIvMvScalingFlag   ( Bool b )                 { m_ivMvScalingFlag = b;    }  
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Bool    getInterSDCFlag      ( Int layerIdInVps )           { return m_bInterSDCFlag[layerIdInVps]; }
   Void    setInterSDCFlag      ( Int layerIdInVps, Bool bval ){ m_bInterSDCFlag[layerIdInVps] = bval; }
@@ -960,8 +867,6 @@
   Int           m_winTopOffset;
   Int           m_winBottomOffset;
-#if H_MV5
 #if H_MV
   Bool          m_scaledFlag; 
-#endif
 #endif
 public:
@@ -972,8 +877,6 @@
   , m_winTopOffset      (0)
   , m_winBottomOffset   (0)
-#if H_MV5
 #if H_MV
   , m_scaledFlag(true)
-#endif
 #endif
   { }
@@ -990,5 +893,4 @@
   Void          setWindowBottomOffset(Int val)    { m_winBottomOffset = val; m_enabledFlag = true; }
 
-#if H_MV5
 #if H_MV
   Void          setScaledFlag(Bool flag)          { m_scaledFlag = flag;  } 
@@ -1005,5 +907,4 @@
     }
   }
-#endif
 #endif
   Void          setWindow(Int offsetLeft, Int offsetLRight, Int offsetLTop, Int offsetLBottom)
@@ -1054,9 +955,4 @@
   TComHRD m_hrdParameters;
   TimingInfo m_timingInfo;
-#if !H_MV5
-#if H_MV
-  Bool m_tileBoundariesAlignedFlag;
-#endif
-#endif
 
 public:
@@ -1091,9 +987,4 @@
     ,m_log2MaxMvLengthHorizontal(15)
     ,m_log2MaxMvLengthVertical(15)
-#if !H_MV5
-#if H_MV
-    ,m_tileBoundariesAlignedFlag(true)
-#endif
-#endif
   {}
 
@@ -1191,10 +1082,4 @@
   TComHRD* getHrdParameters                 ()             { return &m_hrdParameters; }
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
-#if !H_MV5
-#if H_MV
-Bool getTileBoundariesAlignedFlag(  ) { return m_tileBoundariesAlignedFlag; } 
-  Void setTileBoundariesAlignedFlag( Bool flag ) { m_tileBoundariesAlignedFlag = flag; } 
-#endif
-#endif
 
 };
@@ -1281,5 +1166,4 @@
   TComPTL     m_pcPTL;
 #if H_MV
-#if H_MV5
   TComVPS*    m_pcVPS; 
   // SPS 
@@ -1287,13 +1171,6 @@
   Int         m_spsScalingListRefLayerId;
   Bool        m_updateRepFormatFlag;
-#endif
   // SPS Extension 
   Bool        m_interViewMvVertConstraintFlag;
-#if !H_MV5
-  Int         m_numIlpRestrictedRefLayers        ;
-  Int         m_minSpatialSegmentOffsetPlus1[MAX_NUM_LAYERS];
-  Bool        m_ctuBasedOffsetEnabledFlag   [MAX_NUM_LAYERS];
-  Int         m_minHorizontalCtuOffsetPlus1 [MAX_NUM_LAYERS];
-#endif
 #endif
 #if H_3D
@@ -1432,5 +1309,4 @@
   TComPTL* getPTL()     { return &m_pcPTL; }
 #if H_MV
-#if H_MV5
   Void      setVPS          ( TComVPS* pcVPS ) { m_pcVPS = pcVPS; }
   TComVPS*  getVPS          () { return m_pcVPS; }
@@ -1444,27 +1320,11 @@
   Void setUpdateRepFormatFlag( Bool flag )     { m_updateRepFormatFlag = flag; } 
   Bool getUpdateRepFormatFlag(  )              { return m_updateRepFormatFlag; } 
-#endif
   // SPS Extension 
   Void setInterViewMvVertConstraintFlag(Bool val) { m_interViewMvVertConstraintFlag = val; }
   Bool getInterViewMvVertConstraintFlag()         { return m_interViewMvVertConstraintFlag;}
-#if H_MV5
   // Inference 
   Void inferRepFormat( TComVPS* vps, Int layerIdCurr );
 
   Void inferScalingList( TComSPS* spsSrc );
-#else
-  Void setNumIlpRestrictedRefLayers   ( Int val )        { m_numIlpRestrictedRefLayers         = val;}
-  Int  getNumIlpRestrictedRefLayers   ( )                { return m_numIlpRestrictedRefLayers        ;}
-  
-  Void setMinSpatialSegmentOffsetPlus1( Int i, Int val ) { m_minSpatialSegmentOffsetPlus1[ i ] = val;}
-  Int  getMinSpatialSegmentOffsetPlus1( Int i )          { return m_minSpatialSegmentOffsetPlus1[ i ];}
-  
-  Void setCtuBasedOffsetEnabledFlag   ( Int i, Bool flag ) { m_ctuBasedOffsetEnabledFlag   [ i ] = flag;}
-  Bool getCtuBasedOffsetEnabledFlag   ( Int i )            { return m_ctuBasedOffsetEnabledFlag   [ i ];}
-
-  Void setMinHorizontalCtuOffsetPlus1 ( Int i, Int val )   { m_minHorizontalCtuOffsetPlus1 [ i ] = val;}
-  Int  getMinHorizontalCtuOffsetPlus1 ( Int i )            { return m_minHorizontalCtuOffsetPlus1 [ i ];}
-
-#endif
 #endif
 #if H_3D_QTLPC
@@ -1582,10 +1442,8 @@
   Int m_numExtraSliceHeaderBits;
 
-#if H_MV5
 #if H_MV
   Int  m_layerId; 
   Bool m_ppsInferScalingListFlag;
   Int  m_ppsScalingListRefLayerId;
-#endif
 #endif
 public:
@@ -1710,5 +1568,4 @@
   Bool getSliceHeaderExtensionPresentFlag   ()                    { return m_sliceHeaderExtensionPresentFlag; }
   Void setSliceHeaderExtensionPresentFlag   (Bool val)            { m_sliceHeaderExtensionPresentFlag = val; }
-#if H_MV5
 #if H_MV
   Void setLayerId( Int  val ) { m_layerId = val; } 
@@ -1720,5 +1577,4 @@
   Void setPpsScalingListRefLayerId( Int  val ) { m_ppsScalingListRefLayerId = val; } 
   Int  getPpsScalingListRefLayerId(  ) { return m_ppsScalingListRefLayerId; } 
-#endif
 #endif
 };
@@ -1754,11 +1610,11 @@
   Bool        m_PicOutputFlag;        ///< pic_output_flag 
   Int         m_iPOC;
-#if H_MV5
 #if H_MV
   Int         m_iPOCBeforeReset; 
 #endif
-#endif
   Int         m_iLastIDR;
-  static Int  m_prevPOC;
+  Int         m_iAssociatedIRAP;
+  NalUnitType m_iAssociatedIRAPType;
+  static Int  m_prevTid0POC;
   TComReferencePictureSet *m_pcRPS;
   TComReferencePictureSet m_LocalRPS;
@@ -1853,5 +1709,4 @@
   Bool       m_enableTMVPFlag;
 #if H_MV
-#if H_MV5
   std::vector<TComPic*>* m_refPicSetInterLayer0; 
   std::vector<TComPic*>* m_refPicSetInterLayer1; 
@@ -1862,31 +1717,11 @@
   Bool       m_isDepth;
 #endif
-#else
-  std::vector<TComPic*>* m_refPicSetInterLayer; 
-  Int        m_layerId; 
-  Int        m_viewId;
-#if H_3D
-  Int        m_viewIndex; 
-  Bool       m_isDepth;
-#endif
-#endif
 
 // Additional slice header syntax elements 
-#if H_MV5
   Bool       m_pocResetFlag; 
-#endif
   Bool       m_discardableFlag;
   Bool       m_interLayerPredEnabledFlag;
   Int        m_numInterLayerRefPicsMinus1;
   Int        m_interLayerPredLayerIdc       [MAX_NUM_LAYERS];
-#if !H_MV5
-  Bool       m_interLayerSamplePredOnlyFlag;
-  Bool       m_altCollocatedIndicationFlag;
-  Int        m_collocatedRefLayerIdx;
-// Additional slice header semantics variables
-  Int        m_numActiveMotionPredRefLayers;
-  Int        m_activeMotionPredRefLayerId   [ MAX_NUM_LAYER_IDS ];
-
-#endif
   Int        m_aaiCodedScale [2][MAX_NUM_LAYERS];
   Int        m_aaiCodedOffset[2][MAX_NUM_LAYERS];
@@ -1940,8 +1775,12 @@
   Void      setRPSidx          ( Int iBDidx ) { m_iBDidx = iBDidx; }
   Int       getRPSidx          () { return m_iBDidx; }
-  Int       getPrevPOC      ()                          { return  m_prevPOC;       }
+  Int       getPrevTid0POC      ()                        { return  m_prevTid0POC;       }
   TComRefPicListModification* getRefPicListModification() { return &m_RefPicListModification; }
   Void      setLastIDR(Int iIDRPOC)                       { m_iLastIDR = iIDRPOC; }
   Int       getLastIDR()                                  { return m_iLastIDR; }
+  Void      setAssociatedIRAPPOC(Int iAssociatedIRAPPOC)             { m_iAssociatedIRAP = iAssociatedIRAPPOC; }
+  Int       getAssociatedIRAPPOC()                        { return m_iAssociatedIRAP; }
+  Void      setAssociatedIRAPType(NalUnitType associatedIRAPType)    { m_iAssociatedIRAPType = associatedIRAPType; }
+  NalUnitType getAssociatedIRAPType()                        { return m_iAssociatedIRAPType; }
   SliceType getSliceType    ()                          { return  m_eSliceType;         }
   Int       getPOC          ()                          { return  m_iPOC;           }
@@ -1988,4 +1827,5 @@
   Void      checkColRefIdx      (UInt curSliceIdx, TComPic* pic);
   Bool      getIsUsedAsLongTerm (Int i, Int j)                  { return m_bIsUsedAsLongTerm[i][j]; }
+  Void      setIsUsedAsLongTerm (Int i, Int j, Bool value)      { m_bIsUsedAsLongTerm[i][j] = value; }
   Bool      getCheckLDC     ()                                  { return m_bCheckLDC; }
   Bool      getMvdL1ZeroFlag ()                                  { return m_bLMvdL1Zero;    }
@@ -1994,5 +1834,6 @@
   Void      setReferenced(Bool b)                               { m_bRefenced = b; }
   Bool      isReferenced()                                      { return m_bRefenced; }
-  Void      setPOC              ( Int i )                       { m_iPOC              = i; if(getTLayer()==0) m_prevPOC=i; }
+  Bool      isReferenceNalu()                                   { return ((getNalUnitType() <= NAL_UNIT_RESERVED_VCL_R15) && (getNalUnitType()%2 != 0)) || ((getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && (getNalUnitType() <= NAL_UNIT_RESERVED_IRAP_VCL23) ); }
+  Void      setPOC              ( Int i )                       { m_iPOC              = i; if ((getTLayer()==0) && (isReferenceNalu() && (getNalUnitType()!=NAL_UNIT_CODED_SLICE_RASL_R)&& (getNalUnitType()!=NAL_UNIT_CODED_SLICE_RADL_R))) {m_prevTid0POC=i;} }
   Void      setNalUnitType      ( NalUnitType e )               { m_eNalUnitType      = e;      }
   NalUnitType getNalUnitType    () const                        { return m_eNalUnitType;        }
@@ -2000,5 +1841,5 @@
   Bool      getIdrPicFlag       ()                              { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
   Bool      isIRAP              () const                        { return (getNalUnitType() >= 16) && (getNalUnitType() <= 23); }  
-  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic);
+  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic);
   Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic);
   Void      setSliceType        ( SliceType e )                 { m_eSliceType        = e;      }
@@ -2022,18 +1863,12 @@
   
 #if H_MV
-#if H_MV5
   Void      setPocBeforeReset   ( Int i )                       { m_iPOCBeforeReset = i; }
   Int       getPocBeforeReset   ( )                             { return m_iPOCBeforeReset; }
-#endif
   Int       getRefLayerId        ( RefPicList e, Int iRefIdx)    { return  m_aiRefLayerIdList[e][iRefIdx]; }
   Void      setRefLayerId        ( Int i, RefPicList e, Int iRefIdx ) { m_aiRefLayerIdList[e][iRefIdx] = i; }
-#if H_MV5
   Void      getTempRefPicLists   ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1,                                     
                                    std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr = false );
 
   Void      setRefPicList        ( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr = false ); 
-#else
-  Void      setRefPicList       ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& interLayerRefPicSet , Bool checkNumPocTotalCurr = false );
-#endif
 #else
 #if FIX1071
@@ -2082,20 +1917,12 @@
   Void setTLayerInfo( UInt uiTLayer );
   Void decodingMarking( TComList<TComPic*>& rcListPic, Int iGOPSIze, Int& iMaxRefPicNum ); 
+  Void checkLeadingPictureRestrictions( TComList<TComPic*>& rcListPic );
   Void applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *RPSList);
 #if H_MV
-#if !H_MV5
-  Void createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer );
-  static Void markIvRefPicsAsShortTerm    ( std::vector<TComPic*> refPicSetInterLayer );
-#else
   Void createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 );
   static Void markIvRefPicsAsShortTerm    ( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 );
-#endif
   static Void markCurrPic                 ( TComPic* currPic );; 
   static Void markIvRefPicsAsUnused       ( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc  );
-#if H_MV5
   Void        printRefPicList();
-#else
-  Void        xPrintRefPicList();
-#endif
 #endif
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
@@ -2184,8 +2011,6 @@
   Void      setViewId             ( Int viewId )     { m_viewId = viewId;   }
   Int       getViewId             ()                 { return m_viewId;     }
-#if H_MV5
   Void      setViewIndex          ( Int viewIndex )  { m_viewIndex = viewIndex;   }
   Int       getViewIndex          ()                 { return m_viewIndex;     }
-#endif
 #if H_3D
 #if H_3D_TMVP
@@ -2193,8 +2018,4 @@
   Void      setAlterRefIdx          ( RefPicList e, Int i ) { m_aiAlterRefIdx[e]    = i;      }
   Int       getAlterRefIdx          ( RefPicList e )        { return  m_aiAlterRefIdx[e];     }
-#endif
-#if !H_MV5
-  Void      setViewIndex          ( Int viewIndex )  { m_viewIndex = viewIndex;   }
-  Int       getViewIndex          ()                 { return m_viewIndex;     }
 #endif
   Void      setIsDepth            ( Bool isDepth )   { m_isDepth = isDepth; }
@@ -2219,8 +2040,6 @@
 // Additional slice header syntax elements
 
-#if H_MV5
   Void setPocResetFlag( Bool flag ) { m_pocResetFlag = flag; } 
   Bool getPocResetFlag(  ) { return m_pocResetFlag; } 
-#endif
 
 Void setDiscardableFlag( Bool flag ) { m_discardableFlag = flag; } 
@@ -2236,5 +2055,4 @@
 Int  getInterLayerPredLayerIdc( Int i ) { return m_interLayerPredLayerIdc[i]; } 
 
-#if H_MV5 
   // Additional variables derived in slice header semantics 
   Int  getNumInterLayerRefPicsMinus1Len( ) { return gCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerId() )); }
@@ -2250,32 +2068,4 @@
   Void     setRefPicSetInterLayer       ( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1);
   TComPic* getPicFromRefPicSetInterLayer( Int setIdc, Int layerId );
-#else
-Void setInterLayerSamplePredOnlyFlag( Bool flag ) { m_interLayerSamplePredOnlyFlag = flag; } 
-Bool getInterLayerSamplePredOnlyFlag(  ) { return m_interLayerSamplePredOnlyFlag; } 
-
-Void setAltCollocatedIndicationFlag( Bool flag ) { m_altCollocatedIndicationFlag = flag; } 
-Bool getAltCollocatedIndicationFlag(  ) { return m_altCollocatedIndicationFlag; } 
-
-Void setCollocatedRefLayerIdx( Int  val ) { m_collocatedRefLayerIdx = val; } 
-Int  getCollocatedRefLayerIdx(  ) { return m_collocatedRefLayerIdx; } 
-
-// Additional variables derived in slice header semantics 
-Int  getNumInterLayerRefPicsMinus1Len( ) { return xCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerIdInVps() )); }
-Int  getInterLayerPredLayerIdcLen    ( ) { return xCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerIdInVps() )); }
-
-Int  getNumActiveRefLayerPics( );
-Int  getRefPicLayerId               ( Int i );
-
-Void setActiveMotionPredRefLayers   ( );
-
-Int  getNumActiveMotionPredRefLayers(  )      { return m_numActiveMotionPredRefLayers; } 
-Int  getActiveMotionPredRefLayerId  ( Int i ) { return m_activeMotionPredRefLayerId[i]; } 
-
-Bool getInterRefEnabledInRPLFlag( );
-
-Void     setRefPicSetInterLayer       ( std::vector<TComPic*>* m_refPicSetInterLayer );
-TComPic* getPicFromRefPicSetInterLayer( Int layerId );
-
-#endif
 #endif
 protected:
@@ -2284,7 +2074,4 @@
 TComPic*  xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb);
 #if H_MV
-#if !H_MV5
-  Int       xCeilLog2( Int val );
-#endif
   TComPic*  xGetInterLayerRefPic( std::vector<TComPic*>& rcListIlPic, Int layerId );  
 #endif
@@ -2368,25 +2155,4 @@
   //! activate a SPS from a active parameter sets SEI message
   //! \returns true, if activation is successful
-#if !H_MV5
-  Bool activateSPSWithSEI(Int SPSId);
-
-  //! activate a PPS and depending on isIDR parameter also SPS and VPS
-  //! \returns true, if activation is successful
-  Bool activatePPS(Int ppsId, Bool isIRAP);
-
-  TComVPS* getActiveVPS(){ return m_vpsMap.getPS(m_activeVPSId); };
-  TComSPS* getActiveSPS(){ return m_spsMap.getPS(m_activeSPSId); };
-  TComPPS* getActivePPS(){ return m_ppsMap.getPS(m_activePPSId); };
-
-protected:
-  
-  ParameterSetMap<TComVPS> m_vpsMap;
-  ParameterSetMap<TComSPS> m_spsMap; 
-  ParameterSetMap<TComPPS> m_ppsMap;
-
-  Int m_activeVPSId;
-  Int m_activeSPSId;
-  Int m_activePPSId;
-#else
 #if H_MV
   Bool activateSPSWithSEI(Int SPSId, Int layerId );
@@ -2426,5 +2192,4 @@
 #endif
 
-#endif
 };
 
Index: trunk/source/Lib/TLibCommon/TComWedgelet.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComWedgelet.cpp	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComWedgelet.cpp	(revision 655)
@@ -175,474 +175,4 @@
 }
 
-#if !SEC_DMM2_E0146_HHIFIX
-Bool TComWedgelet::checkPredDirAbovePossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset )
-{
-  WedgeResolution eContDWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiPredDirBlockSize]];
-  UInt uiContDStartEndMax = 0;
-  UInt uiContDStartEndOffset = 0;
-  switch( eContDWedgeRes )
-  {
-  case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; }
-  case(   FULL_PEL ): { uiContDStartEndMax =  uiPredDirBlockSize;     uiContDStartEndOffset =  uiPredDirBlockOffset;     break; }
-  case(   HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; }
-  }
-
-  if( m_uhOri == 2 || m_uhOri == 3 || m_uhOri == 4 )
-  {
-    UInt uiThisStartEndMax = 0;
-    switch( m_eWedgeRes )
-    {
-    case( DOUBLE_PEL ): { uiThisStartEndMax = (m_uiWidth>>1); break; }
-    case(   FULL_PEL ): { uiThisStartEndMax =  m_uiWidth;     break; }
-    case(   HALF_PEL ): { uiThisStartEndMax = (m_uiWidth<<1); break; }
-    }
-
-    UChar uhStartX = m_uhXs;
-    UChar uhStartY = m_uhYs;
-    UChar uhEndX   = m_uhXe;
-    UChar uhEndY   = m_uhYe;
-
-    if( 2 == m_uhOri )
-    {
-      std::swap( uhStartX, uhEndX );
-      std::swap( uhStartY, uhEndY );
-    }
-
-    UInt uiScaledEndX = (UInt)uhEndX;
-    Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes;
-    if( iDeltaRes > 0 ) { uiScaledEndX <<=  iDeltaRes; }
-    if( iDeltaRes < 0 ) { uiScaledEndX >>= -iDeltaRes; }
-
-    if( ((UInt)uhEndY == (uiThisStartEndMax-1)) && ((uiScaledEndX-uiContDStartEndOffset) > 0 && (uiScaledEndX-uiContDStartEndOffset) < (uiContDStartEndMax-1)) )
-    {
-      return true;
-    }
-  }
-
-  return false;
-}
-
-Bool TComWedgelet::checkPredDirLeftPossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset )
-{
-  WedgeResolution eContDWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiPredDirBlockSize]];
-  UInt uiContDStartEndMax = 0;
-  UInt uiContDStartEndOffset = 0;
-  switch( eContDWedgeRes )
-  {
-  case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; }
-  case(   FULL_PEL ): { uiContDStartEndMax =  uiPredDirBlockSize;     uiContDStartEndOffset =  uiPredDirBlockOffset;     break; }
-  case(   HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; }
-  }
-
-  if( m_uhOri == 1 || m_uhOri == 2 || m_uhOri == 5 )
-  {
-    UInt uiThisStartEndMax = 0;
-    switch( m_eWedgeRes )
-    {
-    case( DOUBLE_PEL ): { uiThisStartEndMax = (m_uiHeight>>1); break; }
-    case(   FULL_PEL ): { uiThisStartEndMax =  m_uiHeight;     break; }
-    case(   HALF_PEL ): { uiThisStartEndMax = (m_uiHeight<<1); break; }
-    }
-
-    UChar uhStartX = m_uhXs;
-    UChar uhStartY = m_uhYs;
-    UChar uhEndX   = m_uhXe;
-    UChar uhEndY   = m_uhYe;
-
-    if( 1 == m_uhOri || 5 == m_uhOri )
-    {
-      std::swap( uhStartX, uhEndX );
-      std::swap( uhStartY, uhEndY );
-    }
-
-    UInt uiScaledEndY = (UInt)uhEndY;
-    Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes;
-    if( iDeltaRes > 0 ) { uiScaledEndY <<=  iDeltaRes; }
-    if( iDeltaRes < 0 ) { uiScaledEndY >>= -iDeltaRes; }
-
-    if( ((UInt)uhEndX == (uiThisStartEndMax-1)) && ((uiScaledEndY-uiContDStartEndOffset) > 0 && (uiScaledEndY-uiContDStartEndOffset) < (uiContDStartEndMax-1)) )
-    {
-      return true;
-    }
-  }
-
-  return false;
-}
-
-Void TComWedgelet::getPredDirStartEndAbove( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd )
-{
-  ruhXs = 0;
-  ruhYs = 0;
-  ruhXe = 0;
-  ruhYe = 0;
-
-  // get start/end of reference (=this) wedgelet
-  UInt uiRefStartX = (UInt)getStartX();
-  UInt uiRefStartY = (UInt)getStartY();
-  UInt uiRefEndX   = (UInt)getEndX();
-  UInt uiRefEndY   = (UInt)getEndY();
-
-  WedgeResolution eContDWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiPredDirBlockSize]];
-  UInt uiContDStartEndMax = 0;
-  UInt uiContDStartEndOffset = 0;
-  switch( eContDWedgeRes )
-  {
-  case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; }
-  case(   FULL_PEL ): { uiContDStartEndMax =  uiPredDirBlockSize;     uiContDStartEndOffset =  uiPredDirBlockOffset;     break; }
-  case(   HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; }
-  }
-  Int iContDMaxPos = (Int)uiContDStartEndMax - 1;
-
-  // swap if start/end if line orientation is not from top to bottom
-  if( 2 == (UInt)getOri() )
-  {
-    std::swap( uiRefStartX, uiRefEndX );
-    std::swap( uiRefStartY, uiRefEndY );
-  }
-
-  // calc slopes
-  Int iA_DeltaX = (Int)uiRefEndX - (Int)uiRefStartX;
-  Int iA_DeltaY = (Int)uiRefEndY - (Int)uiRefStartY;
-
-  // get aligned end x value of ref wedge
-  UInt uiScaledRefEndX = uiRefEndX;
-  Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes;
-  if( iDeltaRes > 0 ) { uiScaledRefEndX <<=  iDeltaRes; }
-  if( iDeltaRes < 0 ) { uiScaledRefEndX >>= -iDeltaRes; }
-
-  assert( uiScaledRefEndX >= uiContDStartEndOffset );
-  Int iAlignedRefEndX = (Int)uiScaledRefEndX - (Int)uiContDStartEndOffset;
-
-  // special for straight vertical wedge
-  if( iA_DeltaX == 0 )
-  {
-    ruhXs = (UChar)iAlignedRefEndX;
-    ruhYs = 0;
-
-    Int iXe = iAlignedRefEndX + iDeltaEnd;
-    if( iXe < 0 )
-    {
-      ruhXe = 0;
-      ruhYe = (UChar)min( max( (iContDMaxPos + iXe), 0 ), iContDMaxPos );
-
-      return;
-    }
-    else if( iXe > iContDMaxPos )
-    {
-      ruhXe = (UChar)iContDMaxPos;
-      ruhYe = (UChar)min( max( (iContDMaxPos - (iXe - iContDMaxPos)), 0 ), iContDMaxPos );
-
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-    else
-    {
-      ruhXe = (UChar)iXe;
-      ruhYe = (UChar)iContDMaxPos;
-
-      return;
-    }
-  }
-
-  // special for straight horizontal short bottom line
-  if( iA_DeltaY == 0 )
-  {
-    switch( (UInt)getOri() )
-    {
-    case( 2 ):
-      {
-        ruhXs = (UChar)(iAlignedRefEndX-1);
-        ruhYs = 0;
-        ruhXe = 0;
-        ruhYe = (UChar)min( max( iDeltaEnd, 0 ), iContDMaxPos );
-
-        return;
-      }
-    case( 3 ):
-      {
-        ruhXs = (UChar)(iAlignedRefEndX+1);
-        ruhYs = 0;
-        ruhXe = (UChar)iContDMaxPos;
-        ruhYe = (UChar)min( max( -iDeltaEnd, 0 ), iContDMaxPos );
-
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-    default:
-      {
-        assert( 0 );
-        return;
-      }
-    }
-  }
-
-  // set start point depending on slope
-  if( abs( iA_DeltaX ) >= abs( iA_DeltaY ) ) { if( iA_DeltaX < 0 ) { ruhXs = (UChar)(iAlignedRefEndX-1); ruhYs = 0; }
-                                                if( iA_DeltaX > 0 ) { ruhXs = (UChar)(iAlignedRefEndX+1); ruhYs = 0; } }
-  else                                                             { ruhXs = (UChar)(iAlignedRefEndX);   ruhYs = 0;   }
-
-  // calc end point and determine orientation
-  Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iContDMaxPos * ((Double)iA_DeltaX / (Double)iA_DeltaY) );
-
-  if( iVirtualEndX < 0 )
-  {
-    Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iA_DeltaY / (Double)iA_DeltaX) ) + iDeltaEnd;
-    if( iYe < (Int)uiContDStartEndMax )
-    {
-      ruhXe = 0;
-      ruhYe = (UChar)max( iYe, 0 );
-
-      return;
-    }
-    else
-    {
-      ruhXe = (UChar)min( (iYe - iContDMaxPos), iContDMaxPos );
-      ruhYe = (UChar)iContDMaxPos;
-
-      return;
-    }
-  }
-  else if( iVirtualEndX > iContDMaxPos )
-  {
-    Int iYe = roftoi( (Double)(iContDMaxPos - (Int)ruhXs) * ((Double)iA_DeltaY / (Double)iA_DeltaX) ) - iDeltaEnd;
-    if( iYe < (Int)uiContDStartEndMax )
-    {
-      ruhXe = (UChar)iContDMaxPos;
-      ruhYe = (UChar)max( iYe, 0 );
-
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-    else
-    {
-      ruhXe = (UChar)max( (iContDMaxPos - (iYe - iContDMaxPos)), 0 );
-      ruhYe = (UChar)iContDMaxPos;
-
-      return;
-    }
-  }
-  else
-  {
-    Int iXe = iVirtualEndX + iDeltaEnd;
-    if( iXe < 0 )
-    {
-      ruhXe = 0;
-      ruhYe = (UChar)max( (iContDMaxPos + iXe), 0 );
-
-      return;
-    }
-    else if( iXe > iContDMaxPos )
-    {
-      ruhXe = (UChar)iContDMaxPos;
-      ruhYe = (UChar)max( (iContDMaxPos - (iXe - iContDMaxPos)), 0 );
-
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-    else
-    {
-      ruhXe = (UChar)iXe;
-      ruhYe = (UChar)iContDMaxPos;
-
-      return;
-    }
-  }
-}
-
-Void TComWedgelet::getPredDirStartEndLeft( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd )
-{
-  ruhXs = 0;
-  ruhYs = 0;
-  ruhXe = 0;
-  ruhYe = 0;
-
-  // get start/end of reference (=this) wedgelet
-  UInt uiRefStartX = (UInt)getStartX();
-  UInt uiRefStartY = (UInt)getStartY();
-  UInt uiRefEndX   = (UInt)getEndX();
-  UInt uiRefEndY   = (UInt)getEndY();
-
-  WedgeResolution eContDWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiPredDirBlockSize]];
-  UInt uiContDStartEndMax = 0;
-  UInt uiContDStartEndOffset = 0;
-  switch( eContDWedgeRes )
-  {
-  case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; }
-  case(   FULL_PEL ): { uiContDStartEndMax =  uiPredDirBlockSize;     uiContDStartEndOffset =  uiPredDirBlockOffset;     break; }
-  case(   HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; }
-  }
-  Int iContDMaxPos = (Int)uiContDStartEndMax - 1;
-
-  // swap if start/end if line orientation is not from left to right
-  if( 1 == (UInt)getOri() || 5 == (UInt)getOri() )
-  {
-    std::swap( uiRefStartX, uiRefEndX );
-    std::swap( uiRefStartY, uiRefEndY );
-  }
-
-  Int iL_DeltaX = (Int)uiRefEndX - (Int)uiRefStartX;
-  Int iL_DeltaY = (Int)uiRefEndY - (Int)uiRefStartY;
-
-  UInt uiScaledRefEndY = uiRefEndY;
-  Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes;
-  if( iDeltaRes > 0 ) { uiScaledRefEndY <<=  iDeltaRes; }
-  if( iDeltaRes < 0 ) { uiScaledRefEndY >>= -iDeltaRes; }
-
-  assert( uiScaledRefEndY >= uiContDStartEndOffset );
-  Int iAlignedRefEndY = (Int)uiScaledRefEndY - (Int)uiContDStartEndOffset;
-
-  // special for straight horizontal wedge
-  if( iL_DeltaY == 0 )
-  {
-    ruhXs = 0;
-    ruhYs = (UChar)iAlignedRefEndY;
-
-    Int iYe = iAlignedRefEndY - iDeltaEnd;
-    if( iYe < 0 )
-    {
-      ruhXe = (UChar)min( max( (iContDMaxPos + iYe), 0 ), iContDMaxPos );
-      ruhYe = 0;
-
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-    else if( iYe > iContDMaxPos )
-    {
-      ruhXe = (UChar)min( max( (iContDMaxPos - (iYe - iContDMaxPos)), 0 ), iContDMaxPos );
-      ruhYe = (UChar)iContDMaxPos;
-
-      return;
-    }
-    else
-    {
-      ruhXe = (UChar)iContDMaxPos;
-      ruhYe = (UChar)iYe;
-
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-  }
-
-  // special for straight vertical short right line
-  if( iL_DeltaX == 0 )
-  {
-    switch( (UInt)getOri() )
-    {
-    case( 1 ):
-      {
-        ruhXs = 0;
-        ruhYs = (UChar)(iAlignedRefEndY+1);
-        ruhXe = (UChar)min( max( iDeltaEnd, 0 ), iContDMaxPos );
-        ruhYe = (UChar)iContDMaxPos;
-
-        return;
-      }
-    case( 2 ):
-      {
-        ruhXs = 0;
-        ruhYs = (UChar)(iAlignedRefEndY-1);
-        ruhXe = (UChar)min( max( -iDeltaEnd, 0 ), iContDMaxPos );
-        ruhYe = 0;
-
-        std::swap( ruhXs, ruhXe );
-        std::swap( ruhYs, ruhYe );
-        return;
-      }
-    default:
-      {
-        assert( 0 );
-        return;
-      }
-    }
-  }
-
-  // set start point depending on slope
-  if( abs( iL_DeltaY ) >= abs( iL_DeltaX ) ) { if( iL_DeltaY < 0 ) { ruhYs = (UChar)(iAlignedRefEndY-1); ruhXs = 0; }
-                                               if( iL_DeltaY > 0 ) { ruhYs = (UChar)(iAlignedRefEndY+1); ruhXs = 0; } }
-  else                                       {                       ruhYs = (UChar)(iAlignedRefEndY);   ruhXs = 0;   }
-
-  // calc end point and determine orientation
-  Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iContDMaxPos * ((Double)iL_DeltaY / (Double)iL_DeltaX) );
-
-  if( iVirtualEndY < 0 )
-  {
-    Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iL_DeltaX / (Double)iL_DeltaY) ) - iDeltaEnd;
-    if( iXe < (Int)uiContDStartEndMax )
-    {
-      ruhXe = (UChar)max( iXe, 0 );
-      ruhYe = 0;
-
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-    else
-    {
-      ruhXe = (UChar)iContDMaxPos;
-      ruhYe = (UChar)min( (iXe - iContDMaxPos), iContDMaxPos );
-
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-  }
-  else if( iVirtualEndY > iContDMaxPos )
-  {
-    Int iXe = roftoi( (Double)(iContDMaxPos - (Int)ruhYs ) * ((Double)iL_DeltaX / (Double)iL_DeltaY) ) + iDeltaEnd;
-    if( iXe < (Int)uiContDStartEndMax )
-    {
-      ruhXe = (UChar)max( iXe, 0 );
-      ruhYe = (UChar)iContDMaxPos;
-
-      return;
-    }
-    else
-    {
-      ruhXe = (UChar)iContDMaxPos;
-      ruhYe = (UChar)max( (iContDMaxPos - (iXe - iContDMaxPos)), 0 );
-
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-  }
-  else
-  {
-    Int iYe = iVirtualEndY - iDeltaEnd;
-    if( iYe < 0 )
-    {
-      ruhXe = (UChar)max( (iContDMaxPos + iYe), 0 );
-      ruhYe = 0;
-
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-    else if( iYe > iContDMaxPos )
-    {
-      ruhXe = (UChar)max( (iContDMaxPos - (iYe - iContDMaxPos)), 0 );
-      ruhYe = (UChar)iContDMaxPos;
-
-      return;
-    }
-    else
-    {
-      ruhXe = (UChar)iContDMaxPos;
-      ruhYe = (UChar)iYe;
-
-      std::swap( ruhXs, ruhXe );
-      std::swap( ruhYs, ruhYe );
-      return;
-    }
-  }
-}
-#endif
-
 Void TComWedgelet::xGenerateWedgePattern()
 {
Index: trunk/source/Lib/TLibCommon/TComWedgelet.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComWedgelet.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComWedgelet.h	(revision 655)
@@ -50,22 +50,11 @@
 enum DIM_IDX
 {
-#if SEC_DMM2_E0146_HHIFIX
   DMM1_IDX = 0,
   DMM3_IDX = 1,
   DMM4_IDX = 2,
   RBC_IDX  = 3
-#else
-  DMM1_IDX = 0,
-  DMM2_IDX = 3,
-  DMM3_IDX = 1,
-  DMM4_IDX = 2,
-  RBC_IDX  = 4
-#endif
 };
-#if SEC_DMM2_E0146_HHIFIX
+
 #define DMM_NUM_TYPE   3
-#else
-#define DMM_NUM_TYPE   4
-#endif
 #define RBC_NUM_TYPE   1
 #define DIM_NUM_TYPE   (DMM_NUM_TYPE+RBC_NUM_TYPE)
@@ -86,7 +75,4 @@
 #define DMM_NO_WEDGEINDEX       MAX_UINT
 #define DMM_NUM_WEDGE_REFINES   8
-#if !SEC_DMM2_E0146_HHIFIX
-#define DMM2_DELTAEND_MAX       4
-#endif
 #define DMM3_SIMPLIFY_TR        1
 
@@ -151,11 +137,4 @@
   Bool  checkInvIdentical( Bool* pbRefPattern );
 
-#if !SEC_DMM2_E0146_HHIFIX
-  // functions for DMM2 prediction
-  Bool  checkPredDirAbovePossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffsett );
-  Bool  checkPredDirLeftPossible ( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffsett );
-  Void  getPredDirStartEndAbove( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd );
-  Void  getPredDirStartEndLeft ( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd );
-#endif
 };  // END CLASS DEFINITION TComWedgelet
 
Index: trunk/source/Lib/TLibCommon/TComWeightPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComWeightPrediction.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TComWeightPrediction.h	(revision 655)
@@ -53,6 +53,4 @@
 class TComWeightPrediction
 {
-  wpScalingParam  m_wp0[3], m_wp1[3];
-
 public:
   TComWeightPrediction();
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 625)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 655)
@@ -92,9 +92,14 @@
                                               // QC_CU_NBDV_D0181
                                               // SEC_DEFAULT_DV_D0112
-                                              // MTK_DVMCP_FIX_E0172               1 // fix the mismatch between software and WD for DV derivation from DVMCP blocks, issue 2 in JCT3V-E0172
+                                              // MTK_DVMCP_FIX_E0172       fix the mismatch between software and WD for DV derivation from DVMCP blocks, issue 2 in JCT3V-E0172
+                                              // SEC_SIMPLIFIED_NBDV_E0142 Simplified NBDV, JCT3V-E0142 and JCT3V-E0190
+                                              // MTK_NBDV_TN_FIX_E0172     fix the issue of DV derivation from the temporal neighboring blocks, issue 7 in JCT3V-E0172
+                                              // MTK_TEXTURE_MRGCAND_BUGFIX_E0182  Bug fix for TEXTURE MERGING CANDIDATE     , JCT3V-E0182
 #define H_3D_ARP                          1   // Advanced residual prediction (ARP), JCT3V-D0177
 #define H_3D_IC                           1   // Illumination Compensation, JCT3V-B0045, JCT3V-C0046, JCT3V-D0060
                                               // Unifying rounding offset, for IC part, JCT3V-D0135
                                               // Full Pel Interpolation for Depth, HHI_FULL_PEL_DEPTH_MAP_MV_ACC
+                                              // SHARP_ILLUCOMP_REFINE_E0046
+                                              // MTK_CLIPPING_ALIGN_IC_E0168       // To support simplify bi-prediction PU with identical motion checking, JCT3V-E0168
 
 #if H_3D_NBDV
@@ -103,4 +108,7 @@
                                               // MERL_D0166: Reference view selection in NBDV & Bi-VSP
                                               // MERL_C0152: Basic VSP
+                                              // NBDV_DEFAULT_VIEWIDX_BUGFIX Bug fix for invalid default view index for NBDV
+                                              // NTT_DoNBDV_VECTOR_CLIP_E0141 disparity vector clipping in DoNBDV, JCT3V-E0141 and JCT3V-E0209
+
 #endif
 
@@ -112,4 +120,7 @@
                                               // LG_D0092: Multiple VSP candidate allowed
                                               // MTK_VSP_FIX_ALIGN_WD_E0172
+                                              // NTT_VSP_ADAPTIVE_SPLIT_E0207 adaptive sub-PU partitioning in VSP, JCT3V-E0207
+                                              // NTT_VSP_DC_BUGFIX_E0208 bugfix for sub-PU based DC in VSP, JCT3V-E0208
+                                              // NTT_VSP_COMMON_E0207_E0208 common part of JCT3V-E0207 and JCT3V-E0208
 #define H_3D_IV_MERGE                     1   // Inter-view motion merge candidate
                                               // HHI_INTER_VIEW_MOTION_PRED 
@@ -139,77 +150,37 @@
                                               // FIX_SDC_ENC_RD_WVSO_D0163
                                               // MTK_SAMPLE_BASED_SDC_D0110
-
-
-
-/////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////   HTM-8.0 INTEGRATIONS //////////////////////////////
-/////////////////////////////////////////////////////////////////////////////////////////
-
-#define SHARP_ILLUCOMP_REFINE_E0046       1
-#define MTK_FAST_TEXTURE_ENCODING_E0173   1   // Fast merge mode decision and early CU determination for texture component of dependent view, JCT3V-E0173
-#define MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170            1   // Progressive MV Compression, JCT3V-E0170
-#define LGE_INTER_SDC_E0156               1   // Enable inter SDC for depth coding
-
-#if H_3D_IC
-#define MTK_CLIPPING_ALIGN_IC_E0168       1   // To support simplify bi-prediction PU with identical motion checking, JCT3V-E0168
-#endif
-
-#if H_3D_NBDV
-#define NBDV_DEFAULT_VIEWIDX_BUGFIX       1  // Bug fix for invalid default view index for NBDV
-#define MTK_RVS_BUGFIX_E0172              1  // Bug fix for issues caused by reference view selection, JCT3V-E0172
-#define MTK_TEXTURE_MRGCAND_BUGFIX_E0182  1  // Bug fix for TEXTURE MERGING CANDIDATE     , JCT3V-E0182
-
-#if MTK_RVS_BUGFIX_E0172
-#define MTK_DIVMC_FIX_E0172               1 // fix the issue of derivation of disparity inter-view merge candidate, issue 5 in JCT3V-E0172
-#define MTK_NBDV_TN_FIX_E0172             1 // fix the issue of DV derivation from the temporal neighboring blocks, issue 7 in JCT3V-E0172
-#endif // MTK_RVS_BUGFIX_E0172
-
-#if H_3D_NBDV_REF
-#define NTT_DoNBDV_VECTOR_CLIP_E0141      1   // disparity vector clipping in DoNBDV, JCT3V-E0141 and JCT3V-E0209
-#define SEC_SIMPLIFIED_NBDV_E0142         1   // Simplified NBDV, JCT3V-E0142 and JCT3V-E0190
-#endif
-#endif // H_3D_NBDV
-
+                                              // SEC_DMM2_E0146_HHIFIX Removal of DMM2 from DMMs
+                                              // ZJU_DEPTH_INTRA_MODE_E0204 Simplified Binarization for depth_intra_mode
+                                              // KWU_SDC_SIMPLE_DC_E0117 Simplified DC calculation for SDC
+                                              // SCU_HS_DMM4_REMOVE_DIV_E0242 DMM4 Division Removal
+                                              // LGE_SDC_REMOVE_DC_E0158 Removal of DC mode from SDC
+                                              // LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX 1   Removal of overlap between DMM3 and DMM1
+
+#define H_3D_INTER_SDC                    1   // INTER SDC, Inter simplified depth coding
+                                              // LGE_INTER_SDC_E0156  Enable inter SDC for depth coding
+#define H_3D_FCO                          0   // Flexible coding order for 3D
+
+
+
+// OTHERS
+                                              // MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170 // Progressive MV Compression, JCT3V-E0170
+#define H_3D_REN_MAX_DEV_OUT              0   // Output maximal possible shift deviation 
+#define H_3D_FAST_TEXTURE_ENCODING        1   // Fast merge mode decision and early CU determination for texture component of dependent view, JCT3V-E0173
+                                              // MTK_FAST_TEXTURE_ENCODING_E0173
 #if H_3D_DIM
-#define SEC_DMM2_E0146_HHIFIX             1   // Removal of DMM2 from DMMs
-#define ZJU_DEPTH_INTRA_MODE_E0204        1   // Simplified Binarization for depth_intra_mode
-#define KWU_SDC_SIMPLE_DC_E0117           1   // Simplified DC calculation for SDC
-#define SCU_HS_DMM4_REMOVE_DIV_E0242      1   // DMM4 Division Removal
-#define SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX     1   // Fast DMM and RBC Mode Selection
-#endif
-
-#if H_3D_VSP
-#define NTT_VSP_COMMON_E0207_E0208        1 // common part of JCT3V-E0207 and JCT3V-E0208
-#if NTT_VSP_COMMON_E0207_E0208
-#define NTT_VSP_DC_BUGFIX_E0208           1 // bugfix for sub-PU based DC in VSP, JCT3V-E0208
-#define NTT_VSP_VECTOR_CLIP_E0208         1 // disparity vector clipping on fetching depth map in VSP, JCT3V-E0208
-#define NTT_VSP_ADAPTIVE_SPLIT_E0207      1 // adaptive sub-PU partitioning in VSP, JCT3V-E0207
-#endif
-#endif
-
-#define H_3D_REN_MAX_DEV_OUT              0  // Output maximal possible shift deviation 
-
-/// FIXES
-#define H_3D_FIX_BVSP                     1  // DV from NBDV instead of DoNBDV should be used
-#define H_3D_FIX_TICKET_036               1  // fix for ticket #36
-#define H_3D_FIX_REN                      1  // fix of erroneous inpainting for renderer
-#define H_3D_FIX_REN_WARNING              1  // fix of warning related to camera parameter precision
-
-#define H_3D_FIX_UINT_WARNING             1  // explicit in VSD
+#define H_3D_FAST_DEPTH_INTRA             1   // Fast DMM and RBC Mode Selection
+                                              // SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
+#endif
+
+
+// Rate Control
+#define KWU_FIX_URQ                       1
+#define KWU_RC_VIEWRC_E0227               0  ///< JCT3V-E0227, view-wise target bitrate allocation
+#define KWU_RC_MADPRED_E0227              0  ///< JCT3V-E0227, inter-view MAD prediction
+
 #endif // H_3D
 
 
-/////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////   HTM-8.1 INTEGRATIONS //////////////////////////////
-/////////////////////////////////////////////////////////////////////////////////////////
-
-// Please put HTM-8.1 Integration defines here, when possible 
-
-
-/// FIXES
-#if H_MV
-#define H_MV_FIX_LID_PIC_HASH_SEI_T40                      1   // Fix wrong layer_id in decoded picture hash SEI 
-#define H_MV5                                              1   // Update to MV-HEVC 5 HLS
-#endif
+
 /////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////   DERIVED DEFINES ///////////////////////////////////  
@@ -223,22 +194,12 @@
 #define H_3D_VSO_RM_ASSERTIONS            0   // Output VSO assertions
 #define H_3D_VSO_SYNTH_DIST_OUT           0   // Output of synthesized view distortion instead of depth distortion in encoder output
-
 #define H_3D_VSO_FIX                      0   // This fix should be enabled after verification 
-
-#endif
-////   ****** Neighbouring block-based Disparity Vector  *********
+#endif
+
+////   ****** neighbouring block-based disparity vector  *********
 #if H_3D_NBDV
-#if SEC_SIMPLIFIED_NBDV_E0142
 #define DVFROM_LEFT                       0
 #define DVFROM_ABOVE                      1
 #define IDV_CANDS                         2
-#else
-#define DVFROM_LEFTBELOW                  0
-#define DVFROM_LEFT                       1
-#define DVFROM_ABOVERIGHT                 2
-#define DVFROM_ABOVE                      3
-#define DVFROM_ABOVELEFT                  4
-#define IDV_CANDS                         5
-#endif
 #endif
 
@@ -247,4 +208,5 @@
 #define H_3D_ARP_WFNR                     3
 #endif
+
 ///// ***** DEPTH INTRA MODES *********
 #if H_3D_DIM
@@ -256,12 +218,5 @@
                                               // HHI_DEPTH_INTRA_SEARCH_RAU_C0160
                                               // LG_ZEROINTRADEPTHRESI_A0087
-#if H_3D_DIM_SDC
-#define LGE_SDC_REMOVE_DC_E0158           1   // Removal of DC mode from SDC
-#endif
-#if H_3D_DIM_DMM
-#define LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX 1   // Removal of overlap between DMM3 and DMM1
-#endif
-#endif
-
+#endif
 ///// ***** VIEW SYNTHESIS PREDICTION *********
 #if H_3D_VSP
@@ -273,4 +228,18 @@
 #endif
 
+#endif
+
+///// ***** ILLUMATION COMPENSATION *********
+#if H_3D_IC
+#define IC_REG_COST_SHIFT                 7
+#define IC_CONST_SHIFT                    5
+#define IC_SHIFT_DIFF                     12
+#endif
+
+///// ***** FCO *********
+#if H_3D_FCO
+#define H_3D_FCO_VSP_DONBDV_E0163               1   // Adaptive depth reference for flexible coding order
+#else
+#define H_3D_FCO_VSP_DONBDV_E0163               0   // Adaptive depth reference for flexible coding order
 #endif
 
@@ -300,6 +269,14 @@
 #define TICKET_1090_FIX                             1
 
+#if KWU_FIX_URQ
+#if RATE_CONTROL_LAMBDA_DOMAIN
 #define RC_FIX                                      1  /// suggested fix for M0036
 #define RATE_CONTROL_INTRA                          1  ///< JCTVC-M0257, rate control for intra 
+#endif
+#else
+#define RC_FIX                                      1  /// suggested fix for M0036
+#define RATE_CONTROL_INTRA                          1  ///< JCTVC-M0257, rate control for intra 
+#endif
+
 
 #define MAX_CPB_CNT                     32  ///< Upper bound of (cpb_cnt_minus1 + 1)
@@ -484,9 +461,5 @@
 
 #if H_3D_VSO_DIST_INT
-#if H_3D_FIX_TICKET_036
 typedef       Int64            Dist;       ///< RDO distortion
-#else
-typedef       Int              Dist;       ///< RDO distortion
-#endif
 typedef       Int64            Dist64; 
 #define       RDO_DIST_MIN     MIN_INT
@@ -793,15 +766,8 @@
   enum ScalabilityType
   {
-#if H_MV5
 #if H_3D
     DEPTH_ID = 0,    
 #endif    
     VIEW_ORDER_INDEX  = 1,
-#else
-    VIEW_ID  = 0,
-#if H_3D
-    DEPTH_ID = 1,    
-#endif    
-#endif
   };
 #endif
Index: trunk/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 625)
+++ trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 655)
@@ -315,4 +315,5 @@
 
   /* restore primary bitstream for sei_message */
+  getBitstream()->deleteFifo();
   delete getBitstream();
   setBitstream(bs);
Index: trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 625)
+++ trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 655)
@@ -58,9 +58,9 @@
   if (length < 10)
   {
-    fprintf( g_hTrace, "%-50s u(%d)  : %d\n", pSymbolName, length, rValue ); 
+    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue ); 
   }
   else
   {
-    fprintf( g_hTrace, "%-50s u(%d) : %d\n", pSymbolName, length, rValue ); 
+    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue ); 
   }
   fflush ( g_hTrace );
@@ -77,5 +77,5 @@
 #endif
   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
-  fprintf( g_hTrace, "%-50s ue(v) : %d\n", pSymbolName, rValue ); 
+  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue ); 
   fflush ( g_hTrace );
 }
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 655)
@@ -330,5 +330,4 @@
     }
   }
-#if H_MV5
 #if H_MV
   if ( pcPPS->getLayerId() > 0 )
@@ -344,5 +343,4 @@
   {  
 #endif
-#endif
   READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
   if(pcPPS->getScalingListPresentFlag ())
@@ -350,8 +348,6 @@
     parseScalingList( pcPPS->getScalingList() );
   }
-#if H_MV5
-#if H_MV
-  }
-#endif
+#if H_MV
+  }
 #endif
 
@@ -430,10 +426,4 @@
   {
     Window &defDisp = pcVUI->getDefaultDisplayWindow();
-#if !H_MV5
-    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
-    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
-    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
-    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
-#else
 #if H_MV
     defDisp.setScaledFlag( false ); 
@@ -448,5 +438,4 @@
     READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
 #endif
-#endif
   }
   TimingInfo *timingInfo = pcVUI->getTimingInfo();
@@ -471,12 +460,4 @@
   {
     READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
-#if !H_MV5
-#if H_MV
-    if ( pcSPS->getLayerId() > 0 )
-    {
-      READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVUI->setTileBoundariesAlignedFlag( uiCode == 1 );
-    }
-#endif
-#endif
     READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
     READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
@@ -597,5 +578,4 @@
   READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
   assert(uiCode <= 15);
-#if H_MV5
 #if H_MV
   if ( pcSPS->getLayerId() > 0 )
@@ -606,5 +586,4 @@
   if ( pcSPS->getUpdateRepFormatFlag() )
   { 
-#endif
 #endif
   READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
@@ -619,8 +598,6 @@
   READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
   READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
-#if H_MV5
-#if H_MV
-  }
-#endif
+#if H_MV
+  }
 #endif
   READ_FLAG(     uiCode, "conformance_window_flag");
@@ -628,5 +605,4 @@
   {
     Window &conf = pcSPS->getConformanceWindow();
-#if H_MV5
 #if H_MV
     // Needs to be scaled later, when ChromaFormatIdc is known. 
@@ -642,17 +618,9 @@
     READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
 #endif
-#else
-    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
-    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
-    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
-    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
-#endif
-  }
-
-#if H_MV5
+  }
+
 #if H_MV
   if ( pcSPS->getUpdateRepFormatFlag() )
   { 
-#endif
 #endif
   READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
@@ -665,8 +633,6 @@
   pcSPS->setBitDepthC( uiCode + 8 );
   pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
-#if H_MV5
-#if H_MV
-  }
-#endif
+#if H_MV
+  }
 #endif
 
@@ -692,9 +658,5 @@
     pcSPS->setNumReorderPics(uiCode, i);
 #if H_MV
-#if H_MV5
     READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
-#else
-    READ_UVLC ( uiCode, "sps_max_latency_increase[i]");
-#endif
 #else
     READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
@@ -736,5 +698,4 @@
   if(pcSPS->getScalingListFlag())
   {
-#if H_MV5
 #if H_MV
     if ( pcSPS->getLayerId() > 0 )
@@ -750,5 +711,4 @@
     {    
 #endif
-#endif
     READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
     if(pcSPS->getScalingListPresentFlag ())
@@ -756,8 +716,6 @@
       parseScalingList( pcSPS->getScalingList() );
     }
-#if H_MV5
-#if H_MV
-    }
-#endif
+#if H_MV
+    }
 #endif
   }
@@ -814,84 +772,4 @@
   if (uiCode)
   {
-#if !H_MV5
-#if !H_MV
-    while ( xMoreRbspData() )
-    {
-      READ_FLAG( uiCode, "sps_extension_data_flag");
-    }
-#else
-    READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
-    ////   sps_extension_vui_parameters( )
-    if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
-    {  
-      READ_UVLC( uiCode, "num_ilp_restricted_ref_layers" ); pcSPS->setNumIlpRestrictedRefLayers( uiCode ); 
-      for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ ) 
-      {  
-        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcSPS->setMinSpatialSegmentOffsetPlus1( i, uiCode ); 
-        if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 ) 
-        {  
-          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[ i ]"); pcSPS->setCtuBasedOffsetEnabledFlag(i, uiCode == 1 ); 
-          if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) )  
-          {
-            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[ i ]"); pcSPS->setMinHorizontalCtuOffsetPlus1( i, uiCode ); 
-          }
-        }  
-      }  
-    }
-
-#if H_3D_QTLPC
-    if( depthFlag )
-    {
-      READ_FLAG( uiCode, "use_qtl_flag" );
-      pcSPS->setUseQTL( uiCode );
-      READ_FLAG( uiCode, "use_pc_flag" );
-      pcSPS->setUsePC( uiCode );
-    }
-#endif
-    ////   sps_extension_vui_parameters( ) END
-    READ_UVLC( uiCode, "sps_shvc_reserved_zero_idc" ); 
-    READ_FLAG( uiCode, "sps_extension2_flag");
-    if ( uiCode )
-    {
-#if !H_3D
-      while ( xMoreRbspData() )
-      {
-        READ_FLAG( uiCode, "sps_extension_data_flag");
-      }
-#else
-      
-      UInt uiCamParPrecision = 0; 
-      Bool bCamParSlice      = false; 
-      if ( !depthFlag )
-      {      
-        READ_UVLC( uiCamParPrecision, "cp_precision" );
-        READ_FLAG( uiCode, "cp_in_slice_header_flag" );    bCamParSlice = ( uiCode == 1 );
-        if( !bCamParSlice )
-        {       
-          for( UInt uiBaseIndex = 0; uiBaseIndex < viewIndex; uiBaseIndex++ )
-          {
-            Int iCode; 
-            READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale  [ uiBaseIndex ][ viewIndex ]   = iCode;
-            READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset [ uiBaseIndex ][ viewIndex ]   = iCode;
-            READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale  [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ viewIndex ];
-            READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ viewIndex ];
-          }
-        }
-      }
-      pcSPS->initCamParaSPS( viewIndex, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset );
-      READ_FLAG( uiCode, "sps_extension3_flag");
-      if ( uiCode )
-      {
-        while ( xMoreRbspData() )
-        {
-          READ_FLAG( uiCode, "sps_extension_data_flag");
-        }
-      }
-#endif // !H_3D
-    }
-#endif // !H_MV
-  }
-}
-#else 
 #if H_MV
     parseSPSExtension( pcSPS ); 
@@ -918,6 +796,6 @@
   }
 }
-#endif
-#if H_MV5
+
+#if H_MV
 Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
 {
@@ -972,9 +850,5 @@
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
 #if H_MV
-#if H_MV5
   READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayersMinus1( uiCode  );
-#else
-  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1 );
-#endif
 #else
   READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
@@ -1061,223 +935,4 @@
   if (uiCode)
   {
-#if !H_MV5
-#if H_MV
-    m_pcBitstream->readOutTrailingBits();
-
-    READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
-    READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
-
-    for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
-    {
-      READ_FLAG( uiCode,  "scalability_mask[i]" );                  pcVPS->setScalabilityMask( sIdx, uiCode == 1 ? true : false );      
-    }
-
-    for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
-    {
-        READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
-    }
-
-    if ( pcVPS->getSplittingFlag() )
-      {
-      pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1, pcVPS->inferLastDimsionIdLenMinus1() );       
-      }
-
-    READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
-
-    for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
-    {
-      if ( pcVPS->getVpsNuhLayerIdPresentFlag() && ( i > 0 ) )
-      {
-        READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                pcVPS->setLayerIdInNuh( i, uiCode );
-      }
-      else
-      {
-        pcVPS->setLayerIdInNuh( i, i );; 
-    }
-
-      pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i ); 
-    
-      for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
-    {
-        if ( !pcVPS->getSplittingFlag() )
-      {
-          READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
-        }
-        else
-        {
-          pcVPS->setDimensionId( i, j, pcVPS->inferDimensionId( i, j)  );
-        }
-      }
-    }
-
-
-    for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
-    {
-      for( Int j = 0; j < i; j++ )
-      {
-        READ_FLAG( uiCode, "direct_dependency_flag[i][j]" );             pcVPS->setDirectDependencyFlag( i, j, uiCode );
-      }
-    }
-
-    for( Int i = 0; i < pcVPS->getMaxLayers() - 1; i++ )
-    {
-      READ_CODE( 3, uiCode,       "max_tid_il_ref_pics_plus1[i]" );      pcVPS->setMaxTidIlRefPicPlus1( i , uiCode ); 
-    }
-
-    READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1"      );  pcVPS->setVpsNumberLayerSetsMinus1    ( uiCode ); 
-    READ_CODE( 6,  uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode );
-
-    for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
-    {
-      READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
-      if( !pcVPS->getVpsProfilePresentFlag( i ) )
-      {
-        READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); pcVPS->setProfileRefMinus1( i, uiCode );
-      }
-      parsePTL ( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
-      if( !pcVPS->getVpsProfilePresentFlag( i ) )
-      {
-        TComPTL temp = *pcVPS->getPTL( i );
-        *pcVPS->getPTL( i ) = *pcVPS->getPTL( pcVPS->getProfileRefMinus1( i ) + 1 );
-        pcVPS->getPTL( i )->copyLevelFrom( &temp );
-      }
-    }
-
-    Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
-
-    READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); pcVPS->setMoreOutputLayerSetsThanDefaultFlag( uiCode == 1 );
-
-    if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
-    {
-      READ_CODE( 10, uiCode, "num_add_output_layer_sets_minus1"      ); pcVPS->setNumAddOutputLayerSetsMinus1( uiCode );
-      numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1); 
-    }
-
-    if( numOutputLayerSets > 1)
-    {
-      READ_FLAG( uiCode, "default_one_target_output_layer_flag" ); pcVPS->setDefaultOneTargetOutputLayerFlag(  uiCode == 1); 
-    }  
-
-    for( Int i = 1; i < numOutputLayerSets; i++ )
-    {
-      if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
-      {        
-        READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode ); 
-        for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1; j++ )
-        {
-          READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
-        }        
-      }
-      if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
-      {      
-        READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode ); 
-      }
-    }
-
-    READ_FLAG( uiCode , "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag( uiCode == 1 ); 
-    READ_UVLC( uiCode,  "direct_dep_type_len_minus2"); pcVPS->setDirectDepTypeLenMinus2 ( uiCode ); 
-
-    for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
-    {
-      for( Int j = 0; j < i; j++ )
-      {
-        if (pcVPS->getDirectDependencyFlag( i, j) )
-        {        
-          READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
-        }
-      }
-    }
-
-    READ_FLAG ( uiCode,                    "vps_shvc_reserved_zero_flag" ); 
-
-#if H_3D    
-    READ_FLAG( uiCode,  "vps_extension2_flag" );
-    if (uiCode)
-    {
-      m_pcBitstream->readOutTrailingBits();
-
-      for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
-      {
-
-#if H_3D_ARP
-        pcVPS->setUseAdvRP  ( i, 0 );
-        pcVPS->setARPStepNum( i, 1 );
-#endif  
-        if ( i != 0 )
-        {
-          if( !( pcVPS->getDepthId( i ) == 1 ) )
-          {
-#if H_3D_IV_MERGE
-                READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
-#endif
-#if H_3D_ARP
-                READ_FLAG( uiCode, "iv_res_pred_flag[i]"  );  pcVPS->setUseAdvRP  ( i, uiCode ); pcVPS->setARPStepNum( i, uiCode ? H_3D_ARP_WFNR : 1 );
-
-#endif
-#if H_3D_NBDV_REF
-                READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( i, uiCode == 1 ? true : false );
-#endif
-#if H_3D_VSP
-                READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( i, uiCode == 1 ? true : false );
-#endif
-          }
-          else
-          {
-
-            READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
-            //          READ_FLAG( uiCode, "lim_qt_pred_flag[i]");                  pcVPS->setLimQtPreFlag     ( i, uiCode == 1 ? true : false ); 
-#if H_3D_DIM_DLT
-            if( pcVPS->getVpsDepthModesFlag( i ) )
-            {
-              READ_FLAG( uiCode, "dlt_flag[i]" );                       pcVPS->setUseDLTFlag( i, uiCode == 1 ? true : false );
-            }
-            if( pcVPS->getUseDLTFlag( i ) )
-            {
-              // decode mapping
-              UInt uiNumDepthValues;
-              // parse number of values in DLT
-              READ_UVLC(uiNumDepthValues, "num_depth_values_in_dlt[i]");
-
-              // parse actual DLT values
-              Int* aiIdx2DepthValue = (Int*) calloc(uiNumDepthValues, sizeof(Int));
-              for(Int d=0; d<uiNumDepthValues; d++)
-              {
-                READ_UVLC(uiCode, "dlt_depth_value[i][d]");
-                aiIdx2DepthValue[d] = (Int)uiCode;
-              }
-
-              pcVPS->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
-
-              // clean memory
-              free(aiIdx2DepthValue);
-            }
-#endif
-#if LGE_INTER_SDC_E0156
-            READ_FLAG( uiCode, "depth_inter_SDC_flag" );              pcVPS->setInterSDCFlag( i, uiCode ? true : false );
-#endif
-          }
-        }
-      }
-      READ_FLAG( uiCode, "iv_mv_scaling_flag");                       pcVPS->setIvMvScalingFlag( uiCode == 1 ? true : false ); 
-    }
-#endif
-    pcVPS->checkVPSExtensionSyntax(); 
-
-    pcVPS->setRefLayers(); 
-
-#else
-    while ( xMoreRbspData() )
-    {
-      READ_FLAG( uiCode, "vps_extension_data_flag");
-    }
-#endif    
-  }
-
-#if H_3D
-  pcVPS->initViewIndex(); 
-#endif
-  return;
-}
-#else
 #if H_MV
     m_pcBitstream->readOutTrailingBits();
@@ -1305,8 +960,7 @@
 #endif
   }
-}
-#endif
-
-#if H_MV5
+  return; 
+}
+
 #if H_MV
 Void TDecCavlc::parseVPSExtension( TComVPS* pcVPS )
@@ -1640,5 +1294,5 @@
         }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
             READ_FLAG( uiCode, "depth_inter_SDC_flag" );              pcVPS->setInterSDCFlag( i, uiCode ? true : false );
 #endif
@@ -1648,5 +1302,4 @@
   READ_FLAG( uiCode, "iv_mv_scaling_flag");                       pcVPS->setIvMvScalingFlag( uiCode == 1 ? true : false ); 
 }
-#endif
 #endif
 
@@ -1680,5 +1333,4 @@
 #if H_MV
   vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
-#if H_MV5
   assert( vps != NULL );
   
@@ -1692,13 +1344,4 @@
   rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerId() ) == 1 );
 #endif
-#else
-  assert(vps!=0);
-  rpcSlice->setVPS(vps);      
-  rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerIdInVps() )      );
-#if H_3D  
-  rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerIdInVps() )      );  
-  rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerIdInVps() ) == 1 );
-#endif
-#endif
 #endif
   rpcSlice->setSPS(sps);
@@ -1747,5 +1390,4 @@
   {
 #if H_MV    
-#if H_MV5
     Int esb = 0; //Don't use i, otherwise will shadow something below
     if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
@@ -1762,12 +1404,4 @@
 
     for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)    
-#else
-    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
-    {
-      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
-    }
-
-    for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)    
-#endif
 #else
     for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
@@ -1808,7 +1442,7 @@
       READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");  
       Int iPOClsb = uiCode;
-      Int iPrevPOC = rpcSlice->getPrevPOC();
+      Int iPrevPOC = rpcSlice->getPrevTid0POC();
       Int iMaxPOClsb = 1<< sps->getBitsForPOC();
-      Int iPrevPOClsb = iPrevPOC%iMaxPOClsb;
+      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
       Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
       Int iPOCmsb;
@@ -1833,5 +1467,4 @@
       }
       rpcSlice->setPOC              (iPOCmsb+iPOClsb);
-#if H_MV5
 #if H_MV
       if ( rpcSlice->getPocResetFlag() )  
@@ -1841,5 +1474,4 @@
 
       }      
-#endif
 #endif
       TComReferencePictureSet* rps;
@@ -1941,4 +1573,10 @@
             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
             rps->setCheckLTMSBPresent(j,false);  
+            
+            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
+            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
+            {
+              deltaPocMSBCycleLT = 0;
+            }
           }
           prevDeltaMSB = deltaPocMSBCycleLT;
@@ -1970,5 +1608,4 @@
     }
 #if H_MV
-#if H_MV5
     Int layerId       = rpcSlice->getLayerId(); 
     if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )    {   
@@ -1989,29 +1626,4 @@
       }  
     }
-#else
-    Int layerIdInVps       = rpcSlice->getLayerIdInVps(); 
-    if( rpcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
-    {   
-      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
-      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerIdInVps ) > 1 )
-      {            
-        if( !vps->getMaxOneActiveRefLayerFlag())  
-        {
-          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
-        }
-        for( Int i = 0; i < rpcSlice->getNumActiveRefLayerPics(); i++ )   
-        {
-          READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( i, uiCode );
-        }
-      }  
-    }
-
-    rpcSlice->setActiveMotionPredRefLayers( );
-
-    if( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0  &&  rpcSlice->getNumActiveRefLayerPics() > 0 )
-    {
-      READ_FLAG( uiCode, "inter_layer_sample_pred_only_flag" ); rpcSlice->setInterLayerSamplePredOnlyFlag( uiCode == 1 );
-    }
-#endif
 #endif
     if(sps->getUseSAO())
@@ -2155,19 +1767,4 @@
     if ( rpcSlice->getEnableTMVPFlag() )
     {
-#if !H_MV5
-#if H_MV
-      if( rpcSlice->getLayerId() > 0 && rpcSlice->getNumActiveMotionPredRefLayers() > 0 )
-      {
-        READ_FLAG( uiCode, "alt_collocated_indication_flag" ); rpcSlice->setAltCollocatedIndicationFlag( uiCode == 1 );
-      }
-
-      if( rpcSlice->getAltCollocatedIndicationFlag() && rpcSlice->getNumActiveMotionPredRefLayers() > 1 ) 
-      {          
-        READ_UVLC( uiCode, "collocated_ref_layer_idx" ); rpcSlice->setCollocatedRefLayerIdx( uiCode );
-      }      
-      else 
-      {
-#endif
-#endif
       if ( rpcSlice->getSliceType() == B_SLICE )
       {
@@ -2191,9 +1788,4 @@
         rpcSlice->setColRefIdx(0);
       }
-#if !H_MV5
-#if H_MV
-      }
-#endif
-#endif
     }
     if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
@@ -2651,5 +2243,5 @@
 }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 Void TDecCavlc::parseInterSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
 {
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 655)
@@ -76,5 +76,4 @@
   Void  parseQtRootCbf      ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
   Void  parseVPS            ( TComVPS* pcVPS );
-#if H_MV5
 #if H_MV
   Void  parseVPSExtension   ( TComVPS* pcVPS ); 
@@ -86,10 +85,7 @@
   Void  parseSPSExtension   ( TComSPS* pcSPS );  
 #endif
-#endif
 #if H_3D
-#if H_MV5
   Void  parseVPSExtension2  ( TComVPS* pcVPS ); 
   Void  parseSPSExtension2  ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag );
-#endif
   Void  parseSPS            ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag );
 #else
@@ -117,5 +113,5 @@
   Void  parseICFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Void  parseInterSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void  parseInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart );
Index: trunk/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 655)
@@ -458,5 +458,5 @@
   m_pcEntropyDecoder->decodeARPW    ( pcCU , uiAbsPartIdx , uiDepth );  
 #endif  
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   m_pcEntropyDecoder->decodeInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth );
 #endif
@@ -525,5 +525,5 @@
   {
     case MODE_INTER:
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
       if( m_ppcCU[uiDepth]->getInterSDCFlag( 0 ) )
       {
@@ -534,5 +534,5 @@
 #endif
       xReconInter( m_ppcCU[uiDepth], uiDepth );
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
       }
 #endif
@@ -578,5 +578,5 @@
 }
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 Void TDecCu::xReconInterSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
 {
@@ -895,9 +895,5 @@
   // get DC prediction for each segment
   Pel apDCPredValues[2];
-#if KWU_SDC_SIMPLE_DC_E0117
   m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
-#else
-  m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride);
-#endif
   
   // reconstruct residual based on mask + DC residuals
Index: trunk/source/Lib/TLibDecoder/TDecCu.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCu.h	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecCu.h	(revision 655)
@@ -118,5 +118,5 @@
   Void xReconIntraSDC           ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Void xReconInterSDC           ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 655)
@@ -650,5 +650,5 @@
 #endif
   
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
   {
@@ -683,5 +683,5 @@
 }
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 Void TDecEntropy::decodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
 {
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 655)
@@ -91,5 +91,5 @@
   virtual Void parseICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   virtual Void parseInterSDCFlag  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
   virtual Void parseInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart ) = 0;
@@ -170,5 +170,5 @@
   Void decodeICFlag            ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Void decodeInterSDCFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void decodeInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
Index: trunk/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 655)
@@ -158,12 +158,10 @@
     rpcPic->setNumDdvCandPics(rpcPic->getDisCandRefPictures(iColPoc));
   }
-#endif
-#if MTK_NBDV_TN_FIX_E0172 
+
   if(pcSlice->getViewIndex() && !pcSlice->getIsDepth() && !pcSlice->isIntra()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
   {
     rpcPic->checkTemporalIVRef();
   }
-#endif
-#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
+
   if(pcSlice->getIsDepth())
   {
@@ -226,5 +224,5 @@
     rpcPic->destroyNonDBFilterInfo();
   }
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
+#if H_3D
   rpcPic->compressMotion(2); 
 #endif
Index: trunk/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 655)
@@ -89,7 +89,4 @@
 #if H_3D_DIM_DMM
 , m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
-#if !SEC_DMM2_E0146_HHIFIX
-, m_cDmm2DataSCModel          ( 1,             1,               NUM_DMM2_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
-#endif
 , m_cDmm3DataSCModel          ( 1,             1,               NUM_DMM3_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
 #endif
@@ -102,5 +99,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 , m_cInterSDCFlagSCModel             ( 1,             1,  NUM_INTER_SDC_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
 , m_cInterSDCResidualSCModel         ( 1,             1,  NUM_INTER_SDC_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
@@ -179,7 +176,4 @@
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM1_DATA );
-#if !SEC_DMM2_E0146_HHIFIX
-  m_cDmm2DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM2_DATA );
-#endif
   m_cDmm3DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM3_DATA );
 #endif
@@ -192,5 +186,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   m_cInterSDCFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_INTER_SDC_FLAG );
   m_cInterSDCResidualSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_INTER_SDC_RESIDUAL );
@@ -255,7 +249,4 @@
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
-#if !SEC_DMM2_E0146_HHIFIX
-  m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
-#endif
   m_cDmm3DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA );
 #endif
@@ -268,5 +259,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   m_cInterSDCFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_FLAG );
   m_cInterSDCResidualSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_RESIDUAL );
@@ -444,31 +435,5 @@
   ruiTabIdx = uiIdx;
 }
-#if !SEC_DMM2_E0146_HHIFIX
-Void TDecSbac::xParseDmm2Offset( Int& riOffset )
-{
-  Int iDeltaEnd = 0;
-  if( DMM2_DELTAEND_MAX > 0 )
-  {
-    UInt uiFlag = 0;
-    m_pcTDecBinIf->decodeBin( uiFlag, m_cDmm2DataSCModel.get(0, 0, 0) );
-
-    if( uiFlag )
-    {
-      UInt uiAbsValMinus1;
-      UInt uiSymbol;
-      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm2DataSCModel.get(0, 0, 0) ); uiAbsValMinus1  = uiSymbol;
-      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm2DataSCModel.get(0, 0, 0) ); uiAbsValMinus1 |= uiSymbol << 1;
-      iDeltaEnd = uiAbsValMinus1 + 1;
-      UInt uiSign;
-      m_pcTDecBinIf->decodeBinEP( uiSign );
-      if( uiSign )
-      {
-        iDeltaEnd = -iDeltaEnd;
-      }
-    }
-  }
-  riOffset = iDeltaEnd;
-}
-#endif
+
 Void TDecSbac::xParseDmm3WedgeIdx( UInt& ruiIntraIdx, Int iNumBit )
 {
@@ -1175,12 +1140,4 @@
       pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, absPartIdx, depth );
     } break;
-#if !SEC_DMM2_E0146_HHIFIX
-  case( DMM2_IDX ):
-    {
-      Int iOffset = 0;
-      xParseDmm2Offset( iOffset );
-      pcCU->setDmm2DeltaEndSubParts( iOffset, absPartIdx, depth );
-    } break;
-#endif
   case( DMM3_IDX ):
     {
@@ -1250,7 +1207,4 @@
   if( puIdx == 2 )
   {
-#if !LGE_SDC_REMOVE_DC_E0158
-    while( binNum < 2 && symbol )
-#endif
     {
       ctxDepthMode = puIdx*3 + binNum;
@@ -1260,10 +1214,5 @@
     }
          if( modeCode == 0 ) { dir = PLANAR_IDX; sdcFlag = 1;}
-#if LGE_SDC_REMOVE_DC_E0158
     else if( modeCode == 1 ) { dir = 0;          sdcFlag = 0;}
-#else
-    else if( modeCode == 2 ) { dir = 0;          sdcFlag = 0;}
-    else if( modeCode == 3 ) { dir =     DC_IDX; sdcFlag = 1;}
-#endif
   }
   else if( puIdx == 0 )
@@ -1283,108 +1232,35 @@
   else
   {
-#if ZJU_DEPTH_INTRA_MODE_E0204
-      UInt maxBinNum = 0;
-      m_pcTDecBinIf->decodeBinEP(symbol);
-      if( symbol == 1 )
-      {
-          maxBinNum = 3;
-      }
-      else
-      {
-          maxBinNum = 2;
-          symbol = 1;
-      }
-      while( binNum<maxBinNum && symbol )
-      {
-          ctxDepthMode = puIdx*3 + ( binNum >= 2 ? 2 : binNum );
-          m_pcTDecBinIf->decodeBin(symbol,m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode));
-          modeCode = (modeCode<<1)+symbol;
-          binNum++;
-      }
-      if( maxBinNum == 3 )
-      {
-          if ( modeCode == 0 )       { dir =  PLANAR_IDX;             sdcFlag = 1;}
-          else if ( modeCode == 2 )  { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
-          else if ( modeCode == 6 )  { dir = (2*DMM3_IDX+DIM_OFFSET); sdcFlag = 0;}
-          else if ( modeCode == 7 )  { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 0;}
-      }
-      else
-      {
-          if ( modeCode == 0 )       { dir = 5;                       sdcFlag = 0;}
-          else if ( modeCode == 2 )  { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 1;}
-          else if ( modeCode == 3 )  { dir = (2*DMM4_IDX+DIM_OFFSET); sdcFlag = 0;}
-      }
-#else
-    ctxDepthMode = puIdx*3 ;
-    m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
-    modeCode = (modeCode<<1) + symbol;
-    if( !symbol )
-    {
-      ctxDepthMode = puIdx*3 + 1;
-      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
-      modeCode = (modeCode<<1) + symbol;
-      if( symbol ) 
-      { 
-        ctxDepthMode = puIdx*3 + 2;
-        m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
-        modeCode = (modeCode<<1) + symbol;
-      }
+    UInt maxBinNum = 0;
+    m_pcTDecBinIf->decodeBinEP(symbol);
+    if( symbol == 1 )
+    {
+      maxBinNum = 3;
     }
     else
     {
-      ctxDepthMode = puIdx*3 + 1;
-      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
-      modeCode = (modeCode<<1) + symbol;
-      if( !symbol ) 
-      { 
-        ctxDepthMode = puIdx*3 + 2;
-        m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
-        modeCode = (modeCode<<1) + symbol;
-      }
-      else
-      {
-        binNum = 0;
-#if LGE_SDC_REMOVE_DC_E0158
-#if !SEC_DMM2_E0146_HHIFIX
-        while( symbol && binNum < 2 )
-#endif
-#else
-#if SEC_DMM2_E0146_HHIFIX
-        while( symbol && binNum < 2 )
-#else
-        while( symbol && binNum < 3 )
-#endif
-#endif
-        {
-          ctxDepthMode = puIdx*3 + 2;
-          m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
-          modeCode = (modeCode<<1) + symbol;
-          binNum++;
-        }
-      }
-    }
-         if( modeCode == 0  ) { dir =  PLANAR_IDX;             sdcFlag = 1;}
-    else if( modeCode == 2  ) { dir = 5;                       sdcFlag = 0;}
-    else if( modeCode == 3  ) { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 1;}
-    else if( modeCode == 4  ) { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 0;}
-    else if( modeCode == 5  ) { dir = (2*DMM4_IDX+DIM_OFFSET); sdcFlag = 0;}
-    else if( modeCode == 6  ) { dir = (2*DMM3_IDX+DIM_OFFSET); sdcFlag = 0;}
-#if LGE_SDC_REMOVE_DC_E0158
-#if SEC_DMM2_E0146_HHIFIX
-    else if( modeCode == 7 )  { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
-#else
-    else if( modeCode == 14 ) { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
-    else if( modeCode == 15 ) { dir = (2*DMM2_IDX+DIM_OFFSET); sdcFlag = 0;}
-#endif
-#else
-    else if( modeCode == 14 ) { dir =      DC_IDX;             sdcFlag = 1;}
-#if SEC_DMM2_E0146_HHIFIX
-    else if( modeCode == 15 ) { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
-#else
-    else if( modeCode == 30 ) { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
-    else if( modeCode == 31 ) { dir = (2*DMM2_IDX+DIM_OFFSET); sdcFlag = 0;}
-#endif
-#endif
-#endif
+      maxBinNum = 2;
+      symbol = 1;
+    }
+    while( binNum<maxBinNum && symbol )
+    {
+      ctxDepthMode = puIdx*3 + ( binNum >= 2 ? 2 : binNum );
+      m_pcTDecBinIf->decodeBin(symbol,m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode));
+      modeCode = (modeCode<<1)+symbol;
+      binNum++;
+    }
+    if( maxBinNum == 3 )
+    {
+      if ( modeCode == 0 )       { dir =  PLANAR_IDX;             sdcFlag = 1;}
+      else if ( modeCode == 2 )  { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
+      else if ( modeCode == 6 )  { dir = (2*DMM3_IDX+DIM_OFFSET); sdcFlag = 0;}
+      else if ( modeCode == 7 )  { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 0;}
+    }
+    else
+    {
+      if ( modeCode == 0 )       { dir = 5;                       sdcFlag = 0;}
+      else if ( modeCode == 2 )  { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 1;}
+      else if ( modeCode == 3 )  { dir = (2*DMM4_IDX+DIM_OFFSET); sdcFlag = 0;}
+    }
   }
   pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
@@ -2338,5 +2214,5 @@
 #endif
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 Void TDecSbac::parseInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
 {
Index: trunk/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 655)
@@ -102,7 +102,4 @@
 #if H_3D_DIM_DMM
   Void  xParseDmm1WedgeIdx   ( UInt& ruiTabIdx, Int iNumBit );
-#if !SEC_DMM2_E0146_HHIFIX
-  Void  xParseDmm2Offset     ( Int& riOffset );
-#endif
   Void  xParseDmm3WedgeIdx   ( UInt& ruiIntraIdx, Int iNumBit );
 #endif
@@ -114,5 +111,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Void  parseInterSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void  parseInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart );
@@ -216,7 +213,4 @@
 #if H_3D_DIM_DMM
   ContextModel3DBuffer m_cDmm1DataSCModel;
-#if !SEC_DMM2_E0146_HHIFIX
-  ContextModel3DBuffer m_cDmm2DataSCModel;
-#endif
   ContextModel3DBuffer m_cDmm3DataSCModel;
 #endif
@@ -229,5 +223,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   ContextModel3DBuffer m_cInterSDCFlagSCModel;
   ContextModel3DBuffer m_cInterSDCResidualSCModel;
Index: trunk/source/Lib/TLibDecoder/TDecSlice.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSlice.h	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecSlice.h	(revision 655)
@@ -65,5 +65,4 @@
   TDecEntropy*    m_pcEntropyDecoder;
   TDecCu*         m_pcCuDecoder;
-  UInt            m_uiCurrSliceIdx;
 
   TDecSbac*       m_pcBufferSbacDecoders;   ///< line to store temporary contexts, one per column of tiles.
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 655)
@@ -347,10 +347,12 @@
 #endif
 #endif
+  m_associatedIRAPType = NAL_UNIT_INVALID;
   m_pocCRA = 0;
-  m_prevRAPisBLA = false;
   m_pocRandomAccess = MAX_INT;  
   m_prevPOC                = MAX_INT;
   m_bFirstSliceInPicture    = true;
   m_bFirstSliceInSequence   = true;
+  m_prevSliceSkipped = false;
+  m_skippedPOC = 0;
 #if H_MV
   m_layerId = 0;
@@ -436,9 +438,7 @@
   Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
 
-#if H_MV5
 #if H_MV
     assert( conformanceWindow   .getScaledFlag() ); 
     assert( defaultDisplayWindow.getScaledFlag() );
-#endif
 #endif
   for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
@@ -518,9 +518,5 @@
   m_cCuDecoder.destroy();        
 #if H_MV 
-#if H_MV5
   TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 );  
-#else
-  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer );  
-#endif
   TComSlice::markCurrPic( pcPic ); 
   TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
@@ -591,5 +587,4 @@
   assert (sps != 0);
 
-#if H_MV5
 #if H_MV
   TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
@@ -599,7 +594,4 @@
   if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
 #endif
-#else
-  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
-#endif
   {
     printf ("Parameter set activation failed!");
@@ -627,11 +619,7 @@
   m_apcSlicePilot->setSPS(sps);
 #if H_MV
-#if H_MV5
   m_apcSlicePilot->setVPS(vps);  
   sps->inferRepFormat  ( vps , m_layerId ); 
   sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
-#else
-  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
-#endif
 #endif
   pps->setSPS(sps);
@@ -695,16 +683,20 @@
 
 #if H_MV
-#if H_MV5
   m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
-#else
-  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer ); 
-#endif
   m_apcSlicePilot->setLayerId( nalu.m_layerId );
 #endif
   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
+
+  // set POC for dependent slices in skipped pictures
+  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
+  {
+    m_apcSlicePilot->setPOC(m_skippedPOC);
+  }
+
+  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
+  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
 
 #if H_MV  
   TComVPS* vps     = m_apcSlicePilot->getVPS();
-#if H_MV5
   Int layerId  = nalu.m_layerId;   
   setViewId   ( vps->getViewId   ( layerId )      );  
@@ -714,17 +706,10 @@
   m_ivPicLists->setVPS( vps ); 
 #endif
-#else
-  Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId );  
-  setViewId   ( vps->getViewId   ( layerIdInVps )      );  
-#if H_3D
-  setViewIndex( vps->getViewIndex( layerIdInVps )      );  
-  setIsDepth  ( vps->getDepthId  ( layerIdInVps ) == 1 );  
-  m_ivPicLists->setVPS( vps ); 
-#endif
-#endif
 #endif
     // Skip pictures due to random access
     if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
     {
+    m_prevSliceSkipped = true;
+    m_skippedPOC = m_apcSlicePilot->getPOC();
       return false;
     }
@@ -732,6 +717,11 @@
     if (isSkipPictureForBLA(iPOCLastDisplay))
     {
+    m_prevSliceSkipped = true;
+    m_skippedPOC = m_apcSlicePilot->getPOC();
       return false;
     }
+
+  // clear previous slice skipped flag
+  m_prevSliceSkipped = false;
 
   //we should only get a different poc for a new picture (with CTU address==0)
@@ -763,5 +753,4 @@
 #endif
   // actual decoding starts here
-#if H_MV5
 #if H_MV
    // This part needs further testing !
@@ -771,5 +760,4 @@
    }
 #endif
-#endif
   xActivateParameterSets();
 
@@ -791,13 +779,28 @@
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
 #if H_MV
-#if H_MV5
     m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
-#else
-    m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
-#endif
 #endif
     //  Get a new picture buffer
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
 
+    Bool isField = false;
+    Bool isTff = false;
+    
+    if(!m_SEIs.empty())
+    {
+      // Check if any new Picture Timing SEI has arrived
+      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
+      if (pictureTimingSEIs.size()>0)
+      {
+        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
+        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
+        isTff =  (pictureTiming->m_picStruct == 1);
+      }
+    }
+    
+    //Set Field/Frame coding mode
+    m_pcPic->setField(isField);
+    m_pcPic->setTopField(isTff);
+    
     // transfer any SEI messages that have been received to the picture
     pcPic->setSEIs(m_SEIs);
@@ -938,8 +941,7 @@
   if (bNextSlice)
   {
-    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
+    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
     // Set reference list
 #if H_MV    
-#if H_MV5
     std::vector< TComPic* > tempRefPicLists[2];
     std::vector< Bool     > usedAsLongTerm [2];
@@ -948,7 +950,4 @@
     pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
     pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
-#else
-    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );    
-#endif
 #if H_3D_ARP
     pcSlice->setARPStepNum();
@@ -978,6 +977,10 @@
 #if H_3D
     pcSlice->setIvPicLists( m_ivPicLists );         
-#if H_3D_IV_MERGE    
+#if H_3D_IV_MERGE
+#if H_3D_FCO
+    //assert( !getIsDepth() );
+#else
     assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
+#endif
 #endif    
 #endif
@@ -1037,5 +1040,4 @@
       pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
     }
-    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
     if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
     {
@@ -1084,11 +1086,6 @@
   TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
   assert( vps != 0 ); 
-#if H_MV5
   m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( m_layerId ), ( vps->getDepthId( m_layerId ) == 1 ) );
 #else
-  Int layerIdInVPS = vps->getLayerIdInVps( m_layerId ); 
-  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( layerIdInVPS ), ( vps->getDepthId( layerIdInVPS ) == 1 ) );
-#endif
-#else
   m_cEntropyDecoder.decodeSPS( sps );
 #endif
@@ -1099,8 +1096,6 @@
 {
   TComPPS* pps = new TComPPS();
-#if H_MV5
 #if H_MV
   pps->setLayerId( getLayerId() ); 
-#endif
 #endif
   m_cEntropyDecoder.decodePPS( pps );
@@ -1112,5 +1107,4 @@
   if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
   {
-#if H_MV5
 #if H_MV
     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
@@ -1118,11 +1112,7 @@
     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
 #endif
-#else
-    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );  
-#endif
   }
   else
   {
-#if H_MV5
 #if H_MV
     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
@@ -1130,7 +1120,4 @@
     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
 #endif
-#else
-    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
-#endif
     SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
     if (activeParamSets.size()>0)
@@ -1139,10 +1126,6 @@
       m_parameterSetManagerDecoder.applyPrefetchedPS();
       assert(seiAps->activeSeqParamSetId.size()>0);
-#if H_MV5
 #if H_MV
       if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0], m_layerId ))
-#else
-      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
-#endif
 #else
       if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
@@ -1221,5 +1204,6 @@
 Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
 {
-  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
+  if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) && 
+       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
   {
     iPOCLastDisplay++;
@@ -1306,5 +1290,4 @@
 }
 
-#if H_MV5
 Void TDecTop::xResetPocInPicBuffer()
 {
@@ -1324,4 +1307,3 @@
 }
 #endif
-#endif
 //! \}
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 625)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 655)
@@ -176,6 +176,6 @@
   Int                     m_iMaxRefPicNum;
   
+  NalUnitType             m_associatedIRAPType; ///< NAL unit type of the associated IRAP picture
   Int                     m_pocCRA;            ///< POC number of the latest CRA picture
-  Bool                    m_prevRAPisBLA;      ///< true if the previous RAP (CRA/CRANT/BLA/BLANT/IDR) picture is a BLA/BLANT picture
   Int                     m_pocRandomAccess;   ///< POC number of the random access point (the first IDR or CRA picture)
 
@@ -211,4 +211,7 @@
   Bool                    m_bFirstSliceInPicture;
   Bool                    m_bFirstSliceInSequence;
+  Bool                    m_prevSliceSkipped;
+  Int                     m_skippedPOC;
+
 #if H_MV
   // For H_MV m_bFirstSliceInSequence indicates first slice in sequence of the particular layer  
@@ -216,10 +219,6 @@
   Int                     m_viewId;
   TComPicLists*           m_ivPicLists;
-#if H_MV5
   std::vector<TComPic*>   m_refPicSetInterLayer0; 
   std::vector<TComPic*>   m_refPicSetInterLayer1; 
-#else
-  std::vector<TComPic*>   m_refPicSetInterLayer; 
-#endif
 #if H_3D
   Int                     m_viewIndex; 
@@ -279,7 +278,5 @@
   TComPic*  xGetPic( Int layerId, Int poc ); 
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag );  
-#if H_MV5
   Void      xResetPocInPicBuffer();
-#endif
 #else
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
Index: trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp	(revision 655)
@@ -52,4 +52,6 @@
 TEncAnalyze             m_gcAnalyzeP;
 TEncAnalyze             m_gcAnalyzeB;
+
+TEncAnalyze             m_gcAnalyzeAll_in;
 #endif
 
Index: trunk/source/Lib/TLibEncoder/TEncAnalyze.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncAnalyze.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncAnalyze.h	(revision 655)
@@ -116,4 +116,33 @@
   }
   
+  Void    printOutInterlaced ( Char cDelim, Double bits )
+  {
+    Double dFps     =   m_dFrmRate; //--CFG_KDY
+    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
+    
+    printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
+    //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
+    printf( "\t %8d    %c"          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf\n",
+           getNumPic(), cDelim,
+           bits * dScale,
+           getPsnrY() / (Double)getNumPic(),
+           getPsnrU() / (Double)getNumPic(),
+           getPsnrV() / (Double)getNumPic() );
+  }
+  
+  Void    printSummaryOutInterlaced (Int bits)
+  {
+    FILE* pFile = fopen ("summaryTotal.txt", "at");
+    Double dFps     =   m_dFrmRate; //--CFG_KDY
+    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
+    
+    fprintf(pFile, "%f\t %f\t %f\t %f\n", bits * dScale,
+            getPsnrY() / (Double)getNumPic(),
+            getPsnrU() / (Double)getNumPic(),
+            getPsnrV() / (Double)getNumPic() );
+    fclose(pFile);
+  }
+  
+  
   Void    printSummary(Char ch)
   {
@@ -155,4 +184,6 @@
 extern TEncAnalyze             m_gcAnalyzeP;
 extern TEncAnalyze             m_gcAnalyzeB;
+
+extern TEncAnalyze             m_gcAnalyzeAll_in;
 #endif
 
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 655)
@@ -229,5 +229,4 @@
     }
   }
-#if H_MV5
 #if H_MV
   if ( pcPPS->getLayerId() > 0 )
@@ -243,5 +242,4 @@
   {  
 #endif  
-#endif
   WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" ); 
   if( pcPPS->getScalingListPresentFlag() )
@@ -252,8 +250,6 @@
     codeScalingList( m_pcSlice->getScalingList() );
   }
-#if H_MV5
 #if H_MV
   }
-#endif
 #endif
   WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
@@ -339,12 +335,4 @@
   {
     WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(),             "tiles_fixed_structure_flag");
-#if !H_MV5
-#if H_MV
-    if ( pcSPS->getLayerId() > 0 )
-    {
-      WRITE_FLAG( pcVUI->getTileBoundariesAlignedFlag( ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
-    }
-#endif
-#endif
     WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
     WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(),           "restricted_ref_pic_lists_flag");
@@ -451,5 +439,4 @@
 #endif
   WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
-#if H_MV5
 #if H_MV
   if ( pcSPS->getLayerId() > 0 )
@@ -460,5 +447,4 @@
   if ( pcSPS->getUpdateRepFormatFlag() )
   { 
-#endif
 #endif
   WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
@@ -472,8 +458,6 @@
   WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
   WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
-#if H_MV5
 #if H_MV
   }
-#endif
 #endif
   Window conf = pcSPS->getConformanceWindow();
@@ -487,16 +471,12 @@
     WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" );
   }
-#if H_MV5
 #if H_MV
   if ( pcSPS->getUpdateRepFormatFlag() )
   { 
 #endif
-#endif
   WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
   WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
-#if H_MV5
 #if H_MV
   }
-#endif
 #endif
   WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
@@ -525,5 +505,4 @@
   if(pcSPS->getScalingListFlag())
   {
-#if H_MV5
 #if H_MV
     if ( pcSPS->getLayerId() > 0 )
@@ -539,5 +518,4 @@
     {    
 #endif
-#endif
     WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0,                          "sps_scaling_list_data_present_flag" ); 
     if(pcSPS->getScalingListPresentFlag())
@@ -548,8 +526,6 @@
       codeScalingList( m_pcSlice->getScalingList() );
     }
-#if H_MV5
 #if H_MV
     }
-#endif
 #endif
   }
@@ -598,61 +574,4 @@
   }
 
-#if !H_MV5
-#if H_MV
-  WRITE_FLAG( 1, "sps_extension_flag" );
-  WRITE_FLAG( pcSPS->getInterViewMvVertConstraintFlag() ? 1 : 0, "inter_view_mv_vert_constraint_flag" );
-  ////   sps_extension_vui_parameters( )
-  if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
-  {  
-    WRITE_UVLC( pcSPS->getNumIlpRestrictedRefLayers( ),           "num_ilp_restricted_ref_layers" ); 
-    for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ ) 
-    {  
-      WRITE_UVLC( pcSPS->getMinSpatialSegmentOffsetPlus1( i ),    "min_spatial_segment_offset_plus1" ); 
-      if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 ) 
-      {  
-        WRITE_FLAG( pcSPS->getCtuBasedOffsetEnabledFlag( i ),      "ctu_based_offset_enabled_flag[ i ]"); 
-        if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) )  
-        {
-          WRITE_UVLC( pcSPS->getMinHorizontalCtuOffsetPlus1( i ), "min_horizontal_ctu_offset_plus1[ i ]"); 
-        }
-      }  
-    }  
-  } 
-#if H_3D_QTLPC
-  if( depthFlag )
-  {
-    WRITE_FLAG( pcSPS->getUseQTL() ? 1 : 0, "use_qtl_flag");
-    WRITE_FLAG( pcSPS->getUsePC()  ? 1 : 0, "use_pc_flag");
-  }
-#endif
-  ////   sps_extension_vui_parameters( ) END
-  WRITE_UVLC( 0, "sps_shvc_reserved_zero_idc" ); 
-#if !H_3D
-  WRITE_FLAG( 0, "sps_extension2_flag" );
-#else
-  WRITE_FLAG( 1, "sps_extension2_flag"  );
-  if (!depthFlag )
-  {
-    WRITE_UVLC( pcSPS->getCamParPrecision(), "cp_precision" );
-    WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "cp_in_slice_header_flag" );
-    if( !pcSPS->hasCamParInSliceHeader() )
-    {
-      for( UInt uiIndex = 0; uiIndex < viewIndex; uiIndex++ )
-      {
-        WRITE_SVLC( pcSPS->getCodedScale    ()[ uiIndex ],                                      "cp_scale" );
-        WRITE_SVLC( pcSPS->getCodedOffset   ()[ uiIndex ],                                      "cp_off" );
-        WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiIndex ] + pcSPS->getCodedScale ()[ uiIndex ], "cp_inv_scale_plus_scale" );
-        WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiIndex ] + pcSPS->getCodedOffset()[ uiIndex ], "cp_inv_off_plus_off" );
-      }
-    }
-  }
-
-  WRITE_FLAG( 0, "sps_extension3_flag" );
-#endif
-#else
-  WRITE_FLAG( 0, "sps_extension_flag" );
-#endif
-}
-#else
 #if !H_MV
   WRITE_FLAG( 0, "sps_extension_flag" );
@@ -706,5 +625,4 @@
 }
 #endif
-#endif
 
 Void TEncCavlc::codeVPS( TComVPS* pcVPS )
@@ -713,9 +631,5 @@
   WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
 #if H_MV
-#if H_MV5
   WRITE_CODE( pcVPS->getMaxLayersMinus1(),       6,        "vps_max_layers_minus1" );
-#else
-  WRITE_CODE( pcVPS->getMaxLayers() - 1,            6,        "vps_max_layers_minus1" );
-#endif
 #else
   WRITE_CODE( 0,                                    6,        "vps_reserved_zero_6bits" );
@@ -800,191 +714,4 @@
     }
   }
-#if !H_MV5
-#if H_MV
-  WRITE_FLAG( 1,                                             "vps_extension_flag" );
-
-  m_pcBitIf->writeAlignOne();                        
-
-  WRITE_FLAG( pcVPS->getAvcBaseLayerFlag() ? 1 : 0,          "avc_base_layer_flag" );
-  WRITE_FLAG( pcVPS->getSplittingFlag() ? 1 : 0,             "splitting_flag" );
-  
-  for( Int type = 0; type < MAX_NUM_SCALABILITY_TYPES; type++ )
-  {
-    WRITE_FLAG( pcVPS->getScalabilityMask( type ) ? 1 : 0,   "scalability_mask[i]" );
-  }
-
-  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
-  {
-    WRITE_CODE( pcVPS->getDimensionIdLen( sIdx ) - 1 , 3,    "dimension_id_len_minus1[j]");    
-  }
-
-  if ( pcVPS->getSplittingFlag() )
-  { // Ignore old dimension id length
-    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1 ,pcVPS->inferLastDimsionIdLenMinus1() + 1 );       
-  }    
-
-
-  WRITE_FLAG( pcVPS->getVpsNuhLayerIdPresentFlag() ? 1 : 0,  "vps_nuh_layer_id_present_flag");
-
-  for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
-  {
-    if ( pcVPS->getVpsNuhLayerIdPresentFlag() && ( i > 0 ) )
-    {      
-      WRITE_CODE( pcVPS->getLayerIdInNuh( i ), 6,          "layer_id_in_nuh[i]");
-  }
-    else
-    {
-      assert( pcVPS->getLayerIdInNuh( i ) == i ); 
-  }
-
-    assert(  pcVPS->getLayerIdInVps( pcVPS->getLayerIdInNuh( i ) ) == i ); 
-
-    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ )
-  {
-      if ( !pcVPS->getSplittingFlag() )
-    {
-        WRITE_CODE( pcVPS->getDimensionId( i, j ), pcVPS->getDimensionIdLen( j ), "dimension_id[i][j]");      
-      }
-      else
-      {
-        assert( pcVPS->getDimensionId( i, j ) ==  pcVPS->inferDimensionId( i, j )  );
-      }
-    }
-  }
-
-  for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
-  {
-    for( Int j = 0; j < i; j++ )
-    {
-      WRITE_FLAG( pcVPS->getDirectDependencyFlag( i, j ),    "direct_dependency_flag[i][j]" );
-    }
-  }
-
-  for( Int i = 0; i < pcVPS->getMaxLayers() - 1; i++ )
-  {
-    WRITE_CODE( pcVPS->getMaxTidIlRefPicPlus1( i ), 3,       "max_tid_il_ref_pics_plus1[i]" );
-  }
-
-  WRITE_CODE( pcVPS->getVpsNumberLayerSetsMinus1( )    , 10,    "vps_number_layer_sets_minus1"      );
-  WRITE_CODE( pcVPS->getVpsNumProfileTierLevelMinus1( ), 6,     "vps_num_profile_tier_level_minus1" );
-
-  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
-  {
-    WRITE_FLAG( pcVPS->getVpsProfilePresentFlag( i ) ? 1 : 0, "vps_profile_present_flag[i]" );
-    if( !pcVPS->getVpsProfilePresentFlag( i ) )
-    {    
-      WRITE_CODE( pcVPS->getProfileRefMinus1( i ), 6, "profile_ref_minus1[i]" );
-    }
-    codePTL( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers() - 1 );
-  }
-
-  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
-
-  WRITE_FLAG( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) ? 1 : 0, "more_output_layer_sets_than_default_flag" );
-
-  if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
-  {
-    WRITE_CODE( pcVPS->getNumAddOutputLayerSetsMinus1( )    , 10,    "num_add_output_layer_sets_minus1"      );
-    numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1 ); 
-  }
-
-  if( numOutputLayerSets > 1)
-  {
-    WRITE_FLAG( pcVPS->getDefaultOneTargetOutputLayerFlag( ) ? 1 : 0, "default_one_target_output_layer_flag" );
-  }  
-
-  for( Int i = 1; i < numOutputLayerSets; i++ )
-  {
-    if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
-    {      
-      WRITE_UVLC( pcVPS->getOutputLayerSetIdxMinus1( i ),      "output_layer_set_idx_minus1[i]" );
-      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1 ; j++ )
-      {
-        WRITE_FLAG( pcVPS->getOutputLayerFlag( i, j) ? 1 : 0, "output_layer_flag" );
-      }      
-    }
-    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
-    {      
-      WRITE_CODE( pcVPS->getProfileLevelTierIdx( i ), pcVPS->getProfileLevelTierIdxLen() ,"profile_level_tier_idx[ i ]" );   
-    }
-  }
-
-  WRITE_FLAG( pcVPS->getMaxOneActiveRefLayerFlag( ) ? 1 : 0, "max_one_active_ref_layer_flag" );
-  WRITE_UVLC( pcVPS->getDirectDepTypeLenMinus2 ( ),         "direct_dep_type_len_minus2"); 
-
-    for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
-    {
-      for( Int j = 0; j < i; j++ )
-      {
-        if (pcVPS->getDirectDependencyFlag( i, j) )
-        {        
-          assert ( pcVPS->getDirectDependencyType( i, j ) != -1 ); 
-          WRITE_CODE( pcVPS->getDirectDependencyType( i, j ),pcVPS->getDirectDepTypeLenMinus2( ) + 2,  "direct_dependency_type[i][j]" );
-        }
-      }
-    }
-
-    WRITE_FLAG ( 0,                    "vps_shvc_reserved_zero_flag" ); 
-
-#if H_3D
-  WRITE_FLAG( 1,                                             "vps_extension2_flag" );
-  m_pcBitIf->writeAlignOne();      
-  for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
-  {
-    if (i!= 0)
-    {
-      if ( !( pcVPS->getDepthId( i ) == 1 ) )
-      {
-#if H_3D_IV_MERGE
-        WRITE_FLAG( pcVPS->getIvMvPredFlag         ( i ) ? 1 : 0 , "iv_mv_pred_flag[i]");
-#endif
-#if H_3D_ARP
-        WRITE_FLAG( pcVPS->getUseAdvRP             ( i ) ? 1 : 0,  "iv_res_pred_flag[i]"  );
-#endif
-#if H_3D_NBDV_REF
-        WRITE_FLAG( pcVPS->getDepthRefinementFlag  ( i ) ? 1 : 0 , "depth_refinement_flag[i]");
-#endif
-#if H_3D_VSP
-        WRITE_FLAG( pcVPS->getViewSynthesisPredFlag( i ) ? 1 : 0 , "view_synthesis_pred_flag[i]");
-#endif
-      }          
-      else
-      {
-        WRITE_FLAG( pcVPS->getVpsDepthModesFlag( i ) ? 1 : 0 ,          "vps_depth_modes_flag[i]" );
-        //WRITE_FLAG( pcVPS->getLimQtPredFlag    ( i ) ? 1 : 0 ,          "lim_qt_pred_flag[i]"     ); 
-#if H_3D_DIM_DLT
-        if( pcVPS->getVpsDepthModesFlag( i ) )
-        {
-          WRITE_FLAG( pcVPS->getUseDLTFlag( i ) ? 1 : 0, "dlt_flag[i]" );
-        }
-        if( pcVPS->getUseDLTFlag( i ) )
-        {
-          // code mapping
-          WRITE_UVLC(pcVPS->getNumDepthValues(i), "num_depth_values_in_dlt[i]");
-          for(Int d=0; d<pcVPS->getNumDepthValues(i); d++)
-          {
-            WRITE_UVLC( pcVPS->idx2DepthValue(i, d), "dlt_depth_value[i][d]" );
-          }
-        }        
-#endif
-#if LGE_INTER_SDC_E0156
-        WRITE_FLAG( pcVPS->getInterSDCFlag( i ) ? 1 : 0, "depth_inter_SDC_flag" );
-#endif
-      }
-    }  
-  }
-  WRITE_FLAG( pcVPS->getIvMvScalingFlag( ) ? 1 : 0 ,          "iv_mv_scaling_flag" );
-#else
-  WRITE_FLAG( 0,                                             "vps_extension2_flag" );
-#endif
-#else
-  WRITE_FLAG( 0,                     "vps_extension_flag" );
-#endif
-  
-  //future extensions here..
-  
-  return;
-}
-#else
 #if H_MV
   WRITE_FLAG( 1,                     "vps_extension_flag" );
@@ -1003,10 +730,10 @@
 #endif
   //future extensions here..
-}
-
-#endif
-
-
-#if H_MV5
+
+  return;
+}
+
+
+
 #if H_MV
 Void TEncCavlc::codeVPSExtension( TComVPS *pcVPS ) 
@@ -1309,5 +1036,5 @@
         }        
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
         WRITE_FLAG( pcVPS->getInterSDCFlag( i ) ? 1 : 0, "depth_inter_SDC_flag" );
 #endif
@@ -1319,5 +1046,4 @@
 #endif
 }
-#endif
 #endif
 
@@ -1370,5 +1096,4 @@
   {
 #if H_MV    
-#if H_MV5
     Int esb = 0;  //Don't use i, otherwise will shadow something below
     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
@@ -1385,12 +1110,4 @@
 
     for (; esb < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)    
-#else
-    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
-    {
-      WRITE_FLAG( pcSlice->getDiscardableFlag( ) ? 1 : 0 , "discardable_flag" );
-    }
-
-    for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)    
-#endif
 #else
     for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
@@ -1415,5 +1132,5 @@
     if( !pcSlice->getIdrPicFlag() )
     {
-      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
+      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
       WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
       TComReferencePictureSet* rps = pcSlice->getRPS();
@@ -1530,5 +1247,4 @@
     }
 #if H_MV
-#if H_MV5
     Int layerId = pcSlice->getLayerId(); 
     if( pcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
@@ -1550,28 +1266,4 @@
       }  
     }
-#else
-    Int layerIdInVps       = pcSlice->getLayerIdInVps(); 
-    if( pcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
-    {   
-      WRITE_FLAG( pcSlice->getInterLayerPredEnabledFlag( ) ? 1 : 0 , "inter_layer_pred_enabled_flag" );
-      if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerIdInVps ) > 1 )
-      {            
-        if( !vps->getMaxOneActiveRefLayerFlag())  
-        {
-          WRITE_CODE( pcSlice->getNumInterLayerRefPicsMinus1( ), pcSlice->getNumInterLayerRefPicsMinus1Len( ), "num_inter_layer_ref_pics_minus1" );
-        }
-        for( Int i = 0; i < pcSlice->getNumActiveRefLayerPics(); i++ )   
-        {
-          WRITE_CODE( pcSlice->getInterLayerPredLayerIdc( i ), pcSlice->getInterLayerPredLayerIdcLen( ), "inter_layer_pred_layer_idc" );
-        }
-      }  
-    }
-
-    if( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0  &&  pcSlice->getNumActiveRefLayerPics() > 0 )
-    {
-      WRITE_FLAG( pcSlice->getInterLayerSamplePredOnlyFlag( ) ? 1 : 0 , "inter_layer_sample_pred_only_flag" );
-    }
-
-#endif
 #endif
     if(pcSlice->getSPS()->getUseSAO())
@@ -1678,18 +1370,4 @@
     if ( pcSlice->getEnableTMVPFlag() )
     {
-#if !H_MV5
-#if H_MV
-      if( pcSlice->getLayerId() > 0 && pcSlice->getNumActiveMotionPredRefLayers() > 0 )
-      {
-        WRITE_FLAG( pcSlice->getAltCollocatedIndicationFlag( ) ? 1 : 0 , "alt_collocated_indication_flag" );
-      }
-      if( pcSlice->getAltCollocatedIndicationFlag() && pcSlice->getNumActiveMotionPredRefLayers() > 1 ) 
-      {          
-        WRITE_UVLC( pcSlice->getCollocatedRefLayerIdx( ), "collocated_ref_layer_idx" );
-      }      
-      else 
-      {
-#endif
-#endif
       if ( pcSlice->getSliceType() == B_SLICE )
       {
@@ -1704,9 +1382,4 @@
       }
     }
-#if !H_MV5
-#if H_MV
-    }
-#endif
-#endif
     if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
     {
@@ -2256,5 +1929,5 @@
 {
   // Bool state = true, state2 = false;
-  Int lsb = ltrpPOC % (1<<pcSlice->getSPS()->getBitsForPOC());
+  Int lsb = ltrpPOC & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
   for (Int k = 0; k < pcSlice->getSPS()->getNumLongTermRefPicSPS(); k++)
   {
@@ -2282,5 +1955,5 @@
 }
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 Void TEncCavlc::codeInterSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx )
 {
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 655)
@@ -84,5 +84,4 @@
   UInt  getCoeffCost          ()                { return  m_uiCoeffCost;  }
   Void  codeVPS                 ( TComVPS* pcVPS );
-#if H_MV5
 #if H_MV
   Void  codeVPSExtension       ( TComVPS *pcVPS );
@@ -90,16 +89,11 @@
   Void  codeVPSVUI             ( TComVPS* pcVPS );
 #endif 
-#endif
   Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
-#if H_MV5
 #if H_MV
   Void  codeSPSExtension        ( TComSPS* pcSPS ); 
 #endif
-#endif
 #if H_3D
-#if H_MV5
   Void  codeVPSExtension2       ( TComVPS* pcVPS ); 
   Void  codeSPSExtension2       ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag  ); 
-#endif
   Void  codeSPS                 ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag );
 #else
@@ -133,5 +127,5 @@
   Void codeICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Void codeInterSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeInterSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment );
Index: trunk/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 655)
@@ -77,7 +77,4 @@
   Int m_interLayerPredLayerIdc [MAX_NUM_REF_PICS];
   Int m_interViewRefPosL[2][MAX_NUM_REF_PICS];  
-#if !H_MV5
-  Int m_collocatedRefLayerIdx; 
-#endif
 #endif
   GOPEntry()
@@ -97,7 +94,4 @@
 #if H_MV
   , m_numActiveRefLayerPics(0)
-#if !H_MV5
-  , m_collocatedRefLayerIdx(-1)
-#endif
 #endif
   {
@@ -310,8 +304,22 @@
   Int       m_RCInitialQP;
   Bool      m_RCForceIntraQP;
+
+#if KWU_RC_MADPRED_E0227
+  UInt       m_depthMADPred;
+#endif
+#if KWU_RC_VIEWRC_E0227
+  Bool      m_bViewWiseRateCtrl;
+#endif
 #else
   Bool      m_enableRateCtrl;                                ///< Flag for using rate control algorithm
   Int       m_targetBitrate;                                 ///< target bitrate
   Int       m_numLCUInUnit;                                  ///< Total number of LCUs in a frame should be divided by the NumLCUInUnit
+
+#if KWU_RC_MADPRED_E0227
+  UInt       m_depthMADPred;
+#endif
+#if KWU_RC_VIEWRC_E0227
+  Bool      m_bViewWiseRateCtrl;
+#endif
 #endif
   Bool      m_TransquantBypassEnableFlag;                     ///< transquant_bypass_enable_flag setting in PPS.
@@ -361,13 +369,8 @@
   Int       m_layerIdInVps;
   Int       m_viewId;
-#if H_MV5
   Int       m_viewIndex; 
-#endif
 #endif 
 
 #if H_3D
-#if !H_MV5
-  Int       m_viewIndex; 
-#endif
   Bool      m_isDepth;
 
@@ -403,5 +406,5 @@
   Bool      m_bUseIC;
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   bool      m_bInterSDC;
 #endif
@@ -426,11 +429,6 @@
   , m_layerIdInVps(-1)
   , m_viewId(-1)
-#if H_MV5
   , m_viewIndex(-1)
-#endif
 #if H_3D
-#if !H_MV5
-  , m_viewIndex(-1)
-#endif
   , m_isDepth(false)
   , m_bUseVSO(false)
@@ -465,13 +463,7 @@
   Void      setViewId                        ( Int viewId  )      { m_viewId  = viewId;  }
   Int       getViewId                        ()                   { return m_viewId;    }
-#if H_MV5
   Void      setViewIndex                     ( Int viewIndex  )   { m_viewIndex  = viewIndex;  }
   Int       getViewIndex                     ()                   { return m_viewIndex;    }
-#endif
 #if H_3D
-#if !H_MV5
-  Void      setViewIndex                     ( Int viewIndex  )   { m_viewIndex  = viewIndex;  }
-  Int       getViewIndex                     ()                   { return m_viewIndex;    }
-#endif
   Void      setIsDepth                       ( Bool isDepth )   { m_isDepth = isDepth; }
   Bool      getIsDepth                       ()                 { return m_isDepth; }
@@ -514,5 +506,5 @@
   Bool       getUseIC                       ()               { return m_bUseIC; }
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Void       setInterSDCEnable              ( Bool bVal )    { m_bInterSDC = bVal; }
   Bool       getInterSDCEnable              ()               { return m_bInterSDC; }
@@ -826,4 +818,13 @@
   Bool      getForceIntraQP        ()              { return m_RCForceIntraQP;        }
   Void      setForceIntraQP        ( Bool b )      { m_RCForceIntraQP = b;           }
+
+#if KWU_RC_MADPRED_E0227
+  UInt      getUseDepthMADPred    ()                { return m_depthMADPred;        }
+  Void      setUseDepthMADPred    (UInt b)          { m_depthMADPred    = b;        }
+#endif
+#if KWU_RC_VIEWRC_E0227
+  Bool      getUseViewWiseRateCtrl    ()                { return m_bViewWiseRateCtrl;        }
+  Void      setUseViewWiseRateCtrl    (Bool b)          { m_bViewWiseRateCtrl    = b;        }
+#endif
 #else
   Bool      getUseRateCtrl    ()                { return m_enableRateCtrl;    }
@@ -833,4 +834,13 @@
   Int       getNumLCUInUnit   ()                { return m_numLCUInUnit;      }
   Void      setNumLCUInUnit   (Int numLCUs)     { m_numLCUInUnit   = numLCUs; }
+
+#if KWU_RC_MADPRED_E0227
+  UInt      getUseDepthMADPred    ()                { return m_depthMADPred;        }
+  Void      setUseDepthMADPred    (UInt b)          { m_depthMADPred    = b;        }
+#endif
+#if KWU_RC_VIEWRC_E0227
+  Bool      getUseViewWiseRateCtrl    ()                { return m_bViewWiseRateCtrl;        }
+  Void      setUseViewWiseRateCtrl    (Bool b)          { m_bViewWiseRateCtrl    = b;        }
+#endif
 #endif
   Bool      getTransquantBypassEnableFlag()           { return m_TransquantBypassEnableFlag; }
Index: trunk/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 655)
@@ -103,8 +103,22 @@
   
   m_bEncodeDQP = false;
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if RATE_CONTROL_LAMBDA_DOMAIN
+#if !M0036_RC_IMPROVEMENT
   m_LCUPredictionSAD = 0;
   m_addSADDepth      = 0;
   m_temporalSAD      = 0;
+#endif
+#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+  m_LCUPredictionSAD = 0;
+  m_addSADDepth      = 0;
+  m_temporalSAD      = 0;
+  m_spatialSAD       = 0;
+#endif
+#endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
+  m_LCUPredictionSAD = 0;
+  m_addSADDepth      = 0;
+  m_temporalSAD      = 0;
+  m_spatialSAD       = 0;
 #endif
 
@@ -256,8 +270,22 @@
   m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
 
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if RATE_CONTROL_LAMBDA_DOMAIN
+#if !M0036_RC_IMPROVEMENT
   m_addSADDepth      = 0;
   m_LCUPredictionSAD = 0;
   m_temporalSAD      = 0;
+#endif
+#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+  m_LCUPredictionSAD = 0;
+  m_addSADDepth      = 0;
+  m_temporalSAD      = 0;
+  m_spatialSAD       = 0;
+#endif
+#endif
+#if KWU_RC_MADPRED_E0227
+  m_LCUPredictionSAD = 0;
+  m_addSADDepth      = 0;
+  m_temporalSAD      = 0;
+  m_spatialSAD       = 0;
 #endif
 
@@ -404,7 +432,8 @@
 
   // variables for fast encoder decision
-  Bool    bEarlySkip  = false;
-  Bool    bTrySplit    = true;
-  Double  fRD_Skip    = MAX_DOUBLE;
+#if H_3D_QTLPC  
+  Bool    bTrySplit     = true;
+  Bool    bTrySplitDQP  = true;
+#endif
 
   // variable for Early CU determination
@@ -415,5 +444,4 @@
   Bool earlyDetectionSkipMode = false;
 
-  Bool    bTrySplitDQP  = true;
 #if H_3D_VSP
   DisInfo DvInfo; 
@@ -425,13 +453,4 @@
 #endif
 #endif
-  static  Double  afCost[ MAX_CU_DEPTH ];
-  static  Int      aiNum [ MAX_CU_DEPTH ];
-
-  if ( rpcBestCU->getAddr() == 0 )
-  {
-    ::memset( afCost, 0, sizeof( afCost ) );
-    ::memset( aiNum,  0, sizeof( aiNum  ) );
-  }
-
   Bool bBoundary = false;
   UInt uiLPelX   = rpcBestCU->getCUPelX();
@@ -489,5 +508,5 @@
   if(!bSliceEnd && !bSliceStart && bInsidePicture )
   {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
     Bool bIVFMerge = false;
     Int  iIVFMaxD = 0;
@@ -501,7 +520,7 @@
       }
       // variables for fast encoder decision
-      bEarlySkip  = false;
+#if H_3D_QTLPC
       bTrySplit    = true;
-      fRD_Skip    = MAX_DOUBLE;
+#endif
 
       rpcTempCU->initEstData( uiDepth, iQP );
@@ -560,5 +579,5 @@
         }
       }
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
       if(rpcTempCU->getSlice()->getViewIndex() && !rpcTempCU->getSlice()->getIsDepth())
       {
@@ -584,5 +603,5 @@
           rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
 #endif
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
           xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N
 #else
@@ -598,5 +617,5 @@
 #endif
         xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
         bFMD = bIVFMerge && rpcBestCU->isSkipped(0);
 #endif
@@ -605,24 +624,12 @@
         rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
-        // fast encoder decision for early skip
-        if ( m_pcEncCfg->getUseFastEnc() )
-        {
-          Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
-          if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] )
-          {
-            bEarlySkip = true;
-            bTrySplit  = false;
-          }
-        }
 
         if(!m_pcEncCfg->getUseEarlySkipDetection())
         {
           // 2Nx2N, NxN
-          if ( !bEarlySkip )
-          {
 #if H_3D_IC
             rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
 #endif
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP );
 #else
@@ -636,5 +643,4 @@
               doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
             }
-          }
         }
 #if H_3D_IC
@@ -643,25 +649,9 @@
       }
 
-#if H_3D_QTLPC
+#if H_3D_QTLPC      
       if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL())
       {
         bTrySplitDQP = bTrySplit;
       }
-      else
-      {
-#endif
-        if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
-        {
-          if(iQP == iBaseQP)
-          {
-            bTrySplitDQP = bTrySplit;
-          }
-        }
-        else
-        {
-          bTrySplitDQP = bTrySplit;
-        }
-#if H_3D_QTLPC
-      }
 #endif
       if (isAddLowestQP && (iQP == lowestQP))
@@ -678,4 +668,26 @@
     }
 #endif
+#if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+    if ( uiDepth <= m_addSADDepth )
+    {
+      m_LCUPredictionSAD += m_temporalSAD;
+      m_addSADDepth = uiDepth;
+    }
+#endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
+if ( uiDepth <= m_addSADDepth )
+{
+  m_LCUPredictionSAD += m_temporalSAD;
+  m_addSADDepth = uiDepth;
+}
+#endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
+    if(m_pcEncCfg->getUseRateCtrl())
+    {
+      Int qp = m_pcRateCtrl->getUnitQP();
+      iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
+      iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
+    }
+#endif
 
 #if H_3D_DIM_ENC
@@ -700,6 +712,4 @@
         {
           // 2Nx2N, NxN
-          if ( !bEarlySkip )
-          {
             if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
             {
@@ -710,5 +720,5 @@
                 )
               {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFMD  );
 #else
@@ -721,5 +731,4 @@
               }
             }
-          }
 
           // 2NxN, Nx2N
@@ -730,5 +739,5 @@
             )
           {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFMD  );
 #else
@@ -750,5 +759,5 @@
             )
           {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
             xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN, bFMD  );
 #else
@@ -789,5 +798,5 @@
                 )
               {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD );
 #else
@@ -809,5 +818,5 @@
                 )
               {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD );
 #else
@@ -833,5 +842,5 @@
                 )
               {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD, true );
 #else
@@ -853,5 +862,5 @@
                 )
               {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD, true );
 #else
@@ -879,5 +888,5 @@
                 )
               {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD );
 #else
@@ -899,5 +908,5 @@
                 )
               {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD );
 #else
@@ -919,5 +928,5 @@
                 )
               {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD, true );
 #else
@@ -939,5 +948,5 @@
                 )
               {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD, true );
 #else
@@ -990,15 +999,10 @@
 #endif
         }
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
         if(!bFMD)
         {
 #endif
         // do normal intra modes
-#if H_3D_DIM_ENC
-        if ( !bEarlySkip || ( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) )
-#else
-        if ( !bEarlySkip )
-#endif
-        {
+       
           // speedup for inter frames
           if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || 
@@ -1012,4 +1016,27 @@
           {
             xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
+
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+            if ( uiDepth <= m_addSADDepth )
+            {
+              m_LCUPredictionSAD += m_spatialSAD;
+              m_addSADDepth = uiDepth;
+            }
+#endif
+#if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+            if ( uiDepth <= m_addSADDepth )
+            {
+              m_LCUPredictionSAD += m_spatialSAD;
+              m_addSADDepth = uiDepth;
+            }
+#endif
+
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
+            if ( uiDepth <= m_addSADDepth )
+            {
+              m_LCUPredictionSAD += m_spatialSAD;
+              m_addSADDepth = uiDepth;
+            }
+#endif
             rpcTempCU->initEstData( uiDepth, iQP );
             if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
@@ -1029,6 +1056,4 @@
             }
           }
-        }
-
         // test PCM
         if(pcPic->getSlice(0)->getSPS()->getUsePCM()
@@ -1049,5 +1074,5 @@
           }
         }
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
         }
 #endif
@@ -1074,15 +1099,4 @@
     rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
 
-    // accumulate statistics for early skip
-    if ( m_pcEncCfg->getUseFastEnc() )
-    {
-      if ( rpcBestCU->isSkipped(0) )
-      {
-        Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
-        afCost[ iIdx ] += rpcBestCU->getTotalCost();
-        aiNum [ iIdx ] ++;
-      }
-    }
-
     // Early CU determination
     if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
@@ -1094,5 +1108,5 @@
       bSubBranch = true;
     }
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
     if(rpcBestCU->getSlice()->getViewIndex() && !rpcBestCU->getSlice()->getIsDepth() && (uiDepth >=iIVFMaxD) && rpcBestCU->isSkipped(0))
     {
@@ -1168,5 +1182,9 @@
 
     // further split
+#if H_3D_QTLPC
     if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
+#else
+    if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
+#endif
     {
 #if H_3D_VSO // M9
@@ -1580,5 +1598,5 @@
   m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   m_pcEntropyCoder->encodeInterSDCFlag( pcCU, uiAbsPartIdx, false );
 #endif
@@ -1875,5 +1893,5 @@
 
           rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
           TComDataCU *rpcTempCUPre = rpcTempCU;
 #endif
@@ -1881,5 +1899,5 @@
           xCheckDQP( rpcTempCU );
           xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
           if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() && !uiNoResidual )
           {
@@ -1917,5 +1935,5 @@
       if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
       {
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
         if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) )
         {
@@ -1926,5 +1944,5 @@
 #endif
         bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
         }
 #endif
@@ -1971,5 +1989,5 @@
 
 #if AMP_MRG
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
 Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bFMD, Bool bUseMRG)
 #else
@@ -1980,5 +1998,5 @@
 #endif
 {
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
   if(!(bFMD && (ePartSize == SIZE_2Nx2N)))  //have  motion estimation or merge check
   {
@@ -2057,5 +2075,5 @@
 #if AMP_MRG
   rpcTempCU->setMergeAMP (true);
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
   m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bFMD, false, bUseMRG );
 #else
@@ -2102,5 +2120,5 @@
 #endif
 
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if RATE_CONTROL_LAMBDA_DOMAIN  && (!M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227)
   if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
   {
@@ -2111,4 +2129,13 @@
   }
 #endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN  && KWU_RC_MADPRED_E0227
+  if ( m_pcEncCfg->getUseRateCtrl() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
+  {
+    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
+      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
+      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
+    m_temporalSAD = (Int)SAD;
+  }
+#endif
 
   m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
@@ -2121,10 +2148,10 @@
 #endif
   rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   TComDataCU *rpcTempCUPre = rpcTempCU;
 #endif
   xCheckDQP( rpcTempCU );
   xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() )
   {
@@ -2163,5 +2190,5 @@
   }
 #endif
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
   }
 #endif
@@ -2235,4 +2262,34 @@
   rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
   
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+  UChar uhDepth = rpcTempCU->getDepth( 0 );
+  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
+  {
+    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
+      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
+      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
+    m_spatialSAD = (Int)SAD;
+  }
+#endif
+#if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+  UChar uhDepth = rpcTempCU->getDepth( 0 );
+  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
+  {
+    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
+      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
+      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
+    m_spatialSAD = (Int)SAD;
+  }
+#endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
+  UChar uhDepth = rpcTempCU->getDepth( 0 );
+  if ( m_pcEncCfg->getUseRateCtrl() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
+  {
+    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
+      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
+      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
+    m_spatialSAD = (Int)SAD;
+  }
+#endif
   xCheckDQP( rpcTempCU );
   xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth);
Index: trunk/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCu.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncCu.h	(revision 655)
@@ -102,9 +102,24 @@
   Bool                    m_bUseSBACRD;
   TEncRateCtrl*           m_pcRateCtrl;
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if RATE_CONTROL_LAMBDA_DOMAIN
+#if !M0036_RC_IMPROVEMENT
   UInt                    m_LCUPredictionSAD;
   Int                     m_addSADDepth;
   Int                     m_temporalSAD;
 #endif
+#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+  UInt                    m_LCUPredictionSAD;
+  Int                     m_addSADDepth;
+  Int                     m_temporalSAD;
+  Int                     m_spatialSAD;
+#endif
+#endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
+  UInt                    m_LCUPredictionSAD;
+  Int                     m_addSADDepth;
+  Int                     m_temporalSAD;
+  Int                     m_spatialSAD;
+#endif
+
 public:
   /// copy parameters from encoder class
@@ -124,5 +139,5 @@
   
   Void setBitCounter        ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; }
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
   UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; }
 #endif
@@ -145,5 +160,5 @@
 
 #if AMP_MRG
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
   Void  xCheckRDCostInter   ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize,  Bool bFMD, Bool bUseMRG = false  ) ;
 #else
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 655)
@@ -662,5 +662,5 @@
 #endif
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
   {
@@ -824,5 +824,5 @@
 }
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 Void TEncEntropy::encodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
 {
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 655)
@@ -94,5 +94,5 @@
   virtual Void codeICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   virtual Void codeInterSDCFlag  ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
   virtual Void codeInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) = 0;
@@ -185,5 +185,5 @@
   Void encodeICFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Void encodeInterSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
   Void encodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD );
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 655)
@@ -153,4 +153,8 @@
 #endif
 #endif
+
+#if KWU_FIX_URQ
+  m_pcRateCtrl           = pcTEncTop->getRateCtrl();
+#endif
 }
 
@@ -351,7 +355,7 @@
 #endif
 #if H_MV
-Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid)
-#else
-Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
+Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid, bool isField, bool isTff)
+#else
+Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, bool isField, bool isTff)
 #endif
 {
@@ -367,5 +371,6 @@
 
 #if !H_MV
-  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut );
+  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField );
+
   
   m_iNumPicCoded = 0;
@@ -439,10 +444,21 @@
 
     /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding
-    Int pocCurr = iPOCLast -iNumPicRcvd+ m_pcCfg->getGOPEntry(iGOPid).m_POC;
-    Int iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
-    if(iPOCLast == 0)
+    Int iTimeOffset;
+    Int pocCurr;
+    
+    if(iPOCLast == 0) //case first frame or first top field
     {
       pocCurr=0;
       iTimeOffset = 1;
+    }
+    else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value
+    {
+      pocCurr = 1;
+      iTimeOffset = 1;
+    }
+    else
+    {
+      pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField;
+      iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
     }
     if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
@@ -463,5 +479,5 @@
     accessUnitsInGOP.push_back(AccessUnit());
     AccessUnit& accessUnit = accessUnitsInGOP.back();
-    xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr );
+    xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField);
 
     //  Slice data initialization
@@ -472,25 +488,17 @@
 
 
-#if H_MV5
 #if H_MV
-    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId() );     
-#else
-    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
-#endif
-#else
-#if H_3D
-    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId() );     
-#else
-    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
-#endif
-#endif
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId(), isField  );     
+#else
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), isField  );
+#endif
+    
+    //Set Frame/Field coding
+    pcSlice->getPic()->setField(isField);
+
     pcSlice->setLastIDR(m_iLastIDR);
     pcSlice->setSliceIdx(0);
 #if H_MV
-#if H_MV5
     pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
-#else
-    pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer ); 
-#endif
     pcPic  ->setLayerId     ( getLayerId()   );
     pcPic  ->setViewId      ( getViewId()    );    
@@ -508,5 +516,4 @@
     pcSlice->setLFCrossSliceBoundaryFlag(  pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()  );
     pcSlice->setScalingList ( m_pcEncTop->getScalingList()  );
-    pcSlice->getScalingList()->setUseTransformSkip(m_pcEncTop->getPPS()->getUseTransformSkip());
     if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF)
     {
@@ -562,5 +569,7 @@
     if(pcSlice->getTemporalLayerNonReferenceFlag())
     {
-      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
+      if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R &&
+          !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE))
+        // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker)
       {
         pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N);
@@ -655,5 +664,4 @@
     refPicListModification->setRefPicListModificationFlagL1(0);
 #if H_MV
-#if H_MV5
     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 1 )
     {
@@ -699,56 +707,4 @@
     xSetRefPicListModificationsMv( tempRefPicLists, pcSlice, iGOPid );    
 #else
-    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
-    {
-      pcSlice->setDiscardableFlag           ( false );     
-    }    
-
-    TComVPS*           vps = pcSlice->getVPS(); 
-    Int       layerIdInVps = vps    ->getLayerIdInVps( getLayerId()); 
-    Int numDirectRefLayers = vps    ->getNumDirectRefLayers( layerIdInVps ); 
-    GOPEntry gopEntry      = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid );     
-    
-    if ( getLayerId() > 0 && numDirectRefLayers > 0 )
-    {         
-      pcSlice->setInterLayerPredEnabledFlag ( gopEntry.m_numActiveRefLayerPics > 0 );     
-      if ( pcSlice->getInterLayerPredEnabledFlag() && numDirectRefLayers > 1 )
-      {
-        if ( !vps->getMaxOneActiveRefLayerFlag() )
-        {    
-          pcSlice->setNumInterLayerRefPicsMinus1( gopEntry.m_numActiveRefLayerPics - 1 ); 
-        }
-        for (Int i = 0; i < gopEntry.m_numActiveRefLayerPics; i++ )
-        {
-          pcSlice->setInterLayerPredLayerIdc( i, gopEntry.m_interLayerPredLayerIdc[ i ] ); 
-        }
-      }
-    }
-    assert( pcSlice->getNumActiveRefLayerPics() == gopEntry.m_numActiveRefLayerPics ); 
-    
-    if ( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0 && pcSlice->getNumActiveRefLayerPics() > 0)
-    {
-      pcSlice->setInterLayerSamplePredOnlyFlag( gopEntry.m_numRefPics == 0 ); 
-    }    
-
-    pcSlice->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
-    pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) );
-    pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) );
-
-    xSetRefPicListModificationsMv( pcSlice, iGOPid );    
-
-    pcSlice->setActiveMotionPredRefLayers( );
-
-    if ( getLayerId() > 0 && pcSlice->getNumActiveMotionPredRefLayers() > 0 && pcSlice->getEnableTMVPFlag() && 
-        ( pcSlice->getSliceType() == B_SLICE || pcSlice->getSliceType() == P_SLICE ))
-    {
-      pcSlice->setAltCollocatedIndicationFlag( gopEntry.m_collocatedRefLayerIdx >= 0 );
-      if ( pcSlice->getNumActiveRefLayerPics() && pcSlice->getNumActiveMotionPredRefLayers() > 0 )
-      {
-        pcSlice->setCollocatedRefLayerIdx( gopEntry.m_collocatedRefLayerIdx );
-      }
-    }
-
-#endif
-#else
     pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
     pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
@@ -760,5 +716,4 @@
 
     //  Set reference list
-#if H_MV5
 #if H_MV    
     pcSlice->setRefPicList( tempRefPicLists, usedAsLongTerm, numPocTotalCurr ); 
@@ -782,26 +737,4 @@
       }
     }
-#endif
-#else
-#if H_MV    
-    pcSlice->setRefPicList( rcListPic, m_refPicSetInterLayer );
-#if H_3D_ARP
-    pcSlice->setARPStepNum();
-    if(pcSlice->getARPStepNum() > 1)
-    {
-      for(Int iLayerId = 0; iLayerId < getLayerId(); iLayerId ++ )
-      {
-        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
-        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
-        if( iViewIdx<getViewIndex() && !bIsDepth )
-        {
-          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
-        }
-      }
-    }
-#endif
-#else
-    pcSlice->setRefPicList ( rcListPic );
-#endif
 #endif
 #if H_3D
@@ -913,6 +846,13 @@
 
     // SAIT_VSO_EST_A0033
+#if H_3D_FCO
+    Bool flagRec;
+    flagRec =  ((m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false, pcSlice->getPOC(), true) == NULL) ? false: true);
+    pcRdCost->setVideoRecPicYuv( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false, pcSlice->getPOC(), flagRec ) );
+    pcRdCost->setDepthPicYuv   ( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), true, pcSlice->getPOC(), false ) );
+#else
     pcRdCost->setVideoRecPicYuv( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false , pcSlice->getPOC(), true ) );
     pcRdCost->setDepthPicYuv   ( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), true  , pcSlice->getPOC(), false ) );
+#endif
 
     // LGE_WVSO_A0119
@@ -970,4 +910,12 @@
       }
       m_pcRateCtrl->initRCPic( frameLevel );
+
+#if KWU_RC_MADPRED_E0227
+      if(m_pcCfg->getLayerId() != 0)
+      {
+        m_pcRateCtrl->getRCPic()->setIVPic( m_pcEncTop->getEncTop()->getTEncTop(0)->getRateCtrl()->getRCPic() );
+      }
+#endif
+
       estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits();
 
@@ -1014,4 +962,14 @@
       else    // normal case
       {
+#if KWU_RC_MADPRED_E0227
+        if(m_pcRateCtrl->getLayerID() != 0)
+        {
+          list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
+          lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambdaIV( listPreviousPicture, pcSlice->getPOC() );
+          sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
+        }
+        else
+        {
+#endif
         list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
 #if RATE_CONTROL_INTRA
@@ -1021,4 +979,7 @@
 #endif
         sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
+#if KWU_RC_MADPRED_E0227
+        }
+#endif
       }
 
@@ -1155,16 +1116,16 @@
         pcPic->setNumDdvCandPics(pcPic->getDisCandRefPictures(iColPoc));
       }
+#endif
 #if H_3D
       pcSlice->setDepthToDisparityLUTs(); 
 
 #endif
-#endif
-#if MTK_NBDV_TN_FIX_E0172 
+
+#if H_3D_NBDV
       if(pcSlice->getViewIndex() && !pcSlice->getIsDepth() && !pcSlice->isIntra()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
       {
         pcPic->checkTemporalIVRef();
       }
-#endif
-#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
+
       if(pcSlice->getIsDepth())
       {
@@ -1412,5 +1373,5 @@
         }
       }
-      pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the .
+      pictureTimingSEI.m_auCpbRemovalDelay = std::min<Int>(std::max<Int>(1, m_totalCoded - m_lastBPSEI), static_cast<Int>(pow(2, static_cast<double>(pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getCpbRemovalDelayLengthMinus1()+1)))); // Syntax element signalled as minus, hence the .
       pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
       Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
@@ -1862,5 +1823,5 @@
         pcPic->destroyNonDBFilterInfo();
       }
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
+#if H_3D
       pcPic->compressMotion(2); 
 #endif
@@ -1898,5 +1859,5 @@
           digestStr = digestToString(sei_recon_picture_digest.digest, 4);
         }
-#if H_MV_FIX_LID_PIC_HASH_SEI_T40
+#if H_MV
         OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer(), getLayerId() );
 #else
@@ -1940,4 +1901,18 @@
       xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime );
 
+    //In case of field coding, compute the interlaced PSNR for both fields
+    if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)))
+    {
+      //get complementary top field
+      TComPic* pcPicTop;
+      TComList<TComPic*>::iterator   iterPic = rcListPic.begin();
+      while ((*iterPic)->getPOC() != pcPic->getPOC()-1)
+      {
+        iterPic ++;
+      }
+      pcPicTop = *(iterPic);
+      xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime );
+    }
+    
       if (digestStr)
       {
@@ -2072,4 +2047,5 @@
             OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
           m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
+          pictureTimingSEI.m_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0;
           m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
           writeRBSPTrailingBits(nalu.m_Bitstream);
@@ -2166,9 +2142,5 @@
       pcPic->setReconMark   ( true );
 #if H_MV
-#if H_MV5
       TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 );  
-#else
-      TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer );  
-#endif
       std::vector<Int> temp; 
       TComSlice::markCurrPic( pcPic ); 
@@ -2184,5 +2156,5 @@
       delete[] pcSubstreamsOut;
   }
-#if !RATE_CONTROL_LAMBDA_DOMAIN
+#if !KWU_FIX_URQ && !RATE_CONTROL_LAMBDA_DOMAIN
   if(m_pcCfg->getUseRateCtrl())
   {
@@ -2196,10 +2168,10 @@
 
 #if !H_MV
-  assert ( m_iNumPicCoded == iNumPicRcvd );
+  assert ( (m_iNumPicCoded == iNumPicRcvd) || (isField && iPOCLast == 1) );
 #endif
 }
 
 #if !H_MV
-Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded)
+Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, bool isField)
 {
   assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic());
@@ -2207,8 +2179,18 @@
     
   //--CFG_KDY
+  if(isField)
+  {
+    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() * 2);
+    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() * 2);
+    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() * 2);
+    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() * 2);
+  }
+  else
+  {
   m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
   m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
   m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
   m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
+  }
   
   //-- all
@@ -2233,4 +2215,16 @@
   m_gcAnalyzeB.printSummary('B');
 #endif
+
+  if(isField)
+  {
+    //-- interlaced summary
+    m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate());
+    printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
+    m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll.getBits());
+    
+#if _SUMMARY_OUT_
+    m_gcAnalyzeAll_in.printSummaryOutInterlaced();
+#endif
+  }
 
   printf("\nRVM: %.3lf\n" , xCalculateRVM());
@@ -2276,4 +2270,22 @@
 // Protected member functions
 // ====================================================================================================================
+
+
+Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, bool isField )
+{
+  assert( iNumPicRcvd > 0 );
+  //  Exception for the first frames
+  if ( ( isField && (iPOCLast == 0 || iPOCLast == 1) ) || (!isField  && (iPOCLast == 0))  )
+  {
+    m_iGopSize    = 1;
+  }
+  else
+  {
+    m_iGopSize    = m_pcCfg->getGOPSize();
+  }
+  assert (m_iGopSize > 0);
+  
+  return;
+}
 
 Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut )
@@ -2299,14 +2311,34 @@
                          TComPic*&                 rpcPic,
                          TComPicYuv*&              rpcPicYuvRecOut,
-                         Int                       pocCurr )
+                         Int                       pocCurr,
+                         bool                      isField)
 {
   Int i;
   //  Rec. output
   TComList<TComPicYuv*>::iterator     iterPicYuvRec = rcListPicYuvRecOut.end();
-  for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ )
+  
+  if (isField)
+  {
+    for ( i = 0; i < ( (pocCurr == 0 ) || (pocCurr == 1 ) ? (iNumPicRcvd - iTimeOffset + 1) : (iNumPicRcvd - iTimeOffset + 2) ); i++ )
+    {
+      iterPicYuvRec--;
+    }
+  }
+  else
+  {
+    for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ )
   {
     iterPicYuvRec--;
   }
   
+  }
+  
+  if (isField)
+  {
+    if(pocCurr == 1)
+    {
+      iterPicYuvRec++;
+    }
+  }
   rpcPicYuvRecOut = *(iterPicYuvRec);
   
@@ -2323,5 +2355,8 @@
     iterPic++;
   }
-  
+
+#if !H_MV
+  assert( rpcPic != NULL );
+#endif
   assert (rpcPic->getPOC() == pocCurr);
   
@@ -2642,4 +2677,167 @@
 }
 
+
+Void reinterlace(Pel* top, Pel* bottom, Pel* dst, UInt stride, UInt width, UInt height, bool isTff)
+{
+  
+  for (Int y = 0; y < height; y++)
+  {
+    for (Int x = 0; x < width; x++)
+    {
+      dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
+      dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
+    }
+    top += stride;
+    bottom += stride;
+    dst += stride*2;
+  }
+}
+
+
+Void TEncGOP::xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime )
+{
+#if  H_MV
+  assert( 0 ); // Field coding and MV need to be aligned. 
+#else
+  Int     x, y;
+  
+  UInt64 uiSSDY_in  = 0;
+  UInt64 uiSSDU_in  = 0;
+  UInt64 uiSSDV_in  = 0;
+  
+  Double  dYPSNR_in  = 0.0;
+  Double  dUPSNR_in  = 0.0;
+  Double  dVPSNR_in  = 0.0;
+  
+  /*------ INTERLACED PSNR -----------*/
+  
+  /* Luma */
+  
+  Pel*  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getLumaAddr();
+  Pel*  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getLumaAddr();
+  Pel*  pRecTop = pcPicRecTop->getLumaAddr();
+  Pel*  pRecBottom = pcPicRecBottom->getLumaAddr();
+  
+  Int   iWidth;
+  Int   iHeight;
+  Int iStride;
+  
+  iWidth  = pcPicOrgTop->getPicYuvOrg()->getWidth () - m_pcEncTop->getPad(0);
+  iHeight = pcPicOrgTop->getPicYuvOrg()->getHeight() - m_pcEncTop->getPad(1);
+  iStride = pcPicOrgTop->getPicYuvOrg()->getStride();
+  Int   iSize   = iWidth*iHeight;
+  bool isTff = pcPicOrgTop->isTopField();
+  
+  TComPicYuv* pcOrgInterlaced = new TComPicYuv;
+  pcOrgInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+  
+  TComPicYuv* pcRecInterlaced = new TComPicYuv;
+  pcRecInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+  
+  Pel* pOrgInterlaced = pcOrgInterlaced->getLumaAddr();
+  Pel* pRecInterlaced = pcRecInterlaced->getLumaAddr();
+  
+  //=== Interlace fields ====
+  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
+  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
+  
+  //===== calculate PSNR =====
+  for( y = 0; y < iHeight << 1; y++ )
+  {
+    for( x = 0; x < iWidth; x++ )
+    {
+      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
+      uiSSDY_in   += iDiff * iDiff;
+    }
+    pOrgInterlaced += iStride;
+    pRecInterlaced += iStride;
+  }
+  
+  /*Chroma*/
+  
+  iHeight >>= 1;
+  iWidth  >>= 1;
+  iStride >>= 1;
+  
+  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCbAddr();
+  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCbAddr();
+  pRecTop = pcPicRecTop->getCbAddr();
+  pRecBottom = pcPicRecBottom->getCbAddr();
+  pOrgInterlaced = pcOrgInterlaced->getCbAddr();
+  pRecInterlaced = pcRecInterlaced->getCbAddr();
+  
+  //=== Interlace fields ====
+  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
+  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
+  
+  //===== calculate PSNR =====
+  for( y = 0; y < iHeight << 1; y++ )
+  {
+    for( x = 0; x < iWidth; x++ )
+    {
+      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
+      uiSSDU_in   += iDiff * iDiff;
+    }
+    pOrgInterlaced += iStride;
+    pRecInterlaced += iStride;
+  }
+  
+  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCrAddr();
+  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCrAddr();
+  pRecTop = pcPicRecTop->getCrAddr();
+  pRecBottom = pcPicRecBottom->getCrAddr();
+  pOrgInterlaced = pcOrgInterlaced->getCrAddr();
+  pRecInterlaced = pcRecInterlaced->getCrAddr();
+  
+  //=== Interlace fields ====
+  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
+  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
+  
+  //===== calculate PSNR =====
+  for( y = 0; y < iHeight << 1; y++ )
+  {
+    for( x = 0; x < iWidth; x++ )
+    {
+      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
+      uiSSDV_in   += iDiff * iDiff;
+    }
+    pOrgInterlaced += iStride;
+    pRecInterlaced += iStride;
+  }
+  
+  Int maxvalY = 255 << (g_bitDepthY-8);
+  Int maxvalC = 255 << (g_bitDepthC-8);
+  Double fRefValueY = (Double) maxvalY * maxvalY * iSize*2;
+  Double fRefValueC = (Double) maxvalC * maxvalC * iSize*2 / 4.0;
+  dYPSNR_in            = ( uiSSDY_in ? 10.0 * log10( fRefValueY / (Double)uiSSDY_in ) : 99.99 );
+  dUPSNR_in            = ( uiSSDU_in ? 10.0 * log10( fRefValueC / (Double)uiSSDU_in ) : 99.99 );
+  dVPSNR_in            = ( uiSSDV_in ? 10.0 * log10( fRefValueC / (Double)uiSSDV_in ) : 99.99 );
+  
+  /* calculate the size of the access unit, excluding:
+   *  - any AnnexB contributions (start_code_prefix, zero_byte, etc.,)
+   *  - SEI NAL units
+   */
+  UInt numRBSPBytes = 0;
+  for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++)
+  {
+    UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
+    
+    if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
+      numRBSPBytes += numRBSPBytes_nal;
+  }
+  
+  UInt uibits = numRBSPBytes * 8 ;
+  
+  //===== add PSNR =====
+  m_gcAnalyzeAll_in.addResult (dYPSNR_in, dUPSNR_in, dVPSNR_in, (Double)uibits);
+  
+  printf("\n                                      Interlaced frame %d: [Y %6.4lf dB    U %6.4lf dB    V %6.4lf dB]", pcPicOrgBottom->getPOC()/2 , dYPSNR_in, dUPSNR_in, dVPSNR_in );
+  
+  pcOrgInterlaced->destroy();
+  delete pcOrgInterlaced;
+  pcRecInterlaced->destroy();
+  delete pcRecInterlaced;
+#endif
+}
 /** Function for deciding the nal_unit_type.
  * \param pocCurr POC of the current picture
@@ -3002,5 +3200,4 @@
 
 #if H_MV
-#if H_MV5
 Void TEncGOP::xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid )
 { 
@@ -3086,68 +3283,4 @@
   }
 }
-#else
-Void TEncGOP::xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid )
-{ 
-  Int layer    = pcSlice->getLayerIdInVps( ); 
-  
-  if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getPPS()->getListsModificationPresentFlag()) || pcSlice->getNumActiveRefLayerPics() == 0 )
-  {
-    return;
-  }
-
-  // analyze inter-view modifications
-  GOPEntry ge = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && ( layer > 0) ) ? MAX_GOP : iGOPid );
-  assert( ge.m_numActiveRefLayerPics == pcSlice->getNumActiveRefLayerPics() ); 
-  
-  Int maxRefListSize  = pcSlice->getNumRpsCurrTempList();
-  Int numTemporalRefs = maxRefListSize - pcSlice->getNumActiveRefLayerPics();
-
-  for (Int li = 0; li < 2; li ++) // Loop over lists L0 and L1
-  {
-    // set inter-view modifications    
-    Int tempList[16];
-    for( Int k = 0; k < 16; k++ )
-    {
-      tempList[ k ] = -1;
-    }
-
-    Bool isModified = false;
-    if ( maxRefListSize > 1 )
-    {
-      for( Int k = 0, orgIdx = numTemporalRefs; k < ge.m_numActiveRefLayerPics; k++, orgIdx++ )
-      {
-          Int targetIdx = ge.m_interViewRefPosL[ li ][ k ];
-
-        isModified = ( targetIdx != orgIdx ) && ( targetIdx >= 0  );
-        if ( isModified )
-            {
-          assert( tempList[ targetIdx ] == -1 ); // Assert when two inter layer reference pictures are sorted to the same position
-              tempList[ targetIdx ] = orgIdx;              
-        }
-      }
-    }
-
-    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
-    refPicListModification->setRefPicListModificationFlagL( li, isModified );  
-
-      if( isModified )
-      {
-        Int temporalRefIdx = 0;
-        for( Int i = 0; i < pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); i++ )
-        {
-          if( tempList[i] >= 0 ) 
-          {
-            refPicListModification->setRefPicSetIdxL( li, i, tempList[i] );
-          }
-          else
-          {
-            refPicListModification->setRefPicSetIdxL( li, i, temporalRefIdx );
-            temporalRefIdx++;
-          }
-        }
-      }
-  }
-}
-#endif
 #endif
 //! \}
Index: trunk/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 655)
@@ -57,4 +57,7 @@
 #include "TEncAnalyze.h"
 #include "TEncRateCtrl.h"
+#if KWU_RC_MADPRED_E0227
+#include "../App/TAppEncoder/TAppEncTop.h"
+#endif
 #include <vector>
 
@@ -99,10 +102,6 @@
 #if H_MV
   TComPicLists*           m_ivPicLists;
-#if H_MV5
   std::vector<TComPic*>   m_refPicSetInterLayer0; 
   std::vector<TComPic*>   m_refPicSetInterLayer1; 
-#else
-  std::vector<TComPic*>   m_refPicSetInterLayer; 
-#endif
 
   Int                     m_pocLastCoded;
@@ -148,7 +147,7 @@
 #if H_MV
   Void  initGOP     ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP);
-  Void  compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid );
+  Void  compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid, Bool isField, Bool isTff  );
 #else
-  Void  compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
+  Void  compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff  );
 #endif
   Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect);
@@ -169,5 +168,5 @@
 
 #if !H_MV
-  Void  printOutSummary      ( UInt uiNumAllPicCoded );
+  Void  printOutSummary      ( UInt uiNumAllPicCoded , bool isField);
 #endif
 #if H_3D_VSO
@@ -176,5 +175,9 @@
   Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits );
 #endif
-  
+
+#if KWU_RC_MADPRED_E0227
+  TEncTop* getEncTop() { return m_pcEncTop; }
+#endif
+
   TEncSlice*  getSliceEncoder()   { return m_pcSliceEncoder; }
   NalUnitType getNalUnitType( Int pocCurr, Int lastIdr );
@@ -184,8 +187,12 @@
 
 protected:
+  Void xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, bool isField );
+
   Void  xInitGOP          ( Int iPOC, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut );
-  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr );
+  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, bool isField );
   
   Void  xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime );
+  Void  xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime );
+
 #if H_3D_VSO
   Dist64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1);
@@ -216,9 +223,5 @@
   }
 #if H_MV
-#if H_MV5
    Void  xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid );
-#else
-   Void  xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid );
-#endif
 #endif
   Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
Index: trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 655)
@@ -537,4 +537,9 @@
   m_lastPicture  = NULL;
 #endif
+
+#if KWU_RC_MADPRED_E0227
+  m_lastIVPicture = NULL;
+#endif
+
   m_picActualHeaderBits = 0;
 #if !M0036_RC_IMPROVEMENT
@@ -544,4 +549,8 @@
   m_picQP               = 0;
   m_picLambda           = 0.0;
+
+#if KWU_RC_MADPRED_E0227
+  m_IVtotalMAD            = 0.0;
+#endif
 }
 
@@ -621,5 +630,22 @@
 }
 
+#if KWU_RC_MADPRED_E0227
+Void TEncRCPic::addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures )
+{
+  m_lastIVPicture = NULL;
+  m_lastIVPicture = this;
+}
+
+Void TEncRCPic::setIVPic( TEncRCPic* BaseRCPic )
+{
+  m_lastIVPicture = BaseRCPic;
+}
+#endif
+
+#if KWU_RC_MADPRED_E0227
+Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int layerID )
+#else
 Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures )
+#endif
 {
   destroy();
@@ -673,4 +699,10 @@
       Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight );
       m_LCUs[LCUIdx].m_numberOfPixel = currWidth * currHeight;
+
+#if KWU_RC_MADPRED_E0227
+      m_LCUs[LCUIdx].m_CUWidth = currWidth;
+      m_LCUs[LCUIdx].m_CUHeight = currHeight;
+      m_LCUs[LCUIdx].m_IVMAD = -1.0;
+#endif
     }
   }
@@ -683,7 +715,41 @@
   m_picLambda           = 0.0;
 
+
+#if KWU_RC_MADPRED_E0227
+  m_LayerID = layerID;
+  m_lastIVPicture = NULL;
+  m_IVtotalMAD            = 0.0;
+#endif
+
+
 #if !M0036_RC_IMPROVEMENT
   m_lastPicture = NULL;
   list<TEncRCPic*>::reverse_iterator it;
+  for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
+  {
+    if ( (*it)->getFrameLevel() == m_frameLevel )
+    {
+      m_lastPicture = (*it);
+      break;
+    }
+  }
+#endif
+
+#if KWU_RC_MADPRED_E0227
+  list<TEncRCPic*>::reverse_iterator it;
+  if( m_LayerID != 0)
+  {
+    m_lastIVPicture = NULL;
+    for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
+    {
+      if ( (*it)->getLayerID() == 0 )
+      {
+        m_lastIVPicture = (*it);
+        break;
+      }
+    }
+  }
+
+  m_lastPicture = NULL;
   for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
   {
@@ -856,4 +922,71 @@
 }
 
+
+#if KWU_RC_MADPRED_E0227
+Double TEncRCPic::estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int CurPOC )
+{
+  Double alpha         = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
+  Double beta          = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
+  Double bpp       = (Double)m_targetBits/(Double)m_numberOfPixel;
+  Double estLambda = alpha * pow( bpp, beta );
+  Double lastLevelLambda = -1.0;
+  Double lastPicLambda   = -1.0;
+  Double lastValidLambda = -1.0;
+  list<TEncRCPic*>::iterator it;
+
+  if(listPreviousPictures.size() == 0 || CurPOC%8 == 0)
+  {
+    lastLevelLambda = m_lastIVPicture->getPicActualLambda();
+    lastPicLambda     = m_lastIVPicture->getPicActualLambda();
+  }
+  else
+  {
+    for ( it = listPreviousPictures.begin(); it != listPreviousPictures.end(); it++ )
+    {
+      if ( (*it)->getFrameLevel() == m_frameLevel )
+      {
+        lastLevelLambda = (*it)->getPicActualLambda();
+      }
+      lastPicLambda     = (*it)->getPicActualLambda();
+
+      if ( lastPicLambda > 0.0 )
+      {
+        lastValidLambda = lastPicLambda;
+      }
+    }
+  }
+
+  if ( lastLevelLambda > 0.0 )
+  {
+    lastLevelLambda = Clip3( 0.1, 10000.0, lastLevelLambda );
+    estLambda = Clip3( lastLevelLambda * pow( 2.0, -3.0/3.0 ), lastLevelLambda * pow( 2.0, 3.0/3.0 ), estLambda );
+  }
+
+  if ( lastPicLambda > 0.0 )
+  {
+    lastPicLambda = Clip3( 0.1, 2000.0, lastPicLambda );
+    estLambda = Clip3( lastPicLambda * pow( 2.0, -10.0/3.0 ), lastPicLambda * pow( 2.0, 10.0/3.0 ), estLambda );
+  }
+  else if ( lastValidLambda > 0.0 )
+  {
+    lastValidLambda = Clip3( 0.1, 2000.0, lastValidLambda );
+    estLambda = Clip3( lastValidLambda * pow(2.0, -10.0/3.0), lastValidLambda * pow(2.0, 10.0/3.0), estLambda );
+  }
+  else
+  {
+    estLambda = Clip3( 0.1, 10000.0, estLambda );
+  }
+
+  if ( estLambda < 0.1 )
+  {
+    estLambda = 0.1;
+  }
+
+  m_estPicLambda = estLambda;
+  return estLambda;
+}
+#endif
+
+
 #if RATE_CONTROL_INTRA
 Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType)  
@@ -937,4 +1070,121 @@
 }
 
+
+#if KWU_RC_MADPRED_E0227
+Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity )
+{
+  Int   LCUIdx    = getLCUCoded();
+  Double bpp      = -1.0;
+  Int avgBits     = 0;
+#if !M0036_RC_IMPROVEMENT
+  Double totalMAD = -1.0;
+  Double MAD      = -1.0;
+#endif
+
+  Double totalMAD = -1.0;
+  Double MAD      = -1.0;
+
+  Double IVMAD      = -1.0;
+  Double SAD = 0.0;
+  Int     x, y;
+  Int Sum = 0;
+
+  {
+    Pel*  pOrg    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
+    Pel*  pRec    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
+    Pel*  pDep    = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
+    Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
+
+    Int   width  = m_LCUs[ LCUIdx ].m_CUWidth;
+    Int   height = m_LCUs[ LCUIdx ].m_CUHeight;
+
+    for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
+    {
+      for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)
+      {
+        Sum += pDep[x];
+      }
+      pDep += iStride;
+    }
+
+    Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
+
+    Double fL = focalLen * abs( basePos - curPos );
+    Double z  = abs( 1.0 / znear - 1.0 / zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / zfar);
+    *disparity = (Int)(direction*fL * z);
+    Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
+
+    Int disp = *disparity;
+    Int posX, posY;
+    pcCU->getPosInPic(0, posX, posY);
+    if((posX + *disparity) < 0 || (posX + *disparity + width) >= pcCU->getSlice()->getSPS()->getMaxCUWidth())
+    {
+      disp = 0;
+    }
+
+    for( y = 0; y < height; y++ )
+    {
+      for( x = 0; x < width; x++ )
+      {
+        SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)]
+                  - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)] )>>shift;
+      }
+      pOrg += iStride;
+      pRec += iStride;
+    }
+    IVMAD = SAD / (Double)(height * width);
+    IVMAD = IVMAD * IVMAD;
+
+    m_LCUs[ LCUIdx ].m_IVMAD = IVMAD;
+    if(m_lastPicture)
+    {
+      m_LCUs[ LCUIdx ].m_MAD = m_lastPicture->getLCU(LCUIdx).m_MAD;
+    }
+
+    MAD = m_LCUs[ LCUIdx ].m_IVMAD;
+
+    if(m_lastPicture)
+    {
+      totalMAD = m_lastPicture->getTotalMAD();      // get total MAD of temporal frame
+      for ( Int i=0; i<LCUIdx; i++ )
+      {
+        totalMAD -= m_lastPicture->getLCU(i).m_MAD;
+      }
+    }
+    else
+    {
+      totalMAD = m_lastIVPicture->getTotalMAD();      // get total MAD of inter-view frame
+      for ( Int i=0; i<LCUIdx; i++ )
+      {
+        totalMAD -= m_lastIVPicture->getLCU(i).m_MAD;
+      }
+    }
+
+
+    if ( totalMAD > 0.1 )
+    {
+      avgBits = Int( (m_bitsLeft * MAD) / totalMAD );
+    }
+    else
+    {
+      avgBits = Int( (m_bitsLeft) / m_LCULeft );
+    }
+  }
+
+  if ( avgBits < 5 )
+  {
+    avgBits = 5;
+  }
+
+  bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;
+  m_LCUs[ LCUIdx ].m_targetBits = avgBits;
+
+  return bpp;
+}
+#endif
+
+
+
+
 Double TEncRCPic::getLCUEstLambda( Double bpp )
 {
@@ -1185,5 +1435,8 @@
   }
   m_picLambda           = averageLambda;
-#if !M0036_RC_IMPROVEMENT
+#if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
+#if KWU_RC_MADPRED_E0227
+  m_totalMAD = 0;
+#endif
   for ( Int i=0; i<m_numberOfLCU; i++ )
   {
@@ -1393,5 +1646,9 @@
 
 #if M0036_RC_IMPROVEMENT
+#if KWU_RC_MADPRED_E0227
+Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP], Int layerID )
+#else
 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
+#endif
 #else
 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
@@ -1607,4 +1864,8 @@
   }
 
+#if KWU_RC_MADPRED_E0227
+  setLayerID(layerID);
+#endif
+
   delete[] bitsRatio;
   delete[] GOPID2Level;
@@ -1614,5 +1875,9 @@
 {
   m_encRCPic = new TEncRCPic;
+#if KWU_RC_MADPRED_E0227
+  m_encRCPic->create( m_encRCSeq, m_encRCGOP, frameLevel, m_listRCPictures, m_LayerID );
+#else
   m_encRCPic->create( m_encRCSeq, m_encRCGOP, frameLevel, m_listRCPictures );
+#endif
 }
 
@@ -1815,6 +2080,8 @@
   m_sourceHeightInLCU        = (sourceHeight / maxCUHeight) + (( sourceHeight %  maxCUHeight) ? 1 : 0);  
   m_isLowdelay               = (sizeIntraPeriod == -1) ? true : false;
+
   m_prevBitrate              = ( targetKbps << 10 );  // in units of 1,024 bps
   m_currBitrate              = ( targetKbps << 10 );
+
   m_frameRate                = frameRate;
   m_refFrameNum              = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);
@@ -2212,4 +2479,54 @@
 }
 
+
+#if KWU_RC_MADPRED_E0227
+Void  TEncRateCtrl::updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction)
+{
+  Int     x, y;
+  Double dMAD = 0.0;
+  Int Sum = 0;
+  Double SAD = 0.0;
+
+  Pel*  pOrg    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
+  Pel*  pRec    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
+  Pel*  pDep    = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
+  Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
+
+  Int   width  = m_pcLCUData[m_indexLCU].m_widthInPixel;
+  Int   height = m_pcLCUData[m_indexLCU].m_heightInPixel;
+
+  for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
+  {
+    for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)
+    {
+      Sum += pDep[x];
+    }
+    pDep += iStride;
+  }
+
+  Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
+  Double fL = focalLen * abs( basePos - curPos );
+  Double z  = abs( 1.0 / znear - 1.0 / zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / zfar);
+  Int   disparity = (Int)(direction*fL * z);
+  Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
+  Int disp = disparity;
+
+  for( y = 0; y < height; y++ )
+  {
+    for( x = 0; x < width; x++ )
+    {
+      SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)]
+      - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)] )>>shift;
+    }
+    pOrg += iStride;
+    pRec += iStride;
+  }
+  m_pcLCUData[m_indexLCU].m_qp   = qp;
+  m_pcLCUData[m_indexLCU].m_costMAD  = (SAD /(Double)(width*height));
+  m_pcLCUData[m_indexLCU].m_bits = (Int)uiBits;
+}
+#endif
+
+
 Double TEncRateCtrl::xAdjustmentBits(Int& reductionBits, Int& compensationBits)
 {
Index: trunk/source/Lib/TLibEncoder/TEncRateCtrl.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncRateCtrl.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncRateCtrl.h	(revision 655)
@@ -98,4 +98,12 @@
   Int m_targetBitsLeft;
 #endif
+
+#if KWU_RC_MADPRED_E0227
+  Double m_MAD;
+
+  Int m_CUWidth;
+  Int m_CUHeight;
+  Double m_IVMAD;
+#endif
 };
 
@@ -248,7 +256,14 @@
 
 public:
+#if KWU_RC_MADPRED_E0227
+  Void create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int layerID );
+#else
   Void create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures );
+#endif
   Void destroy();
 
+#if KWU_RC_MADPRED_E0227
+  Double estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int curPOC );
+#endif
 #if !RATE_CONTROL_INTRA
   Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );
@@ -267,4 +282,9 @@
   Double getLCUTargetBpp();
 #endif
+
+#if KWU_RC_MADPRED_E0227
+  Double getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity );
+#endif
+
   Double getLCUEstLambda( Double bpp );
   Int    getLCUEstQP( Double lambda, Int clipPicQP );
@@ -282,4 +302,10 @@
 
   Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures );
+
+#if KWU_RC_MADPRED_E0227
+  Void addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures );
+  Void setIVPic( TEncRCPic* baseRCPic );
+#endif
+
 #if !M0036_RC_IMPROVEMENT
   Double getEffectivePercentage();
@@ -322,4 +348,12 @@
 #endif
 
+#if KWU_RC_MADPRED_E0227
+  Double getTotalMAD()                                    { return m_totalMAD; }
+  Void   setTotalMAD( Double MAD )                        { m_totalMAD = MAD; }
+
+  Double getIVTotalMAD()                                    { return m_IVtotalMAD; }
+  Void   setIVTotalMAD( Double MAD )                        { m_IVtotalMAD = MAD; }
+#endif
+
   Int  getPicActualBits()                                 { return m_picActualBits; }
   Int  getPicActualQP()                                   { return m_picQP; }
@@ -330,4 +364,9 @@
   Void setPicEstLambda( Double lambda )                   { m_picLambda = lambda; }
 
+#if KWU_RC_MADPRED_E0227
+  Int getLayerID()                                         { return m_LayerID; }
+  Void setLayerID(Int layerid)                              { m_LayerID = layerid; }
+#endif
+
 private:
   TEncRCSeq* m_encRCSeq;
@@ -361,4 +400,12 @@
   TEncRCPic* m_lastPicture;
 #endif
+
+#if KWU_RC_MADPRED_E0227
+  Double m_totalMAD;
+  TEncRCPic* m_lastPicture;
+  Int m_LayerID;
+  TEncRCPic* m_lastIVPicture;
+  Double m_IVtotalMAD;
+#endif
 };
 
@@ -371,5 +418,9 @@
 public:
 #if M0036_RC_IMPROVEMENT
+#if KWU_RC_MADPRED_E0227
+  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP], Int layerID );
+#else
   Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
+#endif
 #else
   Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
@@ -388,4 +439,9 @@
   list<TEncRCPic*>& getPicList() { return m_listRCPictures; }
 
+#if KWU_RC_MADPRED_E0227
+  Int getLayerID()                { return m_LayerID; }
+  Void setLayerID(Int layerid)     { m_LayerID = layerid; }
+#endif
+
 private:
   TEncRCSeq* m_encRCSeq;
@@ -394,4 +450,8 @@
   list<TEncRCPic*> m_listRCPictures;
   Int        m_RCQP;
+
+#if KWU_RC_MADPRED_E0227
+  Int m_LayerID;
+#endif
 };
 
@@ -518,4 +578,7 @@
   Void          updataRCUnitStatus    ();
   Void          updateLCUData         (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp);
+#if KWU_RC_MADPRED_E0227
+  Void          updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction);
+#endif
   Void          updateFrameData       (UInt64 actualFrameBits);
   Double        xAdjustmentBits       (Int& reductionBits, Int& compensationBits);
Index: trunk/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 655)
@@ -95,7 +95,4 @@
 #if H_3D_DIM_DMM
 , m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
-#if !SEC_DMM2_E0146_HHIFIX
-, m_cDmm2DataSCModel          ( 1,             1,               NUM_DMM2_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
-#endif
 , m_cDmm3DataSCModel          ( 1,             1,               NUM_DMM3_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
 #endif
@@ -108,5 +105,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 , m_cInterSDCFlagSCModel             ( 1,             1,  NUM_INTER_SDC_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
 , m_cInterSDCResidualSCModel         ( 1,             1,  NUM_INTER_SDC_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
@@ -177,7 +174,4 @@
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
-#if !SEC_DMM2_E0146_HHIFIX
-  m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
-#endif
   m_cDmm3DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA );
 #endif
@@ -190,5 +184,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   m_cInterSDCFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_FLAG );
   m_cInterSDCResidualSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_RESIDUAL );
@@ -232,5 +226,5 @@
       curCost += m_cCUICFlagSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_IC_FLAG );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
       curCost += m_cInterSDCFlagSCModel.calcCost      ( curSliceType, qp, (UChar*)INIT_INTER_SDC_FLAG );
       curCost += m_cInterSDCResidualSCModel.calcCost  ( curSliceType, qp, (UChar*)INIT_INTER_SDC_RESIDUAL );
@@ -268,7 +262,4 @@
 #if H_3D_DIM_DMM
       curCost += m_cDmm1DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM1_DATA );
-#if !SEC_DMM2_E0146_HHIFIX
-      curCost += m_cDmm2DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM2_DATA );
-#endif
       curCost += m_cDmm3DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM3_DATA );
 #endif
@@ -340,7 +331,4 @@
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
-#if !SEC_DMM2_E0146_HHIFIX
-  m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
-#endif
   m_cDmm3DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA );
 #endif
@@ -353,5 +341,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   m_cInterSDCFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_FLAG );
   m_cInterSDCResidualSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_RESIDUAL );
@@ -548,23 +536,4 @@
   }
 }
-
-#if !SEC_DMM2_E0146_HHIFIX
-Void TEncSbac::xCodeDmm2Offset( Int iOffset )
-{
-  if( DMM2_DELTAEND_MAX > 0 )
-  {
-    m_pcBinIf->encodeBin( (iOffset != 0) , m_cDmm2DataSCModel.get(0, 0, 0) );
-    if( iOffset != 0 )
-    {
-      UInt uiAbsValMinus1 = abs(iOffset)-1;
-      m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01),      m_cDmm2DataSCModel.get(0, 0, 0) );
-      m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmm2DataSCModel.get(0, 0, 0) );
-
-      UInt uiSign = (iOffset > 0) ? 0 : 1;
-      m_pcBinIf->encodeBinEP( uiSign );
-    }
-  }
-}
-#endif
 
 Void TEncSbac::xCodeDmm3WedgeIdx( UInt uiIntraIdx, Int iNumBit )
@@ -1240,10 +1209,4 @@
       xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
     } break;
-#if !SEC_DMM2_E0146_HHIFIX
-  case( DMM2_IDX ):
-    {
-      xCodeDmm2Offset( pcCU->getDmm2DeltaEnd( absPartIdx ) );
-    } break;
-#endif
   case( DMM3_IDX ):
     {
@@ -1294,26 +1257,6 @@
 Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx )
 {
-#if ZJU_DEPTH_INTRA_MODE_E0204
     UInt codeWordTable[3][7] =    {{0, 0, 0, 2, 0,6, 7},{0, 0, 2, 7, 3, 6, 2},{0, 1, 0, 0, 0, 0, 0}};
     UInt codeWordLenTable[3][7] = {{0, 1, 0, 2, 0,3, 3},{1, 1, 2, 3, 2, 3, 2},{1, 1, 0, 0, 0, 0, 0}};
-#else
-#if LGE_SDC_REMOVE_DC_E0158
-#if SEC_DMM2_E0146_HHIFIX
-  UInt codeWordTable[3][7] =    {{0, 0, 0, 2, 0,6, 7},{0, 2, 3, 4, 5, 6, 7},{0, 1, 0, 0, 0, 0, 0}};
-  UInt codeWordLenTable[3][7] = {{0, 1, 0, 2, 0,3, 3},{2, 3, 3, 3, 3, 3, 3},{1, 1, 0, 0, 0, 0, 0}};
-#else
-  UInt codeWordTable[3][8] =    { { 0, 0, 0, 2, 0, 6, 0, 7 }, { 0, 2, 3, 4, 5, 6, 15, 14 }, { 0, 1, 0, 0, 0, 0, 0, 0 } };
-  UInt codeWordLenTable[3][8] = { { 0, 1, 0, 2, 0, 3, 0, 3 }, { 2, 3, 3, 3, 3, 3,  4,  4 }, { 1, 1, 0, 0, 0, 0, 0, 0 } };
-#endif
-#else
-#if SEC_DMM2_E0146_HHIFIX
-  UInt codeWordTable[3][8] =    {{0, 0, 0, 2, 0,6, 0, 7},{0, 2, 3, 4, 5, 6, 14, 15},{0, 2, 0, 0, 0, 0, 3, 0}};
-  UInt codeWordLenTable[3][8] = {{0, 1, 0, 2, 0,3, 0, 3},{2, 3, 3, 3, 3, 3,  4,  4},{1, 2, 0, 0, 0, 0, 2, 0}};
-#else
-  UInt codeWordTable[3][9] =    {{0, 0, 0, 2, 0,6, 0, 0, 7},{0, 2, 3, 4, 5, 6, 14, 31, 30},{0, 2, 0, 0, 0, 0, 3, 0, 0}};
-  UInt codeWordLenTable[3][9] = {{0, 1, 0, 2, 0,3, 0, 0, 3},{2, 3, 3, 3, 3, 3,  4,  5,  5},{1, 2, 0, 0, 0, 0, 2, 0, 0}};
-#endif
-#endif
-#endif
   UInt dir = pcCU->getLumaIntraDir( absPartIdx );
   UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 );
@@ -1331,19 +1274,5 @@
     case DMM4_IDX: codeIdx = 4; break;
     case DMM3_IDX: codeIdx = 5; break;
-#if LGE_SDC_REMOVE_DC_E0158
-#if SEC_DMM2_E0146_HHIFIX
     case  RBC_IDX: codeIdx = 6; break;
-#else
-    case DMM2_IDX: codeIdx = 6; break;
-    case  RBC_IDX: codeIdx = 7; break;
-#endif
-#else
-#if SEC_DMM2_E0146_HHIFIX
-    case  RBC_IDX: codeIdx = 7; break;
-#else
-    case DMM2_IDX: codeIdx = 7; break;
-    case  RBC_IDX: codeIdx = 8; break;
-#endif
-#endif
     default:                    break;
     }
@@ -1356,12 +1285,8 @@
     {
       case PLANAR_IDX:  codeIdx = 0; break;
-#if !LGE_SDC_REMOVE_DC_E0158
-      case DC_IDX:      codeIdx = 6; break;
-#endif
       default:          codeIdx = 2; break;
     }
   }
 #endif
-#if ZJU_DEPTH_INTRA_MODE_E0204
   if( puIdx==1 )
   {
@@ -1375,5 +1300,4 @@
       }
   }
-#endif
   //mode coding
   for( UInt i = 0; i < codeWordLenTable[puIdx][codeIdx]; i++ )
@@ -2304,5 +2228,5 @@
 }
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 Void TEncSbac::codeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
 {
Index: trunk/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 655)
@@ -121,7 +121,4 @@
 #if H_3D_DIM_DMM
   Void  xCodeDmm1WedgeIdx    ( UInt uiTabIdx, Int iNumBit );
-#if !SEC_DMM2_E0146_HHIFIX
-  Void  xCodeDmm2Offset      ( Int iOffset );
-#endif
   Void  xCodeDmm3WedgeIdx    ( UInt uiIntraIdx, Int iNumBit );
 #endif
@@ -160,5 +157,5 @@
   Void codeICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Void codeInterSDCFlag  ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeInterSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment );
@@ -256,7 +253,4 @@
 #if H_3D_DIM_DMM
   ContextModel3DBuffer m_cDmm1DataSCModel;
-#if !SEC_DMM2_E0146_HHIFIX
-  ContextModel3DBuffer m_cDmm2DataSCModel;
-#endif
   ContextModel3DBuffer m_cDmm3DataSCModel;
 #endif
@@ -269,5 +263,5 @@
 #endif
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   ContextModel3DBuffer m_cInterSDCFlagSCModel;
   ContextModel3DBuffer m_cInterSDCResidualSCModel;
Index: trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 655)
@@ -41,5 +41,5 @@
 #include "TEncSearch.h"
 #include <math.h>
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 #include <memory.h>
 #endif
@@ -323,5 +323,5 @@
   m_cDistParam.bUseIC = pcPatternKey->getICFlag();
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   m_cDistParam.bUseSDCMRSAD = pcPatternKey->getSDCMRSADFlag();
 #endif
@@ -755,5 +755,5 @@
     m_cDistParam.bUseIC = pcPatternKey->getICFlag();
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
     m_cDistParam.bUseSDCMRSAD = pcPatternKey->getSDCMRSADFlag();
 #endif
@@ -1900,17 +1900,9 @@
   // get DC prediction for each segment
   Pel apDCPredValues[2];
-#if KWU_SDC_SIMPLE_DC_E0117
   analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode );
-#else
-  analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride );
-#endif
   
   // get original DC for each segment
   Pel apDCOrigValues[2];
-#if KWU_SDC_SIMPLE_DC_E0117
   analyzeSegmentsSDC(piOrg, uiStride, uiWidth, apDCOrigValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode, true );
-#else
-  analyzeSegmentsSDC(piOrg, uiStride, uiWidth, apDCOrigValues, uiNumSegments, pbMask, uiMaskStride );
-#endif
   
   for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
@@ -2851,5 +2843,5 @@
     {
 
-#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
+#if H_3D_FAST_DEPTH_INTRA
       Int  threshold    = max(((pcCU->getQP(0))>>3)-1,3);
       Int  varThreshold = (Int)( threshold * threshold - 8 );
@@ -2859,5 +2851,5 @@
 #if H_3D_DIM_DMM
       if( m_pcEncCfg->getUseDMM()
-#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
+#if H_3D_FAST_DEPTH_INTRA
          && (uiRdModeList[0] != PLANAR_IDX || varCU >= varThreshold)
 #endif
@@ -2866,4 +2858,11 @@
         for( UInt dmmType = 0; dmmType < DMM_NUM_TYPE; dmmType++ )
         {
+#if H_3D_FCO
+            TComPic* picTexture  = pcCU->getSlice()->getIvPic(false, pcCU->getSlice()->getViewIndex() );
+            if ( !picTexture->getReconMark() && (DMM3_IDX == dmmType || DMM4_IDX == dmmType ) )
+            {
+                continue;
+            }
+#endif
           UInt uiTabIdx = 0;
           TComWedgelet* biSegmentation = NULL;
@@ -2877,20 +2876,7 @@
               biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
             } break;
-#if !SEC_DMM2_E0146_HHIFIX
-          case( DMM2_IDX ):
-            {
-              if( uiWidth > 4 )
-              {
-                Int dmm2DeltaEnd = 0;
-                xSearchDmm2Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, dmm2DeltaEnd );
-                pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth );
-                pcCU->setDmm2DeltaEndSubParts( dmm2DeltaEnd, uiPartOffset, uiDepth + uiInitTrDepth );
-                biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
-              }
-            } break;
-#endif
           case( DMM3_IDX ):
             {
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+
               TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
               TComDataCU* pcColTexCU = pcPicTex->getCU( pcCU->getAddr() );
@@ -2900,17 +2886,10 @@
               if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 )
               {
-#endif
-              UInt uiIntraTabIdx = 0;
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+             UInt uiIntraTabIdx = 0;
               xSearchDmm3Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, uiIntraTabIdx, uiColTexIntraDir );
-#else
-              xSearchDmm3Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, uiIntraTabIdx );
-#endif
               pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth );
               pcCU->setDmm3IntraTabIdxSubParts( uiIntraTabIdx, uiPartOffset, uiDepth + uiInitTrDepth );
               biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
               }
-#endif
             } break;
           case( DMM4_IDX ):
@@ -2941,5 +2920,5 @@
 #if H_3D_DIM_RBC
       if( m_pcEncCfg->getUseRBC()
-#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
+#if H_3D_FAST_DEPTH_INTRA
           && (uiRdModeList[0] != PLANAR_IDX || varCU >= varThreshold)
 #endif
@@ -3581,5 +3560,5 @@
   cDistParam.bUseIC = false;
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   cDistParam.bUseSDCMRSAD = false;
 #endif
@@ -3724,5 +3703,5 @@
  */
 #if AMP_MRG
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
 Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bFMD, Bool bUseRes, Bool bUseMRG )
 #else
@@ -3836,5 +3815,5 @@
 #if AMP_MRG
     Bool bTestNormalMC = true;
-#if  MTK_FAST_TEXTURE_ENCODING_E0173
+#if  H_3D_FAST_TEXTURE_ENCODING
     if (bFMD||( bUseMRG && pcCU->getWidth( 0 ) > 8 && iNumPart == 2 ))
 #else            
@@ -4706,5 +4685,5 @@
   pcPatternKey->setICFlag( bICFlag );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   if ( pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
   {
@@ -4862,5 +4841,5 @@
       m_cDistParam.bUseIC = pcPatternKey->getICFlag();
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
       m_cDistParam.bUseSDCMRSAD = pcPatternKey->getSDCMRSADFlag();
 #endif
@@ -5471,5 +5450,5 @@
 }
 
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
 Void TEncSearch::encodeResAndCalcRdInterSDCCU( TComDataCU* pcCU, TComYuv* pcOrg, TComYuv* pcPred, TComYuv* pcResi, TComYuv* pcRec, const UInt uiDepth )
 {
@@ -6794,5 +6773,5 @@
     m_pcEntropyCoder->encodeARPW( pcCU , 0 );
 #endif
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
     m_pcEntropyCoder->encodeInterSDCFlag( pcCU, 0, true );
 #endif
@@ -7045,8 +7024,8 @@
 }
 
+#if H_3D_DIM
   // -------------------------------------------------------------------------------------------------------------------
   // Depth intra search
   // -------------------------------------------------------------------------------------------------------------------
-#if H_3D_DIM
 Void TEncSearch::xCalcBiSegDCs( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2 )
 {
@@ -7321,73 +7300,4 @@
 }
 
-#if !SEC_DMM2_E0146_HHIFIX
-Void TEncSearch::xSearchDmm2Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, Int& riWedgeDeltaEnd )
-{
-  ruiTabIdx       = 0;
-  riWedgeDeltaEnd = 0;
-
-  // local pred buffer
-  TComYuv cPredYuv;
-  cPredYuv.create( uiWidth, uiHeight );
-  cPredYuv.clear();
-
-  UInt uiPredStride = cPredYuv.getStride();
-  Pel* piPred       = cPredYuv.getLumaAddr();
-
-
-  // regular wedge search
-  Dist uiBestDist    = RDO_DIST_MAX;
-  UInt uiBestTabIdx  = 0;
-  Int  iBestDeltaEnd = 0;
-
-  UInt uiIdx = 0;
-  Pel refDC1 = 0; Pel refDC2 = 0;
-  for( Int iTestDeltaEnd = -DMM2_DELTAEND_MAX; iTestDeltaEnd <= DMM2_DELTAEND_MAX; iTestDeltaEnd++ )
-  {
-    uiIdx = xPredWedgeFromIntra( pcCU, uiAbsPtIdx, uiWidth, uiHeight, iTestDeltaEnd );
-    TComWedgelet* pcWedgelet = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiIdx]);
-    xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
-    xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
-
-    Dist uiActDist = RDO_DIST_MAX;
-#if H_3D_VSO
-    if( m_pcRdCost->getUseVSO() )
-    {
-      if( m_pcRdCost->getUseEstimatedVSD() )
-      {
-        uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
-      }
-      else
-      {
-        uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
-      }
-    }
-    else
-#endif
-    {
-      uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
-    }
-
-    if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX )
-    {
-      uiBestDist    = uiActDist;
-      uiBestTabIdx  = uiIdx;
-      iBestDeltaEnd = iTestDeltaEnd;
-    }
-    else if( uiIdx == uiBestTabIdx && abs(iTestDeltaEnd) < abs(iBestDeltaEnd) )
-    {
-      iBestDeltaEnd = iTestDeltaEnd;
-    }
-  }
-
-  ruiTabIdx       = uiBestTabIdx;
-  riWedgeDeltaEnd = iBestDeltaEnd;
-
-  cPredYuv.destroy();
-  return;
-}
-#endif
-
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
 Void TEncSearch::xSearchDmm3Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx, UInt colTexIntraDir )
 {
@@ -7426,73 +7336,5 @@
   cPredYuv.destroy();
 }
-#else
-Void TEncSearch::xSearchDmm3Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx )
-{
-  ruiTabIdx       = 0;
-  ruiIntraTabIdx  = 0;
-
-  // local pred buffer
-  TComYuv cPredYuv; 
-  cPredYuv.create( uiWidth, uiHeight ); 
-  cPredYuv.clear();
-  Pel* piPred = cPredYuv.getLumaAddr();
-  UInt uiPredStride = cPredYuv.getStride();
-
-  // wedge search
-  UInt uiBestDist = MAX_UINT;
-  WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
-  Pel refDC1 = 0; Pel refDC2 = 0;
-
-  TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
-  assert( pcPicTex != NULL );
-  TComDataCU* pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
-  UInt      uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPtIdx;
-  Int   uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
-
-  std::vector< std::vector<UInt> > pauiWdgLstSz = g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]];
-  if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 )
-  {
-    std::vector<UInt>* pauiWdgLst = &pauiWdgLstSz[uiColTexIntraDir-2];
-    for( UInt uiIdxW = 0; uiIdxW < pauiWdgLst->size(); uiIdxW++ )
-    {
-      UInt uiIdx     =   pauiWdgLst->at(uiIdxW);
-      TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiIdx));
-      xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
-      xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
-
-      UInt uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
-      if( uiActDist < uiBestDist || uiBestDist == MAX_UINT )
-      {
-        uiBestDist     = uiActDist;
-        ruiTabIdx      = uiIdx;
-        ruiIntraTabIdx = uiIdxW;
-      }
-    }
-  }
-  else
-  {
-    WedgeNodeList* pacWedgeNodeList = &g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])];
-    UInt uiBestNodeDist = MAX_UINT;
-    UInt uiBestNodeId   = 0;
-    for( UInt uiNodeId = 0; uiNodeId < pacWedgeNodeList->size(); uiNodeId++ )
-    {
-      TComWedgelet* pcWedgelet = &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx()));
-      xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
-      xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
-
-      UInt uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
-      if( uiActDist < uiBestNodeDist || uiBestNodeDist == MAX_UINT )
-      {
-        uiBestNodeDist = uiActDist;
-        uiBestNodeId   = uiNodeId;
-        ruiIntraTabIdx = uiNodeId;
-      }
-    }
-    ruiTabIdx = pacWedgeNodeList->at(uiBestNodeId).getPatternIdx();
-  }
-
-  cPredYuv.destroy();
-}
-#endif
+
 #endif
 #if H_3D_DIM_RBC
Index: trunk/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 655)
@@ -196,5 +196,5 @@
                                   TComYuv*&   rpcResiYuv,
                                   TComYuv*&   rpcRecoYuv,
-#if MTK_FAST_TEXTURE_ENCODING_E0173
+#if H_3D_FAST_TEXTURE_ENCODING
                                   Bool        bFMD,
 #endif
@@ -213,5 +213,5 @@
                                   TComYuv*&   rpcYuvRec,
                                   Bool        bSkipRes );
-#if LGE_INTER_SDC_E0156
+#if H_3D_INTER_SDC
   Void encodeResAndCalcRdInterSDCCU( TComDataCU* pcCU,
     TComYuv* pcOrg, 
@@ -343,21 +343,13 @@
                                     UInt         stateU0V1Both2 );
 
-
+#if H_3D_DIM
   // -------------------------------------------------------------------------------------------------------------------
   // Depth intra search
   // -------------------------------------------------------------------------------------------------------------------
-#if H_3D_DIM
   Void xCalcBiSegDCs              ( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2 );
 #if H_3D_DIM_DMM
   Void xSearchDmmDeltaDCs         ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 );
   Void xSearchDmm1Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx );
-#if !SEC_DMM2_E0146_HHIFIX
-  Void xSearchDmm2Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, Int& riWedgeDeltaEnd );
-#endif
-#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
   Void xSearchDmm3Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx, UInt colTexIntraDir );
-#else
-  Void xSearchDmm3Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx );
-#endif
 #endif
 #if H_3D_DIM_RBC
Index: trunk/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 655)
@@ -157,5 +157,16 @@
   m_pdRdPicQp         = (Double*)xMalloc( Double, m_pcCfg->getDeltaQpRD() * 2 + 1 );
   m_piRdPicQp         = (Int*   )xMalloc( Int,    m_pcCfg->getDeltaQpRD() * 2 + 1 );
+#if KWU_RC_MADPRED_E0227
+  if(m_pcCfg->getUseRateCtrl())
+  {
+    m_pcRateCtrl        = pcEncTop->getRateCtrl();
+  }
+  else
+  {
+    m_pcRateCtrl        = NULL;
+  }
+#else
   m_pcRateCtrl        = pcEncTop->getRateCtrl();
+#endif
 }
 
@@ -176,16 +187,8 @@
  \param pPPS          PPS associated with the slice
  */
-#if H_MV5
 #if H_MV
-Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId )
-#else
-Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
-#endif
-#else
-#if H_3D
-Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId )
-#else
-Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
-#endif
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId, bool isField )
+#else
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, bool isField )
 #endif
 {
@@ -195,5 +198,5 @@
   rpcSlice = pcPic->getSlice(0);
 
-#if H_MV5
+#if H_MV
   rpcSlice->setVPS( pVPS ); 
 
@@ -203,15 +206,4 @@
 #if H_3D
   rpcSlice->setIsDepth     ( pVPS->getDepthId     ( layerId ) != 0 );    
-#endif
-#else
-#if H_3D
-  // GT: Should also be activated for MV-HEVC at some stage
-  rpcSlice->setVPS( pVPS );
-  Int vpsLayerId = pVPS->getLayerIdInNuh( layerId ); 
-
-  rpcSlice->setLayerId     ( layerId );
-  rpcSlice->setViewId      ( pVPS->getViewId      ( vpsLayerId ) );    
-  rpcSlice->setViewIndex   ( pVPS->getViewIndex   ( vpsLayerId ) );
-  rpcSlice->setIsDepth     ( pVPS->getDepthId     ( vpsLayerId ) != 0 );    
 #endif
 #endif
@@ -342,5 +334,5 @@
     Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
     Int    SHIFT_QP = 12;
-    Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
+    Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)(isField ? NumberBFrames/2 : NumberBFrames) );
 #if FULL_NBIT
     Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
@@ -1125,4 +1117,19 @@
     if(m_pcCfg->getUseRateCtrl())
     {
+#if KWU_RC_MADPRED_E0227
+      if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
+      {
+        Double zn, zf, focallength, position, camshift;
+        Double basepos;
+        Bool bInterpolated;
+        Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
+
+        pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);
+        pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basepos, camshift, bInterpolated);
+        pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camshift, bInterpolated);
+
+        m_pcRateCtrl->updateLCUDataEnhancedView(pcCU, pcCU->getTotalBits(), pcCU->getQP(0), basepos, position, focallength, zn, zf, (direction > 0 ? 1 : -1));
+      }
+#endif
       if(m_pcRateCtrl->calculateUnitQP())
       {
@@ -1223,4 +1230,22 @@
         else
         {
+#if KWU_RC_MADPRED_E0227
+          if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
+          {
+            Double zn, zf, focallength, position, camShift;
+            Double basePos;
+            Bool bInterpolated;
+            Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
+            Int disparity;
+
+            pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);
+            pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basePos, camShift, bInterpolated);
+            pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camShift, bInterpolated);
+            bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBppforInterView( m_pcRateCtrl->getPicList(), pcCU,
+              basePos, position, focallength, zn, zf, (direction > 0 ? 1 : -1), &disparity );
+          }
+          else
+          {
+#endif
 #if RATE_CONTROL_INTRA
           bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
@@ -1239,5 +1264,11 @@
           estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
 #endif
-
+#if KWU_RC_MADPRED_E0227
+          }
+#endif
+#if KWU_RC_MADPRED_E0227
+          estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
+          estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
+#endif
           estQP     = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, estQP );
 
@@ -1343,5 +1374,5 @@
       if ( m_pcCfg->getUseRateCtrl() )
       {
-#if !M0036_RC_IMPROVEMENT
+#if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
Index: trunk/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSlice.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncSlice.h	(revision 655)
@@ -116,20 +116,10 @@
   
   /// preparation of slice encoding (reference marking, QP and lambda)
-#if H_MV5
 #if H_MV
   Void    initEncSlice        ( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, 
-                                Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId ); 
+                                Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId, bool isField  ); 
 #else
   Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
-                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
-#endif
-#else
-#if H_3D
-  Void    initEncSlice        ( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, 
-                                Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId ); 
-#else
-  Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
-                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
-#endif
+                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, bool isField  );
 #endif
 #if RATE_CONTROL_LAMBDA_DOMAIN
Index: trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 655)
@@ -123,9 +123,17 @@
   if ( m_RCEnableRateControl )
   {
+#if KWU_RC_MADPRED_E0227
+    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
+      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList, getLayerId() );
+#else
     m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
                       g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
+#endif
   }
 #else
-  m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
+#if KWU_FIX_URQ
+  if(m_enableRateCtrl)
+#endif
+    m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
 #endif
   // if SBAC-based RD optimization is used
@@ -284,5 +292,9 @@
 }
 
-Void TEncTop::init()
+#if KWU_RC_MADPRED_E0227
+Void TEncTop::init(TAppEncTop* pcTAppEncTop, Bool isFieldCoding)
+#else
+Void TEncTop::init(Bool isFieldCoding)
+#endif
 {
   // initialize SPS
@@ -301,5 +313,5 @@
   m_cPPS.setSPS(&m_cSPS);
   xInitPPS();
-  xInitRPS();
+  xInitRPS(isFieldCoding);
 
   xInitPPSforTiles();
@@ -310,4 +322,7 @@
   m_cCuEncoder.   init( this );
   
+#if KWU_RC_MADPRED_E0227
+  m_pcTAppEncTop = pcTAppEncTop;
+#endif
   // initialize transform & quantization class
   m_pcCavlcCoder = getCavlcCoder();
@@ -392,9 +407,5 @@
   if( picLastCoded )
   {
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
     picLastCoded->compressMotion(1); 
-#else
-    picLastCoded->compressMotion(); 
-#endif
   }
 #endif
@@ -433,5 +444,5 @@
 #if H_MV
   }
-  m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, gopId );
+  m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, gopId, false, false );
 
   if( gopId + 1 == m_cGOPEncoder.getGOPSize() )
@@ -439,5 +450,5 @@
 #else
   // compress GOP
-  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
+  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
 #endif
 
@@ -456,4 +467,160 @@
 #endif
 }
+/**------------------------------------------------
+ Separate interlaced frame into two fields
+ -------------------------------------------------**/
+void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, bool isTop)
+{
+  if (!isTop)
+  {
+    org += stride;
+  }
+  for (Int y = 0; y < height>>1; y++)
+  {
+    for (Int x = 0; x < width; x++)
+    {
+      dstField[x] = org[x];
+    }
+    
+    dstField += stride;
+    org += stride*2;
+  }
+  
+}
+
+#if H_MV
+Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff, Int gopId )
+{
+  assert( 0 ); // Field coding and multiview need to be furhter harmonized. 
+}
+#else
+Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff)
+{
+  /* -- TOP FIELD -- */
+  
+  if (pcPicYuvOrg)
+  {
+    
+    /* -- Top field initialization -- */
+    
+    TComPic *pcTopField;
+    xGetNewPicBuffer( pcTopField );
+    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
+    pcTopField->setReconMark (false);
+    
+    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
+    pcTopField->getPicYuvRec()->setBorderExtension(false);
+    pcTopField->setTopField(isTff);
+    
+    int nHeight = pcPicYuvOrg->getHeight();
+    int nWidth = pcPicYuvOrg->getWidth();
+    int nStride = pcPicYuvOrg->getStride();
+    int nPadLuma = pcPicYuvOrg->getLumaMargin();
+    int nPadChroma = pcPicYuvOrg->getChromaMargin();
+    
+    // Get pointers
+    Pel * PicBufY = pcPicYuvOrg->getBufY();
+    Pel * PicBufU = pcPicYuvOrg->getBufU();
+    Pel * PicBufV = pcPicYuvOrg->getBufV();
+    
+    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
+    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
+    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
+    
+    // compute image characteristics
+    if ( getUseAdaptiveQP() )
+    {
+      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
+    }
+    
+    /* -- Defield -- */
+    
+    bool isTop = isTff;
+    
+    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
+    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    
+  }
+  
+  if (m_iPOCLast == 0) // compress field 0
+  {
+    m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
+  }
+  
+  /* -- BOTTOM FIELD -- */
+  
+  if (pcPicYuvOrg)
+  {
+    
+    /* -- Bottom field initialization -- */
+    
+    TComPic* pcBottomField;
+    xGetNewPicBuffer( pcBottomField );
+    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
+    pcBottomField->setReconMark (false);
+    
+    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
+    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
+    {
+      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
+    }
+    else
+    {
+      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+    }
+    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
+    
+    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
+    pcBottomField->getPicYuvRec()->setBorderExtension(false);
+    pcBottomField->setTopField(!isTff);
+    
+    int nHeight = pcPicYuvOrg->getHeight();
+    int nWidth = pcPicYuvOrg->getWidth();
+    int nStride = pcPicYuvOrg->getStride();
+    int nPadLuma = pcPicYuvOrg->getLumaMargin();
+    int nPadChroma = pcPicYuvOrg->getChromaMargin();
+    
+    // Get pointers
+    Pel * PicBufY = pcPicYuvOrg->getBufY();
+    Pel * PicBufU = pcPicYuvOrg->getBufU();
+    Pel * PicBufV = pcPicYuvOrg->getBufV();
+    
+    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
+    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
+    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
+    
+    // Compute image characteristics
+    if ( getUseAdaptiveQP() )
+    {
+      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
+    }
+    
+    /* -- Defield -- */
+    
+    bool isTop = !isTff;
+    
+    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
+    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    
+  }
+  
+  if ( ( !(m_iNumPicRcvd) || (!flush && m_iPOCLast != 1 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) )
+  {
+    iNumEncoded = 0;
+    return;
+  }
+  
+  // compress GOP
+  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
+  
+  iNumEncoded = m_iNumPicRcvd;
+  m_iNumPicRcvd = 0;
+  m_uiNumAllPicCoded += iNumEncoded;
+}
+#endif
+
+
 
 // ====================================================================================================================
@@ -551,10 +718,8 @@
    * that chooses the actual compatibility based upon options */
 
-#if H_MV5
 #if H_MV  
   m_cSPS.setUpdateRepFormatFlag           ( m_layerId == 0 );    
   m_cSPS.setSpsInferScalingListFlag       ( m_layerId > 0 && m_cVPS->getInDirectDependencyFlag( getLayerIdInVps(), 0 ) ); 
   m_cSPS.setSpsScalingListRefLayerId      ( 0              ); 
-#endif
 #endif
   m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
@@ -680,10 +845,6 @@
 {
 #if H_MV
-#if H_MV5
   m_cPPS.setLayerId( getLayerId() );
   if( getVPS()->getNumDirectRefLayers( getLayerId() ) > 0 )
-#else
-  if( getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) > 0 )
-#endif
   {
     m_cPPS.setListsModificationPresentFlag( true );
@@ -734,4 +895,12 @@
 #if RATE_CONTROL_LAMBDA_DOMAIN
   if ( m_RCEnableRateControl )
+  {
+    m_cPPS.setUseDQP(true);
+    m_cPPS.setMaxCuDQPDepth( 0 );
+    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
+  }
+#endif 
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
+  if ( m_enableRateCtrl )
   {
     m_cPPS.setUseDQP(true);
@@ -751,12 +920,19 @@
   m_cPPS.setOutputFlagPresentFlag( false );
 #if H_MV
-#if H_MV5
   m_cPPS.setNumExtraSliceHeaderBits( 2 ); 
-#else
-  m_cPPS.setNumExtraSliceHeaderBits( 1 ); 
-#endif
 #endif
   m_cPPS.setSignHideFlag(getSignHideFlag());
-  m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
+  if ( getDeblockingFilterMetric() )
+  {
+    m_cPPS.setDeblockingFilterControlPresentFlag (true);
+    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
+    m_cPPS.setPicDisableDeblockingFilterFlag(false);
+    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
+    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
+  } 
+  else
+  {
+    m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
+  }
   m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
   m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
@@ -812,9 +988,9 @@
 
 //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
-Void TEncTop::xInitRPS()
+Void TEncTop::xInitRPS(Bool isFieldCoding)
 {
   TComReferencePictureSet*      rps;
   
-  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs);
+  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs+1);
   TComRPSList* rpsList = m_cSPS.getRPSList();
 
@@ -913,5 +1089,5 @@
         printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
         rps->setNumberOfNegativePictures(numNeg);
-        rps->setNumberOfPositivePictures(numNeg+numPos);
+        rps->setNumberOfPictures(numNeg+numPos);
       }
       if (numPos != rps->getNumberOfPositivePictures())
@@ -919,5 +1095,5 @@
         printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
         rps->setNumberOfPositivePictures(numPos);
-        rps->setNumberOfPositivePictures(numNeg+numPos);
+        rps->setNumberOfPictures(numNeg+numPos);
       }
       RPSTemp.setNumberOfPictures(numNeg+numPos);
@@ -983,5 +1159,21 @@
 #endif //INTER_RPS_AUTO
   }
-  
+  //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file. 
+  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS. 
+  if (isFieldCoding) 
+  {
+    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
+    rps->setNumberOfPictures(1);
+    rps->setNumberOfNegativePictures(1);
+    rps->setNumberOfPositivePictures(0);
+    rps->setNumberOfLongtermPictures(0);
+    rps->setDeltaPOC(0,-1);
+    rps->setPOC(0,0);
+    rps->setUsed(0,true);
+    rps->setInterRPSPrediction(false);
+    rps->setDeltaRIdxMinus1(0);
+    rps->setDeltaRPS(0);
+    rps->setNumRefIdc(0);
+}
 }
 
@@ -1028,4 +1220,8 @@
     }
   }
+  if(POCCurr == 1 && slice->getPic()->isField())
+  {
+    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
+  }
 
   slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
@@ -1147,6 +1343,7 @@
 }
 #if H_MV
-Void TEncTop::printSummary( Int numAllPicCoded )
-{
+Void TEncTop::printSummary( Int numAllPicCoded, Bool isField )
+{
+  assert ( !isField ); // Multiview and field coding need to be further unified
   assert (numAllPicCoded == m_cAnalyzeAll.getNumPic());
 
Index: trunk/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 625)
+++ trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 655)
@@ -64,4 +64,7 @@
 // ====================================================================================================================
 
+#if KWU_RC_MADPRED_E0227
+class TAppEncTop;
+#endif
 /// encoder class
 class TEncTop : public TEncCfg
@@ -124,4 +127,9 @@
   TComScalingList         m_scalingList;                 ///< quantization matrix information
   TEncRateCtrl            m_cRateCtrl;                    ///< Rate control class
+
+#if KWU_RC_MADPRED_E0227
+  TAppEncTop*             m_pcTAppEncTop;
+  TAppComCamPara*         m_cCamParam;
+#endif
   
 #if H_MV
@@ -137,5 +145,5 @@
   
   Void  xInitPPSforTiles  ();
-  Void  xInitRPS          ();                             ///< initialize PPS from encoder options
+  Void  xInitRPS          (Bool isFieldCoding);           ///< initialize PPS from encoder options
 
 public:
@@ -145,5 +153,10 @@
   Void      create          ();
   Void      destroy         ();
-  Void      init            ();
+#if KWU_RC_MADPRED_E0227
+  Void      init            ( TAppEncTop* pcTAppEncTop, Bool isFieldCoding );
+#else
+  Void      init            (Bool isFieldCoding);
+#endif
+
 #if H_MV  
   TComPicLists* getIvPicLists() { return m_ivPicLists; }
@@ -185,4 +198,9 @@
   TEncSbac*               getRDGoOnSbacCoders   () { return  m_pcRDGoOnSbacCoders;   }
   TEncRateCtrl*           getRateCtrl           () { return &m_cRateCtrl;             }
+#if KWU_RC_MADPRED_E0227
+  TAppEncTop*             getEncTop             () { return m_pcTAppEncTop; }
+  TAppComCamPara*         getCamParam()                 { return m_cCamParam;}
+  Void                    setCamParam(TAppComCamPara * pCamparam)                 { m_cCamParam = pCamparam;}
+#endif
   TComSPS*                getSPS                () { return  &m_cSPS;                 }
   TComPPS*                getPPS                () { return  &m_cPPS;                 }
@@ -210,13 +228,22 @@
 #if H_MV
   Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded  , Int gopId  );  
+
+   /// encode several number of pictures until end-of-sequence
+  Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
+              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff  , Int gopId );
+
 #else
   Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
-              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded );  
-#endif
-
-#if H_MV
-  Void printSummary      ( Int numAllPicCoded ); 
-#else
-  void printSummary() { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded); } 
+              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ); 
+   /// encode several number of pictures until end-of-sequence
+  Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
+              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff);
+
+#endif
+
+#if H_MV
+  Void printSummary      ( Int numAllPicCoded, bool isField ); 
+#else
+  Void printSummary(bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField); }
 #endif
 
Index: trunk/source/Lib/TLibExtractor/TExtrTop.cpp
===================================================================
--- trunk/source/Lib/TLibExtractor/TExtrTop.cpp	(revision 625)
+++ trunk/source/Lib/TLibExtractor/TExtrTop.cpp	(revision 655)
@@ -100,5 +100,4 @@
 Void TExtrTop::dumpVpsInfo( std::ostream& rcVpsInfoHandle )
 { 
-#if H_MV5
   rcVpsInfoHandle << "MaxLayers      = " << m_cVPS.getMaxLayersMinus1() + 1 << std::endl; 
   rcVpsInfoHandle << "MaxNuhLayerId  = " << m_cVPS.getVpsMaxLayerId() << std::endl;                      
@@ -114,18 +113,4 @@
 #endif
     rcVpsInfoHandle << "ViewId         = " << m_cVPS.getViewId        ( layerId ) << std::endl;     
-#else
-  rcVpsInfoHandle << "MaxLayers = "     << m_cVPS.getMaxLayers()     << std::endl; 
-  rcVpsInfoHandle << "MaxNuhLayerId = " << m_cVPS.getVpsMaxLayerId() << std::endl; 
-  
-  for ( Int layerIdxInVps = 0; layerIdxInVps < m_cVPS.getMaxLayers(); layerIdxInVps++ )
-  {  
-    rcVpsInfoHandle << "LayerIdxInVps =  " << layerIdxInVps                           << std::endl; 
-    rcVpsInfoHandle << "LayerIdInNuh = "   << m_cVPS.getLayerIdInNuh( layerIdxInVps ) << std::endl; 
-    rcVpsInfoHandle << "ViewId = "         << m_cVPS.getViewId      ( layerIdxInVps ) << std::endl; 
-#if H_3D
-    rcVpsInfoHandle << "DepthFlag = "      << m_cVPS.getViewIndex   ( layerIdxInVps ) << std::endl;     
-    rcVpsInfoHandle << "DepthFlag = "      << m_cVPS.getDepthId     ( layerIdxInVps ) << std::endl;     
-#endif
-#endif
   }
 }
Index: trunk/source/Lib/TLibRenderer/TRenTop.cpp
===================================================================
--- trunk/source/Lib/TLibRenderer/TRenTop.cpp	(revision 625)
+++ trunk/source/Lib/TLibRenderer/TRenTop.cpp	(revision 655)
@@ -1033,5 +1033,4 @@
             for ( ; iInterPolPos <= xCeil (iShiftedPos ) -1 ; iInterPolPos++)
             {
-#if H_3D_FIX_REN
               if ( ( iInterPolPos >= 0 ) && ( iInterPolPos < iOutputWidth ) )
               {
@@ -1050,13 +1049,4 @@
                 }
               }
-#else
-              for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
-              {
-                if ( ( iInterPolPos >= 0 ) && ( iInterPolPos < iOutputWidth ) )
-                {
-                  apcOutputData[uiCurPlane][iInterPolPos]  = apcInputData[uiCurPlane][iPosX];
-                }
-              }
-#endif
             }
           }
@@ -1304,9 +1294,5 @@
         else
         {
-#if H_3D_FIX_REN
           pcAlphaData[iXPos] = pcFilledData[iXPos];
-#else
-          pcAlphaData[iXPos] = REN_IS_FILLED;
-#endif
         }
       }
Index: trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp
===================================================================
--- trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	(revision 625)
+++ trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	(revision 655)
@@ -339,4 +339,44 @@
 }
 
+static Bool writeField(ostream& fd, Pel* top, Pel* bottom, Bool is16bit,
+                       UInt stride,
+                       UInt width, UInt height, bool isTff)
+{
+  Int write_len = width * (is16bit ? 2 : 1)*2;
+  UChar *buf = new UChar[write_len];
+  for (Int y = 0; y < height; y++)
+  {
+    if (!is16bit)
+    {
+      for (Int x = 0; x < width; x++)
+      {
+        buf[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
+        buf[width+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
+      }
+    }
+    else
+    {
+      for (Int x = 0; x < width; x++)
+      {
+        buf[2*x] = isTff ? top[x] & 0xff : bottom[x] & 0xff;
+        buf[2*x+1] = isTff ? (top[x] >> 8) & 0xff : (bottom[x] >> 8) & 0xff;
+        
+        buf[width+2*x] = isTff ? bottom[x] & 0xff : top[x] & 0xff;
+        buf[width+2*x+1] = isTff ? (bottom[x] >> 8) & 0xff : (top[x] >> 8) & 0xff;
+      }
+    }
+    
+    fd.write(reinterpret_cast<Char*>(buf), write_len);
+    if (fd.eof() || fd.fail() )
+    {
+      delete[] buf;
+      return false;
+    }
+    top += stride;
+    bottom += stride;
+  }
+  delete[] buf;
+  return true;
+}
 /**
  * Read one Y'CbCr frame, performing any required input scaling to change
@@ -501,2 +541,108 @@
 }
 
+
+/**
+ * Write one Y'CbCr frame. No bit-depth conversion is performed, pcPicYuv is
+ * assumed to be at TVideoIO::m_fileBitdepth depth.
+ *
+ * @param pPicTop     input top field YUV buffer class pointer
+ * @param pPicBottom  input bottom field YUV buffer class pointer
+ * @param aiPad       source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
+ * @return true for success, false in case of error
+ */
+Bool TVideoIOYuv::write( TComPicYuv* pPicTop, TComPicYuv* pPicBottom, Int cropLeft, Int cropRight, Int cropTop, Int cropBottom , bool isTff)
+{
+  // compute actual YUV frame size excluding padding size
+  Int   iStride = pPicTop->getStride();
+  UInt  width  = pPicTop->getWidth()  - cropLeft - cropRight;
+  UInt  height = pPicTop->getHeight() - cropTop  - cropBottom;
+  Bool is16bit = m_fileBitDepthY > 8 || m_fileBitDepthC > 8;
+  
+  TComPicYuv *dstPicTop = NULL;
+  TComPicYuv *dstPicBottom = NULL;
+  
+  Bool retval = true;
+  
+  if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0)
+  {
+    dstPicTop = new TComPicYuv;
+    dstPicTop->create( pPicTop->getWidth(), pPicTop->getHeight(), 1, 1, 0 );
+    pPicTop->copyToPic(dstPicTop);
+    
+    dstPicBottom = new TComPicYuv;
+    dstPicBottom->create( pPicBottom->getWidth(), pPicBottom->getHeight(), 1, 1, 0 );
+    pPicBottom->copyToPic(dstPicBottom);
+    
+    Pel minvalY = 0;
+    Pel minvalC = 0;
+    Pel maxvalY = (1 << m_fileBitDepthY) - 1;
+    Pel maxvalC = (1 << m_fileBitDepthC) - 1;
+#if CLIP_TO_709_RANGE
+    if (-m_bitDepthShiftY < 0 && m_fileBitDepthY >= 8)
+    {
+      /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
+      minvalY = 1 << (m_fileBitDepthY - 8);
+      maxvalY = (0xff << (m_fileBitDepthY - 8)) -1;
+    }
+    if (-m_bitDepthShiftC < 0 && m_fileBitDepthC >= 8)
+    {
+      /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
+      minvalC = 1 << (m_fileBitDepthC - 8);
+      maxvalC = (0xff << (m_fileBitDepthC - 8)) -1;
+    }
+#endif
+    scalePlane(dstPicTop->getLumaAddr(), dstPicTop->getStride(), dstPicTop->getWidth(), dstPicTop->getHeight(), -m_bitDepthShiftY, minvalY, maxvalY);
+    scalePlane(dstPicTop->getCbAddr(), dstPicTop->getCStride(), dstPicTop->getWidth()>>1, dstPicTop->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
+    scalePlane(dstPicTop->getCrAddr(), dstPicTop->getCStride(), dstPicTop->getWidth()>>1, dstPicTop->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
+    
+    scalePlane(dstPicBottom->getLumaAddr(), dstPicBottom->getStride(), dstPicBottom->getWidth(), dstPicBottom->getHeight(), -m_bitDepthShiftY, minvalY, maxvalY);
+    scalePlane(dstPicBottom->getCbAddr(), dstPicBottom->getCStride(), dstPicBottom->getWidth()>>1, dstPicBottom->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
+    scalePlane(dstPicBottom->getCrAddr(), dstPicBottom->getCStride(), dstPicBottom->getWidth()>>1, dstPicBottom->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
+  }
+  else
+  {
+    dstPicTop = pPicTop;
+    dstPicBottom = pPicBottom;
+  }
+  // location of upper left pel in a plane
+  Int planeOffset = 0; //cropLeft + cropTop * iStride;
+  //Write luma
+  if (! writeField(m_cHandle, dstPicTop->getLumaAddr() + planeOffset,  dstPicBottom->getLumaAddr() + planeOffset, is16bit, iStride, width, height, isTff))
+  {
+    retval=false;
+    goto exit;
+  }
+  
+  width >>= 1;
+  height >>= 1;
+  iStride >>= 1;
+  cropLeft >>= 1;
+  cropRight >>= 1;
+  
+  planeOffset = 0; // cropLeft + cropTop * iStride;
+  
+  //Write chroma U
+  if (! writeField(m_cHandle, dstPicTop->getCbAddr() + planeOffset, dstPicBottom->getCbAddr() + planeOffset, is16bit, iStride, width, height, isTff))
+  {
+    retval=false;
+    goto exit;
+  }
+  
+  //Write chroma V
+  if (! writeField(m_cHandle, dstPicTop->getCrAddr() + planeOffset, dstPicBottom->getCrAddr() + planeOffset, is16bit, iStride, width, height, isTff))
+    
+  {
+    retval=false;
+    goto exit;
+  }
+  
+exit:
+  if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0)
+  {
+    dstPicTop->destroy();
+    delete dstPicTop;
+    dstPicBottom->destroy();
+    delete dstPicBottom;
+  }  
+  return retval;
+}
Index: trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h
===================================================================
--- trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h	(revision 625)
+++ trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h	(revision 655)
@@ -72,4 +72,5 @@
   Bool  read  ( TComPicYuv*   pPicYuv, Int aiPad[2] );     ///< read  one YUV frame with padding parameter
   Bool  write( TComPicYuv*    pPicYuv, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0 );
+  Bool  write( TComPicYuv*    pPicYuv, TComPicYuv*    pPicYuv2, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0  , bool isTff=false); 
   
   Bool  isEof ();                                           ///< check for end-of-file
