Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/ContextTables.h
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/ContextTables.h	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/ContextTables.h	(revision 97)
@@ -152,4 +152,11 @@
 #endif
 
+#if LGE_EDGE_INTRA
+#define NUM_EDGE_INTRA_CTX            1
+#if LGE_EDGE_INTRA_DELTA_DC
+#define NUM_EDGE_INTRA_DELTA_DC_CTX   2 // one for Delta_DC flag, another for Delta_DC value
+#endif
+#endif
+
 // ====================================================================================================================
 // Tables
@@ -1272,9 +1279,41 @@
   }
 };
+
+#if LGE_EDGE_INTRA
+static const Short
+INIT_EDGE_INTRA[3][NUM_EDGE_INTRA_CTX] =
+{
+	{
+		CNU
+	},
+	{
+		CNU
+		},
+		{
+			CNU
+		}
+};
+
+#if LGE_EDGE_INTRA_DELTA_DC
+static const Short
+INIT_EDGE_INTRA_DELTA_DC[3][NUM_EDGE_INTRA_DELTA_DC_CTX] =
+{
+	{
+		CNU, CNU
+	},
+	{
+		CNU, CNU
+		},
+		{
+			CNU, CNU
+		}
+};
+#endif
+#endif
+
 #endif
 
 //! \}
 
-
-#endif
-
+#endif
+
Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDataCU.cpp	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDataCU.cpp	(revision 97)
@@ -141,4 +141,15 @@
   m_pbResPredFlag      = NULL;
 #endif
+#if LGE_EDGE_INTRA
+  m_pucEdgeCode         = NULL;
+  m_pucEdgeNumber       = NULL;
+  m_pucEdgeStartPos     = NULL;
+  m_pbEdgeLeftFirst     = NULL;
+  m_pbEdgePartition     = NULL;
+#if LGE_EDGE_INTRA_DELTA_DC
+  m_piEdgeDeltaDC0      = NULL;
+  m_piEdgeDeltaDC1      = NULL;
+#endif
+#endif
 }
 
@@ -259,4 +270,15 @@
     m_piContourPredTexDeltaDC2 = (Int* )xMalloc(Int,  uiNumPartition);
 #endif
+#if LGE_EDGE_INTRA
+	m_pucEdgeCode       = (UChar*)xMalloc(UChar, uiNumPartition * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4);
+	m_pucEdgeNumber     = (UChar*)xMalloc(UChar, uiNumPartition);
+	m_pucEdgeStartPos   = (UChar*)xMalloc(UChar, uiNumPartition);
+	m_pbEdgeLeftFirst   = (Bool*) xMalloc(Bool,  uiNumPartition);
+	m_pbEdgePartition   = (Bool*) xMalloc(Bool,  uiNumPartition * 16);
+#if LGE_EDGE_INTRA_DELTA_DC
+	m_piEdgeDeltaDC0    = (Int* ) xMalloc(Int,   uiNumPartition);
+	m_piEdgeDeltaDC1    = (Int* ) xMalloc(Int,   uiNumPartition);
+#endif
+#endif
   }
   else
@@ -359,4 +381,15 @@
     if ( m_piContourPredTexDeltaDC2 ) { xFree(m_piContourPredTexDeltaDC2); m_piContourPredTexDeltaDC2 = NULL; }
 #endif    
+#if LGE_EDGE_INTRA
+	if ( m_pbEdgeLeftFirst  ) { xFree(m_pbEdgeLeftFirst);   m_pbEdgeLeftFirst = NULL; }
+	if ( m_pucEdgeStartPos  ) { xFree(m_pucEdgeStartPos);   m_pucEdgeStartPos = NULL; }
+	if ( m_pucEdgeNumber    ) { xFree(m_pucEdgeNumber);     m_pucEdgeNumber   = NULL; }
+	if ( m_pucEdgeCode      ) { xFree(m_pucEdgeCode);       m_pucEdgeCode     = NULL; }
+	if ( m_pbEdgePartition    ) { xFree(m_pbEdgePartition); m_pbEdgePartition = NULL; }
+#if LGE_EDGE_INTRA_DELTA_DC
+	if ( m_piEdgeDeltaDC0     ) { xFree(m_piEdgeDeltaDC0);  m_piEdgeDeltaDC0  = NULL; }
+	if ( m_piEdgeDeltaDC1     ) { xFree(m_piEdgeDeltaDC1);  m_piEdgeDeltaDC1  = NULL; }
+#endif
+#endif
     m_acCUMvField[0].destroy();
     m_acCUMvField[1].destroy();
@@ -1093,4 +1126,18 @@
   m_piContourPredTexDeltaDC2 = pcCU->getContourPredTexDeltaDC2() + uiPart;   
 #endif
+#if LGE_EDGE_INTRA
+  if( pcCU->getSlice()->getSPS()->isDepth() )
+  {
+	  m_pucEdgeCode         = pcCU->getEdgeCode( uiPart );
+	  m_pucEdgeNumber       = pcCU->getEdgeNumber() + uiPart;
+	  m_pucEdgeStartPos     = pcCU->getEdgeStartPos() + uiPart;
+	  m_pbEdgeLeftFirst     = pcCU->getEdgeLeftFirst() + uiPart;
+	  m_pbEdgePartition     = pcCU->getEdgePartition( uiPart );
+#if LGE_EDGE_INTRA_DELTA_DC
+	  m_piEdgeDeltaDC0      = pcCU->getEdgeDeltaDC0() + uiPart;
+	  m_piEdgeDeltaDC1      = pcCU->getEdgeDeltaDC1() + uiPart;
+#endif
+  }
+#endif
 }
 
@@ -1250,4 +1297,20 @@
   memcpy( m_piContourPredTexDeltaDC2 + uiOffset, pcCU->getContourPredTexDeltaDC2(), sizeof( Int  ) * uiNumPartition );
 #endif
+
+#if LGE_EDGE_INTRA
+  if( getSlice()->getSPS()->isDepth() )
+  {
+	  memcpy( getEdgeCode( uiOffset ), pcCU->getEdgeCode(0), iSizeInUchar * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
+	  memcpy( getEdgeNumber() + uiOffset, pcCU->getEdgeNumber(), iSizeInUchar );
+	  memcpy( getEdgeStartPos() + uiOffset, pcCU->getEdgeStartPos(), iSizeInUchar );
+	  memcpy( getEdgeLeftFirst() + uiOffset, pcCU->getEdgeLeftFirst(), iSizeInBool );
+	  memcpy( getEdgePartition( uiOffset ), pcCU->getEdgePartition(0), iSizeInBool * 16 );
+#if LGE_EDGE_INTRA_DELTA_DC
+	  memcpy( getEdgeDeltaDC0() + uiOffset, pcCU->getEdgeDeltaDC0(), sizeof( Int  ) * uiNumPartition );
+	  memcpy( getEdgeDeltaDC1() + uiOffset, pcCU->getEdgeDeltaDC1(), sizeof( Int  ) * uiNumPartition );
+#endif
+  }
+#endif
+
 #if HHI_MPI
   memcpy( m_piTextureModeDepth + uiOffset, pcCU->getTextureModeDepth(), sizeof( Int ) * uiNumPartition );
@@ -1352,4 +1415,20 @@
   memcpy( rpcCU->getContourPredTexDeltaDC2() + m_uiAbsIdxInLCU, m_piContourPredTexDeltaDC2, sizeof( Int  ) * m_uiNumPartition );
 #endif
+
+#if LGE_EDGE_INTRA
+  if( rpcCU->getSlice()->getSPS()->isDepth() )
+  {
+	  memcpy( rpcCU->getEdgeCode( m_uiAbsIdxInLCU ),        m_pucEdgeCode,    iSizeInUchar * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
+	  memcpy( rpcCU->getEdgeNumber()    + m_uiAbsIdxInLCU,  m_pucEdgeNumber,  iSizeInUchar );
+	  memcpy( rpcCU->getEdgeStartPos()  + m_uiAbsIdxInLCU,  m_pucEdgeStartPos,iSizeInUchar );
+	  memcpy( rpcCU->getEdgeLeftFirst() + m_uiAbsIdxInLCU,  m_pbEdgeLeftFirst,iSizeInBool );
+	  memcpy( rpcCU->getEdgePartition( m_uiAbsIdxInLCU ),   m_pbEdgePartition,iSizeInBool * 16 );
+#if LGE_EDGE_INTRA_DELTA_DC
+	  memcpy( rpcCU->getEdgeDeltaDC0() + m_uiAbsIdxInLCU,   m_piEdgeDeltaDC0, sizeof( Int  ) * m_uiNumPartition );
+	  memcpy( rpcCU->getEdgeDeltaDC1() + m_uiAbsIdxInLCU,   m_piEdgeDeltaDC1, sizeof( Int  ) * m_uiNumPartition );
+#endif
+  }
+#endif
+
 #if HHI_MPI
   memcpy( rpcCU->getTextureModeDepth() + m_uiAbsIdxInLCU, m_piTextureModeDepth, sizeof( Int ) * m_uiNumPartition );
@@ -1455,4 +1534,20 @@
   memcpy( rpcCU->getContourPredTexDeltaDC2() + uiPartOffset, m_piContourPredTexDeltaDC2, sizeof( Int  ) * uiQNumPart );
 #endif
+
+#if LGE_EDGE_INTRA
+  if( rpcCU->getSlice()->getSPS()->isDepth() )
+  {
+	  memcpy( rpcCU->getEdgeCode( uiPartOffset ),       m_pucEdgeCode,    iSizeInUchar * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
+	  memcpy( rpcCU->getEdgeNumber()    + uiPartOffset, m_pucEdgeNumber,  iSizeInUchar );
+	  memcpy( rpcCU->getEdgeStartPos()  + uiPartOffset, m_pucEdgeStartPos,iSizeInUchar );
+	  memcpy( rpcCU->getEdgeLeftFirst() + uiPartOffset, m_pbEdgeLeftFirst,iSizeInBool );
+	  memcpy( rpcCU->getEdgePartition( uiPartOffset ),  m_pbEdgePartition,iSizeInBool * 16 );
+#if LGE_EDGE_INTRA_DELTA_DC
+	  memcpy( rpcCU->getEdgeDeltaDC0() + uiPartOffset,  m_piEdgeDeltaDC0, sizeof( Int  ) * uiQNumPart  );
+	  memcpy( rpcCU->getEdgeDeltaDC1() + uiPartOffset,  m_piEdgeDeltaDC1, sizeof( Int  ) * uiQNumPart  );
+#endif
+  }
+#endif
+
 #if HHI_MPI
   memcpy( rpcCU->getTextureModeDepth() + uiPartOffset, m_piTextureModeDepth, sizeof( Int ) * uiQNumPart  );
@@ -2332,4 +2427,7 @@
   mapDMMtoIntraMode( iLeftIntraDir );
 #endif
+#if LGE_EDGE_INTRA
+  mapEdgeIntratoDC( iLeftIntraDir );
+#endif
   
   // Get intra direction of above PU
@@ -2343,4 +2441,7 @@
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
   mapDMMtoIntraMode( iAboveIntraDir );
+#endif
+#if LGE_EDGE_INTRA
+  mapEdgeIntratoDC( iAboveIntraDir );
 #endif
   
@@ -2426,4 +2527,12 @@
   return uiPredNum;
 }
+
+#if LGE_EDGE_INTRA
+UInt TComDataCU::getCtxEdgeIntra( UInt uiAbsPartIdx )
+{
+	UInt        uiCtx = 0;
+	return uiCtx;
+}
+#endif
 
 UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
@@ -3362,5 +3471,11 @@
   cDisInfo.iN = 0;
   if(!bNoPdmMerge)
+  {
+#if USE_DVMCP
+    getDisMvpCand2(uiPUIdx, uiAbsPartIdx, &cDisInfo, true );
+#else
 	  getDisMvpCand (uiPUIdx, uiAbsPartIdx, &cDisInfo );
+#endif
+  }
   if(cDisInfo.iN==0)
   {
@@ -3428,4 +3543,8 @@
       pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
     }
+#if USE_DVMCP
+    pcMvFieldNeighbours[iCount<<1    ].getMv().m_bDvMcp = false;
+    pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -3500,4 +3619,8 @@
       pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
     }
+#if USE_DVMCP
+    pcMvFieldNeighbours[iCount<<1    ].getMv().m_bDvMcp = false;
+    pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -3567,4 +3690,8 @@
       pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
     }
+#if USE_DVMCP
+    pcMvFieldNeighbours[iCount<<1    ].getMv().m_bDvMcp = false;
+    pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -3631,4 +3758,8 @@
       pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
     }
+#if USE_DVMCP
+    pcMvFieldNeighbours[iCount<<1    ].getMv().m_bDvMcp = false;
+    pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -3704,4 +3835,8 @@
         pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
       }
+#if USE_DVMCP
+      pcMvFieldNeighbours[iCount<<1    ].getMv().m_bDvMcp = false;
+      pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
+#endif
 #if SIMP_MRG_PRUN
       if ( mrgCandIdx == iCount )
@@ -3820,4 +3955,8 @@
         puhInterDirNeighbours[uiArrayAddr] = 1;
       }
+#if USE_DVMCP
+      pcMvFieldNeighbours[uiArrayAddr<<1    ].getMv().m_bDvMcp = false;
+      pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv().m_bDvMcp = false;
+#endif
 #if SIMP_MRG_PRUN
       if ( mrgCandIdx == iCount )
@@ -4614,4 +4753,435 @@
 	}//remaining pictures
 }
+
+#if USE_DVMCP
+Void TComDataCU::getDisMvpCand2( UInt uiPartIdx, UInt uiPartAddr,DisInfo* pDInfo, Bool bMerge, RefPicList eRefPicList0, Int iRefIdx0 )
+{
+  PartSize eCUMode = getPartitionSize( uiPartAddr );
+  TComDataCU* pcTmpCU = NULL;
+  TComDataCU* pcCULeft = NULL;
+  pDInfo->iN = 0;
+
+  RefPicList eRefPicList = REF_PIC_LIST_0 ;
+  //-- Get Spatial MV
+  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
+  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
+
+  Int   aiDvMcpDvCand[2][7] = {{0,},    {0,}}; // dummy, 5 spatial + 1 temporal, DV-MCP ÁÖº¯ ºí·°¿¡¼­ »ç¿ëµÈ DV¸¦ ÀúÀå
+  Bool  abDvMcpFlag  [2][7] = {{false,},{false,}}; 
+  //Int   aiRefPOC     [2][7] = {{-1,},{-1}}; // debug
+  TComMv cTmpMvPred, cMv;
+  Bool  bTmpIsSkipped = false;
+  Bool  bDvMcpIsFound = false;
+
+  deriveLeftRightTopIdxGeneral( eCUMode, uiPartAddr, uiPartIdx, uiPartIdxLT, uiPartIdxRT );
+  deriveLeftBottomIdxGeneral( eCUMode, uiPartAddr, uiPartIdx, uiPartIdxLB );
+
+  UInt uiIdx = 0;
+#if MVP_AT_ENTROPYSLICE_BOUNDARY
+  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB, true, false);
+#else
+  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB);
+#endif
+
+  pcCULeft = pcTmpCU;
+  UInt uiLeftPartIdx = uiIdx;
+  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
+  {
+    bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
+    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
+    {
+      eRefPicList = RefPicList(iList);
+      Int refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
+      if( refId >= 0)
+      {
+        Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
+        if (refViewIdx!= m_pcSlice->getViewId()) // DCP
+        {
+          TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+          clipMv(cMvPred);
+          pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred; 
+          pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+          return;
+        }
+        else // MCP 
+        {
+          cTmpMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+          if( cTmpMvPred.m_bDvMcp && bTmpIsSkipped )
+          {
+            aiDvMcpDvCand[iList][DVFROM_LEFT] = cTmpMvPred.m_iDvMcpDispX;
+            abDvMcpFlag  [iList][DVFROM_LEFT] = true; 
+            bDvMcpIsFound = true;
+          }
+#if USE_DVMCP_MSG
+          //printf("skipped %d =%d, curCUAddr=%d, leftCUAddr=%d\n",DVFROM_LEFT, iList, getAddr(), pcTmpCU->getAddr() );
+          aiRefPOC     [iList][DVFROM_LEFT] = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx);
+          if( aiRefPOC[iList][DVFROM_LEFT]<0 )
+          {
+            printf("error\n");
+          }
+          //aiRefPOC     [iList][DVFROM_LEFT] = pcTmpCU->getSlice()->getRefPOC( eRefPicList, );
+#endif
+        }
+      }
+    }
+  }
+
+#if MVP_AT_ENTROPYSLICE_BOUNDARY
+  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT, true, false, true);
+#else
+  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT);
+#endif
+
+  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+  {
+    bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
+    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
+    {
+      eRefPicList = RefPicList(iList);
+      Int refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
+      if( refId >= 0)
+      {
+        Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
+        if (refViewIdx!= m_pcSlice->getViewId())
+        {
+          TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+          clipMv(cMvPred);
+          pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred; 
+          pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+          return;
+        }
+        else // MCP 
+        {
+          cTmpMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+          if( cTmpMvPred.m_bDvMcp  && bTmpIsSkipped )
+          {
+            aiDvMcpDvCand[iList][DVFROM_ABOVE] = cTmpMvPred.m_iDvMcpDispX;
+            abDvMcpFlag  [iList][DVFROM_ABOVE] = true; 
+            bDvMcpIsFound = true;
+          }
+#if USE_DVMCP_MSG
+          //printf("skipped %d =%d, curCUAddr=%d, leftCUAddr=%d\n",DVFROM_ABOVE, iList, getAddr(), pcTmpCU->getAddr() );
+          aiRefPOC     [iList][DVFROM_ABOVE] = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx);
+          if( aiRefPOC[iList][DVFROM_ABOVE]<0 )
+          {
+            printf("error\n");
+          }
+#endif
+        }
+      }
+    }
+  }
+
+#if MVP_AT_ENTROPYSLICE_BOUNDARY
+  pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true, false, true);
+#else
+  pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true, true, true);
+#endif
+  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
+  {
+    bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
+    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
+    {
+      eRefPicList = RefPicList(iList);
+      Int refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
+      if( refId >= 0)
+      {
+        Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
+        if (refViewIdx!= m_pcSlice->getViewId())
+        {
+          TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+          clipMv(cMvPred);
+          pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred; 
+          pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+          return;
+        }
+        else  // MCP 
+        {
+          cTmpMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+          if( cTmpMvPred.m_bDvMcp && bTmpIsSkipped )
+          {
+            aiDvMcpDvCand[iList][DVFROM_ABOVERIGHT] = cTmpMvPred.m_iDvMcpDispX;
+            abDvMcpFlag  [iList][DVFROM_ABOVERIGHT] = true; 
+            bDvMcpIsFound = true;
+          }
+#if USE_DVMCP_MSG
+          //printf("skipped %d =%d, curCUAddr=%d, leftCUAddr=%d\n",DVFROM_ABOVERIGHT, iList, getAddr(), pcTmpCU->getAddr() );
+          aiRefPOC     [iList][DVFROM_ABOVERIGHT] = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx);
+#endif
+        }
+      }
+    }
+  }
+
+#if MVP_AT_ENTROPYSLICE_BOUNDARY
+  pcTmpCU = getPUBelowLeft(uiIdx, uiPartIdxLB, true, false);
+#else
+  pcTmpCU = getPUBelowLeft(uiIdx, uiPartIdxLB);
+#endif
+  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+  {
+    bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
+    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
+    {
+      eRefPicList = RefPicList(iList);
+      Int refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
+      if( refId >= 0)
+      {
+        Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
+        if (refViewIdx!= m_pcSlice->getViewId())
+        {
+          TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+          clipMv(cMvPred);
+          pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred; 
+          pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+          return;
+        }
+        else // MCP 
+        {
+          cTmpMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+          if( cTmpMvPred.m_bDvMcp && bTmpIsSkipped )
+          {
+            aiDvMcpDvCand[iList][DVFROM_LEFTBELOW] = cTmpMvPred.m_iDvMcpDispX;
+            abDvMcpFlag  [iList][DVFROM_LEFTBELOW] = true; 
+            bDvMcpIsFound = true;
+          }
+#if USE_DVMCP_MSG
+          //printf("skipped %d =%d, curCUAddr=%d, leftCUAddr=%d\n",DVFROM_LEFTBELOW, iList, getAddr(), pcTmpCU->getAddr() );
+          aiRefPOC     [iList][DVFROM_LEFTBELOW] = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx);
+#endif
+        }
+      }
+    }
+  }
+
+  // Above predictor search
+#if MVP_AT_ENTROPYSLICE_BOUNDARY
+  pcTmpCU = getPUAboveLeft(uiIdx, (m_uiAbsIdxInLCU + uiPartAddr), true, false, true);
+  assert(uiPartIdxLT == (m_uiAbsIdxInLCU + uiPartAddr));
+#else
+  pcTmpCU = getPUAboveLeft(uiIdx, uiPartIdxLT, true, true, true);
+#endif
+  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+  {
+    bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
+    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
+    {
+      eRefPicList = RefPicList(iList);
+      Int refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
+      if( refId >= 0)
+      {
+        Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
+        if (refViewIdx!= m_pcSlice->getViewId())
+        {
+          TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+          clipMv(cMvPred);
+          pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred; 
+          pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+          return;
+        }
+        else // MCP 
+        {
+          cTmpMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+          if( cTmpMvPred.m_bDvMcp && bTmpIsSkipped )
+          {
+            aiDvMcpDvCand[iList][DVFROM_ABOVELEFT] = cTmpMvPred.m_iDvMcpDispX;
+            abDvMcpFlag  [iList][DVFROM_ABOVELEFT] = true; 
+            bDvMcpIsFound = true;
+          }
+#if USE_DVMCP_MSG
+          aiRefPOC     [iList][DVFROM_ABOVELEFT] = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx);
+          //printf("skipped %d =%d, curCUAddr=%d, leftCUAddr=%d\n",DVFROM_ABOVELEFT, iList, getAddr(), pcTmpCU->getAddr() );
+#endif
+        }
+      }
+    }
+  }
+
+  // copied from getInterMergeCand()
+  if ( getSlice()->getPPS()->getEnableTMVPFlag() )
+  {
+    UInt uiPUIdx = uiPartIdx;
+    UInt uiAbsPartAddr = uiPartAddr;
+
+    // col [2]
+    Int iRefIdxSkip[2] = {-1, -1};
+    if( !bMerge )
+    {
+      iRefIdxSkip[ eRefPicList0 ] = iRefIdx0;
+    }
+    else
+    {
+      for (Int i=0; i<2; i++)
+      {
+        RefPicList  eRefPicList1 = ( i==1 ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
+#if SET_MERGE_TMVP_REFIDX
+        Int iRefIdxTmp;
+        if ( uiPUIdx != 0 )
+        {
+          iRefIdxTmp = 0;
+        }
+        else
+        {    
+          iRefIdxTmp = (pcCULeft != NULL) ? pcCULeft->getCUMvField(eRefPicList1)->getRefIdx(uiLeftPartIdx) : -1;
+        }
+#else      
+        Int iRefIdxTmp = (pcCULeft != NULL) ? pcCULeft->getCUMvField(eRefPicList1)->getRefIdx(uiLeftPartIdx) : -1;
+#endif
+        iRefIdxSkip[i] = (iRefIdxTmp != -1) ? iRefIdxTmp : 0;
+      }
+    }
+
+    //>> MTK colocated-RightBottom
+    UInt uiPartIdxRB;
+    Int uiLCUIdx = getAddr();
+    eCUMode = getPartitionSize( 0 );
+
+    deriveRightBottomIdx( eCUMode, uiPUIdx, uiPartIdxRB );  
+
+    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
+    //UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
+
+    TComMv cColMv;
+    Int iRefIdx;
+
+    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
+    {
+      uiLCUIdx = -1;
+    }
+    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
+    {
+      uiLCUIdx = -1;
+    }
+    else
+    {
+      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU 
+        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
+      {
+        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
+        uiLCUIdx = getAddr();
+      }
+      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
+      {
+        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
+        uiLCUIdx = -1 ; 
+      }
+      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
+      {
+        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
+        uiLCUIdx = getAddr() + 1;
+      }
+      else //is the right bottom corner of LCU                       
+      {
+        uiAbsPartAddr = 0;
+        uiLCUIdx = -1 ; 
+      }
+    }
+
+    Bool bExistMV = false;
+    UInt uiPartIdxCenter;
+    UInt uiCurLCUIdx = getAddr();
+    xDeriveCenterIdx( eCUMode, uiPUIdx, uiPartIdxCenter );
+
+    Int iTargetView, iStartView; 
+    if( !bMerge ) // AMVP
+    {
+      bExistMV = uiLCUIdx >= 0 && xGetColDisMV( eRefPicList0, iRefIdx0, uiLCUIdx, uiAbsPartAddr, cColMv, iTargetView, iStartView );
+      if( bExistMV == false )
+      {
+        bExistMV = xGetColDisMV( eRefPicList0, iRefIdx0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iTargetView, iStartView );
+      }
+      if( bExistMV ) // DV is found
+      {
+        if( cColMv.m_bDvMcp == false ) //=> DCP, if true => DV-MCP
+        {
+          clipMv(cColMv);
+          pDInfo->m_acMvCand[ pDInfo->iN] = cColMv; 
+          pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetView;
+          return;
+        }
+        else // DV-MCP
+        {
+          aiDvMcpDvCand[eRefPicList0][DVFROM_COL] = cColMv.getHor(); 
+          abDvMcpFlag  [eRefPicList0][DVFROM_COL] = true; 
+          bDvMcpIsFound = true;
+        }
+      }
+    }
+    else // MERGE
+    {
+      iRefIdx = iRefIdxSkip[0];
+      bExistMV = uiLCUIdx >= 0 && xGetColDisMV( REF_PIC_LIST_0, iRefIdx, uiLCUIdx, uiAbsPartAddr, cColMv, iTargetView, iStartView );
+      if( bExistMV == false )
+      {
+        bExistMV = xGetColDisMV( REF_PIC_LIST_0, iRefIdx, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iTargetView, iStartView );
+      }
+      if( bExistMV )
+      {
+        if( cColMv.m_bDvMcp == false ) // DCP
+        {
+          clipMv(cColMv);
+          pDInfo->m_acMvCand[ pDInfo->iN] = cColMv; 
+          pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetView;
+          return;
+        }
+        else { // // DV-MCP
+          aiDvMcpDvCand[0][DVFROM_COL] = cColMv.getHor(); 
+          abDvMcpFlag  [0][DVFROM_COL] = true; 
+          bDvMcpIsFound = true;
+        }; 
+
+        if ( getSlice()->isInterB() )
+        {       
+          iRefIdx = iRefIdxSkip[1];
+          bExistMV = uiLCUIdx >= 0 && xGetColDisMV( REF_PIC_LIST_1, iRefIdx, uiLCUIdx, uiAbsPartAddr, cColMv, iTargetView, iStartView );
+          if( bExistMV == false )
+          {
+            bExistMV = xGetColDisMV( REF_PIC_LIST_1, iRefIdx, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iTargetView, iStartView );
+          }
+          if( bExistMV )
+          {
+            if( cColMv.m_bDvMcp == false ) // DCP
+            {
+              clipMv(cColMv);
+              pDInfo->m_acMvCand[ pDInfo->iN] = cColMv; 
+              pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetView;
+              return;
+            }
+            else // DV-MCP
+            {
+              aiDvMcpDvCand[1][DVFROM_COL] = cColMv.getHor(); 
+              abDvMcpFlag  [1][DVFROM_COL] = true; 
+              bDvMcpIsFound = true;
+            }; 
+          }
+        }
+      }
+    }
+  } // if TMVP Flag
+
+  if( bDvMcpIsFound ) // skip dvmcp
+  {
+    for( Int i=1 ; i<7 ; i++ ) // 5 spatial + 1 temporal
+    {
+      for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
+      {
+        if( abDvMcpFlag[iList][i]==true )
+        {
+          TComMv dv( aiDvMcpDvCand[iList][ i ], 0 );
+          clipMv( dv );
+          pDInfo->m_acMvCand[ pDInfo->iN  ] = dv;
+          pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0; 
+          return;
+        }
+
+      }
+    }
+  }
+
+  return;
+
+}
+#endif
+
 #endif
 
@@ -4640,5 +5210,11 @@
   cDisInfo.iN = 0;
   if(m_pcSlice->getSPS()->getViewId() && m_pcSlice->getSPS()->getMultiviewMvPredMode())
-	 getDisMvpCand (uiPartIdx, uiPartAddr, &cDisInfo );
+  {
+#if USE_DVMCP
+    getDisMvpCand2(uiPartIdx, uiPartAddr, &cDisInfo, false, eRefPicList, iRefIdx );
+#else
+	  getDisMvpCand (uiPartIdx, uiPartAddr, &cDisInfo );
+#endif
+  }
   if(cDisInfo.iN==0)
   {
@@ -5064,5 +5640,7 @@
   {
     TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
-    
+#if USE_DVMCP
+    cMvPred.m_bDvMcp = false;
+#endif 
     pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
     return true;
@@ -5099,4 +5677,7 @@
     {
       TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
+#if USE_DVMCP
+      cMvPred.m_bDvMcp = false;
+#endif
       pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
       return true;
@@ -5239,5 +5820,7 @@
     {
       TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
-
+#if USE_DVMCP
+      cMvPred.m_bDvMcp = false;
+#endif
       clipMv(cMvPred);
       pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
@@ -5267,4 +5850,7 @@
       rcMv = cMvPred.scaleMv( iScale );
     }
+#if USE_DVMCP
+    rcMv.m_bDvMcp = false;
+#endif
     pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
     return true;
@@ -5291,4 +5877,7 @@
       rcMv = cMvPred.scaleMv( iScale );
     }
+#if USE_DVMCP
+    rcMv.m_bDvMcp = false;
+#endif
     pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
     return true;
@@ -5301,4 +5890,9 @@
 Bool TComDataCU::xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
 {
+#if USE_DVMCP
+  Int  iDvMcpDispX[2] = {-1,};
+  Bool bDvMcpFlag [2] = { false, }; 
+  Int iCurrViewIdx = m_pcSlice->getViewId();
+#endif
 
   UInt uiAbsPartAddr = uiPartUnitIdx;
@@ -5310,8 +5904,12 @@
   iColViewIdx = pColCU->getSlice()->getViewId();
 
+
   if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiAbsPartAddr))
   {
     return false;
   }
+#if USE_DVMCP
+  Bool bColIsSkipped = pColCU->isSkipped( uiAbsPartAddr );
+#endif
   for (Int ilist = 0; ilist < (pColCU->getSlice()->isInterB()? 2:1); ilist++) 
   {
@@ -5330,8 +5928,26 @@
 	iColRefViewIdx = pColCU->getSlice()->getRefPic(eColRefPicList, iColRefIdx)->getViewId();
     if ( iColViewIdx    == iColRefViewIdx ) // temporal vector
+    {
+#if USE_DVMCP
+      if( iColViewIdx >0 )
+      {
+        TComMv tmpMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
+        if( tmpMv.m_bDvMcp && bColIsSkipped ) // DV-MCP SKIP
+        {
+          iDvMcpDispX[ilist] = tmpMv.m_iDvMcpDispX; 
+          bDvMcpFlag [ilist] = true; 
+          iTargetViewIdx  = 0; //iColRefViewIdx ;
+          iStartViewIdx   = 0; //iCurrViewIdx; //iColViewIdx   ;
+        }
+      }
+#endif
       continue;
+    }
     else 
     {
 	  rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
+#if USE_DVMCP
+    rcMv.m_bDvMcp = false;
+#endif
       iTargetViewIdx  = iColRefViewIdx ;
       iStartViewIdx   = iColViewIdx   ;
@@ -5339,4 +5955,20 @@
     }
   }
+
+#if USE_DVMCP
+  for( Int ilist=0 ; ilist<2 ; ilist++ )
+  {
+    if( bDvMcpFlag[ilist] )
+    {
+      rcMv.setHor( iDvMcpDispX[ilist] ); 
+      rcMv.setVer( 0 );
+      rcMv.m_bDvMcp = true;
+      iTargetViewIdx  = 0; //iColRefViewIdx ;
+      iStartViewIdx   = iCurrViewIdx; //iColViewIdx   ;
+      return true;
+    }
+  }
+#endif
+
   return false;
 }
@@ -6446,5 +7078,9 @@
    PartSize m_peSaved =  getPartitionSize( 0 );
    m_pePartSize[0] =  SIZE_2Nx2N;
+#if USE_DVMCP
+   getDisMvpCand2( 0, 0,  &cDisInfo, true );
+#else
    getDisMvpCand        ( 0, 0,  &cDisInfo );
+#endif
    if( cDisInfo.iN == 0)
    {
@@ -6472,3 +7108,626 @@
 #endif
 
+#if LGE_EDGE_INTRA
+Void TComDataCU::reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion )
+{
+	Int iWidth;
+	Int iHeight;
+	if( uiDepth == 0 )
+	{
+		iWidth = 64;
+		iHeight = 64;
+	}
+	else if( uiDepth == 1 )
+	{
+		iWidth = 32;
+		iHeight = 32;
+	}
+	else if( uiDepth == 2 )
+	{
+		iWidth = 16;
+		iHeight = 16;
+	}
+	else if( uiDepth == 3 )
+	{
+		iWidth = 8;
+		iHeight = 8;
+	}
+	else // uiDepth == 4
+	{
+		iWidth = 4;
+		iHeight = 4;
+	}
+
+	Int iPtr = 0;
+	Int iX, iY;
+	Int iDir = -1;
+	Int iDiffX = 0, iDiffY = 0;
+
+	// 1. Edge Code -> Vert & Horz Edges
+	Bool*  pbEdge = (Bool*) xMalloc( Bool, 4 * iWidth * iHeight );
+
+	for( UInt ui = 0; ui < 4 * iWidth * iHeight; ui++ )
+		pbEdge  [ ui ] = false;
+
+	// Direction : left(0), right(1), top(2), bottom(3), left-top(4), right-top(5), left-bottom(6), right-bottom(7)
+	// Code      : 0deg(0), 45deg(1), -45deg(2), 90deg(3), -90deg(4), 135deg(5), -135deg(6)
+	const UChar tableDir[8][7] = { { 0, 6, 4, 3, 2, 7, 5 },
+	{ 1, 5, 7, 2, 3, 4, 6 },
+	{ 2, 4, 5, 0, 1, 6, 7 },
+	{ 3, 7, 6, 1, 0, 5, 4 },
+	{ 4, 0, 2, 6, 5, 3, 1 },
+	{ 5, 2, 1, 4, 7, 0, 3 },
+	{ 6, 3, 0, 7, 4, 1, 2 },
+	{ 7, 1, 3, 5, 6, 2, 0 }};
+
+	UChar ucCode = pucEdgeCode[iPtr++];
+
+	if( !bLeft )
+	{
+		iX = ucStartPos;
+		iY = 0;
+
+		switch(ucCode)
+		{
+		case 0: // bottom
+			iDir = 3;
+			if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+			break;
+		case 2: // left-bottom
+			iDir = 6;
+			if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+			break;
+		case 1: // right-bottom
+			iDir = 7;
+			if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+			if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+			break;
+		case 4: // left
+			iDir = 0;
+			assert(false);
+			break;
+		case 3: // right
+			iDir = 1;
+			if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+			if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+			break;
+		}
+	}
+	else
+	{
+		iX = 0;
+		iY = ucStartPos;
+
+		switch(ucCode)
+		{
+		case 0: // right
+			iDir = 1;
+			if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+			break;
+		case 1: // right-top
+			iDir = 5;
+			if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+			if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+			break;
+		case 2: // right-bottom
+			iDir = 7;
+			if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+			break;
+		case 3: // top
+			iDir = 2;
+			if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+			if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+			break;
+		case 4: // bottom
+			iDir = 3;
+			assert(false);
+			break;
+		}
+	}
+
+	switch( iDir )
+	{
+	case 0: // left
+		iDiffX = -1;
+		iDiffY = 0;
+		break;
+	case 1: // right
+		iDiffX = +1;
+		iDiffY = 0;
+		break;
+	case 2: // top
+		iDiffX = 0;
+		iDiffY = -1;
+		break;
+	case 3: // bottom
+		iDiffX = 0;
+		iDiffY = +1;
+		break;
+	case 4: // left-top
+		iDiffX = -1;
+		iDiffY = -1;
+		break;
+	case 5: // right-top
+		iDiffX = +1;
+		iDiffY = -1;
+		break;
+	case 6: // left-bottom
+		iDiffX = -1;
+		iDiffY = +1;
+		break;
+	case 7: // right-bottom
+		iDiffX = +1;
+		iDiffY = +1;
+		break;
+	}
+
+	iX += iDiffX;
+	iY += iDiffY;
+
+	while( iPtr < ucNumEdge )
+	{
+		ucCode = pucEdgeCode[iPtr++];
+
+		Int iNewDir = tableDir[iDir][ucCode];
+
+		switch( iNewDir )
+		{
+		case 0: // left
+			iDiffX = -1;
+			iDiffY = 0;
+			break;
+		case 1: // right
+			iDiffX = +1;
+			iDiffY = 0;
+			break;
+		case 2: // top
+			iDiffX = 0;
+			iDiffY = -1;
+			break;
+		case 3: // bottom
+			iDiffX = 0;
+			iDiffY = +1;
+			break;
+		case 4: // left-top
+			iDiffX = -1;
+			iDiffY = -1;
+			break;
+		case 5: // right-top
+			iDiffX = +1;
+			iDiffY = -1;
+			break;
+		case 6: // left-bottom
+			iDiffX = -1;
+			iDiffY = +1;
+			break;
+		case 7: // right-bottom
+			iDiffX = +1;
+			iDiffY = +1;
+			break;
+		}
+
+		switch( iDir )
+		{
+		case 0: // left
+			switch( ucCode )
+			{
+			case 0:
+			case 2:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				break;
+			case 1:
+			case 3:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 4:
+			case 6:
+				// no
+				break;
+			case 5:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			}
+			break;
+		case 1: // right
+			switch( ucCode )
+			{
+			case 0:
+			case 2:
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				break;
+			case 1:
+			case 3:
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 4:
+			case 6:
+				// no
+				break;
+			case 5:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			}
+			break;
+		case 2: // top
+			switch( ucCode )
+			{
+			case 0:
+			case 2:
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 1:
+			case 3:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 4:
+			case 6:
+				// no
+				break;
+			case 5:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			}
+			break;
+		case 3: // bottom
+			switch( ucCode )
+			{
+			case 0:
+			case 2:
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 1:
+			case 3:
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				break;
+			case 4:
+			case 6:
+				// no
+				break;
+			case 5:
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				break;
+			}
+			break;
+		case 4: // left-top
+			switch( ucCode )
+			{
+			case 0:
+			case 1:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 2:
+			case 4:
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 3:
+			case 5:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 6:
+				// no
+				break;
+			}
+			break;
+		case 5: // right-top
+			switch( ucCode )
+			{
+			case 0:
+			case 1:
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 2:
+			case 4:
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				break;
+			case 3:
+			case 5:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 6:
+				// no
+				break;
+			}
+			break;
+		case 6: // left-bottom
+			switch( ucCode )
+			{
+			case 0:
+			case 1:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 2:
+			case 4:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				break;
+			case 3:
+			case 5:
+				if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				break;
+			case 6:
+				// no
+				break;
+			}
+			break;
+		case 7: // right-bottom
+			switch( ucCode )
+			{
+			case 0:
+			case 1:
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 2:
+			case 4:
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				break;
+			case 3:
+			case 5:
+				if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
+				if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
+				if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
+				break;
+			case 6:
+				// no
+				break;
+			}
+			break;
+		}
+
+		assert( iX >= 0 && iX <= iWidth );
+		assert( iY >= 0 && iY <= iHeight );
+
+		iX += iDiffX;
+		iY += iDiffY;
+		iDir = iNewDir;
+	}
+
+	// finalize edge chain
+	if( iX == iWidth-1 )
+	{
+		if( iY == 0 )
+		{
+			if( iDir == 1 )
+			{
+				pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
+			}
+			else if( iDir == 5 )
+			{
+				pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
+			}
+			else
+			{
+				assert(false);
+			}
+		}
+		else if( iY == iHeight-1 )
+		{
+			if( iDir == 3 )
+			{
+				pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
+			}
+			else if( iDir == 7 )
+			{
+				pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
+			}
+			else
+			{
+				assert(false);
+			}
+		}
+		else
+		{
+			if( iDir == 1 )
+			{
+				pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
+			}
+			else if( iDir == 3 )
+			{
+				pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
+				pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
+			}
+			else if( iDir == 5 )
+			{
+				pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
+			}
+			else if( iDir == 7 )
+			{
+				pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
+				pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
+			}
+			else
+			{
+				assert(false);
+			}
+		}
+	}
+	else if( iX == 0 )
+	{
+		if( iY == 0 )
+		{
+			if( iDir == 2 )
+			{
+				pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
+			}
+			else if( iDir == 4 )
+			{
+				pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
+			}
+			else
+			{
+				assert(false);
+			}
+		}
+		else if( iY == iHeight-1 )
+		{
+			if( iDir == 0 )
+			{
+				pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
+			}
+			else if( iDir == 6 )
+			{
+				pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
+			}
+			else
+			{
+				assert(false);
+			}
+		}
+		else
+		{
+			if( iDir == 0 )
+			{
+				pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
+			}
+			else if( iDir == 2 )
+			{
+				pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
+				pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
+			}
+			else if( iDir == 4 )
+			{
+				pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
+				pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
+			}
+			else if( iDir == 6 )
+			{
+				pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
+			}
+			else
+			{
+				assert(false);
+			}
+		}
+	}
+	else if( iY == 0 )
+	{
+		if( iDir == 1 )
+		{
+			pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
+			pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
+		}
+		else if( iDir == 2 )
+		{
+			pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
+		}
+		else if( iDir == 4 )
+		{
+			pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
+		}
+		else if( iDir == 5 )
+		{
+			pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
+			pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
+		}
+		else
+		{
+			assert(false);
+		}
+	}
+	else if( iY == iHeight-1 )
+	{
+		if( iDir == 0 )
+		{
+			pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
+			pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
+		}
+		else if( iDir == 3 )
+		{
+			pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
+		}
+		else if( iDir == 6 )
+		{
+			pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
+			pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
+		}
+		else if( iDir == 7 )
+		{
+			pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
+		}
+		else
+		{
+			assert(false);
+		}
+	}
+	else
+	{
+		printf("xPredIntraEdge: wrong termination\n");
+		assert(false);
+	}
+
+	// Reconstruct Region from Chain Code
+	Bool* pbVisit  = (Bool*) xMalloc( Bool, iWidth * iHeight );
+	Int*  piStack  = (Int* ) xMalloc( Int,  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;
+	}
+
+	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;
+		}
+	}
+
+	xFree( pbEdge );
+	xFree( pbVisit );
+	xFree( piStack );
+}
+
+#endif
+
 //! \}
Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDataCU.h	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDataCU.h	(revision 97)
@@ -214,4 +214,16 @@
 #endif
 
+#if LGE_EDGE_INTRA
+  UChar*        m_pucEdgeCode;          ///< array of edge code
+  UChar*        m_pucEdgeNumber;        ///< total number of edge
+  UChar*        m_pucEdgeStartPos;      ///< starting point position
+  Bool*         m_pbEdgeLeftFirst;      ///< true if edge should be checked in left boundary first
+  Bool*         m_pbEdgePartition;      ///< true if it belongs to region 1, otherwise, region 0
+#if LGE_EDGE_INTRA_DELTA_DC
+  Int*          m_piEdgeDeltaDC0;
+  Int*          m_piEdgeDeltaDC1;
+#endif
+#endif
+
   // -------------------------------------------------------------------------------------------------------------------
   // misc. variables
@@ -513,4 +525,8 @@
   Int           getPdmMergeCandidateDisCan( UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo );
   Void          getDisMvpCand        ( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo );
+#if USE_DVMCP
+  Void          getDisMvpCand2( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo, Bool bMerge=false, RefPicList eRefPicList=REF_PIC_LIST_X, Int iRefIdx=-1 );
+#endif
+
 #endif
   Bool          getIViewOrgDepthMvPred( UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv );
@@ -668,4 +684,9 @@
   UInt          getEntropySliceStartCU  ( UInt pos )                  { return m_uiEntropySliceStartCU[pos-m_uiAbsIdxInLCU];                                                                                   }
   UInt&         getTotalBins            ()                            { return m_uiTotalBins;                                                                                                  }
+
+#if LGE_EDGE_INTRA
+  UInt          getCtxEdgeIntra ( UInt uiAbsPartIdx );
+#endif
+
   // -------------------------------------------------------------------------------------------------------------------
   // member functions for RD cost storage
@@ -743,4 +764,28 @@
   Void  setContourPredTexDeltaDC2SubParts ( Int iDC2, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
+
+#if LGE_EDGE_INTRA
+  UChar*        getEdgeCode( UInt uiIdx )                 { return &m_pucEdgeCode[uiIdx * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4]; }
+  UChar*        getEdgeNumber( )                          { return m_pucEdgeNumber;           }
+  UChar         getEdgeNumber( UInt uiIdx )               { return m_pucEdgeNumber[uiIdx];    }
+  Void          setEdgeNumber( UInt uiIdx, UChar val )    { m_pucEdgeNumber[uiIdx] = val;     }
+  UChar*        getEdgeStartPos( )                        { return m_pucEdgeStartPos;         }
+  UChar         getEdgeStartPos( UInt uiIdx )             { return m_pucEdgeStartPos[uiIdx];  }
+  Void          setEdgeStartPos( UInt uiIdx, UChar val )  { m_pucEdgeStartPos[uiIdx] = val;   }
+  Bool*         getEdgeLeftFirst( )                       { return m_pbEdgeLeftFirst;         }
+  Bool          getEdgeLeftFirst( UInt uiIdx )            { return m_pbEdgeLeftFirst[uiIdx];  }
+  Void          setEdgeLeftFirst( UInt uiIdx, Bool val )  { m_pbEdgeLeftFirst[uiIdx] = val;   }
+  Bool*         getEdgePartition( UInt uiIdx )              { return &m_pbEdgePartition[uiIdx * 16]; }
+  Void          reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion );
+
+#if LGE_EDGE_INTRA_DELTA_DC
+  Int*          getEdgeDeltaDC0( )                          { return m_piEdgeDeltaDC0; }
+  Int*          getEdgeDeltaDC1( )                          { return m_piEdgeDeltaDC1; }
+  Int           getEdgeDeltaDC0( UInt uiIdx )               { return m_piEdgeDeltaDC0[uiIdx]; }
+  Int           getEdgeDeltaDC1( UInt uiIdx )               { return m_piEdgeDeltaDC1[uiIdx]; }
+  Void          setEdgeDeltaDC0( UInt uiIdx, Int val )      { m_piEdgeDeltaDC0[uiIdx] = val;  }
+  Void          setEdgeDeltaDC1( UInt uiIdx, Int val )      { m_piEdgeDeltaDC1[uiIdx] = val;  }
+#endif
+#endif
 };
 
Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDepthMapGenerator.cpp
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 97)
@@ -831,4 +831,7 @@
 TComDepthMapGenerator::getDisCanPdmMvPred    ( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge )
 {
+#if USE_DVMCP
+  rcMv.m_bDvMcp = false;
+#endif
   AOF  ( m_bCreated && m_bInit );
   AOF  ( iRefIdx >= 0 );
@@ -892,4 +895,15 @@
       {
         rcMv.set( cBaseMvField.getHor(), cBaseMvField.getVer() );
+#if USE_DVMCP
+        // save disparity vector when a merge candidate for IVMP is set as DV-MCP
+        if( bMerge ) 
+        {
+          rcMv.m_bDvMcp = true;
+          rcMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor(); 
+        }
+        else { // AMVP ?
+          rcMv.m_bDvMcp = false;
+        }
+#endif
         return true;
       }
Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/TComMv.h
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/TComMv.h	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/TComMv.h	(revision 97)
@@ -57,4 +57,9 @@
 public:
   
+#if USE_DVMCP
+  Bool  m_bDvMcp;       // is dv-mcp ?
+  Int   m_iDvMcpDispX;  // disparity for dv-mcp
+#endif
+
   // ------------------------------------------------------------------------------------------------------------------
   // constructors
@@ -64,4 +69,8 @@
   m_iHor(0),
   m_iVer(0)
+#if USE_DVMCP
+  , m_bDvMcp(false)
+  , m_iDvMcpDispX(0)
+#endif
   {
   }
@@ -70,4 +79,8 @@
   m_iHor(iHor),
   m_iVer(iVer)
+#if USE_DVMCP
+  , m_bDvMcp(false)
+  , m_iDvMcpDispX(0)
+#endif
   {
   }
Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPattern.cpp
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPattern.cpp	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPattern.cpp	(revision 97)
@@ -675,4 +675,7 @@
 {
   Int* piSrc;
+#if LGE_EDGE_INTRA
+  mapEdgeIntratoDC( uiDirMode );
+#endif
   assert(log2BlkSize >= 2 && log2BlkSize < 7);
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPic.h
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPic.h	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPic.h	(revision 97)
@@ -73,4 +73,8 @@
 #endif
 
+#if LG_ZEROINTRADEPTHRESI_M26039
+  Int                   m_uiIntraPeriod;
+#endif
+
 #if HHI_INTER_VIEW_MOTION_PRED
   TComPicYuv*           m_pcOrgDepthMap;          //  original depth map
@@ -129,4 +133,8 @@
 #if VIDYO_VPS_INTEGRATION
   TComVPS*      getVPS()              { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx)->getVPS();  }
+#endif
+#if LG_ZEROINTRADEPTHRESI_M26039
+  Int           getIntraPeriod()                           { return  m_uiIntraPeriod; }
+  Void          setIntraPeriod(Int uiIntraPeriod)          { m_uiIntraPeriod = uiIntraPeriod; }
 #endif
   TComSPS*      getSPS()              { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx)->getSPS();  }
Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPrediction.cpp	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPrediction.cpp	(revision 97)
@@ -419,4 +419,184 @@
 }
 
+#if LGE_EDGE_INTRA
+Void TComPrediction::predIntraLumaEdge ( TComDataCU* pcCU, TComPattern* pcTComPattern, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Pel* piPred, UInt uiStride, Bool bDelta )
+{
+	Pel *piDst = piPred;
+	Int *piSrc;
+	Int iSrcStride = ( iWidth<<1 ) + 1;
+	Int iDstStride = uiStride;
+
+	piSrc = pcTComPattern->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
+
+	xPredIntraEdge ( pcCU, uiAbsPartIdx, iWidth, iHeight, piSrc, iSrcStride, piDst, iDstStride
+#if LGE_EDGE_INTRA_DELTA_DC
+		, bDelta
+#endif
+		);
+}
+
+Pel  TComPrediction::xGetNearestNeighbor( Int x, Int y, Int* pSrc, Int srcStride, Int iWidth, Int iHeight, Bool* bpRegion )
+{
+	Bool bLeft = (x < y) ? true : false;
+	Bool bFound = false;
+	Int  iFoundX = -1, iFoundY = -1;
+	Int  cResult = 0;
+
+#define MAX_DISTANCE_EDGEINTRA 255
+
+	UChar* piTopDistance = new UChar[iWidth];
+	UChar* piLeftDistance = new UChar[iHeight];
+
+	for( Int i = 0; i < iWidth; i++ )
+	{
+		int Abs = x > i ? x - i : i - x;
+		piTopDistance[ i ] = y + Abs;
+
+		Abs = y > i ? y - i : i - y;
+		piLeftDistance[ i ] = x + Abs;
+	}
+
+	for( Int dist = 0; dist < MAX_DISTANCE_EDGEINTRA && !bFound; dist++ )
+	{
+		if( !bLeft )
+		{
+			for( Int i = 0; i < iWidth; i++ )
+			{
+				if( piTopDistance[ i ] == dist )
+				{
+					if( bpRegion[ i ] == bpRegion[ x + y * iWidth ] )
+					{
+						iFoundX = i;
+						iFoundY = 0;
+						bFound = true;
+					}
+				}
+			}
+			for( Int i = 0; i < iHeight; i++ )
+			{
+				if( piLeftDistance[ i ] == dist )
+				{
+					if( bpRegion[ i * iWidth ] == bpRegion[ x + y * iWidth ] )
+					{
+						iFoundX = 0;
+						iFoundY = i;
+						bFound = true;
+					}
+				}
+			}
+		}
+		else
+		{
+			for( Int i = 0; i < iHeight; i++ )
+			{
+				if( piLeftDistance[ i ] == dist )
+				{
+					if( bpRegion[ i * iWidth ] == bpRegion[ x + y * iWidth ] )
+					{
+						iFoundX = 0;
+						iFoundY = i;
+						bFound = true;
+					}
+				}
+			}
+			for( Int i = 0; i < iWidth; i++ )
+			{
+				if( piTopDistance[ i ] == dist )
+				{
+					if( bpRegion[ i ] == bpRegion[ x + y * iWidth ] )
+					{
+						iFoundX = i;
+						iFoundY = 0;
+						bFound = true;
+					}
+				}
+			}
+		}
+	}
+
+	if( iFoundY == 0 )
+	{
+		cResult = pSrc[ iFoundX + 1 ];
+	}
+	else // iFoundX == 0
+	{
+		cResult = pSrc[ (iFoundY + 1) * srcStride ];
+	}
+
+	delete[] piTopDistance;  piTopDistance = NULL;
+	delete[] piLeftDistance; piLeftDistance = NULL;
+
+	assert( bFound );
+
+	return cResult;
+}
+
+Void TComPrediction::xPredIntraEdge( TComDataCU* pcCU, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, Bool bDelta )
+{
+	Pel* pDst = rpDst;
+	Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx );
+
+	// Do prediction
+	{
+		UInt uiSum0 = 0, uiSum1 = 0;
+		UInt uiMean0, uiMean1;
+		UInt uiCount0 = 0, uiCount1 = 0;
+		for( UInt ui = 0; ui < iWidth; ui++ )
+		{
+			if( pbRegion[ ui ] == false )
+			{
+				uiSum0 += (pSrc[ ui + 1 ]);
+				uiCount0++;
+			}
+			else
+			{
+				uiSum1 += (pSrc[ ui + 1 ]);
+				uiCount1++;
+			}
+		}
+		for( UInt ui = 0; ui < iHeight; ui++ ) // (0,0) recount (to avoid division)
+		{
+			if( pbRegion[ ui * iWidth ] == false )
+			{
+				uiSum0 += (pSrc[ (ui + 1) * srcStride ]);
+				uiCount0++;
+			}
+			else
+			{
+				uiSum1 += (pSrc[ (ui + 1) * srcStride ]);
+				uiCount1++;
+			}
+		}
+		if( uiCount0 == 0 )
+			assert(false);
+		if( uiCount1 == 0 )
+			assert(false);
+		uiMean0 = uiSum0 / uiCount0; // TODO : integer op.
+		uiMean1 = uiSum1 / uiCount1;
+#if LGE_EDGE_INTRA_DELTA_DC
+		if( bDelta ) 
+		{
+			Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx );
+			Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx );
+			xDeltaDCQuantScaleUp( pcCU, iDeltaDC0 );
+			xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 );
+			uiMean0 = Clip( uiMean0 + iDeltaDC0 );
+			uiMean1 = Clip( uiMean1 + iDeltaDC1 );
+		}
+#endif
+		for( UInt ui = 0; ui < iHeight; ui++ )
+		{
+			for( UInt uii = 0; uii < iWidth; uii++ )
+			{
+				if( pbRegion[ uii + ui * iWidth ] == false )
+					pDst[ uii + ui * dstStride ] = uiMean0;
+				else
+					pDst[ uii + ui * dstStride ] = uiMean1;
+			}
+		}
+	}
+}
+#endif
+
 #if DEPTH_MAP_GENERATION
 Void TComPrediction::motionCompensation( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY )
Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPrediction.h	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPrediction.h	(revision 97)
@@ -125,4 +125,9 @@
 #endif
 
+#if LGE_EDGE_INTRA
+  Pel  xGetNearestNeighbor  ( Int x, Int y, Int* pSrc, Int srcStride, Int iWidth, Int iHeight, Bool* bpRegion );
+  Void xPredIntraEdge       ( TComDataCU* pcCU, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, Bool bDelta = false );
+#endif
+
 public:
   TComPrediction();
@@ -170,4 +175,7 @@
   Bool  getWedgePatternIdx      ( WedgeRefList* pcWedgeRefList, UInt& ruiTabIdx, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe );
 #endif
+#if LGE_EDGE_INTRA
+  Void predIntraLumaEdge          ( TComDataCU* pcCU, TComPattern* pcTComPattern, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Pel* piPred, UInt uiStride, Bool bDelta = false );
+#endif
 
   // simplified intra pred for "virtual" depth maps
Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/TComRom.h
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/TComRom.h	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/TComRom.h	(revision 97)
@@ -206,4 +206,10 @@
 #endif
 
+#if LGE_EDGE_INTRA
+__inline Void mapEdgeIntratoDC( UChar& curDir ) { curDir = (curDir >= EDGE_INTRA_IDX) ? DC_IDX : curDir; }
+__inline Void mapEdgeIntratoDC(  UInt& curDir ) { curDir = (curDir >= EDGE_INTRA_IDX) ? DC_IDX : curDir; }
+__inline Void mapEdgeIntratoDC(   Int& curDir ) { curDir = (curDir >= EDGE_INTRA_IDX) ? DC_IDX : curDir; }
+#endif
+
 // ==========================================
 // Mode-Dependent DST Matrices
Index: branches/HTM-3.1-LG/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibCommon/TypeDef.h	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibCommon/TypeDef.h	(revision 97)
@@ -42,4 +42,16 @@
 //! \{
 
+#define LGE_EDGE_INTRA                  1       //JCT2-A0070
+#if LGE_EDGE_INTRA
+#define LGE_EDGE_INTRA_MIN_SIZE         4
+#define LGE_EDGE_INTRA_MAX_SIZE        32
+#define LGE_EDGE_INTRA_THRESHOLD       20
+#define LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 8
+#define LGE_EDGE_INTRA_DELTA_DC         1 
+#define LGE_EDGE_INTRA_PIXEL_DIFFERENCE 1
+#endif
+
+#define LG_ZEROINTRADEPTHRESI_M26039      1  //JCT2-A0087
+
 #define SONY_COLPIC_AVAILABILITY          1
 
@@ -54,4 +66,15 @@
 #define MTK_INTERVIEW_MERGE_A0049         1 //  JCT2-A0049 second part
 
+#if QC_MULTI_DIS_CAN                    // JCT2-A0126
+#define USE_DVMCP         0 
+
+#define DVFROM_LEFTBELOW  1
+#define DVFROM_LEFT       2
+#define DVFROM_ABOVERIGHT 3
+#define DVFROM_ABOVE      4
+#define DVFROM_ABOVELEFT  5
+#define DVFROM_COL        6
+#endif
+
 
 #define HHI_VSO                           1
@@ -231,5 +254,13 @@
 #define LOG2_SCAN_SET_SIZE                4
 
+#if LGE_EDGE_INTRA
+#if LGE_EDGE_INTRA_DELTA_DC
+#define FAST_UDI_MAX_RDMODE_NUM               37          ///< maximum number of RD comparison in fast-UDI estimation loop
+#else
+#define FAST_UDI_MAX_RDMODE_NUM               36          ///< maximum number of RD comparison in fast-UDI estimation loop
+#endif
+#else
 #define FAST_UDI_MAX_RDMODE_NUM               35          ///< maximum number of RD comparison in fast-UDI estimation loop
+#endif
 
 #define ZERO_MVD_EST                          0           ///< Zero Mvd Estimation in normal mode
@@ -270,4 +301,13 @@
 #define NUM_DMM_MODE 4
 #endif
+
+#if LGE_EDGE_INTRA
+#if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX
+#define EDGE_INTRA_IDX  (NUM_INTRA_MODE+NUM_DMM_MODE)
+#endif // HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX
+#if LGE_EDGE_INTRA_DELTA_DC
+#define EDGE_INTRA_DELTA_IDX          (EDGE_INTRA_IDX+1)
+#endif
+#endif // LGE_EDGE_INTRA
 
 #define IBDI_DISTORTION                0           ///< enable/disable SSE modification when IBDI is used (JCTVC-D152)
Index: branches/HTM-3.1-LG/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibDecoder/TDecCu.cpp	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibDecoder/TDecCu.cpp	(revision 97)
@@ -705,4 +705,15 @@
                                      m_pcPrediction->getPredicBufHeight (),
                                      bAboveAvail, bLeftAvail );
+#if LGE_EDGE_INTRA
+  if( uiLumaPredMode >= EDGE_INTRA_IDX )
+  {
+	  m_pcPrediction->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 =====
Index: branches/HTM-3.1-LG/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 97)
@@ -98,4 +98,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 );
@@ -182,4 +188,10 @@
 
   m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
+#if LGE_EDGE_INTRA
+  m_cEdgeIntraSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_EDGE_INTRA );
+#if LGE_EDGE_INTRA_DELTA_DC
+  m_cEdgeIntraDeltaDCSCModel.initBuffer  ( sliceType, qp, (UChar*)INIT_EDGE_INTRA_DELTA_DC );
+#endif
+#endif
   m_uiLastDQpNonZero  = 0;
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
@@ -850,4 +862,14 @@
 #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
+
 #if LOGI_INTRA_NAME_3MPM
   Int uiPreds[3] = {-1, -1, -1};
@@ -855,5 +877,8 @@
   Int uiPreds[2] = {-1, -1};
 #endif
-  Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds);  
+  Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); 
+#if LGE_EDGE_INTRA
+  UInt uiCheckBit = 0;
+#endif
  
   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
@@ -878,4 +903,15 @@
    
     m_pcTDecBinIf->decodeBinsEP( uiSymbol, 5 );
+#if LGE_EDGE_INTRA
+	if (bCodeEdgeIntra)
+	{
+		if (uiSymbol==31)
+		{
+			m_pcTDecBinIf->decodeBinsEP(uiCheckBit,1);
+			if (uiCheckBit)
+				uiSymbol = EDGE_INTRA_IDX;
+		}
+	}
+#endif
     intraPredMode = uiSymbol;
     
@@ -903,9 +939,57 @@
     }
 #endif
+#if LGE_EDGE_INTRA
+	if ( intraPredMode != EDGE_INTRA_IDX)
+	{
+#endif
     for ( Int i = 0; i < uiPredNum; i++ )
     {
       intraPredMode += ( intraPredMode >= uiPreds[i] );
     }
-  }
+#if LGE_EDGE_INTRA
+	}
+#endif
+  }
+
+#if LGE_EDGE_INTRA
+  if( intraPredMode == EDGE_INTRA_IDX )
+  {
+	  xParseEdgeIntraInfo( pcCU, uiAbsPartIdx, uiDepth );
+#if LGE_EDGE_INTRA_DELTA_DC
+	  m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
+	  if( uiSymbol )
+	  {
+		  intraPredMode = EDGE_INTRA_DELTA_IDX;
+		  Int iDeltaDC0;
+		  Int iDeltaDC1;
+
+		  xReadExGolombLevel( (UInt &) iDeltaDC0, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
+		  if( iDeltaDC0 != 0 )
+		  {
+			  UInt uiSign;
+			  m_pcTDecBinIf->decodeBinEP( uiSign );
+			  if ( uiSign )
+			  {
+				  iDeltaDC0 = -iDeltaDC0;
+			  }
+		  }
+		  xReadExGolombLevel( (UInt &) iDeltaDC1, m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
+		  if( iDeltaDC1 != 0 )
+		  {
+			  UInt uiSign;
+			  m_pcTDecBinIf->decodeBinEP( uiSign );
+			  if ( uiSign )
+			  {
+				  iDeltaDC1 = -iDeltaDC1;
+			  }
+		  }
+
+		  pcCU->setEdgeDeltaDC0( uiAbsPartIdx, iDeltaDC0 );
+		  pcCU->setEdgeDeltaDC1( uiAbsPartIdx, iDeltaDC1 );
+	  }
+#endif
+  }
+#endif
+
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
   }
@@ -2012,5 +2096,5 @@
 #endif
 
-#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 TDecSbac::xReadExGolombLevel( UInt& ruiSymbol, ContextModel& rcSCModel  )
 {
@@ -2270,3 +2354,102 @@
 }
 #endif
+
+#if LGE_EDGE_INTRA
+Void TDecSbac::xParseEdgeIntraInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+{
+	UInt uiSymbol = 0;
+
+	// 1. Top(0) or Left(1)
+	UChar ucLeft;
+	m_pcTDecBinIf->decodeBinEP( uiSymbol );
+	ucLeft = uiSymbol;
+
+	// 2. Start position (lowest bit first)
+	UChar ucStart = 0;
+	for( UInt ui = 0; ui < 6 - uiDepth; ui++ )
+	{
+		m_pcTDecBinIf->decodeBinEP( uiSymbol );
+		ucStart |= (uiSymbol << ui);
+	}
+
+	// 3. Number of edges
+	UChar ucMax = 0;
+	for( UInt ui = 0; ui < 7 - uiDepth; ui++ )
+	{
+		m_pcTDecBinIf->decodeBinEP( uiSymbol );
+		ucMax |= (uiSymbol << ui);
+	}
+	ucMax++; // +1
+
+	// 4. Edges
+	UChar* pucSymbolList = (UChar*) xMalloc( UChar, 256 * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
+	UInt uiCtxEdgeIntra = pcCU->getCtxEdgeIntra( uiAbsPartIdx );
+	for( Int iPtr = 0; iPtr < ucMax; iPtr++ )
+	{
+		UChar ucEdge = 0;
+		UInt  uiReorderEdge = 0;
+		// Left-friendly direction
+		// 0 (   0deg) => 0
+		// 1 (  45deg) => 10
+		// 2 ( -45deg) => 110
+		// 3 (  90deg) => 1110
+		// 4 ( -90deg) => 11110
+		// 5 ( 135deg) => 111110
+		// 6 (-135deg) => 111111
+		// Right-friendly direction
+		// 0 (   0deg) => 0
+		// 1 ( -45deg) => 10
+		// 2 (  45deg) => 110
+		// 3 ( -90deg) => 1110
+		// 4 (  90deg) => 11110
+		// 5 (-135deg) => 111110
+		// 6 ( 135deg) => 111111
+		// refer to a paper "An efficient chain code with Huffman coding"
+		for( UInt ui = 0; ui < 6; ui++ )
+		{
+			m_pcTDecBinIf->decodeBin( uiSymbol, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) );
+			ucEdge <<= 1;
+			ucEdge |= uiSymbol;
+			if( uiSymbol == 0 )
+				break;
+		}
+
+		switch( ucEdge )
+		{
+		case 0 :  // "0"
+			uiReorderEdge = 0;
+			break;
+		case 2 :  // "10"
+			uiReorderEdge = 1;
+			break;
+		case 6 :  // "110"
+			uiReorderEdge = 2;
+			break;
+		case 14 : // "1110"
+			uiReorderEdge = 3;
+			break;
+		case 30 : // "11110"
+			uiReorderEdge = 4;
+			break;
+		case 62 : // "111110"
+			uiReorderEdge = 5;
+			break;
+		case 63 : // "111111"
+			uiReorderEdge = 6;
+			break;
+		default :
+			printf("parseIntraEdgeChain: error (unknown code %d)\n",ucEdge);
+			assert(false);
+			break;
+		}
+		pucSymbolList[iPtr] = uiReorderEdge;
+	}
+	/////////////////////
+	// Edge Reconstruction
+	Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx );
+	pcCU->reconPartition( uiAbsPartIdx, uiDepth, ucLeft == 1, ucStart, ucMax, pucSymbolList, pbRegion );
+	xFree( pucSymbolList );
+}
+#endif
+
 //! \}
Index: branches/HTM-3.1-LG/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibDecoder/TDecSbac.h	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibDecoder/TDecSbac.h	(revision 97)
@@ -145,4 +145,8 @@
   Void xParseContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
+
+#if LGE_EDGE_INTRA
+  Void xParseEdgeIntraInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#endif
   
 private:
@@ -253,4 +257,10 @@
   ContextModel3DBuffer m_cDmmDataSCModel;
 #endif
+#if LGE_EDGE_INTRA
+  ContextModel3DBuffer m_cEdgeIntraSCModel;
+#if LGE_EDGE_INTRA_DELTA_DC
+  ContextModel3DBuffer m_cEdgeIntraDeltaDCSCModel;
+#endif
+#endif
 };
 
Index: branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 97)
@@ -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
@@ -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 )
   {
-    m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE, m_cDmmFlagSCModel.get(0, 0, 0) );
-  }
+#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: branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSbac.h	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSbac.h	(revision 97)
@@ -175,4 +175,7 @@
   Void  xCodeContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx );
 #endif
+#if LGE_EDGE_INTRA
+  Void  xCodeEdgeIntraInfo( TComDataCU* pcCU, UInt uiPartIdx );
+#endif
 
 protected:
@@ -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: branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 97)
@@ -952,10 +952,14 @@
 Void
 TEncSearch::xIntraCodingLumaBlk( TComDataCU* pcCU,
-                                UInt        uiTrDepth,
-                                UInt        uiAbsPartIdx,
-                                TComYuv*    pcOrgYuv, 
-                                TComYuv*    pcPredYuv, 
-                                TComYuv*    pcResiYuv, 
-                                Dist&       ruiDist )
+								UInt        uiTrDepth,
+								UInt        uiAbsPartIdx,
+								TComYuv*    pcOrgYuv, 
+								TComYuv*    pcPredYuv, 
+								TComYuv*    pcResiYuv, 
+								Dist&       ruiDist 
+#if LG_ZEROINTRADEPTHRESI_M26039
+								,Bool        bZeroResi
+#endif
+								)
 {
   UInt    uiLumaPredMode    = pcCU     ->getLumaIntraDir     ( uiAbsPartIdx );
@@ -988,4 +992,21 @@
   pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
   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 =====
@@ -1020,4 +1041,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 =====
@@ -1300,16 +1333,20 @@
 Void 
 TEncSearch::xRecurIntraCodingQT( TComDataCU*  pcCU, 
-                                UInt         uiTrDepth,
-                                UInt         uiAbsPartIdx, 
-                                Bool         bLumaOnly,
-                                TComYuv*     pcOrgYuv, 
-                                TComYuv*     pcPredYuv, 
-                                TComYuv*     pcResiYuv, 
-                                Dist&        ruiDistY,
-                                Dist&        ruiDistC,
+								UInt         uiTrDepth,
+								UInt         uiAbsPartIdx, 
+								Bool         bLumaOnly,
+								TComYuv*     pcOrgYuv, 
+								TComYuv*     pcPredYuv, 
+								TComYuv*     pcResiYuv, 
+								Dist&        ruiDistY,
+								Dist&        ruiDistC,
 #if HHI_RQT_INTRA_SPEEDUP
-                                Bool         bCheckFirst,
-#endif
-                                Double&      dRDCost )
+								Bool         bCheckFirst,
+#endif
+								Double&      dRDCost 
+#if LG_ZEROINTRADEPTHRESI_M26039
+								,Bool         bZeroResi
+#endif
+								)
 {
   UInt    uiFullDepth   = pcCU->getDepth( 0 ) +  uiTrDepth;
@@ -1328,4 +1365,10 @@
   {
     bCheckSplit = false;
+  }
+#endif
+#if LGE_EDGE_INTRA
+  if( pcCU->getLumaIntraDir( uiAbsPartIdx ) >= EDGE_INTRA_IDX )
+  {
+	  bCheckSplit = false;
   }
 #endif
@@ -1346,5 +1389,9 @@
     //----- code luma block with given intra prediction mode and store Cbf-----
     dSingleCost   = 0.0;
-    xIntraCodingLumaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistY ); 
+#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 )
     {
@@ -1807,4 +1854,19 @@
     UInt uiRdModeList[FAST_UDI_MAX_RDMODE_NUM];
     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
@@ -1866,4 +1928,7 @@
 #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 +2039,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,12 +2061,22 @@
     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 ) )
-      {
-        continue;
-      }
+	  if( m_pcEncCfg->getIsDepth() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight ) 
+#if LGE_EDGE_INTRA
+		  && uiOrgMode < EDGE_INTRA_IDX
+#endif
+		  )
+	  {
+		  continue;
+	  }
 #endif
 
@@ -2020,7 +2104,11 @@
 
 #if HHI_RQT_INTRA_SPEEDUP
-      xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost );
-#else
-      xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost );
+#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 );
 #endif
       
@@ -2053,5 +2141,8 @@
       }
 #endif
-    } // Mode loop
+#if LG_ZEROINTRADEPTHRESI_M26039
+		}
+#endif
+	} // Mode loop
     
 #if HHI_RQT_INTRA_SPEEDUP
@@ -6207,3 +6298,1277 @@
 }
 #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);
+		//printf("OffsetX %2d OffsetY %2d\n",uiOffsetX, uiOffsetY);
+	}
+
+	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
+			Bool   bSign0=false, bSign1=false, bSign2=false;
+			if( x > 0 && *(pbEdgeXPtr-1) == true )
+			{
+				if( *(psDiffXPtr-1) >= 0)
+				{
+					usAbs0 = *(psDiffXPtr-1);
+					bSign0 = true;
+				}
+				else
+				{
+					usAbs0 = (-1) * *(psDiffXPtr-1);
+					bSign0 = false;
+				}
+			}
+			if( *pbEdgeXPtr == true )
+			{
+				if( *(psDiffXPtr) >= 0)
+				{
+					usAbs1 = *(psDiffXPtr);
+					bSign1 = true;
+				}
+				else
+				{
+					usAbs1 = (-1) * *(psDiffXPtr);
+					bSign1 = false;
+				}
+			}
+			if( x < iWidth-2 && *(pbEdgeXPtr+1) == true )
+			{
+				if( *(psDiffXPtr+1) >= 0)
+				{
+					usAbs2 = *(psDiffXPtr+1);
+					bSign2 = true;
+				}
+				else
+				{
+					usAbs2 = (-1) * *(psDiffXPtr+1);
+					bSign2 = false;
+				}
+			}
+
+			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
+			Bool   bSign0=false, bSign1=false, bSign2=false;
+			if( y > 0 && *(pbEdgeYPtr-iWidth) == true )
+			{
+				if( *(psDiffYPtr-iWidth) >= 0)
+				{
+					usAbs0 = *(psDiffYPtr-iWidth);
+					bSign0 = true;
+				}
+				else
+				{
+					usAbs0 = (-1) * *(psDiffYPtr-iWidth);
+					bSign0 = false;
+				}
+			}
+			if( *pbEdgeYPtr == true )
+			{
+				if( *(psDiffYPtr) >= 0)
+				{
+					usAbs1 = *(psDiffYPtr);
+					bSign1 = true;
+				}
+				else
+				{
+					usAbs1 = (-1) * *(psDiffYPtr);
+					bSign1 = false;
+				}
+			}
+			if( y < iHeight-2 && *(pbEdgeYPtr+iWidth) == true )
+			{
+				if( *(psDiffYPtr+iWidth) >= 0)
+				{
+					usAbs2 = *(psDiffYPtr+iWidth);
+					bSign2 = true;
+				}
+				else
+				{
+					usAbs2 = (-1) * *(psDiffYPtr+iWidth);
+					bSign2 = false;
+				}
+			}
+
+			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++;
+		}
+	}
+
+#if 0
+	// Loop Edge Pruning (permit only single chain)
+	/// Step 1. Stack push the boundary edges
+	UShort* pusBoundaryStack = new UShort[ iWidth + iHeight ];
+	Int iBoundaryStackPtr = 0;
+	for( Int i = iHeight - 1; i >= 0; i-- )
+	{
+		if( pbCUEdge[ i * iWidth ] )
+		{
+			pusBoundaryStack[iBoundaryStackPtr] = (i << 8);
+			iBoundaryStackPtr++;
+		}
+	}
+	for( Int i = iWidth - 1; i >= 0; i-- )
+	{
+		if( pbCUEdge[ i ] )
+		{
+			pusBoundaryStack[iBoundaryStackPtr] = i;
+			iBoundaryStackPtr++;
+		}
+	}
+
+	/// Step 2. Traverse edges
+	Bool      bFound = false;
+	//Bool*    pbVisit = new Bool[ iWidth * iHeight ];
+
+	for( Int i = iBoundaryStackPtr - 1; i >= 0 && !bFound; i-- )
+	{
+		//Int iX, iY;
+		Int iStartX, iStartY;
+		Bool*  pbStacked = new Bool[ iWidth * iHeight ];
+		UShort* pusStack = new UShort[ iWidth * iHeight ];
+		Int iStackPtr = 0;
+
+		for( Int ii = 0; ii < iWidth * iHeight; ii++ )
+			pbVisit[ii] = false;
+		for( Int ii = 0; ii < iWidth * iHeight; ii++ )
+			pbStacked[ii] = false;
+
+		iStartX = iX = *(pusBoundaryStack + i) & 0xff;
+		iStartY = iY = *(pusBoundaryStack + i) >> 8;
+		pbStacked[ iX + iY * iWidth ] = true;
+		pusStack[iStackPtr++] = (iY << 8) | (iX);
+
+		while(!bFound)
+		{
+			//printf("(%d,%d) StackPtr %d\n",iX,iY,iStackPtr);
+			// right
+			if( iX < iWidth - 1 && !pbStacked[ (iX + 1) + iY * iWidth ] && pbCUEdge[ (iX + 1) + iY * iWidth ] )
+			{
+				iX = iX + 1;
+				pbStacked[ iX + iY * iWidth ] = true;
+				pusStack[iStackPtr] = (iY << 8) | (iX);
+				iStackPtr++;
+			}
+			// left
+			else if( iX > 0 && !pbStacked[ (iX - 1) + iY * iWidth ] && pbCUEdge[ (iX - 1) + iY * iWidth ] )
+			{
+				iX = iX - 1;
+				pbStacked[ iX + iY * iWidth ] = true;
+				pusStack[iStackPtr] = (iY << 8) | (iX);
+				iStackPtr++;
+			}
+			// bottom
+			else if( iY < iHeight - 1 && !pbStacked[ iX + (iY + 1) * iWidth ] && pbCUEdge[ iX + (iY + 1) * iWidth ] )
+			{
+				iY = iY + 1;
+				pbStacked[ iX + iY * iWidth ] = true;
+				pusStack[iStackPtr] = (iY << 8) | (iX);
+				iStackPtr++;
+			}
+			// top
+			else if( iY > 0 && !pbStacked[ iX + (iY - 1) * iWidth ] && pbCUEdge[ iX + (iY - 1) * iWidth ] )
+			{
+				iY = iY - 1;
+				pbStacked[ iX + iY * iWidth ] = true;
+				pusStack[iStackPtr] = (iY << 8) | (iX);
+				iStackPtr++;
+			}
+			// left-top
+			else if( iX > 0 && iY > 0 && !pbStacked[ (iX - 1) + (iY - 1) * iWidth ] && pbCUEdge[ (iX - 1) + (iY - 1) * iWidth])
+			{
+				iX = iX - 1;
+				iY = iY - 1;
+				pbStacked[ iX + iY * iWidth ] = true;
+				pusStack[iStackPtr] = (iY << 8) | (iX);
+				iStackPtr++;
+			}
+			// right-top
+			else if( iX < iWidth - 1 && iY > 0 && !pbStacked[ (iX + 1) + (iY - 1) * iWidth ] && pbCUEdge[ (iX + 1) + (iY - 1) * iWidth])
+			{
+				iX = iX + 1;
+				iY = iY - 1;
+				pbStacked[ iX + iY * iWidth ] = true;
+				pusStack[iStackPtr] = (iY << 8) | (iX);
+				iStackPtr++;
+			}
+			// left-bottom
+			else if( iX > 0 && iY < iHeight - 1 && !pbStacked[ (iX - 1) + (iY + 1) * iWidth ] && pbCUEdge[ (iX - 1) + (iY + 1) * iWidth])
+			{
+				iX = iX - 1;
+				iY = iY + 1;
+				pbStacked[ iX + iY * iWidth ] = true;
+				pusStack[iStackPtr] = (iY << 8) | (iX);
+				iStackPtr++;
+			}
+			// right-bottom
+			else if( iX < iWidth - 1 && iY < iHeight - 1 && !pbStacked[ (iX + 1) + (iY + 1) * iWidth ] && pbCUEdge[ (iX + 1) + (iY + 1) * iWidth])
+			{
+				iX = iX + 1;
+				iY = iY + 1;
+				pbStacked[ iX + iY * iWidth ] = true;
+				pusStack[iStackPtr] = (iY << 8) | (iX);
+				iStackPtr++;
+			}
+			else
+			{
+				if(iX == 0 || iY == 0 || iX == iWidth - 1 || iY == iHeight - 1 ) // boundary! (finished)
+				{
+					if( iX == iStartX && iY == iStartY )
+					{
+						//printf("return back to starting edge\n");
+						break; // not found!
+					}
+					for( Int ii = 0; ii < iStackPtr; ii++ )
+					{
+						Int iVisitX = pusStack[ii] & 0xff;
+						Int iVisitY = pusStack[ii] >> 8;
+						pbVisit[ iVisitX + iVisitY * iWidth ] = true;
+					}
+					bFound = true;
+					//printf("\nEdge Found!!\n");
+				}
+				else
+				{
+					pbCUEdge[ iX + iY * iWidth ] = false; // prune!
+					iStackPtr--;
+					iX = pusStack[iStackPtr-1] & 0xff;
+					iY = pusStack[iStackPtr-1] >> 8;
+					//printf("perform pruning!\n");
+				}
+			}
+		}
+		delete pbStacked;
+		delete pusStack;
+	} // result : pbVisit[]
+
+	// 3. Update Edge variable
+	for( Int i = 0; i < iWidth * iHeight; i++ )
+	{
+		pbCUEdge[ i ] = pbVisit[ i ];
+	}
+#endif
+
+	// 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: branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSearch.h	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSearch.h	(revision 97)
@@ -254,10 +254,14 @@
   
   Void  xIntraCodingLumaBlk       ( TComDataCU*  pcCU,
-                                    UInt         uiTrDepth,
-                                    UInt         uiAbsPartIdx,
-                                    TComYuv*     pcOrgYuv, 
-                                    TComYuv*     pcPredYuv, 
-                                    TComYuv*     pcResiYuv, 
-                                    Dist&        ruiDist );
+	  UInt         uiTrDepth,
+	  UInt         uiAbsPartIdx,
+	  TComYuv*     pcOrgYuv, 
+	  TComYuv*     pcPredYuv, 
+	  TComYuv*     pcResiYuv, 
+	  Dist&        ruiDist 
+#if LG_ZEROINTRADEPTHRESI_M26039
+	  ,Bool        bZeroResi = false
+#endif
+	  );
   Void  xIntraCodingChromaBlk     ( TComDataCU*  pcCU,
                                     UInt         uiTrDepth,
@@ -269,16 +273,20 @@
                                     UInt         uiChromaId );
   Void  xRecurIntraCodingQT       ( TComDataCU*  pcCU, 
-                                    UInt         uiTrDepth,
-                                    UInt         uiAbsPartIdx, 
-                                    Bool         bLumaOnly,
-                                    TComYuv*     pcOrgYuv, 
-                                    TComYuv*     pcPredYuv, 
-                                    TComYuv*     pcResiYuv, 
-                                    Dist&        ruiDistY,
-                                    Dist&        ruiDistC,
+	  UInt         uiTrDepth,
+	  UInt         uiAbsPartIdx, 
+	  Bool         bLumaOnly,
+	  TComYuv*     pcOrgYuv, 
+	  TComYuv*     pcPredYuv, 
+	  TComYuv*     pcResiYuv, 
+	  Dist&        ruiDistY,
+	  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, 
Index: branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 96)
+++ branches/HTM-3.1-LG/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 97)
@@ -627,4 +627,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
