Index: branches/HTM-14.1-update-dev1-HHI/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/App/TAppDecoder/TAppDecTop.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/App/TAppDecoder/TAppDecTop.cpp	(revision 1209)
@@ -528,5 +528,5 @@
   // initialize global variables
   initROM();  
-#if H_3D_DIM_DMM
+#if NH_3D_DMM
   initWedgeLists();
 #endif
Index: branches/HTM-14.1-update-dev1-HHI/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1209)
@@ -1773,5 +1773,5 @@
   // allocate slice-based dQP values
 #if NH_MV
-  for (Int i = m_layerIdInNuh.size(); i < m_numberOfLayers; i++ )
+  for (Int i = (Int)m_layerIdInNuh.size(); i < m_numberOfLayers; i++ )
   {
     m_layerIdInNuh.push_back( i == 0 ? 0 : m_layerIdInNuh[ i - 1 ] + 1 ); 
Index: branches/HTM-14.1-update-dev1-HHI/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1209)
@@ -811,5 +811,5 @@
   // initialize global variables
   initROM();
-#if H_3D_DIM_DMM
+#if NH_3D_DMM
   initWedgeLists( true );
 #endif
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/ContextTables.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/ContextTables.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/ContextTables.h	(revision 1209)
@@ -173,18 +173,16 @@
 #define CNU                          154      ///< dummy initialization value for unused context models 'Context model Not Used'
 
-#if H_3D_DIM
-#define NUM_DEPTH_INTRA_MODE_CTX      1       ///< 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              1       ///< 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
-#endif
-#define NUM_ANGLE_FLAG_CTX            1
-#endif
-
+#if NH_3D_DMM
+#define NUM_NOTDMM_FLAG_CTX           1       ///< number of context models for not-DMM flag
+#define NUM_DMM_MODE_CTX              1       ///< number of context models for DMM modes
+#endif
+#if NH_3D_DMM || NH_3D_SDC
+#define NUM_DDC_DATA_CTX              1       ///< number of context models for deltaDC data (DMM or SDC)
+#endif
 #if H_3D_DIM_SDC
 #define SDC_NUM_RESIDUAL_FLAG_CTX     1
 #define SDC_NUM_RESIDUAL_CTX          1
 #define NUM_SDC_FLAG_CTX              1      ///< number of context 
+#define NUM_DDC_FLAG_CTX              2       ///< number of context models for deltaDC flag (SDC only)
 #endif
 #if H_3D_DBBP
@@ -562,15 +560,8 @@
 
 #endif
-#if H_3D_DIM
-static const UChar
-INIT_DEPTH_INTRA_MODE[3][NUM_DEPTH_INTRA_MODE_CTX] =
-{
-  { 154, },
-  { 154, },
-  { 154, }
-};
-
+
+#if NH_3D_DMM
 static const UChar 
-INIT_ANGLE_FLAG[3][NUM_ANGLE_FLAG_CTX] =
+INIT_NOTDMM_FLAG[3][NUM_NOTDMM_FLAG_CTX] =
 {
   { 154 },
@@ -578,5 +569,43 @@
   { 155 },
 };
-
+static const UChar 
+INIT_DMM_MODE[3][NUM_DMM_MODE_CTX] =
+{
+  { CNU },
+  { CNU },
+  { CNU }
+};
+#endif
+#if NH_3D_DMM || NH_3D_SDC
+static const UChar
+INIT_DDC_DATA[3][NUM_DDC_DATA_CTX] = 
+{
+  { CNU }, 
+  { CNU }, 
+  { CNU }, 
+};
+#endif
+#if H_3D_DIM_SDC
+static const UChar
+INIT_SDC_RESIDUAL_FLAG[3][SDC_NUM_RESIDUAL_FLAG_CTX] =
+{
+  { CNU },
+  { CNU },
+  { CNU },
+};
+static const UChar
+INIT_SDC_RESIDUAL[3][SDC_NUM_RESIDUAL_CTX] =
+{
+  { 155 },
+  { 155 },
+  { 155 },
+};
+static const UChar 
+INIT_SDC_FLAG[3][NUM_SDC_FLAG_CTX] =
+{
+  { 154 },  
+  { 154 },
+  { 154 },
+};
 static const UChar 
 INIT_DDC_FLAG[3][NUM_DDC_FLAG_CTX] =
@@ -586,47 +615,5 @@
   {64, CNU}
 };
-static const UChar
-INIT_DDC_DATA[3][NUM_DDC_DATA_CTX] = 
-{
-  { 154 }, 
-  { 154 }, 
-  { 154 }, 
-};
-#if H_3D_DIM_DMM
-static const UChar
-INIT_DMM1_DATA[3][NUM_DMM1_DATA_CTX] = 
-{
-  { CNU }, 
-  { CNU }, 
-  { CNU }, 
-};
-#endif
-#if H_3D_DIM_SDC
-static const UChar
-INIT_SDC_RESIDUAL_FLAG[3][SDC_NUM_RESIDUAL_FLAG_CTX] =
-{
-  { CNU },
-  { CNU },
-  { CNU },
-};
-static const UChar
-INIT_SDC_RESIDUAL[3][SDC_NUM_RESIDUAL_CTX] =
-{
-  { 155 },
-  { 155 },
-  { 155 },
-};
-#endif
-#endif
-#if H_3D_DIM_SDC
-static const UChar 
-INIT_SDC_FLAG[3][NUM_SDC_FLAG_CTX] =
-{
-  { 154 },  
-  { 154 },
-  { 154 },
-};
-#endif
-
+#endif
 #if H_3D_DBBP
 static const UChar INIT_DBBP_FLAG[3][DBBP_NUM_FLAG_CTX] =
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComCodingStatistics.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComCodingStatistics.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComCodingStatistics.h	(revision 1209)
@@ -92,4 +92,16 @@
   STATS__CABAC_BITS__ALIGNED_SIGN_BIT,
   STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS,
+
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+  STATS__CABAC_BITS__DELTADC_SIGN_EP,
+  STATS__CABAC_BITS__DELTADC_PREFIX,
+  STATS__CABAC_BITS__DELTADC_SUFFIX_EP,
+#endif
+#if NH_3D_DMM
+  STATS__CABAC_BITS__NOTDMM_FLAG,
+  STATS__CABAC_BITS__DMMMODE,
+  STATS__CABAC_BITS__DMM1_BITS_EP,
+#endif
+
   STATS__NUM_STATS
 };
@@ -142,4 +154,14 @@
     "CABAC_BITS__ALIGNED_SIGN_BIT",
     "CABAC_BITS__ALIGNED_ESCAPE_BITS"
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+   ,"STATS__CABAC_BITS__DELTADC_SIGN_EP"
+   ,"STATS__CABAC_BITS__DELTADC_PREFIX"
+   ,"STATS__CABAC_BITS__DELTADC_SUFFIX_EP"
+#endif
+#if NH_3D_DMM
+   ,"STATS__CABAC_BITS__NOTDMM_FLAG"
+   ,"STATS__CABAC_BITS__DMMMODE"
+   ,"STATS__CABAC_BITS__DMM1_BITS_EP"
+#endif
   };
   assert(STATS__NUM_STATS == sizeof(statNames)/sizeof(Char *) && name < STATS__NUM_STATS);
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComDataCU.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComDataCU.cpp	(revision 1209)
@@ -104,15 +104,11 @@
   }
 
-#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;
-  }
+#if NH_3D_DMM
+  for( Int i = 0; i < NUM_DMM; i++ )
+  {
+    m_dmmDeltaDC[i][0] = NULL; 
+    m_dmmDeltaDC[i][1] = NULL;
+  }
+  m_dmm1WedgeTabIdx = NULL;
 #endif
 #if H_3D_DIM_SDC
@@ -120,5 +116,4 @@
   m_apSegmentDCOffset[0]  = NULL;
   m_apSegmentDCOffset[1]  = NULL;
-#endif
 #endif
 
@@ -255,15 +250,11 @@
     m_pbICFlag           = (Bool* )xMalloc(Bool,   uiNumPartition);
 #endif
-#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);
-    }
+#if NH_3D_DMM
+    for( Int i = 0; i < NUM_DMM; i++ )
+    {
+      m_dmmDeltaDC[i][0] = (Pel* )xMalloc(Pel, uiNumPartition); 
+      m_dmmDeltaDC[i][1] = (Pel* )xMalloc(Pel, uiNumPartition);
+    }
+    m_dmm1WedgeTabIdx    = (UInt*)xMalloc(UInt, uiNumPartition);
 #endif
 #if H_3D_DIM_SDC
@@ -271,5 +262,4 @@
     m_apSegmentDCOffset[0]  = (Pel*)xMalloc(Pel, uiNumPartition);
     m_apSegmentDCOffset[1]  = (Pel*)xMalloc(Pel, uiNumPartition);
-#endif
 #endif
 #if H_3D_DBBP
@@ -475,15 +465,11 @@
 #endif
 
-#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 NH_3D_DMM
+    for( Int i = 0; i < NUM_DMM; i++ )
+    {
+      if ( m_dmmDeltaDC[i][0] ) { xFree( m_dmmDeltaDC[i][0] ); m_dmmDeltaDC[i][0] = NULL; }
+      if ( m_dmmDeltaDC[i][1] ) { xFree( m_dmmDeltaDC[i][1] ); m_dmmDeltaDC[i][1] = NULL; }
+    }
+    if ( m_dmm1WedgeTabIdx    ) { xFree( m_dmm1WedgeTabIdx );  m_dmm1WedgeTabIdx = NULL;  }
 #endif
 #if H_3D_DIM_SDC
@@ -491,5 +477,4 @@
     if ( m_apSegmentDCOffset[0] ) { xFree(m_apSegmentDCOffset[0]);  m_apSegmentDCOffset[0]  = NULL; }
     if ( m_apSegmentDCOffset[1] ) { xFree(m_apSegmentDCOffset[1]);  m_apSegmentDCOffset[1]  = NULL; }
-#endif    
 #endif    
 #if H_3D_DBBP
@@ -659,15 +644,12 @@
 
 
-#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] ) );
-    }
+
+#if NH_3D_DMM
+  for( Int i = 0; i < NUM_DMM; i++ )
+  {
+    memset( m_dmmDeltaDC[i][0], 0,                        m_uiNumPartition * sizeof( *m_dmmDeltaDC[i][0] ) );
+    memset( m_dmmDeltaDC[i][1], 0,                        m_uiNumPartition * sizeof( *m_dmmDeltaDC[i][1] ) );
+  }
+  memset( m_dmm1WedgeTabIdx,    0,                        m_uiNumPartition * sizeof( *m_dmm1WedgeTabIdx   ) );
 #endif
 #if H_3D_DIM_SDC
@@ -675,7 +657,8 @@
     memset( m_apSegmentDCOffset[0]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[0] ) );
     memset( m_apSegmentDCOffset[1]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[1] ) );
-#endif
+#if !TEMP_SDC_CLEANUP // PM: should be obsolete after cleanup
     m_apDmmPredictor[0] = 0;
     m_apDmmPredictor[1] = 0;
+#endif
 #endif
 #if H_3D_DBBP
@@ -820,15 +803,11 @@
 
 
-#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;
-      }
+#if NH_3D_DMM
+    for( Int i = 0; i < NUM_DMM; i++ )
+    {
+      m_dmmDeltaDC[i][0] [ui] = 0;
+      m_dmmDeltaDC[i][1] [ui] = 0;
+    }
+    m_dmm1WedgeTabIdx    [ui] = 0;
 #endif
 #if H_3D_DIM_SDC
@@ -836,7 +815,8 @@
       m_apSegmentDCOffset[0][ui] = 0;
       m_apSegmentDCOffset[1][ui] = 0;
-#endif
+#if !TEMP_SDC_CLEANUP // PM: should be obsolete after cleanup
       m_apDmmPredictor[0] = 0;
       m_apDmmPredictor[1] = 0;
+#endif
 #endif
 #if H_3D_DBBP
@@ -929,15 +909,11 @@
   memset( m_pbICFlag,          0, iSizeInBool  );
 #endif
-#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 );
-  }
+#if NH_3D_DMM
+  for( Int i = 0; i < NUM_DMM; i++ )
+  {
+    memset( m_dmmDeltaDC[i][0], 0, sizeof(Pel ) * m_uiNumPartition );
+    memset( m_dmmDeltaDC[i][1], 0, sizeof(Pel ) * m_uiNumPartition );
+  }
+  memset( m_dmm1WedgeTabIdx,    0, sizeof(UInt) * m_uiNumPartition );
 #endif
 #if H_3D_DIM_SDC
@@ -945,7 +921,8 @@
   memset( m_apSegmentDCOffset[0], 0, sizeof(Pel) * m_uiNumPartition   );
   memset( m_apSegmentDCOffset[1], 0, sizeof(Pel) * m_uiNumPartition   );
-#endif
+#if !TEMP_SDC_CLEANUP // PM: should be obsolete after cleanup
   m_apDmmPredictor[0] = 0;
   m_apDmmPredictor[1] = 0;
+#endif
 #endif
 #if H_3D_DBBP
@@ -989,15 +966,11 @@
       m_pbICFlag          [ui] = pcCU->m_pbICFlag[uiPartOffset+ui];
 #endif
-#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];
-      }
+#if NH_3D_DMM
+  for( Int i = 0; i < NUM_DMM; i++ )
+  {
+    m_dmmDeltaDC[i][0] [ui] = pcCU->m_dmmDeltaDC[i][0] [uiPartOffset+ui];
+    m_dmmDeltaDC[i][1] [ui] = pcCU->m_dmmDeltaDC[i][1] [uiPartOffset+ui];
+  }
+  m_dmm1WedgeTabIdx    [ui] = pcCU->m_dmm1WedgeTabIdx  [uiPartOffset+ui];
 #endif
 #if H_3D_DIM_SDC
@@ -1005,5 +978,4 @@
       m_apSegmentDCOffset[0][ui] = pcCU->m_apSegmentDCOffset[0] [ uiPartOffset + ui ];
       m_apSegmentDCOffset[1][ui] = pcCU->m_apSegmentDCOffset[1] [ uiPartOffset + ui ];
-#endif
 #endif
 #if H_3D_DBBP
@@ -1112,15 +1084,11 @@
     m_explicitRdpcmMode[comp]             = pcCU->getExplicitRdpcmMode(ComponentID(comp))             + 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;
-  }
+#if NH_3D_DMM
+  for( Int i = 0; i < NUM_DMM; i++ )
+  {
+    m_dmmDeltaDC[i][0] = pcCU->getDmmDeltaDC( (DmmID)i, 0 ) + uiPart;
+    m_dmmDeltaDC[i][1] = pcCU->getDmmDeltaDC( (DmmID)i, 1 ) + uiPart;
+  }
+  m_dmm1WedgeTabIdx    = pcCU->getDmm1WedgeTabIdx()  + uiPart;
 #endif
 #if H_3D_DIM_SDC
@@ -1128,5 +1096,4 @@
   m_apSegmentDCOffset[0]    = pcCU->getSDCSegmentDCOffset(0)  + uiPart;
   m_apSegmentDCOffset[1]    = pcCU->getSDCSegmentDCOffset(1)  + uiPart;
-#endif  
 #endif  
 #if H_3D_DBBP
@@ -1319,15 +1286,11 @@
     memcpy( m_explicitRdpcmMode[comp]             + uiOffset, pcCU->getExplicitRdpcmMode(ComponentID(comp))            , 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 );
-  }
+#if NH_3D_DMM
+  for( Int i = 0; i < NUM_DMM; i++ )
+  {
+    memcpy( m_dmmDeltaDC[i][0] + uiOffset, pcCU->getDmmDeltaDC( (DmmID)i, 0 ), sizeof(Pel ) * uiNumPartition );
+    memcpy( m_dmmDeltaDC[i][1] + uiOffset, pcCU->getDmmDeltaDC( (DmmID)i, 1 ), sizeof(Pel ) * uiNumPartition );
+  }
+  memcpy( m_dmm1WedgeTabIdx    + uiOffset, pcCU->getDmm1WedgeTabIdx(),         sizeof(UInt) * uiNumPartition );
 #endif
 #if H_3D_DIM_SDC
@@ -1335,5 +1298,4 @@
   memcpy( m_apSegmentDCOffset[0]  + uiOffset, pcCU->getSDCSegmentDCOffset(0), sizeof( Pel ) * uiNumPartition);
   memcpy( m_apSegmentDCOffset[1]  + uiOffset, pcCU->getSDCSegmentDCOffset(1), sizeof( Pel ) * uiNumPartition);
-#endif
 #endif
 #if H_3D_DBBP
@@ -1447,15 +1409,11 @@
   }
 
-#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 );
-  }
+#if NH_3D_DMM
+  for( Int i = 0; i < NUM_DMM; i++ )
+  {
+    memcpy( pCtu->getDmmDeltaDC( (DmmID)i, 0 ) + m_absZIdxInCtu, m_dmmDeltaDC[i][0], sizeof(Pel ) * m_uiNumPartition );
+    memcpy( pCtu->getDmmDeltaDC( (DmmID)i, 1 ) + m_absZIdxInCtu, m_dmmDeltaDC[i][1], sizeof(Pel ) * m_uiNumPartition );
+  }
+  memcpy( pCtu->getDmm1WedgeTabIdx()           + m_absZIdxInCtu, m_dmm1WedgeTabIdx,  sizeof(UInt) * m_uiNumPartition );
 #endif
 #if H_3D_DIM_SDC
@@ -1463,5 +1421,4 @@
   memcpy( rpcCU->getSDCSegmentDCOffset(0) + m_uiAbsIdxInLCU, m_apSegmentDCOffset[0], sizeof( Pel ) * m_uiNumPartition);
   memcpy( rpcCU->getSDCSegmentDCOffset(1) + m_uiAbsIdxInLCU, m_apSegmentDCOffset[1], sizeof( Pel ) * m_uiNumPartition);
-#endif
 #endif
 #if H_3D_DBBP
@@ -1522,21 +1479,8 @@
   memcpy( rpcCU->getSPIVMPFlag()        + uiPartOffset, m_pbSPIVMPFlag,        sizeof(Bool) * uiQNumPart );
 #endif
-#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 );
-  }
-#endif
 #if H_3D_DIM_SDC
   memcpy( rpcCU->getSDCFlag()             + uiPartOffset, m_pbSDCFlag,      iSizeInBool  );
   memcpy( rpcCU->getSDCSegmentDCOffset(0) + uiPartOffset, m_apSegmentDCOffset[0], sizeof( Pel ) * uiQNumPart);
   memcpy( rpcCU->getSDCSegmentDCOffset(1) + uiPartOffset, m_apSegmentDCOffset[1], sizeof( Pel ) * uiQNumPart);
-#endif
 #endif
 #if H_3D_DBBP
@@ -1952,6 +1896,6 @@
   }
   iLeftIntraDir  = pcCULeft ? ( pcCULeft->isIntra( LeftPartIdx ) ? pcCULeft->getIntraDir( chType, LeftPartIdx ) : DC_IDX ) : DC_IDX;
-#if H_3D_DIM
-  mapDepthModeToIntraDir( iLeftIntraDir );
+#if NH_3D_DMM
+  mapDmmToIntraDir( iLeftIntraDir );
 #endif
 
@@ -1964,6 +1908,6 @@
   }
   iAboveIntraDir = pcCUAbove ? ( pcCUAbove->isIntra( AbovePartIdx ) ? pcCUAbove->getIntraDir( chType, AbovePartIdx ) : DC_IDX ) : DC_IDX;
-#if H_3D_DIM
-  mapDepthModeToIntraDir( iAboveIntraDir );
+#if NH_3D_DMM
+  mapDmmToIntraDir( iAboveIntraDir );
 #endif
 
@@ -2460,4 +2404,15 @@
 Bool TComDataCU::getSDCAvailable( UInt uiAbsPartIdx )
 {
+#if TEMP_SDC_CLEANUP // PM: consider this cleanup for DMM and SDC
+  if( getSlice()->getIsDepth() && isIntra(uiAbsPartIdx) && getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N )
+  {
+    UInt lumaPredMode = getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx );
+    if( lumaPredMode < NUM_INTRA_MODE ) { return true; }
+#if NH_3D_DMM
+    if( isDmmMode( lumaPredMode )     ) { return true; }
+#endif
+  }
+  return false;
+#else
   // check general CU information
   if( !getSlice()->getIsDepth() || !isIntra(uiAbsPartIdx) || getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
@@ -2466,5 +2421,5 @@
   }
 
-  if( isDimMode( getLumaIntraDir( uiAbsPartIdx ) ) )
+  if( isDmmMode( getLumaIntraDir( uiAbsPartIdx ) ) )
   {
     return true;
@@ -2479,9 +2434,10 @@
   // check prediction mode
   UInt uiLumaPredMode = getLumaIntraDir( uiAbsPartIdx );  
-  if( uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX  ) )
+  if( uiLumaPredMode == PLANAR_IDX || ( getDmmType( uiLumaPredMode ) == DMM1_IDX  ) )
     return true;
   
   // else
   return false;
+#endif
 }
 #endif
@@ -5637,7 +5593,6 @@
 
   UInt uiDirMode  = getIntraDir(toChannelType(compID), uiAbsPartIdx);
-
-#if H_3D_DIM
-    mapDepthModeToIntraDir( uiDirMode );
+#if NH_3D_DMM
+  mapDmmToIntraDir( uiDirMode );
 #endif
 
@@ -5647,6 +5602,6 @@
     const UInt partsPerMinCU = 1<<(2*(sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize()));
     uiDirMode = getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, getPic()->getChromaFormat(), partsPerMinCU));
-#if H_3D_DIM
-      mapDepthModeToIntraDir( uiDirMode );
+#if NH_3D_DMM
+    mapDmmToIntraDir( uiDirMode );
 #endif
   }
@@ -6732,12 +6687,9 @@
 }
 #endif
-#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; 
-  }
+#if NH_3D_DMM
+Void TComDataCU::setDmm1WedgeTabIdxSubParts( UInt tabIdx, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
+  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm1WedgeTabIdx[uiAbsPartIdx+ui] = tabIdx; }
 }
 #endif
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComDataCU.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComDataCU.h	(revision 1209)
@@ -182,12 +182,12 @@
   Bool*         m_pbICFlag;           ///< array of IC flags
 #endif
-#if H_3D_DIM
-  Pel*          m_dimDeltaDC[DIM_NUM_TYPE][2];
-#if H_3D_DIM_DMM
-  UInt*         m_dmmWedgeTabIdx[DMM_NUM_TYPE]; 
+#if NH_3D_DMM
+  Pel*          m_dmmDeltaDC[NUM_DMM][2];
+  UInt*         m_dmm1WedgeTabIdx;
 #endif
 #if H_3D_DIM_SDC
   Bool*         m_pbSDCFlag;
   Pel*          m_apSegmentDCOffset[2];
+#if !TEMP_SDC_CLEANUP // PM: should be obsolete after cleanup
   Pel           m_apDmmPredictor[2];
 #endif
@@ -553,14 +553,13 @@
   Bool          isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth);
 
-#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 );
-
+#if NH_3D_DMM
+  Pel*  getDmmDeltaDC                 ( DmmID dmmType, UInt segId )                      { return m_dmmDeltaDC[dmmType][segId];        } 
+  Pel   getDmmDeltaDC                 ( DmmID dmmType, UInt segId, UInt uiIdx )          { return m_dmmDeltaDC[dmmType][segId][uiIdx]; } 
+  Void  setDmmDeltaDC                 ( DmmID dmmType, UInt segId, UInt uiIdx, Pel val ) { m_dmmDeltaDC[dmmType][segId][uiIdx] = val;  }
+
+  UInt* getDmm1WedgeTabIdx            ()                                                { return m_dmm1WedgeTabIdx;          }        
+  UInt  getDmm1WedgeTabIdx            ( UInt uiIdx )                                    { return m_dmm1WedgeTabIdx[uiIdx];   }
+  Void  setDmm1WedgeTabIdx            ( UInt uiIdx, UInt tabIdx )                       { m_dmm1WedgeTabIdx[uiIdx] = tabIdx; }
+  Void  setDmm1WedgeTabIdxSubParts    ( UInt tabIdx, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
 #if H_3D_DIM_SDC
@@ -574,8 +573,9 @@
   Pel           getSDCSegmentDCOffset( UInt uiSeg, UInt uiPartIdx ) { return m_apSegmentDCOffset[uiSeg][uiPartIdx]; }
   Void          setSDCSegmentDCOffset( Pel pOffset, UInt uiSeg, UInt uiPartIdx) { m_apSegmentDCOffset[uiSeg][uiPartIdx] = pOffset; }
+#if !TEMP_SDC_CLEANUP // PM: should be obsolete after cleanup
   Void          setDmmPredictor ( Pel pOffset, UInt uiSeg) { m_apDmmPredictor[uiSeg] = pOffset; }
   Pel           getDmmPredictor ( UInt uiSeg) { return m_apDmmPredictor[uiSeg]; }
+#endif
   UInt          getCtxSDCFlag          ( UInt   uiAbsPartIdx );
-#endif
 #endif
   
@@ -747,9 +747,10 @@
   UInt          getCoefScanIdx(const UInt uiAbsPartIdx, const UInt uiWidth, const UInt uiHeight, const ComponentID compID) const ;
 
-#if H_3D_DIM
+#if !TEMP_SDC_CLEANUP // PM: should be obsolete after cleanup
+#if NH_3D_DMM
   Bool         isDMM1UpscaleMode       ( UInt uiWidth ){ Bool bDMM1UpsampleModeFlag = true; UInt uiBaseWidth = 16; if( uiBaseWidth >= uiWidth ){ bDMM1UpsampleModeFlag = false; } return bDMM1UpsampleModeFlag; };
   UInt         getDMM1BasePatternWidth ( UInt uiWidth ){ UInt uiBaseWidth = 16; if( uiBaseWidth >= uiWidth ){ uiBaseWidth =  uiWidth; } return uiBaseWidth; }
 #endif
-
+#endif
 };
 
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComPrediction.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComPrediction.cpp	(revision 1209)
@@ -530,108 +530,49 @@
 }
 
-#if H_3D_DIM
-Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc, TComWedgelet* dmm4Segmentation  )
+#if NH_3D_DMM
+Void TComPrediction::predIntraLumaDmm( TComDataCU* pcCU, UInt uiAbsPartIdx, DmmID dmmType, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight )
 {
   assert( iWidth == iHeight  );
-  assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
-  assert( isDimMode( uiIntraMode ) );
-
-  UInt dimType    = getDimType  ( uiIntraMode );
-  Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
-
-  Bool* biSegPattern  = NULL;
-  UInt  patternStride = 0;
-
-  // get partiton
-#if H_3D_DIM_DMM
-  TComWedgelet* dmmSegmentation = NULL;
-  if( isDmmMode )
-  {
-    switch( dimType )
-    {
-    case( DMM1_IDX ): 
-      {
-        dmmSegmentation = pcCU->isDMM1UpscaleMode((UInt)iWidth) ? 
-            &(g_dmmWedgeLists[ g_aucConvertToBit[pcCU->getDMM1BasePatternWidth((UInt)iWidth)] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]) : 
-            &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
-      } break;
-    case( DMM4_IDX ): 
-      {
-        if( dmm4Segmentation == NULL )
-        { 
-          dmmSegmentation = new TComWedgelet( iWidth, iHeight );
-          xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
-        }
-        else
-        {
-          xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmm4Segmentation );
-          dmmSegmentation = dmm4Segmentation;
-        }
-      } break;
-    default: assert(0);
-    }
-    assert( dmmSegmentation );
-    if( dimType == DMM1_IDX && pcCU->isDMM1UpscaleMode((UInt)iWidth) ) 
-    {
-        biSegPattern = dmmSegmentation->getScaledPattern((UInt)iWidth);
-        patternStride = iWidth;
-    } 
-    else 
-    { 
-        biSegPattern  = dmmSegmentation->getPattern();
-        patternStride = dmmSegmentation->getStride ();
-    }
-  }
-#endif
+  assert( iWidth >= DMM_MIN_SIZE && iWidth <= DMM_MAX_SIZE );
+#if H_3D_DIM_SDC
+  assert( !pcCU->getSDCFlag( uiAbsPartIdx ) );
+#endif
+
+  // get partition
+  Bool* biSegPattern  = new Bool[ (UInt)(iWidth*iHeight) ];
+  UInt  patternStride = (UInt)iWidth;
+  switch( dmmType )
+  {
+  case( DMM1_IDX ): { (getWedgeListScaled( (UInt)iWidth )->at( pcCU->getDmm1WedgeTabIdx( uiAbsPartIdx ) )).getPatternScaledCopy( (UInt)iWidth, biSegPattern ); } break;
+  case( DMM4_IDX ): { predContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, biSegPattern );                                                                 } break;
+  default: assert(0);
+  }
 
   // get predicted partition values
-  assert( biSegPattern );
-  Int* piMask = NULL;
-  piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering
-  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 );
+  Pel predDC1 = 0, predDC2 = 0;
+  predBiSegDCs( pcCU, uiAbsPartIdx, iWidth, iHeight, biSegPattern, patternStride, predDC1, predDC2 );
 
   // set segment values with deltaDC offsets
-  Pel segDC1 = 0;
-  Pel segDC2 = 0;
-  if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
-  {
-    Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx );
-    Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx );
-#if H_3D_DIM_DMM
-    if( isDmmMode )
-    {
+  Pel segDC1 = 0, segDC2 = 0;
+  Pel deltaDC1 = pcCU->getDmmDeltaDC( dmmType, 0, uiAbsPartIdx );
+  Pel deltaDC2 = pcCU->getDmmDeltaDC( dmmType, 1, uiAbsPartIdx );
 #if H_3D_DIM_DLT
-      segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
-      segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
+  segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
+  segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
 #else
-      segDC1 = ClipY( predDC1 + deltaDC1 );
-      segDC2 = ClipY( predDC2 + deltaDC2 );
-#endif
-    }
-#endif
-  }
-  else
-  {
-    segDC1 = predDC1;
-    segDC2 = predDC2;
-  }
+  segDC1 = ClipBD( predDC1 + deltaDC1, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) );
+  segDC2 = ClipBD( predDC2 + deltaDC2, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) );
+#endif
 
   // set prediction signal
   Pel* pDst = piPred;
-  xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
+  assignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
+#if !TEMP_SDC_CLEANUP // PM: should be obsolete after cleanup
+#if H_3D_DIM_SDC  
   pcCU->setDmmPredictor(segDC1, 0);
   pcCU->setDmmPredictor(segDC2, 1);
-
-#if H_3D_DIM_DMM
-  if( dimType == DMM4_IDX && dmm4Segmentation == NULL )
-  { 
-    dmmSegmentation->destroy(); 
-    delete dmmSegmentation; 
-  }
-#endif
+#endif
+#endif
+  delete[] biSegPattern;
 }
 #endif
@@ -2447,7 +2388,131 @@
 #endif
 
-#if H_3D_DIM
-Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
-{
+#if TEMP_SDC_CLEANUP // PM: consider this cleanup for SDC
+#if NH_3D_SDC
+Void TComPrediction::predConstantSDC( Pel* ptrSrc, UInt srcStride, UInt uiSize, Pel& predDC )
+{
+  Pel* pLeftTop     =  ptrSrc;
+  Pel* pRightTop    =  ptrSrc                          + (uiSize-1);
+  Pel* pLeftBottom  = (ptrSrc+ (srcStride*(uiSize-1))              );
+  Pel* pRightBottom = (ptrSrc+ (srcStride*(uiSize-1))  + (uiSize-1));
+  predDC = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
+}
+#endif
+#else // PM: should be obsolete after cleanup
+#if H_3D_DIM_SDC
+Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
+                                         ,UInt uiIntraMode
+                                         ,Bool orgDC
+                                        )
+{
+  Int iSumDepth[2];
+  memset(iSumDepth, 0, sizeof(Int)*2);
+  Int iSumPix[2];
+  memset(iSumPix, 0, sizeof(Int)*2);
+
+  for( Int i = 0; i < uiNumSegments; i++ )
+  {
+    rpSegMeans[i] = 0;  
+  }
+
+  if ( !orgDC )
+  {
+    Pel* pLeftTop = pOrig;
+    Pel* pRightTop = pOrig + (uiSize-1);
+    Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
+    Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
+
+    rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
+    return;
+  }
+
+  Int subSamplePix;
+  if ( uiSize == 64 || uiSize == 32 )
+  {
+    subSamplePix = 2;
+  }
+  else
+  {
+    subSamplePix = 1;
+  }
+
+  for (Int y=0; y<uiSize; y+=subSamplePix)
+  {
+    for (Int x=0; x<uiSize; x+=subSamplePix)
+    {
+      UChar ucSegment = pMask?(UChar)pMask[x]:0;
+      assert( ucSegment < uiNumSegments );
+      
+      iSumDepth[ucSegment] += pOrig[x];
+      iSumPix[ucSegment]   += 1;
+    }
+    
+    pOrig  += uiStride*subSamplePix;
+    pMask  += uiMaskStride*subSamplePix;
+  }
+  
+  // compute mean for each segment
+  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
+  {
+    if( iSumPix[ucSeg] > 0 )
+    {
+      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
+    }
+    else
+    {
+      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
+    }
+  }
+}
+#endif // H_3D_DIM_SDC
+#endif
+
+#if NH_3D_DMM
+Void TComPrediction::predContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* segPattern )
+{
+  // get copy of co-located texture luma block
+  TComYuv cTempYuv;
+  cTempYuv.create( uiWidth, uiHeight, CHROMA_400 ); 
+  cTempYuv.clear();
+  Pel* piRefBlkY = cTempYuv.getAddr( COMPONENT_Y );
+  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
+  assert( pcPicYuvRef != NULL );
+  Int  iRefStride = pcPicYuvRef->getStride( COMPONENT_Y );
+  Pel* piRefY     = pcPicYuvRef->getAddr  ( COMPONENT_Y, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
+
+  for( Int y = 0; y < uiHeight; y++ )
+  {
+    ::memcpy(piRefBlkY, piRefY, sizeof(Pel)*uiWidth);
+    piRefBlkY += uiWidth;
+    piRefY += iRefStride;
+  }
+
+
+  // find contour for texture luma block
+  piRefBlkY = cTempYuv.getAddr( COMPONENT_Y );
+  UInt iDC = 0;
+  iDC  = piRefBlkY[ 0 ];
+  iDC += piRefBlkY[ uiWidth - 1 ];
+  iDC += piRefBlkY[ uiWidth * (uiHeight - 1) ];
+  iDC += piRefBlkY[ uiWidth * (uiHeight - 1) + uiWidth - 1 ];
+  iDC = iDC >> 2;
+
+  piRefBlkY = cTempYuv.getAddr( COMPONENT_Y );
+  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
+  { 
+    segPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
+  }
+
+  cTempYuv.destroy();
+}
+
+Void TComPrediction::predBiSegDCs( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
+{
+  assert( biSegPattern );
+  const Pel *piMask = getPredictorPtr( COMPONENT_Y, false );
+  assert( piMask );
+  Int srcStride = 2*uiWidth + 1;
+  const Pel *ptrSrc = piMask+srcStride+1;
+
   Int  refDC1, refDC2;
   const Int  iTR = (   patternStride - 1        ) - srcStride;
@@ -2476,18 +2541,13 @@
 }
 
-Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
-{
+Void TComPrediction::assignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
+{
+  assert( biSegPattern );
   if( dstStride == patternStride )
   {
     for( UInt k = 0; k < (patternStride * patternStride); k++ )
     {
-      if( true == biSegPattern[k] )
-      { 
-        ptrDst[k] = valDC2; 
-      }
-      else                          
-      { 
-        ptrDst[k] = valDC1; 
-      }
+      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
+      else                          { ptrDst[k] = valDC1; }
     }
   }
@@ -2499,12 +2559,6 @@
       for( UInt uiX = 0; uiX < patternStride; uiX++ )
       {
-        if( true == biSegPattern[uiX] ) 
-        { 
-          piTemp[uiX] = valDC2; 
-        }
-        else                            
-        { 
-          piTemp[uiX] = valDC1; 
-        }
+        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
+        else                            { piTemp[uiX] = valDC1; }
       }
       piTemp       += dstStride;
@@ -2513,124 +2567,4 @@
   }
 }
-
-#if H_3D_DIM_DMM
-
-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;
-
-  iDC  = piRefBlkY[ 0 ];
-  iDC += piRefBlkY[ uiWidth - 1 ];
-  iDC += piRefBlkY[ uiWidth * (uiHeight - 1) ];
-  iDC += piRefBlkY[ uiWidth * (uiHeight - 1) + uiWidth - 1 ];
-  iDC = iDC >> 2;
-
-  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()->getTexturePic()->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;
-  }
-}
-#endif
-
-
-#if H_3D_DIM_SDC
-Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
-                                         ,UInt uiIntraMode
-                                         ,Bool orgDC
-                                        )
-{
-  Int iSumDepth[2];
-  memset(iSumDepth, 0, sizeof(Int)*2);
-  Int iSumPix[2];
-  memset(iSumPix, 0, sizeof(Int)*2);
-
-  for( Int i = 0; i < uiNumSegments; i++ )
-  {
-    rpSegMeans[i] = 0;  
-  }
-
-  if ( !orgDC )
-  {
-    Pel* pLeftTop = pOrig;
-    Pel* pRightTop = pOrig + (uiSize-1);
-    Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
-    Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
-
-    rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
-    return;
-  }
-
-  Int subSamplePix;
-  if ( uiSize == 64 || uiSize == 32 )
-  {
-    subSamplePix = 2;
-  }
-  else
-  {
-    subSamplePix = 1;
-  }
-
-  for (Int y=0; y<uiSize; y+=subSamplePix)
-  {
-    for (Int x=0; x<uiSize; x+=subSamplePix)
-    {
-      UChar ucSegment = pMask?(UChar)pMask[x]:0;
-      assert( ucSegment < uiNumSegments );
-      
-      iSumDepth[ucSegment] += pOrig[x];
-      iSumPix[ucSegment]   += 1;
-    }
-    
-    pOrig  += uiStride*subSamplePix;
-    pMask  += uiMaskStride*subSamplePix;
-  }
-  
-  // compute mean for each segment
-  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
-  {
-    if( iSumPix[ucSeg] > 0 )
-    {
-      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
-    }
-    else
-    {
-      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
-    }
-  }
-}
-#endif // H_3D_DIM_SDC
-#endif
-
+#endif
 //! \}
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComPrediction.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComPrediction.h	(revision 1209)
@@ -144,14 +144,4 @@
   Void xGetSubPUAddrAndMerge(TComDataCU* pcCU, UInt uiPartAddr, Int iSPWidth, Int iSPHeight, Int iNumSPInOneLine, Int iNumSP, UInt* uiMergedSPW, UInt* uiMergedSPH, UInt* uiSPAddr );
 #endif
-#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 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 );
-#endif
-#endif
 
   Void destroy();
@@ -174,14 +164,17 @@
   Void predIntraAng               ( const ComponentID compID, UInt uiDirMode, Pel *piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, Bool bAbove, Bool bLeft, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM = false );
 
-#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 
-    , TComWedgelet* dmm4Segmentation = NULL
-    );
+#if NH_3D_DMM
+  Void predIntraLumaDmm           ( TComDataCU* pcCU, UInt uiAbsPartIdx, DmmID dmmType, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight );
+  Void predContourFromTex         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* segPattern );
+  Void predBiSegDCs               ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 );
+  Void assignBiSegDCs             ( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 );
+#endif
+#if TEMP_SDC_CLEANUP // PM: consider this cleanup for SDC
+#if NH_3D_SDC
+  Void predConstantSDC            ( Pel* ptrSrc, UInt srcStride, UInt uiSize, Pel& predDC );
+#endif
+#else // PM: should be obsolete after cleanup
 #if H_3D_DIM_SDC
-  Void analyzeSegmentsSDC         ( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
-                                    ,UInt uiIntraMode 
-                                    ,Bool orgDC=false
-    );
+  Void analyzeSegmentsSDC         ( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride, UInt uiIntraMode, Bool orgDC=false );
 #endif
 #endif
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRdCost.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRdCost.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRdCost.cpp	(revision 1209)
@@ -511,7 +511,6 @@
 }
 
-#if H_3D_FAST_DEPTH_INTRA
-
-UInt TComRdCost::calcVAR (Pel* pi0, Int stride, Int width, Int height, Int cuDepth)
+#if NH_3D_ENC_DEPTH
+UInt TComRdCost::calcVAR (Pel* pi0, Int stride, Int width, Int height, Int cuDepth, UInt maxCuWidth)
 { 
   Int temp = 0;
@@ -525,5 +524,5 @@
   }
 
-  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;
+  Int cuMaxLog2Size = g_aucConvertToBit[maxCuWidth]+2;
   
   if ( width == 4 ) 
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRdCost.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRdCost.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRdCost.h	(revision 1209)
@@ -212,6 +212,6 @@
   Distortion calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
 
-#if H_3D_FAST_DEPTH_INTRA
-  UInt    calcVAR(Pel* pi0, Int stride, Int width, Int height, Int cuDepth);
+#if NH_3D_ENC_DEPTH
+  UInt    calcVAR(Pel* pi0, Int stride, Int width, Int height, Int cuDepth, UInt maxCuWidth );
 #endif  
 
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRom.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRom.cpp	(revision 1209)
@@ -253,27 +253,14 @@
     }
   }
-#if H_3D_DIM_DMM
+
+#if NH_3D_DMM
   if( !g_dmmWedgeLists.empty() ) 
   {
-    for( UInt ui = 0; ui < g_dmmWedgeLists.size(); ui++ )
-    { 
-      g_dmmWedgeLists[ui].clear(); 
-    }
+    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(); 
-    }
+    for( UInt ui = 0; ui < g_dmmWedgeNodeLists.size(); ui++ ) { g_dmmWedgeNodeLists[ui].clear(); }
     g_dmmWedgeNodeLists.clear();
   }
@@ -523,5 +510,5 @@
   //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, DM
   { 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31, DM_CHROMA_IDX};
-#if H_3D_DIM_DMM
+#if NH_3D_DMM
 // ====================================================================================================================
 // Depth coding modes
@@ -539,10 +526,7 @@
 { //2x2   4x4   8x8 16x16 32x32 64x64
      0,    7,   10,   9,    9,   13 };
-const UChar g_dmm3IntraTabIdxBits[6] =
-{ //2x2   4x4   8x8 16x16 32x32 64x64
-     0,    4,    7,    8,    8,    0 };
+
 Bool g_wedgePattern[32*32];
 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
@@ -753,19 +737,19 @@
 #endif
 #endif
-#if H_3D_DIM_DMM
+#if NH_3D_DMM
 std::vector< std::vector<TComWedgelet>  > g_dmmWedgeLists;
-std::vector< std::vector<TComWedgeRef>  > g_dmmWedgeRefLists;
 std::vector< std::vector<TComWedgeNode> > g_dmmWedgeNodeLists;
+
 Void initWedgeLists( Bool initNodeList )
 {
   if( !g_dmmWedgeLists.empty() ) return;
-  for( UInt ui = g_aucConvertToBit[DIM_MIN_SIZE]; ui < (g_aucConvertToBit[DIM_MAX_SIZE]); ui++ )
-  {
-    UInt uiWedgeBlockSize = ((UInt)DIM_MIN_SIZE)<<ui;
+  for( UInt ui = g_aucConvertToBit[DMM_MIN_SIZE]; ui < (g_aucConvertToBit[DMM_MAX_SIZE]); ui++ )
+  {
+    UInt uiWedgeBlockSize = ((UInt)DMM_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 );
+
     if( initNodeList )
     {
@@ -827,4 +811,5 @@
   }
 }
+
 Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes )
 {
@@ -867,4 +852,5 @@
   }
 }
+
 Void addWedgeletToList( TComWedgelet cWedgelet, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList )
 {
@@ -900,5 +886,4 @@
   if( bValid )
   {
-    cWedgelet.findClosestAngle();
     racWedgeList.push_back( cWedgelet );
     TComWedgeRef cWedgeRef;
@@ -907,4 +892,12 @@
   }
 }
-#endif //H_3D_DIM_DMM
+WedgeList* getWedgeListScaled( UInt blkSize ) 
+{ 
+  return &g_dmmWedgeLists[ g_aucConvertToBit[( 16 >= blkSize ) ? blkSize : 16] ]; 
+}
+WedgeNodeList* getWedgeNodeListScaled( UInt blkSize )
+{
+  return &g_dmmWedgeNodeLists[ g_aucConvertToBit[( 16 >= blkSize ) ? blkSize : 16] ]; 
+}
+#endif //NH_3D_DMM
 //! \}
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRom.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRom.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComRom.h	(revision 1209)
@@ -39,5 +39,5 @@
 #include<stdio.h>
 #include<iostream>
-#if H_3D_DIM
+#if NH_3D_DMM
 #include "TComWedgelet.h"
 #endif
@@ -91,25 +91,27 @@
 extern const UChar  g_aucIntraModeNumFast_NotUseMPM[MAX_CU_DEPTH];
 extern const UChar  g_chroma422IntraAngleMappingTable[NUM_INTRA_MODE];
-#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_SDC || H_3D_DIM_DLT
-__inline UInt numBitsForValue( UInt value ) { UInt bits = 0; while (value != 0) { value >>= 1; bits++; } return bits; };
-#endif
-#if H_3D_DIM_DMM
+#if NH_3D_DMM
 extern const WedgeResolution                                 g_dmmWedgeResolution [6];
 extern const UChar                                           g_dmm1TabIdxBits     [6];
-extern const UChar                                           g_dmm3IntraTabIdxBits[6];
 extern Bool                                                  g_wedgePattern[32*32];
 extern       std::vector< std::vector<TComWedgelet> >        g_dmmWedgeLists;
-extern       std::vector< std::vector<TComWedgeRef> >        g_dmmWedgeRefLists;
 extern       std::vector< std::vector<TComWedgeNode> >       g_dmmWedgeNodeLists;
+
 Void initWedgeLists( Bool initNodeList = 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
+
+WedgeList*     getWedgeListScaled    ( UInt blkSize );
+WedgeNodeList* getWedgeNodeListScaled( UInt blkSize );
+
+__inline Void mapDmmToIntraDir( UInt& intraMode ) { if( isDmmMode( intraMode ) ) intraMode = DC_IDX; }
+__inline Void mapDmmToIntraDir(  Int& intraMode ) { if( isDmmMode( intraMode ) ) intraMode = DC_IDX; }
+#endif
+#if H_3D_DIM_SDC || H_3D_DIM_DLT
+__inline UInt numBitsForValue( UInt value ) { UInt bits = 0; while (value != 0) { value >>= 1; bits++; } return bits; };
 #endif
 // ====================================================================================================================
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComSlice.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComSlice.h	(revision 1209)
@@ -2706,6 +2706,4 @@
   Int                         getNumCurCmpLIds( )                      const         { return (Int) m_inCmpRefViewIdcs.size();                       }
   TComPic*                    getIvPic( Bool depthFlag, Int viewIndex) const         { return  m_ivPicsCurrPoc[ depthFlag ? 1 : 0 ][ viewIndex ];    }
-#endif                                                                                                                                               
-#if H_3D                                                                                                                                             
   TComPic*                    getTexturePic       ()                                 { return  m_ivPicsCurrPoc[0][ m_viewIndex ];                    }
 #endif                                                                                                                                               
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComWedgelet.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComWedgelet.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComWedgelet.cpp	(revision 1209)
@@ -45,5 +45,5 @@
 using namespace std;
 
-#if H_3D_DIM_DMM
+#if NH_3D_DMM
 TComWedgelet::TComWedgelet( UInt uiWidth, UInt uiHeight ) : m_uhXs     ( 0 ),
                                                             m_uhYs     ( 0 ),
@@ -64,9 +64,8 @@
                                                             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) ) )
-                                                            ,m_pbScaledPattern( g_wedgePattern )
+                                                            m_pbPattern( (Bool*)xMalloc( Bool, (m_uiWidth * m_uiHeight) ) ),
+                                                            m_pbScaledPattern( g_wedgePattern )
 {
   ::memcpy( m_pbPattern, rcWedge.m_pbPattern, sizeof(Bool) * (m_uiWidth * m_uiHeight));
@@ -97,33 +96,4 @@
 {
   ::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;
 }
 
@@ -205,5 +175,4 @@
   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;
@@ -295,29 +264,64 @@
 }
 
-Bool* TComWedgelet::getScaledPattern(UInt uiDstSize)
+Bool* TComWedgelet::getPatternScaled( UInt dstSize )
 {
   Bool *pbSrcPat = this->getPattern();
   UInt uiSrcSize = this->getStride();
 
-  Int scale = (g_aucConvertToBit[uiDstSize] - g_aucConvertToBit[uiSrcSize]);
-  assert(scale>=0);
-  for (Int y=0; y<uiDstSize; y++)
-  {
-    for (Int x=0; x<uiDstSize; x++)
-    {
-      Int srcX = x>>scale;
-      Int srcY = y>>scale;
-      m_pbScaledPattern[y*uiDstSize + x] = pbSrcPat[ srcY*uiSrcSize + srcX ];
-    }
-  }
-  return m_pbScaledPattern;
-}
+  if( 16 >= dstSize )
+  {
+    assert( dstSize == uiSrcSize );
+    return pbSrcPat;
+  }
+  else
+  {
+    Int scale = (g_aucConvertToBit[dstSize] - g_aucConvertToBit[uiSrcSize]);
+    assert(scale>=0);
+    for (Int y=0; y<dstSize; y++)
+    {
+      for (Int x=0; x<dstSize; x++)
+      {
+        Int srcX = x>>scale;
+        Int srcY = y>>scale;
+        m_pbScaledPattern[y*dstSize + x] = pbSrcPat[ srcY*uiSrcSize + srcX ];
+      }
+    }
+    return m_pbScaledPattern;
+  }
+}
+
+Void TComWedgelet::getPatternScaledCopy( UInt dstSize, Bool* dstBuf )
+{
+  Bool *pbSrcPat = this->getPattern();
+  UInt uiSrcSize = this->getStride();
+
+  if( 16 >= dstSize )
+  {
+    assert( dstSize == uiSrcSize );
+    memcpy( dstBuf, pbSrcPat, (dstSize*dstSize) );
+  }
+  else
+  {
+    Int scale = (g_aucConvertToBit[dstSize] - g_aucConvertToBit[uiSrcSize]);
+    assert(scale>=0);
+    for (Int y=0; y<dstSize; y++)
+    {
+      for (Int x=0; x<dstSize; x++)
+      {
+        Int srcX = x>>scale;
+        Int srcY = y>>scale;
+        dstBuf[y*dstSize + x] = pbSrcPat[ srcY*uiSrcSize + srcX ];
+      }
+    }
+  }
+}
+
 
 TComWedgeNode::TComWedgeNode()
 {
-  m_uiPatternIdx = DMM_NO_WEDGEINDEX;
+  m_uiPatternIdx = DMM_NO_WEDGE_IDX;
   for( UInt uiPos = 0; uiPos < DMM_NUM_WEDGE_REFINES; uiPos++ )
   {
-    m_uiRefineIdx[uiPos] = DMM_NO_WEDGEINDEX;
+    m_uiRefineIdx[uiPos] = DMM_NO_WEDGE_IDX;
   }
 }
@@ -341,3 +345,3 @@
   m_uiRefineIdx[uiPos] = uiIdx;  
 }
-#endif //H_3D_DIM_DMM
+#endif //NH_3D_DMM
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComWedgelet.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComWedgelet.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TComWedgelet.h	(revision 1209)
@@ -43,29 +43,27 @@
 #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
+#if NH_3D_DMM
+#define DMM_OFFSET     (NUM_INTRA_MODE+1) // offset for DMM and RBC mode numbers
+#define DMM_MIN_SIZE                   4  // min. block size for DMM and RBC modes
+#define DMM_MAX_SIZE                  32  // max. block size for DMM and RBC modes
 
-enum DIM_IDX
+enum DmmID
 {
   DMM1_IDX = 0,
   DMM4_IDX = 1,
+  NUM_DMM  = 2,
+  DMM_NO_IDX = MAX_UINT
 };
 
-#define DMM_NUM_TYPE   2
-#define DIM_NUM_TYPE   (DMM_NUM_TYPE)
-#define DIM_NO_IDX     MAX_UINT
+__inline DmmID getDmmType( Int intraMode ) 
+{ 
+    Int dmmType = intraMode-DMM_OFFSET; 
+    return (dmmType >= 0 && dmmType < NUM_DMM) ? (DmmID)dmmType : DMM_NO_IDX; 
+}
+__inline Bool isDmmMode( Int intraMode ) { return ((UInt)getDmmType( intraMode ) < NUM_DMM); }
 
-__inline UInt getDimType  ( Int intraMode ) 
-{ 
-    Int dimType = intraMode-DIM_OFFSET; 
-    return (dimType >= 0 && dimType < DIM_NUM_TYPE) ? (UInt)dimType : DIM_NO_IDX; 
-}
-__inline Bool isDimMode   ( Int intraMode ) { return (getDimType( intraMode ) < DIM_NUM_TYPE); }
-#endif
 
-#if H_3D_DIM_DMM
-#define DMM_NO_WEDGEINDEX       MAX_UINT
+// Wedgelets
+#define DMM_NO_WEDGE_IDX       MAX_UINT
 #define DMM_NUM_WEDGE_REFINES   8
 
@@ -90,5 +88,4 @@
   WedgeResolution m_eWedgeRes;                  // start/end pos resolution
   Bool            m_bIsCoarse; 
-  UInt            m_uiAng;
 
   UInt  m_uiWidth;
@@ -121,14 +118,14 @@
   UChar           getOri     () { return m_uhOri; }
   Bool            getIsCoarse() { return m_bIsCoarse; }
-  UInt            getAng     () { return m_uiAng; }
-  Bool*           getScaledPattern(UInt uiWidth);
 
   Void  generateWedgePatternByRotate(const TComWedgelet &rcWedge, Int rotate);
   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 );
+
+  Bool* getPatternScaled    ( UInt dstSize );
+  Void  getPatternScaledCopy( UInt dstSize, Bool* dstBuf );
 
 };  // END CLASS DEFINITION TComWedgelet
@@ -162,6 +159,4 @@
 };  // END CLASS DEFINITION TComWedgeRef
 
-// type definition wedgelet reference list
-typedef std::vector<TComWedgeRef> WedgeRefList;
 
 // ====================================================================================================================
@@ -187,14 +182,5 @@
 // type definition wedgelet node list
 typedef std::vector<TComWedgeNode> WedgeNodeList;
-#endif //H_3D_DIM_DMM
+#endif //NH_3D_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-14.1-update-dev1-HHI/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TypeDef.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibCommon/TypeDef.h	(revision 1209)
@@ -69,5 +69,14 @@
 #if NH_3D
 #define NH_3D_VSO                         1
-#endif
+#define NH_3D_DMM                         1   // Depth modeling modes
+#define NH_3D_SDC                         1   // Segment-wise DC coding for intra and inter
+#define NH_3D_ENC_DEPTH                   1   // Encoder optimizations for depth, incl.
+                                              // HHI_DEPTH_INTRA_SEARCH_RAU_C0160
+                                              // LG_ZEROINTRADEPTHRESI_A0087
+                                              // HHI_DMM4_ENC_I0066
+                                              // H_3D_FAST_DEPTH_INTRA
+#endif
+
+#define TEMP_SDC_CLEANUP                  1   // PM: consider these cleanups for DMM and SDC
 
 #if H_3D
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1209)
@@ -3389,9 +3389,4 @@
 #endif
 #if H_3D_INTER_SDC
-Void TDecCavlc::parseDeltaDC( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
-{ 
-  assert(0);
-}
-
 Void TDecCavlc::parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
 {
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 1209)
@@ -123,6 +123,8 @@
   Void  parseICFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+  Void  parseDeltaDC        ( TComDataCU* /*pcCU*/, UInt /*absPartIdx*/, UInt /*depth*/ ) { assert(0); };
+#endif
 #if H_3D_INTER_SDC
-  Void  parseDeltaDC        ( TComDataCU* pcCU, UInt absPartIdx, UInt depth );
   Void  parseSDCFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecCu.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecCu.cpp	(revision 1209)
@@ -1009,15 +1009,14 @@
 
   //===== get prediction signal =====
-#if H_3D_DIM
-  if( isDimMode( uiLumaPredMode ) )
-  {
-    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
+#if NH_3D_DMM
+  if( bIsLuma && isDmmMode( uiChFinalMode ) )
+  {
+    m_pcPrediction->predIntraLumaDmm( pcCU, uiAbsPartIdx, getDmmType( uiChFinalMode ), piPred, uiStride, uiWidth, uiHeight );
   }
   else
   {
 #endif
-
   m_pcPrediction->predIntraAng( compID,   uiChFinalMode, 0 /* Decoder does not have an original image */, 0, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
-#if H_3D_DIM
+#if NH_3D_DMM
   }
 #endif
@@ -1040,5 +1039,5 @@
 #endif
 #if H_3D
-  Bool useDltFlag = (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps());
+  Bool useDltFlag = (isDmmMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps());
 
   if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) || useDltFlag )
@@ -1158,8 +1157,4 @@
   }
 }
-#if H_3D_DIM
-      mapDepthModeToIntraDir( uiChromaPredMode );
-#endif
-
 
 Void
@@ -1191,4 +1186,143 @@
 Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
 {
+#if TEMP_SDC_CLEANUP // PM: consider this cleanup for DMM and SDC
+  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
+  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
+  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
+
+  Bool bAboveAvail    = false;
+  Bool bLeftAvail     = false;
+  UInt uiWidth        = pcCU->getWidth ( 0 );
+  UInt uiHeight       = pcCU->getHeight( 0 );
+  UInt uiLumaPredMode = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx );
+
+  UInt sdcDepth = 0;
+  UInt uiStride;
+  Pel* piReco;
+  Pel* piPred;
+  Pel* piResi;
+
+  UInt uiZOrder;        
+  Pel* piRecIPred;      
+  UInt uiRecIPredStride;
+  
+  Pel apDCPredValues[2];
+  UInt uiNumSegments;
+
+  Bool* pbMask = NULL;
+  UInt uiMaskStride = 0;
+
+#if NH_3D_DMM
+  TComWedgelet* dmm4Segmentation = NULL;
+  if( isDmmMode( uiLumaPredMode ) )
+  {
+    assert( uiWidth == uiHeight  );
+    assert( uiWidth >= DMM_MIN_SIZE && uiWidth <= DMM_MAX_SIZE );
+    assert( !((uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize()) > 1) );
+
+    uiNumSegments     = 2;
+
+    uiStride          = pcRecoYuv->getStride( COMPONENT_Y );
+    piReco            = pcRecoYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
+    piPred            = pcPredYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
+    piResi            = pcResiYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
+
+    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getAddr  ( COMPONENT_Y, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
+    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride( COMPONENT_Y );
+
+    //===== init availability pattern =====
+#if !TEMP_SDC_CLEANUP // PM: please migrate together with below "initPattern" and remove macro
+    pcCU->getPattern()->initPattern   ( pcCU, sdcDepth, uiAbsPartIdx );
+    pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, sdcDepth, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
+#endif
+
+    // get partition
+    pbMask       = new Bool[ uiWidth*uiHeight ];
+    uiMaskStride = uiWidth;
+    switch( getDmmType( uiLumaPredMode ) )
+    {
+    case( DMM1_IDX ): { (getWedgeListScaled( uiWidth )->at( pcCU->getDmm1WedgeTabIdx( uiAbsPartIdx ) )).getPatternScaledCopy( uiWidth, pbMask ); } break;
+    case( DMM4_IDX ): { m_pcPrediction->predContourFromTex( pcCU, uiAbsPartIdx, uiWidth, uiHeight, pbMask );                                     } break;
+    default: assert(0);
+    }
+
+    // get predicted partition values
+    Pel predDC1 = 0, predDC2 = 0;
+    m_pcPrediction->predBiSegDCs( pcCU, uiAbsPartIdx, uiWidth, uiHeight, pbMask, uiMaskStride, predDC1, predDC2 );
+
+    // set prediction signal
+    Pel* pDst = piPred;
+    m_pcPrediction->assignBiSegDCs( pDst, uiStride, pbMask, uiMaskStride, predDC1, predDC2 );
+    apDCPredValues[0] = predDC1;
+    apDCPredValues[1] = predDC2;
+  }
+  else // regular HEVC intra modes
+  {
+#endif
+    uiNumSegments = 1;
+
+    UInt numParts = 1;
+    UInt uiSubPartIdx = uiAbsPartIdx;
+
+    if ((uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize()) > 1)
+    {
+      numParts = uiWidth * uiWidth >> (2 * pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
+      sdcDepth = g_aucConvertToBit[uiWidth] + 2 - pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
+      uiWidth = uiHeight = (1 << pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
+    }
+
+    for ( Int i = 0; i < numParts; i++ )
+    {
+      uiStride    = pcRecoYuv->getStride  ();
+      piReco      = pcRecoYuv->getLumaAddr( uiSubPartIdx );
+      piPred      = pcPredYuv->getLumaAddr( uiSubPartIdx );
+      piResi      = pcResiYuv->getLumaAddr( uiSubPartIdx );
+
+      uiZOrder          = pcCU->getZorderIdxInCU() + uiSubPartIdx;
+      piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
+      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
+
+      AOF( uiWidth == uiHeight );
+
+      //===== init availability pattern =====
+      pcCU->getPattern()->initPattern   ( pcCU, sdcDepth, uiSubPartIdx );
+      pcCU->getPattern()->initAdiPattern( pcCU, uiSubPartIdx, sdcDepth, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
+
+      m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
+
+      if ( numParts > 1 )
+      {
+        for( UInt uiY = 0; uiY < uiHeight; uiY++ )
+        {
+          for( UInt uiX = 0; uiX < uiWidth; uiX++ )
+          {
+            piReco        [ uiX ] = ClipY( piPred[ uiX ] );
+            piRecIPred    [ uiX ] = piReco[ uiX ];
+          }
+          piPred     += uiStride;
+          piReco     += uiStride;
+          piRecIPred += uiRecIPredStride;
+        }
+      }
+      uiSubPartIdx += ( (uiWidth * uiWidth) >> 4 );
+    }
+
+    // reset to full block
+    uiWidth  = pcCU->getWidth( 0 );
+    uiHeight = pcCU->getHeight( 0 );
+
+    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
+    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
+    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
+
+    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
+    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
+    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
+
+    m_pcPrediction->predConstantSDC( piPred, uiStride, uiWidth, apDCPredValues[0] ); apDCPredValues[1] = 0;
+#if NH_3D_DMM
+  }
+#endif
+#else
   UInt uiWidth        = pcCU->getWidth  ( 0 );
   UInt uiHeight       = pcCU->getHeight ( 0 );
@@ -1242,5 +1376,5 @@
     TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
     //===== get prediction signal =====
-    if( isDimMode( uiLumaPredMode ) )
+    if( isDmmMode( uiLumaPredMode ) )
     {
       m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, false, dmm4Segmentation  );
@@ -1292,5 +1426,5 @@
   UInt uiMaskStride = 0;
   
-  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
+  if( getDmmType( uiLumaPredMode ) == DMM1_IDX )
   {
     Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
@@ -1304,5 +1438,5 @@
     uiMaskStride = pcCU->isDMM1UpscaleMode( uiWidth ) ? uiWidth : pcWedgelet->getStride();
   }
-  if( getDimType( uiLumaPredMode ) == DMM4_IDX )
+  if( getDmmType( uiLumaPredMode ) == DMM4_IDX )
   {
     uiNumSegments = 2;
@@ -1312,5 +1446,5 @@
   // get DC prediction for each segment
   Pel apDCPredValues[2];
-  if ( getDimType( uiLumaPredMode ) == DMM1_IDX || getDimType( uiLumaPredMode ) == DMM4_IDX )
+  if ( getDmmType( uiLumaPredMode ) == DMM1_IDX || getDmmType( uiLumaPredMode ) == DMM4_IDX )
   {
     apDCPredValues[0] = pcCU->getDmmPredictor( 0 );
@@ -1321,4 +1455,5 @@
     m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode);
   }
+#endif
   
   // reconstruct residual based on mask + DC residuals
@@ -1379,5 +1514,11 @@
     pRecCr += uiStrideC;
   }
+#if NH_3D_DMM
+#if TEMP_SDC_CLEANUP // PM: consider this cleanup for DMM and SDC
+  if( pbMask ) { delete[] pbMask; }
+#else
   dmm4SegmentationOrg->destroy(); delete dmm4SegmentationOrg;
+#endif
+#endif
 }
 #endif
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 1209)
@@ -970,4 +970,5 @@
     assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
 }
+#endif
 #if H_3D_INTER_SDC
   if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx) )
@@ -978,24 +979,28 @@
   }
 #endif
-  if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) )
-  {
-    Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
-    UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
-  
-    if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
-    {
-      for( Int iPart = 0; iPart < iPartNum; iPart++ )
-      {
-        if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) 
-        {
-          m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart, uiDepth + ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) );
-        }
-      }
-    }
-    else
+#if NH_3D
+  if( pcCU->getSlice()->getIsDepth() )
+  {
+#if H_3D_DIM_SDC || H_3D_INTER_SDC
+    if( pcCU->getSDCFlag( uiAbsPartIdx ) )
     {
       m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx, uiDepth );
       return;
     }
+#endif
+#if NH_3D_DMM
+    if( pcCU->isIntra( uiAbsPartIdx ) )
+    {
+      Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
+      UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
+      for( Int iPart = 0; iPart < iPartNum; iPart++ )
+      {
+        if( isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx + uiPartOffset*iPart ) ) )
+        {
+          m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart, uiDepth + ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) );
+        }
+      }
+    }
+#endif
   }
 #endif
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecEntropy.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecEntropy.h	(revision 1209)
@@ -91,6 +91,8 @@
   virtual Void parseICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
 #endif
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+  virtual Void  parseDeltaDC      ( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) = 0;
+#endif
 #if H_3D_INTER_SDC
-  virtual Void parseDeltaDC       ( TComDataCU* pcCU, UInt absPartIdx, UInt depth ) = 0;
   virtual Void parseSDCFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
 #endif
@@ -180,4 +182,5 @@
   Void decodeICFlag            ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
+
 #if H_3D_INTER_SDC
   Void decodeSDCFlag           ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 1209)
@@ -106,19 +106,20 @@
 , m_ChromaQpAdjFlagSCModel                   ( 1,             1,                      NUM_CHROMA_QP_ADJ_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
 , m_ChromaQpAdjIdcSCModel                    ( 1,             1,                      NUM_CHROMA_QP_ADJ_IDC_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)
-, m_cAngleFlagSCModel         ( 1,             1,               NUM_ANGLE_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
+
+#if NH_3D_DMM
+, m_cNotDmmFlagSCModel                       ( 1,             1,                      NUM_NOTDMM_FLAG_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDmmModeSCModel                          ( 1,             1,                      NUM_DMM_MODE_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
+#if NH_3D_DMM || NH_3D_SDC
+, m_cDdcDataSCModel                          ( 1,             1,                      NUM_DDC_DATA_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
 #if H_3D_DIM_SDC
-, m_cSDCResidualFlagSCModel     ( 1,             1,             SDC_NUM_RESIDUAL_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
-, m_cSDCResidualSCModel         ( 1,             1,             SDC_NUM_RESIDUAL_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
-#endif
-#endif
-#if H_3D_DIM_SDC
-, m_cSDCFlagSCModel                  ( 1,             1,  NUM_SDC_FLAG_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cSDCResidualFlagSCModel                  ( 1,             1,                     SDC_NUM_RESIDUAL_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cSDCResidualSCModel                      ( 1,             1,                     SDC_NUM_RESIDUAL_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cSDCFlagSCModel                          ( 1,             1,                     NUM_SDC_FLAG_CTX                      , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDdcFlagSCModel                          ( 1,             1,                     NUM_DDC_FLAG_CTX                      , m_contextModels + m_numContextModels, m_numContextModels)
 #endif
 #if H_3D_DBBP
-, m_cDBBPFlagSCModel             ( 1,             1,                 DBBP_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDBBPFlagSCModel                         ( 1,             1,                     DBBP_NUM_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
 #endif
 
@@ -197,19 +198,19 @@
   m_ChromaQpAdjFlagSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG );
   m_ChromaQpAdjIdcSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC );
-#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 );
-  m_cAngleFlagSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_ANGLE_FLAG );
+#if NH_3D_DMM
+  m_cNotDmmFlagSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_NOTDMM_FLAG );
+  m_cDmmModeSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_DMM_MODE );
+#endif
+#if NH_3D_DMM || NH_3D_SDC
+  m_cDdcDataSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_DDC_DATA );
+#endif
 #if H_3D_DIM_SDC
-  m_cSDCResidualFlagSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
-  m_cSDCResidualSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
-#endif
-#endif
-#if H_3D_DIM_SDC
-  m_cSDCFlagSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SDC_FLAG );
+  m_cSDCResidualFlagSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
+  m_cSDCResidualSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_SDC_RESIDUAL );
+  m_cSDCFlagSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_SDC_FLAG );
+  m_cDdcFlagSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_DDC_FLAG );
 #endif
 #if H_3D_DBBP
-  m_cDBBPFlagSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_DBBP_FLAG );
+  m_cDBBPFlagSCModel.initBuffer                   ( sliceType, qp, (UChar*)INIT_DBBP_FLAG );
 #endif
 
@@ -247,16 +248,9 @@
   m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
 #endif
-#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 );
-  m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
 #if H_3D_DIM_SDC
   m_cSDCResidualFlagSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
   m_cSDCResidualSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
-#endif
-#endif
-#if H_3D_DIM_SDC
   m_cSDCFlagSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
+  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
 #endif
 #if H_3D_DBBP
@@ -433,61 +427,4 @@
   }
 }
-
-#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 != 3 ) );
-  ruiSymbol = uiCount - 1;
-
-  if( uiSymbol )
-  {
-    xReadEpExGolomb( uiSymbol, 0 );
-    ruiSymbol += uiSymbol + 1;
-  }
-
-  return;
-}
-
-Void TDecSbac::xParseDimDeltaDC( Pel& rValDeltaDC, UInt uiNumSeg )
-{
-  UInt absValDeltaDC = 0;
-  xReadExGolombLevel( absValDeltaDC, m_cDdcDataSCModel.get(0, 0, 0) );
-  rValDeltaDC = (Pel)absValDeltaDC + ( uiNumSeg > 1 ? 0 : 1 );
-
-  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->decodeBinEP( uiSymbol );
-    uiIdx += uiSymbol << i;
-  }
-  ruiTabIdx = uiIdx;
-}
-#endif
-
-
-#endif
-
 
 /** Parse I_PCM information.
@@ -1019,10 +956,11 @@
   for (j=0;j<partNum;j++)
   {
-#if H_3D_DIM
+#if NH_3D_DMM
     if( pcCU->getSlice()->getIntraSdcWedgeFlag() || pcCU->getSlice()->getIntraContourFlag() )
     {
-      parseIntraDepth( pcCU, absPartIdx+partOffset*j, depth );
-    }
-    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
+      xParseIntraDepthMode( pcCU, absPartIdx+partOffset*j, depth );
+      xParseDmmData       ( pcCU, absPartIdx+partOffset*j, depth );
+    }
+    if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
     {
 #endif
@@ -1032,5 +970,5 @@
       DTRACE_CU("prev_intra_luma_pred_flag", symbol)
 #endif
-#if H_3D_DIM
+#if NH_3D_DMM
     }
 #endif
@@ -1038,6 +976,6 @@
   for (j=0;j<partNum;j++)
   {
-#if H_3D_DIM
-    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
+#if NH_3D_DMM
+    if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
     {
 #endif
@@ -1084,5 +1022,5 @@
     }
     pcCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
-#if H_3D_DIM
+#if NH_3D_DMM
     }
 #endif
@@ -1120,74 +1058,4 @@
   pcCU->setIntraDirSubParts( CHANNEL_TYPE_CHROMA, uiSymbol, uiAbsPartIdx, uiDepth );
 }
-
-#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)] );
-
-      assert( uiTabIdx < g_dmmWedgeLists[ g_aucConvertToBit[ pcCU->getDMM1BasePatternWidth( pcCU->getWidth( absPartIdx ) )]].size());
-
-      pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, absPartIdx, depth );
-    } break;
-  case( DMM4_IDX ): break;
-#endif
-  default: break;
-  }
-
-  pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
-}
-
-Void TDecSbac::parseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
-{
-  UInt uiSymbol, uiIsDimMode;
-
-  if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
-  {
-    m_pcTDecBinIf->decodeBin( uiSymbol, m_cAngleFlagSCModel.get( 0, 0, 0 ) );
-  }
-  else
-  {
-    uiSymbol = 1;
-  }
-  uiIsDimMode = uiSymbol ? 0 : 1;
-  pcCU->setLumaIntraDirSubParts( 0, absPartIdx, depth );
-
-  //decode DMM index
-  if( uiIsDimMode )
-  {
-    if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag() )
-    {
-      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
-      if( !uiSymbol )
-      {
-        pcCU->setLumaIntraDirSubParts( DIM_OFFSET, absPartIdx, depth );
-      }
-      else
-      {
-        pcCU->setLumaIntraDirSubParts( ( 1+ DIM_OFFSET ), absPartIdx, depth );
-      }
-    }
-    else if ( pcCU->getSlice()->getIntraSdcWedgeFlag() )
-    {
-      pcCU->setLumaIntraDirSubParts( DIM_OFFSET, absPartIdx, depth );
-    }
-    else if( pcCU->getSlice()->getIntraContourFlag() )
-    {
-      pcCU->setLumaIntraDirSubParts( ( 1+ DIM_OFFSET ), absPartIdx, depth );
-    }
-  }
-}
-#endif
 
 Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
@@ -2472,18 +2340,19 @@
 #endif
 
-#if H_3D_INTER_SDC
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
 Void TDecSbac::parseDeltaDC( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
 {
-  if( ! ( pcCU->getSDCFlag( absPartIdx ) || ( pcCU->isIntra( absPartIdx ) && getDimType( pcCU->getLumaIntraDir( absPartIdx ) ) < DIM_NUM_TYPE ) ) )
-  {
+#if H_3D_DIM_SDC || H_3D_INTER_SDC
+  if( !(pcCU->getSDCFlag( absPartIdx )) )
+#endif
+#if NH_3D_DMM
+  if( !(pcCU->isIntra( absPartIdx ) && isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) )) )
+#endif
     assert( 0 );
-  }
 
   UInt symbol = 1;
-  UInt uiNumSegments = isDimMode( pcCU->getLumaIntraDir( absPartIdx ) ) ? 2 : 1;
-
+#if H_3D_DIM_SDC
   if( pcCU->isIntra( absPartIdx ) && pcCU->getSDCFlag( absPartIdx ))
   {
-
     m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get( 0, 0, 0 ) );
       assert( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N );
@@ -2491,4 +2360,9 @@
       pcCU->setCbfSubParts( 1, 1, 1, absPartIdx, depth );
     }
+#endif
+  UInt uiNumSegments = 1;
+#if NH_3D_DMM
+  uiNumSegments = isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ) ? 2 : 1;
+#endif
 
   for( UInt segment = 0; segment < uiNumSegments; segment++ )
@@ -2497,11 +2371,10 @@
     if( symbol )
     {
-      xParseDimDeltaDC( valDeltaDC, uiNumSegments );
+      xParseDeltaDC( valDeltaDC, uiNumSegments );
     }
 
     if( pcCU->isIntra( absPartIdx ) )
     {
-      UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
-
+#if H_3D_DIM_SDC
       if( pcCU->getSDCFlag( absPartIdx ) )
       {
@@ -2510,14 +2383,129 @@
       else
       {
-        pcCU->setDimDeltaDC( getDimType( dir ), segment, absPartIdx, valDeltaDC );
-      }
-    }
+#endif
+#if NH_3D_DMM
+        pcCU->setDmmDeltaDC( getDmmType( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ), segment, absPartIdx, valDeltaDC );
+#endif
+#if H_3D_DIM_SDC
+      }
+#endif
+    }
+#if H_3D_INTER_SDC
     else
     {
       pcCU->setSDCSegmentDCOffset( valDeltaDC, segment, absPartIdx );
     }
-  }
-}
-
+#endif
+  }
+}
+
+Void TDecSbac::xParseDeltaDC( Pel& rValDeltaDC, UInt uiNumSeg )
+{
+  UInt absValDeltaDC = 0;
+  xReadExGolombLevelDdc( absValDeltaDC );
+  rValDeltaDC = (Pel)absValDeltaDC + ( uiNumSeg > 1 ? 0 : 1 );
+
+  if( rValDeltaDC != 0 )
+  {
+    UInt uiSign;
+    m_pcTDecBinIf->decodeBinEP( uiSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTADC_SIGN_EP) );
+    if ( uiSign )
+    {
+      rValDeltaDC = -rValDeltaDC;
+    }
+  }
+}
+
+Void TDecSbac::xReadExGolombLevelDdc( UInt& ruiSymbol )
+{
+  UInt uiSymbol;
+  UInt uiCount = 0;
+  do
+  {
+    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDdcDataSCModel.get(0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTADC_PREFIX) );
+    uiCount++;
+  }
+  while( uiSymbol && ( uiCount != 3 ) );
+  ruiSymbol = uiCount - 1;
+
+  if( uiSymbol )
+  {
+    xReadEpExGolomb( uiSymbol, 0 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTADC_SUFFIX_EP) );
+    ruiSymbol += uiSymbol + 1;
+  }
+
+  return;
+}
+#endif
+#if NH_3D_DMM
+Void TDecSbac::xParseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
+{
+  pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, 0, absPartIdx, depth );
+
+  UInt uiSymbol;
+  if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
+  {
+    m_pcTDecBinIf->decodeBin( uiSymbol, m_cNotDmmFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__NOTDMM_FLAG) );
+  }
+  else
+  {
+    uiSymbol = 1;
+  }
+
+  //decode DMM mode index
+  if( !uiSymbol )
+  {
+    if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag() )
+    {
+      m_pcTDecBinIf->decodeBin( uiSymbol, m_cDmmModeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DMMMODE) );
+      if( !uiSymbol )
+      {
+        pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, DMM_OFFSET, absPartIdx, depth );
+      }
+      else
+      {
+        pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, ( 1+ DMM_OFFSET ), absPartIdx, depth );
+      }
+    }
+    else if( pcCU->getSlice()->getIntraSdcWedgeFlag() )
+    {
+      pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, DMM_OFFSET, absPartIdx, depth );
+    }
+    else if( pcCU->getSlice()->getIntraContourFlag() )
+    {
+      pcCU->setIntraDirSubParts( CHANNEL_TYPE_LUMA, ( 1+ DMM_OFFSET ), absPartIdx, depth );
+    }
+  }
+}
+
+Void TDecSbac::xParseDmmData( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
+{
+  UInt dir = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx );
+  switch( getDmmType( dir ) )
+  {
+  case( DMM1_IDX ):
+    {
+      UInt uiTabIdx = 0;
+      xParseDmm1WedgeIdx( uiTabIdx, g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
+      assert( uiTabIdx < getWedgeListScaled( pcCU->getWidth( absPartIdx ) )->size() );
+      pcCU->setDmm1WedgeTabIdxSubParts( uiTabIdx, absPartIdx, depth );
+    } break;
+  case( DMM4_IDX ): break;
+  default: break;
+  }
+}
+
+Void TDecSbac::xParseDmm1WedgeIdx( UInt& ruiTabIdx, Int iNumBit )
+{
+  UInt uiSymbol, uiIdx = 0;
+  for( Int i = 0; i < iNumBit; i++ )
+  {
+    m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DMM1_BITS_EP) );
+    uiIdx += uiSymbol << i;
+  }
+  ruiTabIdx = uiIdx;
+}
+#endif
+#if H_3D_INTER_SDC
 Void TDecSbac::parseSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
 {
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecSbac.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibDecoder/TDecSbac.h	(revision 1209)
@@ -107,8 +107,11 @@
   Void  xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange );
 #endif
-#if H_3D_DIM
-  Void  xReadExGolombLevel   ( UInt& ruiSymbol, ContextModel& rcSCModel  );
-  Void  xParseDimDeltaDC     ( Pel& rValDeltaDC, UInt uiNumSeg );
-#if H_3D_DIM_DMM
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+  Void  xReadExGolombLevelDdc( UInt& ruiSymbol );
+  Void  xParseDeltaDC        ( Pel& rValDeltaDC, UInt uiNumSeg );
+#endif
+#if NH_3D_DMM
+  Void  xParseIntraDepthMode ( TComDataCU* pcCU, UInt absPartIdx, UInt depth );
+  Void  xParseDmmData        ( TComDataCU* pcCU, UInt absPartIdx, UInt depth );
   Void  xParseDmm1WedgeIdx   ( UInt& ruiTabIdx, Int iNumBit );
 #endif
@@ -116,7 +119,5 @@
   Void  xParseSDCResidualData     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart );
 #endif
-#endif
 #if H_3D_INTER_SDC
-  Void  parseDeltaDC         ( TComDataCU* pcCU, UInt absPartIdx, UInt depth );
   Void  parseSDCFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
@@ -134,4 +135,7 @@
 #if H_3D
   Void parseDIS          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#endif
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+  Void  parseDeltaDC      ( TComDataCU* pcCU, UInt absPartIdx, UInt depth );
 #endif
   Void parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
@@ -150,10 +154,4 @@
   Void parseIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   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 );
@@ -227,16 +225,16 @@
   ContextModel3DBuffer m_ChromaQpAdjFlagSCModel;
   ContextModel3DBuffer m_ChromaQpAdjIdcSCModel;
-#if H_3D_DIM
-  ContextModel3DBuffer m_cDepthIntraModeSCModel;
-  ContextModel3DBuffer m_cDdcFlagSCModel;
+#if NH_3D_DMM
+  ContextModel3DBuffer m_cNotDmmFlagSCModel;
+  ContextModel3DBuffer m_cDmmModeSCModel;
+#endif
+#if NH_3D_DMM || NH_3D_SDC
   ContextModel3DBuffer m_cDdcDataSCModel;
-  ContextModel3DBuffer m_cAngleFlagSCModel;
+#endif
 #if H_3D_DIM_SDC  
   ContextModel3DBuffer m_cSDCResidualFlagSCModel;
   ContextModel3DBuffer m_cSDCResidualSCModel;
-#endif
-#endif
-#if H_3D_DIM_SDC  
   ContextModel3DBuffer m_cSDCFlagSCModel;
+  ContextModel3DBuffer m_cDdcFlagSCModel;
 #endif
 #if H_3D_DBBP
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1209)
@@ -2887,16 +2887,9 @@
    assert(0);
  }
-
 #if H_3D_INTER_SDC
-Void TEncCavlc::codeDeltaDC( TComDataCU* pcCU, UInt uiAbsPartIdx )
+Void TEncCavlc::codeSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx )
 {
   assert(0);
 }
-
-Void TEncCavlc::codeSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx )
-{
-  assert(0);
-}
-
 #endif
     
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCavlc.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCavlc.h	(revision 1209)
@@ -126,4 +126,7 @@
   Void codeMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx );
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+  Void  codeDeltaDC      ( TComDataCU* /*pcCU*/, UInt /*absPartIdx*/ ) { assert(0); };
+#endif
 #if H_3D_ARP
   Void codeARPW          ( TComDataCU* pcCU, UInt uiAbsPartIdx );
@@ -132,6 +135,6 @@
   Void codeICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx );
 #endif
+
 #if H_3D_INTER_SDC
-  Void codeDeltaDC       ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeSDCFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx );
 #endif
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCu.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCu.cpp	(revision 1209)
@@ -733,5 +733,5 @@
     }
 #endif
-#if H_3D_DIM_ENC
+#if NH_3D_ENC_DEPTH
     if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() )
     {
@@ -1075,23 +1075,21 @@
 
         if((rpcBestCU->getSlice()->getSliceType() == I_SLICE)                                     ||
-            ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && (
+           ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && ( // avoid very complex intra if it is unlikely
            (rpcBestCU->getCbf( 0, COMPONENT_Y  ) != 0)                                            ||
           ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) ||
-          ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr))) 
- // avoid very complex intra if it is unlikely
-#if H_3D_DIM_ENC
+          ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr)) 
+ #if NH_3D_ENC_DEPTH
             || rpcBestCU->getSlice()->getIsDepth()
 #endif
-            ))
+            )))
         {
-#if H_3D_DIM
+#if NH_3D_ENC_DEPTH
             Bool bOnlyIVP = false;
             Bool bUseIVP = true;
-            if( rpcBestCU->getSlice()->getIsDepth() && !(rpcBestCU->getSlice()->isIRAP()) && 
-              rpcBestCU->getSlice()->getSliceType() != I_SLICE && 
-              rpcBestCU->getCbf( 0, TEXT_LUMA     ) == 0 &&
-              rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) == 0 &&
-              rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) == 0 
-              )
+            if( (rpcBestCU->getSlice()->getSliceType() != I_SLICE) && 
+                !( (rpcBestCU->getCbf( 0, COMPONENT_Y  ) != 0)                                            ||
+                  ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) ||
+                  ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr))   ) &&
+                  (rpcBestCU->getSlice()->getIsDepth() && !(rpcBestCU->getSlice()->isIRAP())) )
             { 
               bOnlyIVP = true;
@@ -1100,5 +1098,5 @@
             if( bUseIVP )
             {
-              xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bOnlyIVP );
+              xCheckRDCostIntra( rpcBestCU, rpcTempCU, intraCost, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug), bOnlyIVP );
 #else
           xCheckRDCostIntra( rpcBestCU, rpcTempCU, intraCost, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
@@ -1122,6 +1120,6 @@
             {
               Double tmpIntraCost;
-#if H_3D_DIM
-              xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN, bOnlyIVP );
+#if NH_3D_ENC_DEPTH
+              xCheckRDCostIntra( rpcBestCU, rpcTempCU, tmpIntraCost, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug), bOnlyIVP );
 #else
               xCheckRDCostIntra( rpcBestCU, rpcTempCU, tmpIntraCost, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug)   );
@@ -1135,5 +1133,5 @@
 #endif
           }
-#if H_3D
+#if NH_3D_ENC_DEPTH
           }
 #endif
@@ -2654,13 +2652,13 @@
 #endif
 
-#if H_3D_DIM
-Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize, Bool bOnlyIVP )
-#else
 Void TEncCu::xCheckRDCostIntra( TComDataCU *&rpcBestCU,
                                 TComDataCU *&rpcTempCU,
                                 Double      &cost,
                                 PartSize     eSize
-                                DEBUG_STRING_FN_DECLARE(sDebug) )
-#endif
+                                DEBUG_STRING_FN_DECLARE(sDebug)
+#if NH_3D_ENC_DEPTH
+                              , Bool bOnlyIVP
+#endif
+                              )
 {
   DEBUG_STRING_NEW(sTest)
@@ -2690,5 +2688,9 @@
   Pel resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE];
 
-  m_pcPredSearch->estIntraPredLumaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) );
+  m_pcPredSearch->estIntraPredLumaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) 
+#if NH_3D_ENC_DEPTH
+                                    , bOnlyIVP
+#endif
+                                    );
 
   m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() );
@@ -2696,9 +2698,5 @@
   if (rpcBestCU->getPic()->getChromaFormat()!=CHROMA_400)
   {
-#if H_3D_DIM
-    m_pcPredSearch->estIntraPredQT      ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma, bOnlyIVP );
-#else
     m_pcPredSearch->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) );
-#endif
   }
 #if H_3D_DIM_SDC
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCu.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncCu.h	(revision 1209)
@@ -162,7 +162,4 @@
   Void  xCheckRDCostDIS   ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize  );
 #endif
-#if H_3D_DIM
-  Void  xCheckRDCostIntra   ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bOnlyIVP );
-#else
   Void  xCheckRDCostIntra   ( TComDataCU *&rpcBestCU,
                               TComDataCU *&rpcTempCU,
@@ -170,6 +167,8 @@
                               PartSize     ePartSize
                               DEBUG_STRING_FN_DECLARE(sDebug)
+#if NH_3D_ENC_DEPTH
+                            , Bool bOnlyIVP
+#endif
                             );
-#endif
   Void  xCheckDQP           ( TComDataCU*  pcCU );
 
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 1209)
@@ -722,6 +722,6 @@
     assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
   }
-
-
+#endif
+#if H_3D_INTER_SDC
   if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx ) )
   {
@@ -730,15 +730,23 @@
     assert( pcCU->getSlice()->getIsDepth() );
   }
-
-  if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) )
+#endif
+#if NH_3D
+  if( pcCU->getSlice()->getIsDepth() )
+  {
+#if H_3D_DIM_SDC || H_3D_INTER_SDC
+    if( pcCU->getSDCFlag( uiAbsPartIdx ) )
+    {
+      m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx );
+      return;
+    }
+#endif
+#if NH_3D_DMM
+    if( pcCU->isIntra(uiAbsPartIdx) )
   {
     Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
-    UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
-    
-    if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
-    {
+      UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
       for( Int iPart = 0; iPart < iPartNum; iPart++ )
       {
-        if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) 
+        if( isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx + uiPartOffset*iPart ) ) ) 
         {
           m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart );
@@ -746,12 +754,7 @@
       }
     }
-    else
-    {
-      m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx );
-      return;
-    }
-  }
-#endif
-
+#endif
+  }
+#endif
 
   if( pcCU->isIntra(uiAbsPartIdx) )
@@ -840,10 +843,11 @@
 }
 
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+Void TEncEntropy::encodeDeltaDC  ( TComDataCU* pcCU, UInt absPartIdx )
+{
+  m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx );
+}
+#endif
 #if H_3D_INTER_SDC
-Void TEncEntropy::encodeDeltaDC  ( TComDataCU* pcCU, UInt absPartIdx )
-{
-  m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx );
-}
-
 Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
 {
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncEntropy.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncEntropy.h	(revision 1209)
@@ -84,4 +84,7 @@
   virtual Void codeMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
   virtual Void codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+  virtual Void codeDeltaDC       ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
+#endif
 #if H_3D_ARP
   virtual Void codeARPW          ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
@@ -91,5 +94,4 @@
 #endif
 #if H_3D_INTER_SDC
-  virtual Void codeDeltaDC       ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
   virtual Void codeSDCFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
 #endif
@@ -179,6 +181,8 @@
   Void encodeICFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
 #endif
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+  Void encodeDeltaDC      ( TComDataCU* pcCU, UInt absPartIdx );
+#endif
 #if H_3D_INTER_SDC
-  Void encodeDeltaDC      ( TComDataCU* pcCU, UInt absPartIdx );
   Void encodeSDCFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
 #endif
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 1209)
@@ -101,16 +101,17 @@
 , m_ChromaQpAdjFlagSCModel             ( 1,             1,                      NUM_CHROMA_QP_ADJ_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
 , m_ChromaQpAdjIdcSCModel              ( 1,             1,                      NUM_CHROMA_QP_ADJ_IDC_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)
+
+#if NH_3D_DMM
+, m_cNotDmmFlagSCModel                 ( 1,             1,                      NUM_NOTDMM_FLAG_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDmmModeSCModel                    ( 1,             1,                      NUM_DMM_MODE_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
+#if NH_3D_DMM || NH_3D_SDC
 , m_cDdcDataSCModel                    ( 1,             1,                      NUM_DDC_DATA_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
-, m_cAngleFlagSCModel                  ( 1,             1,                      NUM_ANGLE_FLAG_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
 #if H_3D_DIM_SDC                                                                                                     
 , m_cSDCResidualFlagSCModel            ( 1,             1,                      SDC_NUM_RESIDUAL_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
 , m_cSDCResidualSCModel                ( 1,             1,                      SDC_NUM_RESIDUAL_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
-#endif
-#endif
-#if H_3D_DIM_SDC
 , m_cSDCFlagSCModel                    ( 1,             1,                       NUM_SDC_FLAG_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cDdcFlagSCModel                    ( 1,             1,                      NUM_DDC_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
 #endif                                                                                                          
 #if H_3D_DBBP                                                                                                  
@@ -181,16 +182,17 @@
   m_ChromaQpAdjFlagSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG );
   m_ChromaQpAdjIdcSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_CHROMA_QP_ADJ_IDC );
-#if H_3D_DIM
-  m_cDepthIntraModeSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
-  m_cDdcFlagSCModel.initBuffer                    ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
+
+#if NH_3D_DMM
+  m_cNotDmmFlagSCModel.initBuffer                 ( eSliceType, iQp, (UChar*)INIT_NOTDMM_FLAG );
+  m_cDmmModeSCModel.initBuffer                    ( eSliceType, iQp, (UChar*)INIT_DMM_MODE );
+#endif
+#if NH_3D_DMM || NH_3D_SDC
   m_cDdcDataSCModel.initBuffer                    ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
-  m_cAngleFlagSCModel.initBuffer                  ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
+#endif
 #if H_3D_DIM_SDC                                 
   m_cSDCResidualFlagSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
   m_cSDCResidualSCModel.initBuffer                ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
-#endif                                           
-#endif                                           
-#if H_3D_DIM_SDC                                 
   m_cSDCFlagSCModel.initBuffer                    ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
+  m_cDdcFlagSCModel.initBuffer                    ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
 #endif                                           
 #if H_3D_DBBP                                    
@@ -274,12 +276,10 @@
       curCost += m_ChromaQpAdjFlagSCModel.calcCost             ( curSliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG );
       curCost += m_ChromaQpAdjIdcSCModel.calcCost              ( curSliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC );
-#if H_3D_DIM
-      if( m_pcSlice->getIntraSdcWedgeFlag() || m_pcSlice->getIntraContourFlag() )
-      {
-        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 );
-        curCost += m_cAngleFlagSCModel.calcCost         ( curSliceType, qp, (UChar*)INIT_ANGLE_FLAG );  
-      }
+#if NH_3D_DMM
+      curCost += m_cNotDmmFlagSCModel.calcCost                 ( curSliceType, qp, (UChar*)INIT_NOTDMM_FLAG );  
+      curCost += m_cDmmModeSCModel.calcCost                    ( curSliceType, qp, (UChar*)INIT_DMM_MODE );
+#endif
+#if NH_3D_DMM || NH_3D_SDC
+      curCost += m_cDdcDataSCModel.calcCost                    ( curSliceType, qp, (UChar*)INIT_DDC_DATA );
 #endif
 
@@ -308,16 +308,9 @@
   m_cCUICFlagSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_IC_FLAG );
 #endif
-#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 );
-  m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
 #if H_3D_DIM_SDC
   m_cSDCResidualFlagSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
   m_cSDCResidualSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
-#endif
-#endif
-#if H_3D_DIM_SDC
   m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
+  m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
 #endif
 #if H_3D_DBBP
@@ -530,56 +523,4 @@
   }
 }
-#if H_3D_DIM
-Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel  )
-{
-  if( uiSymbol )
-  {
-    m_pcBinIf->encodeBin( 1, rcSCModel );
-    UInt uiCount = 0;
-    Bool bNoExGo = ( uiSymbol < 3 );
-
-    while( --uiSymbol && ++uiCount < 3 )
-    {
-      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 uiNumSeg )
-{
-  xWriteExGolombLevel( UInt( abs( valDeltaDC ) - ( uiNumSeg > 1 ? 0 : 1 ) ), m_cDdcDataSCModel.get(0, 0, 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->encodeBinEP( ( uiTabIdx >> i ) & 1 );
-  }
-}
-
-#endif
-#endif
-
 // SBAC RD
 Void  TEncSbac::load ( const TEncSbac* pSrc)
@@ -601,12 +542,10 @@
 }
 
-#if H_3D_DIM
-Void TEncSbac::loadIntraDepthMode( TEncSbac* pSrc)
+#if NH_3D_DMM
+Void TEncSbac::loadIntraDepthDmm( const TEncSbac* pSrc )
 {
   m_pcBinIf->copyState( pSrc->m_pcBinIf );
-
-  this->m_cDepthIntraModeSCModel .copyFrom( &pSrc->m_cDepthIntraModeSCModel );
-  this->m_cDdcFlagSCModel        .copyFrom( &pSrc->m_cDdcFlagSCModel );
-  this->m_cAngleFlagSCModel      .copyFrom( &pSrc->m_cAngleFlagSCModel );
+  this->m_cNotDmmFlagSCModel.copyFrom( &pSrc->m_cNotDmmFlagSCModel );
+  this->m_cDmmModeSCModel   .copyFrom( &pSrc->m_cDmmModeSCModel );
 }
 #endif
@@ -1098,10 +1037,11 @@
   {
     dir[j] = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j );
-#if H_3D_DIM
+#if NH_3D_DMM
     if( pcCU->getSlice()->getIntraSdcWedgeFlag() ||  pcCU->getSlice()->getIntraContourFlag() )
     {
-      codeIntraDepth( pcCU, absPartIdx+partOffset*j );
-    }
-    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
+      xCodeIntraDepthMode( pcCU, absPartIdx+partOffset*j );
+      xCodeDmmData       ( pcCU, absPartIdx+partOffset*j );
+    }
+    if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
     {
 #endif
@@ -1118,5 +1058,5 @@
       DTRACE_CU("prev_intra_luma_pred_flag", (predIdx[j] != -1)? 1 : 0); 
 #endif
-#if H_3D_DIM
+#if NH_3D_DMM
     }
 #endif
@@ -1125,6 +1065,6 @@
   for (j=0;j<partNum;j++)
   {
-#if H_3D_DIM
-    if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
+#if NH_3D_DMM
+    if( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
     {
 #endif
@@ -1163,5 +1103,5 @@
 #endif
     }
-#if H_3D_DIM
+#if NH_3D_DMM
     }
 #endif
@@ -1206,52 +1146,4 @@
   return;
 }
-
-#if H_3D_DIM
-Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx )
-{
-  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( DMM4_IDX ): break;
-#endif
-  default: break;
-  }
-}
-
-Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx )
-{
-  UInt dir = pcCU->getLumaIntraDir( absPartIdx );
-
-  if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
-  {
-    m_pcBinIf->encodeBin( isDimMode( dir ) ? 0 : 1, m_cAngleFlagSCModel.get( 0, 0, 0 ) );
-  }
-  if( isDimMode( dir ) )
-  {
-    UInt uiCodeIdx = 0;
-
-    switch( getDimType( dir ) )
-    {
-    case DMM1_IDX: uiCodeIdx = 0; break;
-    case DMM4_IDX: uiCodeIdx = 1; break;
-    default:                      break;
-    }
-    //mode coding
-    if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag())
-    {
-      m_pcBinIf->encodeBin( uiCodeIdx == 0 ? 0 : 1, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
-    }
-  }
-}
-#endif
 
 Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx )
@@ -2595,49 +2487,157 @@
 }
 
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+Void TEncSbac::codeDeltaDC( TComDataCU* pcCU, UInt absPartIdx )
+{
+#if H_3D_DIM_SDC || H_3D_INTER_SDC
+  if( !(pcCU->getSDCFlag( absPartIdx )) )
+#endif
+#if NH_3D_DMM
+    if( !(pcCU->isIntra( absPartIdx ) && isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) )) )
+#endif
+    assert( 0 );
+
+  UInt uiNumSegments = 1;
+#if NH_3D_DMM
+  uiNumSegments = isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ) ? 2 : 1;
+#endif
+
+  UInt hasDeltaDC = 1;
+#if H_3D_DIM_SDC
+  if( pcCU->isIntra( absPartIdx ) && pcCU->getSDCFlag( absPartIdx ))
+  {
+    if( uiNumSegments == 1 )
+    {
+      hasDeltaDC = pcCU->getSDCSegmentDCOffset( 0, absPartIdx ) ? 1 : 0;
+    }
+    else
+    {
+      hasDeltaDC = ( pcCU->getSDCSegmentDCOffset( 0, absPartIdx ) || pcCU->getSDCSegmentDCOffset( 1, absPartIdx ) ) ? 1 : 0;
+    }
+    m_pcBinIf->encodeBin( hasDeltaDC, m_cDdcFlagSCModel.get( 0, 0, 0 ) );
+  }
+#endif
+
+  if( hasDeltaDC )
+  {
+    for( UInt segment = 0; segment < uiNumSegments; segment++ )
+    {
+      Pel deltaDC = 0;
+      if( pcCU->isIntra( absPartIdx ) )
+      {
+#if H_3D_DIM_SDC
+        if( pcCU->getSDCFlag( absPartIdx ) )
+        {
+          deltaDC = pcCU->getSDCSegmentDCOffset( segment, absPartIdx );
+        }
+        else
+        {
+#endif
+#if NH_3D_DMM
+        deltaDC = pcCU->getDmmDeltaDC( getDmmType( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx ) ), segment, absPartIdx );
+#endif
+#if H_3D_DIM_SDC
+        }
+#endif
+      }
 #if H_3D_INTER_SDC
-Void TEncSbac::codeDeltaDC( TComDataCU* pcCU, UInt absPartIdx )
-{
-  if( !( pcCU->getSDCFlag( absPartIdx ) || ( pcCU->isIntra( absPartIdx ) && getDimType( pcCU->getLumaIntraDir( absPartIdx ) ) < DIM_NUM_TYPE ) ) )
-  {
-    assert( 0 );
-  }
-
-  UInt uiNumSegments = isDimMode( pcCU->getLumaIntraDir( absPartIdx ) ) ? 2 : 1;
-  UInt dimDeltaDC = 1;
-
-  if( pcCU->isIntra( absPartIdx ) && pcCU->getSDCFlag( absPartIdx ))
-  {
-      if( uiNumSegments == 1 )
-      {
-        dimDeltaDC = pcCU->getSDCSegmentDCOffset( 0, absPartIdx ) ? 1 : 0;
-      }
       else
       {
-        dimDeltaDC = ( pcCU->getSDCSegmentDCOffset( 0, absPartIdx ) || pcCU->getSDCSegmentDCOffset( 1, absPartIdx ) ) ? 1 : 0;
-      }
-    m_pcBinIf->encodeBin( dimDeltaDC, m_cDdcFlagSCModel.get( 0, 0, 0 ) );
-  }
-
-  if( dimDeltaDC )
-  {
-    for( UInt segment = 0; segment < uiNumSegments; segment++ )
-    {
-      Pel deltaDC = 0;
-
-      if( pcCU->isIntra( absPartIdx ) )
-      {
-        UInt dir     = pcCU->getLumaIntraDir( absPartIdx );
-        deltaDC = pcCU->getSDCFlag( absPartIdx ) ? pcCU->getSDCSegmentDCOffset( segment, absPartIdx ) : pcCU->getDimDeltaDC( getDimType( dir ), segment, absPartIdx );
-      }
-      else
-      {
         deltaDC = pcCU->getSDCSegmentDCOffset( segment, absPartIdx );
       }
-
-      xCodeDimDeltaDC( deltaDC, uiNumSegments );
-    }
-  }
-}
-
+#endif
+      xCodeDeltaDC( deltaDC, uiNumSegments );
+    }
+  }
+}
+
+Void TEncSbac::xCodeDeltaDC( Pel valDeltaDC, UInt uiNumSeg )
+{
+  xWriteExGolombLevelDdc( UInt( abs( valDeltaDC ) - ( uiNumSeg > 1 ? 0 : 1 ) ) );
+  if( valDeltaDC != 0 )
+  {
+    UInt uiSign = valDeltaDC > 0 ? 0 : 1;
+    m_pcBinIf->encodeBinEP( uiSign );
+  }
+}
+
+Void TEncSbac::xWriteExGolombLevelDdc( UInt uiSymbol )
+{
+  if( uiSymbol )
+  {
+    m_pcBinIf->encodeBin( 1, m_cDdcDataSCModel.get(0, 0, 0) );
+    UInt uiCount = 0;
+    Bool bNoExGo = ( uiSymbol < 3 );
+
+    while( --uiSymbol && ++uiCount < 3 )
+    {
+      m_pcBinIf->encodeBin( 1, m_cDdcDataSCModel.get(0, 0, 0) );
+    }
+    if( bNoExGo )
+    {
+      m_pcBinIf->encodeBin( 0, m_cDdcDataSCModel.get(0, 0, 0) );
+    }
+    else
+    {
+      xWriteEpExGolomb( uiSymbol, 0 );
+    }
+  }
+  else
+  {
+    m_pcBinIf->encodeBin( 0, m_cDdcDataSCModel.get(0, 0, 0) );
+  }
+
+  return;
+}
+#endif
+
+#if NH_3D_DMM
+Void TEncSbac::xCodeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx )
+{
+  UInt dir = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx );
+
+  if( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() >> pcCU->getDepth( absPartIdx ) ) < 64 ) //DMM and HEVC intra modes are both allowed
+  {
+    m_pcBinIf->encodeBin( isDmmMode( dir ) ? 0 : 1, m_cNotDmmFlagSCModel.get( 0, 0, 0 ) );
+  }
+  if( isDmmMode( dir ) )
+  {
+    UInt uiCodeIdx = 0;
+
+    switch( getDmmType( dir ) )
+    {
+    case DMM1_IDX: uiCodeIdx = 0; break;
+    case DMM4_IDX: uiCodeIdx = 1; break;
+    default:                      break;
+    }
+    //mode coding
+    if( pcCU->getSlice()->getIntraSdcWedgeFlag() && pcCU->getSlice()->getIntraContourFlag())
+    {
+      m_pcBinIf->encodeBin( uiCodeIdx == 0 ? 0 : 1, m_cDmmModeSCModel.get( 0, 0, 0 ) );
+    }
+  }
+}
+
+Void TEncSbac::xCodeDmmData( TComDataCU* pcCU, UInt absPartIdx )
+{
+  UInt dir = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, absPartIdx );
+  switch( getDmmType( dir ) )
+  {
+  case( DMM1_IDX ): { xCodeDmm1WedgeIdx( pcCU->getDmm1WedgeTabIdx( absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); } break;
+  case( DMM4_IDX ): break;
+  default:          break;
+  }
+}
+
+Void TEncSbac::xCodeDmm1WedgeIdx( UInt uiTabIdx, Int iNumBit )
+{
+  for ( Int i = 0; i < iNumBit; i++ )
+  {
+    m_pcBinIf->encodeBinEP( ( uiTabIdx >> i ) & 1 );
+  }
+}
+#endif
+
+#if H_3D_INTER_SDC
 Void TEncSbac::codeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
 {
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSbac.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSbac.h	(revision 1209)
@@ -80,6 +80,6 @@
   Void  load                   ( const TEncSbac* pSrc  );
   Void  loadIntraDirMode       ( const TEncSbac* pScr, const ChannelType chType  );
-#if H_3D_DIM
-  Void  loadIntraDepthMode     ( TEncSbac* pScr  );
+#if NH_3D_DMM
+  Void  loadIntraDepthDmm      ( const TEncSbac* pSrc );
 #endif
   Void  store                  ( TEncSbac* pDest ) const;
@@ -115,11 +115,14 @@
   Void  xWriteEpExGolomb     ( UInt uiSymbol, UInt uiCount );
   Void  xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange );
-#if H_3D_DIM
-  Void  xWriteExGolombLevel  ( UInt uiSymbol, ContextModel& rcSCModel  );
-  Void  xCodeDimDeltaDC      ( Pel valDeltaDC, UInt uiNumSeg );
-#if H_3D_DIM_DMM
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+  Void  xWriteExGolombLevelDdc( UInt uiSymbol );
+  Void  xCodeDeltaDC         ( Pel valDeltaDC, UInt uiNumSeg );
+#endif
+#if NH_3D_DMM
+  Void  xCodeIntraDepthMode  ( TComDataCU* pcCU, UInt absPartIdx );
+  Void  xCodeDmmData         ( TComDataCU* pcCU, UInt absPartIdx );
   Void  xCodeDmm1WedgeIdx    ( UInt uiTabIdx, Int iNumBit );
 #endif
-#endif
+
 
   Void  xCopyFrom            ( const TEncSbac* pSrc );
@@ -146,6 +149,8 @@
   Void codeICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx );
 #endif
+#if NH_3D_DMM || H_3D_DIM_SDC || H_3D_INTER_SDC
+  Void  codeDeltaDC      ( TComDataCU* pcCU, UInt absPartIdx );
+#endif
 #if H_3D_INTER_SDC
-  Void codeDeltaDC       ( TComDataCU* pcCU, UInt absPartIdx );
   Void codeSDCFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx );
 #endif
@@ -165,12 +170,5 @@
   Void codeQtRootCbfZero       ( );
   Void codeIntraDirLumaAng     ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple);
-
   Void codeIntraDirChroma      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
-
-#if H_3D_DIM
-  Void codeIntraDepth          ( TComDataCU* pcCU, UInt absPartIdx );
-  Void codeIntraDepthMode      ( TComDataCU* pcCU, UInt absPartIdx );
-#endif
-
   Void codeInterDir            ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeRefFrmIdx           ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
@@ -249,16 +247,17 @@
   ContextModel3DBuffer m_ChromaQpAdjFlagSCModel;
   ContextModel3DBuffer m_ChromaQpAdjIdcSCModel;
-#if H_3D_DIM
-  ContextModel3DBuffer m_cDepthIntraModeSCModel;
-  ContextModel3DBuffer m_cDdcFlagSCModel;
+
+#if NH_3D_DMM
+  ContextModel3DBuffer m_cNotDmmFlagSCModel;
+  ContextModel3DBuffer m_cDmmModeSCModel;
+#endif
+#if NH_3D_DMM || NH_3D_SDC
   ContextModel3DBuffer m_cDdcDataSCModel;
-  ContextModel3DBuffer m_cAngleFlagSCModel;
+#endif
 #if H_3D_DIM_SDC  
   ContextModel3DBuffer m_cSDCResidualFlagSCModel;
   ContextModel3DBuffer m_cSDCResidualSCModel;
-#endif
-#endif
-#if H_3D_DIM_SDC
   ContextModel3DBuffer m_cSDCFlagSCModel;
+  ContextModel3DBuffer m_cDdcFlagSCModel;
 #endif
 #if H_3D_DBBP
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1209)
@@ -1053,5 +1053,5 @@
 #if H_3D_DIM_SDC
           m_pcEntropyCoder->encodeSDCFlag( pcCU, 0, true );
-          if( pcCU->getSlice()->getIsDepth() && ( !pcCU->getSDCFlag( 0 ) ) && getDimType( pcCU->getLumaIntraDir( 0 ) ) < DIM_NUM_TYPE ) 
+          if( pcCU->getSlice()->getIsDepth() && ( !pcCU->getSDCFlag( 0 ) ) && isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, 0 ) ) ) 
           {
             m_pcEntropyCoder->encodeDeltaDC( pcCU, 0 );
@@ -1071,5 +1071,5 @@
           for( UInt uiPart = 0; uiPart < 4; uiPart++ )
           {
-            if( pcCU->getSlice()->getIsDepth() && ( !pcCU->getSDCFlag( uiPart * uiQNumParts ) ) && getDimType( pcCU->getLumaIntraDir( uiPart * uiQNumParts ) ) < DIM_NUM_TYPE ) 
+            if( pcCU->getSlice()->getIsDepth() && ( !pcCU->getSDCFlag( uiPart * uiQNumParts ) ) && isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiPart * uiQNumParts ) ) ) 
             {
               m_pcEntropyCoder->encodeDeltaDC( pcCU, uiPart * uiQNumParts );
@@ -1081,5 +1081,5 @@
             m_pcEntropyCoder->encodeSDCFlag( pcCU, 0, true );
           }
-          if( pcCU->getSlice()->getIsDepth() && ( !pcCU->getSDCFlag( uiAbsPartIdx ) ) && getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx ) ) < DIM_NUM_TYPE ) 
+          if( pcCU->getSlice()->getIsDepth() && ( !pcCU->getSDCFlag( uiAbsPartIdx ) ) && isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx ) ) ) 
           {
             m_pcEntropyCoder->encodeDeltaDC( pcCU, uiAbsPartIdx );
@@ -1168,6 +1168,6 @@
                                       DEBUG_STRING_FN_DECLARE(sDebug)
                                            ,Int         default0Save1Load2
-#if H_3D_DIM_ENC
-                                , Bool       zeroResi
+#if NH_3D_ENC_DEPTH
+                                          , Bool        zeroResiFlag
 #endif
 
@@ -1244,15 +1244,14 @@
 
     //===== get prediction signal =====
-#if H_3D_DIM
-    if( isDimMode( uiLumaPredMode ) )
-    {
-      predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, true );
+#if NH_3D_DMM
+    if( bIsLuma && isDmmMode( uiChFinalMode ) )
+    {
+      predIntraLumaDmm( pcCU, uiAbsPartIdx, getDmmType( uiChFinalMode ), piPred, uiStride, uiWidth, uiHeight );
     }
     else
     {
 #endif
-
     predIntraAng( compID, uiChFinalMode, piOrg, uiStride, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
-#if H_3D_DIM
+#if NH_3D_DMM
     }
 #endif
@@ -1301,6 +1300,6 @@
     for( UInt uiY = 0; uiY < uiHeight; uiY++ )
     {
-#if H_3D_DIM_ENC
-      if( zeroResi )
+#if NH_3D_ENC_DEPTH
+      if( zeroResiFlag )
       {
         memset( pResi, 0, sizeof( Pel ) * uiWidth );
@@ -1318,5 +1317,5 @@
       pResi += uiStride;
       pPred += uiStride;
-#if H_3D_DIM_ENC
+#if NH_3D_ENC_DEPTH
       }
 #endif
@@ -1492,9 +1491,4 @@
     ruiDist += m_pcRdCost->getDistPart( bitDepth, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, compID );
 }
-#if H_3D_DIM
-    mapDepthModeToIntraDir( uiChromaPredMode );
-#endif
-
-
 
 
@@ -1514,8 +1508,9 @@
                                     Double&     dRDCost,
                                     TComTU&     rTu
-#if H_3D_DIM_ENC
-                                , Bool        zeroResi
+                                    DEBUG_STRING_FN_DECLARE(sDebug)
+#if NH_3D_ENC_DEPTH
+                                  , Bool        zeroResiFlag
 #endif                                
-                                    DEBUG_STRING_FN_DECLARE(sDebug))
+                                  )
 {
   TComDataCU   *pcCU          = rTu.getCU();
@@ -1568,6 +1563,6 @@
   }
 #endif
-#if H_3D_DIM
-  if( isDimMode( pcCU->getLumaIntraDir( uiAbsPartIdx ) ) )
+#if NH_3D_DMM
+  if( isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx ) ) )
   {
     bCheckSplit = false;
@@ -1712,6 +1707,6 @@
         pcCU ->setTransformSkipSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, totalAdjustedDepthChan );
       }
-#if H_3D_DIM_ENC
-      xIntraCodingLumaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistY, 0, zeroResi );
+#if NH_3D_ENC_DEPTH
+      xIntraCodingTUBlock( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaSingle, false, uiSingleDistLuma, COMPONENT_Y, rTu DEBUG_STRING_PASS_INTO(sDebug), zeroResiFlag );
 #else
       xIntraCodingTUBlock( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaSingle, false, uiSingleDistLuma, COMPONENT_Y, rTu DEBUG_STRING_PASS_INTO(sDebug));
@@ -1982,4 +1977,145 @@
 Void TEncSearch::xIntraCodingSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, Bool bZeroResidual, Int iSDCDeltaResi  )
 {
+#if TEMP_SDC_CLEANUP // PM: consider this cleanup for DMM and SDC
+  Bool bAboveAvail    = false;
+  Bool bLeftAvail     = false;
+  UInt uiWidth        = pcCU->getWidth ( 0 );
+  UInt uiHeight       = pcCU->getHeight( 0 );
+  UInt uiLumaPredMode = pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx );
+
+  UInt sdcDepth = 0;
+  UInt uiStride;         
+  Pel* piOrg;          
+  Pel* piPred;          
+  Pel* piReco;        
+
+  UInt uiZOrder;         
+  Pel* piRecIPred;       
+  UInt uiRecIPredStride; 
+
+  Pel apDCPredValues[2];
+  Pel apDCOrigValues[2];
+  UInt uiNumSegments;
+
+  Bool* pbMask = NULL;
+  UInt uiMaskStride = 0;
+#if NH_3D_DMM
+  TComWedgelet* dmm4Segmentation = NULL;
+  if( isDmmMode( uiLumaPredMode ) )
+  {
+    assert( uiWidth == uiHeight  );
+    assert( uiWidth >= DMM_MIN_SIZE && uiWidth <= DMM_MAX_SIZE );
+    assert( !(( uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) > 1) );
+
+    uiNumSegments     = 2;
+
+    uiStride          = pcOrgYuv ->getStride( COMPONENT_Y );
+    piOrg             = pcOrgYuv ->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
+    piPred            = pcPredYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
+    piReco            = pcPredYuv->getAddr  ( COMPONENT_Y, uiAbsPartIdx );
+
+    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getAddr  ( COMPONENT_Y, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
+    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride( COMPONENT_Y );
+
+    //===== init availability pattern =====
+#if !TEMP_SDC_CLEANUP // PM: please migrate together with below "initPattern" and remove macro
+    pcCU->getPattern()->initPattern   ( pcCU, sdcDepth, uiAbsPartIdx );
+    pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, sdcDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail );
+#endif
+
+    // get partition
+    pbMask       = new Bool[ uiWidth*uiHeight ];
+    uiMaskStride = uiWidth;
+    switch( getDmmType( uiLumaPredMode ) )
+    {
+    case( DMM1_IDX ): { (getWedgeListScaled( uiWidth )->at( pcCU->getDmm1WedgeTabIdx( uiAbsPartIdx ) )).getPatternScaledCopy( uiWidth, pbMask ); } break;
+    case( DMM4_IDX ): { predContourFromTex( pcCU, uiAbsPartIdx, uiWidth, uiHeight, pbMask );                                                     } break;
+    default: assert(0);
+    }
+
+    // get predicted partition values
+    Pel predDC1 = 0, predDC2 = 0;
+    predBiSegDCs( pcCU, uiAbsPartIdx, uiWidth, uiHeight, pbMask, uiMaskStride, predDC1, predDC2 );
+
+    // set prediction signal
+    Pel* pDst = piPred;
+    assignBiSegDCs( pDst, uiStride, pbMask, uiMaskStride, predDC1, predDC2 );
+    apDCPredValues[0] = predDC1;
+    apDCPredValues[1] = predDC2;
+
+    // get original partition values
+    xCalcBiSegDCs( piOrg, uiStride, pbMask, uiMaskStride, apDCOrigValues[0], apDCOrigValues[1], 0, (uiMaskStride > 16) );
+  }
+  else // regular HEVC intra modes
+  {
+#endif
+    uiNumSegments = 1;
+
+    UInt numParts = 1;
+    UInt uiSubPartIdx = uiAbsPartIdx;
+
+    if( ( uiWidth >> pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) > 1 )
+    {
+      numParts = uiWidth * uiWidth >> ( 2 * pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() );
+      sdcDepth = g_aucConvertToBit[uiWidth] + 2 - pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
+      uiWidth = uiHeight = ( 1 << pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() );
+    }
+
+    for ( Int i = 0; i < numParts; i++ )
+    {
+      uiStride          = pcOrgYuv ->getStride  ();
+      piOrg             = pcOrgYuv ->getLumaAddr( uiSubPartIdx );
+      piPred            = pcPredYuv->getLumaAddr( uiSubPartIdx );
+      piReco            = pcPredYuv->getLumaAddr( uiSubPartIdx );
+
+      uiZOrder          = pcCU->getZorderIdxInCU() + uiSubPartIdx;
+      piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
+      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
+
+      AOF( uiWidth == uiHeight );
+
+      //===== init availability pattern =====
+      pcCU->getPattern()->initPattern   ( pcCU, sdcDepth, uiSubPartIdx );
+      pcCU->getPattern()->initAdiPattern( pcCU, uiSubPartIdx, sdcDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail );
+
+      predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
+
+      if ( numParts > 1 )
+      {
+        for( UInt uiY = 0; uiY < uiHeight; uiY++ )
+        {
+          for( UInt uiX = 0; uiX < uiWidth; uiX++ )
+          {
+            piPred        [ uiX ] = ClipY( piPred[ uiX ] );
+            piRecIPred    [ uiX ] = piPred[ uiX ];
+          }
+          piPred     += uiStride;
+          piRecIPred += uiRecIPredStride;
+        }
+      }
+
+      uiSubPartIdx += ( ( uiWidth * uiWidth ) >> 4 );
+    }
+
+    // reset to full block
+    uiWidth  = pcCU->getWidth( 0 );
+    uiHeight = pcCU->getHeight( 0 );
+
+    uiStride          = pcOrgYuv ->getStride  ();
+    piOrg             = pcOrgYuv ->getLumaAddr( uiAbsPartIdx );
+    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
+    piReco            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
+
+    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
+    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
+    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
+
+    // get predicted and original DC
+    predConstantSDC( piPred, uiStride, uiWidth, apDCPredValues[0] ); apDCPredValues[1] = 0;
+    xCalcConstantSDC( piOrg, uiStride, uiWidth, apDCOrigValues[0] ); apDCOrigValues[1] = 0;
+#if NH_3D_DMM  
+  }
+#endif
+#else
   UInt    uiLumaPredMode    = pcCU     ->getLumaIntraDir( uiAbsPartIdx );
   UInt    uiWidth           = pcCU     ->getWidth   ( 0 );
@@ -2024,7 +2160,7 @@
     TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
     //===== get prediction signal =====
-    if( isDimMode( uiLumaPredMode ) )
-    {
-      UInt dimType   = getDimType  ( uiLumaPredMode );
+    if( isDmmMode( uiLumaPredMode ) )
+    {
+      UInt dimType   = getDmmType  ( uiLumaPredMode );
       UInt patternID = pcCU->getDmmWedgeTabIdx(dimType, uiAbsPartIdx);
       UInt uiBaseWidth = pcCU->isDMM1UpscaleMode(uiWidth) ? pcCU->getDMM1BasePatternWidth(uiWidth) : uiWidth;
@@ -2089,5 +2225,5 @@
   UInt uiMaskStride = 0;
 
-  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
+  if( getDmmType( uiLumaPredMode ) == DMM1_IDX )
   {
     Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
@@ -2100,5 +2236,5 @@
     uiMaskStride = pcCU->isDMM1UpscaleMode( uiWidth ) ? uiWidth : pcWedgelet->getStride();
   }
-  if( getDimType( uiLumaPredMode ) == DMM4_IDX )
+  if( getDmmType( uiLumaPredMode ) == DMM4_IDX )
   {
     uiNumSegments = 2;
@@ -2109,5 +2245,5 @@
   // get DC prediction for each segment
   Pel apDCPredValues[2];
-  if ( getDimType( uiLumaPredMode ) == DMM1_IDX || getDimType( uiLumaPredMode ) == DMM4_IDX )
+  if ( getDmmType( uiLumaPredMode ) == DMM1_IDX || getDmmType( uiLumaPredMode ) == DMM4_IDX )
   {
     apDCPredValues[0] = pcCU->getDmmPredictor( 0 );
@@ -2123,4 +2259,5 @@
   Pel apDCOrigValues[2];
   analyzeSegmentsSDC(piOrg, uiStride, uiWidth, apDCOrigValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode, true );
+#endif
 
   for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
@@ -2203,4 +2340,10 @@
   }
 
+#if TEMP_SDC_CLEANUP // PM: consider this cleanup for DMM and SDC
+#if NH_3D_DMM
+  if( pbMask ) { delete[] pbMask; }
+#endif
+#endif
+
   //===== determine distortion =====
 #if H_3D_VSO
@@ -2229,7 +2372,5 @@
   // encode pred direction + DC residual data
   m_pcEntropyCoder->encodePredInfo( pcCU, 0, true );
-#if H_3D_DIM_SDC
   m_pcEntropyCoder->encodeSDCFlag( pcCU, 0, true );
-#endif
 
   Bool bDummy = false;
@@ -2243,5 +2384,7 @@
 #endif
     dRDCost = m_pcRdCost->calcRdCost( uiBits, ruiDist );
+#if !TEMP_SDC_CLEANUP // PM: should be obsolete after cleanup
   dmm4SegmentationOrg->destroy(); delete dmm4SegmentationOrg;
+#endif
 }
 #endif
@@ -2789,9 +2932,9 @@
                                TComYuv*    pcRecoYuv,
                                Pel         resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE]
-#if H_3D_DIM
+                               DEBUG_STRING_FN_DECLARE(sDebug)
+#if NH_3D_ENC_DEPTH
                              , Bool        bOnlyIVP
 #endif
-
-                               DEBUG_STRING_FN_DECLARE(sDebug))
+                              )
 {
   const UInt         uiDepth               = pcCU->getDepth(0);
@@ -2865,5 +3008,5 @@
       initIntraPatternChType( tuRecurseWithPU, bAboveAvail, bLeftAvail, COMPONENT_Y, true DEBUG_STRING_PASS_INTO(sTemp2) );
     }
-#if H_3D_DIM
+#if NH_3D_ENC_DEPTH
     if( bOnlyIVP )
     {
@@ -2987,121 +3130,87 @@
       }
     }
-#if H_3D_DIM
-    }
-#endif
-
-#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( bOnlyIVP )
-      {
-        TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
-        xPredContourFromTex( pcCU, uiPartOffset, uiWidth, uiHeight, dmm4Segmentation );
-
-        Pel deltaDC1 = 0; Pel deltaDC2 = 0;
-        xSearchDmmDeltaDCs( pcCU, uiPartOffset, piOrg, piPred, uiStride, dmm4Segmentation->getPattern(), dmm4Segmentation->getStride(), uiWidth, uiHeight, deltaDC1, deltaDC2 );
-        pcCU->setDimDeltaDC( DMM4_IDX, 0, uiPartOffset, deltaDC1 );
-        pcCU->setDimDeltaDC( DMM4_IDX, 1, uiPartOffset, deltaDC2 );
-
-        uiRdModeList[ numModesForFullRD++ ] = (DMM4_IDX+DIM_OFFSET);
-        dmm4Segmentation->destroy(); delete dmm4Segmentation;
-      }
-      else
-      {
-#if H_3D_FAST_DEPTH_INTRA
-        Int  threshold    = max(((pcCU->getQP(0))>>3)-1,3);
-        Int  varThreshold = (Int)( threshold * threshold - 8 );
-        UInt varCU      = m_pcRdCost->calcVAR(piOrg, uiStride, uiWidth,uiHeight,pcCU->getDepth(0));
-#endif
-
-#if H_3D_DIM_DMM
-        if( ( ( m_pcEncCfg->getUseDMM() &&  pcCU->getSlice()->getIntraSdcWedgeFlag() )  || pcCU->getSlice()->getIntraContourFlag() )
-#if H_3D_FAST_DEPTH_INTRA
-          && (uiRdModeList[0] != PLANAR_IDX || varCU >= varThreshold)
-#endif
-          )
-        {
-          UInt uiStart, uiEnd;
-          if( ( m_pcEncCfg->getUseDMM() &&  pcCU->getSlice()->getIntraSdcWedgeFlag() ) &&  pcCU->getSlice()->getIntraContourFlag() )
+#if NH_3D_ENC_DEPTH
+    }
+#endif
+
+#if NH_3D_DMM
+    if( m_pcEncCfg->getIsDepth() )
+    {
+      const TComRectangle &puRect=tuRecurseWithPU.getRect(COMPONENT_Y);
+      const UInt uiAbsPartIdx=tuRecurseWithPU.GetAbsPartIdxTU();
+
+      Pel* piOrg         = pcOrgYuv ->getAddr( COMPONENT_Y, uiAbsPartIdx );
+      Pel* piPred        = pcPredYuv->getAddr( COMPONENT_Y, uiAbsPartIdx );
+      UInt uiStride      = pcPredYuv->getStride( COMPONENT_Y );
+
+      if( puRect.width >= DMM_MIN_SIZE && puRect.width <= DMM_MAX_SIZE &&  puRect.width == puRect.height &&
+          ((m_pcEncCfg->getUseDMM() &&  pcCU->getSlice()->getIntraSdcWedgeFlag()) || pcCU->getSlice()->getIntraContourFlag()) )
+      {
+#if NH_3D_ENC_DEPTH
+        if( bOnlyIVP )
+        {
+          Bool* dmm4Pattern   = new Bool[ puRect.width*puRect.height ];
+          UInt  patternStride = puRect.width;
+          predContourFromTex( pcCU, uiPartOffset, puRect.width, puRect.height, dmm4Pattern );
+
+          Pel deltaDC1 = 0; Pel deltaDC2 = 0;
+          xSearchDmmDeltaDCs( pcCU, uiPartOffset, piOrg, piPred, uiStride, dmm4Pattern, patternStride, puRect.width, puRect.height, deltaDC1, deltaDC2 );
+          pcCU->setDmmDeltaDC( DMM4_IDX, 0, uiPartOffset, deltaDC1 );
+          pcCU->setDmmDeltaDC( DMM4_IDX, 1, uiPartOffset, deltaDC2 );
+
+          uiRdModeList[ numModesForFullRD++ ] = (DMM4_IDX+DMM_OFFSET);
+          delete[] dmm4Pattern;
+        }
+        else
+        {
+          Int  threshold    = max(((pcCU->getQP(0))>>3)-1,3);
+          Int  varThreshold = (Int)( threshold * threshold - 8 );
+          UInt varCU        = m_pcRdCost->calcVAR( piOrg, uiStride, puRect.width, puRect.height, pcCU->getDepth(0), pcCU->getSlice()->getSPS()->getMaxCUWidth() );
+          if( uiRdModeList[0] != PLANAR_IDX || varCU >= varThreshold )
           {
-            uiStart = 0;
-            uiEnd   = 2;
+#endif
+            UInt startIdx = ( m_pcEncCfg->getUseDMM() &&  pcCU->getSlice()->getIntraSdcWedgeFlag() ) ? 0 : 1;
+            UInt endIdx   = (                             pcCU->getSlice()->getIntraContourFlag()  ) ? 1 : 0;
+            for( UInt dmmType = startIdx; dmmType <= endIdx; dmmType++ )
+            {
+#if H_3D_FCO
+              if ( !(pcCU->getSlice()->getIvPic(false, pcCU->getSlice()->getViewIndex() )->getReconMark()) && (DMM4_IDX == dmmType ) ) { continue; }
+#endif
+              Bool* biSegPattern  = new Bool[ puRect.width*puRect.height ];
+              UInt  patternStride = puRect.width;
+              Pel deltaDC1 = 0; Pel deltaDC2 = 0;
+              switch( dmmType )
+              {
+              case( DMM1_IDX ):
+                {
+                  UInt uiTabIdx = 0;
+                  xSearchDmm1Wedge( pcCU, uiPartOffset, piOrg, uiStride, puRect.width, puRect.height, uiTabIdx );
+                  pcCU->setDmm1WedgeTabIdxSubParts( uiTabIdx,  uiPartOffset, uiDepth + uiInitTrDepth );
+                  (getWedgeListScaled( puRect.width )->at( pcCU->getDmm1WedgeTabIdx( uiAbsPartIdx ) )).getPatternScaledCopy( puRect.width, biSegPattern );
+                } break;
+              case( DMM4_IDX ):
+                {
+                  predContourFromTex( pcCU, uiPartOffset, puRect.width, puRect.height, biSegPattern );
+                } break;
+              default: assert(0);
+              }
+
+              if( biSegPattern )
+              {
+                xSearchDmmDeltaDCs( pcCU, uiPartOffset, piOrg, piPred, uiStride, biSegPattern, patternStride, puRect.width, puRect.height, deltaDC1, deltaDC2 );
+                pcCU->setDmmDeltaDC( (DmmID)dmmType, 0, uiPartOffset, deltaDC1 );
+                pcCU->setDmmDeltaDC( (DmmID)dmmType, 1, uiPartOffset, deltaDC2 );
+  
+                uiRdModeList[ numModesForFullRD++ ] = (dmmType+DMM_OFFSET);
+                delete[] biSegPattern;
+              }
+            }
+#if NH_3D_ENC_DEPTH
           }
-          else if( ( m_pcEncCfg->getUseDMM() &&  pcCU->getSlice()->getIntraSdcWedgeFlag() ) )
-          {
-            uiStart = 0;
-            uiEnd   = 1;
-          }
-          else if( pcCU->getSlice()->getIntraContourFlag() )
-          {
-            uiStart = 1;
-            uiEnd   = 2;
-          }
-          else
-          {
-            uiStart = 0;
-            uiEnd   = 0;
-          }
-          for( UInt dmmType = uiStart; dmmType < uiEnd; dmmType++ )
-          {
-#if H_3D_FCO
-            TComPic* picTexture  = pcCU->getSlice()->getIvPic(false, pcCU->getSlice()->getViewIndex() );
-#if H_3D_FCO
-            if ( !picTexture->getReconMark() && (DMM4_IDX == dmmType ) )
-#else
-            if ( !picTexture->getReconMark() && (DMM3_IDX == dmmType || DMM4_IDX == dmmType ) )
-#endif
-            {
-              continue;
-            }
-#endif
-            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 = pcCU->isDMM1UpscaleMode( uiWidth ) ? 
-                  &(g_dmmWedgeLists[(g_aucConvertToBit[pcCU->getDMM1BasePatternWidth(uiWidth)])][uiTabIdx]) : &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
-              } break;
-
-            case( DMM4_IDX ):
-              {
-                {
-                  biSegmentation = new TComWedgelet( uiWidth, uiHeight );
-                  xPredContourFromTex( pcCU, uiPartOffset, uiWidth, uiHeight, biSegmentation );
-                }
-              } break;
-            default: assert(0);
-            }
-
-            if( biSegmentation )
-            {
-              if( dmmType == DMM1_IDX && pcCU->isDMM1UpscaleMode( uiWidth ) ){
-                xSearchDmmDeltaDCs( pcCU, uiPartOffset, piOrg, piPred, uiStride, biSegmentation->getScaledPattern(uiWidth), uiWidth, uiWidth, uiHeight, deltaDC1, deltaDC2 );
-              } 
-              else
-              {
-                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++ ] = (dmmType  +DIM_OFFSET);
-              if( DMM4_IDX == dmmType ) { biSegmentation->destroy(); delete biSegmentation; }
-            }
-          }
-        }
-#if H_3D_DIM
-      }
-#endif
-#endif
-    }
-#endif
-
+        }
+#endif
+      }
+    }
+#endif
 
     //===== check modes (using r-d costs) =====
@@ -3226,12 +3335,8 @@
           }
 #endif
-#if H_3D_DIM_ENC || H_3D_DIM_SDC
-          Bool bTestZeroResi = false;
-#if H_3D_DIM_ENC
-          bTestZeroResi |= pcCU->getSlice()->getIsDepth() && !pcCU->getSlice()->isIRAP();
-#endif
+#if NH_3D_ENC_DEPTH
+          UInt zeroResiTest = (pcCU->getSlice()->getIsDepth() && !pcCU->getSlice()->isIRAP()) ? 1 : 0;
 #if H_3D_DIM_SDC
           bTestZeroResi |= pcCU->getSDCFlag(uiPartOffset);
-#endif
           if( uiSDC != 0 && iSDCDeltaResi != 0 )
           {
@@ -3239,10 +3344,7 @@
           }
 #endif
-
-#if H_3D_DIM_ENC || H_3D_DIM_SDC      
-          for( UInt testZeroResi = 0; testZeroResi <= (bTestZeroResi ? 1 : 0) ; testZeroResi++ )
+          for( UInt zeroResi = 0; zeroResi <= zeroResiTest; zeroResi++ )
           {
 #endif
-
       DEBUG_STRING_NEW(sMode)
       // set context models
@@ -3280,6 +3382,6 @@
 
 #if HHI_RQT_INTRA_SPEEDUP
-#if H_3D_DIM_ENC
-              xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost, (testZeroResi != 0) );
+#if NH_3D_ENC_DEPTH
+      xRecurIntraCodingLumaQT( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaPU, uiPUDistY, true, dPUCost, tuRecurseWithPU DEBUG_STRING_PASS_INTO(sMode), (zeroResi != 0) );
 #if H_3D_FAST_INTRA_SDC    
               if( dPUCost < dBestPUCostConv )
@@ -3295,6 +3397,6 @@
 #endif
 #else
-#if H_3D_DIM_ENC
-              xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost, (testZeroResi != 0) );
+#if NH_3D_ENC_DEPTH
+      xRecurIntraCodingLumaQT( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaPU, uiPUDistY, dPUCost, tuRecurseWithPU DEBUG_STRING_PASS_INTO(sMode), (zeroResi != 0) );
 #else
       xRecurIntraCodingLumaQT( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaPU, uiPUDistY, dPUCost, tuRecurseWithPU DEBUG_STRING_PASS_INTO(sMode) );
@@ -3374,9 +3476,9 @@
       }
 #endif
-#if H_3D_DIM_ENC || H_3D_DIM_SDC
+#if NH_3D_ENC_DEPTH
           }
+#endif
+#if H_3D_DIM_SDC
         } // SDC residual loop
-#endif
-#if H_3D_DIM_SDC
       } // SDC loop
 #endif
@@ -7017,6 +7119,9 @@
   // Reload only contexts required for coding intra mode information
   m_pcRDGoOnSbacCoder->loadIntraDirMode( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST], chType );
-#if H_3D_DIM
-    m_pcRDGoOnSbacCoder->loadIntraDepthMode( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
+#if NH_3D_DMM
+  if( pcCU->getSlice()->getIsDepth() && isLuma(chType) )
+  {
+    m_pcRDGoOnSbacCoder->loadIntraDepthDmm( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
+  }
 #endif
 
@@ -7401,53 +7506,37 @@
 }
 
-#if H_3D_DIM
+#if NH_3D_DMM
   // -------------------------------------------------------------------------------------------------------------------
   // Depth intra search
   // -------------------------------------------------------------------------------------------------------------------
-Void TEncSearch::xCalcBiSegDCs( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2 )
+Void TEncSearch::xCalcBiSegDCs( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2, Pel defaultVal, Bool subSamp )
 {
-  valDC1 = ( 1<<( g_bitDepthY - 1) );
-  valDC2 = ( 1<<( g_bitDepthY - 1) );
+  valDC1 = defaultVal;
+  valDC2 = defaultVal;
 
   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];
+  
+  Int subSamplePix = subSamp ? 2 : 1;
+
+  Pel* piTemp = ptrSrc;
+  for( UInt uiY = 0; uiY < patternStride; uiY += subSamplePix )
+  {
+    for( UInt uiX = 0; uiX < patternStride; uiX += subSamplePix )
+    {
+      if( true == biSegPattern[uiX] ) 
+      {
+        uiDC2 += piTemp[uiX];
         uiNumPixDC2++;
       }
       else
       {
-        uiDC1 += ptrSrc[k];
+        uiDC1 += piTemp[uiX];
         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;
-    }
+    piTemp       += subSamplePix*srcStride;
+    biSegPattern += subSamplePix*patternStride;
   }
 
@@ -7456,22 +7545,20 @@
 }
 
-#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 );
+  Int bitDepthY = pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA);
+
   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;
+  xCalcBiSegDCs  ( piOrig,   uiStride, biSegPattern, patternStride, origDC1, origDC2, (1<<(bitDepthY-1)) );
+  assignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, origDC1, origDC2 );
+
   Pel  predDC1 = 0; Pel predDC2 = 0;
-  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
+  predBiSegDCs( pcCU, uiAbsPtIdx, uiWidth, uiHeight, biSegPattern, patternStride, predDC1, predDC2 );
 
   rDeltaDC1 = origDC1 - predDC1;
   rDeltaDC2 = origDC2 - predDC2;
 
-#if H_3D_VSO
+#if NH_3D_VSO
   if( m_pcRdCost->getUseVSO() )
   {
@@ -7492,20 +7579,20 @@
     // 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( fullDeltaDC1 >= 0 && uiDeltaDC1Max > ((1<<bitDepthY)-1) - abs(predDC1) ) { uiDeltaDC1Max = ((1<<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); }
+    if( fullDeltaDC2 >= 0 && uiDeltaDC2Max > ((1<<bitDepthY)-1) - abs(predDC2) ) { uiDeltaDC2Max = ((1<<bitDepthY)-1) - abs(predDC2); }
 
     // init dist with original segment DCs
-    xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, origDC1, origDC2 );
+    assignBiSegDCs( 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 );
+      uiOrgDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, bitDepthY, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
     }
     else
     {
-      uiOrgDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+      uiOrgDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, bitDepthY, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
     }
 
@@ -7517,19 +7604,18 @@
     for( UInt uiQStepDC1 = 0; uiQStepDC1 < uiDeltaDC1Max; uiQStepDC1 += 4 )
     {
-      Pel testDC1 = ClipY( predDC1 + ((Int)(uiQStepDC1) * (( fullDeltaDC1 < 0 ) ? -1 : 1)) );
+      Pel testDC1 = ClipBD( predDC1 + ((Int)(uiQStepDC1) * (( fullDeltaDC1 < 0 ) ? -1 : 1)), bitDepthY );
       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 );
+        Pel testDC2 = ClipBD( predDC2 + ((Int)(uiQStepDC2) * (( fullDeltaDC2 < 0 ) ? -1 : 1)), bitDepthY );
+        assignBiSegDCs( 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 );
+          uiAct4Dist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, bitDepthY, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
         }
         else
         {
-          uiAct4Dist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+          uiAct4Dist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, bitDepthY, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
         }
 
@@ -7546,19 +7632,18 @@
     for( UInt uiQStepDC1 = (UInt)max(0, ((Int)uiBestQStepDC1-3)); uiQStepDC1 <= (uiBestQStepDC1+3); uiQStepDC1++ )
     {
-      Pel testDC1 = ClipY( predDC1 + ((Int)(uiQStepDC1) * (( fullDeltaDC1 < 0 ) ? -1 : 1)) );
+      Pel testDC1 = ClipBD( predDC1 + ((Int)(uiQStepDC1) * (( fullDeltaDC1 < 0 ) ? -1 : 1)), bitDepthY );
       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 );
+        Pel testDC2 = ClipBD( predDC2 + ((Int)(uiQStepDC2) * (( fullDeltaDC2 < 0 ) ? -1 : 1)), bitDepthY );
+        assignBiSegDCs( 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 );
+          uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, bitDepthY, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
         }
         else
         {
-          uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
+          uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, bitDepthY, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false );
         }
 
@@ -7577,6 +7662,6 @@
 
 #if H_3D_DIM_DLT
-  rDeltaDC1 = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipY(predDC1 + rDeltaDC1) ) - pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 );
-  rDeltaDC2 = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipY(predDC2 + rDeltaDC2) ) - pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 );
+  rDeltaDC1 = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipBD(predDC1 + rDeltaDC1), bitDepthY ) - pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 );
+  rDeltaDC2 = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipBD(predDC2 + rDeltaDC2), bitDepthY ) - pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 );
 #endif
 }
@@ -7585,16 +7670,18 @@
 {
   ruiTabIdx = 0;
+  Int bitDepthY = pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA);
 
   // local pred buffer
   TComYuv cPredYuv;
-  cPredYuv.create( uiWidth, uiHeight );
+  cPredYuv.create( uiWidth, uiHeight, CHROMA_400 );
   cPredYuv.clear();
 
-  UInt uiPredStride = cPredYuv.getStride();
-  Pel* piPred       = cPredYuv.getLumaAddr();
+  UInt uiPredStride = cPredYuv.getStride( COMPONENT_Y );
+  Pel* piPred       = cPredYuv.getAddr( COMPONENT_Y );
 
   Pel refDC1 = 0; Pel refDC2 = 0;
-  WedgeList*     pacWedgeList     = pcCU->isDMM1UpscaleMode( uiWidth ) ? &g_dmmWedgeLists[(g_aucConvertToBit[pcCU->getDMM1BasePatternWidth(uiWidth)])] : &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
-  WedgeNodeList* pacWedgeNodeList = pcCU->isDMM1UpscaleMode( uiWidth ) ? &g_dmmWedgeNodeLists[(g_aucConvertToBit[pcCU->getDMM1BasePatternWidth(uiWidth)])] : &g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])];
+
+  WedgeList*     pacWedgeList     = getWedgeListScaled    ( uiWidth );
+  WedgeNodeList* pacWedgeNodeList = getWedgeNodeListScaled( uiWidth );
 
   // coarse wedge search
@@ -7604,20 +7691,20 @@
   {
     TComWedgelet* pcWedgelet = &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx()));
-    Bool *pbPattern = pcCU->isDMM1UpscaleMode(uiWidth) ? pcWedgelet->getScaledPattern(uiWidth) : pcWedgelet->getPattern();
-    UInt uiStride   = pcCU->isDMM1UpscaleMode(uiWidth) ? uiWidth : pcWedgelet->getStride();
-    xCalcBiSegDCs  ( piRef,  uiRefStride,  pbPattern, uiStride, refDC1, refDC2 );
-    xAssignBiSegDCs( piPred, uiPredStride, pbPattern, uiStride, refDC1, refDC2 );
+    Bool *pbPattern = pcWedgelet->getPatternScaled(uiWidth);
+    UInt uiStride   = uiWidth;
+    xCalcBiSegDCs  ( piRef,  uiRefStride,  pbPattern, uiStride, refDC1, refDC2, (1<<(bitDepthY-1)) );
+    assignBiSegDCs( piPred, uiPredStride, pbPattern, uiStride, refDC1, refDC2 );
 
     Dist uiActDist = RDO_DIST_MAX;
-#if H_3D_VSO
+#if NH_3D_VSO
     if( m_pcRdCost->getUseVSO() )
     {
       if( m_pcRdCost->getUseEstimatedVSD() )
       {
-        uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
+        uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
       }
       else
       {
-        uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
+        uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
       }
     }
@@ -7625,5 +7712,5 @@
 #endif
     {
-      uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
+      uiActDist = m_pcRdCost->getDistPart( bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, COMPONENT_Y, DF_SAD );
     }
 
@@ -7640,22 +7727,22 @@
   for( UInt uiRefId = 0; uiRefId < DMM_NUM_WEDGE_REFINES; uiRefId++ )
   {
-    if( pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ) != DMM_NO_WEDGEINDEX )
+    if( pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ) != DMM_NO_WEDGE_IDX )
     {
       TComWedgelet* pcWedgelet = &(pacWedgeList->at(pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId )));
-      Bool *pbPattern = pcCU->isDMM1UpscaleMode(uiWidth) ? pcWedgelet->getScaledPattern(uiWidth) : pcWedgelet->getPattern();
-      UInt uiStride   = pcCU->isDMM1UpscaleMode(uiWidth) ? uiWidth : pcWedgelet->getStride();
-      xCalcBiSegDCs  ( piRef,  uiRefStride,  pbPattern, uiStride, refDC1, refDC2 );
-      xAssignBiSegDCs( piPred, uiPredStride, pbPattern, uiStride, refDC1, refDC2 );
+      Bool *pbPattern = pcWedgelet->getPatternScaled(uiWidth);
+      UInt uiStride   = uiWidth;
+      xCalcBiSegDCs  ( piRef,  uiRefStride,  pbPattern, uiStride, refDC1, refDC2, (1<<(bitDepthY-1)) );
+      assignBiSegDCs( piPred, uiPredStride, pbPattern, uiStride, refDC1, refDC2 );
       Dist uiActDist = RDO_DIST_MAX;
-#if H_3D_VSO
+#if NH_3D_VSO
       if( m_pcRdCost->getUseVSO() )
       {
-        if( m_pcRdCost->getUseEstimatedVSD() ) //PM: use VSO instead of VSD here?
-        {
-          uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
+        if( m_pcRdCost->getUseEstimatedVSD() )
+        {
+          uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
         }
         else
         {
-          uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
+          uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
         }
       }
@@ -7663,5 +7750,5 @@
 #endif
       {
-        uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
+        uiActDist = m_pcRdCost->getDistPart( bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, COMPONENT_Y, DF_SAD );
       }
 
@@ -7681,5 +7768,28 @@
 
 #endif
-#endif
-
+#if TEMP_SDC_CLEANUP // PM: consider this cleanup for SDC
+#if NH_3D_SDC
+Void TEncSearch::xCalcConstantSDC( Pel* ptrSrc, UInt srcStride, UInt uiSize, Pel& valDC )
+{
+  valDC = 0;
+  UInt       uiDC = 0;
+  UInt uiNumPixDC = 0;
+
+  Int subSamplePix = ( uiSize > 16 ) ? 2 : 1;
+
+  Pel* piTemp = ptrSrc;
+  for( UInt uiY = 0; uiY < uiSize; uiY += subSamplePix )
+  {
+    for( UInt uiX = 0; uiX < uiSize; uiX += subSamplePix )
+    {
+      uiDC += piTemp[uiX];
+      uiNumPixDC++;
+    }
+    piTemp += subSamplePix*srcStride;
+  }
+
+  if( uiNumPixDC > 0 ) { valDC = uiDC / uiNumPixDC; }
+}
+#endif
+#endif
 //! \}
Index: branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSearch.h	(revision 1203)
+++ branches/HTM-14.1-update-dev1-HHI/source/Lib/TLibEncoder/TEncSearch.h	(revision 1209)
@@ -179,8 +179,9 @@
                                   TComYuv*    pcRecoYuv,
                                   Pel         resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE]
-#if H_3D_DIM
+                                  DEBUG_STRING_FN_DECLARE(sDebug)
+#if NH_3D_ENC_DEPTH
                                 , Bool        bOnlyIVP
 #endif
-                                  DEBUG_STRING_FN_DECLARE(sDebug));
+                                );
 
   Void  estIntraPredChromaQT    ( TComDataCU* pcCU,
@@ -282,6 +283,6 @@
                                     DEBUG_STRING_FN_DECLARE(sTest)
                                          ,Int           default0Save1Load2 = 0
-#if H_3D_DIM_ENC
-                                  , Bool          zeroResi = false
+#if NH_3D_ENC_DEPTH
+                                  , Bool          zeroResiFlag = false
 #endif
                                    );
@@ -300,9 +301,10 @@
 #endif
                                     Double&      dRDCost,
-#if H_3D_DIM_ENC
-                                   , Bool          zeroResi = false
-#endif
                                     TComTU      &rTu
-                                    DEBUG_STRING_FN_DECLARE(sDebug));
+                                    DEBUG_STRING_FN_DECLARE(sDebug)
+#if NH_3D_ENC_DEPTH
+                                  , Bool        zeroResiFlag = false
+#endif
+                                  );
 
   Void  xSetIntraResultLumaQT     ( TComYuv*     pcRecoYuv,
@@ -345,10 +347,10 @@
   Void xIntraCodingDIS           ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, UInt uiPredMode );
 #endif
-#if H_3D_DIM
+
   // -------------------------------------------------------------------------------------------------------------------
   // Depth intra search
   // -------------------------------------------------------------------------------------------------------------------
-  Void xCalcBiSegDCs              ( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2 );
-#if H_3D_DIM_DMM
+#if NH_3D_DMM
+  Void xCalcBiSegDCs              ( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2, Pel defaultVal, Bool subSamp = false );
   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 );
@@ -356,4 +358,8 @@
 #if H_3D_DIM_SDC
   Void xIntraCodingSDC            ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, Bool bZeroResidual, Int iSDCDeltaResi    );
+#endif
+#if TEMP_SDC_CLEANUP // PM: consider this cleanup for SDC
+#if NH_3D_SDC
+  Void xCalcConstantSDC           ( Pel* ptrSrc, UInt srcStride, UInt uiSize, Pel& valDC );
 #endif
 #endif
