Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/ContextTables.h
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/ContextTables.h	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/ContextTables.h	(revision 781)
@@ -107,9 +107,17 @@
 
 #if H_3D_DIM
+#if QC_GENERIC_SDC_G0122
+#define NUM_DEPTH_INTRA_MODE_CTX      1       ///< number of context models for depth intra modes
+#else
 #define NUM_DEPTH_INTRA_MODE_CTX      8       ///< number of context models for depth intra modes
+#endif
 #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
+#if QC_GENERIC_SDC_G0122
+#define NUM_ANGLE_FLAG_CTX            3
+#define NUM_INTRASDC_FLAG_CTX         3
 #endif
 #endif
@@ -383,4 +391,13 @@
 #endif
 #if H_3D_DIM
+#if QC_GENERIC_SDC_G0122
+static const UChar
+INIT_DEPTH_INTRA_MODE[3][NUM_DEPTH_INTRA_MODE_CTX] =
+{
+  { 154, },
+  { 154, },
+  { 154, }
+};
+#else
 static const UChar
 INIT_DEPTH_INTRA_MODE[3][NUM_DEPTH_INTRA_MODE_CTX] =
@@ -390,4 +407,22 @@
     {64, 0, CNU, CNU, 168, 109,   0, 0}
 };
+#endif
+
+#if QC_GENERIC_SDC_G0122
+static const UChar 
+INIT_ANGLE_FLAG[3][NUM_ANGLE_FLAG_CTX] =
+{
+  { 154, 155, 156 },
+  { 141, 185, 214 },
+  { 155, 170, 157 },
+};
+static const UChar 
+INIT_INTRASDC_FLAG[3][NUM_INTRASDC_FLAG_CTX] =
+{
+  { 214, 229, 230 },
+  { 215, 202, 174 },
+  { 213, 201, 246 },
+};
+#endif
 
 static const UChar 
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComDataCU.cpp	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComDataCU.cpp	(revision 781)
@@ -2401,4 +2401,40 @@
 #endif
 
+#if QC_GENERIC_SDC_G0122
+UInt TComDataCU::getCtxSDCFlag( UInt uiAbsPartIdx )
+{
+  TComDataCU* pcTempCU;
+  UInt        uiTempPartIdx;
+  UInt        uiCtx = 0;
+
+  // Get BCBP of left PU
+  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
+  uiCtx    = ( pcTempCU && pcTempCU->isIntra( uiTempPartIdx ) ) ? pcTempCU->getSDCFlag( uiTempPartIdx ) : 0;
+
+  // Get BCBP of above PU
+  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
+  uiCtx   += ( pcTempCU && pcTempCU->isIntra( uiTempPartIdx ) ) ? pcTempCU->getSDCFlag( uiTempPartIdx ) : 0;
+
+  return uiCtx;
+}
+
+UInt TComDataCU::getCtxAngleFlag( UInt uiAbsPartIdx )
+{
+  TComDataCU* pcTempCU;
+  UInt        uiTempPartIdx;
+  UInt        uiCtx = 0;
+
+  // Get BCBP of left PU
+  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
+  uiCtx    = ( pcTempCU && pcTempCU->isIntra( uiTempPartIdx ) ) ? ( pcTempCU->getLumaIntraDir( uiTempPartIdx ) < NUM_INTRA_MODE ? 1 : 0 ) : 0;
+
+  // Get BCBP of above PU
+  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
+  uiCtx   += ( pcTempCU && pcTempCU->isIntra( uiTempPartIdx ) ) ? ( pcTempCU->getLumaIntraDir( uiTempPartIdx ) < NUM_INTRA_MODE ? 1 : 0 ) : 0;
+
+  return uiCtx;
+}
+#endif
+
 UInt TComDataCU::getCtxInterDir( UInt uiAbsPartIdx )
 {
@@ -2627,5 +2663,17 @@
   if( !getSlice()->getIsDepth() || !isIntra(uiAbsPartIdx) || getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
     return false;
-  
+#if QC_GENERIC_SDC_G0122
+  if( isDimMode( getLumaIntraDir( uiAbsPartIdx ) ) && !isDimDeltaDC( getLumaIntraDir( uiAbsPartIdx ) ) )
+  {
+    return true;
+  }
+
+  if( getLumaIntraDir( uiAbsPartIdx ) < NUM_INTRA_MODE )
+  {
+    return true;
+  }
+
+  return false;
+#endif
   // check prediction mode
   UInt uiLumaPredMode = getLumaIntraDir( uiAbsPartIdx );  
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComDataCU.h	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComDataCU.h	(revision 781)
@@ -571,4 +571,8 @@
   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 QC_GENERIC_SDC_G0122
+  UInt          getCtxSDCFlag          ( UInt   uiAbsPartIdx );
+  UInt          getCtxAngleFlag        ( UInt   uiAbsPartIdx );
+#endif
 #endif
 #endif
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComPrediction.cpp	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComPrediction.cpp	(revision 781)
@@ -416,5 +416,9 @@
 
 #if H_3D_DIM
-Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc )
+Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc
+#if QC_GENERIC_SDC_G0122
+  , TComWedgelet* dmm4Segmentation
+#endif
+  )
 {
   assert( iWidth == iHeight  );
@@ -442,6 +446,19 @@
     case( DMM4_IDX ): 
       {
+#if QC_GENERIC_SDC_G0122
+        if( dmm4Segmentation == NULL )
+        { 
+          dmmSegmentation = new TComWedgelet( iWidth, iHeight );
+          xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
+        }
+        else
+        {
+          xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmm4Segmentation );
+          dmmSegmentation = dmm4Segmentation;
+        }
+#else
         dmmSegmentation = new TComWedgelet( iWidth, iHeight );
         xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
+#endif
       } break;
     default: assert(0);
@@ -494,5 +511,9 @@
 
 #if H_3D_DIM_DMM
+#if QC_GENERIC_SDC_G0122
+  if( dimType == DMM4_IDX && dmm4Segmentation == NULL ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
+#else
   if( dimType == DMM4_IDX ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
+#endif
 #endif
 }
@@ -2184,5 +2205,10 @@
   Int iSumPix[2];
   memset(iSumPix, 0, sizeof(Int)*2);
-  
+#if QC_GENERIC_SDC_G0122
+  for( Int i = 0; i < uiNumSegments; i++ )
+  {
+    rpSegMeans[i] = 0;
+  }
+#endif
   if (orgDC == false)
   {
@@ -2199,5 +2225,41 @@
       rpSegMeans[ucSegmentRB] = pOrig[uiStride * (uiSize-1) + (uiSize-1) ];
     }
+#if QC_GENERIC_SDC_G0122
+    else if( getDimType( uiIntraMode ) == DMM4_IDX )
+    {
+      Pel *ptmpOrig = pOrig;
+      Bool *ptmpMask = pMask, bBreak = false;
+      UChar ucSegment = ptmpMask? (UChar) ptmpMask[0] : 0;
+      UChar bFirstSeg = ucSegment;
+
+      rpSegMeans[ucSegment] = ptmpOrig[0];
+      for ( Int y = 0; y < uiSize; y++ )
+      {
+        for ( Int x = 0; x < uiSize; x++ )
+        {
+          ucSegment = ptmpMask[x];
+          assert( ucSegment < uiNumSegments );
+
+          if( bFirstSeg != ucSegment )
+          {
+            rpSegMeans[ucSegment] = ptmpOrig[x];
+            bBreak = true;
+            break;
+          }
+        }
+
+        if( bBreak )
+        {
+          break;
+        }
+
+        ptmpOrig  += uiStride;
+        ptmpMask  += uiMaskStride;
+      }
+    }
+    else
+#else
     else if (uiIntraMode == PLANAR_IDX)
+#endif
     {
       Pel* pLeftTop = pOrig;
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComPrediction.h	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComPrediction.h	(revision 781)
@@ -167,5 +167,9 @@
 #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 QC_GENERIC_SDC_G0122
+    , TComWedgelet* dmm4Segmentation = NULL
+#endif
+    );
 #if H_3D_DIM_SDC
   Void analyzeSegmentsSDC         ( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TypeDef.h	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TypeDef.h	(revision 781)
@@ -235,4 +235,5 @@
 #define H_3D_DELTA_DLT                    1
 #endif
+#define QC_GENERIC_SDC_G0122              1  // Generalize SDC to all depth intra modes
 
 #define H_3D_DIM_ENC                      1   // Depth Intra encoder optimizations, includes:
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibDecoder/TDecCu.cpp	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibDecoder/TDecCu.cpp	(revision 781)
@@ -932,10 +932,16 @@
   pcCU->getPattern()->initPattern   ( pcCU, 0, uiAbsPartIdx );
   pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, m_pcPrediction->getPredicBuf(), m_pcPrediction->getPredicBufWidth(), m_pcPrediction->getPredicBufHeight(), bAboveAvail, bLeftAvail );
-  
+#if QC_GENERIC_SDC_G0122
+  TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
+#endif
   //===== get prediction signal =====
 #if H_3D_DIM
   if( isDimMode( uiLumaPredMode ) )
   {
-    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight );
+    m_pcPrediction->predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight 
+#if QC_GENERIC_SDC_G0122
+      , false, dmm4Segmentation
+#endif
+      );
   }
   else
@@ -963,5 +969,12 @@
     uiMaskStride = pcWedgelet->getStride();
   }
-  
+#if QC_GENERIC_SDC_G0122
+  if( getDimType( uiLumaPredMode ) == DMM4_IDX )
+  {
+    uiNumSegments = 2;
+    pbMask  = dmm4Segmentation->getPattern();
+    uiMaskStride = dmm4Segmentation->getStride();
+  }
+#endif
   // get DC prediction for each segment
   Pel apDCPredValues[2];
@@ -1025,4 +1038,7 @@
     pRecCr += uiStrideC;
   }
+#if QC_GENERIC_SDC_G0122
+  dmm4Segmentation->destroy(); delete dmm4Segmentation;
+#endif
 }
 #endif
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 781)
@@ -87,4 +87,8 @@
 , m_cDdcFlagSCModel           ( 1,             1,               NUM_DDC_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
 , m_cDdcDataSCModel           ( 1,             1,               NUM_DDC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
+#if QC_GENERIC_SDC_G0122
+, m_cAngleFlagSCModel         ( 1,             1,               NUM_ANGLE_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cIntraSdcFlagSCModel      ( 1,             1,               NUM_INTRASDC_FLAG_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
 #if H_3D_DIM_DMM
 , m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
@@ -170,4 +174,8 @@
   m_cDdcFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_FLAG );
   m_cDdcDataSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_DDC_DATA );
+#if QC_GENERIC_SDC_G0122
+  m_cAngleFlagSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_ANGLE_FLAG );
+  m_cIntraSdcFlagSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_INTRASDC_FLAG );
+#endif
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM1_DATA );
@@ -239,4 +247,8 @@
   m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
   m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
+#if QC_GENERIC_SDC_G0122
+  m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
+  m_cIntraSdcFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_INTRASDC_FLAG );
+#endif
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
@@ -925,5 +937,9 @@
     if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
 #if H_3D_DIM_SDC
+#if QC_GENERIC_SDC_G0122
+      if( 1 )
+#else
       if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
+#endif
 #endif
     {
@@ -943,5 +959,9 @@
     if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
 #if H_3D_DIM_SDC
+#if QC_GENERIC_SDC_G0122
+      if( 1 )
+#else
       if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
+#endif
 #endif
     {
@@ -1049,5 +1069,9 @@
   {
     UInt symbol;
+#if QC_GENERIC_SDC_G0122
+    UInt uiNumSegments = isDimMode( dir ) ? 2 : 1;
+#else
     UInt uiNumSegments = ( dir == PLANAR_IDX ) ? 1 : 2;
+#endif
 
     if( pcCU->getSDCFlag( absPartIdx ) )
@@ -1089,4 +1113,46 @@
 }
 
+#if QC_GENERIC_SDC_G0122
+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, pcCU->getCtxAngleFlag( absPartIdx ) ) );
+  }
+  else
+  {
+    uiSymbol = 1;
+  }
+  uiIsDimMode = uiSymbol ? 0 : 1;
+  pcCU->setLumaIntraDirSubParts( 0, absPartIdx, depth );
+
+  if( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N ) //SDC is allowed only in this case
+  {
+    m_pcTDecBinIf->decodeBin( uiSymbol, m_cIntraSdcFlagSCModel.get( 0, 0, pcCU->getCtxSDCFlag( absPartIdx ) ) );
+  }
+  else
+  {
+    uiSymbol = 0;
+  }
+
+  pcCU->setSDCFlagSubParts( uiSymbol, absPartIdx, depth );
+
+  //decode DMM index
+  if( uiIsDimMode )
+  {
+    m_pcTDecBinIf->decodeBin( uiSymbol, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
+    if( !uiSymbol )
+    {
+      pcCU->setLumaIntraDirSubParts( ( 2 * DMM1_IDX + DIM_OFFSET ), absPartIdx, depth );
+    }
+    else
+    {
+      pcCU->setLumaIntraDirSubParts( ( 2 * DMM4_IDX + DIM_OFFSET ), absPartIdx, depth );
+    }
+  }
+}
+#else
 Void TDecSbac::parseIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
 {
@@ -1151,4 +1217,5 @@
 #endif
 }
+#endif
 #endif
 
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibDecoder/TDecSbac.h	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibDecoder/TDecSbac.h	(revision 781)
@@ -211,4 +211,8 @@
   ContextModel3DBuffer m_cDdcFlagSCModel;
   ContextModel3DBuffer m_cDdcDataSCModel;
+#if QC_GENERIC_SDC_G0122
+  ContextModel3DBuffer m_cAngleFlagSCModel;
+  ContextModel3DBuffer m_cIntraSdcFlagSCModel;
+#endif
 #if H_3D_DIM_DMM
   ContextModel3DBuffer m_cDmm1DataSCModel;
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 781)
@@ -93,4 +93,8 @@
 , m_cDdcFlagSCModel           ( 1,             1,               NUM_DDC_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
 , m_cDdcDataSCModel           ( 1,             1,               NUM_DDC_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
+#if QC_GENERIC_SDC_G0122
+, m_cAngleFlagSCModel         ( 1,             1,               NUM_ANGLE_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cIntraSdcFlagSCModel      ( 1,             1,               NUM_INTRASDC_FLAG_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
 #if H_3D_DIM_DMM
 , m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
@@ -168,4 +172,8 @@
   m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
   m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
+#if QC_GENERIC_SDC_G0122
+  m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
+  m_cIntraSdcFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_INTRASDC_FLAG );
+#endif
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
@@ -252,4 +260,8 @@
       curCost += m_cDdcFlagSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_DDC_FLAG );
       curCost += m_cDdcDataSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_DDC_DATA );
+#if QC_GENERIC_SDC_G0122
+      curCost += m_cAngleFlagSCModel.calcCost         ( curSliceType, qp, (UChar*)INIT_ANGLE_FLAG );  
+      curCost += m_cIntraSdcFlagSCModel.calcCost      ( curSliceType, qp, (UChar*)INIT_INTRASDC_FLAG );  
+#endif
 #if H_3D_DIM_DMM
       curCost += m_cDmm1DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM1_DATA );
@@ -317,4 +329,8 @@
   m_cDdcFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG );
   m_cDdcDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DDC_DATA );
+#if QC_GENERIC_SDC_G0122
+  m_cAngleFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_ANGLE_FLAG );
+  m_cIntraSdcFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_INTRASDC_FLAG );
+#endif
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
@@ -629,4 +645,8 @@
   this->m_cDepthIntraModeSCModel .copyFrom( &pSrc->m_cDepthIntraModeSCModel );
   this->m_cDdcFlagSCModel        .copyFrom( &pSrc->m_cDdcFlagSCModel );
+#if QC_GENERIC_SDC_G0122
+  this->m_cAngleFlagSCModel      .copyFrom( &pSrc->m_cAngleFlagSCModel );
+  this->m_cIntraSdcFlagSCModel   .copyFrom( &pSrc->m_cIntraSdcFlagSCModel );
+#endif
 }
 #endif
@@ -1016,5 +1036,9 @@
     if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
 #if H_3D_DIM_SDC
+#if QC_GENERIC_SDC_G0122
+      if( 1 )
+#else
       if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
+#endif
 #endif
     {
@@ -1042,5 +1066,9 @@
     if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE )
 #if H_3D_DIM_SDC
+#if QC_GENERIC_SDC_G0122
+      if( 1 )
+#else
       if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) )
+#endif
 #endif
     {
@@ -1146,5 +1174,9 @@
     UInt dimDeltaDC;
     Pel  deltaDC;
+#if QC_GENERIC_SDC_G0122
+    UInt uiNumSegments = isDimMode( dir ) ? 2 : 1;
+#else
     UInt uiNumSegments = ( dir == PLANAR_IDX ) ? 1 : 2;
+#endif
     if( pcCU->getSDCFlag( absPartIdx ) )
     {
@@ -1176,4 +1208,34 @@
 }
 
+#if QC_GENERIC_SDC_G0122
+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, pcCU->getCtxAngleFlag( absPartIdx ) ) );
+  }
+
+  if( pcCU->getPartitionSize( absPartIdx ) == SIZE_2Nx2N ) //SDC is allowed only in this case
+  {
+    m_pcBinIf->encodeBin( pcCU->getSDCFlag( absPartIdx ) ? 1 : 0, m_cIntraSdcFlagSCModel.get( 0, 0, pcCU->getCtxSDCFlag( absPartIdx ) ) );
+  }
+
+  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
+    m_pcBinIf->encodeBin( uiCodeIdx == 0 ? 0 : 1, m_cDepthIntraModeSCModel.get( 0, 0, 0 ) );
+  }
+}
+#else
 Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx )
 {
@@ -1216,4 +1278,5 @@
   }
 }
+#endif
 #endif
 
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSbac.h	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSbac.h	(revision 781)
@@ -247,4 +247,8 @@
   ContextModel3DBuffer m_cDdcFlagSCModel;
   ContextModel3DBuffer m_cDdcDataSCModel;
+#if QC_GENERIC_SDC_G0122
+  ContextModel3DBuffer m_cAngleFlagSCModel;
+  ContextModel3DBuffer m_cIntraSdcFlagSCModel;
+#endif
 #if H_3D_DIM_DMM
   ContextModel3DBuffer m_cDmm1DataSCModel;
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 781)
@@ -1862,5 +1862,11 @@
 
 #if H_3D_DIM_SDC
-Void TEncSearch::xIntraCodingSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, Bool bResidual )
+Void TEncSearch::xIntraCodingSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, 
+#if QC_GENERIC_SDC_G0122
+  Bool bZeroResidual, Int iSDCDeltaResi
+#else
+  Bool bResidual
+#endif
+  )
 {
   UInt    uiLumaPredMode    = pcCU     ->getLumaIntraDir( uiAbsPartIdx );
@@ -1880,6 +1886,8 @@
   AOF( pcCU->getSDCAvailable(uiAbsPartIdx) );
   AOF( pcCU->getSDCFlag(uiAbsPartIdx) );
+#if !QC_GENERIC_SDC_G0122
   AOF( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX && !isDimDeltaDC( uiLumaPredMode ) ) );
   AOF( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || uiWidth < 64  );
+#endif
   
   //===== init availability pattern =====
@@ -1888,10 +1896,16 @@
   pcCU->getPattern()->initPattern   ( pcCU, 0, uiAbsPartIdx );
   pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail );
-  
+#if QC_GENERIC_SDC_G0122
+  TComWedgelet* dmm4Segmentation = new TComWedgelet( uiWidth, uiHeight );
+#endif
   //===== get prediction signal =====
 #if H_3D_DIM
   if( isDimMode( uiLumaPredMode ) )
   {
-    predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, true );
+    predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, true 
+#if QC_GENERIC_SDC_G0122
+      , dmm4Segmentation
+#endif
+      );
   }
   else
@@ -1919,5 +1933,13 @@
     uiMaskStride = pcWedgelet->getStride();
   }
-  
+#if QC_GENERIC_SDC_G0122
+  if( getDimType( uiLumaPredMode ) == DMM4_IDX )
+  {
+    uiNumSegments = 2;
+    pbMask  = dmm4Segmentation->getPattern();
+    uiMaskStride = dmm4Segmentation->getStride();
+  }
+#endif
+
   // get DC prediction for each segment
   Pel apDCPredValues[2];
@@ -1931,6 +1953,9 @@
   {
     // remap reconstructed value to valid depth values
+#if QC_GENERIC_SDC_G0122
+    Pel pDCRec = ( !bZeroResidual ) ? apDCOrigValues[uiSegment] : apDCPredValues[uiSegment];
+#else
     Pel pDCRec = bResidual?apDCOrigValues[uiSegment]:apDCPredValues[uiSegment];
-    
+#endif
     // get residual (idx)
 #if H_3D_DIM_DLT
@@ -1939,5 +1964,15 @@
     Pel pResidualIdx = pDCRec - apDCPredValues[uiSegment];
 #endif
-    
+#if QC_GENERIC_SDC_G0122
+    if( !bZeroResidual )
+    {
+      Pel   pPredIdx    = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );
+      Int   pTestIdx    = pPredIdx + pResidualIdx + iSDCDeltaResi;
+      if( pTestIdx >= 0 && pTestIdx < pcCU->getSlice()->getPPS()->getDLT()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ) )
+      {
+        pResidualIdx += iSDCDeltaResi;
+      }
+    }
+#endif
     // save SDC DC offset
     pcCU->setSDCSegmentDCOffset(pResidualIdx, uiSegment, uiAbsPartIdx);
@@ -2024,4 +2059,7 @@
 #endif
     dRDCost = m_pcRdCost->calcRdCost( uiBits, ruiDist );
+#if QC_GENERIC_SDC_G0122
+  dmm4Segmentation->destroy(); delete dmm4Segmentation;
+#endif
 }
 #endif
@@ -2901,5 +2939,7 @@
           case( DMM4_IDX ):
             {
+#if !QC_GENERIC_SDC_G0122
               if( uiWidth > 4 )
+#endif
               {
                 biSegmentation = new TComWedgelet( uiWidth, uiHeight );
@@ -2957,4 +2997,12 @@
       {
         pcCU->setSDCFlagSubParts( (uiSDC != 0), uiPartOffset, uiDepth + uiInitTrDepth );
+#if QC_GENERIC_SDC_G0122
+        for( Int iSDCDeltaResi = -2; iSDCDeltaResi <= 2; iSDCDeltaResi++ )
+        {
+          if( ( uiSDC == 0 ) && iSDCDeltaResi != 0 )
+          {
+            continue;
+          }
+#endif
 #endif
       
@@ -2966,4 +3014,10 @@
 #if H_3D_DIM_SDC
       bTestZeroResi |= pcCU->getSDCFlag(uiPartOffset);
+#endif
+#if QC_GENERIC_SDC_G0122
+      if( uiSDC != 0 && iSDCDeltaResi != 0 )
+      {
+        bTestZeroResi = false;
+      }
 #endif
 #endif
@@ -3000,5 +3054,9 @@
               
               // start encoding with SDC
+#if QC_GENERIC_SDC_G0122
+              xIntraCodingSDC(pcCU, uiPartOffset, pcOrgYuv, pcPredYuv, uiPUDistY, dPUCost, ( testZeroResi != 0 ), iSDCDeltaResi );
+#else
               xIntraCodingSDC(pcCU, uiPartOffset, pcOrgYuv, pcPredYuv, uiPUDistY, dPUCost, (testZeroResi!=0));
+#endif
             }
             else
@@ -3073,4 +3131,7 @@
 #if H_3D_DIM_ENC || H_3D_DIM_SDC
       }
+#endif
+#if QC_GENERIC_SDC_G0122
+        } // SDC residual loop
 #endif
 #if H_3D_DIM_SDC
Index: branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSearch.h	(revision 778)
+++ branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibEncoder/TEncSearch.h	(revision 781)
@@ -353,5 +353,11 @@
 #endif
 #if H_3D_DIM_SDC
-  Void xIntraCodingSDC            ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, Bool bResidual );
+  Void xIntraCodingSDC            ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, 
+#if QC_GENERIC_SDC_G0122
+    Bool bZeroResidual, Int iSDCDeltaResi
+#else
+    Bool bResidual
+#endif
+    );
 #endif
 #endif
