Index: branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncTop.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncTop.cpp	(revision 467)
@@ -123,4 +123,11 @@
   {
     vps.setVpsDepthModesFlag( layer, ((vps.getDepthId( layer ) != 0) && (m_useDMM || m_useRBC || m_useSDC || m_useDLT)) ? true : false );
+#if H_3D_DIM_DLT
+    vps.setUseDLTFlag( layer , ((vps.getDepthId( layer ) != 0) && m_useDLT) ? true : false );
+    if( vps.getUseDLTFlag( layer ) )
+    {
+      xAnalyzeInputBaseDepth(layer, max(m_iIntraPeriod, 24), &vps);
+    }
+#endif
   }
 
@@ -986,4 +993,77 @@
 }
 
+#if H_3D_DIM_DLT
+Void TAppEncTop::xAnalyzeInputBaseDepth(UInt layer, UInt uiNumFrames, TComVPS* vps)
+{
+  TComPicYuv*       pcDepthPicYuvOrg = new TComPicYuv;
+  // allocate original YUV buffer
+  pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+  
+  TVideoIOYuv* depthVideoFile = new TVideoIOYuv;
+  
+  UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1);
+  
+  Bool abValidDepths[256];
+  
+  depthVideoFile->open( m_pchInputFileList[layer], false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
+  
+  // initialize boolean array
+  for(Int p=0; p<=uiMaxDepthValue; p++)
+    abValidDepths[p] = false;
+  
+  Int iHeight   = pcDepthPicYuvOrg->getHeight();
+  Int iWidth    = pcDepthPicYuvOrg->getWidth();
+  Int iStride   = pcDepthPicYuvOrg->getStride();
+  
+  Pel* pInDM    = pcDepthPicYuvOrg->getLumaAddr();
+  
+  for(Int uiFrame=0; uiFrame < uiNumFrames; uiFrame++ )
+  {
+    depthVideoFile->read( pcDepthPicYuvOrg, m_aiPad );
+    
+    // check all pixel values
+    for (Int i=0; i<iHeight; i++)
+    {
+      Int rowOffset = i*iStride;
+      
+      for (Int j=0; j<iWidth; j++)
+      {
+        Pel depthValue = pInDM[rowOffset+j];
+        abValidDepths[depthValue] = true;
+      }
+    }
+  }
+  
+  depthVideoFile->close();
+  
+  pcDepthPicYuvOrg->destroy();
+  delete pcDepthPicYuvOrg;
+  
+  // convert boolean array to idx2Depth LUT
+  Int* aiIdx2DepthValue = (Int*) calloc(uiMaxDepthValue, sizeof(Int));
+  Int iNumDepthValues = 0;
+  for(Int p=0; p<=uiMaxDepthValue; p++)
+  {
+    if( abValidDepths[p] == true)
+    {
+      aiIdx2DepthValue[iNumDepthValues++] = p;
+    }
+  }
+  
+  if( uiNumFrames == 0 || (Int)ceil(Log2(iNumDepthValues)) == (Int)ceil(Log2(((1 << g_bitDepthY)-1))) )
+  {
+    // don't use DLT
+    vps->setUseDLTFlag(layer, false);
+  }
+  
+  // assign LUT
+  if( vps->getUseDLTFlag(layer) )
+    vps->setDepthLUTs(layer, aiIdx2DepthValue, iNumDepthValues);
+  
+  // free temporary memory
+  free(aiIdx2DepthValue);
+}
+#endif
+
 #if H_MV
 Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps )
Index: branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncTop.h	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/App/TAppEncoder/TAppEncTop.h	(revision 467)
@@ -121,4 +121,8 @@
   Int  xGetMax( std::vector<Int>& vec);
 #endif
+  
+#if H_3D_DIM_DLT
+  Void  xAnalyzeInputBaseDepth(UInt layer, UInt uiNumFrames, TComVPS* vps);
+#endif
 public:
   TAppEncTop();
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/ContextTables.h
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/ContextTables.h	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/ContextTables.h	(revision 467)
@@ -111,4 +111,8 @@
 #endif
 
+#if H_3D_DIM_SDC
+#define SDC_NUM_RESIDUAL_FLAG_CTX        1
+#define SDC_NUM_RESIDUAL_CTX             1
+#endif
 // ====================================================================================================================
 // Tables
@@ -403,4 +407,20 @@
 };
 #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
 //! \}
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.cpp	(revision 467)
@@ -130,4 +130,9 @@
   m_pbEdgePartition = NULL;
 #endif
+#if H_3D_DIM_SDC
+  m_pbSDCFlag             = NULL;
+  m_apSegmentDCOffset[0]  = NULL;
+  m_apSegmentDCOffset[1]  = NULL;
+#endif
 #endif
 
@@ -245,4 +250,9 @@
     m_pbEdgeLeftFirst = (Bool*)xMalloc(Bool, uiNumPartition);
     m_pbEdgePartition = (Bool*)xMalloc(Bool, uiNumPartition * 16);
+#endif
+#if H_3D_DIM_SDC
+    m_pbSDCFlag             = (Bool*)xMalloc(Bool, uiNumPartition);
+    m_apSegmentDCOffset[0]  = (Pel*)xMalloc(Pel, uiNumPartition);
+    m_apSegmentDCOffset[1]  = (Pel*)xMalloc(Pel, uiNumPartition);
 #endif
 #endif
@@ -353,4 +363,9 @@
     if ( m_pucEdgeCode     ) { xFree( m_pucEdgeCode     ); m_pucEdgeCode     = NULL; }
     if ( m_pbEdgePartition ) { xFree( m_pbEdgePartition ); m_pbEdgePartition = NULL; }
+#endif
+#if H_3D_DIM_SDC
+    if ( m_pbSDCFlag            ) { xFree(m_pbSDCFlag);             m_pbSDCFlag             = NULL; }
+    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
@@ -481,4 +496,7 @@
     m_puhCbf[2][ui]=pcFrom->m_puhCbf[2][ui];
     m_pbIPCMFlag[ui] = pcFrom->m_pbIPCMFlag[ui];
+#if H_3D_DIM_SDC
+    m_pbSDCFlag[ui] = pcFrom->m_pbSDCFlag[ui];
+#endif
   }
   
@@ -535,4 +553,9 @@
     memset( m_pbEdgeLeftFirst   + firstElement, false,                    numElements * sizeof( *m_pbEdgeLeftFirst ) );
     memset( m_pbEdgePartition   + firstElement, false,                    numElements * sizeof( *m_pbEdgePartition ) * 16 );
+#endif
+#if H_3D_DIM_SDC
+    memset( m_pbSDCFlag             + firstElement,     0,                numElements * sizeof( *m_pbSDCFlag            ) );
+    memset( m_apSegmentDCOffset[0]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[0] ) );
+    memset( m_apSegmentDCOffset[1]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[1] ) );
 #endif
 #endif
@@ -687,4 +710,9 @@
       m_dmm3IntraTabIdx [ui] = 0;
 #endif
+#if H_3D_DIM_SDC
+      m_pbSDCFlag           [ui] = false;
+      m_apSegmentDCOffset[0][ui] = 0;
+      m_apSegmentDCOffset[1][ui] = 0;
+#endif
 #endif
     }
@@ -785,4 +813,9 @@
   memset( m_pbEdgeLeftFirst, 0, iSizeInBool );
   memset( m_pbEdgePartition, 0, iSizeInBool * 16 );
+#endif
+#if H_3D_DIM_SDC
+  memset( m_pbSDCFlag,            0, sizeof(Bool) * m_uiNumPartition  );
+  memset( m_apSegmentDCOffset[0], 0, sizeof(Pel) * m_uiNumPartition   );
+  memset( m_apSegmentDCOffset[1], 0, sizeof(Pel) * m_uiNumPartition   );
 #endif
 #endif
@@ -840,4 +873,9 @@
       m_dmm3IntraTabIdx [ui] = pcCU->m_dmm3IntraTabIdx[uiPartOffset+ui];
 #endif
+#if H_3D_DIM_SDC
+      m_pbSDCFlag           [ui] = pcCU->m_pbSDCFlag            [ uiPartOffset + ui ];
+      m_apSegmentDCOffset[0][ui] = pcCU->m_apSegmentDCOffset[0] [ uiPartOffset + ui ];
+      m_apSegmentDCOffset[1][ui] = pcCU->m_apSegmentDCOffset[1] [ uiPartOffset + ui ];
+#endif
 #endif
     }
@@ -980,4 +1018,9 @@
   m_pbEdgeLeftFirst = pcCU->getEdgeLeftFirst()   + uiPart;
   m_pbEdgePartition = pcCU->getEdgePartition( uiPart );
+#endif
+#if H_3D_DIM_SDC
+  m_pbSDCFlag               = pcCU->getSDCFlag()              + uiPart;
+  m_apSegmentDCOffset[0]    = pcCU->getSDCSegmentDCOffset(0)  + uiPart;
+  m_apSegmentDCOffset[1]    = pcCU->getSDCSegmentDCOffset(1)  + uiPart;
 #endif
 #endif
@@ -1131,4 +1174,9 @@
   memcpy( getEdgePartition( uiOffset ),  pcCU->getEdgePartition(0), iSizeInBool * 16 );
 #endif
+#if H_3D_DIM_SDC
+  memcpy( m_pbSDCFlag             + uiOffset, pcCU->getSDCFlag(),             iSizeInBool  );
+  memcpy( m_apSegmentDCOffset[0]  + uiOffset, pcCU->getSDCSegmentDCOffset(0), sizeof( Pel ) * uiNumPartition);
+  memcpy( m_apSegmentDCOffset[1]  + uiOffset, pcCU->getSDCSegmentDCOffset(1), sizeof( Pel ) * uiNumPartition);
+#endif
 #endif
 
@@ -1233,4 +1281,9 @@
   memcpy( rpcCU->getEdgeLeftFirst()   + m_uiAbsIdxInLCU, m_pbEdgeLeftFirst, iSizeInBool );
   memcpy( rpcCU->getEdgePartition( m_uiAbsIdxInLCU ),    m_pbEdgePartition, iSizeInBool * 16 );
+#endif
+#if H_3D_DIM_SDC
+  memcpy( rpcCU->getSDCFlag()             + m_uiAbsIdxInLCU, m_pbSDCFlag,      iSizeInBool  );
+  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
@@ -1328,4 +1381,9 @@
   memcpy( rpcCU->getEdgePartition( uiPartOffset ),    m_pbEdgePartition, iSizeInBool * 16 );
 #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
 
@@ -2226,4 +2284,27 @@
   }
 }
+
+#if H_3D_DIM_SDC
+Void TComDataCU::setSDCFlagSubParts ( Bool bSDCFlag, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  assert( sizeof( *m_pbSDCFlag) == 1 );
+  memset( m_pbSDCFlag + uiAbsPartIdx, bSDCFlag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
+}
+
+Bool TComDataCU::getSDCAvailable( UInt uiAbsPartIdx )
+{
+  // check general CU information
+  if( !getSlice()->getIsDepth() || !isIntra(uiAbsPartIdx) || getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
+    return false;
+  
+  // check prediction mode
+  UInt uiLumaPredMode = getLumaIntraDir( uiAbsPartIdx );  
+  if( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX && !isDimDeltaDC( uiLumaPredMode ) ) )
+    return true;
+  
+  // else
+  return false;
+}
+#endif
 
 Void TComDataCU::setMergeFlagSubParts ( Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.h	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComDataCU.h	(revision 467)
@@ -202,4 +202,8 @@
   Bool*         m_pbEdgePartition;      ///< true if it belongs to region 1, otherwise, region 0
 #endif
+#if H_3D_DIM_SDC
+  Bool*         m_pbSDCFlag;
+  Pel*          m_apSegmentDCOffset[2];
+#endif
 #endif
   
@@ -461,4 +465,15 @@
 
   Void   reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion );
+#endif
+#if H_3D_DIM_SDC
+  Bool*         getSDCFlag          ()                        { return m_pbSDCFlag;               }
+  Bool          getSDCFlag          ( UInt uiIdx )            { return m_pbSDCFlag[uiIdx];        }
+  Void          setSDCFlagSubParts  ( Bool bSDCFlag, UInt uiAbsPartIdx, UInt uiDepth );
+  
+  Bool          getSDCAvailable             ( UInt uiAbsPartIdx );
+  
+  Pel*          getSDCSegmentDCOffset( UInt uiSeg ) { return m_apSegmentDCOffset[uiSeg]; }
+  Pel           getSDCSegmentDCOffset( UInt uiSeg, UInt uiPartIdx ) { return m_apSegmentDCOffset[uiSeg][uiPartIdx]; }
+  Void          setSDCSegmentDCOffset( Pel pOffset, UInt uiSeg, UInt uiPartIdx) { m_apSegmentDCOffset[uiSeg][uiPartIdx] = pOffset; }
 #endif
 #endif
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.cpp	(revision 467)
@@ -476,6 +476,6 @@
     {
 #if H_3D_DIM_DLT
-      segDC1 = GetIdx2DepthValue( GetDepthValue2Idx( predDC1 ) + deltaDC1 );
-      segDC2 = GetIdx2DepthValue( GetDepthValue2Idx( predDC2 ) + deltaDC2 );
+      segDC1 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
+      segDC2 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
 #else
       segDC1 = ClipY( predDC1 + deltaDC1 );
@@ -1479,4 +1479,46 @@
 }
 #endif
+#if H_3D_DIM_SDC
+Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride )
+{
+  Int iSumDepth[2];
+  memset(iSumDepth, 0, sizeof(Int)*2);
+  Int iSumPix[2];
+  memset(iSumPix, 0, sizeof(Int)*2);
+  
+  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
 //! \}
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.h	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComPrediction.h	(revision 467)
@@ -128,5 +128,8 @@
 #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 );         
+  Void predIntraLumaDepth         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc = false );
+#if H_3D_DIM_SDC
+  Void analyzeSegmentsSDC         ( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride );
+#endif
 #endif
 
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.cpp	(revision 467)
@@ -1480,4 +1480,21 @@
     m_viewIndex         [i] = -1; 
     m_vpsDepthModesFlag [i] = false;
+#if H_3D_DIM_DLT
+    m_bUseDLTFlag         [i] = false;
+    
+    // allocate some memory and initialize with default mapping
+    m_iNumDepthmapValues[i] = ((1 << g_bitDepthY)-1)+1;
+    m_iBitsPerDepthValue[i] = (Int)ceil(Log2(m_iNumDepthmapValues[i]));
+    
+    m_iDepthValue2Idx[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
+    m_iIdx2DepthValue[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
+    
+    //default mapping
+    for (Int d=0; d<m_iNumDepthmapValues[i]; d++)
+    {
+      m_iDepthValue2Idx[i][d] = d;
+      m_iIdx2DepthValue[i][d] = d;
+    }
+#endif
 #endif
 
@@ -1502,4 +1519,67 @@
   if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
 }
+  
+#if H_3D_DIM_DLT
+  Void TComVPS::setDepthLUTs(Int layerIdInVps, Int* idx2DepthValue, Int iNumDepthValues)
+  {
+    if( idx2DepthValue == NULL || iNumDepthValues == 0 ) // default mapping only
+      return;
+    
+    // copy idx2DepthValue to internal array
+    memcpy(m_iIdx2DepthValue[layerIdInVps], idx2DepthValue, iNumDepthValues*sizeof(UInt));
+    
+    UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1);
+    for(Int p=0; p<=uiMaxDepthValue; p++)
+    {
+      Int iIdxDown    = 0;
+      Int iIdxUp      = iNumDepthValues-1;
+      Bool bFound     = false;
+      
+      // iterate over indices to find lower closest depth
+      Int i = 1;
+      while(!bFound && i<iNumDepthValues)
+      {
+        if( m_iIdx2DepthValue[layerIdInVps][i] > p )
+        {
+          iIdxDown  = i-1;
+          bFound    = true;
+        }
+        
+        i++;
+      }
+      // iterate over indices to find upper closest depth
+      i = iNumDepthValues-2;
+      bFound = false;
+      while(!bFound && i>=0)
+      {
+        if( m_iIdx2DepthValue[layerIdInVps][i] < p )
+        {
+          iIdxUp  = i+1;
+          bFound    = true;
+        }
+        
+        i--;
+      }
+      
+      // assert monotony
+      assert(iIdxDown<=iIdxUp);
+      
+      // assign closer depth value/idx
+      if( abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxDown]) < abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxUp]) )
+      {
+        m_iDepthValue2Idx[layerIdInVps][p] = iIdxDown;
+      }
+      else
+      {
+        m_iDepthValue2Idx[layerIdInVps][p] = iIdxUp;
+      }
+      
+    }
+    
+    // update DLT variables
+    m_iNumDepthmapValues[layerIdInVps] = iNumDepthValues;
+    m_iBitsPerDepthValue[layerIdInVps] = (Int)ceil(Log2(m_iNumDepthmapValues[layerIdInVps]));
+  }
+#endif
 
 #if H_MV
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.h	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TComSlice.h	(revision 467)
@@ -525,4 +525,12 @@
   Int         m_viewIndex                [MAX_NUM_LAYERS   ];
   Bool        m_vpsDepthModesFlag        [MAX_NUM_LAYERS   ];
+#if H_3D_DIM_DLT
+  Bool        m_bUseDLTFlag              [MAX_NUM_LAYERS   ];
+  
+  Int         m_iBitsPerDepthValue       [MAX_NUM_LAYERS   ];
+  Int         m_iNumDepthmapValues       [MAX_NUM_LAYERS   ];
+  Int*        m_iDepthValue2Idx          [MAX_NUM_LAYERS   ];
+  Int*        m_iIdx2DepthValue          [MAX_NUM_LAYERS   ];
+#endif
 #endif
 
@@ -646,4 +654,14 @@
   Void    setVpsDepthModesFlag( Int layerIdInVps, Bool val )               { m_vpsDepthModesFlag[ layerIdInVps ] = val; }
   Bool    getVpsDepthModesFlag( Int layerIdInVps )                         { return m_vpsDepthModesFlag[ layerIdInVps ]; }
+#if H_3D_DIM_DLT
+  Bool    getUseDLTFlag      ( Int layerIdInVps )                         { return m_bUseDLTFlag[ layerIdInVps ]; }
+  Void    setUseDLTFlag      ( Int layerIdInVps, Bool b ) { m_bUseDLTFlag[ layerIdInVps ]  = b;          }
+  
+  Int     getBitsPerDepthValue( Int layerIdInVps )        { return getUseDLTFlag(layerIdInVps)?m_iBitsPerDepthValue[layerIdInVps]:g_bitDepthY; }
+  Int     getNumDepthValues( Int layerIdInVps )           { return getUseDLTFlag(layerIdInVps)?m_iNumDepthmapValues[layerIdInVps]:((1 << g_bitDepthY)-1); }
+  Int     depthValue2idx( Int layerIdInVps, Pel value )   { return getUseDLTFlag(layerIdInVps)?m_iDepthValue2Idx[layerIdInVps][value]:value; }
+  Pel     idx2DepthValue( Int layerIdInVps, UInt uiIdx )  { return getUseDLTFlag(layerIdInVps)?m_iIdx2DepthValue[layerIdInVps][uiIdx]:uiIdx; }
+  Void    setDepthLUTs( Int layerIdInVps, Int* idx2DepthValue = NULL, Int iNumDepthValues = 0 );
+#endif
 #endif
 
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TypeDef.h	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibCommon/TypeDef.h	(revision 467)
@@ -87,5 +87,5 @@
                                               // HHI_DELTADC_DLT_D0035
                                               // PKU_QC_DEPTH_INTRA_UNI_D0195
-                                              // ... [PM: add SDC and DLT related]
+                                              // RWTH_SDC_DLT_B0036
 #endif 
 
@@ -107,9 +107,12 @@
 #define H_3D_DIM_DMM                      1   // Depth Modeling Modes
 #define H_3D_DIM_RBC                      1   // Region Boundary Chain mode
-#define H_3D_DIM_SDC                      0   // Simplified Depth Coding method
-#define H_3D_DIM_DLT                      0   // Depth Lookup Table
+#define H_3D_DIM_SDC                      1   // Simplified Depth Coding method
+#define H_3D_DIM_DLT                      1   // Depth Lookup Table
 #define H_3D_DIM_ENC                      1   // Depth Intra encoder optimizations, includes:
                                               // HHI_DEPTH_INTRA_SEARCH_RAU_C0160
                                               // LG_ZEROINTRADEPTHRESI_A0087
+#if H_3D_DIM_DLT || H_3D_DIM_SDC
+#define Log2( n ) ( log((double)n) / log(2.0) )
+#endif
 #endif
 
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 467)
@@ -961,4 +961,36 @@
         {
           READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
+          
+#if H_3D_DIM_DLT
+          if( pcVPS->getVpsDepthModesFlag( i ) )
+          {
+            READ_FLAG( uiCode, "use_dlt_flag[i]" );
+            pcVPS->setUseDLTFlag( i, uiCode == 1 ? true : false );
+            if( pcVPS->getUseDLTFlag( i ) )
+            {
+              // decode mapping
+              UInt uiNumDepthValues;
+              // parse number of values in DLT
+              READ_UVLC(uiNumDepthValues, "num_dlt_depth_values[i]");
+              
+              // parse actual DLT values
+              Int* aiIdx2DepthValue = (Int*) calloc(uiNumDepthValues, sizeof(Int));
+              for(Int d=0; d<uiNumDepthValues; d++)
+              {
+                READ_UVLC(uiCode, "dlt_depth_value[i][d]");
+                aiIdx2DepthValue[d] = (Int)uiCode;
+              }
+              
+              pcVPS->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
+              
+              // clean memory
+              free(aiIdx2DepthValue);
+            }
+            else
+              pcVPS->setDepthLUTs(i);
+          }
+          else
+            pcVPS->setDepthLUTs(i);
+#endif
         }
       }
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCu.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCu.cpp	(revision 467)
@@ -399,4 +399,9 @@
       break;
     case MODE_INTRA:
+#if H_3D_DIM_SDC
+      if( m_ppcCU[uiDepth]->getSDCFlag(0) )
+        xReconIntraSDC( m_ppcCU[uiDepth], 0, uiDepth );
+      else
+#endif
       xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
       break;
@@ -634,4 +639,131 @@
 
 }
+
+#if H_3D_DIM_SDC
+Void TDecCu::xReconIntraSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  UInt uiWidth        = pcCU->getWidth  ( 0 );
+  UInt uiHeight       = pcCU->getHeight ( 0 );
+  
+  TComYuv* pcRecoYuv  = m_ppcYuvReco[uiDepth];
+  TComYuv* pcPredYuv  = m_ppcYuvReco[uiDepth];
+  TComYuv* pcResiYuv  = m_ppcYuvResi[uiDepth];
+  
+  UInt    uiStride    = pcRecoYuv->getStride  ();
+  Pel*    piReco      = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
+  Pel*    piPred      = pcPredYuv->getLumaAddr( uiAbsPartIdx );
+  Pel*    piResi      = pcResiYuv->getLumaAddr( uiAbsPartIdx );
+  
+  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
+  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
+  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
+  
+  UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
+  
+  AOF( uiWidth == uiHeight );
+  AOF( uiAbsPartIdx == 0 );
+  AOF( pcCU->getSDCAvailable(uiAbsPartIdx) );
+  AOF( pcCU->getSDCFlag(uiAbsPartIdx) );
+  
+  //===== init availability pattern =====
+  Bool  bAboveAvail = false;
+  Bool  bLeftAvail  = false;
+  pcCU->getPattern()->initPattern   ( pcCU, 0, uiAbsPartIdx );
+  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
+  
+  //===== get prediction signal =====
+#if H_3D_DIM
+  if( isDimMode( uiLumaPredMode ) )
+  {
+    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
+  }
+  else
+  {
+#endif
+    m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
+#if H_3D_DIM
+  }
+#endif
+  
+  // number of segments depends on prediction mode
+  UInt uiNumSegments = 1;
+  Bool* pbMask = NULL;
+  UInt uiMaskStride = 0;
+  
+  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
+  {
+    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
+    
+    WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
+    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
+    
+    uiNumSegments = 2;
+    pbMask = pcWedgelet->getPattern();
+    uiMaskStride = pcWedgelet->getStride();
+  }
+  
+  // get DC prediction for each segment
+  Pel apDCPredValues[2];
+  m_pcPrediction->analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride);
+  
+  // reconstruct residual based on mask + DC residuals
+  Pel apDCResiValues[2];
+  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
+  {
+#if H_3D_DIM_DLT
+    Pel   pPredIdx    = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
+    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
+    Pel   pRecoValue  = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
+    
+    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
+#else
+    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
+#endif
+  }
+  
+  //===== reconstruction =====
+  Bool*pMask      = pbMask;
+  Pel* pPred      = piPred;
+  Pel* pResi      = piResi;
+  Pel* pReco      = piReco;
+  Pel* pRecIPred  = piRecIPred;
+  
+  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
+  {
+    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
+    {
+      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
+      assert( ucSegment < uiNumSegments );
+      
+      Pel pResiDC = apDCResiValues[ucSegment];
+      
+      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResiDC );
+      pRecIPred[ uiX ] = pReco[ uiX ];
+    }
+    pPred     += uiStride;
+    pResi     += uiStride;
+    pReco     += uiStride;
+    pRecIPred += uiRecIPredStride;
+    pMask     += uiMaskStride;
+  }
+  
+  // clear UV
+  UInt  uiStrideC     = pcPredYuv->getCStride();
+  Pel   *pRecCb       = pcPredYuv->getCbAddr();
+  Pel   *pRecCr       = pcPredYuv->getCrAddr();
+  
+  for (Int y=0; y<uiHeight/2; y++)
+  {
+    for (Int x=0; x<uiWidth/2; x++)
+    {
+      pRecCb[x] = 128;
+      pRecCr[x] = 128;
+    }
+    
+    pRecCb += uiStrideC;
+    pRecCr += uiStrideC;
+  }
+}
+#endif
 
 /** Function for deriving recontructed PU/CU Luma sample with QTree structure
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCu.h
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCu.h	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecCu.h	(revision 467)
@@ -115,4 +115,7 @@
   Void setdQPFlag               ( Bool b )                { m_bDecodeDQP = b;           }
   Void xFillPCMBuffer           (TComDataCU* pCU, UInt depth);
+#if H_3D_DIM_SDC
+  Void xReconIntraSDC           ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#endif
 };
 
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 467)
@@ -107,5 +107,8 @@
   {
     decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
-    decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
+#if H_3D_DIM_SDC
+    if(!pcCU->getSDCFlag(uiAbsPartIdx))
+#endif
+      decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
   }
   else                                                                // if it is Inter mode, encode motion vector and reference index
@@ -129,4 +132,10 @@
     return;
   }
+#if H_3D_DIM_SDC
+  if( pcCU->getSDCFlag(uiAbsPartIdx) )
+  {
+    return;
+  }
+#endif
   
   m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
@@ -535,4 +544,16 @@
   UInt uiChromaOffset = uiLumaOffset>>2;
   
+#if H_3D_DIM_SDC
+  if( pcCU->getSDCFlag( uiAbsPartIdx ) )
+  {
+    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
+    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
+    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
+    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
+    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
+    return;
+  }
+#endif
+  
   if( pcCU->isIntra(uiAbsPartIdx) )
   {
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 467)
@@ -89,4 +89,8 @@
 , m_cRbcDataSCModel           ( 1,             1,               NUM_RBC_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
 {
@@ -162,4 +166,8 @@
 #if H_3D_DIM_RBC
   m_cRbcDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_RBC_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
@@ -222,4 +230,8 @@
   m_cRbcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_RBC_DATA );
 #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
   m_pcTDecBinIf->start();
@@ -505,4 +517,69 @@
 }
 #endif
+#if H_3D_DIM_SDC
+Void TDecSbac::xParseSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSegment )
+{
+  assert( pcCU->getSlice()->getIsDepth() );
+  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
+  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
+  assert( uiSegment < 2 );
+  
+  UInt uiResidual = 0;
+  UInt uiBit      = 0;
+  UInt uiAbsIdx   = 0;
+  UInt uiSign     = 0;
+  Int  iIdx       = 0;
+  
+#if H_3D_DIM_DLT
+  UInt uiMaxResidualBits = pcCU->getSlice()->getVPS()->getBitsPerDepthValue( pcCU->getSlice()->getLayerIdInVps() );
+#else
+  UInt uiMaxResidualBits = g_bitDepthY;
+#endif
+  assert( uiMaxResidualBits <= g_bitDepthY );
+  
+  m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
+  
+  if (uiResidual)
+  {
+    // decode residual sign bit
+    m_pcTDecBinIf->decodeBinEP(uiSign);
+    
+    // decode residual magnitude
+    // prefix part
+    UInt uiCount = 0;
+#if H_3D_DIM_DLT
+    UInt uiNumDepthValues = pcCU->getSlice()->getVPS()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() );
+#else
+    UInt uiNumDepthValues = ((1 << g_bitDepthY)-1);
+#endif
+    UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2);
+    for ( UInt ui = 0; ui < uiPrefixThreshold; ui++)
+    {
+      m_pcTDecBinIf->decodeBin( uiBit, m_cSDCResidualSCModel.get(0, 0, 0) );
+      if ( uiBit == 0 )
+        break;
+      else
+        uiCount++;
+    }
+    // suffix part
+    if ( uiCount == uiPrefixThreshold )
+    {
+      for ( UInt ui = 0; ui < ( (UInt)ceil( Log2(uiNumDepthValues - uiPrefixThreshold) ) ); ui++ )
+      {
+        m_pcTDecBinIf->decodeBinEP( uiBit );
+        uiAbsIdx |= uiBit << ui;
+      }
+      uiAbsIdx += uiCount;
+    }
+    else
+      uiAbsIdx = uiCount;
+    
+    uiAbsIdx += 1;
+    iIdx =(Int)(uiSign ? -1 : 1)*uiAbsIdx;
+  }
+  
+  pcCU->setSDCSegmentDCOffset(iIdx, uiSegment, uiAbsPartIdx);
+}
+#endif
 #endif
 
@@ -962,34 +1039,34 @@
 
 #if H_3D_DIM_SDC
-  if( pcCU->getSDCAvailable(absPartIdx) && pcCU->getSDCFlag(absPartIdx) ) // sdcFlag
-  {
-    //assert(pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_NxN);
-    //pcCU->setTrIdxSubParts(0, uiAbsPartIdx, uiDepth);
-    //pcCU->setCbfSubParts(1, 1, 1, uiAbsPartIdx, uiDepth);
-
-    //UInt uiNumSegments = ( uiDir == DC_IDX || uiDir == PLANAR_IDX )? 1 : 2;
-    //for (int uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
-    //{
-    //  parseSDCResidualData(pcCU, uiAbsPartIdx, uiDepth, uiSeg);
-    //}
+  if( pcCU->getSDCFlag(absPartIdx) )
+  {
+    assert(pcCU->getPartitionSize(absPartIdx)==SIZE_2Nx2N);
+    pcCU->setTrIdxSubParts(0, absPartIdx, depth);
+    pcCU->setCbfSubParts(1, 1, 1, absPartIdx, depth);
+
+    UInt uiNumSegments = ( dir == DC_IDX || dir == PLANAR_IDX )? 1 : 2;
+    for (UInt uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
+    {
+      xParseSDCResidualData(pcCU, absPartIdx, depth, uiSeg);
+    }
   }
   else
   {
 #endif
-  if( dimType < DIM_NUM_TYPE )
-  {
-    UInt symbol;
-    m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) );
-    if( symbol )
-    {
-      dir += symbol;
-      for( UInt segment = 0; segment < 2; segment++ )
-      {
-        Pel valDeltaDC = 0;
-        xParseDimDeltaDC( valDeltaDC, dimType );
-        pcCU->setDimDeltaDC( dimType, segment, absPartIdx, valDeltaDC );
-      }
-    }
-  }
+    if( dimType < DIM_NUM_TYPE )
+    {
+      UInt symbol;
+      m_pcTDecBinIf->decodeBin( symbol, m_cDdcFlagSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) );
+      if( symbol )
+      {
+        dir += symbol;
+        for( UInt segment = 0; segment < 2; segment++ )
+        {
+          Pel valDeltaDC = 0;
+          xParseDimDeltaDC( valDeltaDC, dimType );
+          pcCU->setDimDeltaDC( dimType, segment, absPartIdx, valDeltaDC );
+        }
+      }
+    }
 #if H_3D_DIM_SDC
   }
@@ -1088,5 +1165,5 @@
   pcCU->setLumaIntraDirSubParts( (UChar)dir, absPartIdx, depth );
 #if H_3D_DIM_SDC
-  pcCU->setSDCFlagSubParts( sdcFlag, absPartIdx, 0, depth ); 
+  pcCU->setSDCFlagSubParts( sdcFlag, absPartIdx, depth ); 
 #endif
 }
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.h	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibDecoder/TDecSbac.h	(revision 467)
@@ -108,4 +108,7 @@
   Void  xParseRbcEdge        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
 #endif
+#if H_3D_DIM_SDC
+  Void  xParseSDCResidualData     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart );
+#endif
 #endif
 private:
@@ -201,4 +204,8 @@
   ContextModel3DBuffer m_cRbcDataSCModel;
 #endif
+#if H_3D_DIM_SDC  
+  ContextModel3DBuffer m_cSDCResidualFlagSCModel;
+  ContextModel3DBuffer m_cSDCResidualSCModel;
+#endif
 #endif
 };
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 467)
@@ -752,4 +752,20 @@
     {
       WRITE_FLAG( pcVPS->getVpsDepthModesFlag( i ),          "vps_depth_modes_flag[i]" );
+      
+#if H_3D_DIM_DLT
+      if( pcVPS->getVpsDepthModesFlag( i ) )
+      {
+        WRITE_FLAG( pcVPS->getUseDLTFlag( i ) ? 1 : 0, "use_dlt_flag[i]" );
+        if( pcVPS->getUseDLTFlag( i ) )
+        {
+          // code mapping
+          WRITE_UVLC(pcVPS->getNumDepthValues(i), "num_dlt_depth_values[i]");
+          for(Int d=0; d<pcVPS->getNumDepthValues(i); d++)
+          {
+            WRITE_UVLC( pcVPS->idx2DepthValue(i, d), "dlt_depth_value[i][d]" );
+          }
+        }
+      }
+#endif
     }
   }
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCu.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncCu.cpp	(revision 467)
@@ -1487,4 +1487,7 @@
   m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() );
   
+#if H_3D_DIM_SDC
+  if( !rpcTempCU->getSDCFlag( 0 ) )
+#endif
   m_pcPredSearch  ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC );
   
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 467)
@@ -217,4 +217,10 @@
     return;
   }
+#if H_3D_DIM_SDC
+  if( pcCU->getSDCFlag(uiAbsPartIdx) )
+  {
+    return;
+  }
+#endif
   
   if( bRD )
@@ -427,4 +433,7 @@
   {
     encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
+#if H_3D_DIM_SDC
+    if(!pcCU->getSDCFlag(uiAbsPartIdx))
+#endif
     encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
   }
@@ -592,5 +601,17 @@
   UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
   UInt uiChromaOffset = uiLumaOffset>>2;
-    
+  
+#if H_3D_DIM_SDC
+  if( pcCU->getSDCFlag( uiAbsPartIdx ) )
+  {
+    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
+    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
+    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
+    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
+    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
+    return;
+  }
+#endif
+
   if( pcCU->isIntra(uiAbsPartIdx) )
   {
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 467)
@@ -95,4 +95,8 @@
 , m_cRbcDataSCModel           ( 1,             1,               NUM_RBC_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
 {
@@ -159,4 +163,8 @@
 #if H_3D_DIM_RBC
   m_cRbcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_RBC_DATA );
+#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
@@ -293,4 +301,8 @@
   m_cRbcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_RBC_DATA );
 #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
   m_pcBinIf->start();
@@ -557,4 +569,75 @@
     if( uiReorderSymbol != 6 )
       m_pcBinIf->encodeBin( 0, m_cRbcDataSCModel.get( 0, 0, 0 ) );
+  }
+}
+#endif
+#if H_3D_DIM_SDC
+Void TEncSbac::xCodeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment )
+{
+  assert( pcCU->getSlice()->getIsDepth() );
+  assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
+  assert( pcCU->getSDCFlag(uiAbsPartIdx) );
+  assert( uiSegment < 2 );
+  
+  Pel segmentDCOffset = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
+  
+  UInt uiResidual = segmentDCOffset == 0 ? 0 : 1;
+  UInt uiSign     = segmentDCOffset < 0 ? 1 : 0;
+  UInt uiAbsIdx   = abs(segmentDCOffset);
+
+#if H_3D_DIM_DLT
+  UInt uiMaxResidualBits = pcCU->getSlice()->getVPS()->getBitsPerDepthValue( pcCU->getSlice()->getLayerIdInVps() );
+#else
+  UInt uiMaxResidualBits = g_bitDepthY;
+#endif
+  assert( uiMaxResidualBits <= g_bitDepthY );
+  
+  // residual flag
+  m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
+  
+  if (uiResidual)
+  {
+    // encode sign bit of residual
+    m_pcBinIf->encodeBinEP( uiSign );
+    
+#if H_3D_DIM_DLT
+    UInt uiNumDepthValues = pcCU->getSlice()->getVPS()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() );
+#else
+    UInt uiNumDepthValues = ((1 << g_bitDepthY)-1);
+#endif
+    assert(uiAbsIdx <= uiNumDepthValues);
+    
+    // encode residual magnitude
+    uiAbsIdx -= 1;
+    // prefix part
+    if ( uiAbsIdx == 0 )
+      m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) );
+    else
+    {
+      UInt l = uiAbsIdx;
+      UInt k = 0;
+      UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2);
+      while ( l > 0 && k < uiPrefixThreshold )
+      {
+        m_pcBinIf->encodeBin( 1, m_cSDCResidualSCModel.get(0, 0, 0) );
+        l--;
+        k++;
+      }
+      if ( uiAbsIdx < uiPrefixThreshold )
+        m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) );
+      // suffix part
+      else
+      {
+        uiAbsIdx -= uiPrefixThreshold;
+        UInt uiSuffixLength = ( (UInt)ceil( Log2(uiNumDepthValues - uiPrefixThreshold) ) );
+        UInt uiBitInfo = 0;
+        for ( Int i = 0; i < uiSuffixLength; i++)
+        {
+          uiBitInfo = ( uiAbsIdx & ( 1 << i ) ) >> i;
+          m_pcBinIf->encodeBinEP( uiBitInfo);
+        }
+      }
+    }
+    
   }
 }
@@ -695,4 +778,12 @@
 Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
 {
+#if H_3D_DIM_SDC
+  if ( pcCU->getSlice()->isIntra() )
+  {
+    assert( pcCU->isIntra(uiAbsPartIdx) );
+    return;
+  }
+#endif
+  
   // get context function is here
   Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx );
@@ -916,5 +1007,5 @@
 
 #if H_3D_DIM
-Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx, Bool sdcRD )
+Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx )
 {
   codeIntraDepthMode( pcCU, absPartIdx );
@@ -953,13 +1044,10 @@
   if( pcCU->getSDCFlag( absPartIdx ) )
   {
-  //  assert(pcCU->getPartitionSize(uiAbsPartIdx)==SIZE_2Nx2N);
-  //  UInt uiNumSegments = ( uiDir == DC_IDX || uiDir == PLANAR_IDX )? 1 : 2;
-  //  if(!bSdcRD)
-  //  {
-  //    for (int uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
-  //    {
-  //      codeSDCResidualData(pcCU, uiAbsPartIdx, uiSeg);
-  //    }
-  //  }
+    assert(pcCU->getPartitionSize(absPartIdx)==SIZE_2Nx2N);
+    UInt uiNumSegments = ( dir == DC_IDX || dir == PLANAR_IDX )? 1 : 2;
+    for(UInt uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
+    {
+      xCodeSDCResidualData(pcCU, absPartIdx, uiSeg);
+    }
   }
   else
@@ -1010,12 +1098,11 @@
 #if H_3D_DIM_SDC
   if( pcCU->getSDCFlag( absPartIdx ) )
-  { 
-  //  switch( dir )
-  //  {
-  //  case PLANAR_IDX:              codeIdx = 0; break;
-  //  case DC_IDX:                  codeIdx = 6; break;
-  //  case (2*DMM1_IDX+DIM_OFFSET): codeIdx = 2; break;
-  //  default:                                   break;
-  //  }
+  {
+    switch( dir )
+    {
+      case PLANAR_IDX:  codeIdx = 0; break;
+      case DC_IDX:      codeIdx = 6; break;
+      default:          codeIdx = 2; break;
+    }
   }
 #endif
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.h	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSbac.h	(revision 467)
@@ -127,4 +127,7 @@
   Void  xCodeRbcEdge         ( TComDataCU* pcCU, UInt uiAbsPartIdx );
 #endif
+#if H_3D_DIM_SDC
+  Void  xCodeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment );
+#endif
 #endif
   
@@ -165,5 +168,5 @@
 
 #if H_3D_DIM
-  Void codeIntraDepth          ( TComDataCU* pcCU, UInt absPartIdx, Bool sdcRD = false );
+  Void codeIntraDepth          ( TComDataCU* pcCU, UInt absPartIdx );
   Void codeIntraDepthMode      ( TComDataCU* pcCU, UInt absPartIdx );
 #endif
@@ -241,4 +244,8 @@
   ContextModel3DBuffer m_cRbcDataSCModel;
 #endif
+#if H_3D_DIM_SDC  
+  ContextModel3DBuffer m_cSDCResidualFlagSCModel;
+  ContextModel3DBuffer m_cSDCResidualSCModel;
+#endif
 #endif
 };
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 467)
@@ -1838,4 +1838,185 @@
 }
 
+#if H_3D_DIM_SDC
+Void TEncSearch::xIntraCodingSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, Bool bResidual )
+{
+  UInt    uiLumaPredMode    = pcCU     ->getLumaIntraDir( uiAbsPartIdx );
+  UInt    uiWidth           = pcCU     ->getWidth   ( 0 );
+  UInt    uiHeight          = pcCU     ->getHeight  ( 0 );
+  UInt    uiStride          = pcOrgYuv ->getStride  ();
+  Pel*    piOrg             = pcOrgYuv ->getLumaAddr( uiAbsPartIdx );
+  Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
+  Pel*    piReco            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
+  
+  UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
+  Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
+  UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
+  
+  AOF( uiWidth == uiHeight );
+  AOF( uiAbsPartIdx == 0 );
+  AOF( pcCU->getSDCAvailable(uiAbsPartIdx) );
+  AOF( pcCU->getSDCFlag(uiAbsPartIdx) );
+  AOF( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX && !isDimDeltaDC( uiLumaPredMode ) ) );
+  AOF( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || uiWidth < 64  );
+  
+  //===== init availability pattern =====
+  Bool  bAboveAvail = false;
+  Bool  bLeftAvail  = false;
+  pcCU->getPattern()->initPattern   ( pcCU, 0, uiAbsPartIdx );
+  pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail );
+  
+  //===== get prediction signal =====
+#if H_3D_DIM
+  if( isDimMode( uiLumaPredMode ) )
+  {
+    predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, true );
+  }
+  else
+  {
+#endif
+    predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
+#if H_3D_DIM
+  }
+#endif
+  
+  // number of segments depends on prediction mode
+  UInt uiNumSegments = 1;
+  Bool* pbMask = NULL;
+  UInt uiMaskStride = 0;
+    
+  if( getDimType( uiLumaPredMode ) == DMM1_IDX )
+  {
+    Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx);
+    
+    WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
+    TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx ));
+    
+    uiNumSegments = 2;
+    pbMask = pcWedgelet->getPattern();
+    uiMaskStride = pcWedgelet->getStride();
+  }
+  
+  // get DC prediction for each segment
+  Pel apDCPredValues[2];
+  analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride );
+  
+  // get original DC for each segment
+  Pel apDCOrigValues[2];
+  analyzeSegmentsSDC(piOrg, uiStride, uiWidth, apDCOrigValues, uiNumSegments, pbMask, uiMaskStride );
+  
+  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
+  {
+    // remap reconstructed value to valid depth values
+    Pel pDCRec = bResidual?apDCOrigValues[uiSegment]:apDCPredValues[uiSegment];
+    
+    // get residual (idx)
+#if H_3D_DIM_DLT
+    Pel pResidualIdx = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pDCRec ) - pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
+#else
+    Pel pResidualIdx = pDCRec - apDCPredValues[uiSegment];
+#endif
+    
+    // save SDC DC offset
+    pcCU->setSDCSegmentDCOffset(pResidualIdx, uiSegment, uiAbsPartIdx);
+  }
+  
+  // reconstruct residual based on mask + DC residuals
+  Pel apDCResiValues[2];
+  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
+  {
+#if H_3D_DIM_DLT
+    Pel   pPredIdx    = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
+    Pel   pResiIdx    = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
+    Pel   pRecoValue  = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );
+    
+    apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
+#else
+    apDCResiValues[uiSegment]  = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);
+#endif
+  }
+  
+  //===== reconstruction =====
+  Bool* pMask     = pbMask;
+  Pel* pPred      = piPred;
+  Pel* pReco      = piReco;
+  Pel* pRecIPred  = piRecIPred;
+  
+  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
+  {
+    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
+    {
+      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
+      assert( ucSegment < uiNumSegments );
+
+      Pel pResiDC = apDCResiValues[ucSegment];
+      
+      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResiDC );
+      pRecIPred[ uiX ] = pReco[ uiX ];
+    }
+    pPred     += uiStride;
+    pReco     += uiStride;
+    pRecIPred += uiRecIPredStride;
+    pMask     += uiMaskStride;
+  }
+  
+  // clear UV
+  UInt  uiStrideC     = pcPredYuv->getCStride();
+  Pel   *pRecCb       = pcPredYuv->getCbAddr();
+  Pel   *pRecCr       = pcPredYuv->getCrAddr();
+  
+  for (Int y=0; y<uiHeight/2; y++)
+  {
+    for (Int x=0; x<uiWidth/2; x++)
+    {
+      pRecCb[x] = 128;
+      pRecCr[x] = 128;
+    }
+    
+    pRecCb += uiStrideC;
+    pRecCr += uiStrideC;
+  }
+  
+  //===== determine distortion =====
+#if H_3D_VSO
+  if( m_pcRdCost->getUseVSO() )
+  {
+    if( m_pcRdCost->getUseEstimatedVSD() )
+    {
+      ruiDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPartIdx, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, false );
+    }
+    else
+    {
+      ruiDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPartIdx, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, false );
+    }
+  }
+  else
+#endif
+  {
+    ruiDist = m_pcRdCost->getDistPart( g_bitDepthY, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );
+  }
+  
+  //----- determine rate and r-d cost -----
+  m_pcEntropyCoder->resetBits();
+  
+  // encode reduced intra header
+  m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true );
+  m_pcEntropyCoder->encodePredMode( pcCU, 0, true );
+  
+  // encode pred direction + residual data
+  m_pcEntropyCoder->encodePredInfo( pcCU, 0, true );
+  UInt   uiBits = m_pcEntropyCoder->getNumberOfWrittenBits();
+  
+#if HHI_VSO
+  if ( m_pcRdCost->getUseLambdaScaleVSO())
+  {
+    dRDCost = m_pcRdCost->calcRdCostVSO( uiBits, ruiDist );
+  }
+  else
+#endif
+  {
+    dRDCost = m_pcRdCost->calcRdCost( uiBits, ruiDist );
+  }
+}
+#endif
 
 Void
@@ -2766,10 +2947,10 @@
     UInt    uiBestPUDistC = 0;
     Double  dBestPUCost   = MAX_DOUBLE;
+#if H_3D_DIM_SDC
+    Bool    bBestUseSDC   = false;
+    Pel     apBestDCOffsets[2] = {0,0};
+#endif
     for( UInt uiMode = 0; uiMode < numModesForFullRD; uiMode++ )
     {
-#if H_3D_DIM_ENC
-      for( UInt testZeroResi = 0; testZeroResi <= ((pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->isIRAP()) ? 1 : 0 ); testZeroResi++ )
-      {
-#endif
       // set luma prediction mode
       UInt uiOrgMode = uiRdModeList[uiMode];
@@ -2777,4 +2958,26 @@
       pcCU->setLumaIntraDirSubParts ( uiOrgMode, uiPartOffset, uiDepth + uiInitTrDepth );
       
+#if H_3D_DIM_SDC
+      Bool bTestSDC = ( m_pcEncCfg->getUseSDC() && pcCU->getSDCAvailable(uiPartOffset) );
+      
+      for( UInt uiSDC=0; uiSDC<=(bTestSDC?1:0); uiSDC++ )
+      {
+        pcCU->setSDCFlagSubParts( (uiSDC != 0), uiPartOffset, uiDepth + uiInitTrDepth );
+#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 H_3D_DIM_SDC
+      bTestZeroResi |= pcCU->getSDCFlag(uiPartOffset);
+#endif
+#endif
+      
+#if H_3D_DIM_ENC || H_3D_DIM_SDC      
+      for( UInt testZeroResi = 0; testZeroResi <= (bTestZeroResi ? 1 : 0) ; testZeroResi++ )
+      {
+#endif
       // set context models
       if( m_bUseSBACRD )
@@ -2797,4 +3000,16 @@
       }
 #endif
+#if H_3D_DIM_SDC
+            if( pcCU->getSDCFlag(uiPartOffset) )
+            {
+              pcCU->setTrIdxSubParts(0, uiPartOffset, uiDepth + uiInitTrDepth);
+              pcCU->setCbfSubParts(1, 1, 1, uiPartOffset, uiDepth + uiInitTrDepth);
+              
+              // start encoding with SDC
+              xIntraCodingSDC(pcCU, uiPartOffset, pcOrgYuv, pcPredYuv, uiPUDistY, dPUCost, (testZeroResi!=0));
+            }
+            else
+            {
+#endif
 #if HHI_RQT_INTRA_SPEEDUP
 #if H_3D_DIM_ENC
@@ -2810,4 +3025,7 @@
 #endif
 #endif
+#if H_3D_DIM_SDC
+            }
+#endif
       
       // check r-d cost
@@ -2822,4 +3040,104 @@
         uiBestPUDistC = uiPUDistC;
         dBestPUCost   = dPUCost;
+        
+#if H_3D_DIM_SDC
+        if( pcCU->getSDCFlag(uiPartOffset) )
+        {
+          bBestUseSDC = true;
+          
+          // copy reconstruction
+          pcPredYuv->copyPartToPartYuv(pcRecoYuv, uiPartOffset, uiWidth, uiHeight);
+          
+          // copy DC values
+          apBestDCOffsets[0] = pcCU->getSDCSegmentDCOffset(0, uiPartOffset);
+          apBestDCOffsets[1] = pcCU->getSDCSegmentDCOffset(1, uiPartOffset);
+        }
+        else
+        {
+          bBestUseSDC = false;
+#endif
+        xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv );
+        
+        UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 );
+        ::memcpy( m_puhQTTempTrIdx,  pcCU->getTransformIdx()       + uiPartOffset, uiQPartNum * sizeof( UChar ) );
+        ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA     ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
+        ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
+        ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
+        ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, uiQPartNum * sizeof( UChar ) );
+        ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
+        ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
+#if H_3D_DIM_SDC
+        }
+#endif
+      }
+#if HHI_RQT_INTRA_SPEEDUP_MOD
+      else if( dPUCost < dSecondBestPUCost )
+      {
+        uiSecondBestMode  = uiOrgMode;
+        dSecondBestPUCost = dPUCost;
+      }
+#endif
+#if H_3D_DIM_ENC || H_3D_DIM_SDC
+      }
+#endif
+#if H_3D_DIM_SDC
+      } // SDC loop
+#endif
+    } // Mode loop
+    
+#if HHI_RQT_INTRA_SPEEDUP
+#if HHI_RQT_INTRA_SPEEDUP_MOD
+    for( UInt ui =0; ui < 2; ++ui )
+#endif
+    {
+#if HHI_RQT_INTRA_SPEEDUP_MOD
+      UInt uiOrgMode   = ui ? uiSecondBestMode  : uiBestPUMode;
+      if( uiOrgMode == MAX_UINT )
+      {
+        break;
+      }
+#else
+      UInt uiOrgMode = uiBestPUMode;
+#endif
+      
+      pcCU->setLumaIntraDirSubParts ( uiOrgMode, uiPartOffset, uiDepth + uiInitTrDepth );
+#if H_3D_DIM_SDC
+      pcCU->setSDCFlagSubParts(false, uiPartOffset, uiDepth + uiInitTrDepth);
+#endif
+      
+      // set context models
+      if( m_bUseSBACRD )
+      {
+        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
+      }
+      
+      // determine residual for partition
+#if H_3D_VSO
+      Dist   uiPUDistY = 0;
+#else
+      UInt   uiPUDistY = 0;
+#endif
+      UInt   uiPUDistC = 0;
+      Double dPUCost   = 0.0;
+
+#if H_3D_VSO // M37
+      // reset Model
+      if( m_pcRdCost->getUseRenModel() )
+      {
+        m_pcRdCost->setRenModelData( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight );
+      }
+#endif
+      xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, false, dPUCost );
+      
+      // check r-d cost
+      if( dPUCost < dBestPUCost )
+      {
+        uiBestPUMode  = uiOrgMode;
+        uiBestPUDistY = uiPUDistY;
+        uiBestPUDistC = uiPUDistC;
+        dBestPUCost   = dPUCost;
+#if H_3D_DIM_SDC
+        bBestUseSDC   = false;
+#endif
         
         xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv );
@@ -2834,76 +3152,4 @@
         ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
       }
-#if HHI_RQT_INTRA_SPEEDUP_MOD
-      else if( dPUCost < dSecondBestPUCost )
-      {
-        uiSecondBestMode  = uiOrgMode;
-        dSecondBestPUCost = dPUCost;
-      }
-#endif
-#if H_3D_DIM_ENC
-      }
-#endif
-    } // Mode loop
-    
-#if HHI_RQT_INTRA_SPEEDUP
-#if HHI_RQT_INTRA_SPEEDUP_MOD
-    for( UInt ui =0; ui < 2; ++ui )
-#endif
-    {
-#if HHI_RQT_INTRA_SPEEDUP_MOD
-      UInt uiOrgMode   = ui ? uiSecondBestMode  : uiBestPUMode;
-      if( uiOrgMode == MAX_UINT )
-      {
-        break;
-      }
-#else
-      UInt uiOrgMode = uiBestPUMode;
-#endif
-      
-      pcCU->setLumaIntraDirSubParts ( uiOrgMode, uiPartOffset, uiDepth + uiInitTrDepth );
-      
-      // set context models
-      if( m_bUseSBACRD )
-      {
-        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
-      }
-      
-      // determine residual for partition
-#if H_3D_VSO
-      Dist   uiPUDistY = 0;
-#else
-      UInt   uiPUDistY = 0;
-#endif
-      UInt   uiPUDistC = 0;
-      Double dPUCost   = 0.0;
-
-#if H_3D_VSO // M37
-      // reset Model
-      if( m_pcRdCost->getUseRenModel() )
-      {
-        m_pcRdCost->setRenModelData( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight );
-      }
-#endif
-      xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, false, dPUCost );
-      
-      // check r-d cost
-      if( dPUCost < dBestPUCost )
-      {
-        uiBestPUMode  = uiOrgMode;
-        uiBestPUDistY = uiPUDistY;
-        uiBestPUDistC = uiPUDistC;
-        dBestPUCost   = dPUCost;
-        
-        xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv );
-        
-        UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 );
-        ::memcpy( m_puhQTTempTrIdx,  pcCU->getTransformIdx()       + uiPartOffset, uiQPartNum * sizeof( UChar ) );
-        ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA     ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
-        ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
-        ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
-        ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, uiQPartNum * sizeof( UChar ) );
-        ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
-        ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
-      }
     } // Mode loop
 #endif
@@ -2912,4 +3158,18 @@
     uiOverallDistY += uiBestPUDistY;
     uiOverallDistC += uiBestPUDistC;
+    
+#if H_3D_DIM_SDC
+    if( bBestUseSDC )
+    {
+      pcCU->setTrIdxSubParts(0, uiPartOffset, uiDepth + uiInitTrDepth);
+      pcCU->setCbfSubParts(1, 1, 1, uiPartOffset, uiDepth + uiInitTrDepth);
+      
+      //=== copy best DC segment values back to CU ====
+      pcCU->setSDCSegmentDCOffset(apBestDCOffsets[0], 0, uiPartOffset);
+      pcCU->setSDCSegmentDCOffset(apBestDCOffsets[1], 1, uiPartOffset);
+    }
+    else
+    {
+#endif
     
     //--- update transform index and cbf ---
@@ -2922,4 +3182,7 @@
     ::memcpy( pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhQTTempTransformSkipFlag[1], uiQPartNum * sizeof( UChar ) );
     ::memcpy( pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhQTTempTransformSkipFlag[2], uiQPartNum * sizeof( UChar ) );
+#if H_3D_DIM_SDC
+    }
+#endif
     //--- set reconstruction for next intra prediction blocks ---
     if( uiPU != uiNumPU - 1 )
@@ -2989,4 +3252,7 @@
     //=== update PU data ====
     pcCU->setLumaIntraDirSubParts     ( uiBestPUMode, uiPartOffset, uiDepth + uiInitTrDepth );
+#if H_3D_DIM_SDC
+    pcCU->setSDCFlagSubParts          ( bBestUseSDC, uiPartOffset, uiDepth + uiInitTrDepth );
+#endif
     pcCU->copyToPic                   ( uiDepth, uiPU, uiInitTrDepth );
   } // PU loop
@@ -6729,6 +6995,6 @@
 
 #if H_3D_DIM_DLT
-  rDeltaDC1 = (Int)GetDepthValue2Idx( ClipY(predDC1 + rDeltaDC1) ) - (Int)GetDepthValue2Idx( predDC1 );
-  rDeltaDC2 = (Int)GetDepthValue2Idx( ClipY(predDC2 + rDeltaDC2) ) - (Int)GetDepthValue2Idx( predDC2 );
+  rDeltaDC1 = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipY(predDC1 + rDeltaDC1) ) - pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 );
+  rDeltaDC2 = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipY(predDC2 + rDeltaDC2) ) - pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 );
 #endif
 }
Index: branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.h	(revision 466)
+++ branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncSearch.h	(revision 467)
@@ -352,4 +352,7 @@
   Bool xConstructChainCode        ( TComDataCU* pcCU, UInt uiAbsPtIdx, UInt uiWidth, UInt uiHeight );
 #endif
+#if H_3D_DIM_SDC
+  Void xIntraCodingSDC            ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, Bool bResidual );
+#endif
 #endif
 
