Index: trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 100)
@@ -378,5 +378,5 @@
 Void TEncCavlc::codeVPS( TComVPS* pcVPS )
 {
-	WRITE_CODE( pcVPS->getMaxTLayers() - 1,     3,        "max_temporal_layers_minus1" );
+  WRITE_CODE( pcVPS->getMaxTLayers() - 1,     3,        "max_temporal_layers_minus1" );
   WRITE_CODE( pcVPS->getMaxLayers() - 1,      5,        "max_layers_minus1" );
   WRITE_FLAG( pcVPS->getTemporalNestingFlag() - 1,      "temporal_id_nesting_flag" );
@@ -775,5 +775,4 @@
     {
       WRITE_CODE( (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC()), pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
-#if HHI_FIX
       if( pcSlice->getPOC() == 0 && pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDV )
       {
@@ -848,7 +847,4 @@
       }
       if( pcSlice->getPOC() != 0 )
-#else
-      if( pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDV )
-#endif
       {
         TComReferencePictureSet* rps = pcSlice->getRPS();
Index: trunk/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 100)
@@ -205,4 +205,9 @@
   UInt      m_uiVSOMode;
 #endif
+#if SAIT_VSO_EST_A0033
+  Bool      m_bUseEstimatedVSD; 
+  Double    m_dDispCoeff;
+#endif
+
 
   //====== Tool list ========
@@ -568,4 +573,9 @@
 #endif
 
+#if SAIT_VSO_EST_A0033
+  Void      setUseEstimatedVSD              ( Bool  b )     { m_bUseEstimatedVSD = b; }
+  Void      setDispCoeff                    ( Double  d )   { m_dDispCoeff  = d; }
+#endif
+
   Void      setUseFastEnc                   ( Bool  b )     { m_bUseFastEnc = b; }
   Void      setUseEarlyCU                   ( Bool  b )     { m_bUseEarlyCU = b; }
@@ -608,4 +618,9 @@
   Bool      getUseVSO                       ()      { return m_bUseVSO;     }
 #endif
+#if SAIT_VSO_EST_A0033
+  Bool      getUseEstimatedVSD              ()      { return m_bUseEstimatedVSD; }
+  Double    getDispCoeff                    ()      { return m_dDispCoeff;    }
+#endif
+
   Bool      getUseFastEnc                   ()      { return m_bUseFastEnc; }
   Bool      getUseEarlyCU                   ()      { return m_bUseEarlyCU; }
Index: trunk/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 100)
@@ -1156,5 +1156,4 @@
       if( m_pcRdCost->getUseRenModel() )
       {
-#if HHI_FIX
         UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth ( );
         UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight( );
@@ -1162,11 +1161,4 @@
         UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride();
         m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#else
-        UInt  uiWidth     = m_ppcBestCU[uiDepth]->getWidth ( 0 );
-        UInt  uiHeight    = m_ppcBestCU[uiDepth]->getHeight( 0 );
-        Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 );
-        UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride();
-        m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#endif
       }
 #endif
@@ -1212,7 +1204,8 @@
 
 #if HHI_VSO
+#if HHI_VSO_SET_OPTIM 
+#else 
           if( m_pcRdCost->getUseRenModel() ) // necessary ??
           {
-#if HHI_FIX
             UInt  uiWidth     = m_ppcRecoYuvBest[uhNextDepth]->getWidth   (  );
             UInt  uiHeight    = m_ppcRecoYuvBest[uhNextDepth]->getHeight  (   );
@@ -1220,12 +1213,6 @@
             UInt  uiSrcStride = m_ppcRecoYuvBest[uhNextDepth]->getStride  (   );
             m_pcRdCost->setRenModelData( pcSubBestPartCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#else
-            UInt  uiWidth     = pcSubBestPartCU->getWidth ( 0 );
-            UInt  uiHeight    = pcSubBestPartCU->getHeight( 0 );
-            Pel*  piSrc       = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getLumaAddr( 0 );
-            UInt  uiSrcStride = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getStride();
-            m_pcRdCost->setRenModelData( pcSubBestPartCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#endif
-          }
+          }
+#endif
 #endif
         }
@@ -1369,5 +1356,4 @@
   if( m_pcRdCost->getUseRenModel() )
   {
-#if HHI_FIX
       UInt  uiWidth     = m_ppcRecoYuvBest[uiDepth]->getWidth   ( );
       UInt  uiHeight    = m_ppcRecoYuvBest[uiDepth]->getHeight  ( );
@@ -1375,11 +1361,4 @@
       UInt  uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride  ( );
       m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#else
-    UInt  uiWidth     = rpcBestCU->getWidth ( 0 );
-    UInt  uiHeight    = rpcBestCU->getHeight( 0 );
-    Pel*  piSrc       = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 );
-    UInt  uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride();
-    m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#endif
   }
 #endif
@@ -1747,5 +1726,4 @@
   if( m_pcRdCost->getUseRenModel() )
   {
-#if HHI_FIX
     UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
     UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
@@ -1753,11 +1731,4 @@
     UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
     m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#else
-    UInt  uiWidth     = rpcTempCU->getWidth ( 0 );
-    UInt  uiHeight    = rpcTempCU->getHeight( 0 );
-    Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
-    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
-    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#endif
   }
 #endif
@@ -1851,5 +1822,4 @@
           if( m_pcRdCost->getUseRenModel() )
           { //Reset
-#if HHI_FIX
             UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
             UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
@@ -1857,11 +1827,4 @@
             UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
             m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#else
-            UInt  uiWidth     = rpcTempCU->getWidth ( 0 );
-            UInt  uiHeight    = rpcTempCU->getHeight( 0 );
-            Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
-            UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
-            m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#endif
           }
 #endif
@@ -1927,5 +1890,4 @@
   if( m_pcRdCost->getUseRenModel() )
   {
-#if HHI_FIX
     UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
     UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
@@ -1933,11 +1895,4 @@
     UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
     m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#else
-    UInt  uiWidth     = rpcTempCU->getWidth ( 0 );
-    UInt  uiHeight    = rpcTempCU->getHeight( 0 );
-    Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
-    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
-    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#endif
   }
 #endif  
@@ -2046,5 +2001,4 @@
   if( m_pcRdCost->getUseRenModel() )
   {
-#if HHI_FIX
     UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth   ();
     UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight  ();
@@ -2052,11 +2006,4 @@
     UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride  ();
     m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#else
-    UInt  uiWidth     = rpcTempCU->getWidth ( 0 );
-    UInt  uiHeight    = rpcTempCU->getHeight( 0 );
-    Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr( );
-    UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride();
-    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#endif
   }
 #endif
@@ -2557,5 +2504,4 @@
   if( m_pcRdCost->getUseRenModel() && !bRecursiveCall)
   {
-#if HHI_FIX
     UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth   ();
     UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight  ();
@@ -2563,11 +2509,4 @@
     UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride  ();
     m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#else
-    UInt  uiWidth     = m_ppcTempCU [uhDepth]->getWidth ( 0 );
-    UInt  uiHeight    = m_ppcTempCU [uhDepth]->getHeight( 0 );
-    Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( 0 );
-    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
-    m_pcRdCost->setRenModelData( m_ppcTempCU[uhDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#endif
   }
 #endif
@@ -2717,5 +2656,4 @@
   if( !bSplit && bRecursiveCall && m_pcRdCost->getUseRenModel() )
   {
-#if HHI_FIX
     UInt  uiWidth     = m_ppcRecoYuvBest[uhDepth]->getWidth   (   );
     UInt  uiHeight    = m_ppcRecoYuvBest[uhDepth]->getHeight  (   );
@@ -2723,11 +2661,4 @@
     Pel*  piSrc       = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 );
     m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#else
-    UInt  uiWidth     = rpcBestCU->getWidth ( 0 );
-    UInt  uiHeight    = rpcBestCU->getHeight( 0 );
-    Pel*  piSrc       = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 );
-    UInt  uiSrcStride = m_ppcRecoYuvBest[uhDepth]->getStride();
-    m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
-#endif
   }
 #endif
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 100)
@@ -77,7 +77,7 @@
 
 #if VIDYO_VPS_INTEGRATION
-	virtual Void  codeVPS                 ( TComVPS* pcVPS )                                      = 0;
-#endif
-	
+  virtual Void  codeVPS                 ( TComVPS* pcVPS )                                      = 0;
+#endif
+
 #if HHI_MPI
   virtual Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth )                       = 0;
@@ -234,5 +234,5 @@
 public:
 #if VIDYO_VPS_INTEGRATION
-	Void encodeVPS               ( TComVPS* pcVPS);
+  Void encodeVPS               ( TComVPS* pcVPS);
 #endif
   // SPS
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 100)
@@ -436,4 +436,7 @@
   Bool bUseVSO = m_pcEncTop->getUseVSO();
   m_pcRdCost->setUseVSO( bUseVSO );
+#if SAIT_VSO_EST_A0033
+  m_pcRdCost->setUseEstimatedVSD( m_pcEncTop->getUseEstimatedVSD() );
+#endif
 
   if ( bUseVSO )
@@ -445,4 +448,6 @@
 #endif
 
+#if HHI_VSO_SPEEDUP_A033
+#else
     if ( iVSOMode == 4 )
     {
@@ -453,4 +458,12 @@
       AOT(true); 
     }
+#endif
+
+#if SAIT_VSO_EST_A0033
+    m_pcRdCost->setVideoRecPicYuv( m_pcEncTop->getEncTop()->xGetPicYuvFromViewTemp( pcSlice->getViewId(), pcSlice->getPOC(), false, true ) );
+    m_pcRdCost->setDepthPicYuv   ( m_pcEncTop->getEncTop()->xGetPicYuvFromViewTemp( pcSlice->getViewId(), pcSlice->getPOC(), true, false ) );
+#endif
+
+
   }
 #endif
@@ -691,5 +704,7 @@
       // init view component and predict virtual depth map
       m_pcDepthMapGenerator->initViewComponent( pcPic );
+#if !QC_MULTI_DIS_CAN
       m_pcDepthMapGenerator->predictDepthMap  ( pcPic );
+#endif
 #endif
 #if HHI_INTER_VIEW_MOTION_PRED
@@ -758,6 +773,8 @@
 #endif
 #if DEPTH_MAP_GENERATION
+#if !QC_MULTI_DIS_CAN
       // update virtual depth map
       m_pcDepthMapGenerator->updateDepthMap( pcPic );
+#endif
 #endif
 
@@ -2475,18 +2492,18 @@
     if( hasModification )
     {
-	    Int temporalRefIdx = 0;
-	    for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++ )
-	    {
-	      if( tempListEntryL0[i] >= 0 ) 
-	      {
-	        refPicListModification->setRefPicSetIdxL0( i, tempListEntryL0[i] );
-	      }
-	      else
-	      {
-	        refPicListModification->setRefPicSetIdxL0( i, temporalRefIdx );
-	        temporalRefIdx++;
-	      }
-	    }
-	  }
+      Int temporalRefIdx = 0;
+      for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++ )
+      {
+        if( tempListEntryL0[i] >= 0 ) 
+        {
+          refPicListModification->setRefPicSetIdxL0( i, tempListEntryL0[i] );
+        }
+        else
+        {
+          refPicListModification->setRefPicSetIdxL0( i, temporalRefIdx );
+          temporalRefIdx++;
+        }
+      }
+    }
     else
     {
@@ -2520,17 +2537,17 @@
     if( hasModification )
     {
-	    Int temporalRefIdx = 0;
-	    for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++ )
-	    {
-	      if( tempListEntryL1[i] >= 0 ) 
-	      {
-	        refPicListModification->setRefPicSetIdxL1( i, tempListEntryL1[i] );
-	      }
-	      else
-	      {
-	        refPicListModification->setRefPicSetIdxL1( i, temporalRefIdx );
-	        temporalRefIdx++;
-	      }
-	    }
+      Int temporalRefIdx = 0;
+      for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++ )
+      {
+        if( tempListEntryL1[i] >= 0 ) 
+        {
+          refPicListModification->setRefPicSetIdxL1( i, tempListEntryL1[i] );
+        }
+        else
+        {
+          refPicListModification->setRefPicSetIdxL1( i, temporalRefIdx );
+          temporalRefIdx++;
+        }
+      }
     } 
     else
Index: trunk/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 100)
@@ -137,4 +137,7 @@
   
   Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits );
+#if HHI_VSO_SPEEDUP_A033
+  TEncTop* getEncTop() { return m_pcEncTop; }
+#endif
   
   TEncSlice*  getSliceEncoder()   { return m_pcSliceEncoder; }
Index: trunk/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 100)
@@ -106,4 +106,10 @@
 , m_cDmmDataSCModel           ( 1,             1,               NUM_DMM_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
 #endif
+#if LGE_EDGE_INTRA
+, m_cEdgeIntraSCModel         ( 1,             1,               NUM_EDGE_INTRA_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
+#if LGE_EDGE_INTRA_DELTA_DC
+, m_cEdgeIntraDeltaDCSCModel  ( 1,             1,               NUM_EDGE_INTRA_DELTA_DC_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
+#endif
 {
   assert( m_numContextModels <= MAX_NUM_CTX_MOD );
@@ -181,4 +187,10 @@
   m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
 #endif
+#if LGE_EDGE_INTRA
+  m_cEdgeIntraSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_EDGE_INTRA );
+#if LGE_EDGE_INTRA_DELTA_DC
+  m_cEdgeIntraDeltaDCSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_EDGE_INTRA_DELTA_DC );
+#endif
+#endif
 
   // new structure
@@ -345,5 +357,5 @@
 Void TEncSbac::codeVPS( TComVPS* pcVPS )
 {
-	assert (0);
+  assert (0);
   return;
 }
@@ -828,4 +840,79 @@
   DTRACE_CABAC_T( "\n" )
 }
+
+#if LGE_EDGE_INTRA
+Void TEncSbac::xCodeEdgeIntraInfo( TComDataCU* pcCU, UInt uiPartIdx )
+{
+  UInt   uiDepth        = pcCU->getDepth( uiPartIdx ) + (pcCU->getPartitionSize( uiPartIdx ) == SIZE_NxN ? 1 : 0);
+  UInt   uiCtxEdgeIntra = pcCU->getCtxEdgeIntra( uiPartIdx );
+  UChar* pucSymbolList  = pcCU->getEdgeCode( uiPartIdx );
+  UChar  ucEdgeNumber   = pcCU->getEdgeNumber( uiPartIdx );
+  Bool   bLeft          = pcCU->getEdgeLeftFirst( uiPartIdx );
+  UChar  ucStart        = pcCU->getEdgeStartPos( uiPartIdx );
+  UInt   uiSymbol;
+
+  // 1. Top(0) or Left(1)
+  uiSymbol = (bLeft == false) ? 0 : 1;
+  m_pcBinIf->encodeBinEP( uiSymbol );
+
+  // 2. Start position (lowest bit first)
+  uiSymbol = ucStart;
+  for( UInt ui = 6; ui > uiDepth; ui-- ) // 64(0)->6, 32(1)->5, 16(2)->4, 8(3)->3, 4(4)->2
+  {
+    m_pcBinIf->encodeBinEP( uiSymbol & 0x1 );
+    uiSymbol >>= 1;
+  }
+
+  // 3. Number of edges
+  uiSymbol = ucEdgeNumber > 0 ? ucEdgeNumber - 1 : 0;
+  for( UInt ui = 7; ui > uiDepth; ui-- ) // 64(0)->7, 32(1)->6, 16(2)->5, 8(3)->4, 4(4)->3
+  {
+    m_pcBinIf->encodeBinEP( uiSymbol & 0x1 );
+    uiSymbol >>= 1;
+  }
+
+  if(uiSymbol != 0)
+  {
+    printf(" ucEdgeNumber %d at depth %d\n",ucEdgeNumber, uiDepth);
+    assert(false);
+  }
+
+  // 4. Edges
+  for( Int iPtr2 = 0; iPtr2 < ucEdgeNumber; iPtr2++ )
+  {
+    UInt uiReorderSymbol = pucSymbolList[iPtr2];
+
+    //printf ("Ptr = %d, Symbol = %d\n", iPtr2, uiSymbol);
+
+    // Left-friendly direction (Top start)
+    // 0 (   0deg) => 0
+    // 1 (  45deg) => 10
+    // 2 ( -45deg) => 110
+    // 3 (  90deg) => 1110
+    // 4 ( -90deg) => 11110
+    // 5 ( 135deg) => 111110
+    // 6 (-135deg) => 111111
+    // Right-friendly direction (Left start)
+    // 0 (   0deg) => 0
+    // 2 ( -45deg) => 10
+    // 1 (  45deg) => 110
+    // 4 ( -90deg) => 1110
+    // 3 (  90deg) => 11110
+    // 6 (-135deg) => 111110
+    // 5 ( 135deg) => 111111
+
+    // refer to a paper "An efficient chain code with Huffman coding"
+
+    for( UInt ui = 0; ui < uiReorderSymbol; ui++ )
+    {
+      m_pcBinIf->encodeBin( 1, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) );
+    }
+
+    if( uiReorderSymbol != 6 )
+      m_pcBinIf->encodeBin( 0, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) );
+  }
+}
+#endif
+
 Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx )
 {
@@ -835,7 +922,15 @@
   if( pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE )
   {
+#if LGE_EDGE_INTRA
+    m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX, m_cDmmFlagSCModel.get(0, 0, 0) );
+#else
     m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE, m_cDmmFlagSCModel.get(0, 0, 0) );
-  }
+#endif
+  }
+#if LGE_EDGE_INTRA
+  if( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX )
+#else
   if( uiDir >= NUM_INTRA_MODE )
+#endif
   {
     assert( pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE );
@@ -870,8 +965,47 @@
   }
   else
+#if LGE_EDGE_INTRA
+    if ( uiDir >= EDGE_INTRA_IDX)
+    {
+      m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) );
+      m_pcBinIf->encodeBinsEP( 63, 6 );
+      xCodeEdgeIntraInfo( pcCU, uiAbsPartIdx );
+#if LGE_EDGE_INTRA_DELTA_DC
+      m_pcBinIf->encodeBin( (uiDir == EDGE_INTRA_DELTA_IDX), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
+      if( uiDir == EDGE_INTRA_DELTA_IDX )
+      {
+        Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx );
+        Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx );
+
+        xWriteExGolombLevel( UInt( abs( iDeltaDC0 ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
+        if ( iDeltaDC0 != 0 )
+        {
+          UInt uiSign = iDeltaDC0 > 0 ? 0 : 1;
+          m_pcBinIf->encodeBinEP( uiSign );
+        }
+        xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
+        if ( iDeltaDC1 != 0 )
+        {
+          UInt uiSign = iDeltaDC1 > 0 ? 0 : 1;
+          m_pcBinIf->encodeBinEP( uiSign );
+        }
+      }
+#endif
+    }
+    else
+#endif // LGE_EDGE_INTRA
   {
 #endif
 #if !LOGI_INTRA_NAME_3MPM
   Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx);
+#endif
+#if LGE_EDGE_INTRA
+  Bool bCodeEdgeIntra = false;
+  if( pcCU->getSlice()->getSPS()->isDepth() )
+  {
+    UInt uiPUWidth = pcCU->getWidth( uiAbsPartIdx ) >> (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0);
+    if( uiPUWidth <= LGE_EDGE_INTRA_MAX_SIZE && uiPUWidth >= LGE_EDGE_INTRA_MIN_SIZE )
+      bCodeEdgeIntra = true;
+  }
 #endif
   
@@ -932,4 +1066,8 @@
 #if LOGI_INTRA_NAME_3MPM
     m_pcBinIf->encodeBinsEP( uiDir, 5 );
+#if LGE_EDGE_INTRA
+  if (bCodeEdgeIntra)
+    if (uiDir == 31) m_pcBinIf->encodeBinsEP(0,1);
+#endif
 #else
     if ( uiDir < 31 )
@@ -2270,5 +2408,5 @@
 }
 
-#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
+#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX || (LGE_EDGE_INTRA && LGE_EDGE_INTRA_DELTA_DC)
 Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel  )
 {
Index: trunk/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 100)
@@ -101,5 +101,5 @@
   Void  codeVPS                 ( TComVPS* pcVPS );
 #endif
-	
+  
 #if HHI_MPI
   Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth );
@@ -174,4 +174,7 @@
   Void  xCodeWedgePredTexDeltaInfo  ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void  xCodeContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx );
+#endif
+#if LGE_EDGE_INTRA
+  Void  xCodeEdgeIntraInfo( TComDataCU* pcCU, UInt uiPartIdx );
 #endif
 
@@ -307,4 +310,10 @@
   ContextModel3DBuffer m_cDmmDataSCModel;
 #endif
+#if LGE_EDGE_INTRA
+  ContextModel3DBuffer m_cEdgeIntraSCModel;
+#if LGE_EDGE_INTRA_DELTA_DC
+  ContextModel3DBuffer m_cEdgeIntraDeltaDCSCModel;
+#endif
+#endif
 };
 
Index: trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 100)
@@ -304,5 +304,5 @@
   // motion cost
   uiSad += m_pcRdCost->getCost( iSearchX, iSearchY );
-#if HHI_FIX  
+
   // regularization cost
   if( m_pcRdCost->useMultiviewReg() )
@@ -310,5 +310,4 @@
     uiSad += m_pcRdCost->getMultiviewRegCost( iSearchX, iSearchY );
   }
-#endif
   if( uiSad < rcStruct.uiBestSad )
   {
@@ -957,5 +956,9 @@
                                 TComYuv*    pcPredYuv, 
                                 TComYuv*    pcResiYuv, 
-                                Dist&       ruiDist )
+                                Dist&       ruiDist 
+#if LG_ZEROINTRADEPTHRESI_M26039
+                                ,Bool        bZeroResi
+#endif
+                                )
 {
   UInt    uiLumaPredMode    = pcCU     ->getLumaIntraDir     ( uiAbsPartIdx );
@@ -989,4 +992,21 @@
   pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail );
   
+#if LGE_EDGE_INTRA
+  if( uiLumaPredMode >= EDGE_INTRA_IDX )
+  {
+#if LGE_EDGE_INTRA_DELTA_DC
+    if( uiLumaPredMode == EDGE_INTRA_DELTA_IDX )
+      xAssignEdgeIntraDeltaDCs( pcCU, uiAbsPartIdx, piOrg, uiStride, piPred, uiWidth, uiHeight );
+#endif
+
+    predIntraLumaEdge( pcCU, pcCU->getPattern(), uiAbsPartIdx, uiWidth, uiHeight, piPred, uiStride
+#if LGE_EDGE_INTRA_DELTA_DC
+     , uiLumaPredMode == EDGE_INTRA_DELTA_IDX
+#endif
+    );
+  }
+  else
+#endif
+  
   //===== get prediction signal =====
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
@@ -1020,4 +1040,16 @@
     }
   }
+#if LG_ZEROINTRADEPTHRESI_M26039
+  if(bZeroResi)
+  {
+    Pel* pResi = piResi;
+
+    for( UInt uiY = 0; uiY < uiHeight; uiY++ )
+    {
+      memset( pResi, 0, sizeof( Pel ) * uiWidth );
+      pResi += uiStride;
+    }
+  }
+#endif
   
   //===== transform and quantization =====
@@ -1311,5 +1343,9 @@
                                 Bool         bCheckFirst,
 #endif
-                                Double&      dRDCost )
+                                Double&      dRDCost 
+#if LG_ZEROINTRADEPTHRESI_M26039
+                               ,Bool         bZeroResi
+#endif
+                              )
 {
   UInt    uiFullDepth   = pcCU->getDepth( 0 ) +  uiTrDepth;
@@ -1326,4 +1362,10 @@
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
   if( pcCU->getLumaIntraDir( uiAbsPartIdx ) >= NUM_INTRA_MODE )
+  {
+    bCheckSplit = false;
+  }
+#endif
+#if LGE_EDGE_INTRA
+  if( pcCU->getLumaIntraDir( uiAbsPartIdx ) >= EDGE_INTRA_IDX )
   {
     bCheckSplit = false;
@@ -1346,5 +1388,9 @@
     //----- code luma block with given intra prediction mode and store Cbf-----
     dSingleCost   = 0.0;
+#if LG_ZEROINTRADEPTHRESI_M26039
+    xIntraCodingLumaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistY, bZeroResi ); 
+#else
     xIntraCodingLumaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistY ); 
+#endif
     if( bCheckSplit )
     {
@@ -1808,4 +1854,19 @@
     Int numModesForFullRD = g_aucIntraModeNumFast[ uiWidthBit ];
     
+#if LGE_EDGE_INTRA
+  Bool bTestEdgeIntra = false;
+  if ( m_pcEncCfg->isDepthCoder() && uiWidth >= LGE_EDGE_INTRA_MIN_SIZE && uiWidth <= LGE_EDGE_INTRA_MAX_SIZE && uiWidth == uiHeight )
+  {
+    bTestEdgeIntra = true;
+
+    Bool bEdgeExist;
+
+    bEdgeExist = xEdgePartition( pcCU, uiPartOffset, pcCU->getPartitionSize(0) == SIZE_NxN );
+
+    if( !bEdgeExist )
+      bTestEdgeIntra = false;
+  }
+#endif
+    
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     Bool bTestDmm = ( m_pcEncCfg->getUseDMM() );
@@ -1828,42 +1889,58 @@
 
         predIntraLumaAng( pcCU->getPattern(), uiMode, piPred, uiStride, uiWidth, uiHeight, pcCU, bAboveAvail, bLeftAvail );
-        
+
         // use hadamard transform here
-      Dist uiSad;
+        Dist uiSad;
 #if HHI_VSO
-      if ( m_pcRdCost->getUseVSO() )
-      {
-        Bool bSad = !m_pcRdCost->getUseRenModel();
-        uiSad = m_pcRdCost->getDistVS(pcCU, uiPartOffset, piPred, uiStride, piOrg, uiStride, uiWidth, uiHeight, bSad, 0 );
-      }
-      else
-#endif
-      {
-        uiSad = (Dist) m_pcRdCost->calcHAD( piOrg, uiStride, piPred, uiStride, uiWidth, uiHeight );
-      }
-        
+        if ( m_pcRdCost->getUseVSO() )
+        {
+#if SAIT_VSO_EST_A0033
+          if ( m_pcRdCost->getUseEstimatedVSD() )
+          {          
+            TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
+            TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
+
+            uiSad = (Dist) ( m_pcRdCost->getDistPart( piPred, uiStride, piOrg, uiStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiPartOffset), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiPartOffset), pcVirRec->getStride(), uiWidth, uiHeight ) );
+          }
+          else
+#endif
+          {          
+            Bool bSad = !m_pcRdCost->getUseRenModel();
+            uiSad = m_pcRdCost->getDistVS(pcCU, uiPartOffset, piPred, uiStride, piOrg, uiStride, uiWidth, uiHeight, bSad, 0 );
+          }
+
+        }
+        else
+#endif
+        {
+          uiSad = (Dist) m_pcRdCost->calcHAD( piOrg, uiStride, piPred, uiStride, uiWidth, uiHeight );
+        }
+
         UInt   iModeBits = xModeBitsIntra( pcCU, uiMode, uiPU, uiPartOffset, uiDepth, uiInitTrDepth );
 
-      Double dLambda;
+        Double dLambda;
 #if HHI_VSO
-      if ( m_pcRdCost->getUseLambdaScaleVSO() )
-      {
-        dLambda = m_pcRdCost->getUseRenModel() ? m_pcRdCost->getLambdaVSO() : m_pcRdCost->getSqrtLambdaVSO();
-        //GT: Sad is SSE for VSO4
-      }
-      else
-      {
+        if ( m_pcRdCost->getUseLambdaScaleVSO() )
+        {
+          dLambda = m_pcRdCost->getUseRenModel() ? m_pcRdCost->getLambdaVSO() : m_pcRdCost->getSqrtLambdaVSO();
+          //GT: Sad is SSE for VSO4
+        }
+        else
+        {
+          dLambda = m_pcRdCost->getSqrtLambda();
+        }
+#else
         dLambda = m_pcRdCost->getSqrtLambda();
-      }
-#else
-      dLambda = m_pcRdCost->getSqrtLambda();
-#endif
-
-      Double cost = (Double)uiSad + (Double)iModeBits *  dLambda;
-        
+#endif
+
+        Double cost = (Double)uiSad + (Double)iModeBits *  dLambda;
+
         CandNum += xUpdateCandList( uiMode, cost, numModesForFullRD, uiRdModeList, CandCostList );
 
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
         if( bTestDmm ) bTestDmm = uiSad ? true : false;
+#endif
+#if LGE_EDGE_INTRA
+        if ( bTestEdgeIntra ) bTestEdgeIntra = uiSad ? true : false;
 #endif
       }
@@ -1974,4 +2051,13 @@
     }
 #endif
+#if LGE_EDGE_INTRA
+  if( bTestEdgeIntra )
+  {
+    uiRdModeList[ numModesForFullRD++ ] = EDGE_INTRA_IDX;
+#if LGE_EDGE_INTRA_DELTA_DC
+    uiRdModeList[ numModesForFullRD++ ] = EDGE_INTRA_DELTA_IDX;
+#endif
+  }
+#endif
 
     //===== check modes (using r-d costs) =====
@@ -1987,9 +2073,19 @@
     for( UInt uiMode = 0; uiMode < numModesForFullRD; uiMode++ )
     {
+#if LG_ZEROINTRADEPTHRESI_M26039
+    Bool bAllowZeroResi = pcCU->getSlice()->getIsDepth() && (pcCU->getSlice()->getPOC()%pcCU->getPic()->getIntraPeriod());// && (uiMode < NUM_INTRA_MODE);
+    for(UInt uiCnt = 0; uiCnt < (bAllowZeroResi ? 2 : 1); uiCnt++)
+    {
+      Bool bZeroResi = uiCnt ? true : false;
+#endif
       // set luma prediction mode
       UInt uiOrgMode = uiRdModeList[uiMode];
-      
+
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
-      if( m_pcEncCfg->getIsDepth() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight ) )
+      if( m_pcEncCfg->getIsDepth() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight ) 
+#if LGE_EDGE_INTRA
+        && uiOrgMode < EDGE_INTRA_IDX
+#endif
+        )
       {
         continue;
@@ -2020,5 +2116,9 @@
 
 #if HHI_RQT_INTRA_SPEEDUP
+#if LG_ZEROINTRADEPTHRESI_M26039
+      xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost, bZeroResi );
+#else
       xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost );
+#endif
 #else
       xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost );
@@ -2052,4 +2152,7 @@
         dSecondBestPUCost = dPUCost;
       }
+#endif
+#if LG_ZEROINTRADEPTHRESI_M26039
+    }
 #endif
     } // Mode loop
@@ -2579,31 +2682,31 @@
       pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
 #if LG_RESTRICTEDRESPRED_M24766
-	  Int iAddResiShift;
-	  UInt uiPartAddr;
-	  Int iRoiWidth, iRoiHeight;
-
-	  pcCU->getPartIndexAndSize( iPUIdx, uiPartAddr, iRoiWidth, iRoiHeight );
-	  iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
-	  iAddResiShift = (pcCU->getSlice()->getPPS()->getUseWP() || pcCU->getInterDir(uiPartAddr) != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1 - iAddResiShift : -1);
-
-	  if( pcCU->getResPredFlag( 0 ))
-	  { // subtract residual prediction from original in motion search
-		  if(iLastAddResiShift != iAddResiShift)
-		  {
-			  //add subtracted residual last time
-			  if(iLastAddResiShift >= 0)
-			  {
-				  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
-				  pcYuvOrg->add(iPUResiPredShift, ePartSize, rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
-			  }
-			  //subtract residual
-			  if(iAddResiShift >= 0)
-			  {
-				  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iAddResiShift;
-				  pcYuvOrg->add(iPUResiPredShift, ePartSize, rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
-			  }
-			  iLastAddResiShift = iAddResiShift;
-		  }
-	  }
+      Int iAddResiShift;
+      UInt uiPartAddr;
+      Int iRoiWidth, iRoiHeight;
+
+      pcCU->getPartIndexAndSize( iPUIdx, uiPartAddr, iRoiWidth, iRoiHeight );
+      iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
+      iAddResiShift = (pcCU->getSlice()->getPPS()->getUseWP() || pcCU->getInterDir(uiPartAddr) != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1 - iAddResiShift : -1);
+
+      if( pcCU->getResPredFlag( 0 ))
+      { // subtract residual prediction from original in motion search
+        if(iLastAddResiShift != iAddResiShift)
+        {
+          //add subtracted residual last time
+          if(iLastAddResiShift >= 0)
+          {
+            iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
+            pcYuvOrg->add(iPUResiPredShift, ePartSize, rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+          }
+          //subtract residual
+          if(iAddResiShift >= 0)
+          {
+            iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iAddResiShift;
+            pcYuvOrg->add(iPUResiPredShift, ePartSize, rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
+          }
+          iLastAddResiShift = iAddResiShift;
+        }
+      }
 #endif
       xGetInterPredictionError( pcCU, pcYuvOrg, iPUIdx, uiCostCand, m_pcEncCfg->getUseHADME() );
@@ -2631,6 +2734,6 @@
   if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
   {
-	  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
-	  pcYuvOrg->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+    iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
+    pcYuvOrg->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
   }
 #endif
@@ -2755,5 +2858,5 @@
     UInt          uiBitsTempL0[MAX_NUM_REF];
 #if LG_RESTRICTEDRESPRED_M24766
-	Int iPUResiPredShift[4] = {0, 0, 0, 0};
+    Int iPUResiPredShift[4] = {0, 0, 0, 0};
 #endif
     xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
@@ -2773,5 +2876,5 @@
 #endif
 #if LG_RESTRICTEDRESPRED_M24766
-		Bool bLastResiFlag = false;
+      Bool bLastResiFlag = false;
 #endif
     //  Uni-directional prediction
@@ -2783,19 +2886,19 @@
       {
 #if LG_RESTRICTEDRESPRED_M24766
-		  if( pcCU->getResPredFlag( 0 ))
-		  {
-			  if(pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp))
-			  { // subtract residual prediction from original in motion search
-				  if(!bLastResiFlag)
-					  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
-				  bLastResiFlag = true;
-			  }
-			  else
-			  {
-				  if(bLastResiFlag)
-					  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
-				  bLastResiFlag = false;
-			  }
-		  }
+        if( pcCU->getResPredFlag( 0 ))
+        {
+          if(pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp))
+          { // subtract residual prediction from original in motion search
+            if(!bLastResiFlag)
+              pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
+            bLastResiFlag = true;
+          }
+          else
+          {
+            if(bLastResiFlag)
+              pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+            bLastResiFlag = false;
+          }
+        }
 #endif
         uiBitsTemp = uiMbBits[iRefList];
@@ -2963,8 +3066,8 @@
     }
 #if LG_RESTRICTEDRESPRED_M24766
-	if( pcCU->getResPredFlag( 0 ) && bLastResiFlag)
-	{ // subtract residual prediction from original in motion search
-		pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
-	}
+    if( pcCU->getResPredFlag( 0 ) && bLastResiFlag)
+    { // subtract residual prediction from original in motion search
+      pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+    }
 #endif
     //  Bi-directional prediction
@@ -2972,5 +3075,5 @@
     {
 #if LG_RESTRICTEDRESPRED_M24766
-		Int iLastAddResiShift = -1000;
+      Int iLastAddResiShift = -1000;
 #endif
       cMvBi[0] = cMv[0];            cMvBi[1] = cMv[1];
@@ -3077,33 +3180,33 @@
 #endif
 #if LG_RESTRICTEDRESPRED_M24766
-		  Int iAddResiShift = -1, iPredFrom = 0;
-		  Int iBestRefIdx = pcCU->getCUMvField(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0)->getRefIdx(uiPartAddr);
-
-		  iPredFrom = iBestRefIdx >= 0 ? 3 : 1;
-		  if(iBestRefIdx >= 0 && pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0, iBestRefIdx))
-			  iAddResiShift++;
-		  if(pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp))
-			  iAddResiShift++;
-		  iAddResiShift = (pcCU->getSlice()->getPPS()->getUseWP() || iPredFrom != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
-
-		  if( pcCU->getResPredFlag( 0 ) )
-		  {
-			  if(iLastAddResiShift != iAddResiShift)
-			  {
-				  //add substracted residual last time
-				  if(iLastAddResiShift >= 0 )
-				  {
-					  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
-					  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
-				  }
-				  //substract residual
-				  if(iAddResiShift >= 0)
-				  {
-					  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iAddResiShift;
-					  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
-				  }
-				  iLastAddResiShift = iAddResiShift;
-			  }
-		  }
+          Int iAddResiShift = -1, iPredFrom = 0;
+          Int iBestRefIdx = pcCU->getCUMvField(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0)->getRefIdx(uiPartAddr);
+
+          iPredFrom = iBestRefIdx >= 0 ? 3 : 1;
+          if(iBestRefIdx >= 0 && pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0, iBestRefIdx))
+            iAddResiShift++;
+          if(pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp))
+            iAddResiShift++;
+          iAddResiShift = (pcCU->getSlice()->getPPS()->getUseWP() || iPredFrom != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
+
+          if( pcCU->getResPredFlag( 0 ) )
+          {
+            if(iLastAddResiShift != iAddResiShift)
+            {
+              //add substracted residual last time
+              if(iLastAddResiShift >= 0 )
+              {
+                iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
+                pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+              }
+              //substract residual
+              if(iAddResiShift >= 0)
+              {
+                iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iAddResiShift;
+                pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
+              }
+              iLastAddResiShift = iAddResiShift;
+            }
+          }
 #endif
           // call ME
@@ -3162,9 +3265,9 @@
       } // for loop-iter
 #if LG_RESTRICTEDRESPRED_M24766
-	  if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
-	  {
-		  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
-		  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
-	  }
+      if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
+      {
+        iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
+        pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+      }
 #endif
     } // if (B_SLICE)
@@ -3375,19 +3478,19 @@
       {
 #if LG_RESTRICTEDRESPRED_M24766
-		  Int iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
-		  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = \
-			  (pcCU->getSlice()->getPPS()->getUseWP() || pcCU->getInterDir(uiPartAddr) != 3)? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
-		  if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
-		  {
-			  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true);
-		  }
+        Int iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
+        iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = \
+          (pcCU->getSlice()->getPPS()->getUseWP() || pcCU->getInterDir(uiPartAddr) != 3)? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
+        if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
+        {
+          pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true);
+        }
 #endif
         xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiMEError, m_pcEncCfg->getUseHADME() );
         uiMECost = uiMEError + m_pcRdCost->getCost( uiMEBits );
 #if LG_RESTRICTEDRESPRED_M24766
-		if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
-		{
-			pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
-		}
+        if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
+        {
+          pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+        }
 #endif
       }
@@ -3871,9 +3974,5 @@
   else
   {
-#if HHI_FIX
     rcMv = ( m_pcRdCost->useMultiviewReg() ? m_pcRdCost->getMultiviewOrgMvPred() : *pcMvPred );
-#else
-    rcMv = *pcMvPred;
-#endif
     xPatternSearchFast  ( pcCU, pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost );
   }
@@ -3977,5 +4076,4 @@
       uiSad += m_pcRdCost->getCost( x, y );
       
-#if HHI_FIX 
       // regularization cost
       if( m_pcRdCost->useMultiviewReg() )
@@ -3983,5 +4081,4 @@
         uiSad += m_pcRdCost->getMultiviewRegCost( x, y );
       }
-#endif
 
       if ( uiSad < uiSadBest )
@@ -4281,6 +4378,6 @@
     {
 #if LG_RESTRICTEDRESPRED_M24766
-		pcCU->getPUResiPredShift(iPUResiPredShift, 0);
-		rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResPrd, uiWidth, uiHeight );
+      pcCU->getPUResiPredShift(iPUResiPredShift, 0);
+      rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResPrd, uiWidth, uiHeight );
 #else
       rpcYuvRec->add( rpcYuvResPrd, uiWidth, uiHeight );
@@ -4294,5 +4391,5 @@
     {
       uiDistortion = m_pcRdCost->getDistVS( pcCU, 0, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight     , false, 0 );
-	}
+    }
     else    
     {
@@ -4349,7 +4446,12 @@
     pcCU->setTrIdxSubParts( 0, 0, pcCU->getDepth(0) );
     
+
 #if HHI_VSO // necessary? 
     // set Model
+#if SAIT_VSO_EST_A0033
+    if( !m_pcRdCost->getUseEstimatedVSD()&& m_pcRdCost->getUseRenModel() )
+#else
     if( m_pcRdCost->getUseRenModel() )
+#endif
     {
       Pel*  piSrc       = rpcYuvRec->getLumaAddr();
@@ -4395,6 +4497,6 @@
   {
 #if LG_RESTRICTEDRESPRED_M24766
-	  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
-	  rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), pcYuvOrg, pcYuvPred, 0, uiWidth );
+    iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
+    rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), pcYuvOrg, pcYuvPred, 0, uiWidth );
 #else
   rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );
@@ -4405,6 +4507,6 @@
     {
 #if LG_RESTRICTEDRESPRED_M24766
-		pcCU->getPUResiPredShift(iPUResiPredShift, 0);
-		rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResi, rpcYuvResPrd, 0, uiWidth );
+      pcCU->getPUResiPredShift(iPUResiPredShift, 0);
+      rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResi, rpcYuvResPrd, 0, uiWidth );
 #else
       rpcYuvResi->subtract( rpcYuvResi, rpcYuvResPrd, 0, uiWidth );
@@ -4579,7 +4681,11 @@
     }
 
+
 #if HHI_VSO
-    // GT: reset Model, only fordQP necessary??
+#if SAIT_VSO_EST_A0033    
+    if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() )
+#else
     if( m_pcRdCost->getUseRenModel() )
+#endif
     {
       Pel*  piSrc       = pcYuvOrg->getLumaAddr();
@@ -4624,7 +4730,7 @@
     pcYuvPred->copyToPartYuv( rpcYuvRec, 0 );
 #if LG_RESTRICTEDRESPRED_M24766
-	pcCU->getPUResiPredShift(iPUResiPredShift, 0);
-	rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResPrd,   uiWidth, uiHeight );
-	iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
+    pcCU->getPUResiPredShift(iPUResiPredShift, 0);
+    rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResPrd,   uiWidth, uiHeight );
+    iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
     rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResiBest, uiWidth, uiHeight );
 #else
@@ -4685,6 +4791,11 @@
 
   // set Model
+
 #if HHI_VSO // necessary??
+#if SAIT_VSO_EST_A0033    
+  if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() )
+#else
   if( m_pcRdCost->getUseRenModel() )
+#endif
   {
     Pel*  piSrc       = rpcYuvRec->getLumaAddr();
@@ -4693,5 +4804,4 @@
 }
 #endif
-
 }
 
@@ -4869,5 +4979,16 @@
     if ( m_pcRdCost->getUseVSO() )
     {
-      uiDistY = m_pcRdCost->getDistVS  ( pcCU, uiAbsPartIdx, pcPred->getLumaAddr( uiAbsPartIdx ), pcPred->getStride(), pcOrg->getLumaAddr( uiAbsPartIdx), pcOrg->getStride(), 1<< uiLog2TrSize, 1<< uiLog2TrSize, false, 0 ); // initialized with zero residual distortion
+#if SAIT_VSO_EST_A0033
+      if( m_pcRdCost->getUseEstimatedVSD() )
+      {
+        TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
+        TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
+        uiDistY = m_pcRdCost->getDistPart( m_pTempPel, 1<< uiLog2TrSize, pcResi->getLumaAddr( uiAbsPartIdx ), pcResi->getStride(), pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPartIdx), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPartIdx), pcVirRec->getStride(), 1<< uiLog2TrSize, 1<< uiLog2TrSize );
+      }
+      else
+#endif
+      {      
+        uiDistY = m_pcRdCost->getDistVS  ( pcCU, uiAbsPartIdx, pcPred->getLumaAddr( uiAbsPartIdx ), pcPred->getStride(), pcOrg->getLumaAddr( uiAbsPartIdx), pcOrg->getStride(), 1<< uiLog2TrSize, 1<< uiLog2TrSize, false, 0 ); // initialized with zero residual distortion
+      }
     }
     else
@@ -4880,5 +5001,4 @@
 #endif
     }
-
 
     if ( puiZeroDist )
@@ -4909,9 +5029,18 @@
       if ( m_pcRdCost->getUseVSO() )
       {
-        static int iCount = 1; 
-        iCount++; 
-        m_cYuvRecTemp.addClipPartLuma( &m_pcQTTempTComYuv[uiQTTempAccessLayer], pcPred, uiAbsPartIdx, 1<< uiLog2TrSize  );
-        uiNonzeroDistY = m_pcRdCost->getDistVS( pcCU, uiAbsPartIdx, m_cYuvRecTemp.getLumaAddr(uiAbsPartIdx), m_cYuvRecTemp.getStride(),
-                                                pcOrg->getLumaAddr( uiAbsPartIdx ), pcOrg->getStride(), 1<< uiLog2TrSize,   1<< uiLog2TrSize, false, 0 );
+#if SAIT_VSO_EST_A0033
+        if ( m_pcRdCost->getUseEstimatedVSD() )
+        {          
+          TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
+          TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
+          uiNonzeroDistY = m_pcRdCost->getDistPart( m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( uiAbsPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), pcResi->getLumaAddr( uiAbsPartIdx ), pcResi->getStride(), pcVirRec->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiAbsPartIdx ), pcVirOrg->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiAbsPartIdx ), pcVirRec->getStride(), 1<< uiLog2TrSize,    1<< uiLog2TrSize );
+        }
+        else
+#endif
+        {        
+          m_cYuvRecTemp.addClipPartLuma( &m_pcQTTempTComYuv[uiQTTempAccessLayer], pcPred, uiAbsPartIdx, 1<< uiLog2TrSize  );
+          uiNonzeroDistY = m_pcRdCost->getDistVS( pcCU, uiAbsPartIdx, m_cYuvRecTemp.getLumaAddr(uiAbsPartIdx), m_cYuvRecTemp.getStride(),
+                                                  pcOrg->getLumaAddr( uiAbsPartIdx ), pcOrg->getStride(), 1<< uiLog2TrSize,   1<< uiLog2TrSize, false, 0 );
+        }
       }
       else
@@ -5307,6 +5436,11 @@
   }
 
+
 #if HHI_VSO
+#if SAIT_VSO_EST_A0033
+  if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() )
+#else
   if ( m_pcRdCost->getUseRenModel() ) //Only done if not split ( see return above )
+#endif
   {
     UInt  uiWidth     = 1<< uiLog2TrSize;
@@ -5977,6 +6111,20 @@
 
         assignWedgeDCs2Pred( pcWedgelet, piPredic, uiStride, iTestDC1, iTestDC2 );
-
-        Dist uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPredic, uiStride,  piOrig, uiStride, uiWidth, uiHeight, false, 0 );
+        
+        Dist uiActDist = RDO_DIST_MAX;
+#if SAIT_VSO_EST_A0033
+        if ( m_pcRdCost->getUseEstimatedVSD() )
+        {          
+          TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
+          TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
+          uiActDist = m_pcRdCost->getDistPart( piPredic, uiStride, piOrig, uiStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirRec->getStride(), uiWidth, uiHeight );
+        }
+        else       
+#else
+        {        
+          uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPredic, uiStride,  piOrig, uiStride, uiWidth, uiHeight, false, 0 );
+        }
+#endif
+
         if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX )
         {
@@ -6078,5 +6226,16 @@
     if( m_pcRdCost->getUseVSO() )
     {
-      uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false, 0 );
+#if SAIT_VSO_EST_A0033
+      if ( m_pcRdCost->getUseEstimatedVSD() )
+      {          
+        TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
+        TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
+        uiActDist = m_pcRdCost->getDistPart( piPred, uiPredStride, piRef, uiRefStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirRec->getStride(), uiWidth, uiHeight );
+      }
+      else
+#endif
+      {      
+        uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false, 0 );
+      }
     }
     else
@@ -6133,5 +6292,16 @@
     if( m_pcRdCost->getUseVSO() )
     {
-      uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false, 0 );
+#if SAIT_VSO_EST_A0033
+      if ( m_pcRdCost->getUseEstimatedVSD() )
+      {          
+        TComPicYuv* pcVirRec = m_pcRdCost->getVideoRecPicYuv();
+        TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
+        uiActDist = m_pcRdCost->getDistPart( piPred, uiPredStride, piRef, uiRefStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPtIdx), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPtIdx), pcVirRec->getStride(), uiWidth, uiHeight );
+      }
+      else
+#endif
+      {      
+        uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false, 0 );
+      }
     }
     else
@@ -6207,3 +6377,1113 @@
 }
 #endif
+
+#if LGE_EDGE_INTRA
+Bool TEncSearch::xCheckTerminatedEdge( Bool* pbEdge, Int iX, Int iY, Int iWidth, Int iHeight )
+{
+  if( (iY % 2) == 0 ) // vertical edge
+  {
+    Bool bTopConnected = false;
+    Bool bBottomConnected = false;
+
+    if( iY != 0 )
+    {
+      if( pbEdge[ iX + (iY - 2) * 2 * iWidth ] )
+        bTopConnected = true;
+      if( pbEdge[ (iX - 1) + (iY - 1) * 2 * iWidth ] )
+        bTopConnected = true;
+      if( pbEdge[ (iX + 1) + (iY - 1) * 2 * iWidth ] )
+        bTopConnected = true;
+    }
+    else
+    {
+      bTopConnected = true;
+    }
+
+
+    if( iY != 2 * iHeight - 2 )
+    {
+      if( pbEdge[ iX + (iY + 2) * 2 * iWidth ] )
+        bBottomConnected = true;
+      if( pbEdge[ (iX - 1) + (iY + 1) * 2 * iWidth ] )
+        bBottomConnected = true;
+      if( pbEdge[ (iX + 1) + (iY + 1) * 2 * iWidth ] )
+        bBottomConnected = true;
+    }
+    else
+    {
+      bBottomConnected = true;
+    }
+
+
+    if( bTopConnected && bBottomConnected )
+    {
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
+  else
+  {
+    Bool bLeftConnected = false;
+    Bool bRightConnected = false;
+
+    if( iX != 0 )
+    {
+      if( pbEdge[ (iX - 2) + iY * 2 * iWidth ] )
+        bLeftConnected = true;
+      if( pbEdge[ (iX - 1) + (iY - 1) * 2 * iWidth ] )
+        bLeftConnected = true;
+      if( pbEdge[ (iX - 1) + (iY + 1) * 2 * iWidth ] )
+        bLeftConnected = true;
+    }
+    else
+    {
+      bLeftConnected = true;
+    }
+
+    if( iX != 2 * iWidth - 2 )
+    {
+      if( pbEdge[ (iX + 2) + iY * 2 * iWidth ] )
+        bRightConnected = true;
+      if( pbEdge[ (iX + 1) + (iY - 1) * 2 * iWidth ] )
+        bRightConnected = true;
+      if( pbEdge[ (iX + 1) + (iY + 1) * 2 * iWidth ] )
+        bRightConnected = true;
+    }
+    else
+    {
+      bRightConnected = true;
+    }
+
+
+    if( bLeftConnected && bRightConnected )
+    {
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
+}
+
+#if LGE_EDGE_INTRA_PIXEL_DIFFERENCE
+Bool TEncSearch::xEdgePartition( TComDataCU* pcCU, UInt uiPartIdx, Bool bPU4x4 )
+{
+  Pel* pcOrgY   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr());
+  UInt uiStride = pcCU->getPic()->getPicYuvOrg()->getStride();
+  Int iWidth    = pcCU->getWidth(uiPartIdx) >> (bPU4x4 ? 1 : 0);
+  Int iHeight   = pcCU->getHeight(uiPartIdx) >> (bPU4x4 ? 1 : 0);
+  Bool* pbEdge  = (Bool*) xMalloc( Bool, iWidth * iHeight * 4 );
+
+  {
+    UInt uiOffsetX = 0;
+    UInt uiOffsetY = 0;
+    UInt uiAbsPartIdx = pcCU->getZorderIdxInCU() + uiPartIdx;
+
+    uiOffsetX =  (uiAbsPartIdx & 0x1) |
+      ((uiAbsPartIdx & 0x4)  >> 1) |
+      ((uiAbsPartIdx & 0x10) >> 2) |
+      ((uiAbsPartIdx & 0x40) >> 3);
+    uiOffsetY = ((uiAbsPartIdx & 0x2)  >> 1) |
+      ((uiAbsPartIdx & 0x8)  >> 2) |
+      ((uiAbsPartIdx & 0x20) >> 3) |
+      ((uiAbsPartIdx & 0x80) >> 4);
+    uiOffsetX *= 4;
+    uiOffsetY *= 4;
+    pcOrgY += (uiOffsetX + uiOffsetY * uiStride);
+
+  }
+
+  Short* psDiffX = new Short[ iWidth * iHeight ];
+  Short* psDiffY = new Short[ iWidth * iHeight ];
+  Bool*  pbEdgeX = new Bool [ iWidth * iHeight ];
+  Bool*  pbEdgeY = new Bool [ iWidth * iHeight ];
+
+  // Find Horizontal Gradient & Edge Detection ((x+1, y) - (x,y))
+  for( Int y=0; y<iHeight; y++ )
+  {
+    Short* psDiffXPtr = &psDiffX[ y * iHeight ];
+    Bool*  pbEdgeXPtr = &pbEdgeX[ y * iHeight ];
+    for(Int x=0; x<iWidth-1; x++ )
+    {
+      *psDiffXPtr = pcOrgY[ x+1 + y*uiStride ] - pcOrgY[ x + y*uiStride ];
+      if(*psDiffXPtr >= LGE_EDGE_INTRA_THRESHOLD || *psDiffXPtr <= (-1)*LGE_EDGE_INTRA_THRESHOLD)
+      {
+        *pbEdgeXPtr = true;
+      }
+      else
+      {
+        *pbEdgeXPtr = false;
+      }
+
+      psDiffXPtr++;
+      pbEdgeXPtr++;
+    }
+  }
+
+  // Find Vertical Gradient & Edge Detection((x,y+1) - (x,y))
+  for( Int y=0; y<iHeight-1; y++ )
+  {
+    Short* psDiffYPtr = &psDiffY[ y * iHeight ];
+    Bool*  pbEdgeYPtr = &pbEdgeY[ y * iHeight ];
+    for(Int x=0; x<iWidth; x++ )
+    {
+      *psDiffYPtr = pcOrgY[ x + (y+1)*uiStride ] - pcOrgY [ x + y*uiStride ];
+      if(*psDiffYPtr >= LGE_EDGE_INTRA_THRESHOLD || *psDiffYPtr <= (-1)*LGE_EDGE_INTRA_THRESHOLD)
+      {
+        *pbEdgeYPtr = true;
+      }
+      else
+      {
+        *pbEdgeYPtr = false;
+      }
+
+      psDiffYPtr++;
+      pbEdgeYPtr++;
+    }
+  }
+
+  // Eliminate local maximum
+  for( Int y=0; y<iHeight; y++ )
+  {
+    Short* psDiffXPtr = &psDiffX[ y * iHeight ];
+    Bool*  pbEdgeXPtr = &pbEdgeX[ y * iHeight ];
+    for( Int x=0; x<iWidth-1; x++ )
+    {
+      UShort usAbs0=0, usAbs1=0, usAbs2=0;  // 0 : left, 1 : current, 2 : right
+
+      if( x > 0 && *(pbEdgeXPtr-1) == true )
+      {
+        if( *(psDiffXPtr-1) >= 0)
+        {
+          usAbs0 = *(psDiffXPtr-1);
+
+        }
+        else
+        {
+          usAbs0 = (-1) * *(psDiffXPtr-1);
+        }
+      }
+      if( *pbEdgeXPtr == true )
+      {
+        if( *(psDiffXPtr) >= 0)
+        {
+          usAbs1 = *(psDiffXPtr);
+        }
+        else
+        {
+          usAbs1 = (-1) * *(psDiffXPtr);
+        }
+      }
+      if( x < iWidth-2 && *(pbEdgeXPtr+1) == true )
+      {
+        if( *(psDiffXPtr+1) >= 0)
+        {
+          usAbs2 = *(psDiffXPtr+1);
+          //bSign2 = true;
+        }
+        else
+        {
+          usAbs2 = (-1) * *(psDiffXPtr+1);
+        }
+      }
+
+      if( x == 0 )
+      {
+        if( usAbs1 < usAbs2 )
+        {
+          *pbEdgeXPtr = false;
+        }
+      }
+      else if( x == iWidth-2 )
+      {
+        if( usAbs1 <= usAbs0 )
+          *pbEdgeXPtr = false;
+      }
+      else
+      {
+        if( usAbs2 > usAbs0 )
+        {
+          if( usAbs1 < usAbs2 )
+            *pbEdgeXPtr = false;
+        }
+        else
+        {
+          if( usAbs1 <= usAbs0 )
+            *pbEdgeXPtr = false;
+        }
+      }
+
+      psDiffXPtr++;
+      pbEdgeXPtr++;
+    }
+  }
+
+  for( Int y=0; y<iHeight-1; y++ )
+  {
+    Short* psDiffYPtr = &psDiffY[ y * iWidth ];
+    Bool*  pbEdgeYPtr = &pbEdgeY[ y * iWidth ];
+    for( Int x=0; x<iWidth; x++ )
+    {
+      UShort usAbs0=0, usAbs1=0, usAbs2=0;  // 0 : upper, 1 : current, 2 : bottom
+      if( y > 0 && *(pbEdgeYPtr-iWidth) == true )
+      {
+        if( *(psDiffYPtr-iWidth) >= 0)
+        {
+          usAbs0 = *(psDiffYPtr-iWidth);
+        }
+        else
+        {
+          usAbs0 = (-1) * *(psDiffYPtr-iWidth);          
+        }
+      }
+      if( *pbEdgeYPtr == true )
+      {
+        if( *(psDiffYPtr) >= 0)
+        {
+          usAbs1 = *(psDiffYPtr);
+        }
+        else
+        {
+          usAbs1 = (-1) * *(psDiffYPtr);
+        }
+      }
+      if( y < iHeight-2 && *(pbEdgeYPtr+iWidth) == true )
+      {
+        if( *(psDiffYPtr+iWidth) >= 0)
+        {
+          usAbs2 = *(psDiffYPtr+iWidth);          
+        }
+        else
+        {
+          usAbs2 = (-1) * *(psDiffYPtr+iWidth);
+        }
+      }
+
+      if( y == 0 )
+      {
+        if( usAbs1 < usAbs2 )
+          *pbEdgeYPtr = false;
+      }
+      else if( y == iHeight-2 )
+      {
+        if( usAbs1 <= usAbs0 )
+          *pbEdgeYPtr = false;
+      }
+      else
+      {
+        if( usAbs2 > usAbs0 )
+        {
+          if( usAbs1 < usAbs2 )
+            *pbEdgeYPtr = false;
+        }
+        else
+        {
+          if( usAbs1 <= usAbs0 )
+            *pbEdgeYPtr = false;
+        }
+      }
+
+      psDiffYPtr++;
+      pbEdgeYPtr++;
+    }
+  }
+
+  // Edge Merging
+  for( Int i=0; i< 4 * iWidth * iHeight; i++ )
+    pbEdge[ i ] = false;
+  /// Even Line (0,2,4,6,...) => Vertical Edge
+  for( Int i=0; i<iHeight; i++)
+  {
+    for( Int j=0; j<iWidth-1; j++)
+    {
+      pbEdge[ (2 * j + 1) + (2 * i) * 2 * iWidth ] = pbEdgeX[ j + i * iHeight ];
+    }
+  }
+  /// Odd Line (1,3,5,7,...) => Horizontal Edge
+  for( Int i=0; i<iHeight-1; i++)
+  {
+    for( Int j=0; j<iWidth; j++)
+    {
+      pbEdge[ (2 * j) + (2 * i + 1) * 2 * iWidth ] = pbEdgeY[ j + i * iHeight ]; 
+    }
+  }
+
+  // Intersection Filling
+  /// Vertical Edge between Horizontal Edges
+  for( Int i = 1; i < 2 * iHeight - 3; i += 2)
+  {
+    for( Int j = 0; j < 2 * iWidth - 1; j += 2)
+    {
+      if( pbEdge[ j + i * 2 * iWidth ] )
+      {
+        if( j != 0 && pbEdge[ (j - 2) + ((i + 2) * 2 * iWidth) ] )
+        {
+          if( !pbEdge[ (j - 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j - 1) + ((i + 3) * 2 * iWidth) ] )
+            pbEdge[ (j - 1) + ((i + 1) * 2 * iWidth) ] = true;
+        }
+        if( j != 2 * iWidth - 2 && pbEdge[ (j + 2) + ((i + 2) * 2 * iWidth) ] )
+        {
+          if( !pbEdge[ (j + 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j + 1) + ((i + 3) * 2 * iWidth) ] )
+            pbEdge[ (j + 1) + ((i + 1) * 2 * iWidth) ] = true;
+        }
+      }
+    }
+  }
+  /// Horizontal Edge between Vertical Edges
+  for( Int j = 1; j < 2 * iWidth - 3; j += 2)
+  {
+    for( Int i = 0; i < 2 * iHeight - 1; i += 2)
+    {
+      if( pbEdge[ j + i * 2 * iWidth ] )
+      {
+        if( i != 0 && pbEdge[ (j + 2) + ((i - 2) * 2 * iWidth) ] )
+        {
+          if( !pbEdge[ (j - 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j + 3) + ((i - 1) * 2 * iWidth) ] )
+            pbEdge[ (j + 1) + ((i - 1) * 2 * iWidth) ] = true;
+        }
+        if( i != 2 * iHeight - 2 && pbEdge[ (j + 2) + ((i + 2) * 2 * iWidth) ] )
+        {
+          if( !pbEdge[ (j - 1) + ((i + 1) * 2 * iWidth) ] && !pbEdge[ (j + 3) + ((i + 1) * 2 * iWidth) ] )
+            pbEdge[ (j + 1) + ((i + 1) * 2 * iWidth) ] = true;
+        }
+      }
+    }
+  }
+
+  // Static Pruning Unnecessary Edges
+  /// Step1. Stack push the unconnected edges
+  UShort* pusUnconnectedEdgeStack = new UShort[ 4 * iWidth * iHeight ]; // approximate size calculation
+  Int iUnconnectedEdgeStackPtr = 0;
+  //// Vertical Edges
+  for( Int i = 0; i < 2 * iHeight - 1; i += 2 )
+  {
+    for( Int j = 1; j < 2 * iWidth - 2; j += 2 )
+    {
+      if( pbEdge[ j + i * 2 * iWidth ] )
+      {
+        if( !xCheckTerminatedEdge( pbEdge, j, i, iWidth, iHeight ) )
+        {
+          pusUnconnectedEdgeStack[iUnconnectedEdgeStackPtr] = (i << 8) | (j);
+          iUnconnectedEdgeStackPtr++;
+        }
+      }
+    }
+  }
+
+  //// Horizontal Edges
+  for( Int i = 1; i < 2 * iHeight - 2; i += 2 )
+  {
+    for( Int j = 0; j < 2 * iWidth - 1; j += 2 )
+    {
+      if( pbEdge[ j + i * 2 * iWidth ] )
+      {
+        if( !xCheckTerminatedEdge( pbEdge, j, i, iWidth, iHeight ) )
+        {
+          pusUnconnectedEdgeStack[iUnconnectedEdgeStackPtr] = (i << 8) | (j);
+          iUnconnectedEdgeStackPtr++;
+        }
+      }
+    }
+  }
+
+  /// Step2. Remove the edges from the stack and push the new unconnected edges
+  //// (This step may contain duplicated edges already in the stack)
+  //// (But it doesn't cause any functional problems)
+  while( iUnconnectedEdgeStackPtr != 0 )
+  {
+    iUnconnectedEdgeStackPtr--;
+    Int iX = pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] & 0xff;
+    Int iY = pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] >> 8;
+
+    pbEdge[ iX + iY * 2 * iWidth ] = false;
+
+    if( iY % 2 == 1 && iX > 0 && pbEdge[ iX - 2 + iY * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX - 2, iY, iWidth, iHeight ) ) // left
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 0) << 8) | (iX - 2);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iY % 2 == 1 && iX < 2 * iWidth - 2 && pbEdge[ iX + 2 + iY * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX + 2, iY, iWidth, iHeight ) ) // right
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 0) << 8) | (iX + 2);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iY % 2 == 0 && iY > 0 && pbEdge[ iX + (iY - 2) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX, iY - 2, iWidth, iHeight ) ) // top
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 2) << 8) | (iX + 0);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iY % 2 == 0 && iY < 2 * iHeight - 2 && pbEdge[ iX + (iY + 2) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX, iY + 2, iWidth, iHeight ) ) // bottom
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 2) << 8) | (iX + 0);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iX > 0 && iY > 0 && pbEdge[ iX - 1 + (iY - 1) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX - 1, iY - 1, iWidth, iHeight ) ) // left-top
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 1) << 8) | (iX - 1);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iX < 2 * iWidth - 1 && iY > 0 && pbEdge[ iX + 1 + (iY - 1) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX + 1, iY - 1, iWidth, iHeight ) ) // right-top
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 1) << 8) | (iX + 1);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iX > 0 && iY < 2 * iHeight - 1 && pbEdge[ iX - 1 + (iY + 1) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX - 1, iY + 1, iWidth, iHeight ) ) // left-bottom
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 1) << 8) | (iX - 1);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iX < 2 * iWidth - 1 && iY < 2 * iHeight - 1 && pbEdge[ iX + 1 + (iY + 1) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX + 1, iY + 1, iWidth, iHeight ) ) // right-bottom
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 1) << 8) | (iX + 1);
+      iUnconnectedEdgeStackPtr++;
+    }
+  }
+
+
+  // Region Generation ( edge -> region )
+  Bool* pbRegion = pcCU->getEdgePartition( uiPartIdx );
+  Bool* pbVisit  = new Bool[ iWidth * iHeight ];
+
+  for( UInt ui = 0; ui < iWidth * iHeight; ui++ )
+  {
+    pbRegion[ ui ] = true; // fill it as region 1 (we'll discover region 0 next)
+    pbVisit [ ui ] = false;
+  }
+
+  Int* piStack = new Int[ iWidth * iHeight ];
+
+  Int iPtr = 0;
+
+  piStack[iPtr++] = (0 << 8) | (0);
+  pbRegion[ 0 ] = false;
+
+  while(iPtr > 0)
+  {
+    Int iTmp = piStack[--iPtr];
+    Int iX1, iY1;
+    iX1 = iTmp & 0xff;
+    iY1 = (iTmp >> 8) & 0xff;
+
+    pbVisit[ iX1 + iY1 * iWidth ] = true;
+
+    assert( iX1 >= 0 && iX1 < iWidth );
+    assert( iY1 >= 0 && iY1 < iHeight );
+
+    if( iX1 > 0 && !pbEdge[ 2 * iX1 - 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 - 1 + iY1 * iWidth ] )
+    {
+      piStack[iPtr++] = (iY1 << 8) | (iX1 - 1);
+      pbRegion[ iX1 - 1 + iY1 * iWidth ] = false;
+    }
+    if( iX1 < iWidth - 1 && !pbEdge[ 2 * iX1 + 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 + 1 + iY1 * iWidth ] )
+    {
+      piStack[iPtr++] = (iY1 << 8) | (iX1 + 1);
+      pbRegion[ iX1 + 1 + iY1 * iWidth ] = false;
+    }
+    if( iY1 > 0 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 - 1) * iWidth ] && !pbVisit[ iX1 + (iY1 - 1) * iWidth ] )
+    {
+      piStack[iPtr++] = ((iY1 - 1) << 8) | iX1;
+      pbRegion[ iX1 + (iY1 - 1) * iWidth ] = false;
+    }
+    if( iY1 < iHeight - 1 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 + 1) * iWidth ] && !pbVisit[ iX1 + (iY1 + 1) * iWidth ] )
+    {
+      piStack[iPtr++] = ((iY1 + 1) << 8) | iX1;
+      pbRegion[ iX1 + (iY1 + 1) * iWidth ] = false;
+    }
+  }
+
+  ///////////
+  iPtr = 0;
+  for( Int i = 0; i < iWidth * iHeight; i++ )
+    pbVisit[ i ] = false;
+  piStack[ iPtr++ ] = (0 << 8) | (0); // initial seed
+  while( iPtr > 0 && iPtr < iWidth * iHeight )
+  {
+    Int iX;
+    Int iY;
+    iPtr--;
+    iX = piStack[ iPtr ] & 0xff;
+    iY = piStack[ iPtr ] >> 8;
+    pbVisit[ iY * iWidth + iX ] = true;
+
+    if( iY > 0 && !pbVisit[ (iY - 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY - 1) * iWidth + iX ] )
+    {
+      piStack[ iPtr++ ] = ((iY - 1) << 8) | iX;
+    }
+    if( iY < iHeight - 1 && !pbVisit[ (iY + 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY + 1) * iWidth + iX ] )
+    {
+      piStack[ iPtr++ ] = ((iY + 1) << 8) | iX;
+    }
+    if( iX > 0 && !pbVisit[ iY * iWidth + (iX - 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX - 1) ] )
+    {
+      piStack[ iPtr++ ] = (iY << 8) | (iX - 1);
+    }
+    if( iX < iWidth - 1 && !pbVisit[ iY * iWidth + (iX + 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX + 1) ] )
+    {
+      piStack[ iPtr++ ] = (iY << 8) | (iX + 1);
+    }
+  }
+  assert( iPtr == 0 || iPtr == iWidth * iHeight );
+
+  Bool bBipartition;
+  if( iPtr == iWidth * iHeight )
+  {
+    bBipartition = false; // single partition
+  }
+  else
+  {
+    for( Int i = 0; i < iWidth * iHeight; i++ )
+    {
+      if( !pbVisit[ i ] )
+      {
+        piStack[ iPtr++ ] = (( i / iWidth ) << 8) | ( i % iWidth );
+        pbVisit[ i ] = true;
+        break;
+      }
+    }
+    while( iPtr > 0 )
+    {
+      Int iX;
+      Int iY;
+      iPtr--;
+      iX = piStack[ iPtr ] & 0xff;
+      iY = piStack[ iPtr ] >> 8;
+      pbVisit[ iY * iWidth + iX ] = true;
+
+      if( iY > 0 && !pbVisit[ (iY - 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY - 1) * iWidth + iX ] )
+      {
+        piStack[ iPtr++ ] = ((iY - 1) << 8) | iX;
+      }
+      if( iY < iHeight - 1 && !pbVisit[ (iY + 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY + 1) * iWidth + iX ] )
+      {
+        piStack[ iPtr++ ] = ((iY + 1) << 8) | iX;
+      }
+      if( iX > 0 && !pbVisit[ iY * iWidth + (iX - 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX - 1) ] )
+      {
+        piStack[ iPtr++ ] = (iY << 8) | (iX - 1);
+      }
+      if( iX < iWidth - 1 && !pbVisit[ iY * iWidth + (iX + 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX + 1) ] )
+      {
+        piStack[ iPtr++ ] = (iY << 8) | (iX + 1);
+      }
+    }
+    bBipartition = true;
+    for( Int i = 0; i < iWidth * iHeight; i++ )
+    {
+      if( !pbVisit[ i ] )
+      {
+        bBipartition = false;
+        break;
+      }
+    }
+  }
+
+  xFree( pbEdge );
+  delete[] pbEdgeX; pbEdgeX = NULL;
+  delete[] pbEdgeY; pbEdgeY = NULL;
+  delete[] psDiffX; psDiffX = NULL;
+  delete[] psDiffY; psDiffY = NULL;
+  delete[] pusUnconnectedEdgeStack; pusUnconnectedEdgeStack = NULL;
+  delete[] pbVisit; pbVisit = NULL;
+  delete[] piStack; piStack = NULL;
+
+  Bool bCheckPossibleChain;
+
+  if( bBipartition )
+    bCheckPossibleChain = xConstructChainCode( pcCU, uiPartIdx, bPU4x4 );
+  else
+    bCheckPossibleChain = false;
+
+  return bCheckPossibleChain;
+}
+
+#endif
+
+Bool TEncSearch::xConstructChainCode( TComDataCU* pcCU, UInt uiPartIdx, Bool bPU4x4 )
+{
+  UInt   uiWidth    = pcCU->getWidth( uiPartIdx ) >> (bPU4x4 ? 1 : 0);
+  UInt   uiHeight   = pcCU->getHeight( uiPartIdx ) >> (bPU4x4 ? 1 : 0);
+  Bool*  pbEdge     = (Bool*) xMalloc( Bool, uiWidth * uiHeight * 4 );
+  Bool*  pbVisit    = (Bool*) xMalloc( Bool, uiWidth * uiHeight * 4 );
+  UInt   uiMaxEdge  = uiWidth * (LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 / 4);
+  Bool*  pbRegion   = pcCU->getEdgePartition( uiPartIdx );
+  UChar* piEdgeCode = pcCU->getEdgeCode( uiPartIdx );
+  Bool   bStartLeft = false;
+  Bool   bPossible  = false;
+  Bool   bFinish    = false;
+  Int    iStartPosition = -1;
+  Int    iPtr = 0;
+  Int    iDir = -1, iNextDir = -1;
+  Int    iArrow = -1, iNextArrow = -1;
+  Int    iX = -1, iY = -1;
+  Int    iDiffX = 0, iDiffY = 0;
+  UChar  iCode = 255;
+  UInt   uiWidth2 = uiWidth * 2;
+
+  for( Int i = 0; i < uiWidth * uiHeight * 4; i++ )
+    pbEdge[ i ] = false;
+
+  for( Int i = 0; i < uiHeight; i++ )
+  {
+    for( Int j = 0; j < uiWidth - 1; j++ )
+    {
+      if( pbRegion[ i * uiWidth + j ] != pbRegion[ i * uiWidth + j + 1 ] )
+        pbEdge[ i * uiWidth * 4 + j * 2 + 1 ] = true;
+    }
+  }
+
+  for( Int i = 0; i < uiHeight - 1; i++ )
+  {
+    for( Int j = 0; j < uiWidth; j++ )
+    {
+      if( pbRegion[ (i + 0) * uiWidth + j ] != pbRegion[ (i + 1) * uiWidth + j ] )
+        pbEdge[ (2 * i + 1) * 2 * uiWidth + j * 2 ] = true;
+    }
+  }
+
+  for( Int i = 1; i < uiWidth2 - 2; i+=2 )
+  {
+    if(pbEdge[ i ])
+    {
+      bPossible  = true;
+      bStartLeft = false;
+      iStartPosition = iX = i;
+      iY = 0;
+      iDir = 3;
+      iArrow = 3;
+      break;
+    }
+  }
+
+  if( !bPossible )
+  {
+    for( Int i = 1; i < uiWidth2 - 2; i+=2 )
+    {
+      if(pbEdge[ i * uiWidth2 ])
+      {
+        bPossible  = true;
+        bStartLeft = true;
+        iX = 0;
+        iStartPosition = iY = i;
+        iDir = 1;
+        iArrow = 1;
+        break;
+      }
+    }
+  }
+
+  if( bPossible )
+  {
+    for( Int i = 0; i < 4 * uiWidth * uiHeight; i++ )
+      pbVisit[ i ] = false;
+
+    while( !bFinish )
+    {
+      Bool bArrowSkip = false;
+      pbVisit[ iX + iY * uiWidth2 ] = true;
+
+      switch( iDir )
+      {
+      case 0: // left
+        if( iX > 0 && !pbVisit[ (iX - 2) + iY * uiWidth2 ] && pbEdge[ (iX - 2) + iY * uiWidth2 ] ) // left
+        {
+          iDiffX = -2;
+          iDiffY =  0;
+          iNextDir = 0;
+          iNextArrow = 0;
+        }
+        else if( iX > 0 && !pbVisit[ (iX - 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY - 1) * uiWidth2 ] ) // top
+        {
+          iDiffX = -1;
+          iDiffY = -1;
+          iNextDir = 2;
+          iNextArrow = 4;
+        }
+        else if( iX > 0 && !pbVisit[ (iX - 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY + 1) * uiWidth2 ] ) // bottom
+        {
+          iDiffX = -1;
+          iDiffY = +1;
+          iNextDir = 3;
+          iNextArrow = iArrow;
+          if( !(iPtr == 0 && iX == uiWidth2 - 2 && iY == uiHeight * 2 - 3) )
+            bArrowSkip = true;
+          else
+            iNextArrow = 3;
+        }
+        else if( iX == 0 )
+        {
+          iDiffX = 0;
+          iDiffY = 0;
+          iNextDir = iDir;
+          iNextArrow = iArrow;
+          bFinish = true;
+          continue;
+        }
+        else
+        {
+          iPtr = 0; // edge loop or unwanted case
+          bFinish = true;
+          //continue;
+          assert(false);
+        }
+        break;
+      case 1: // right
+        if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 2) + iY * uiWidth2 ] && pbEdge[ (iX + 2) + iY * uiWidth2 ] ) // right
+        {
+          iDiffX = +2;
+          iDiffY =  0;
+          iNextDir = 1;
+          iNextArrow = 1;
+        }
+        else if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY - 1) * uiWidth2 ] ) // top
+        {
+          iDiffX = +1;
+          iDiffY = -1;
+          iNextDir = 2;
+          iNextArrow = iArrow;
+          if( !(iPtr == 0 && iX == 0 && iY == 1) )
+            bArrowSkip = true;
+          else
+            iNextArrow = 2;
+        }
+        else if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY + 1) * uiWidth2 ] ) // bottom
+        {
+          iDiffX = +1;
+          iDiffY = +1;
+          iNextDir = 3;
+          iNextArrow = 7;
+        }
+        else if( iX == uiWidth2 - 2 )
+        {
+          iDiffX = 0;
+          iDiffY = 0;
+          iNextDir = iDir;
+          iNextArrow = iArrow;
+          bFinish = true;
+          continue;
+        }
+        else
+        {
+          iPtr = 0; // edge loop or unwanted case
+          bFinish = true;
+          //continue;
+          assert(false);
+        }
+        break;
+      case 2: // top
+        if( iY > 0 && !pbVisit[ (iX - 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY - 1) * uiWidth2 ] ) // left
+        {
+          iDiffX = -1;
+          iDiffY = -1;
+          iNextDir = 0;
+          iNextArrow = iArrow;
+          if( !(iPtr == 0 && iX == 1 && iY == uiHeight * 2 - 2) )
+            bArrowSkip = true;
+          else
+            iNextArrow = 0;
+        }
+        else if( iY > 0 && !pbVisit[ (iX + 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY - 1) * uiWidth2 ] ) // right
+        {
+          iDiffX = +1;
+          iDiffY = -1;
+          iNextDir = 1;
+          iNextArrow = 5;
+        }
+        else if( iY > 0 && !pbVisit[ iX + (iY - 2) * uiWidth2 ] && pbEdge[ iX + (iY - 2) * uiWidth2 ] ) // top
+        {
+          iDiffX =  0;
+          iDiffY = -2;
+          iNextDir = 2;
+          iNextArrow = 2;
+        }
+        else if( iY == 0 )
+        {
+          iDiffX = 0;
+          iDiffY = 0;
+          iNextDir = iDir;
+          iNextArrow = iArrow;
+          bFinish = true;
+          continue;
+        }
+        else
+        {
+          iPtr = 0; // edge loop or unwanted case
+          bFinish = true;
+          //continue;
+          assert(false);
+        }
+        break;
+      case 3: // bottom
+        if( iY < uiWidth2 - 2 && !pbVisit[ (iX - 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY + 1) * uiWidth2 ] ) // left
+        {
+          iDiffX = -1;
+          iDiffY = +1;
+          iNextDir = 0;
+          iNextArrow = 6;
+        }
+        else if( iY < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY + 1) * uiWidth2 ] ) // right
+        {
+          iDiffX = +1;
+          iDiffY = +1;
+          iNextDir = 1;
+          iNextArrow = iArrow;
+          if( !(iPtr == 0 && iX == uiWidth * 2 - 3 && iY == 0) )
+            bArrowSkip = true;
+          else
+            iNextArrow = 1;
+        }
+        else if( iY < uiWidth2 - 2 && !pbVisit[ iX + (iY + 2) * uiWidth2 ] && pbEdge[ iX + (iY + 2) * uiWidth2 ] ) // bottom
+        {
+          iDiffX =  0;
+          iDiffY = +2;
+          iNextDir = 3;
+          iNextArrow = 3;
+        }
+        else if( iY == uiWidth2 - 2 )
+        {
+          iDiffX = 0;
+          iDiffY = 0;
+          iNextDir = iDir;
+          iNextArrow = iArrow;
+          bFinish = true;
+          continue;
+        }
+        else
+        {
+          iPtr = 0; // edge loop or unwanted case
+          bFinish = true;
+          //continue;
+          assert(false);
+        }
+        break;
+      }
+
+      const UChar tableCode[8][8] = { { 0, -1, 4, 3, 2, 6, 1, 5 }, // iArrow(current direction), iNextArrow(next direction)
+      { -1, 0, 3, 4, 5, 1, 6, 2 },
+      { 3, 4, 0, -1, 1, 2, 5, 6 },
+      { 4, 3, -1, 0, 6, 5, 2, 1 },
+      { 1, 6, 2, 5, 0, 4, 3, -1 },
+      { 5, 2, 1, 6, 3, 0, -1, 4 },
+      { 2, 5, 6, 1, 4, -1, 0, 3 },
+      { 6, 1, 5, 2, -1, 3, 4, 0 } };
+
+      iCode = tableCode[iArrow][iNextArrow];
+
+      if(iPtr >= uiMaxEdge)
+      {
+        iPtr = 0; // over the maximum number of edge
+        bPossible = false;
+        break;
+      }
+
+      if( !bArrowSkip )
+      {
+        piEdgeCode[iPtr++] = iCode; // first edge coding
+        //printf("xEdgeCoding: (%d,%d)->(%d,%d) code %d\n",iX,iY, iX+iDiffX, iY+iDiffY, iCode);
+      }
+
+      iX += iDiffX;
+      iY += iDiffY;
+      iDir = iNextDir;
+      iArrow = iNextArrow;
+    }
+  }
+
+  pcCU->setEdgeLeftFirst( uiPartIdx, bStartLeft );
+  pcCU->setEdgeStartPos ( uiPartIdx, bStartLeft ? (iStartPosition - 1) >> 1 : (iStartPosition + 1) >> 1);
+  pcCU->setEdgeNumber   ( uiPartIdx, iPtr );
+
+  xFree( pbEdge );
+  xFree( pbVisit );
+
+  return (iPtr != 0);
+}
+
+#if LGE_EDGE_INTRA_DELTA_DC
+Void TEncSearch::xAssignEdgeIntraDeltaDCs( TComDataCU*   pcCU,
+                                          UInt          uiAbsPartIdx,
+                                          Pel*          piOrig,
+                                          UInt          uiStride,
+                                          Pel*          piPredic,
+                                          UInt          uiWidth,
+                                          UInt          uiHeight )
+{
+  Int iDC0 = 0;
+  Int iDC1 = 0;
+  Int iPredDC0 = 0;
+  Int iPredDC1 = 0;
+  Int iDeltaDC0 = 0;
+  Int iDeltaDC1 = 0;
+
+  Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx );
+
+  Int* piMask = pcCU->getPattern()->getAdiOrgBuf( uiWidth, uiHeight, m_piYuvExt );
+  Int iMaskStride = ( uiWidth<<1 ) + 1;
+
+  // DC Calculation
+  {
+    UInt uiSum0 = 0;
+    UInt uiSum1 = 0;
+    UInt uiCount0 = 0;
+    UInt uiCount1 = 0;
+
+    Pel* piTemp = piOrig;
+    for( UInt ui = 0; ui < uiHeight; ui++ )
+    {
+      for( UInt uii = 0; uii < uiWidth; uii++ )
+      {
+        if( pbRegion[ ui * uiWidth + uii ] == false )
+        {
+          uiSum0 += (piTemp[ uii ]);
+          uiCount0++;
+        }
+        else
+        {
+          uiSum1 += (piTemp[ uii ]);
+          uiCount1++;
+        }
+      }
+      piTemp += uiStride;
+    }
+    if( uiCount0 == 0 )
+      assert(false);
+    if( uiCount1 == 0 )
+      assert(false);
+    iDC0 = uiSum0 / uiCount0; // TODO : integer op.
+    iDC1 = uiSum1 / uiCount1;
+  }
+
+  // PredDC Calculation
+  {
+    UInt uiSum0 = 0;
+    UInt uiSum1 = 0;
+    UInt uiCount0 = 0;
+    UInt uiCount1 = 0;
+
+    for( UInt ui = 0; ui < uiWidth; ui++ )
+    {
+      if( pbRegion[ ui ] == false )
+      {
+        uiSum0 += (piMask[ ui + 1 ]);
+        uiCount0++;
+      }
+      else
+      {
+        uiSum1 += (piMask[ ui + 1 ]);
+        uiCount1++;
+      }
+    }
+    for( UInt ui = 0; ui < uiHeight; ui++ ) // (0,0) recount (to avoid division)
+    {
+      if( pbRegion[ ui * uiWidth ] == false )
+      {
+        uiSum0 += (piMask[ (ui + 1) * iMaskStride ]);
+        uiCount0++;
+      }
+      else
+      {
+        uiSum1 += (piMask[ (ui + 1) * iMaskStride ]);
+        uiCount1++;
+      }
+    }
+    if( uiCount0 == 0 )
+      assert(false);
+    if( uiCount1 == 0 )
+      assert(false);
+    iPredDC0 = uiSum0 / uiCount0; // TODO : integer op.
+    iPredDC1 = uiSum1 / uiCount1;
+  }
+
+  iDeltaDC0 = iDC0 - iPredDC0;
+  iDeltaDC1 = iDC1 - iPredDC1;
+
+#if HHI_VSO
+  if( m_pcRdCost->getUseVSO() )
+  {
+    Int iFullDeltaDC0 = iDeltaDC0;
+    Int iFullDeltaDC1 = iDeltaDC1;
+
+    xDeltaDCQuantScaleDown( pcCU, iFullDeltaDC0 );
+    xDeltaDCQuantScaleDown( pcCU, iFullDeltaDC1 );
+
+    Dist  uiBestDist     = RDO_DIST_MAX;
+    UInt  uiBestQStepDC0 = 0;
+    UInt  uiBestQStepDC1 = 0;
+
+    UInt uiDeltaDC0Max = abs(iFullDeltaDC0);
+    UInt uiDeltaDC1Max = abs(iFullDeltaDC1);
+
+    //VSO Level delta DC check range extension
+    uiDeltaDC0Max += (uiDeltaDC0Max>>1);
+    uiDeltaDC1Max += (uiDeltaDC1Max>>1);
+
+    for( UInt uiQStepDC0 = 1; uiQStepDC0 <= uiDeltaDC0Max; uiQStepDC0++  )
+    {
+      Int iLevelDeltaDC0 = (Int)(uiQStepDC0) * (Int)(( iFullDeltaDC0 < 0 ) ? -1 : 1);
+      xDeltaDCQuantScaleUp( pcCU, iLevelDeltaDC0 );
+
+      Int iTestDC0 = Clip( iPredDC0 + iLevelDeltaDC0 );
+      for( UInt uiQStepDC1 = 1; uiQStepDC1 <= uiDeltaDC1Max; uiQStepDC1++  )
+      {
+        Int iLevelDeltaDC1 = (Int)(uiQStepDC1) * (Int)(( iFullDeltaDC1 < 0 ) ? -1 : 1);
+        xDeltaDCQuantScaleUp( pcCU, iLevelDeltaDC1 );
+
+        Int iTestDC1 = Clip( iPredDC1 + iLevelDeltaDC1 );
+
+        Pel* piTemp = piPredic;
+        for( UInt ui = 0; ui < uiHeight; ui++ )
+        {
+          for( UInt uii = 0; uii < uiWidth; uii++ )
+          {
+            if( pbRegion[ ui * uiWidth + uii ] == false )
+            {
+              piTemp[ uii ] = iTestDC0;
+            }
+            else
+            {
+              piTemp[ uii ] = iTestDC1;
+            }
+          }
+          piTemp += uiStride;
+        }
+
+        Dist uiActDist = m_pcRdCost->getDistVS( pcCU, 0, piPredic, uiStride,  piOrig, uiStride, uiWidth, uiHeight, false, 0 );
+        if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX )
+        {
+          uiBestDist     = uiActDist;
+          uiBestQStepDC0 = uiQStepDC0;
+          uiBestQStepDC1 = uiQStepDC1;
+        }
+      }
+    }
+
+    iFullDeltaDC0 = (Int)(uiBestQStepDC0) * (Int)(( iFullDeltaDC0 < 0 ) ? -1 : 1);
+    iFullDeltaDC1 = (Int)(uiBestQStepDC1) * (Int)(( iFullDeltaDC1 < 0 ) ? -1 : 1);
+    xDeltaDCQuantScaleUp( pcCU, iFullDeltaDC0 );
+    xDeltaDCQuantScaleUp( pcCU, iFullDeltaDC1 );
+    iDeltaDC0 = iFullDeltaDC0;
+    iDeltaDC1 = iFullDeltaDC1;
+  }
+#endif
+
+  xDeltaDCQuantScaleDown( pcCU, iDeltaDC0 );
+  xDeltaDCQuantScaleDown( pcCU, iDeltaDC1 );
+
+  pcCU->setEdgeDeltaDC0( uiAbsPartIdx, iDeltaDC0 );
+  pcCU->setEdgeDeltaDC1( uiAbsPartIdx, iDeltaDC1 );
+}
+#endif
+#endif
+
 //! \}
Index: trunk/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 100)
@@ -189,5 +189,5 @@
                                   TComYuv*    pcOrgYuv,
 #if LG_RESTRICTEDRESPRED_M24766
-								  TComYuv*     rpcResiPredYuv,
+                                  TComYuv*    rpcResiPredYuv,
 #endif
                                   TComYuv*&   rpcPredYuv,
@@ -259,5 +259,9 @@
                                     TComYuv*     pcPredYuv, 
                                     TComYuv*     pcResiYuv, 
-                                    Dist&        ruiDist );
+                                    Dist&        ruiDist 
+#if LG_ZEROINTRADEPTHRESI_M26039
+                                   ,Bool        bZeroResi = false
+#endif
+                                   );
   Void  xIntraCodingChromaBlk     ( TComDataCU*  pcCU,
                                     UInt         uiTrDepth,
@@ -278,7 +282,11 @@
                                     Dist&        ruiDistC,
 #if HHI_RQT_INTRA_SPEEDUP
-                                   Bool         bCheckFirst,
-#endif
-                                   Double&      dRDCost );
+                                    Bool         bCheckFirst,
+#endif
+                                    Double&      dRDCost 
+#if LG_ZEROINTRADEPTHRESI_M26039
+                                   ,Bool         bZeroResi = false
+#endif
+                                  );
   
   Void  xSetIntraResultQT         ( TComDataCU*  pcCU,
@@ -321,4 +329,14 @@
                                     Bool           bLeftAvail );
 #endif
+
+#if LGE_EDGE_INTRA
+  Bool  xEdgePartition       ( TComDataCU* pcCU, UInt uiPartIdx, Bool bPU4x4 );
+  Bool  xCheckTerminatedEdge ( Bool* pbEdge, Int iX, Int iY, Int iWidth, Int iHeight );
+  Bool  xConstructChainCode  ( TComDataCU* pcCU, UInt uiPartIdx, Bool bPU4x4 );
+#if LGE_EDGE_INTRA_DELTA_DC
+  Void  xAssignEdgeIntraDeltaDCs( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piOrig, UInt uiStride, Pel* piPredic, UInt uiWidth, UInt uiHeight );
+#endif
+#endif
+
 #if HHI_DMM_WEDGE_INTRA
   Void findWedgeFullMinDist       ( TComDataCU*    pcCU, 
@@ -444,5 +462,5 @@
                                     TComYuv*        pcYuvOrg,
 #if LG_RESTRICTEDRESPRED_M24766
-									TComYuv*        rpcResiPredYuv, 
+                                    TComYuv*        rpcResiPredYuv, 
 #endif
                                     Int             iPartIdx,
Index: trunk/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 100)
@@ -38,5 +38,11 @@
 #include "TEncTop.h"
 #include "TEncSlice.h"
+#if HHI_VSO_SPEEDUP_A033
+#include "../../App/TAppEncoder/TAppEncTop.h"
+#endif
 #include <math.h>
+#if SAIT_VSO_EST_A0033
+extern Double g_dDispCoeff;
+#endif
 
 //! \ingroup TLibEncoder
@@ -627,4 +633,7 @@
   TComSlice* pcSlice            = rpcPic->getSlice(getSliceIdx());
   xDetermineStartAndBoundingCUAddr ( uiStartCUAddr, uiBoundingCUAddr, rpcPic, false );
+#if LG_ZEROINTRADEPTHRESI_M26039
+  rpcPic->setIntraPeriod(this->m_pcCfg->getIntraPeriod());
+#endif
   
   // initialize cost values
@@ -702,4 +711,29 @@
   m_pcEntropyCoder->setMaxAlfCtrlDepth(0); //unnecessary
   
+#if SAIT_VSO_EST_A0033
+ if( m_pcCfg->getUseVSO() )
+ {
+   m_pcRdCost->setDisparityCoeff( g_dDispCoeff );  // Temp. code!!!
+   //printf( "Disp Coeff : %3.4f \n", m_pcRdCost->getDisparityCoeff() );
+
+   Int frameWidth = m_pcCfg->getSourceWidth();
+   Pel* pVideoRec = m_pcRdCost->getVideoRecPicYuv()->getLumaAddr();
+   Int iVideoRecStride = m_pcRdCost->getVideoRecPicYuv()->getStride();
+
+   Pel* pDepthOrg = m_pcRdCost->getDepthPicYuv()->getLumaAddr();
+   Int iDepthOrgStride = m_pcRdCost->getDepthPicYuv()->getStride();
+
+   for( Int y = 0 ; y < m_pcCfg->getSourceHeight() ; y++ )
+   {
+     pVideoRec[-4] = pVideoRec[-3] = pVideoRec[-2] = pVideoRec[-1] = pVideoRec[0];
+     pVideoRec[frameWidth+3] = pVideoRec[frameWidth+2] = pVideoRec[frameWidth+1] = pVideoRec[frameWidth] = pVideoRec[frameWidth-1];
+     pDepthOrg[-4] = pDepthOrg[-3] = pDepthOrg[-2] = pDepthOrg[-1] = pDepthOrg[0];
+     pDepthOrg[frameWidth+3] = pDepthOrg[frameWidth+2] = pDepthOrg[frameWidth+1] = pDepthOrg[frameWidth] = pDepthOrg[frameWidth-1];
+
+     pVideoRec += iVideoRecStride;
+     pDepthOrg += iDepthOrgStride;
+   }
+ }
+#endif
   TEncTop* pcEncTop = (TEncTop*) m_pcCfg;
   TEncSbac**** ppppcRDSbacCoders    = pcEncTop->getRDSbacCoders();
@@ -753,4 +787,8 @@
   UInt uiTileLCUX     = 0;
 
+#if HHI_VSO_SPEEDUP_A033
+  Int iLastPosY = -1;
+#endif
+
   // for every CU in slice
   UInt uiEncCUOrder;
@@ -763,4 +801,21 @@
     TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
     pcCU->initCU( rpcPic, uiCUAddr );
+
+#if HHI_VSO_SPEEDUP_A033
+    if ( m_pcRdCost->getUseRenModel() )
+    {
+      // updated renderer model if necessary
+      Int iCurPosX;
+      Int iCurPosY; 
+      pcCU->getPosInPic(0, iCurPosX, iCurPosY );
+      if ( iCurPosY != iLastPosY )
+      {
+        iLastPosY = iCurPosY; 
+        
+        m_pcGOPEncoder->getEncTop()->getEncTop()->setupRenModel( rpcPic->getCurrSlice()->getPOC() , rpcPic->getCurrSlice()->getSPS()->getViewId(), rpcPic->getCurrSlice()->getSPS()->isDepth() ? 1 : 0, iCurPosY );
+      }
+    }    
+#endif
+
 
     // inherit from TR if necessary, select substream to use.
Index: trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 81)
+++ trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 100)
@@ -597,4 +597,7 @@
   // mark it should be extended
   rpcPic->getPicYuvRec()->setBorderExtension(false);
+#if FIXES
+  rpcPic->getPicYuvOrg()->setBorderExtension(false); 
+#endif
 }
 
@@ -981,9 +984,5 @@
 Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid,TComList<TComPic*>& listPic )
 {
-#if HHI_FIX
   if( slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV && POCCurr == 0 )
-#else
-  if( slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV )
-#endif
   {
     TComReferencePictureSet* rps = slice->getLocalRPS();
