Index: /branches/HTM-DEV-0.3-dev1/build/linux/lib/TLibCommon/makefile
===================================================================
--- /branches/HTM-DEV-0.3-dev1/build/linux/lib/TLibCommon/makefile	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/build/linux/lib/TLibCommon/makefile	(revision 459)
@@ -55,4 +55,5 @@
 			$(OBJ_DIR)/TComInterpolationFilter.o \
 			$(OBJ_DIR)/libmd5.o \
+			$(OBJ_DIR)/TComWedgelet.o \
 			$(OBJ_DIR)/TComWeightPrediction.o \
 			$(OBJ_DIR)/TComRdCostWeightPrediction.o \
Index: /branches/HTM-DEV-0.3-dev1/build/vc10/TLibCommon_vc10.vcxproj
===================================================================
--- /branches/HTM-DEV-0.3-dev1/build/vc10/TLibCommon_vc10.vcxproj	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/build/vc10/TLibCommon_vc10.vcxproj	(revision 459)
@@ -166,4 +166,5 @@
     <ClCompile Include="..\..\source\Lib\TLibCommon\TComSlice.cpp" />
     <ClCompile Include="..\..\source\Lib\TLibCommon\TComTrQuant.cpp" />
+    <ClCompile Include="..\..\source\Lib\TLibCommon\TComWedgelet.cpp" />
     <ClCompile Include="..\..\source\Lib\TLibCommon\TComWeightPrediction.cpp" />
     <ClCompile Include="..\..\source\Lib\TLibCommon\TComYuv.cpp" />
@@ -199,4 +200,5 @@
     <ClInclude Include="..\..\source\Lib\TLibCommon\TComSlice.h" />
     <ClInclude Include="..\..\source\Lib\TLibCommon\TComTrQuant.h" />
+    <ClInclude Include="..\..\source\Lib\TLibCommon\TComWedgelet.h" />
     <ClInclude Include="..\..\source\Lib\TLibCommon\TComWeightPrediction.h" />
     <ClInclude Include="..\..\source\Lib\TLibCommon\TComYuv.h" />
Index: /branches/HTM-DEV-0.3-dev1/build/vc8/TLibCommon_vc8.vcproj
===================================================================
--- /branches/HTM-DEV-0.3-dev1/build/vc8/TLibCommon_vc8.vcproj	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/build/vc8/TLibCommon_vc8.vcproj	(revision 459)
@@ -369,4 +369,8 @@
 			</File>
 			<File
+				RelativePath="..\..\source\Lib\TLibCommon\TComWedgelet.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\source\Lib\TLibCommon\TComWeightPrediction.cpp"
 				>
@@ -499,4 +503,8 @@
 			</File>
 			<File
+				RelativePath="..\..\source\Lib\TLibCommon\TComWedgelet.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\source\Lib\TLibCommon\TComWeightPrediction.h"
 				>
Index: /branches/HTM-DEV-0.3-dev1/build/vc9/TLibCommon_vc9.vcproj
===================================================================
--- /branches/HTM-DEV-0.3-dev1/build/vc9/TLibCommon_vc9.vcproj	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/build/vc9/TLibCommon_vc9.vcproj	(revision 459)
@@ -372,4 +372,8 @@
 			</File>
 			<File
+				RelativePath="..\..\source\Lib\TLibCommon\TComWedgelet.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\source\Lib\TLibCommon\TComWeightPrediction.cpp"
 				>
@@ -502,4 +506,8 @@
 			</File>
 			<File
+				RelativePath="..\..\source\Lib\TLibCommon\TComWedgelet.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\source\Lib\TLibCommon\TComWeightPrediction.h"
 				>
Index: /branches/HTM-DEV-0.3-dev1/cfg/3D-HEVC/baseCfg_2view+depth.cfg
===================================================================
--- /branches/HTM-DEV-0.3-dev1/cfg/3D-HEVC/baseCfg_2view+depth.cfg	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/cfg/3D-HEVC/baseCfg_2view+depth.cfg	(revision 459)
@@ -199,4 +199,8 @@
 #========== depth coding tools ==========
 VSO                       : 1                                      # use of view synthesis optimization for depth coding
+DMM                                : 1
+RBC                                : 1
+SDC                                : 1
+DLT                                : 1
 
 #========== view synthesis optimization (VSO) ==========
Index: /branches/HTM-DEV-0.3-dev1/cfg/3D-HEVC/baseCfg_3view+depth.cfg
===================================================================
--- /branches/HTM-DEV-0.3-dev1/cfg/3D-HEVC/baseCfg_3view+depth.cfg	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/cfg/3D-HEVC/baseCfg_3view+depth.cfg	(revision 459)
@@ -198,4 +198,8 @@
 #========== depth coding tools ==========
 VSO                       : 1                                      # use of view synthesis optimization for depth coding
+DMM                                : 1
+RBC                                : 1
+SDC                                : 1
+DLT                                : 1
 
 #========== view synthesis optimization (VSO) ==========
Index: /branches/HTM-DEV-0.3-dev1/cfg/3D-HEVC/fullCfg.cfg
===================================================================
--- /branches/HTM-DEV-0.3-dev1/cfg/3D-HEVC/fullCfg.cfg	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/cfg/3D-HEVC/fullCfg.cfg	(revision 459)
@@ -204,4 +204,8 @@
 #========== depth coding tools ==========
 VSO                       : 1                                      # use of view synthesis optimization for depth coding
+DMM                                : 1
+RBC                                : 1
+SDC                                : 1
+DLT                                : 1
 
 #========== view synthesis optimization (VSO) ==========
Index: /branches/HTM-DEV-0.3-dev1/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/App/TAppDecoder/TAppDecTop.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/App/TAppDecoder/TAppDecTop.cpp	(revision 459)
@@ -371,4 +371,7 @@
   // initialize global variables
   initROM();  
+#if H_3D_DIM_DMM
+  initWedgeLists();
+#endif
 #else
   // create decoder class
Index: /branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 459)
@@ -389,4 +389,10 @@
 #if H_3D
   ("DepthFlag",             m_depthFlag          , std::vector<Int>(1,0), "Depth Flag")
+#if H_3D_DIM
+  ("DMM",                   m_useDMM,           true,  "Depth intra model modes")
+  ("RBC",                   m_useRBC,           true,  "Region boundary chain mode")
+  ("SDC",                   m_useSDC,           true,  "Simplified depth coding")
+  ("DLT",                   m_useDLT,           true,  "Depth lookup table")
+#endif
 #endif
   ("LayerIdInNuh",          m_layerIdInNuh       , std::vector<Int>(1,0), "LayerId in Nuh")
@@ -2278,4 +2284,10 @@
   printf("WVSO:%d ", m_bUseWVSO );  
 #endif
+#if H_3D_DIM
+  printf("DMM:%d ", m_useDMM );
+  printf("RBC:%d ", m_useRBC );
+  printf("SDC:%d ", m_useSDC );
+  printf("DLT:%d ", m_useDLT );
+#endif
   printf("\n\n");  
 
Index: /branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncCfg.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncCfg.h	(revision 459)
@@ -405,4 +405,10 @@
   TRenModSetupStrParser       m_cRenModStrParser;
 #endif
+#if H_3D_DIM
+  Bool      m_useDMM;                                        ///< flag for using DMM
+  Bool      m_useRBC;                                        ///< flag for using RBC
+  Bool      m_useSDC;                                        ///< flag for using SDC
+  Bool      m_useDLT;                                        ///< flag for using DLT
+#endif
 #endif
   // internal member functions
Index: /branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncTop.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncTop.cpp	(revision 459)
@@ -120,4 +120,9 @@
   xSetDirectDependencyFlags( vps );
 #if H_3D
+  for( Int layer = 0; layer < m_numberOfLayers; layer++ )
+  {
+    vps.setVpsDepthModesFlag( layer, ((vps.getDepthId( layer ) != 0) && (m_useDMM || m_useRBC || m_useSDC || m_useDLT)) ? true : false );
+  }
+
   vps.initViewIndex(); 
   m_ivPicLists.setVPS      ( &vps ); 
@@ -166,4 +171,12 @@
     m_cTEncTop.setDWeight                      ( isDepth ? m_iDWeight             : 0     );
 #endif // H_3D_VSO
+
+  //========== Depth intra modes ==========
+#if H_3D_DIM
+    m_cTEncTop.setUseDMM                       ( isDepth ? m_useDMM               : false );
+    m_cTEncTop.setUseRBC                       ( isDepth ? m_useRBC               : false );
+    m_cTEncTop.setUseSDC                       ( isDepth ? m_useSDC               : false );
+    m_cTEncTop.setUseDLT                       ( isDepth ? m_useDLT               : false );
+#endif
 #endif // H_3D
 
@@ -543,4 +556,7 @@
   // initialize global variables
   initROM();
+#if H_3D_DIM_DMM
+  initWedgeLists( true );
+#endif
 
   for( Int layer=0; layer < m_numberOfLayers; layer++)
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/ContextTables.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/ContextTables.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/ContextTables.h	(revision 459)
@@ -97,4 +97,18 @@
 #define CNU                          154      ///< dummy initialization value for unused context models 'Context model Not Used'
 
+#if H_3D_DIM
+#define NUM_DEPTH_INTRA_MODE_CTX      8       ///< number of context models for depth intra modes
+#define NUM_DDC_FLAG_CTX              2       ///< number of context models for deltaDC flag (DMM or RBC)
+#define NUM_DDC_DATA_CTX              2       ///< number of context models for deltaDC data (DMM or RBC)
+#if H_3D_DIM_DMM
+#define NUM_DMM1_DATA_CTX             1       ///< number of context models for DMM1 data
+#define NUM_DMM2_DATA_CTX             1       ///< number of context models for DMM2 data
+#define NUM_DMM3_DATA_CTX             1       ///< number of context models for DMM3 data
+#endif
+#if H_3D_DIM_RBC
+#define NUM_RBC_DATA_CTX              1       ///< number of context models for RBC data
+#endif
+#endif
+
 // ====================================================================================================================
 // Tables
@@ -334,4 +348,60 @@
   { 139,  139}, 
 };
+
+#if H_3D_DIM
+static const UChar 
+INIT_DEPTH_INTRA_MODE[3][NUM_DEPTH_INTRA_MODE_CTX] =
+{
+  {0,  0,  64,   0, CNU,   0, CNU, 0},
+  {0, 64,   0, CNU,   0, CNU,   0, 0},
+  {64, 0, CNU,   0, CNU,   0,   0, 0}
+};
+static const UChar 
+INIT_DDC_FLAG[3][NUM_DDC_FLAG_CTX] =
+{
+  {0 , CNU},
+  {0 , CNU},
+  {64, CNU}
+};
+static const UChar
+INIT_DDC_DATA[3][NUM_DDC_DATA_CTX] = 
+{
+  { CNU, CNU }, 
+  { CNU, CNU }, 
+  { CNU, CNU }, 
+};
+#if H_3D_DIM_DMM
+static const UChar
+INIT_DMM1_DATA[3][NUM_DMM1_DATA_CTX] = 
+{
+  { CNU }, 
+  { CNU }, 
+  { CNU }, 
+};
+static const UChar
+INIT_DMM2_DATA[3][NUM_DMM2_DATA_CTX] = 
+{
+  { CNU }, 
+  { CNU }, 
+  { CNU }, 
+};
+static const UChar
+INIT_DMM3_DATA[3][NUM_DMM3_DATA_CTX] = 
+{
+  { CNU }, 
+  { CNU }, 
+  { CNU }, 
+};
+#endif
+#if H_3D_DIM_RBC
+static const UChar
+INIT_RBC_DATA[3][NUM_RBC_DATA_CTX] = 
+{
+  { CNU }, 
+  { CNU }, 
+  { CNU }, 
+};
+#endif
+#endif
 //! \}
 
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.cpp	(revision 459)
@@ -109,4 +109,27 @@
   m_apiMVPNum[1]       = NULL;
 
+#if H_3D_DIM
+  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
+  {
+    m_dimDeltaDC[i][0] = NULL; 
+    m_dimDeltaDC[i][1] = NULL;
+  }
+#if H_3D_DIM_DMM
+  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+  {
+    m_dmmWedgeTabIdx[i] = NULL;
+  }
+  m_dmm2DeltaEnd    = NULL;
+  m_dmm3IntraTabIdx = NULL;
+#endif
+#if H_3D_DIM_RBC
+  m_pucEdgeCode     = NULL;
+  m_pucEdgeNumber   = NULL;
+  m_pucEdgeStartPos = NULL;
+  m_pbEdgeLeftFirst = NULL;
+  m_pbEdgePartition = NULL;
+#endif
+#endif
+
   m_bDecSubCu          = false;
   m_sliceStartCU        = 0;
@@ -202,4 +225,26 @@
     m_acCUMvField[1].create( uiNumPartition );
     
+#if H_3D_DIM
+    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
+    {
+      m_dimDeltaDC[i][0] = (Pel* )xMalloc(Pel, uiNumPartition); 
+      m_dimDeltaDC[i][1] = (Pel* )xMalloc(Pel, uiNumPartition);
+    }
+#if H_3D_DIM_DMM
+    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+    {
+      m_dmmWedgeTabIdx[i]    = (UInt*)xMalloc(UInt, uiNumPartition);
+    }
+    m_dmm2DeltaEnd    = (Int* )xMalloc(Int,  uiNumPartition);
+    m_dmm3IntraTabIdx = (UInt*)xMalloc(UInt, uiNumPartition);
+#endif
+#if H_3D_DIM_RBC
+    m_pucEdgeCode     = (UChar*)xMalloc(UChar, uiNumPartition * RBC_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);
+#endif
+#endif
   }
   else
@@ -288,4 +333,26 @@
     m_acCUMvField[1].destroy();
     
+#if H_3D_DIM
+    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
+    {
+      if ( m_dimDeltaDC[i][0] ) { xFree( m_dimDeltaDC[i][0] ); m_dimDeltaDC[i][0] = NULL; }
+      if ( m_dimDeltaDC[i][1] ) { xFree( m_dimDeltaDC[i][1] ); m_dimDeltaDC[i][1] = NULL; }
+    }
+#if H_3D_DIM_DMM
+    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+    {
+      if ( m_dmmWedgeTabIdx[i] ) { xFree( m_dmmWedgeTabIdx[i] ); m_dmmWedgeTabIdx[i] = NULL; }
+    }
+    if ( m_dmm2DeltaEnd    ) { xFree( m_dmm2DeltaEnd    ); m_dmm2DeltaEnd    = NULL; }
+    if ( m_dmm3IntraTabIdx ) { xFree( m_dmm3IntraTabIdx ); m_dmm3IntraTabIdx = NULL; }
+#endif
+#if H_3D_DIM_RBC
+    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; }
+#endif
+#endif
   }
   
@@ -447,4 +514,27 @@
     memset( m_puhCbf[2]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[2] ) );
     memset( m_pbIPCMFlag        + firstElement, false,                    numElements * sizeof( *m_pbIPCMFlag ) );
+
+#if H_3D_DIM
+    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
+    {
+      memset( m_dimDeltaDC[i][0] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][0] ) );
+      memset( m_dimDeltaDC[i][1] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][1] ) );
+    }
+#if H_3D_DIM_DMM
+    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+    {
+      memset( m_dmmWedgeTabIdx[i] + firstElement, 0,                      numElements * sizeof( *m_dmmWedgeTabIdx[i] ) );
+    }
+    memset( m_dmm2DeltaEnd      + firstElement, 0,                        numElements * sizeof( *m_dmm2DeltaEnd    ) );
+    memset( m_dmm3IntraTabIdx   + firstElement, 0,                        numElements * sizeof( *m_dmm3IntraTabIdx ) );
+#endif
+#if H_3D_DIM_RBC
+    memset( m_pucEdgeCode       + firstElement, 0,                        numElements * sizeof( *m_pucEdgeCode     ) * RBC_MAX_EDGE_NUM_PER_4x4 );
+    memset( m_pucEdgeNumber     + firstElement, 0,                        numElements * sizeof( *m_pucEdgeNumber   ) );
+    memset( m_pucEdgeStartPos   + firstElement, 0,                        numElements * sizeof( *m_pucEdgeStartPos ) );
+    memset( m_pbEdgeLeftFirst   + firstElement, false,                    numElements * sizeof( *m_pbEdgeLeftFirst ) );
+    memset( m_pbEdgePartition   + firstElement, false,                    numElements * sizeof( *m_pbEdgePartition ) * 16 );
+#endif
+#endif
   }
   
@@ -582,4 +672,20 @@
       m_puhCbf[1][ui] = 0;
       m_puhCbf[2][ui] = 0;
+
+#if H_3D_DIM
+      for( Int i = 0; i < DIM_NUM_TYPE; i++ )
+      {
+        m_dimDeltaDC[i][0] [ui] = 0;
+        m_dimDeltaDC[i][1] [ui] = 0;
+      }
+#if H_3D_DIM_DMM
+      for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+      {
+        m_dmmWedgeTabIdx[i] [ui] = 0;
+      }
+      m_dmm2DeltaEnd    [ui] = 0;
+      m_dmm3IntraTabIdx [ui] = 0;
+#endif
+#endif
     }
   }
@@ -658,4 +764,28 @@
   memset( m_puhHeight,         uhHeight, iSizeInUchar );
   memset( m_pbIPCMFlag,        0, iSizeInBool  );
+  
+#if H_3D_DIM
+  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
+  {
+    memset( m_dimDeltaDC[i][0], 0, sizeof(Pel ) * m_uiNumPartition );
+    memset( m_dimDeltaDC[i][1], 0, sizeof(Pel ) * m_uiNumPartition );
+  }
+#if H_3D_DIM_DMM
+  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+  {
+    memset( m_dmmWedgeTabIdx[i], 0, sizeof(UInt) * m_uiNumPartition );
+  }
+  memset( m_dmm2DeltaEnd   , 0, sizeof(Int ) * m_uiNumPartition );
+  memset( m_dmm3IntraTabIdx, 0, sizeof(UInt) * m_uiNumPartition );
+#endif
+#if H_3D_DIM_RBC
+  memset( m_pucEdgeCode    , 0, iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
+  memset( m_pucEdgeNumber  , 0, iSizeInUchar );
+  memset( m_pucEdgeStartPos, 0, iSizeInUchar );
+  memset( m_pbEdgeLeftFirst, 0, iSizeInBool );
+  memset( m_pbEdgePartition, 0, iSizeInBool * 16 );
+#endif
+#endif
+ 
   for (UInt ui = 0; ui < m_uiNumPartition; ui++)
   {
@@ -696,4 +826,19 @@
       m_puhCbf[2][ui]=pcCU->m_puhCbf[2][uiPartOffset+ui];
 
+#if H_3D_DIM
+      for( Int i = 0; i < DIM_NUM_TYPE; i++ )
+      {
+        m_dimDeltaDC[i][0] [ui] = pcCU->m_dimDeltaDC[i][0] [uiPartOffset+ui];
+        m_dimDeltaDC[i][1] [ui] = pcCU->m_dimDeltaDC[i][1] [uiPartOffset+ui];
+      }
+#if H_3D_DIM_DMM
+      for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+      {
+        m_dmmWedgeTabIdx[i] [ui] = pcCU->m_dmmWedgeTabIdx[i] [uiPartOffset+ui];
+      }
+      m_dmm2DeltaEnd    [ui] = pcCU->m_dmm2DeltaEnd   [uiPartOffset+ui];
+      m_dmm3IntraTabIdx [ui] = pcCU->m_dmm3IntraTabIdx[uiPartOffset+ui];
+#endif
+#endif
     }
   }
@@ -815,4 +960,27 @@
   m_puhCbf[2]= pcCU->getCbf(TEXT_CHROMA_V)        + uiPart;
   
+#if H_3D_DIM
+  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
+  {
+    m_dimDeltaDC[i][0] = pcCU->getDimDeltaDC( i, 0 ) + uiPart;
+    m_dimDeltaDC[i][1] = pcCU->getDimDeltaDC( i, 1 ) + uiPart;
+  }
+#if H_3D_DIM_DMM
+  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+  {
+    m_dmmWedgeTabIdx[i] = pcCU->getDmmWedgeTabIdx( i ) + uiPart;
+  }
+  m_dmm2DeltaEnd    = pcCU->getDmm2DeltaEnd()    + uiPart;
+  m_dmm3IntraTabIdx = pcCU->getDmm3IntraTabIdx() + uiPart;
+#endif
+#if H_3D_DIM_RBC
+  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 );
+#endif
+#endif
+
   m_puhDepth=pcCU->getDepth()                     + uiPart;
   m_puhWidth=pcCU->getWidth()                     + uiPart;
@@ -942,4 +1110,27 @@
   memcpy( m_puhCbf[2] + uiOffset, pcCU->getCbf(TEXT_CHROMA_V), iSizeInUchar );
   
+#if H_3D_DIM
+  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
+  {
+    memcpy( m_dimDeltaDC[i][0] + uiOffset, pcCU->getDimDeltaDC( i, 0 ), sizeof(Pel ) * uiNumPartition );
+    memcpy( m_dimDeltaDC[i][1] + uiOffset, pcCU->getDimDeltaDC( i, 1 ), sizeof(Pel ) * uiNumPartition );
+  }
+#if H_3D_DIM_DMM
+  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+  {
+    memcpy( m_dmmWedgeTabIdx[i] + uiOffset, pcCU->getDmmWedgeTabIdx( i ), sizeof(UInt) * uiNumPartition );
+  }
+  memcpy( m_dmm2DeltaEnd    + uiOffset, pcCU->getDmm2DeltaEnd()   , sizeof(Int ) * uiNumPartition );
+  memcpy( m_dmm3IntraTabIdx + uiOffset, pcCU->getDmm3IntraTabIdx(), sizeof(UInt) * uiNumPartition );
+#endif
+#if H_3D_DIM_RBC
+  memcpy( getEdgeCode( uiOffset ),       pcCU->getEdgeCode(0),      iSizeInUchar * RBC_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 );
+#endif
+#endif
+
   memcpy( m_puhDepth  + uiOffset, pcCU->getDepth(),  iSizeInUchar );
   memcpy( m_puhWidth  + uiOffset, pcCU->getWidth(),  iSizeInUchar );
@@ -1022,4 +1213,27 @@
   memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhCbf[2], iSizeInUchar );
   
+#if H_3D_DIM
+  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
+  {
+    memcpy( rpcCU->getDimDeltaDC( i, 0 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][0], sizeof(Pel ) * m_uiNumPartition );
+    memcpy( rpcCU->getDimDeltaDC( i, 1 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][1], sizeof(Pel ) * m_uiNumPartition );
+  }
+#if H_3D_DIM_DMM
+  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+  {
+    memcpy( rpcCU->getDmmWedgeTabIdx( i ) + m_uiAbsIdxInLCU, m_dmmWedgeTabIdx[i], sizeof(UInt) * m_uiNumPartition );
+  }
+  memcpy( rpcCU->getDmm2DeltaEnd()    + m_uiAbsIdxInLCU, m_dmm2DeltaEnd   , sizeof(Int ) * m_uiNumPartition );
+  memcpy( rpcCU->getDmm3IntraTabIdx() + m_uiAbsIdxInLCU, m_dmm3IntraTabIdx, sizeof(UInt) * m_uiNumPartition );
+#endif
+#if H_3D_DIM_RBC
+  memcpy( rpcCU->getEdgeCode( m_uiAbsIdxInLCU ),         m_pucEdgeCode,     iSizeInUchar * RBC_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 );
+#endif
+#endif
+
   memcpy( rpcCU->getDepth()  + m_uiAbsIdxInLCU, m_puhDepth,  iSizeInUchar );
   memcpy( rpcCU->getWidth()  + m_uiAbsIdxInLCU, m_puhWidth,  iSizeInUchar );
@@ -1093,4 +1307,27 @@
   memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + uiPartOffset, m_puhCbf[2], iSizeInUchar );
   
+#if H_3D_DIM
+  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+  {
+    memcpy( rpcCU->getDimDeltaDC( i, 0 ) + uiPartOffset, m_dimDeltaDC[i][0], sizeof(Pel ) * uiQNumPart );
+    memcpy( rpcCU->getDimDeltaDC( i, 1 ) + uiPartOffset, m_dimDeltaDC[i][1], sizeof(Pel ) * uiQNumPart );
+  }
+#if H_3D_DIM_DMM
+  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
+  {
+    memcpy( rpcCU->getDmmWedgeTabIdx( i ) + uiPartOffset, m_dmmWedgeTabIdx[i], sizeof(UInt) * uiQNumPart );
+  }
+  memcpy( rpcCU->getDmm2DeltaEnd()    + uiPartOffset, m_dmm2DeltaEnd   , sizeof(Int ) * uiQNumPart );
+  memcpy( rpcCU->getDmm3IntraTabIdx() + uiPartOffset, m_dmm3IntraTabIdx, sizeof(UInt) * uiQNumPart );
+#endif
+#if H_3D_DIM_RBC
+  memcpy( rpcCU->getEdgeCode( uiPartOffset ),         m_pucEdgeCode,     iSizeInUchar * RBC_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 );
+#endif
+#endif
+
   memcpy( rpcCU->getDepth()  + uiPartOffset, m_puhDepth,  iSizeInUchar );
   memcpy( rpcCU->getWidth()  + uiPartOffset, m_puhWidth,  iSizeInUchar );
@@ -1648,4 +1885,7 @@
   
   iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
+#if H_3D_DIM
+  mapDepthModeToIntraDir( iLeftIntraDir );
+#endif
   
   // Get intra direction of above PU
@@ -1653,4 +1893,7 @@
   
   iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
+#if H_3D_DIM
+  mapDepthModeToIntraDir( iAboveIntraDir );
+#endif
   
   uiPredNum = 3;
@@ -3437,4 +3680,7 @@
   {
     uiDirMode = getLumaIntraDir(uiAbsPartIdx);
+#if H_3D_DIM
+    mapDepthModeToIntraDir( uiDirMode );
+#endif
     uiScanIdx = SCAN_DIAG;
     if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
@@ -3454,4 +3700,7 @@
       // get luma mode from upper-left corner of current CU
       uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
+#if H_3D_DIM
+      mapDepthModeToIntraDir( uiDirMode );
+#endif
     }
     uiScanIdx = SCAN_DIAG;
@@ -3845,4 +4094,642 @@
   riPosY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelY();  
 }
+#if H_3D_DIM_DMM
+Void TComDataCU::setDmmWedgeTabIdxSubParts( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
+  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
+}
+Void  TComDataCU::setDmm2DeltaEndSubParts( Int iDelta, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
+  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm2DeltaEnd[uiAbsPartIdx+ui] = iDelta; }
+}
+Void  TComDataCU::setDmm3IntraTabIdxSubParts( UInt uiTIdx, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
+  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm3IntraTabIdx[uiAbsPartIdx+ui] = uiTIdx; }
+}
+#endif
+#if H_3D_DIM_RBC
+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("reconPartiton: 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
 #endif
 
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.h	(revision 459)
@@ -188,4 +188,20 @@
   Bool*         m_pbIPCMFlag;         ///< array of intra_pcm flags
 
+#if H_3D_DIM
+  Pel*          m_dimDeltaDC[DIM_NUM_TYPE][2];
+#if H_3D_DIM_DMM
+  UInt*         m_dmmWedgeTabIdx[DMM_NUM_TYPE]; 
+  Int*          m_dmm2DeltaEnd;
+  UInt*         m_dmm3IntraTabIdx;
+#endif
+#if H_3D_DIM_RBC
+  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
+#endif
+#endif
+  
   // -------------------------------------------------------------------------------------------------------------------
   // misc. variables
@@ -406,4 +422,46 @@
                                           ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
                                           ,Bool bIndependentTileBoundaryEnabled );
+  
+#if H_3D_DIM
+  Pel*  getDimDeltaDC                 ( UInt dimType, UInt segId )                      { return m_dimDeltaDC[dimType][segId];        } 
+  Pel   getDimDeltaDC                 ( UInt dimType, UInt segId, UInt uiIdx )          { return m_dimDeltaDC[dimType][segId][uiIdx]; } 
+  Void  setDimDeltaDC                 ( UInt dimType, UInt segId, UInt uiIdx, Pel val ) { m_dimDeltaDC[dimType][segId][uiIdx] = val;  }
+#if H_3D_DIM_DMM
+  UInt* getDmmWedgeTabIdx             ( UInt dmmType )                          { return m_dmmWedgeTabIdx[dmmType];          }        
+  UInt  getDmmWedgeTabIdx             ( UInt dmmType, UInt uiIdx )              { return m_dmmWedgeTabIdx[dmmType][uiIdx];   }
+  Void  setDmmWedgeTabIdx             ( UInt dmmType, UInt uiIdx, UInt tabIdx ) { m_dmmWedgeTabIdx[dmmType][uiIdx] = tabIdx; }
+  Void  setDmmWedgeTabIdxSubParts     ( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth );
+
+  Int*  getDmm2DeltaEnd               ()                      { return m_dmm2DeltaEnd;        }
+  Int   getDmm2DeltaEnd               ( UInt uiIdx )          { return m_dmm2DeltaEnd[uiIdx]; }
+  Void  setDmm2DeltaEnd               ( UInt uiIdx, Int iD )  { m_dmm2DeltaEnd[uiIdx] = iD;   }
+  Void  setDmm2DeltaEndSubParts       ( Int iDelta, UInt uiAbsPartIdx, UInt uiDepth );
+
+  UInt* getDmm3IntraTabIdx            ()                      { return m_dmm3IntraTabIdx;        }
+  UInt  getDmm3IntraTabIdx            ( UInt uiIdx )          { return m_dmm3IntraTabIdx[uiIdx]; }
+  Void  setDmm3IntraTabIdx            ( UInt uiIdx, UInt uh ) { m_dmm3IntraTabIdx[uiIdx] = uh;   }
+  Void  setDmm3IntraTabIdxSubParts    ( UInt uiTIdx, UInt uiAbsPartIdx, UInt uiDepth );
+#endif
+#if H_3D_DIM_RBC
+  UChar* getEdgeCode( UInt uiIdx )                 { return &m_pucEdgeCode[uiIdx * RBC_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 );
+#endif
+#endif
+
   // -------------------------------------------------------------------------------------------------------------------
   // member functions for accessing partition information
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.cpp	(revision 459)
@@ -386,4 +386,128 @@
 }
 
+#if H_3D_DIM
+Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc )
+{
+  assert( iWidth == iHeight  );
+  assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
+  assert( isDimMode( uiIntraMode ) );
+
+  UInt dimType    = getDimType  ( uiIntraMode );
+  Bool dimDeltaDC = isDimDeltaDC( uiIntraMode );    
+  Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
+  Bool isRbcMode  = (dimType == RBC_IDX);
+
+  Bool* biSegPattern  = NULL;
+  UInt  patternStride = 0;
+
+  // get partiton
+#if H_3D_DIM_DMM
+  TComWedgelet* dmmSegmentation = NULL;
+  if( isDmmMode )
+  {
+    switch( dimType )
+    {
+    case( DMM1_IDX ): 
+      {
+        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
+      } break;
+    case( DMM2_IDX ):
+      {
+        UInt uiTabIdx = 0;
+        if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); }
+        else
+        {
+          uiTabIdx = xPredWedgeFromIntra( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm2DeltaEnd( uiAbsPartIdx ) );
+          pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) );
+        }
+        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]);
+      } break;
+    case( DMM3_IDX ): 
+      {
+        UInt uiTabIdx = 0;
+        if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); }
+        else
+        {
+          uiTabIdx = xPredWedgeFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm3IntraTabIdx( uiAbsPartIdx ) );
+          pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) );
+        }
+        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]);
+      } break;
+    case( DMM4_IDX ): 
+      {
+        dmmSegmentation = new TComWedgelet( iWidth, iHeight );
+        xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
+      } break;
+    default: assert(0);
+    }
+    assert( dmmSegmentation );
+    biSegPattern  = dmmSegmentation->getPattern();
+    patternStride = dmmSegmentation->getStride ();
+  }
+#endif
+#if H_3D_DIM_RBC
+  if( isRbcMode )
+  {
+    biSegPattern  = pcCU->getEdgePartition( uiAbsPartIdx );
+    patternStride = iWidth;
+  }
+#endif
+
+  // get predicted partition values
+  assert( biSegPattern );
+  Int* piMask = NULL;
+  if( isDmmMode ) piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering for DMM
+  else            piMask = pcCU->getPattern()->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
+  assert( piMask );
+  Int maskStride = 2*iWidth + 1;  
+  Int* ptrSrc = piMask+maskStride+1;
+  Pel predDC1 = 0; Pel predDC2 = 0;
+  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
+
+  // set segment values with deltaDC offsets
+  Pel segDC1 = 0;
+  Pel segDC2 = 0;
+  if( dimDeltaDC )
+  {
+    Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx );
+    Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx );
+#if H_3D_DIM_DMM
+    if( isDmmMode )
+    {
+#if H_3D_DIM_DLT
+      segDC1 = GetIdx2DepthValue( GetDepthValue2Idx( predDC1 ) + deltaDC1 );
+      segDC2 = GetIdx2DepthValue( GetDepthValue2Idx( predDC2 ) + deltaDC2 );
+#else
+      segDC1 = ClipY( predDC1 + deltaDC1 );
+      segDC2 = ClipY( predDC2 + deltaDC2 );
+#endif
+    }
+#endif
+#if H_3D_DIM_RBC
+    if( isRbcMode )
+    {
+      xDeltaDCQuantScaleUp( pcCU, deltaDC1 );
+      xDeltaDCQuantScaleUp( pcCU, deltaDC2 );
+      segDC1 = ClipY( predDC1 + deltaDC1 );
+      segDC2 = ClipY( predDC2 + deltaDC2 );
+    }
+#endif
+  }
+  else
+  {
+    segDC1 = predDC1;
+    segDC2 = predDC2;
+  }
+
+  // set prediction signal
+  Pel* pDst = piPred;
+  xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
+
+#if H_3D_DIM_DMM
+  if( dimType == DMM4_IDX ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
+#endif
+}
+#endif
+
 /** Function for checking identical motion.
  * \param TComDataCU* pcCU
@@ -758,3 +882,601 @@
   return;
 }
+
+#if H_3D_DIM
+Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
+{
+  Int  refDC1, refDC2;
+  const Int  iTR = (   patternStride - 1        ) - srcStride;
+  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
+  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
+  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
+
+  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
+  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
+
+  if( bL == bT )
+  {
+    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 );
+    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
+  }
+  else
+  {
+    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
+    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
+  }
+
+  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
+  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
+}
+
+Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
+{
+  if( dstStride == patternStride )
+  {
+    for( UInt k = 0; k < (patternStride * patternStride); k++ )
+    {
+      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
+      else                          { ptrDst[k] = valDC1; }
+    }
+  }
+  else
+  {
+    Pel* piTemp = ptrDst;
+    for( UInt uiY = 0; uiY < patternStride; uiY++ )
+    {
+      for( UInt uiX = 0; uiX < patternStride; uiX++ )
+      {
+        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
+        else                            { piTemp[uiX] = valDC1; }
+      }
+      piTemp       += dstStride;
+      biSegPattern += patternStride;
+    }
+  }
+}
+
+#if H_3D_DIM_DMM
+UInt TComPrediction::xPredWedgeFromIntra( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd )
+{
+  UInt uiThisBlockSize = uiWidth;
+
+  TComDataCU* pcTempCU;
+  UInt        uiTempPartIdx;
+  // 1st: try continue above wedgelet
+  pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
+  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
+  {
+    UInt dimType =  getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
+    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
+    {
+      // get offset between current and reference block
+      UInt uiOffsetX = 0, uiOffsetY = 0;
+      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
+
+      // get reference wedgelet
+      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
+      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
+
+      // find wedgelet, if direction is suitable for continue wedge
+      if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) )
+      {
+        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
+        pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd );
+        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
+      }
+    }
+  }
+
+  // 2nd: try continue left wedglelet
+  pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
+  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
+  {
+    UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
+    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
+    {
+      // get offset between current and reference block
+      UInt uiOffsetX = 0, uiOffsetY = 0;
+      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
+
+      // get reference wedgelet
+      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
+      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
+
+      // find wedgelet, if direction is suitable for continue wedge
+      if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) )
+      {
+        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
+        pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd );
+        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
+      }
+    }
+  }
+
+  // 3rd: (default) make wedglet from intra dir and max slope point
+  Int iSlopeX = 0, iSlopeY = 0;
+  UInt uiStartPosX = 0, uiStartPosY = 0;
+  if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) )
+  {
+    UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
+    xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd );
+    return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
+  }
+
+  return 0;
+}
+
+UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx )
+{
+  TComPic*      pcPicTex = pcCU->getSlice()->getPicLists()->getPic( pcCU->getSlice()->getViewIndex(), false, pcCU->getSlice()->getPOC() );
+  assert( pcPicTex != NULL );
+  TComDataCU*   pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
+  UInt          uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
+  Int           uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
+
+  if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) { return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx); }
+  else                                                     { return g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])].at(intraTabIdx).getPatternIdx(); }
+}
+
+Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
+{
+  pcContourWedge->clear();
+
+  // get copy of co-located texture luma block
+  TComYuv cTempYuv;
+  cTempYuv.create( uiWidth, uiHeight ); 
+  cTempYuv.clear();
+  Pel* piRefBlkY = cTempYuv.getLumaAddr();
+  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
+  piRefBlkY = cTempYuv.getLumaAddr();
+
+  // find contour for texture luma block
+  UInt iDC = 0;
+  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
+  { 
+    iDC += piRefBlkY[k]; 
+  }
+  iDC /= (uiWidth*uiHeight);
+  piRefBlkY = cTempYuv.getLumaAddr();
+
+  Bool* pabContourPattern = pcContourWedge->getPattern();
+  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
+  { 
+    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
+  }
+
+  cTempYuv.destroy();
+}
+
+
+Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
+{
+  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getPicLists()->getPic( pcCU->getSlice()->getViewIndex(), false, pcCU->getSlice()->getPOC() )->getPicYuvRec();
+  assert( pcPicYuvRef != NULL );
+  Int         iRefStride = pcPicYuvRef->getStride();
+  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
+
+  for ( Int y = 0; y < uiHeight; y++ )
+  {
+    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
+    piDestBlockY += uiWidth;
+    piRefY += iRefStride;
+  }
+}
+
+Void TComPrediction::xGetBlockOffset( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY )
+{
+  ruiOffsetX = 0;
+  ruiOffsetY = 0;
+
+  // get offset between current and above/left block
+  UInt uiThisOriginX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
+  UInt uiThisOriginY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
+
+  UInt uiNumPartInRefCU = pcRefCU->getTotalNumPart();
+  UInt uiMaxDepthRefCU = 0;
+  while( uiNumPartInRefCU > 1 )
+  {
+    uiNumPartInRefCU >>= 2;
+    uiMaxDepthRefCU++;
+  }
+
+  UInt uiDepthRefPU = (pcRefCU->getDepth(uiRefAbsPartIdx)) + (pcRefCU->getPartitionSize(uiRefAbsPartIdx) == SIZE_2Nx2N ? 0 : 1);
+  UInt uiShifts = (uiMaxDepthRefCU - uiDepthRefPU)*2;
+  UInt uiRefBlockOriginPartIdx = (uiRefAbsPartIdx>>uiShifts)<<uiShifts;
+
+  UInt uiRefOriginX = pcRefCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
+  UInt uiRefOriginY = pcRefCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
+
+  if( (uiThisOriginX - uiRefOriginX) > 0 ) { ruiOffsetX = (UInt)(uiThisOriginX - uiRefOriginX); }
+  if( (uiThisOriginY - uiRefOriginY) > 0 ) { ruiOffsetY = (UInt)(uiThisOriginY - uiRefOriginY); }
+}
+
+Bool TComPrediction::xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY )
+{
+  riSlopeX = 0, riSlopeY = 0, ruiStartPosX = 0, ruiStartPosY = 0;
+
+  // 1st step: get wedge start point (max. slope)
+  Int* piSource = pcCU->getPattern()->getAdiOrgBuf( uiBlockSize, uiBlockSize, m_piYuvExt );
+  Int iSourceStride = ( uiBlockSize<<1 ) + 1;
+
+  UInt uiSlopeMaxAbove = 0, uiPosSlopeMaxAbove = 0;
+  for( UInt uiPosHor = 0; uiPosHor < (uiBlockSize-1); uiPosHor++ )
+  {
+    if( abs( piSource[uiPosHor+1] - piSource[uiPosHor] ) > uiSlopeMaxAbove )
+    {
+      uiSlopeMaxAbove = abs( piSource[uiPosHor+1] - piSource[uiPosHor] );
+      uiPosSlopeMaxAbove = uiPosHor;
+    }
+  }
+
+  UInt uiSlopeMaxLeft = 0, uiPosSlopeMaxLeft = 0;
+  for( UInt uiPosVer = 0; uiPosVer < (uiBlockSize-1); uiPosVer++ )
+  {
+    if( abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ) > uiSlopeMaxLeft )
+    {
+      uiSlopeMaxLeft = abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] );
+      uiPosSlopeMaxLeft = uiPosVer;
+    }
+  }
+
+  if( uiSlopeMaxAbove == 0 && uiSlopeMaxLeft == 0 ) 
+  { 
+    return false; 
+  }
+
+  ruiStartPosX = ( uiSlopeMaxAbove >  uiSlopeMaxLeft  ) ? uiPosSlopeMaxAbove : 0;
+  ruiStartPosY = ( uiSlopeMaxLeft  >= uiSlopeMaxAbove ) ? uiPosSlopeMaxLeft  : 0;
+
+  // 2nd step: derive wedge direction
+  Int uiPreds[3] = {-1, -1, -1};
+  Int iMode = -1;
+  Int iPredNum = pcCU->getIntraDirLumaPredictor( uiAbsPartIdx, uiPreds, &iMode );  
+
+  UInt uiDirMode = 0;
+  if( iMode >= 0 ) { iPredNum = iMode; }
+  if( iPredNum == 1 ) { uiDirMode = uiPreds[0]; }
+  if( iPredNum == 2 ) { uiDirMode = uiPreds[1]; }
+
+  if( uiDirMode < 2 ) { return false; } // no planar & DC
+
+  Bool modeHor       = (uiDirMode < 18);
+  Bool modeVer       = !modeHor;
+  Int intraPredAngle = modeVer ? (Int)uiDirMode - VER_IDX : modeHor ? -((Int)uiDirMode - HOR_IDX) : 0;
+  Int absAng         = abs(intraPredAngle);
+  Int signAng        = intraPredAngle < 0 ? -1 : 1;
+  Int angTable[9]    = {0,2,5,9,13,17,21,26,32};
+  absAng             = angTable[absAng];
+  intraPredAngle     = signAng * absAng;
+
+  // 3rd step: set slope for direction
+  if( modeHor )
+  {
+    riSlopeX = ( intraPredAngle > 0 ) ?            -32 :              32;
+    riSlopeY = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
+  }
+  else if( modeVer )
+  {
+    riSlopeX = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
+    riSlopeY = ( intraPredAngle > 0 ) ?            -32 :              32;
+  }
+
+  return true;
+}
+
+Void TComPrediction::xGetWedgeIntraDirStartEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int iDeltaX, Int iDeltaY, UInt uiPMSPosX, UInt uiPMSPosY, UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, Int iDeltaEnd )
+{
+  ruhXs = 0;
+  ruhYs = 0;
+  ruhXe = 0;
+  ruhYe = 0;
+
+  // scaling of start pos and block size to wedge resolution
+  UInt uiScaledStartPosX = 0;
+  UInt uiScaledStartPosY = 0;
+  UInt uiScaledBlockSize = 0;
+  WedgeResolution eWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiBlockSize]];
+  switch( eWedgeRes )
+  {
+  case( DOUBLE_PEL ): { uiScaledStartPosX = (uiPMSPosX>>1); uiScaledStartPosY = (uiPMSPosY>>1); uiScaledBlockSize = (uiBlockSize>>1); break; }
+  case(   FULL_PEL ): { uiScaledStartPosX =  uiPMSPosX;     uiScaledStartPosY =  uiPMSPosY;     uiScaledBlockSize =  uiBlockSize;     break; }
+  case(   HALF_PEL ): { uiScaledStartPosX = (uiPMSPosX<<1); uiScaledStartPosY = (uiPMSPosY<<1); uiScaledBlockSize = (uiBlockSize<<1); break; }
+  }
+  Int iMaxPos = (Int)uiScaledBlockSize - 1;
+
+  // case above
+  if( uiScaledStartPosX > 0 && uiScaledStartPosY == 0 )
+  {
+    ruhXs = (UChar)uiScaledStartPosX;
+    ruhYs = 0;
+
+    if( iDeltaY == 0 )
+    {
+      if( iDeltaX < 0 )
+      {
+        ruhXe = 0;
+        ruhYe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos );
+        return;
+      }
+      else
+      {
+        ruhXe = (UChar)iMaxPos;
+        ruhYe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos );
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+    }
+
+    // regular case
+    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) );
+
+    if( iVirtualEndX < 0 )
+    {
+      Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) + iDeltaEnd;
+      if( iYe < (Int)uiScaledBlockSize )
+      {
+        ruhXe = 0;
+        ruhYe = (UChar)std::max( iYe, 0 );
+        return;
+      }
+      else
+      {
+        ruhXe = (UChar)std::min( (iYe - iMaxPos), iMaxPos );
+        ruhYe = (UChar)iMaxPos;
+        return;
+      }
+    }
+    else if( iVirtualEndX > iMaxPos )
+    {
+      Int iYe = roftoi( (Double)(iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
+      if( iYe < (Int)uiScaledBlockSize )
+      {
+        ruhXe = (UChar)iMaxPos;
+        ruhYe = (UChar)std::max( iYe, 0 );
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+      else
+      {
+        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
+        ruhYe = (UChar)iMaxPos;
+        return;
+      }
+    }
+    else
+    {
+      Int iXe = iVirtualEndX + iDeltaEnd;
+      if( iXe < 0 )
+      {
+        ruhXe = 0;
+        ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 );
+        return;
+      }
+      else if( iXe > iMaxPos )
+      {
+        ruhXe = (UChar)iMaxPos;
+        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+      else
+      {
+        ruhXe = (UChar)iXe;
+        ruhYe = (UChar)iMaxPos;
+        return;
+      }
+    }
+  }
+
+  // case left
+  if( uiScaledStartPosY > 0 && uiScaledStartPosX == 0 )
+  {
+    ruhXs = 0;
+    ruhYs = (UChar)uiScaledStartPosY;
+
+    if( iDeltaX == 0 )
+    {
+      if( iDeltaY < 0 )
+      {
+        ruhXe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos );
+        ruhYe = 0;
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+      else
+      {
+        ruhXe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos );
+        ruhYe = (UChar)iMaxPos;
+        return; 
+      }
+    }
+
+    // regular case
+    Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iMaxPos * ((Double)iDeltaY / (Double)iDeltaX) );
+
+    if( iVirtualEndY < 0 )
+    {
+      Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) - iDeltaEnd;
+      if( iXe < (Int)uiScaledBlockSize )
+      {
+        ruhXe = (UChar)std::max( iXe, 0 );
+        ruhYe = 0;
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+      else
+      {
+        ruhXe = (UChar)iMaxPos;
+        ruhYe = (UChar)std::min( (iXe - iMaxPos), iMaxPos );
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+    }
+    else if( iVirtualEndY > (uiScaledBlockSize-1) )
+    {
+      Int iXe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) + iDeltaEnd;
+      if( iXe < (Int)uiScaledBlockSize )
+      {
+        ruhXe = (UChar)std::max( iXe, 0 );
+        ruhYe = (UChar)(uiScaledBlockSize-1);
+        return;
+      }
+      else
+      {
+        ruhXe = (UChar)iMaxPos;
+        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+    }
+    else
+    {
+      Int iYe = iVirtualEndY - iDeltaEnd;
+      if( iYe < 0 )
+      {
+        ruhXe = (UChar)std::max( (iMaxPos + iYe), 0 );
+        ruhYe = 0;
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+      else if( iYe > iMaxPos )
+      {
+        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
+        ruhYe = (UChar)iMaxPos;
+        return;
+      }
+      else
+      {
+        ruhXe = (UChar)iMaxPos;
+        ruhYe = (UChar)iYe;
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+    }
+  }
+
+  // case origin
+  if( uiScaledStartPosX == 0 && uiScaledStartPosY == 0 )
+  {
+    if( iDeltaX*iDeltaY < 0 )
+    {
+      return;
+    }
+
+    ruhXs = 0;
+    ruhYs = 0;
+
+    if( iDeltaY == 0 )
+    {
+      ruhXe = (UChar)iMaxPos;
+      ruhYe = 0;
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+
+    if( iDeltaX == 0 )
+    {
+      ruhXe = 0;
+      ruhYe = (UChar)iMaxPos;
+      return;
+    }
+
+    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) );
+
+    if( iVirtualEndX > iMaxPos )
+    {
+      Int iYe = roftoi( (Double)((Int)iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
+      if( iYe < (Int)uiScaledBlockSize )
+      {
+        ruhXe = (UChar)(uiScaledBlockSize-1);
+        ruhYe = (UChar)std::max( iYe, 0 );
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+      else
+      {
+        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
+        ruhYe = (UChar)(uiScaledBlockSize-1);
+        return;
+      }
+    }
+    else
+    {
+      Int iXe = iVirtualEndX + iDeltaEnd;
+      if( iXe < 0 )
+      {
+        ruhXe = 0;
+        ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 );
+        return;
+      }
+      else if( iXe > iMaxPos )
+      {
+        ruhXe = (UChar)(uiScaledBlockSize-1);
+        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+      else
+      {
+        ruhXe = (UChar)iXe;
+        ruhYe = (UChar)(uiScaledBlockSize-1);
+        return;
+      }
+    }
+  }
+}
+
+UInt TComPrediction::xGetWedgePatternIdx( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe )
+{
+  WedgeRefList* pcWedgeRefList = &g_dmmWedgeRefLists[(g_aucConvertToBit[uiBlockSize])];
+  for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ )
+  {
+    TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx));
+    if( pcTestWedgeRef->getStartX() == uhXs && pcTestWedgeRef->getStartY() == uhYs && pcTestWedgeRef->getEndX() == uhXe && pcTestWedgeRef->getEndY() == uhYe )
+    {
+      return pcTestWedgeRef->getRefIdx();
+    }
+  }
+  return 0;
+}
+#endif
+#if H_3D_DIM_RBC
+Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC )
+{
+  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
+  UInt uiAbs  = abs( rDeltaDC );
+
+  Int iQp = pcCU->getQP(0);
+  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
+  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
+
+  rDeltaDC = iSign * roftoi( uiAbs * dStepSize );
+  return;
+}
+
+Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU*  pcCU, Pel& rDeltaDC )
+{
+  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
+  UInt uiAbs  = abs( rDeltaDC );
+
+  Int iQp = pcCU->getQP(0);
+  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
+  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
+
+  rDeltaDC = iSign * roftoi( uiAbs / dStepSize );
+  return;
+}
+#endif
+#endif
 //! \}
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.h	(revision 459)
@@ -88,4 +88,26 @@
   Bool xCheckIdenticalMotion    ( TComDataCU* pcCU, UInt PartAddr);
 
+#if H_3D_DIM
+  // depth intra functions
+  Void xPredBiSegDCs            ( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 );
+  Void xAssignBiSegDCs          ( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel   valDC1, Pel   valDC2 );
+#if H_3D_DIM_DMM
+  UInt xPredWedgeFromIntra      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd = 0 );
+  UInt xPredWedgeFromTex        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx );
+  Void xPredContourFromTex      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge );
+
+  Void xCopyTextureLumaBlock    ( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight );
+
+  Void xGetBlockOffset          ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY );
+  Bool xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY );
+  Void xGetWedgeIntraDirStartEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int iDeltaX, Int iDeltaY, UInt uiPMSPosX, UInt uiPMSPosY, UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, Int iDeltaEnd = 0 );
+  UInt xGetWedgePatternIdx      ( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe );
+#endif
+#if H_3D_DIM_RBC
+  Void xDeltaDCQuantScaleUp     ( TComDataCU* pcCU, Pel& rDeltaDC );
+  Void xDeltaDCQuantScaleDown   ( TComDataCU* pcCU, Pel& rDeltaDC );
+#endif
+#endif
+
 public:
   TComPrediction();
@@ -104,4 +126,9 @@
   Void predIntraChromaAng         ( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft );
   
+#if H_3D_DIM
+  // Depth intra
+  Void predIntraLumaDepth         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc = false );         
+#endif
+
   Pel  predIntraGetPredValDC      ( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft );
   
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComRom.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComRom.cpp	(revision 459)
@@ -82,4 +82,23 @@
     delete[] g_auiSigLastScan[2][i];
   }
+
+#if H_3D_DIM_DMM
+  if( !g_dmmWedgeLists.empty() ) 
+  {
+    for( UInt ui = 0; ui < g_dmmWedgeLists.size(); ui++ ) { g_dmmWedgeLists[ui].clear(); }
+    g_dmmWedgeLists.clear();
+  }
+  if( !g_dmmWedgeRefLists.empty() )
+  {
+    for( UInt ui = 0; ui < g_dmmWedgeRefLists.size(); ui++ ) { g_dmmWedgeRefLists[ui].clear(); }
+    g_dmmWedgeRefLists.clear();
+  }
+
+  if( !g_dmmWedgeNodeLists.empty() )
+  {
+    for( UInt ui = 0; ui < g_dmmWedgeNodeLists.size(); ui++ ) { g_dmmWedgeNodeLists[ui].clear(); }
+    g_dmmWedgeNodeLists.clear();
+  }
+#endif
 }
 
@@ -312,4 +331,30 @@
 
 // ====================================================================================================================
+// Depth coding modes
+// ====================================================================================================================
+#if H_3D_DIM_DMM
+const WedgeResolution g_dmmWedgeResolution[6] = 
+{
+  HALF_PEL,    //   4x4
+  HALF_PEL,    //   8x8
+  FULL_PEL,    //  16x16
+  DOUBLE_PEL,  //  32x32
+  DOUBLE_PEL,  //  64x64
+  DOUBLE_PEL   // 128x128
+};
+
+const UChar g_dmm1TabIdxBits[6] =
+{ //2x2   4x4   8x8 16x16 32x32 64x64
+     0,    7,   10,   11,   11,   13 };
+const UChar g_dmm3IntraTabIdxBits[6] =
+{ //2x2   4x4   8x8 16x16 32x32 64x64
+     0,    6,    9,    9,    9,    0 };
+
+extern std::vector< std::vector<TComWedgelet> >   g_dmmWedgeLists;
+extern std::vector< std::vector<TComWedgeRef> >   g_dmmWedgeRefLists;
+extern std::vector< std::vector<TComWedgeNode> >  g_dmmWedgeNodeLists;
+#endif
+
+// ====================================================================================================================
 // Misc.
 // ====================================================================================================================
@@ -518,3 +563,186 @@
 Int  g_eTTable[4] = {0,3,1,2};
 
+#if H_3D_DIM_DMM
+std::vector< std::vector<TComWedgelet>  > g_dmmWedgeLists;
+std::vector< std::vector<TComWedgeRef>  > g_dmmWedgeRefLists;
+std::vector< std::vector<TComWedgeNode> > g_dmmWedgeNodeLists;
+std::vector< std::vector< std::vector<UInt> > > g_aauiWdgLstM3;
+
+Void initWedgeLists( Bool initRefinements )
+{
+  if( !g_dmmWedgeLists.empty() ) return;
+
+  for( UInt ui = g_aucConvertToBit[DIM_MIN_SIZE]; ui < (g_aucConvertToBit[DIM_MAX_SIZE]+1); ui++ )
+  {
+    UInt uiWedgeBlockSize = ((UInt)DIM_MIN_SIZE)<<ui;
+    std::vector<TComWedgelet> acWedgeList;
+    std::vector<TComWedgeRef> acWedgeRefList;
+    createWedgeList( uiWedgeBlockSize, uiWedgeBlockSize, acWedgeList, acWedgeRefList, g_dmmWedgeResolution[ui] );
+    g_dmmWedgeLists.push_back( acWedgeList );
+    g_dmmWedgeRefLists.push_back( acWedgeRefList );
+
+    // create WedgeNodeList
+    std::vector<TComWedgeNode> acWedgeNodeList;
+    for( UInt uiPos = 0; uiPos < acWedgeList.size(); uiPos++ )
+    {
+      if( acWedgeList[uiPos].getIsCoarse() )
+      {
+        TComWedgeNode cWedgeNode;
+        cWedgeNode.setPatternIdx( uiPos );
+
+        if( initRefinements )
+        {
+          UInt uiRefPos = 0;
+          for( Int iOffS = -1; iOffS <= 1; iOffS++ )
+          {
+            for( Int iOffE = -1; iOffE <= 1; iOffE++ )
+            {
+              if( iOffS == 0 && iOffE == 0 ) { continue; }
+
+              Int iSx = (Int)acWedgeList[uiPos].getStartX();
+              Int iSy = (Int)acWedgeList[uiPos].getStartY();
+              Int iEx = (Int)acWedgeList[uiPos].getEndX();
+              Int iEy = (Int)acWedgeList[uiPos].getEndY();
+
+              switch( acWedgeList[uiPos].getOri() )
+              {
+              case( 0 ): { iSx += iOffS; iEy += iOffE; } break;
+              case( 1 ): { iSy += iOffS; iEx -= iOffE; } break;
+              case( 2 ): { iSx -= iOffS; iEy -= iOffE; } break;
+              case( 3 ): { iSy -= iOffS; iEx += iOffE; } break;
+              case( 4 ): { iSx += iOffS; iEx += iOffE; } break;
+              case( 5 ): { iSy += iOffS; iEy += iOffE; } break;
+              default: assert( 0 );
+              }
+
+              for( UInt k = 0; k < acWedgeRefList.size(); k++ )
+              {
+                if( iSx == (Int)acWedgeRefList[k].getStartX() && 
+                    iSy == (Int)acWedgeRefList[k].getStartY() && 
+                    iEx == (Int)acWedgeRefList[k].getEndX()   && 
+                    iEy == (Int)acWedgeRefList[k].getEndY()      )
+                {
+                  if( acWedgeRefList[k].getRefIdx() != cWedgeNode.getPatternIdx() )
+                  {
+                    Bool bNew = true;
+                    for( UInt m = 0; m < uiRefPos; m++ ) { if( acWedgeRefList[k].getRefIdx() == cWedgeNode.getRefineIdx( m ) ) { bNew = false; break; } }
+
+                    if( bNew ) 
+                    {
+                      cWedgeNode.setRefineIdx( acWedgeRefList[k].getRefIdx(), uiRefPos );
+                      uiRefPos++;
+                      break;
+                    }
+                  }
+                }
+              }
+            }
+          }
+        }
+        acWedgeNodeList.push_back( cWedgeNode );
+      }
+    }
+    g_dmmWedgeNodeLists.push_back( acWedgeNodeList );
+  }
+  return;
+}
+
+Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes )
+{
+  assert( uiWidth == uiHeight );
+
+  UChar    uhStartX = 0,    uhStartY = 0,    uhEndX = 0,    uhEndY = 0;
+  Int   iStepStartX = 0, iStepStartY = 0, iStepEndX = 0, iStepEndY = 0;
+
+  UInt uiBlockSize = 0;
+  switch( eWedgeRes )
+  {
+  case( DOUBLE_PEL ): { uiBlockSize = (uiWidth>>1); break; }
+  case(   FULL_PEL ): { uiBlockSize =  uiWidth;     break; }
+  case(   HALF_PEL ): { uiBlockSize = (uiWidth<<1); break; }
+  }
+
+  TComWedgelet cTempWedgelet( uiWidth, uiHeight );
+  for( UInt uiOri = 0; uiOri < 6; uiOri++ )
+  {
+    // init the edge line parameters for each of the 6 wedgelet types
+    switch( uiOri )
+    {
+    case( 0 ): {  uhStartX = 0;               uhStartY = 0;               uhEndX = 0;               uhEndY = 0;               iStepStartX = +1; iStepStartY =  0; iStepEndX =  0; iStepEndY = +1; break; }
+    case( 1 ): {  uhStartX = (uiBlockSize-1); uhStartY = 0;               uhEndX = (uiBlockSize-1); uhEndY = 0;               iStepStartX =  0; iStepStartY = +1; iStepEndX = -1; iStepEndY =  0; break; }
+    case( 2 ): {  uhStartX = (uiBlockSize-1); uhStartY = (uiBlockSize-1); uhEndX = (uiBlockSize-1); uhEndY = (uiBlockSize-1); iStepStartX = -1; iStepStartY =  0; iStepEndX =  0; iStepEndY = -1; break; }
+    case( 3 ): {  uhStartX = 0;               uhStartY = (uiBlockSize-1); uhEndX = 0;               uhEndY = (uiBlockSize-1); iStepStartX =  0; iStepStartY = -1; iStepEndX = +1; iStepEndY =  0; break; }
+    case( 4 ): {  uhStartX = 0;               uhStartY = 0;               uhEndX = 0;               uhEndY = (uiBlockSize-1); iStepStartX = +1; iStepStartY =  0; iStepEndX = +1; iStepEndY =  0; break; }
+    case( 5 ): {  uhStartX = (uiBlockSize-1); uhStartY = 0;               uhEndX = 0;               uhEndY = 0;               iStepStartX =  0; iStepStartY = +1; iStepEndX =  0; iStepEndY = +1; break; }
+    }
+
+    for( Int iK = 0; iK < uiBlockSize; iK++ )
+    {
+      for( Int iL = 0; iL < uiBlockSize; iL++ )
+      {
+        cTempWedgelet.setWedgelet( uhStartX + (iK*iStepStartX) , uhStartY + (iK*iStepStartY), uhEndX + (iL*iStepEndX), uhEndY + (iL*iStepEndY), (UChar)uiOri, eWedgeRes, ((iL%2)==0 && (iK%2)==0) );
+        addWedgeletToList( cTempWedgelet, racWedgeList, racWedgeRefList );
+      }
+    }
+  }
+
+  UInt uiThrSz = DMM3_SIMPLIFY_TR;
+  std::vector< std::vector<UInt> > auiWdgListSz;
+  for( Int idxM=2; idxM<=34 ; idxM++)
+  {
+    std::vector<UInt> auiWdgList;
+    for( Int idxW=0; idxW<racWedgeList.size(); idxW++)
+    {
+      UInt uiAbsDiff = abs(idxM-(Int)racWedgeList[idxW].getAng());
+      if( uiAbsDiff <= uiThrSz )
+      {
+        auiWdgList.push_back(idxW);
+      }
+    }
+    auiWdgListSz.push_back(auiWdgList);
+  }
+  g_aauiWdgLstM3.push_back(auiWdgListSz);
+}
+
+Void addWedgeletToList( TComWedgelet cWedgelet, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList )
+{
+  Bool bValid = cWedgelet.checkNotPlain();
+  if( bValid )
+  {
+    for( UInt uiPos = 0; uiPos < racWedgeList.size(); uiPos++ )
+    {
+      if( cWedgelet.checkIdentical( racWedgeList[uiPos].getPattern() ) )
+      {
+        TComWedgeRef cWedgeRef;
+        cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), uiPos );
+        racWedgeRefList.push_back( cWedgeRef );
+        bValid = false;
+        return;
+      }
+    }
+  }
+  if( bValid )
+  {
+    for( UInt uiPos = 0; uiPos < racWedgeList.size(); uiPos++ )
+    {
+      if( cWedgelet.checkInvIdentical( racWedgeList[uiPos].getPattern() ) )
+      {
+        TComWedgeRef cWedgeRef;
+        cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), uiPos );
+        racWedgeRefList.push_back( cWedgeRef );
+        bValid = false;
+        return;
+      }
+    }
+  }
+  if( bValid )
+  {
+    cWedgelet.findClosestAngle();
+    racWedgeList.push_back( cWedgelet );
+    TComWedgeRef cWedgeRef;
+    cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), (UInt)(racWedgeList.size()-1) );
+    racWedgeRefList.push_back( cWedgeRef );
+  }
+}
+#endif //H_3D_DIM_DMM
 //! \}
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComRom.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComRom.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComRom.h	(revision 459)
@@ -44,4 +44,8 @@
 #include<iostream>
 
+#if H_3D_DIM
+#include "TComWedgelet.h"
+#endif
+
 //! \ingroup TLibCommon
 //! \{
@@ -147,4 +151,27 @@
 
 extern const UChar g_aucConvertTxtTypeToIdx[4];
+
+#if H_3D_DIM
+// ====================================================================================================================
+// Depth coding modes
+// ====================================================================================================================
+__inline Void mapDepthModeToIntraDir( UInt& intraMode ) { if( isDimMode( intraMode ) ) intraMode = DC_IDX; }
+__inline Void mapDepthModeToIntraDir(  Int& intraMode ) { if( isDimMode( intraMode ) ) intraMode = DC_IDX; }
+
+#if H_3D_DIM_DMM
+extern const WedgeResolution                                 g_dmmWedgeResolution [6];
+extern const UChar                                           g_dmm1TabIdxBits     [6];
+extern const UChar                                           g_dmm3IntraTabIdxBits[6];
+
+extern       std::vector< std::vector<TComWedgelet> >        g_dmmWedgeLists;
+extern       std::vector< std::vector<TComWedgeRef> >        g_dmmWedgeRefLists;
+extern       std::vector< std::vector<TComWedgeNode> >       g_dmmWedgeNodeLists;
+extern       std::vector< std::vector< std::vector<UInt> > > g_aauiWdgLstM3;
+
+Void initWedgeLists( Bool initRefinements = false );
+Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes );
+Void addWedgeletToList( TComWedgelet cWedgelet, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList );
+#endif
+#endif
 
 // ==========================================
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.cpp	(revision 459)
@@ -73,4 +73,7 @@
 , m_pcPPS                         ( NULL )
 , m_pcPic                         ( NULL )
+#if H_3D
+, m_picLists                      ( NULL )
+#endif
 , m_colFromL0Flag                 ( 1 )
 , m_colRefIdx                     ( 0 )
@@ -913,5 +916,7 @@
 
   m_pcPic                = pSrc->m_pcPic;
-
+#if H_3D
+  m_picLists             = pSrc->m_picLists;
+#endif
   m_colFromL0Flag        = pSrc->m_colFromL0Flag;
   m_colRefIdx            = pSrc->m_colRefIdx;
@@ -1474,4 +1479,5 @@
 #if H_3D
     m_viewIndex         [i] = -1; 
+    m_vpsDepthModesFlag [i] = false;
 #endif
 
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.h	(revision 459)
@@ -524,4 +524,5 @@
 #if H_3D
   Int         m_viewIndex                [MAX_NUM_LAYERS   ];
+  Bool        m_vpsDepthModesFlag        [MAX_NUM_LAYERS   ];
 #endif
 
@@ -642,4 +643,7 @@
   Int     getDepthId      ( Int layerIdInVps )                             { return getScalabilityId( layerIdInVps, DEPTH_ID ); }
   Int     getLayerIdInNuh( Int viewIndex, Bool depthFlag );  
+
+  Void    setVpsDepthModesFlag( Int layerIdInVps, Bool val )               { m_vpsDepthModesFlag[ layerIdInVps ] = val; }
+  Bool    getVpsDepthModesFlag( Int layerIdInVps )                         { return m_vpsDepthModesFlag[ layerIdInVps ]; }
 #endif
 
@@ -1424,4 +1428,7 @@
   TComPPS*    m_pcPPS;
   TComPic*    m_pcPic;
+#if H_3D
+  TComPicLists* m_picLists;
+#endif
 #if ADAPTIVE_QP_SELECTION
   TComTrQuant* m_pcTrQuant;
@@ -1542,4 +1549,7 @@
   Int       getNumRefIdx        ( RefPicList e )                { return  m_aiNumRefIdx[e];             }
   TComPic*  getPic              ()                              { return  m_pcPic;                      }
+#if H_3D
+  TComPicLists* getPicLists     ()                              { return m_picLists; }
+#endif
   TComPic*  getRefPic           ( RefPicList e, Int iRefIdx)    { return  m_apcRefPicList[e][iRefIdx];  }
   Int       getRefPOC           ( RefPicList e, Int iRefIdx)    { return  m_aiRefPOCList[e][iRefIdx];   }
@@ -1596,4 +1606,7 @@
   Void      setNumRefIdx        ( RefPicList e, Int i )         { m_aiNumRefIdx[e]    = i;      }
   Void      setPic              ( TComPic* p )                  { m_pcPic             = p;      }
+#if H_3D
+  Void      setPicLists         ( TComPicLists* p )             { m_picLists          = p;      }
+#endif
   Void      setDepth            ( Int iDepth )                  { m_iDepth            = iDepth; }
   
@@ -1756,4 +1769,6 @@
   Int*      getInvCodedScale      ()  { return m_aaiCodedScale [1]; }
   Int*      getInvCodedOffset     ()  { return m_aaiCodedOffset[1]; }
+
+  Bool      getVpsDepthModesFlag  ()  { return getVPS()->getVpsDepthModesFlag( getVPS()->getLayerIdInVps( m_layerId ) ); }
 #endif
 #endif
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComWedgelet.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComWedgelet.cpp	(revision 459)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComWedgelet.cpp	(revision 459)
@@ -0,0 +1,812 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+
+
+// Include files
+#include "CommonDef.h"
+#include "TComYuv.h"
+#include "TComWedgelet.h"
+
+#include <stdlib.h>
+#include <memory.h>
+
+using namespace std;
+
+#if H_3D_DIM_DMM
+TComWedgelet::TComWedgelet( UInt uiWidth, UInt uiHeight ) : m_uhXs     ( 0 ),
+                                                            m_uhYs     ( 0 ),
+                                                            m_uhXe     ( 0 ),
+                                                            m_uhYe     ( 0 ),
+                                                            m_uhOri    ( 0 ),
+                                                            m_eWedgeRes( FULL_PEL ),
+                                                            m_bIsCoarse( false )
+{
+  create( uiWidth, uiHeight );
+}
+
+TComWedgelet::TComWedgelet( const TComWedgelet &rcWedge ) : m_uhXs     ( rcWedge.m_uhXs      ),
+                                                            m_uhYs     ( rcWedge.m_uhYs      ),
+                                                            m_uhXe     ( rcWedge.m_uhXe      ),
+                                                            m_uhYe     ( rcWedge.m_uhYe      ),
+                                                            m_uhOri    ( rcWedge.m_uhOri     ),
+                                                            m_eWedgeRes( rcWedge.m_eWedgeRes ),
+                                                            m_bIsCoarse( rcWedge.m_bIsCoarse ),
+                                                            m_uiAng    ( rcWedge.m_uiAng     ),
+                                                            m_uiWidth  ( rcWedge.m_uiWidth   ),
+                                                            m_uiHeight ( rcWedge.m_uiHeight  ),
+                                                            m_pbPattern( (Bool*)xMalloc( Bool, (m_uiWidth * m_uiHeight) ) )
+{
+  ::memcpy( m_pbPattern, rcWedge.m_pbPattern, sizeof(Bool) * (m_uiWidth * m_uiHeight));
+}
+
+TComWedgelet::~TComWedgelet(void)
+{
+  destroy();
+}
+
+Void TComWedgelet::create( UInt uiWidth, UInt uiHeight )
+{
+  assert( uiWidth > 0 && uiHeight > 0 );
+
+  m_uiWidth   = uiWidth;
+  m_uiHeight  = uiHeight;
+
+  m_pbPattern = (Bool*)xMalloc( Bool, (m_uiWidth * m_uiHeight) );
+}
+
+Void TComWedgelet::destroy()
+{
+  if( m_pbPattern ) { xFree( m_pbPattern ); m_pbPattern = NULL; }
+}
+
+Void TComWedgelet::clear()
+{
+  ::memset( m_pbPattern, 0, (m_uiWidth * m_uiHeight) * sizeof(Bool) );
+}
+
+Void TComWedgelet::findClosestAngle()
+{
+  UInt uiAng=0,uiOptAng=0;
+  UInt uiMinD=MAX_UINT;
+  UInt uiTmpD=0;
+  Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
+  
+  UChar uhXs = m_uhXs;
+  UChar uhYs = m_uhYs;
+  UChar uhXe = m_uhXe;
+  UChar uhYe = m_uhYe;
+
+  for(uiAng=2; uiAng<=34; uiAng++)
+  {
+    Int iSign    = (uiAng<VER_IDX && uiAng>HOR_IDX ) ? -1 : 1;
+    Int iVer     = uiAng>17 ? 32 : angTable[(uiAng>10) ? (uiAng-10) : (10-uiAng)];
+    Int iHor     = uiAng<19 ? 32 : angTable[(uiAng>26) ? (uiAng-26) : (26-uiAng)];
+
+    uiTmpD  = abs(iVer*iSign*(uhXs-uhXe) - iHor*(uhYe-uhYs));
+    
+    if( uiTmpD < uiMinD )
+    {
+      uiMinD = uiTmpD;
+      uiOptAng = uiAng;
+    }
+  }
+  m_uiAng = uiOptAng;
+}
+
+Void TComWedgelet::setWedgelet( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, UChar uhOri, WedgeResolution eWedgeRes, Bool bIsCoarse )
+{
+  m_uhXs      = uhXs;
+  m_uhYs      = uhYs;
+  m_uhXe      = uhXe;
+  m_uhYe      = uhYe;
+  m_uhOri     = uhOri;
+  m_eWedgeRes = eWedgeRes;
+  m_bIsCoarse = bIsCoarse;
+
+  xGenerateWedgePattern();
+}
+
+Bool TComWedgelet::checkNotPlain()
+{
+  for( UInt k = 1; k < (m_uiWidth * m_uiHeight); k++ )
+  {
+    if( m_pbPattern[0] != m_pbPattern[k] )
+    {
+      return true;
+    }
+  }
+  return false;
+}
+
+Bool TComWedgelet::checkIdentical( Bool* pbRefPattern )
+{
+  for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ )
+  {
+    if( m_pbPattern[k] != pbRefPattern[k] )
+    {
+      return false;
+    }
+  }
+  return true;
+}
+
+Bool TComWedgelet::checkInvIdentical( Bool* pbRefPattern )
+{
+  for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ )
+  {
+    if( m_pbPattern[k] == pbRefPattern[k] )
+    {
+      return false;
+    }
+  }
+  return true;
+}
+
+Bool TComWedgelet::checkPredDirAbovePossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset )
+{
+  WedgeResolution eContDWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiPredDirBlockSize]];
+  UInt uiContDStartEndMax = 0;
+  UInt uiContDStartEndOffset = 0;
+  switch( eContDWedgeRes )
+  {
+  case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; }
+  case(   FULL_PEL ): { uiContDStartEndMax =  uiPredDirBlockSize;     uiContDStartEndOffset =  uiPredDirBlockOffset;     break; }
+  case(   HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; }
+  }
+
+  if( m_uhOri == 2 || m_uhOri == 3 || m_uhOri == 4 )
+  {
+    UInt uiThisStartEndMax = 0;
+    switch( m_eWedgeRes )
+    {
+    case( DOUBLE_PEL ): { uiThisStartEndMax = (m_uiWidth>>1); break; }
+    case(   FULL_PEL ): { uiThisStartEndMax =  m_uiWidth;     break; }
+    case(   HALF_PEL ): { uiThisStartEndMax = (m_uiWidth<<1); break; }
+    }
+
+    UChar uhStartX = m_uhXs;
+    UChar uhStartY = m_uhYs;
+    UChar uhEndX   = m_uhXe;
+    UChar uhEndY   = m_uhYe;
+
+    if( 2 == m_uhOri )
+    {
+      std::swap( uhStartX, uhEndX );
+      std::swap( uhStartY, uhEndY );
+    }
+
+    UInt uiScaledEndX = (UInt)uhEndX;
+    Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes;
+    if( iDeltaRes > 0 ) { uiScaledEndX <<=  iDeltaRes; }
+    if( iDeltaRes < 0 ) { uiScaledEndX >>= -iDeltaRes; }
+
+    if( ((UInt)uhEndY == (uiThisStartEndMax-1)) && ((uiScaledEndX-uiContDStartEndOffset) > 0 && (uiScaledEndX-uiContDStartEndOffset) < (uiContDStartEndMax-1)) )
+    {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+Bool TComWedgelet::checkPredDirLeftPossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset )
+{
+  WedgeResolution eContDWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiPredDirBlockSize]];
+  UInt uiContDStartEndMax = 0;
+  UInt uiContDStartEndOffset = 0;
+  switch( eContDWedgeRes )
+  {
+  case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; }
+  case(   FULL_PEL ): { uiContDStartEndMax =  uiPredDirBlockSize;     uiContDStartEndOffset =  uiPredDirBlockOffset;     break; }
+  case(   HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; }
+  }
+
+  if( m_uhOri == 1 || m_uhOri == 2 || m_uhOri == 5 )
+  {
+    UInt uiThisStartEndMax = 0;
+    switch( m_eWedgeRes )
+    {
+    case( DOUBLE_PEL ): { uiThisStartEndMax = (m_uiHeight>>1); break; }
+    case(   FULL_PEL ): { uiThisStartEndMax =  m_uiHeight;     break; }
+    case(   HALF_PEL ): { uiThisStartEndMax = (m_uiHeight<<1); break; }
+    }
+
+    UChar uhStartX = m_uhXs;
+    UChar uhStartY = m_uhYs;
+    UChar uhEndX   = m_uhXe;
+    UChar uhEndY   = m_uhYe;
+
+    if( 1 == m_uhOri || 5 == m_uhOri )
+    {
+      std::swap( uhStartX, uhEndX );
+      std::swap( uhStartY, uhEndY );
+    }
+
+    UInt uiScaledEndY = (UInt)uhEndY;
+    Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes;
+    if( iDeltaRes > 0 ) { uiScaledEndY <<=  iDeltaRes; }
+    if( iDeltaRes < 0 ) { uiScaledEndY >>= -iDeltaRes; }
+
+    if( ((UInt)uhEndX == (uiThisStartEndMax-1)) && ((uiScaledEndY-uiContDStartEndOffset) > 0 && (uiScaledEndY-uiContDStartEndOffset) < (uiContDStartEndMax-1)) )
+    {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+Void TComWedgelet::getPredDirStartEndAbove( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd )
+{
+  ruhXs = 0;
+  ruhYs = 0;
+  ruhXe = 0;
+  ruhYe = 0;
+
+  // get start/end of reference (=this) wedgelet
+  UInt uiRefStartX = (UInt)getStartX();
+  UInt uiRefStartY = (UInt)getStartY();
+  UInt uiRefEndX   = (UInt)getEndX();
+  UInt uiRefEndY   = (UInt)getEndY();
+
+  WedgeResolution eContDWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiPredDirBlockSize]];
+  UInt uiContDStartEndMax = 0;
+  UInt uiContDStartEndOffset = 0;
+  switch( eContDWedgeRes )
+  {
+  case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; }
+  case(   FULL_PEL ): { uiContDStartEndMax =  uiPredDirBlockSize;     uiContDStartEndOffset =  uiPredDirBlockOffset;     break; }
+  case(   HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; }
+  }
+  Int iContDMaxPos = (Int)uiContDStartEndMax - 1;
+
+  // swap if start/end if line orientation is not from top to bottom
+  if( 2 == (UInt)getOri() )
+  {
+    std::swap( uiRefStartX, uiRefEndX );
+    std::swap( uiRefStartY, uiRefEndY );
+  }
+
+  // calc slopes
+  Int iA_DeltaX = (Int)uiRefEndX - (Int)uiRefStartX;
+  Int iA_DeltaY = (Int)uiRefEndY - (Int)uiRefStartY;
+
+  // get aligned end x value of ref wedge
+  UInt uiScaledRefEndX = uiRefEndX;
+  Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes;
+  if( iDeltaRes > 0 ) { uiScaledRefEndX <<=  iDeltaRes; }
+  if( iDeltaRes < 0 ) { uiScaledRefEndX >>= -iDeltaRes; }
+
+  assert( uiScaledRefEndX >= uiContDStartEndOffset );
+  Int iAlignedRefEndX = (Int)uiScaledRefEndX - (Int)uiContDStartEndOffset;
+
+  // special for straight vertical wedge
+  if( iA_DeltaX == 0 )
+  {
+    ruhXs = (UChar)iAlignedRefEndX;
+    ruhYs = 0;
+
+    Int iXe = iAlignedRefEndX + iDeltaEnd;
+    if( iXe < 0 )
+    {
+      ruhXe = 0;
+      ruhYe = (UChar)min( max( (iContDMaxPos + iXe), 0 ), iContDMaxPos );
+
+      return;
+    }
+    else if( iXe > iContDMaxPos )
+    {
+      ruhXe = (UChar)iContDMaxPos;
+      ruhYe = (UChar)min( max( (iContDMaxPos - (iXe - iContDMaxPos)), 0 ), iContDMaxPos );
+
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+    else
+    {
+      ruhXe = (UChar)iXe;
+      ruhYe = (UChar)iContDMaxPos;
+
+      return;
+    }
+  }
+
+  // special for straight horizontal short bottom line
+  if( iA_DeltaY == 0 )
+  {
+    switch( (UInt)getOri() )
+    {
+    case( 2 ):
+      {
+        ruhXs = (UChar)(iAlignedRefEndX-1);
+        ruhYs = 0;
+        ruhXe = 0;
+        ruhYe = (UChar)min( max( iDeltaEnd, 0 ), iContDMaxPos );
+
+        return;
+      }
+    case( 3 ):
+      {
+        ruhXs = (UChar)(iAlignedRefEndX+1);
+        ruhYs = 0;
+        ruhXe = (UChar)iContDMaxPos;
+        ruhYe = (UChar)min( max( -iDeltaEnd, 0 ), iContDMaxPos );
+
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+    default:
+      {
+        assert( 0 );
+        return;
+      }
+    }
+  }
+
+  // set start point depending on slope
+  if( abs( iA_DeltaX ) >= abs( iA_DeltaY ) ) { if( iA_DeltaX < 0 ) { ruhXs = (UChar)(iAlignedRefEndX-1); ruhYs = 0; }
+                                                if( iA_DeltaX > 0 ) { ruhXs = (UChar)(iAlignedRefEndX+1); ruhYs = 0; } }
+  else                                                             { ruhXs = (UChar)(iAlignedRefEndX);   ruhYs = 0;   }
+
+  // calc end point and determine orientation
+  Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iContDMaxPos * ((Double)iA_DeltaX / (Double)iA_DeltaY) );
+
+  if( iVirtualEndX < 0 )
+  {
+    Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iA_DeltaY / (Double)iA_DeltaX) ) + iDeltaEnd;
+    if( iYe < (Int)uiContDStartEndMax )
+    {
+      ruhXe = 0;
+      ruhYe = (UChar)max( iYe, 0 );
+
+      return;
+    }
+    else
+    {
+      ruhXe = (UChar)min( (iYe - iContDMaxPos), iContDMaxPos );
+      ruhYe = (UChar)iContDMaxPos;
+
+      return;
+    }
+  }
+  else if( iVirtualEndX > iContDMaxPos )
+  {
+    Int iYe = roftoi( (Double)(iContDMaxPos - (Int)ruhXs) * ((Double)iA_DeltaY / (Double)iA_DeltaX) ) - iDeltaEnd;
+    if( iYe < (Int)uiContDStartEndMax )
+    {
+      ruhXe = (UChar)iContDMaxPos;
+      ruhYe = (UChar)max( iYe, 0 );
+
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+    else
+    {
+      ruhXe = (UChar)max( (iContDMaxPos - (iYe - iContDMaxPos)), 0 );
+      ruhYe = (UChar)iContDMaxPos;
+
+      return;
+    }
+  }
+  else
+  {
+    Int iXe = iVirtualEndX + iDeltaEnd;
+    if( iXe < 0 )
+    {
+      ruhXe = 0;
+      ruhYe = (UChar)max( (iContDMaxPos + iXe), 0 );
+
+      return;
+    }
+    else if( iXe > iContDMaxPos )
+    {
+      ruhXe = (UChar)iContDMaxPos;
+      ruhYe = (UChar)max( (iContDMaxPos - (iXe - iContDMaxPos)), 0 );
+
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+    else
+    {
+      ruhXe = (UChar)iXe;
+      ruhYe = (UChar)iContDMaxPos;
+
+      return;
+    }
+  }
+}
+
+Void TComWedgelet::getPredDirStartEndLeft( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd )
+{
+  ruhXs = 0;
+  ruhYs = 0;
+  ruhXe = 0;
+  ruhYe = 0;
+
+  // get start/end of reference (=this) wedgelet
+  UInt uiRefStartX = (UInt)getStartX();
+  UInt uiRefStartY = (UInt)getStartY();
+  UInt uiRefEndX   = (UInt)getEndX();
+  UInt uiRefEndY   = (UInt)getEndY();
+
+  WedgeResolution eContDWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiPredDirBlockSize]];
+  UInt uiContDStartEndMax = 0;
+  UInt uiContDStartEndOffset = 0;
+  switch( eContDWedgeRes )
+  {
+  case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; }
+  case(   FULL_PEL ): { uiContDStartEndMax =  uiPredDirBlockSize;     uiContDStartEndOffset =  uiPredDirBlockOffset;     break; }
+  case(   HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; }
+  }
+  Int iContDMaxPos = (Int)uiContDStartEndMax - 1;
+
+  // swap if start/end if line orientation is not from left to right
+  if( 1 == (UInt)getOri() || 5 == (UInt)getOri() )
+  {
+    std::swap( uiRefStartX, uiRefEndX );
+    std::swap( uiRefStartY, uiRefEndY );
+  }
+
+  Int iL_DeltaX = (Int)uiRefEndX - (Int)uiRefStartX;
+  Int iL_DeltaY = (Int)uiRefEndY - (Int)uiRefStartY;
+
+  UInt uiScaledRefEndY = uiRefEndY;
+  Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes;
+  if( iDeltaRes > 0 ) { uiScaledRefEndY <<=  iDeltaRes; }
+  if( iDeltaRes < 0 ) { uiScaledRefEndY >>= -iDeltaRes; }
+
+  assert( uiScaledRefEndY >= uiContDStartEndOffset );
+  Int iAlignedRefEndY = (Int)uiScaledRefEndY - (Int)uiContDStartEndOffset;
+
+  // special for straight horizontal wedge
+  if( iL_DeltaY == 0 )
+  {
+    ruhXs = 0;
+    ruhYs = (UChar)iAlignedRefEndY;
+
+    Int iYe = iAlignedRefEndY - iDeltaEnd;
+    if( iYe < 0 )
+    {
+      ruhXe = (UChar)min( max( (iContDMaxPos + iYe), 0 ), iContDMaxPos );
+      ruhYe = 0;
+
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+    else if( iYe > iContDMaxPos )
+    {
+      ruhXe = (UChar)min( max( (iContDMaxPos - (iYe - iContDMaxPos)), 0 ), iContDMaxPos );
+      ruhYe = (UChar)iContDMaxPos;
+
+      return;
+    }
+    else
+    {
+      ruhXe = (UChar)iContDMaxPos;
+      ruhYe = (UChar)iYe;
+
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+  }
+
+  // special for straight vertical short right line
+  if( iL_DeltaX == 0 )
+  {
+    switch( (UInt)getOri() )
+    {
+    case( 1 ):
+      {
+        ruhXs = 0;
+        ruhYs = (UChar)(iAlignedRefEndY+1);
+        ruhXe = (UChar)min( max( iDeltaEnd, 0 ), iContDMaxPos );
+        ruhYe = (UChar)iContDMaxPos;
+
+        return;
+      }
+    case( 2 ):
+      {
+        ruhXs = 0;
+        ruhYs = (UChar)(iAlignedRefEndY-1);
+        ruhXe = (UChar)min( max( -iDeltaEnd, 0 ), iContDMaxPos );
+        ruhYe = 0;
+
+        std::swap( ruhXs, ruhXe );
+        std::swap( ruhYs, ruhYe );
+        return;
+      }
+    default:
+      {
+        assert( 0 );
+        return;
+      }
+    }
+  }
+
+  // set start point depending on slope
+  if( abs( iL_DeltaY ) >= abs( iL_DeltaX ) ) { if( iL_DeltaY < 0 ) { ruhYs = (UChar)(iAlignedRefEndY-1); ruhXs = 0; }
+                                               if( iL_DeltaY > 0 ) { ruhYs = (UChar)(iAlignedRefEndY+1); ruhXs = 0; } }
+  else                                       {                       ruhYs = (UChar)(iAlignedRefEndY);   ruhXs = 0;   }
+
+  // calc end point and determine orientation
+  Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iContDMaxPos * ((Double)iL_DeltaY / (Double)iL_DeltaX) );
+
+  if( iVirtualEndY < 0 )
+  {
+    Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iL_DeltaX / (Double)iL_DeltaY) ) - iDeltaEnd;
+    if( iXe < (Int)uiContDStartEndMax )
+    {
+      ruhXe = (UChar)max( iXe, 0 );
+      ruhYe = 0;
+
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+    else
+    {
+      ruhXe = (UChar)iContDMaxPos;
+      ruhYe = (UChar)min( (iXe - iContDMaxPos), iContDMaxPos );
+
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+  }
+  else if( iVirtualEndY > iContDMaxPos )
+  {
+    Int iXe = roftoi( (Double)(iContDMaxPos - (Int)ruhYs ) * ((Double)iL_DeltaX / (Double)iL_DeltaY) ) + iDeltaEnd;
+    if( iXe < (Int)uiContDStartEndMax )
+    {
+      ruhXe = (UChar)max( iXe, 0 );
+      ruhYe = (UChar)iContDMaxPos;
+
+      return;
+    }
+    else
+    {
+      ruhXe = (UChar)iContDMaxPos;
+      ruhYe = (UChar)max( (iContDMaxPos - (iXe - iContDMaxPos)), 0 );
+
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+  }
+  else
+  {
+    Int iYe = iVirtualEndY - iDeltaEnd;
+    if( iYe < 0 )
+    {
+      ruhXe = (UChar)max( (iContDMaxPos + iYe), 0 );
+      ruhYe = 0;
+
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+    else if( iYe > iContDMaxPos )
+    {
+      ruhXe = (UChar)max( (iContDMaxPos - (iYe - iContDMaxPos)), 0 );
+      ruhYe = (UChar)iContDMaxPos;
+
+      return;
+    }
+    else
+    {
+      ruhXe = (UChar)iContDMaxPos;
+      ruhYe = (UChar)iYe;
+
+      std::swap( ruhXs, ruhXe );
+      std::swap( ruhYs, ruhYe );
+      return;
+    }
+  }
+}
+
+Void TComWedgelet::xGenerateWedgePattern()
+{
+  UInt uiTempBlockSize = 0;
+  UChar uhXs = 0, uhYs = 0, uhXe = 0, uhYe = 0;
+  switch( m_eWedgeRes )
+  {
+  case( DOUBLE_PEL ): { uiTempBlockSize =  m_uiWidth;     uhXs = (m_uhXs<<1); uhYs = (m_uhYs<<1); uhXe = (m_uhXe<<1); uhYe = (m_uhYe<<1); } break;
+  case(   FULL_PEL ): { uiTempBlockSize =  m_uiWidth;     uhXs =  m_uhXs;     uhYs =  m_uhYs;     uhXe =  m_uhXe;     uhYe =  m_uhYe;     } break;
+  case(   HALF_PEL ): { uiTempBlockSize = (m_uiWidth<<1); uhXs =  m_uhXs;     uhYs =  m_uhYs;     uhXe =  m_uhXe;     uhYe =  m_uhYe;     } break;
+  }
+
+  if( m_eWedgeRes == DOUBLE_PEL) // adjust line-end for DOUBLE_PEL resolution
+  {
+    if( m_uhOri == 1 ) { uhXs = uiTempBlockSize-1; }
+    if( m_uhOri == 2 ) { uhXe = uiTempBlockSize-1; uhYs = uiTempBlockSize-1; }
+    if( m_uhOri == 3 ) { uhYe = uiTempBlockSize-1; }
+    if( m_uhOri == 4 ) { uhYe = uiTempBlockSize-1; }
+    if( m_uhOri == 5 ) { uhXs = uiTempBlockSize-1; }
+  }
+
+  Bool* pbTempPattern = new Bool[ (uiTempBlockSize * uiTempBlockSize) ];
+  ::memset( pbTempPattern, 0, (uiTempBlockSize * uiTempBlockSize) * sizeof(Bool) );
+  Int iTempStride = uiTempBlockSize;
+
+  xDrawEdgeLine( uhXs, uhYs, uhXe, uhYe, pbTempPattern, iTempStride );
+
+  switch( m_uhOri )
+  {
+  case( 0 ): { for( UInt iX = 0;                 iX < uhXs;            iX++ ) { UInt iY = 0;                 while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iY++; } } } break;
+  case( 1 ): { for( UInt iY = 0;                 iY < uhYs;            iY++ ) { UInt iX = uiTempBlockSize-1; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iX--; } } } break;
+  case( 2 ): { for( UInt iX = uiTempBlockSize-1; iX > uhXs;            iX-- ) { UInt iY = uiTempBlockSize-1; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iY--; } } } break;
+  case( 3 ): { for( UInt iY = uiTempBlockSize-1; iY > uhYs;            iY-- ) { UInt iX = 0;                 while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iX++; } } } break;
+  case( 4 ): 
+    { 
+      if( (uhXs+uhXe) < uiTempBlockSize ) { for( UInt iY = 0; iY < uiTempBlockSize; iY++ ) { UInt iX = 0;                 while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iX++; } } }
+      else                                { for( UInt iY = 0; iY < uiTempBlockSize; iY++ ) { UInt iX = uiTempBlockSize-1; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iX--; } } }
+    }
+    break;
+  case( 5 ): 
+    { 
+      if( (uhYs+uhYe) < uiTempBlockSize ) { for( UInt iX = 0; iX < uiTempBlockSize; iX++ ) { UInt iY = 0;                 while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iY++; } } }
+      else                                { for( UInt iX = 0; iX < uiTempBlockSize; iX++ ) { UInt iY = uiTempBlockSize-1; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iY--; } } }
+    }
+  }
+
+  clear();
+  switch( m_eWedgeRes )
+  {
+  case( DOUBLE_PEL ): { for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ ) { m_pbPattern[k] = pbTempPattern[k]; }; } break;
+  case(   FULL_PEL ): { for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ ) { m_pbPattern[k] = pbTempPattern[k]; }; } break;
+  case(   HALF_PEL ): // sub-sampling by factor 2
+    {
+      Int iStride = getStride();
+
+      UInt uiOffX, uiOffY;
+      switch( m_uhOri )
+      {
+      case( 0 ): { uiOffX = 0; uiOffY = 0; } break;
+      case( 1 ): { uiOffX = 1; uiOffY = 0; } break;
+      case( 2 ): { uiOffX = 1; uiOffY = 1; } break;
+      case( 3 ): { uiOffX = 0; uiOffY = 1; } break;
+      case( 4 ): 
+        { 
+          if( (uhXs+uhXe) < uiTempBlockSize ) { uiOffX = 0; uiOffY = 0; }
+          else                                { uiOffX = 1; uiOffY = 0; }
+        } 
+        break;
+      case( 5 ): 
+        { 
+          if( (uhYs+uhYe) < uiTempBlockSize ) { uiOffX = 0; uiOffY = 0; }
+          else                                { uiOffX = 0; uiOffY = 1; }
+        } 
+        break;
+      default:   { uiOffX = 0; uiOffY = 0; } break;
+      }
+
+      for(Int iY = 0; iY < m_uiHeight; iY++)
+      {
+        for(Int iX = 0; iX < m_uiWidth; iX++)
+        {
+          m_pbPattern[(iY * iStride) + iX] = pbTempPattern[(((iY<<1)+uiOffY) * iTempStride) + ((iX<<1)+uiOffX)];
+        }
+      }
+    }
+    break;
+  }
+
+  if( pbTempPattern )
+  {
+    delete [] pbTempPattern;
+    pbTempPattern = NULL;
+  }
+}
+
+Void TComWedgelet::xDrawEdgeLine( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, Bool* pbPattern, Int iPatternStride )
+{
+  Int x0 = (Int)uhXs;
+  Int y0 = (Int)uhYs;
+  Int x1 = (Int)uhXe;
+  Int y1 = (Int)uhYe;
+
+  // direction independent Bresenham line
+  bool steep = (abs(y1 - y0) > abs(x1 - x0));
+  if( steep )
+  {
+    std::swap( x0, y0 );
+    std::swap( x1, y1 );
+  }
+
+  bool backward = ( x0 > x1 );
+  if( backward )
+  {
+    std::swap( x0, x1 );
+    std::swap( y0, y1 );
+  }
+
+  Int deltax = x1 - x0;
+  Int deltay = abs(y1 - y0);
+  Int error = 0;
+  Int deltaerr = (deltay<<1);
+
+  Int ystep;
+  Int y = y0;
+  if( y0 < y1 ) ystep =  1;
+  else          ystep = -1;
+
+  for( Int x = x0; x <= x1; x++ )
+  {
+    if( steep ) { pbPattern[(x * iPatternStride) + y] = true; }
+    else        { pbPattern[(y * iPatternStride) + x] = true; }
+
+    error += deltaerr;
+    if( error >= deltax )
+    {
+      y += ystep;
+      error = error - (deltax<<1);
+    }
+  }
+}
+
+TComWedgeNode::TComWedgeNode()
+{
+  m_uiPatternIdx = DMM_NO_WEDGEINDEX;
+  for( UInt uiPos = 0; uiPos < DMM_NUM_WEDGE_REFINES; uiPos++ )
+  {
+    m_uiRefineIdx[uiPos] = DMM_NO_WEDGEINDEX;
+  }
+}
+
+UInt TComWedgeNode::getPatternIdx()
+{
+  return m_uiPatternIdx;
+}
+UInt TComWedgeNode::getRefineIdx( UInt uiPos )
+{
+  assert( uiPos < DMM_NUM_WEDGE_REFINES );
+  return m_uiRefineIdx[uiPos];
+}
+Void TComWedgeNode::setPatternIdx( UInt uiIdx )
+{
+  m_uiPatternIdx = uiIdx;
+}
+Void TComWedgeNode::setRefineIdx( UInt uiIdx, UInt uiPos )
+{
+  assert( uiPos < DMM_NUM_WEDGE_REFINES );
+  m_uiRefineIdx[uiPos] = uiIdx;  
+}
+#endif //H_3D_DIM_DMM
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComWedgelet.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComWedgelet.h	(revision 459)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComWedgelet.h	(revision 459)
@@ -0,0 +1,211 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+
+#ifndef __TCOMWEDGELET__
+#define __TCOMWEDGELET__
+
+// Include files
+#include <assert.h>
+#include "CommonDef.h"
+
+#include <vector>
+
+#if H_3D_DIM
+#define DIM_OFFSET     (NUM_INTRA_MODE+1) // offset for DMM and RBC mode numbers (PM: not consistent with spec, but non-overlapping with chroma, see DM_CHROMA_IDX)
+#define DIM_MIN_SIZE                   4  // min. block size for DMM and RBC modes
+#define DIM_MAX_SIZE                  32  // max. block size for DMM and RBC modes
+
+enum DIM_IDX
+{
+  DMM1_IDX = 0,
+  DMM2_IDX = 3,
+  DMM3_IDX = 1,
+  DMM4_IDX = 2,
+  RBC_IDX  = 4
+};
+#define DMM_NUM_TYPE   4
+#define RBC_NUM_TYPE   1
+#define DIM_NUM_TYPE   (DMM_NUM_TYPE+RBC_NUM_TYPE)
+#define DIM_NO_IDX     MAX_UINT
+
+__inline UInt getDimType  ( Int intraMode ) { Int dimType = (intraMode-DIM_OFFSET)/2; return (dimType >= 0 && dimType < DIM_NUM_TYPE) ? (UInt)dimType : DIM_NO_IDX; }
+__inline Bool isDimMode   ( Int intraMode ) { return (getDimType( intraMode ) < DIM_NUM_TYPE); }
+__inline Bool isDimDeltaDC( Int intraMode ) { return (isDimMode( intraMode ) && ((intraMode-DIM_OFFSET)%2) == 1); }
+#endif
+
+#if H_3D_DIM_RBC
+#define RBC_THRESHOLD              20
+#define RBC_MAX_EDGE_NUM_PER_4x4   8
+#define RBC_MAX_DISTANCE           255
+#endif
+
+#if H_3D_DIM_DMM
+#define DMM_NO_WEDGEINDEX       MAX_UINT
+#define DMM_NUM_WEDGE_REFINES   8
+#define DMM2_DELTAEND_MAX       4
+#define DMM3_SIMPLIFY_TR        1
+
+enum WedgeResolution
+{
+  DOUBLE_PEL,
+  FULL_PEL,
+  HALF_PEL
+};
+
+
+// ====================================================================================================================
+// Class definition TComWedgelet
+// ====================================================================================================================
+class TComWedgelet
+{
+private:
+  UChar           m_uhXs;                       // line start X pos
+  UChar           m_uhYs;                       // line start Y pos
+  UChar           m_uhXe;                       // line end   X pos
+  UChar           m_uhYe;                       // line end   Y pos
+  UChar           m_uhOri;                      // orientation index
+  WedgeResolution m_eWedgeRes;                  // start/end pos resolution
+  Bool            m_bIsCoarse; 
+  UInt            m_uiAng;
+
+  UInt  m_uiWidth;
+  UInt  m_uiHeight;
+
+  Bool* m_pbPattern;
+
+  Void  xGenerateWedgePattern();
+  Void  xDrawEdgeLine( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, Bool* pbPattern, Int iPatternStride );
+
+public:
+  TComWedgelet( UInt uiWidth, UInt uiHeight );
+  TComWedgelet( const TComWedgelet &rcWedge );
+  virtual ~TComWedgelet();
+
+  Void  create ( UInt iWidth, UInt iHeight );   ///< create  wedgelet pattern
+  Void  destroy();                              ///< destroy wedgelet pattern
+  Void  clear  ();                              ///< clear   wedgelet pattern
+
+  UInt            getWidth   () { return m_uiWidth; }
+  UInt            getStride  () { return m_uiWidth; }
+  UInt            getHeight  () { return m_uiHeight; }
+  WedgeResolution getWedgeRes() { return m_eWedgeRes; }
+  Bool*           getPattern () { return m_pbPattern; }
+  UChar           getStartX  () { return m_uhXs; }
+  UChar           getStartY  () { return m_uhYs; }
+  UChar           getEndX    () { return m_uhXe; }
+  UChar           getEndY    () { return m_uhYe; }
+  UChar           getOri     () { return m_uhOri; }
+  Bool            getIsCoarse() { return m_bIsCoarse; }
+  UInt            getAng     () { return m_uiAng; }
+
+  Void  setWedgelet( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, UChar uhOri, WedgeResolution eWedgeRes, Bool bIsCoarse = false );
+  Void  findClosestAngle();
+
+  Bool  checkNotPlain();
+  Bool  checkIdentical( Bool* pbRefPattern );
+  Bool  checkInvIdentical( Bool* pbRefPattern );
+
+  // functions for DMM2 prediction
+  Bool  checkPredDirAbovePossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffsett );
+  Bool  checkPredDirLeftPossible ( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffsett );
+  Void  getPredDirStartEndAbove( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd );
+  Void  getPredDirStartEndLeft ( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd );
+};  // END CLASS DEFINITION TComWedgelet
+
+// type definition wedgelet pattern list
+typedef std::vector<TComWedgelet> WedgeList;
+
+// ====================================================================================================================
+// Class definition TComWedgeRef
+// ====================================================================================================================
+class TComWedgeRef
+{
+private:
+  UChar           m_uhXs;                       // line start X pos
+  UChar           m_uhYs;                       // line start Y pos
+  UChar           m_uhXe;                       // line end   X pos
+  UChar           m_uhYe;                       // line end   Y pos
+  UInt            m_uiRefIdx;                   // index of corresponding pattern of TComWedgelet object in wedge list
+
+public:
+  TComWedgeRef() {}
+  virtual ~TComWedgeRef() {}
+
+  UChar           getStartX  () { return m_uhXs; }
+  UChar           getStartY  () { return m_uhYs; }
+  UChar           getEndX    () { return m_uhXe; }
+  UChar           getEndY    () { return m_uhYe; }
+  UInt            getRefIdx  () { return m_uiRefIdx; }
+
+  Void  setWedgeRef( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, UInt uiRefIdx ) { m_uhXs = uhXs; m_uhYs = uhYs; m_uhXe = uhXe; m_uhYe = uhYe; m_uiRefIdx = uiRefIdx; }
+};  // END CLASS DEFINITION TComWedgeRef
+
+// type definition wedgelet reference list
+typedef std::vector<TComWedgeRef> WedgeRefList;
+
+// ====================================================================================================================
+// Class definition TComWedgeNode
+// ====================================================================================================================
+class TComWedgeNode
+{
+private:
+  UInt            m_uiPatternIdx;
+  UInt            m_uiRefineIdx[DMM_NUM_WEDGE_REFINES];
+
+public:
+  TComWedgeNode();
+  virtual ~TComWedgeNode() {}
+
+  UInt            getPatternIdx();
+  UInt            getRefineIdx ( UInt uiPos );
+
+  Void            setPatternIdx( UInt uiIdx );
+  Void            setRefineIdx ( UInt uiIdx, UInt uiPos );
+};  // END CLASS DEFINITION TComWedgeNode
+
+// type definition wedgelet node list
+typedef std::vector<TComWedgeNode> WedgeNodeList;
+#endif //H_3D_DIM_DMM
+
+
+// ====================================================================================================================
+// Function definition roftoi (mathematically correct rounding of float to int)
+// ====================================================================================================================
+__inline Int roftoi( Double value )
+{
+  (value < -0.5) ? (value -= 0.5) : (value += 0.5);
+  return ( (Int)value );
+}
+#endif // __TCOMWEDGELET__
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TypeDef.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TypeDef.h	(revision 459)
@@ -78,4 +78,14 @@
                                               // SAIT_VSO_EST_A0033, JCT3V-A0033 modification 3
                                               // LGE_WVSO_A0119
+#define H_3D_DIM                          1   // DIM, Depth intra modes, includes:
+                                              // HHI_DMM_WEDGE_INTRA
+                                              // HHI_DMM_PRED_TEX
+                                              // FIX_WEDGE_NOFLOAT_D0036
+                                              // LGE_EDGE_INTRA_A0070
+                                              // LGE_DMM3_SIMP_C0044
+                                              // QC_DC_PREDICTOR_D0183
+                                              // HHI_DELTADC_DLT_D0035
+                                              // PKU_QC_DEPTH_INTRA_UNI_D0195
+                                              // ... [PM: add SDC and DLT related]
 #endif 
 
@@ -91,4 +101,12 @@
 #define H_3D_VSO_RM_ASSERTIONS            0   // Output VSO assertions
 #define H_3D_VSO_SYNTH_DIST_OUT           0   // Output of synthesized view distortion instead of depth distortion in encoder output
+#endif
+
+///// ***** DEPTH INTRA MODES *********
+#if H_3D_DIM
+#define H_3D_DIM_DMM                   1 // Depth Modeling Modes
+#define H_3D_DIM_RBC                   1 // Region Boundary Chain mode
+#define H_3D_DIM_SDC                   0 // Simplified Depth Coding method
+#define H_3D_DIM_DLT                   0 // Depth Lookup Table
 #endif
 
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 459)
@@ -953,8 +953,20 @@
     if (uiCode)
     {
+#if H_3D
+      m_pcBitstream->readOutTrailingBits();
+
+      for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
+      {
+        if( pcVPS->getDepthId( i ) )
+        {
+          READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
+        }
+      }
+#else
       while ( xMoreRbspData() )
       {
         READ_FLAG( uiCode, "vps_extension2_data_flag");
       }
+#endif
     }
 
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCu.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCu.cpp	(revision 459)
@@ -468,5 +468,16 @@
   
   //===== get prediction signal =====
+#if H_3D_DIM
+  if( isDimMode( uiLumaPredMode ) )
+  {
+    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
+  }
+  else
+  {
+#endif
   m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
+#if H_3D_DIM
+  }
+#endif
   
   //===== inverse transform =====
@@ -556,4 +567,7 @@
     {
       uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
+#if H_3D_DIM
+      mapDepthModeToIntraDir( uiChromaPredMode );
+#endif
     }
     m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );  
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 459)
@@ -77,4 +77,17 @@
 , m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
 , m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+#if H_3D_DIM
+, m_cDepthIntraModeSCModel    ( 1,             1,               NUM_DEPTH_INTRA_MODE_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDdcFlagSCModel           ( 1,             1,               NUM_DDC_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDdcDataSCModel           ( 1,             1,               NUM_DDC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
+#if H_3D_DIM_DMM
+, m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDmm2DataSCModel          ( 1,             1,               NUM_DMM2_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDmm3DataSCModel          ( 1,             1,               NUM_DMM3_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
+#if H_3D_DIM_RBC
+, m_cRbcDataSCModel           ( 1,             1,               NUM_RBC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
+#endif
 {
   assert( m_numContextModels <= MAX_NUM_CTX_MOD );
@@ -137,4 +150,19 @@
   m_cTransformSkipSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
   m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
+
+#if H_3D_DIM
+  m_cDepthIntraModeSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE );
+  m_cDdcFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_FLAG );
+  m_cDdcDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_DATA );
+#if H_3D_DIM_DMM
+  m_cDmm1DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM1_DATA );
+  m_cDmm2DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM2_DATA );
+  m_cDmm3DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM3_DATA );
+#endif
+#if H_3D_DIM_RBC
+  m_cRbcDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_RBC_DATA );
+#endif
+#endif
+
   m_uiLastDQpNonZero  = 0;
   
@@ -181,4 +209,18 @@
   m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
   m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
+
+#if H_3D_DIM
+  m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
+  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
+  m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
+#if H_3D_DIM_DMM
+  m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
+  m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
+  m_cDmm3DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA );
+#endif
+#if H_3D_DIM_RBC
+  m_cRbcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_RBC_DATA );
+#endif
+#endif
   m_pcTDecBinIf->start();
 }
@@ -297,4 +339,171 @@
   }
 }
+
+#if H_3D_DIM
+Void TDecSbac::xReadExGolombLevel( UInt& ruiSymbol, ContextModel& rcSCModel  )
+{
+  UInt uiSymbol;
+  UInt uiCount = 0;
+  do
+  {
+    m_pcTDecBinIf->decodeBin( uiSymbol, rcSCModel );
+    uiCount++;
+  }
+  while( uiSymbol && ( uiCount != 13 ) );
+
+  ruiSymbol = uiCount - 1;
+
+  if( uiSymbol )
+  {
+    xReadEpExGolomb( uiSymbol, 0 );
+    ruiSymbol += uiSymbol + 1;
+  }
+
+  return;
+}
+
+Void TDecSbac::xParseDimDeltaDC( Pel& rValDeltaDC, UInt dimType )
+{
+  UInt absValDeltaDC = 0;
+  xReadExGolombLevel( absValDeltaDC, m_cDdcDataSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) );
+  rValDeltaDC = (Pel)absValDeltaDC;
+
+  if( rValDeltaDC != 0 )
+  {
+    UInt uiSign;
+    m_pcTDecBinIf->decodeBinEP( uiSign );
+    if ( uiSign )
+    {
+      rValDeltaDC = -rValDeltaDC;
+    }
+  }
+}
+#if H_3D_DIM_DMM
+Void TDecSbac::xParseDmm1WedgeIdx( UInt& ruiTabIdx, Int iNumBit )
+{
+  UInt uiSymbol, uiIdx = 0;
+  for( Int i = 0; i < iNumBit; i++ )
+  {
+    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm1DataSCModel.get(0, 0, 0) );
+    uiIdx += uiSymbol << i;
+  }
+  ruiTabIdx = uiIdx;
+}
+Void TDecSbac::xParseDmm2Offset( Int& riOffset )
+{
+  Int iDeltaEnd = 0;
+  if( DMM2_DELTAEND_MAX > 0 )
+  {
+    UInt uiFlag = 0;
+    m_pcTDecBinIf->decodeBin( uiFlag, m_cDmm2DataSCModel.get(0, 0, 0) );
+
+    if( uiFlag )
+    {
+      UInt uiAbsValMinus1;
+      UInt uiSymbol;
+      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm2DataSCModel.get(0, 0, 0) ); uiAbsValMinus1  = uiSymbol;
+      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm2DataSCModel.get(0, 0, 0) ); uiAbsValMinus1 |= uiSymbol << 1;
+      iDeltaEnd = uiAbsValMinus1 + 1;
+      UInt uiSign;
+      m_pcTDecBinIf->decodeBinEP( uiSign );
+      if( uiSign )
+      {
+        iDeltaEnd = -iDeltaEnd;
+      }
+    }
+  }
+  riOffset = iDeltaEnd;
+}
+Void TDecSbac::xParseDmm3WedgeIdx( UInt& ruiIntraIdx, Int iNumBit )
+{
+  UInt uiSymbol, uiIdx = 0;
+  for( Int i = 0; i < iNumBit; i++ )
+  {
+    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmm3DataSCModel.get(0, 0, 0) );
+    uiIdx += uiSymbol << i;
+  }
+  ruiIntraIdx = uiIdx;
+}
+#endif
+#if H_3D_DIM_RBC
+Void TDecSbac::xParseRbcEdge( 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 * RBC_MAX_EDGE_NUM_PER_4x4 );
+  for( Int iPtr = 0; iPtr < ucMax; iPtr++ )
+  {
+    UChar ucEdge = 0;
+    UInt  uiReorderEdge = 0;
+    for( UInt ui = 0; ui < 6; ui++ )
+    {
+      m_pcTDecBinIf->decodeBin( uiSymbol, m_cRbcDataSCModel.get( 0, 0, 0 ) );
+      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
+#endif
 
 /** Parse I_PCM information. 
@@ -619,9 +828,30 @@
   for (j=0;j<partNum;j++)
   {
+#if H_3D_DIM
+    if( pcCU->getSlice()->getVpsDepthModesFlag() )
+    {
+      parseIntraDepth( pcCU, absPartIdx+partOffset*j, depth );
+    }
+    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
+#if H_3D_DIM_SDC
+      if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
+#endif
+    {
+#endif
     m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
     mpmPred[j] = symbol;
+#if H_3D_DIM
+    }
+#endif
   }
   for (j=0;j<partNum;j++)
   {
+#if H_3D_DIM
+    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
+#if H_3D_DIM_SDC
+      if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
+#endif
+    {
+#endif
     Int preds[3] = {-1, -1, -1};
     Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds);  
@@ -661,4 +891,7 @@
     }
     pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
+#if H_3D_DIM
+    }
+#endif
   }
 }
@@ -687,4 +920,176 @@
   return;
 }
+
+#if H_3D_DIM
+Void TDecSbac::parseIntraDepth( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
+{
+  parseIntraDepthMode( pcCU, absPartIdx, depth );
+
+  UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
+  UInt dimType = getDimType( dir );
+
+  switch( dimType )
+  {
+#if H_3D_DIM_DMM
+  case( DMM1_IDX ):
+    {
+      UInt uiTabIdx = 0;
+      xParseDmm1WedgeIdx( uiTabIdx, g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
+      pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, absPartIdx, depth );
+    } break;
+  case( DMM2_IDX ):
+    {
+      Int iOffset = 0;
+      xParseDmm2Offset( iOffset );
+      pcCU->setDmm2DeltaEndSubParts( iOffset, absPartIdx, depth );
+    } break;
+  case( DMM3_IDX ):
+    {
+      UInt uiIntraIdx = 0;
+      xParseDmm3WedgeIdx( uiIntraIdx, g_dmm3IntraTabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
+      pcCU->setDmm3IntraTabIdxSubParts( uiIntraIdx, absPartIdx, depth );
+    } break;
+  case( DMM4_IDX ): break;
+#endif
+#if H_3D_DIM_RBC
+  case( RBC_IDX ): 
+    {
+      xParseRbcEdge( pcCU, absPartIdx, depth );
+    } break;
+#endif
+  default: break;
+  }
+
+#if H_3D_DIM_SDC
+  if( pcCU->getSDCAvailable(absPartIdx) && pcCU->getSDCFlag(absPartIdx) ) // sdcFlag
+  {
+    //assert(pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_NxN);
+    //pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth);
+    //pcCU->setCbfSubParts(1, 1, 1, uiAbsPartIdx, uiDepth);
+
+    //UInt uiNumSegments = ( uiDir == DC_IDX || uiDir == PLANAR_IDX )? 1 : 2;
+    //for (int uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
+    //{
+    //  parseSDCResidualData(pcCU, uiAbsPartIdx, uiDepth, uiSeg);
+    //}
+  }
+  else
+  {
+#endif
+  if( dimType < DIM_NUM_TYPE )
+  {
+    UInt symbol;
+    m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) );
+    if( symbol )
+    {
+      dir += symbol;
+      for( UInt segment = 0; segment < 2; segment++ )
+      {
+        Pel valDeltaDC = 0;
+        xParseDimDeltaDC( valDeltaDC, dimType );
+        pcCU->setDimDeltaDC( dimType, segment, absPartIdx, valDeltaDC );
+      }
+    }
+  }
+#if H_3D_DIM_SDC
+  }
+#endif
+
+  pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
+}
+
+Void TDecSbac::parseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
+{
+  UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 );
+  UInt dir = 0;
+  Bool sdcFlag = 0;
+  UInt symbol = 1;
+  UInt modeCode = 0 ;
+  UInt binNum = 0;
+  UInt ctxDepthMode = 0;
+
+  if( puIdx == 2 )
+  {
+    while( binNum < 2 && symbol )
+    {
+      ctxDepthMode = puIdx*3 + binNum;
+      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
+      modeCode = (modeCode<<1) + symbol;
+      binNum++;
+    }
+         if( modeCode == 0 ) { dir = PLANAR_IDX; sdcFlag = 1;}
+    else if( modeCode == 2 ) { dir = 0;          sdcFlag = 0;}
+    else if( modeCode == 3 ) { dir =     DC_IDX; sdcFlag = 1;}
+  }
+  else if( puIdx == 0 )
+  {
+    while( binNum < 3 && symbol )
+    {
+      ctxDepthMode = puIdx*3 + ((binNum >= 2) ? 2 : binNum);
+      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
+      modeCode = (modeCode<<1) + symbol;
+      binNum++;
+    }
+         if( modeCode == 0 ) { dir = 0;                       sdcFlag = 0;}
+    else if( modeCode == 2 ) { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 0;}
+    else if( modeCode == 6 ) { dir = (2*DMM3_IDX+DIM_OFFSET); sdcFlag = 0;}
+    else if( modeCode == 7 ) { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
+  }
+  else
+  {
+    ctxDepthMode = puIdx*3 ;
+    m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
+    modeCode = (modeCode<<1) + symbol;
+    if( !symbol )
+    {
+      ctxDepthMode = puIdx*3 + 1;
+      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
+      modeCode = (modeCode<<1) + symbol;
+      if( symbol ) 
+      { 
+        ctxDepthMode = puIdx*3 + 2;
+        m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
+        modeCode = (modeCode<<1) + symbol;
+      }
+    }
+    else
+    {
+      ctxDepthMode = puIdx*3 + 1;
+      m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
+      modeCode = (modeCode<<1) + symbol;
+      if( !symbol ) 
+      { 
+        ctxDepthMode = puIdx*3 + 2;
+        m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
+        modeCode = (modeCode<<1) + symbol;
+      }
+      else
+      {
+        binNum = 0;
+        while( symbol && binNum < 3 )
+        {
+          ctxDepthMode = puIdx*3 + 2;
+          m_pcTDecBinIf->decodeBin( symbol, m_cDepthIntraModeSCModel.get(0,0,ctxDepthMode) );
+          modeCode = (modeCode<<1) + symbol;
+          binNum++;
+        }
+      }
+    }
+         if( modeCode == 0  ) { dir =  PLANAR_IDX;             sdcFlag = 1;}
+    else if( modeCode == 2  ) { dir = 5;                       sdcFlag = 0;}
+    else if( modeCode == 3  ) { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 1;}
+    else if( modeCode == 4  ) { dir = (2*DMM1_IDX+DIM_OFFSET); sdcFlag = 0;}
+    else if( modeCode == 5  ) { dir = (2*DMM4_IDX+DIM_OFFSET); sdcFlag = 0;}
+    else if( modeCode == 6  ) { dir = (2*DMM3_IDX+DIM_OFFSET); sdcFlag = 0;}
+    else if( modeCode == 14 ) { dir =      DC_IDX;             sdcFlag = 1;}
+    else if( modeCode == 30 ) { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
+    else if( modeCode == 31 ) { dir = (2*DMM2_IDX+DIM_OFFSET); sdcFlag = 0;}
+  }
+  pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
+#if H_3D_DIM_SDC
+  pcCU->setSDCFlagSubParts( sdcFlag, absPartIdx, 0, depth ); 
+#endif
+}
+#endif
 
 Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.h	(revision 459)
@@ -97,4 +97,16 @@
   Void  xReadEpExGolomb     ( UInt& ruiSymbol, UInt uiCount );
   Void  xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam );
+#if H_3D_DIM
+  Void  xReadExGolombLevel   ( UInt& ruiSymbol, ContextModel& rcSCModel  );
+  Void  xParseDimDeltaDC     ( Pel& rValDeltaDC, UInt dimType );
+#if H_3D_DIM_DMM
+  Void  xParseDmm1WedgeIdx   ( UInt& ruiTabIdx, Int iNumBit );
+  Void  xParseDmm2Offset     ( Int& riOffset );
+  Void  xParseDmm3WedgeIdx   ( UInt& ruiIntraIdx, Int iNumBit );
+#endif
+#if H_3D_DIM_RBC
+  Void  xParseRbcEdge        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#endif
+#endif
 private:
   TComInputBitstream* m_pcBitstream;
@@ -115,4 +127,9 @@
   Void parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   
+#if H_3D_DIM
+  Void parseIntraDepth     ( TComDataCU* pcCU, UInt absPartIdx, UInt depth );
+  Void parseIntraDepthMode ( TComDataCU* pcCU, UInt absPartIdx, UInt depth );
+#endif
+
   Void parseInterDir      ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx );
   Void parseRefFrmIdx     ( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList );
@@ -171,4 +188,18 @@
   ContextModel3DBuffer m_cTransformSkipSCModel;
   ContextModel3DBuffer m_CUTransquantBypassFlagSCModel;
+
+#if H_3D_DIM
+  ContextModel3DBuffer m_cDepthIntraModeSCModel;
+  ContextModel3DBuffer m_cDdcFlagSCModel;
+  ContextModel3DBuffer m_cDdcDataSCModel;
+#if H_3D_DIM_DMM
+  ContextModel3DBuffer m_cDmm1DataSCModel;
+  ContextModel3DBuffer m_cDmm2DataSCModel;
+  ContextModel3DBuffer m_cDmm3DataSCModel;
+#endif
+#if H_3D_DIM_RBC
+  ContextModel3DBuffer m_cRbcDataSCModel;
+#endif
+#endif
 };
 
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecTop.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecTop.cpp	(revision 459)
@@ -894,4 +894,7 @@
 
 #endif
+#if H_3D
+    pcSlice->setPicLists( m_ivPicLists );
+#endif
     // For generalized B
     // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 459)
@@ -741,5 +741,20 @@
     }
   }
+
+#if H_3D
+  WRITE_FLAG( 1,                                             "vps_extension2_flag" );
+
+  m_pcBitIf->writeAlignOne();                        
+  
+  for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
+  {
+    if( pcVPS->getDepthId( i ) )
+    {
+      WRITE_FLAG( pcVPS->getVpsDepthModesFlag( i ),          "vps_depth_modes_flag[i]" );
+    }
+  }
+#else
   WRITE_FLAG( 0,                                             "vps_extension2_flag" );
+#endif
 #else
   WRITE_FLAG( 0,                     "vps_extension_flag" );
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCfg.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCfg.h	(revision 459)
@@ -394,4 +394,12 @@
   Bool      m_bUseEstimatedVSD; 
   Double    m_dDispCoeff;
+
+  //====== Depth Intra Modes ======
+#if H_3D_DIM
+  Bool      m_useDMM;
+  Bool      m_useRBC;
+  Bool      m_useSDC;
+  Bool      m_useDLT;
+#endif
 #endif
 
@@ -926,4 +934,16 @@
   Void      setDispCoeff                    ( Double  d )   { m_dDispCoeff  = d; }
 #endif // H_3D_VSO
+
+ //==== DIM  ==========
+#if H_3D_DIM
+  Bool      getUseDMM                       ()        { return m_useDMM; }
+  Void      setUseDMM                       ( Bool b) { m_useDMM = b;    }
+  Bool      getUseRBC                       ()        { return m_useRBC; }
+  Void      setUseRBC                       ( Bool b) { m_useRBC = b;    }
+  Bool      getUseSDC                       ()        { return m_useSDC; }
+  Void      setUseSDC                       ( Bool b) { m_useSDC = b;    }
+  Bool      getUseDLT                       ()        { return m_useDLT; }
+  Void      setUseDLT                       ( Bool b) { m_useDLT = b;    }
+#endif
 #endif // H_3D
 };
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 459)
@@ -673,4 +673,7 @@
     pcSlice->setRefPicList ( rcListPic );
 #endif
+#if H_3D
+    pcSlice->setPicLists( m_ivPicLists );
+#endif
 
     //  Slice info. refinement
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 459)
@@ -83,4 +83,17 @@
 , m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
 , m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+#if H_3D_DIM
+, m_cDepthIntraModeSCModel    ( 1,             1,               NUM_DEPTH_INTRA_MODE_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDdcFlagSCModel           ( 1,             1,               NUM_DDC_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDdcDataSCModel           ( 1,             1,               NUM_DDC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
+#if H_3D_DIM_DMM
+, m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDmm2DataSCModel          ( 1,             1,               NUM_DMM2_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDmm3DataSCModel          ( 1,             1,               NUM_DMM3_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
+#if H_3D_DIM_RBC
+, m_cRbcDataSCModel           ( 1,             1,               NUM_RBC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
+#endif
 {
   assert( m_numContextModels <= MAX_NUM_CTX_MOD );
@@ -134,4 +147,18 @@
   m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
   m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
+
+#if H_3D_DIM
+  m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
+  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
+  m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
+#if H_3D_DIM_DMM
+  m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
+  m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
+  m_cDmm3DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA );
+#endif
+#if H_3D_DIM_RBC
+  m_cRbcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_RBC_DATA );
+#endif
+#endif
   // new structure
   m_uiLastQp = iQp;
@@ -188,4 +215,20 @@
       curCost += m_cTransformSkipSCModel.calcCost     ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
       curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
+#if H_3D_DIM
+    if( m_pcSlice->getVpsDepthModesFlag() )
+    {
+      curCost += m_cDepthIntraModeSCModel.calcCost    ( curSliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE );
+      curCost += m_cDdcFlagSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_DDC_FLAG );
+      curCost += m_cDdcDataSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_DDC_DATA );
+#if H_3D_DIM_DMM
+      curCost += m_cDmm1DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM1_DATA );
+      curCost += m_cDmm2DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM2_DATA );
+      curCost += m_cDmm3DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM3_DATA );
+#endif
+#if H_3D_DIM_RBC
+      curCost += m_cRbcDataSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_RBC_DATA );
+#endif
+    }
+#endif
       if (curCost < bestCost)
       {
@@ -237,4 +280,18 @@
   m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
   m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
+
+#if H_3D_DIM
+  m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
+  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
+  m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
+#if H_3D_DIM_DMM
+  m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
+  m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
+  m_cDmm3DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA );
+#endif
+#if H_3D_DIM_RBC
+  m_cRbcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_RBC_DATA );
+#endif
+#endif
   m_pcBinIf->start();
 }
@@ -379,4 +436,130 @@
 }
 
+#if H_3D_DIM
+Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel  )
+{
+  if( uiSymbol )
+  {
+    m_pcBinIf->encodeBin( 1, rcSCModel );
+    UInt uiCount = 0;
+    Bool bNoExGo = (uiSymbol < 13);
+
+    while( --uiSymbol && ++uiCount < 13 )
+    {
+      m_pcBinIf->encodeBin( 1, rcSCModel );
+    }
+    if( bNoExGo )
+    {
+      m_pcBinIf->encodeBin( 0, rcSCModel );
+    }
+    else
+    {
+      xWriteEpExGolomb( uiSymbol, 0 );
+    }
+  }
+  else
+  {
+    m_pcBinIf->encodeBin( 0, rcSCModel );
+  }
+
+  return;
+}
+
+Void TEncSbac::xCodeDimDeltaDC( Pel valDeltaDC, UInt dimType )
+{
+  xWriteExGolombLevel( UInt( abs( valDeltaDC ) ), m_cDdcDataSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) );
+  if( valDeltaDC != 0 )
+  {
+    UInt uiSign = valDeltaDC > 0 ? 0 : 1;
+    m_pcBinIf->encodeBinEP( uiSign );
+  }
+}
+
+#if H_3D_DIM_DMM
+Void TEncSbac::xCodeDmm1WedgeIdx( UInt uiTabIdx, Int iNumBit )
+{
+  for ( Int i = 0; i < iNumBit; i++ )
+  {
+    m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmm1DataSCModel.get(0, 0, 0) );
+  }
+}
+
+Void TEncSbac::xCodeDmm2Offset( Int iOffset )
+{
+  if( DMM2_DELTAEND_MAX > 0 )
+  {
+    m_pcBinIf->encodeBin( (iOffset != 0) , m_cDmm2DataSCModel.get(0, 0, 0) );
+    if( iOffset != 0 )
+    {
+      UInt uiAbsValMinus1 = abs(iOffset)-1;
+      m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01),      m_cDmm2DataSCModel.get(0, 0, 0) );
+      m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmm2DataSCModel.get(0, 0, 0) );
+
+      UInt uiSign = (iOffset > 0) ? 0 : 1;
+      m_pcBinIf->encodeBinEP( uiSign );
+    }
+  }
+}
+
+Void TEncSbac::xCodeDmm3WedgeIdx( UInt uiIntraIdx, Int iNumBit )
+{
+  for( Int i = 0; i < iNumBit; i++ )
+  {
+    m_pcBinIf->encodeBin( ( uiIntraIdx >> i ) & 1, m_cDmm3DataSCModel.get(0, 0, 0) );
+  }
+}
+#endif
+#if H_3D_DIM_RBC
+Void TEncSbac::xCodeRbcEdge( TComDataCU* pcCU, UInt uiAbsPartIdx )
+{
+  UInt   uiDepth        = pcCU->getDepth( uiAbsPartIdx ) + (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0);
+  UChar* pucSymbolList  = pcCU->getEdgeCode     ( uiAbsPartIdx );
+  UChar  ucEdgeNumber   = pcCU->getEdgeNumber   ( uiAbsPartIdx );
+  Bool   bLeft          = pcCU->getEdgeLeftFirst( uiAbsPartIdx );
+  UChar  ucStart        = pcCU->getEdgeStartPos ( uiAbsPartIdx );
+  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];
+    for( UInt ui = 0; ui < uiReorderSymbol; ui++ )
+    {
+      m_pcBinIf->encodeBin( 1, m_cRbcDataSCModel.get( 0, 0, 0 ) );
+    }
+
+    if( uiReorderSymbol != 6 )
+      m_pcBinIf->encodeBin( 0, m_cRbcDataSCModel.get( 0, 0, 0 ) );
+  }
+}
+#endif
+#endif
+
 // SBAC RD
 Void  TEncSbac::load ( TEncSbac* pSrc)
@@ -391,5 +574,13 @@
   this->m_cCUIntraPredSCModel      .copyFrom( &pSrc->m_cCUIntraPredSCModel       );
 }
-
+#if H_3D_DIM
+Void TEncSbac::loadIntraDepthMode( TEncSbac* pSrc)
+{
+  m_pcBinIf->copyState( pSrc->m_pcBinIf );
+
+  this->m_cDepthIntraModeSCModel .copyFrom( &pSrc->m_cDepthIntraModeSCModel );
+  this->m_cDdcFlagSCModel        .copyFrom( &pSrc->m_cDdcFlagSCModel );
+}
+#endif
 
 Void  TEncSbac::store( TEncSbac* pDest)
@@ -628,4 +819,15 @@
   {
     dir[j] = pcCU->getLumaIntraDir( absPartIdx+partOffset*j );
+#if H_3D_DIM
+    if( pcCU->getSlice()->getVpsDepthModesFlag() )
+    {
+      codeIntraDepth( pcCU, absPartIdx+partOffset*j );
+    }
+    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
+#if H_3D_DIM_SDC
+      if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
+#endif
+    {
+#endif
     predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]);  
     for(UInt i = 0; i < predNum[j]; i++)
@@ -637,7 +839,17 @@
     }
     m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) );
+#if H_3D_DIM
+    }
+#endif
   }  
   for (j=0;j<partNum;j++)
   {
+#if H_3D_DIM
+    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
+#if H_3D_DIM_SDC
+      if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
+#endif
+    {
+#endif
     if(predIdx[j] != -1)
     {
@@ -668,4 +880,7 @@
       m_pcBinIf->encodeBinsEP( dir[j], 5 );
     }
+#if H_3D_DIM
+    }
+#endif
   }
   return;
@@ -699,4 +914,119 @@
   return;
 }
+
+#if H_3D_DIM
+Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx, Bool sdcRD )
+{
+  codeIntraDepthMode( pcCU, absPartIdx );
+
+  UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
+  UInt dimType = getDimType( dir );
+
+  switch( dimType )
+  {
+#if H_3D_DIM_DMM
+  case( DMM1_IDX ):
+    {
+      xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
+    } break;
+  case( DMM2_IDX ):
+    {
+      xCodeDmm2Offset( pcCU->getDmm2DeltaEnd( absPartIdx ) );
+    } break;
+  case( DMM3_IDX ):
+    {
+      xCodeDmm3WedgeIdx( pcCU->getDmm3IntraTabIdx( absPartIdx ), g_dmm3IntraTabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
+    } break;
+  case( DMM4_IDX ): break;
+#endif
+#if H_3D_DIM_RBC
+  case( RBC_IDX ):
+    {
+      assert( pcCU->getWidth( absPartIdx ) < 64 );
+      xCodeRbcEdge( pcCU, absPartIdx );
+    } break;
+#endif
+  default: break;
+  }
+
+#if H_3D_DIM_SDC
+  if( pcCU->getSDCFlag( absPartIdx ) )
+  {
+  //  assert(pcCU->getPartitionSize(uiAbsPartIdx)==SIZE_2Nx2N);
+  //  UInt uiNumSegments = ( uiDir == DC_IDX || uiDir == PLANAR_IDX )? 1 : 2;
+  //  if(!bSdcRD)
+  //  {
+  //    for (int uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
+  //    {
+  //      codeSDCResidualData(pcCU, uiAbsPartIdx, uiSeg);
+  //    }
+  //  }
+  }
+  else
+  {
+#endif
+    if( dimType < DIM_NUM_TYPE )
+    {
+      UInt dimDeltaDC = isDimDeltaDC( dir );
+      m_pcBinIf->encodeBin( dimDeltaDC, m_cDdcFlagSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) );
+      if( dimDeltaDC ) 
+      {
+        for( UInt segment = 0; segment < 2; segment++ )
+        {
+          xCodeDimDeltaDC( pcCU->getDimDeltaDC( dimType, segment, absPartIdx ), dimType );
+        }
+      }
+    }
+#if H_3D_DIM_SDC
+  }
+#endif
+}
+
+Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx )
+{
+  UInt codeWordTable[3][9] =    {{0, 0, 0, 2, 0,6, 0, 0, 7},{0, 2, 3, 4, 5, 6, 14, 31, 30},{0, 2, 0, 0, 0, 0, 3, 0, 0}};
+  UInt codeWordLenTable[3][9] = {{0, 1, 0, 2, 0,3, 0, 0, 3},{2, 3, 3, 3, 3, 3,  4,  5,  5},{1, 2, 0, 0, 0, 0, 2, 0, 0}};
+  UInt dir = pcCU->getLumaIntraDir( absPartIdx );
+  UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 );
+  UInt codeIdx = 0;
+
+  if( dir < NUM_INTRA_MODE )
+  { 
+    codeIdx = 1; 
+  }
+  if( isDimMode( dir ) )
+  {
+    switch( getDimType( dir ) )
+    {
+    case DMM1_IDX: codeIdx = 3; break;
+    case DMM4_IDX: codeIdx = 4; break;
+    case DMM3_IDX: codeIdx = 5; break;
+    case DMM2_IDX: codeIdx = 7; break;
+    case  RBC_IDX: codeIdx = 8; break;
+    default:                    break;
+    }
+  }
+
+#if H_3D_DIM_SDC
+  if( pcCU->getSDCFlag( absPartIdx ) )
+  { 
+  //  switch( dir )
+  //  {
+  //  case PLANAR_IDX:              codeIdx = 0; break;
+  //  case DC_IDX:                  codeIdx = 6; break;
+  //  case (2*DMM1_IDX+DIM_OFFSET): codeIdx = 2; break;
+  //  default:                                   break;
+  //  }
+  }
+#endif
+  //mode coding
+  for( UInt i = 0; i < codeWordLenTable[puIdx][codeIdx]; i++ )
+  {
+    UInt bit = codeWordTable[puIdx][codeIdx] & ( 1<<(codeWordLenTable[puIdx][codeIdx] - i - 1) );
+    UInt ctxDepthMode = puIdx*3 + ( (i >= 2) ? 2 : i );
+    m_pcBinIf->encodeBin( bit!=0 , m_cDepthIntraModeSCModel.get(0, 0, ctxDepthMode) );
+  }
+}
+#endif
 
 Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx )
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.h	(revision 459)
@@ -84,4 +84,7 @@
   Void  load                   ( TEncSbac* pScr  );
   Void  loadIntraDirModeLuma   ( TEncSbac* pScr  );
+#if H_3D_DIM
+  Void  loadIntraDepthMode     ( TEncSbac* pScr  );
+#endif
   Void  store                  ( TEncSbac* pDest );
   Void  loadContexts           ( TEncSbac* pScr  );
@@ -113,4 +116,16 @@
   Void  xWriteEpExGolomb     ( UInt uiSymbol, UInt uiCount );
   Void  xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam );
+  #if H_3D_DIM
+  Void  xWriteExGolombLevel  ( UInt uiSymbol, ContextModel& rcSCModel  );
+  Void  xCodeDimDeltaDC      ( Pel valDeltaDC, UInt dimType );
+#if H_3D_DIM_DMM
+  Void  xCodeDmm1WedgeIdx    ( UInt uiTabIdx, Int iNumBit );
+  Void  xCodeDmm2Offset      ( Int iOffset );
+  Void  xCodeDmm3WedgeIdx    ( UInt uiIntraIdx, Int iNumBit );
+#endif
+#if H_3D_DIM_RBC
+  Void  xCodeRbcEdge         ( TComDataCU* pcCU, UInt uiAbsPartIdx );
+#endif
+#endif
   
   Void  xCopyFrom            ( TEncSbac* pSrc );
@@ -148,4 +163,10 @@
   
   Void codeIntraDirChroma      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
+
+#if H_3D_DIM
+  Void codeIntraDepth          ( TComDataCU* pcCU, UInt absPartIdx, Bool sdcRD = false );
+  Void codeIntraDepthMode      ( TComDataCU* pcCU, UInt absPartIdx );
+#endif
+
   Void codeInterDir            ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeRefFrmIdx           ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
@@ -207,4 +228,18 @@
   ContextModel3DBuffer m_cTransformSkipSCModel;
   ContextModel3DBuffer m_CUTransquantBypassFlagSCModel;
+
+#if H_3D_DIM
+  ContextModel3DBuffer m_cDepthIntraModeSCModel;
+  ContextModel3DBuffer m_cDdcFlagSCModel;
+  ContextModel3DBuffer m_cDdcDataSCModel;
+#if H_3D_DIM_DMM
+  ContextModel3DBuffer m_cDmm1DataSCModel;
+  ContextModel3DBuffer m_cDmm2DataSCModel;
+  ContextModel3DBuffer m_cDmm3DataSCModel;
+#endif
+#if H_3D_DIM_RBC
+  ContextModel3DBuffer m_cRbcDataSCModel;
+#endif
+#endif
 };
 
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 459)
@@ -1047,5 +1047,17 @@
     pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail );
     //===== get prediction signal =====
+#if H_3D_DIM
+    if( isDimMode( uiLumaPredMode ) )
+    {
+      predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, true );
+    }
+    else
+    {
+#endif
     predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
+#if H_3D_DIM
+    }
+#endif
+
     // save prediction 
     if(default0Save1Load2 == 1)
@@ -1224,4 +1236,7 @@
   {
     uiChromaPredMode          = pcCU->getLumaIntraDir( 0 );
+#if H_3D_DIM
+    mapDepthModeToIntraDir( uiChromaPredMode );
+#endif
   }
   
@@ -1431,4 +1446,11 @@
 #endif
 #endif
+#if H_3D_DIM
+  if( isDimMode( pcCU->getLumaIntraDir( uiAbsPartIdx ) ) )
+  {
+    bCheckSplit = false;
+  }
+#endif
+
   Double  dSingleCost   = MAX_DOUBLE;
 #if H_3D_VSO
@@ -2624,4 +2646,86 @@
     }
     
+#if H_3D_DIM
+    //===== determine set of depth intra modes to be tested =====
+    if( m_pcEncCfg->getIsDepth() && uiWidth >= DIM_MIN_SIZE && uiWidth <= DIM_MAX_SIZE && uiWidth == uiHeight )
+    {
+#if H_3D_DIM_DMM
+      if( m_pcEncCfg->getUseDMM() )
+      {
+        for( UInt dmmType = 0; dmmType < DMM_NUM_TYPE; dmmType++ )
+        {
+          UInt uiTabIdx = 0;
+          TComWedgelet* biSegmentation = NULL;
+          Pel deltaDC1 = 0; Pel deltaDC2 = 0;
+          switch( dmmType )
+          {
+          case( DMM1_IDX ):
+            {
+              xSearchDmm1Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx );
+              pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType,  uiPartOffset, uiDepth + uiInitTrDepth );
+              biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
+            } break;
+          case( DMM2_IDX ):
+            {
+              if( uiWidth > 4 )
+              {
+                Int dmm2DeltaEnd = 0;
+                xSearchDmm2Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, dmm2DeltaEnd );
+                pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth );
+                pcCU->setDmm2DeltaEndSubParts( dmm2DeltaEnd, uiPartOffset, uiDepth + uiInitTrDepth );
+                biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
+              }
+            } break;
+          case( DMM3_IDX ):
+            {
+              UInt uiIntraTabIdx = 0;
+              xSearchDmm3Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, uiIntraTabIdx );
+              pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth );
+              pcCU->setDmm3IntraTabIdxSubParts( uiIntraTabIdx, uiPartOffset, uiDepth + uiInitTrDepth );
+              biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
+            } break;
+          case( DMM4_IDX ):
+            {
+              if( uiWidth > 4 )
+              {
+                biSegmentation = new TComWedgelet( uiWidth, uiHeight );
+                xPredContourFromTex( pcCU, uiPartOffset, uiWidth, uiHeight, biSegmentation );
+              }
+            } break;
+          default: assert(0);
+          }
+
+          if( biSegmentation )
+          {
+            xSearchDmmDeltaDCs( pcCU, uiPartOffset, piOrg, piPred, uiStride, biSegmentation->getPattern(), biSegmentation->getStride(), uiWidth, uiHeight, deltaDC1, deltaDC2 );
+            pcCU->setDimDeltaDC( dmmType, 0, uiPartOffset, deltaDC1 );
+            pcCU->setDimDeltaDC( dmmType, 1, uiPartOffset, deltaDC2 );
+
+            uiRdModeList[ numModesForFullRD++ ] = (2*dmmType  +DIM_OFFSET);
+            uiRdModeList[ numModesForFullRD++ ] = (2*dmmType+1+DIM_OFFSET);
+
+            if( DMM4_IDX == dmmType ) { biSegmentation->destroy(); delete biSegmentation; }
+          }
+        }
+      }
+#endif
+#if H_3D_DIM_RBC
+      if( m_pcEncCfg->getUseRBC() )
+      {
+        if( xSearchRbcEdge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight ) )
+        {
+          Pel deltaDC1 = 0; Pel deltaDC2 = 0;
+          xSearchRbcDeltaDCs( pcCU, uiPartOffset, piOrg, piPred, uiStride, pcCU->getEdgePartition( uiPartOffset ), uiWidth, uiWidth, uiHeight, deltaDC1, deltaDC2 );
+          pcCU->setDimDeltaDC( RBC_IDX, 0, uiPartOffset, deltaDC1 );
+          pcCU->setDimDeltaDC( RBC_IDX, 1, uiPartOffset, deltaDC2 );
+
+          uiRdModeList[ numModesForFullRD++ ] = (2*RBC_IDX  +DIM_OFFSET);
+          uiRdModeList[ numModesForFullRD++ ] = (2*RBC_IDX+1+DIM_OFFSET);
+        }
+      }
+#endif
+    }
+#endif
+
     //===== check modes (using r-d costs) =====
 #if HHI_RQT_INTRA_SPEEDUP_MOD
@@ -6091,4 +6195,7 @@
     // Reload only contexts required for coding intra mode information
     m_pcRDGoOnSbacCoder->loadIntraDirModeLuma( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
+#if H_3D_DIM
+    m_pcRDGoOnSbacCoder->loadIntraDepthMode( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
+#endif
   }
   
@@ -6407,3 +6514,1402 @@
 }
 
+  // -------------------------------------------------------------------------------------------------------------------
+  // Depth intra search
+  // -------------------------------------------------------------------------------------------------------------------
+#if H_3D_DIM
+Void TEncSearch::xCalcBiSegDCs( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2 )
+{
+  valDC1 = ( 1<<( g_bitDepthY - 1) );
+  valDC2 = ( 1<<( g_bitDepthY - 1) );
+
+  UInt uiDC1 = 0;
+  UInt uiDC2 = 0;
+  UInt uiNumPixDC1 = 0, uiNumPixDC2 = 0;
+  if( srcStride == patternStride )
+  {
+    for( UInt k = 0; k < (patternStride * patternStride); k++ )
+    {
+      if( true == biSegPattern[k] ) 
+      {
+        uiDC2 += ptrSrc[k];
+        uiNumPixDC2++;
+      }
+      else
+      {
+        uiDC1 += ptrSrc[k];
+        uiNumPixDC1++;
+      }
+    }
+  }
+  else
+  {
+    Pel* piTemp = ptrSrc;
+    for( UInt uiY = 0; uiY < patternStride; uiY++ )
+    {
+      for( UInt uiX = 0; uiX < patternStride; uiX++ )
+      {
+        if( true == biSegPattern[uiX] ) 
+        {
+          uiDC2 += piTemp[uiX];
+          uiNumPixDC2++;
+        }
+        else
+        {
+          uiDC1 += piTemp[uiX];
+          uiNumPixDC1++;
+        }
+      }
+      piTemp       += srcStride;
+      biSegPattern += patternStride;
+    }
+  }
+
+  if( uiNumPixDC1 > 0 ) { valDC1 = uiDC1 / uiNumPixDC1; }
+  if( uiNumPixDC2 > 0 ) { valDC2 = uiDC2 / uiNumPixDC2; }
+}
+
+#if H_3D_DIM_DMM
+Void TEncSearch::xSearchDmmDeltaDCs( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 )
+{
+  assert( biSegPattern );
+  Pel origDC1 = 0; Pel origDC2 = 0;
+  xCalcBiSegDCs  ( piOrig,   uiStride, biSegPattern, patternStride, origDC1, origDC2 );
+  xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, origDC1, origDC2 );
+
+  Int* piMask = pcCU->getPattern()->getAdiOrgBuf( uiWidth, uiHeight, m_piYuvExt ); // no filtering for DMM
+  Int  maskStride = 2*uiWidth + 1;
+  Int* ptrSrc = piMask+maskStride+1;
+  Pel  predDC1 = 0; Pel predDC2 = 0;
+  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
+
+  rDeltaDC1 = origDC1 - predDC1;
+  rDeltaDC2 = origDC2 - predDC2;
+
+#if H_3D_VSO
+  if( m_pcRdCost->getUseVSO() )
+  {
+    Pel fullDeltaDC1 = rDeltaDC1;
+    Pel fullDeltaDC2 = rDeltaDC2;
+
+    Dist uiBestDist      = RDO_DIST_MAX;
+    UInt  uiBestQStepDC1 = 0;
+    UInt  uiBestQStepDC2 = 0;
+
+    UInt uiDeltaDC1Max = abs(fullDeltaDC1);
+    UInt uiDeltaDC2Max = abs(fullDeltaDC2);
+
+    //VSO Level delta DC check range extension
+    uiDeltaDC1Max += (uiDeltaDC1Max>>1);
+    uiDeltaDC2Max += (uiDeltaDC2Max>>1);
+
+    // limit search range to [0, IBDI_MAX]
+    if( fullDeltaDC1 <  0 && uiDeltaDC1Max >                          abs(predDC1) ) { uiDeltaDC1Max =                          abs(predDC1); }
+    if( fullDeltaDC1 >= 0 && uiDeltaDC1Max > ((1 << g_bitDepthY)-1) - abs(predDC1) ) { uiDeltaDC1Max = ((1 << g_bitDepthY)-1) - abs(predDC1); }
+
+    if( fullDeltaDC2 <  0 && uiDeltaDC2Max >                          abs(predDC2) ) { uiDeltaDC2Max =                          abs(predDC2); }
+    if( fullDeltaDC2 >= 0 && uiDeltaDC2Max > ((1 << g_bitDepthY)-1) - abs(predDC2) ) { uiDeltaDC2Max = ((1 << g_bitDepthY)-1) - abs(predDC2); }
+
+    // init dist with original segment DCs
+    xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, origDC1, origDC2 );
+
+    Dist uiOrgDist = RDO_DIST_MAX;
+    if( m_pcRdCost->getUseEstimatedVSD() )
+    {
+      uiOrgDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+    }
+    else
+    {
+      uiOrgDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+    }
+
+    uiBestDist     = uiOrgDist;
+    uiBestQStepDC1 = abs(fullDeltaDC1);
+    uiBestQStepDC2 = abs(fullDeltaDC2);
+
+    // coarse search with step size 4
+    for( UInt uiQStepDC1 = 0; uiQStepDC1 < uiDeltaDC1Max; uiQStepDC1 += 4 )
+    {
+      Pel testDC1 = ClipY( predDC1 + ((Int)(uiQStepDC1) * (( fullDeltaDC1 < 0 ) ? -1 : 1)) );
+      for( UInt uiQStepDC2 = 0; uiQStepDC2 < uiDeltaDC2Max; uiQStepDC2 += 4 )
+      {
+        Pel testDC2 = ClipY( predDC2 + ((Int)(uiQStepDC2) * (( fullDeltaDC2 < 0 ) ? -1 : 1)) );
+
+        xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, testDC1, testDC2 );
+
+        Dist uiAct4Dist = RDO_DIST_MAX;
+        if( m_pcRdCost->getUseEstimatedVSD() )
+        {
+          uiAct4Dist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+        }
+        else
+        {
+          uiAct4Dist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+        }
+
+        if( uiAct4Dist < uiBestDist || uiBestDist == RDO_DIST_MAX )
+        {
+          uiBestDist     = uiAct4Dist;
+          uiBestQStepDC1 = uiQStepDC1;
+          uiBestQStepDC2 = uiQStepDC2;
+        }
+      }
+    }
+
+    // refinement +-3
+    for( UInt uiQStepDC1 = (UInt)max(0, ((Int)uiBestQStepDC1-3)); uiQStepDC1 <= (uiBestQStepDC1+3); uiQStepDC1++ )
+    {
+      Pel testDC1 = ClipY( predDC1 + ((Int)(uiQStepDC1) * (( fullDeltaDC1 < 0 ) ? -1 : 1)) );
+      for( UInt uiQStepDC2 = (UInt)max(0, ((Int)uiBestQStepDC2-3)); uiQStepDC2 <= (uiBestQStepDC2+3); uiQStepDC2++ )
+      {
+        Pel testDC2 = ClipY( predDC2 + ((Int)(uiQStepDC2) * (( fullDeltaDC2 < 0 ) ? -1 : 1)) );
+
+        xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, testDC1, testDC2 );
+
+        Dist uiActDist = RDO_DIST_MAX;
+        if( m_pcRdCost->getUseEstimatedVSD() )
+        {
+          uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+        }
+        else
+        {
+          uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+        }
+
+        if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX )
+        {
+          uiBestDist     = uiActDist;
+          uiBestQStepDC1 = uiQStepDC1;
+          uiBestQStepDC2 = uiQStepDC2;
+        }
+      }
+    }
+    rDeltaDC1 = (Int)(uiBestQStepDC1) * (Int)(( fullDeltaDC1 < 0 ) ? -1 : 1);
+    rDeltaDC2 = (Int)(uiBestQStepDC2) * (Int)(( fullDeltaDC2 < 0 ) ? -1 : 1);
+  }
+#endif
+
+#if H_3D_DIM_DLT
+  rDeltaDC1 = (Int)GetDepthValue2Idx( ClipY(predDC1 + rDeltaDC1) ) - (Int)GetDepthValue2Idx( predDC1 );
+  rDeltaDC2 = (Int)GetDepthValue2Idx( ClipY(predDC2 + rDeltaDC2) ) - (Int)GetDepthValue2Idx( predDC2 );
+#endif
+}
+
+Void TEncSearch::xSearchDmm1Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx )
+{
+  ruiTabIdx = 0;
+
+  // local pred buffer
+  TComYuv cPredYuv;
+  cPredYuv.create( uiWidth, uiHeight );
+  cPredYuv.clear();
+
+  UInt uiPredStride = cPredYuv.getStride();
+  Pel* piPred       = cPredYuv.getLumaAddr();
+
+  Pel refDC1 = 0; Pel refDC2 = 0;
+  WedgeList*     pacWedgeList     = &g_dmmWedgeLists    [(g_aucConvertToBit[uiWidth])];
+  WedgeNodeList* pacWedgeNodeList = &g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])];
+
+  // coarse wedge search
+  Dist uiBestDist   = RDO_DIST_MAX;
+  UInt uiBestNodeId = 0;
+  for( UInt uiNodeId = 0; uiNodeId < pacWedgeNodeList->size(); uiNodeId++ )
+  {
+    TComWedgelet* pcWedgelet = &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx()));
+    xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+    xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+
+    Dist uiActDist = RDO_DIST_MAX;
+#if H_3D_VSO
+    if( m_pcRdCost->getUseVSO() )
+    {
+      if( m_pcRdCost->getUseEstimatedVSD() )
+      {
+        uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
+      }
+      else
+      {
+        uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
+      }
+    }
+    else
+#endif
+    {
+      uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
+    }
+
+    if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX )
+    {
+      uiBestDist   = uiActDist;
+      uiBestNodeId = uiNodeId;
+    }
+  }
+
+  // refinement
+  Dist uiBestDistRef = uiBestDist;
+  UInt uiBestTabIdxRef  = pacWedgeNodeList->at(uiBestNodeId).getPatternIdx();
+  for( UInt uiRefId = 0; uiRefId < DMM_NUM_WEDGE_REFINES; uiRefId++ )
+  {
+    if( pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ) != DMM_NO_WEDGEINDEX )
+    {
+      TComWedgelet* pcWedgelet = &(pacWedgeList->at(pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId )));
+      xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+      xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+
+      Dist uiActDist = RDO_DIST_MAX;
+#if H_3D_VSO
+      if( m_pcRdCost->getUseVSO() )
+      {
+        if( m_pcRdCost->getUseEstimatedVSD() )
+        {
+          uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
+        }
+        else
+        {
+          uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
+        }
+      }
+      else
+#endif
+      {
+        uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
+      }
+
+      if( uiActDist < uiBestDistRef || uiBestDistRef == RDO_DIST_MAX )
+      {
+        uiBestDistRef   = uiActDist;
+        uiBestTabIdxRef = pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId );
+      }
+    }
+  }
+
+  ruiTabIdx = uiBestTabIdxRef;
+
+  cPredYuv.destroy();
+  return;
+}
+
+Void TEncSearch::xSearchDmm2Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, Int& riWedgeDeltaEnd )
+{
+  ruiTabIdx       = 0;
+  riWedgeDeltaEnd = 0;
+
+  // local pred buffer
+  TComYuv cPredYuv;
+  cPredYuv.create( uiWidth, uiHeight );
+  cPredYuv.clear();
+
+  UInt uiPredStride = cPredYuv.getStride();
+  Pel* piPred       = cPredYuv.getLumaAddr();
+
+
+  // regular wedge search
+  Dist uiBestDist    = RDO_DIST_MAX;
+  UInt uiBestTabIdx  = 0;
+  Int  iBestDeltaEnd = 0;
+
+  UInt uiIdx = 0;
+  Pel refDC1 = 0; Pel refDC2 = 0;
+  for( Int iTestDeltaEnd = -DMM2_DELTAEND_MAX; iTestDeltaEnd <= DMM2_DELTAEND_MAX; iTestDeltaEnd++ )
+  {
+    uiIdx = xPredWedgeFromIntra( pcCU, uiAbsPtIdx, uiWidth, uiHeight, iTestDeltaEnd );
+    TComWedgelet* pcWedgelet = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiIdx]);
+    xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+    xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+
+    Dist uiActDist = RDO_DIST_MAX;
+#if H_3D_VSO
+    if( m_pcRdCost->getUseVSO() )
+    {
+      if( m_pcRdCost->getUseEstimatedVSD() )
+      {
+        uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
+      }
+      else
+      {
+        uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
+      }
+    }
+    else
+#endif
+    {
+      uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
+    }
+
+    if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX )
+    {
+      uiBestDist    = uiActDist;
+      uiBestTabIdx  = uiIdx;
+      iBestDeltaEnd = iTestDeltaEnd;
+    }
+    else if( uiIdx == uiBestTabIdx && abs(iTestDeltaEnd) < abs(iBestDeltaEnd) )
+    {
+      iBestDeltaEnd = iTestDeltaEnd;
+    }
+  }
+
+  ruiTabIdx       = uiBestTabIdx;
+  riWedgeDeltaEnd = iBestDeltaEnd;
+
+  cPredYuv.destroy();
+  return;
+}
+
+Void TEncSearch::xSearchDmm3Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx )
+{
+  ruiTabIdx       = 0;
+  ruiIntraTabIdx  = 0;
+
+  // local pred buffer
+  TComYuv cPredYuv; 
+  cPredYuv.create( uiWidth, uiHeight ); 
+  cPredYuv.clear();
+  Pel* piPred = cPredYuv.getLumaAddr();
+  UInt uiPredStride = cPredYuv.getStride();
+
+  // wedge search
+  UInt uiBestDist = MAX_UINT;
+  WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
+  Pel refDC1 = 0; Pel refDC2 = 0;
+
+  TComPic*      pcPicTex = pcCU->getSlice()->getPicLists()->getPic( pcCU->getSlice()->getViewIndex(), false, pcCU->getSlice()->getPOC() );
+  assert( pcPicTex != NULL );
+  TComDataCU* pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
+  UInt      uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPtIdx;
+  Int   uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
+
+  std::vector< std::vector<UInt> > pauiWdgLstSz = g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]];
+  if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 )
+  {
+    std::vector<UInt>* pauiWdgLst = &pauiWdgLstSz[uiColTexIntraDir-2];
+    for( UInt uiIdxW = 0; uiIdxW < pauiWdgLst->size(); uiIdxW++ )
+    {
+      UInt uiIdx     =   pauiWdgLst->at(uiIdxW);
+      TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiIdx));
+      xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+      xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+
+      UInt uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
+      if( uiActDist < uiBestDist || uiBestDist == MAX_UINT )
+      {
+        uiBestDist     = uiActDist;
+        ruiTabIdx      = uiIdx;
+        ruiIntraTabIdx = uiIdxW;
+      }
+    }
+  }
+  else
+  {
+    WedgeNodeList* pacWedgeNodeList = &g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])];
+    UInt uiBestNodeDist = MAX_UINT;
+    UInt uiBestNodeId   = 0;
+    for( UInt uiNodeId = 0; uiNodeId < pacWedgeNodeList->size(); uiNodeId++ )
+    {
+      TComWedgelet* pcWedgelet = &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx()));
+      xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+      xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+
+      UInt uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
+      if( uiActDist < uiBestNodeDist || uiBestNodeDist == MAX_UINT )
+      {
+        uiBestNodeDist = uiActDist;
+        uiBestNodeId   = uiNodeId;
+        ruiIntraTabIdx = uiNodeId;
+      }
+    }
+    ruiTabIdx = pacWedgeNodeList->at(uiBestNodeId).getPatternIdx();
+  }
+
+  cPredYuv.destroy();
+}
+#endif
+#if H_3D_DIM_RBC
+Void TEncSearch::xSearchRbcDeltaDCs( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 )
+{
+  assert( biSegPattern );
+  Pel origDC1 = 0; Pel origDC2 = 0;
+  xCalcBiSegDCs  ( piOrig,   uiStride, biSegPattern, patternStride, origDC1, origDC2 );
+  xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, origDC1, origDC2 );
+
+  Int* piMask = pcCU->getPattern()->getAdiOrgBuf( uiWidth, uiHeight, m_piYuvExt ); // no filtering for DMM
+  Int  maskStride = 2*uiWidth + 1;
+  Int* ptrSrc = piMask+maskStride+1;
+  Pel  predDC1 = 0; Pel predDC2 = 0;
+  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
+
+  rDeltaDC1 = origDC1 - predDC1;
+  rDeltaDC2 = origDC2 - predDC2;
+
+#if H_3D_VSO
+  if( m_pcRdCost->getUseVSO() )
+  {
+    Pel fullDeltaDC1 = rDeltaDC1;
+    Pel fullDeltaDC2 = rDeltaDC2;
+
+    xDeltaDCQuantScaleDown( pcCU, fullDeltaDC1 );
+    xDeltaDCQuantScaleDown( pcCU, fullDeltaDC2 );
+
+    Dist uiBestDist     = RDO_DIST_MAX;
+    UInt uiBestQStepDC1 = 0;
+    UInt uiBestQStepDC2 = 0;
+
+    UInt uiDeltaDC1Max = abs(fullDeltaDC1);
+    UInt uiDeltaDC2Max = abs(fullDeltaDC2);
+
+    //VSO Level delta DC check range extension
+    uiDeltaDC1Max += (uiDeltaDC1Max>>1);
+    uiDeltaDC2Max += (uiDeltaDC2Max>>1);
+
+    for( UInt uiQStepDC1 = 1; uiQStepDC1 <= uiDeltaDC1Max; uiQStepDC1++  )
+    {
+      Pel iLevelDeltaDC1 = (Pel)(uiQStepDC1) * (Pel)(( fullDeltaDC1 < 0 ) ? -1 : 1);
+      xDeltaDCQuantScaleUp( pcCU, iLevelDeltaDC1 );
+      Pel testDC1 = ClipY( predDC1 + iLevelDeltaDC1 );
+
+      for( UInt uiQStepDC2 = 1; uiQStepDC2 <= uiDeltaDC2Max; uiQStepDC2++  )
+      {
+        Pel iLevelDeltaDC2 = (Pel)(uiQStepDC2) * (Pel)(( fullDeltaDC2 < 0 ) ? -1 : 1);
+        xDeltaDCQuantScaleUp( pcCU, iLevelDeltaDC2 );
+        Pel testDC2 = ClipY( predDC2 + iLevelDeltaDC2 );
+
+        xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, testDC1, testDC2 );
+
+        Dist uiActDist = RDO_DIST_MAX;
+        if( m_pcRdCost->getUseEstimatedVSD() )
+        {
+          uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+        }
+        else
+        {
+          uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+        }
+
+        if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX )
+        {
+          uiBestDist     = uiActDist;
+          uiBestQStepDC1 = uiQStepDC1;
+          uiBestQStepDC2 = uiQStepDC2;
+        }
+      }
+    }
+
+    fullDeltaDC1 = (Int)(uiBestQStepDC1) * (Int)(( fullDeltaDC1 < 0 ) ? -1 : 1);
+    fullDeltaDC2 = (Int)(uiBestQStepDC2) * (Int)(( fullDeltaDC2 < 0 ) ? -1 : 1);
+    xDeltaDCQuantScaleUp( pcCU, fullDeltaDC1 );
+    xDeltaDCQuantScaleUp( pcCU, fullDeltaDC2 );
+    rDeltaDC1 = fullDeltaDC1;
+    rDeltaDC2 = fullDeltaDC2;
+  }
+#endif
+
+  xDeltaDCQuantScaleDown( pcCU, rDeltaDC1 );
+  xDeltaDCQuantScaleDown( pcCU, rDeltaDC2 );
+}
+
+Bool TEncSearch::xSearchRbcEdge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, Int iWidth, Int iHeight )
+{
+  Bool* pbEdge  = (Bool*) xMalloc( Bool, iWidth * iHeight * 4 );
+
+  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 = piRef[ x+1 + y*uiRefStride ] - piRef[ x + y*uiRefStride ];
+      if(*psDiffXPtr >= RBC_THRESHOLD || *psDiffXPtr <= (-1)*RBC_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 = piRef[ x + (y+1)*uiRefStride ] - piRef[ x + y*uiRefStride ];
+      if(*psDiffYPtr >= RBC_THRESHOLD || *psDiffYPtr <= (-1)*RBC_THRESHOLD)
+      {
+        *pbEdgeYPtr = true;
+      }
+      else
+      {
+        *pbEdgeYPtr = false;
+      }
+
+      psDiffYPtr++;
+      pbEdgeYPtr++;
+    }
+  }
+
+  // Eliminate local maximum
+  for( Int y=0; y<iHeight; y++ )
+  {
+    Short* psDiffXPtr = &psDiffX[ y * iHeight ];
+    Bool*  pbEdgeXPtr = &pbEdgeX[ y * iHeight ];
+    for( Int x=0; x<iWidth-1; x++ )
+    {
+      UShort usAbs0=0, usAbs1=0, usAbs2=0;  // 0 : left, 1 : current, 2 : right
+
+      if( x > 0 && *(pbEdgeXPtr-1) == true )
+      {
+        if( *(psDiffXPtr-1) >= 0)
+        {
+          usAbs0 = *(psDiffXPtr-1);
+
+        }
+        else
+        {
+          usAbs0 = (-1) * *(psDiffXPtr-1);
+        }
+      }
+      if( *pbEdgeXPtr == true )
+      {
+        if( *(psDiffXPtr) >= 0)
+        {
+          usAbs1 = *(psDiffXPtr);
+        }
+        else
+        {
+          usAbs1 = (-1) * *(psDiffXPtr);
+        }
+      }
+      if( x < iWidth-2 && *(pbEdgeXPtr+1) == true )
+      {
+        if( *(psDiffXPtr+1) >= 0)
+        {
+          usAbs2 = *(psDiffXPtr+1);
+          //bSign2 = true;
+        }
+        else
+        {
+          usAbs2 = (-1) * *(psDiffXPtr+1);
+        }
+      }
+
+      if( x == 0 )
+      {
+        if( usAbs1 < usAbs2 )
+        {
+          *pbEdgeXPtr = false;
+        }
+      }
+      else if( x == iWidth-2 )
+      {
+        if( usAbs1 <= usAbs0 )
+          *pbEdgeXPtr = false;
+      }
+      else
+      {
+        if( usAbs2 > usAbs0 )
+        {
+          if( usAbs1 < usAbs2 )
+            *pbEdgeXPtr = false;
+        }
+        else
+        {
+          if( usAbs1 <= usAbs0 )
+            *pbEdgeXPtr = false;
+        }
+      }
+
+      psDiffXPtr++;
+      pbEdgeXPtr++;
+    }
+  }
+
+  for( Int y=0; y<iHeight-1; y++ )
+  {
+    Short* psDiffYPtr = &psDiffY[ y * iWidth ];
+    Bool*  pbEdgeYPtr = &pbEdgeY[ y * iWidth ];
+    for( Int x=0; x<iWidth; x++ )
+    {
+      UShort usAbs0=0, usAbs1=0, usAbs2=0;  // 0 : upper, 1 : current, 2 : bottom
+      if( y > 0 && *(pbEdgeYPtr-iWidth) == true )
+      {
+        if( *(psDiffYPtr-iWidth) >= 0)
+        {
+          usAbs0 = *(psDiffYPtr-iWidth);
+        }
+        else
+        {
+          usAbs0 = (-1) * *(psDiffYPtr-iWidth);          
+        }
+      }
+      if( *pbEdgeYPtr == true )
+      {
+        if( *(psDiffYPtr) >= 0)
+        {
+          usAbs1 = *(psDiffYPtr);
+        }
+        else
+        {
+          usAbs1 = (-1) * *(psDiffYPtr);
+        }
+      }
+      if( y < iHeight-2 && *(pbEdgeYPtr+iWidth) == true )
+      {
+        if( *(psDiffYPtr+iWidth) >= 0)
+        {
+          usAbs2 = *(psDiffYPtr+iWidth);          
+        }
+        else
+        {
+          usAbs2 = (-1) * *(psDiffYPtr+iWidth);
+        }
+      }
+
+      if( y == 0 )
+      {
+        if( usAbs1 < usAbs2 )
+          *pbEdgeYPtr = false;
+      }
+      else if( y == iHeight-2 )
+      {
+        if( usAbs1 <= usAbs0 )
+          *pbEdgeYPtr = false;
+      }
+      else
+      {
+        if( usAbs2 > usAbs0 )
+        {
+          if( usAbs1 < usAbs2 )
+            *pbEdgeYPtr = false;
+        }
+        else
+        {
+          if( usAbs1 <= usAbs0 )
+            *pbEdgeYPtr = false;
+        }
+      }
+
+      psDiffYPtr++;
+      pbEdgeYPtr++;
+    }
+  }
+
+  // Edge Merging
+  for( Int i=0; i< 4 * iWidth * iHeight; i++ )
+    pbEdge[ i ] = false;
+  /// Even Line (0,2,4,6,...) => Vertical Edge
+  for( Int i=0; i<iHeight; i++)
+  {
+    for( Int j=0; j<iWidth-1; j++)
+    {
+      pbEdge[ (2 * j + 1) + (2 * i) * 2 * iWidth ] = pbEdgeX[ j + i * iHeight ];
+    }
+  }
+  /// Odd Line (1,3,5,7,...) => Horizontal Edge
+  for( Int i=0; i<iHeight-1; i++)
+  {
+    for( Int j=0; j<iWidth; j++)
+    {
+      pbEdge[ (2 * j) + (2 * i + 1) * 2 * iWidth ] = pbEdgeY[ j + i * iHeight ]; 
+    }
+  }
+
+  // Intersection Filling
+  /// Vertical Edge between Horizontal Edges
+  for( Int i = 1; i < 2 * iHeight - 3; i += 2)
+  {
+    for( Int j = 0; j < 2 * iWidth - 1; j += 2)
+    {
+      if( pbEdge[ j + i * 2 * iWidth ] )
+      {
+        if( j != 0 && pbEdge[ (j - 2) + ((i + 2) * 2 * iWidth) ] )
+        {
+          if( !pbEdge[ (j - 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j - 1) + ((i + 3) * 2 * iWidth) ] )
+            pbEdge[ (j - 1) + ((i + 1) * 2 * iWidth) ] = true;
+        }
+        if( j != 2 * iWidth - 2 && pbEdge[ (j + 2) + ((i + 2) * 2 * iWidth) ] )
+        {
+          if( !pbEdge[ (j + 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j + 1) + ((i + 3) * 2 * iWidth) ] )
+            pbEdge[ (j + 1) + ((i + 1) * 2 * iWidth) ] = true;
+        }
+      }
+    }
+  }
+  /// Horizontal Edge between Vertical Edges
+  for( Int j = 1; j < 2 * iWidth - 3; j += 2)
+  {
+    for( Int i = 0; i < 2 * iHeight - 1; i += 2)
+    {
+      if( pbEdge[ j + i * 2 * iWidth ] )
+      {
+        if( i != 0 && pbEdge[ (j + 2) + ((i - 2) * 2 * iWidth) ] )
+        {
+          if( !pbEdge[ (j - 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j + 3) + ((i - 1) * 2 * iWidth) ] )
+            pbEdge[ (j + 1) + ((i - 1) * 2 * iWidth) ] = true;
+        }
+        if( i != 2 * iHeight - 2 && pbEdge[ (j + 2) + ((i + 2) * 2 * iWidth) ] )
+        {
+          if( !pbEdge[ (j - 1) + ((i + 1) * 2 * iWidth) ] && !pbEdge[ (j + 3) + ((i + 1) * 2 * iWidth) ] )
+            pbEdge[ (j + 1) + ((i + 1) * 2 * iWidth) ] = true;
+        }
+      }
+    }
+  }
+
+  // Static Pruning Unnecessary Edges
+  /// Step1. Stack push the unconnected edges
+  UShort* pusUnconnectedEdgeStack = new UShort[ 4 * iWidth * iHeight ]; // approximate size calculation
+  Int iUnconnectedEdgeStackPtr = 0;
+  //// Vertical Edges
+  for( Int i = 0; i < 2 * iHeight - 1; i += 2 )
+  {
+    for( Int j = 1; j < 2 * iWidth - 2; j += 2 )
+    {
+      if( pbEdge[ j + i * 2 * iWidth ] )
+      {
+        if( !xCheckTerminatedEdge( pbEdge, j, i, iWidth, iHeight ) )
+        {
+          pusUnconnectedEdgeStack[iUnconnectedEdgeStackPtr] = (i << 8) | (j);
+          iUnconnectedEdgeStackPtr++;
+        }
+      }
+    }
+  }
+
+  //// Horizontal Edges
+  for( Int i = 1; i < 2 * iHeight - 2; i += 2 )
+  {
+    for( Int j = 0; j < 2 * iWidth - 1; j += 2 )
+    {
+      if( pbEdge[ j + i * 2 * iWidth ] )
+      {
+        if( !xCheckTerminatedEdge( pbEdge, j, i, iWidth, iHeight ) )
+        {
+          pusUnconnectedEdgeStack[iUnconnectedEdgeStackPtr] = (i << 8) | (j);
+          iUnconnectedEdgeStackPtr++;
+        }
+      }
+    }
+  }
+
+  /// Step2. Remove the edges from the stack and push the new unconnected edges
+  //// (This step may contain duplicated edges already in the stack)
+  //// (But it doesn't cause any functional problems)
+  while( iUnconnectedEdgeStackPtr != 0 )
+  {
+    iUnconnectedEdgeStackPtr--;
+    Int iX = pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] & 0xff;
+    Int iY = pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] >> 8;
+
+    pbEdge[ iX + iY * 2 * iWidth ] = false;
+
+    if( iY % 2 == 1 && iX > 0 && pbEdge[ iX - 2 + iY * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX - 2, iY, iWidth, iHeight ) ) // left
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 0) << 8) | (iX - 2);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iY % 2 == 1 && iX < 2 * iWidth - 2 && pbEdge[ iX + 2 + iY * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX + 2, iY, iWidth, iHeight ) ) // right
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 0) << 8) | (iX + 2);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iY % 2 == 0 && iY > 0 && pbEdge[ iX + (iY - 2) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX, iY - 2, iWidth, iHeight ) ) // top
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 2) << 8) | (iX + 0);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iY % 2 == 0 && iY < 2 * iHeight - 2 && pbEdge[ iX + (iY + 2) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX, iY + 2, iWidth, iHeight ) ) // bottom
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 2) << 8) | (iX + 0);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iX > 0 && iY > 0 && pbEdge[ iX - 1 + (iY - 1) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX - 1, iY - 1, iWidth, iHeight ) ) // left-top
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 1) << 8) | (iX - 1);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iX < 2 * iWidth - 1 && iY > 0 && pbEdge[ iX + 1 + (iY - 1) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX + 1, iY - 1, iWidth, iHeight ) ) // right-top
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 1) << 8) | (iX + 1);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iX > 0 && iY < 2 * iHeight - 1 && pbEdge[ iX - 1 + (iY + 1) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX - 1, iY + 1, iWidth, iHeight ) ) // left-bottom
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 1) << 8) | (iX - 1);
+      iUnconnectedEdgeStackPtr++;
+    }
+    if( iX < 2 * iWidth - 1 && iY < 2 * iHeight - 1 && pbEdge[ iX + 1 + (iY + 1) * 2 * iWidth ] &&
+      !xCheckTerminatedEdge( pbEdge, iX + 1, iY + 1, iWidth, iHeight ) ) // right-bottom
+    {
+      pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 1) << 8) | (iX + 1);
+      iUnconnectedEdgeStackPtr++;
+    }
+  }
+
+
+  // Region Generation ( edge -> region )
+  Bool* pbRegion = pcCU->getEdgePartition( uiAbsPtIdx );
+  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;
+
+  if( bBipartition )
+  {
+    return xConstructChainCode( pcCU, uiAbsPtIdx, (UInt)iWidth, (UInt)iHeight );
+  }
+  else
+  {
+    return false;
+  }
+}
+
+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;
+    }
+  }
+}
+Bool TEncSearch::xConstructChainCode( TComDataCU* pcCU, UInt uiAbsPtIdx, UInt uiWidth, UInt uiHeight )
+{
+  //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 * (RBC_MAX_EDGE_NUM_PER_4x4 / 4);
+  Bool*  pbRegion   = pcCU->getEdgePartition( uiAbsPtIdx );
+  UChar* piEdgeCode = pcCU->getEdgeCode( uiAbsPtIdx );
+  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( uiAbsPtIdx, bStartLeft );
+  pcCU->setEdgeStartPos ( uiAbsPtIdx, bStartLeft ? (iStartPosition - 1) >> 1 : (iStartPosition + 1) >> 1);
+  pcCU->setEdgeNumber   ( uiAbsPtIdx, iPtr );
+
+  xFree( pbEdge );
+  xFree( pbVisit );
+
+  return (iPtr != 0);
+}
+#endif
+#endif
 //! \}
Index: /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.h	(revision 458)
+++ /branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.h	(revision 459)
@@ -325,4 +325,25 @@
                                     UInt         stateU0V1Both2 );
 
+
+  // -------------------------------------------------------------------------------------------------------------------
+  // Depth intra search
+  // -------------------------------------------------------------------------------------------------------------------
+#if H_3D_DIM
+  Void xCalcBiSegDCs              ( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2 );
+#if H_3D_DIM_DMM
+  Void xSearchDmmDeltaDCs         ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 );
+  Void xSearchDmm1Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx );
+  Void xSearchDmm2Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, Int& riWedgeDeltaEnd );
+  Void xSearchDmm3Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx );
+#endif
+#if H_3D_DIM_RBC
+  Void xSearchRbcDeltaDCs         ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 );
+  Bool xSearchRbcEdge             ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride,  Int  iWidth,  Int  iHeight );
+  
+  Bool xCheckTerminatedEdge       ( Bool* pbEdge, Int iX, Int iY, Int iWidth, Int iHeight );
+  Bool xConstructChainCode        ( TComDataCU* pcCU, UInt uiAbsPtIdx, UInt uiWidth, UInt uiHeight );
+#endif
+#endif
+
   // -------------------------------------------------------------------------------------------------------------------
   // Inter search (AMP)
