Index: branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1486)
+++ branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1487)
@@ -57,5 +57,5 @@
 
 
-
+#if !SCALABLE_REXT
 enum ExtendedProfileName // this is used for determining profile strings, where multiple profiles map to a single profile idc with various constraint flag combinations
 {
@@ -70,4 +70,7 @@
   SCALABLEMAIN = 7,
   SCALABLEMAIN10 = 8,
+#if SCALABLE_REXT
+  SCALABLEREXT = 10,
+#endif
 #endif
   // The following are RExt profiles, which would map to the MAINREXT profile idc.
@@ -75,5 +78,6 @@
   //                           the chroma format in the next digit
   //                           the intra constraint in the next digit
-  //                           If it is a RExt still picture, there is a '1' for the top digit.
+  //                           If it is a RExt still picture, there is a '1' for the next digit,
+  //                           If it is a Scalable Rext profile, there is a '1' for the top digit.
   MONOCHROME_8      = 1008,
   MONOCHROME_12     = 1012,
@@ -97,5 +101,13 @@
   MAIN_444_STILL_PICTURE = 11308,
   MAIN_444_16_STILL_PICTURE = 12316
+#if SCALABLE_REXT
+  ,
+  SCALABLE_MONOCHROME_8   = 101008,
+  SCALABLE_MONOCHROME_12  = 101012,
+  SCALABLE_MONOCHROME_16  = 101016,
+  SCALABLE_MAIN_444       = 101308
+#endif
 };
+#endif
 
 
@@ -257,4 +269,7 @@
   {"scalable-main",        Profile::SCALABLEMAIN       },
   {"scalable-main10",      Profile::SCALABLEMAIN10     },
+#if SCALABLE_REXT
+  {"scalable-Rext",        Profile::SCALABLEREXT     },
+#endif
 #endif
 };
@@ -305,4 +320,10 @@
     {"scalable-main",             SCALABLEMAIN     },
     {"scalable-main10",           SCALABLEMAIN10   },
+#if SCALABLE_REXT
+    {"scalable-monochrome",       SCALABLE_MONOCHROME_8   },
+    {"scalable-monochrome12",     SCALABLE_MONOCHROME_12  },
+    {"scalable-monochrome16",     SCALABLE_MONOCHROME_16  },
+    {"scalable-main_444",         SCALABLE_MAIN_444       },
+#endif
 #endif
 };
@@ -1074,5 +1095,5 @@
   ("OutputBitDepth%d",                               cfg_OutputBitDepth[CHANNEL_TYPE_LUMA],    0, m_numLayers, "Bit-depth of output file (default:InternalBitDepth)")
   ("InputBitDepthC%d",                               cfg_InputBitDepth[CHANNEL_TYPE_CHROMA],   0, m_numLayers, "As per InputBitDepth but for chroma component. (default:InputBitDepth) for layer %d")
-  ("InternalBitDepthC%d",                            cfg_InternalBitDepth[CHANNEL_TYPE_CHROMA],0, m_numLayers, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth) for layer %d")
+  ("InternalBitDepthC%d",                            cfg_InternalBitDepth[CHANNEL_TYPE_CHROMA],0, m_numLayers, "As per InternalBitDepth but for chroma component. (default:InternalBitDepth) for layer %d")
   ("OutputBitDepthC%d",                              cfg_OutputBitDepth[CHANNEL_TYPE_CHROMA],  0, m_numLayers, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
 
@@ -1791,4 +1812,7 @@
   
 #if SVC_EXTENSION
+#if SCALABLE_REXT
+  Int cfgTmpConstraintChromaFormat = tmpConstraintChromaFormat;
+#endif
   for( Int layer = 0; layer < m_numLayers; layer++ )
   {
@@ -1854,5 +1878,14 @@
       m_profileList[layerPTLIdx] = Profile::MAINREXT;            
 
+#if SCALABLE_REXT
+      if(m_numLayers > 1 && layer == 0 )
+      {
+        m_profileList[0] = extendedToShortProfileName(extendedProfile[0]);
+      }
+
+      if( m_apcLayerCfg[layer]->m_bitDepthConstraint != 0 || cfgTmpConstraintChromaFormat != 0)
+#else
       if( m_apcLayerCfg[layer]->m_bitDepthConstraint != 0 || tmpConstraintChromaFormat != 0)
+#endif
       {
         fprintf(stderr, "Error: The bit depth and chroma format constraints are not used when an explicit RExt profile is specified\n");
@@ -1869,9 +1902,34 @@
       }
     }
+#if SCALABLE_REXT
+    else if(extendedProfile[layerPTLIdx] >= 101008 && extendedProfile[layerPTLIdx] <= 101308)
+    {
+      m_profileList[layerPTLIdx] = Profile::SCALABLEREXT;
+      
+      if( m_apcLayerCfg[layer]->m_bitDepthConstraint != 0 || cfgTmpConstraintChromaFormat != 0)
+      {
+        fprintf(stderr, "Error: The bit depth and chroma format constraints are not used when an explicit Scalabe-RExt profile is specified\n");
+        exit(EXIT_FAILURE);
+      }
+      m_apcLayerCfg[layer]->m_bitDepthConstraint  = (extendedProfile[layerPTLIdx]%100);
+      m_apcLayerCfg[layer]->m_intraConstraintFlag = 0; // no all-intra constraint for scalable-Rext profiles 
+      switch ((extendedProfile[layerPTLIdx]/100)%10)
+      {
+        case 0:  tmpConstraintChromaFormat=400; break;
+        case 1:  tmpConstraintChromaFormat=420; break;
+        case 2:  tmpConstraintChromaFormat=422; break;
+        default: tmpConstraintChromaFormat=444; break;
+      }
+    }
+#endif
     else
     {
       if( layer == 0 )
       {
+#if SCALABLE_REXT
+        m_profileList[0] = extendedToShortProfileName(extendedProfile[0]);
+#else
         m_profileList[0] = Profile::Name(extendedProfile[0]);
+#endif
       }
 
@@ -1884,5 +1942,9 @@
       m_apcLayerCfg[layer]->m_chromaFormatConstraint = (tmpConstraintChromaFormat == 0) ? CHROMA_444 : numberToChromaFormat(tmpConstraintChromaFormat);
     }
+#if SCALABLE_REXT
+    else if( m_profileList[layerPTLIdx] == Profile::MAINREXT || m_profileList[layerPTLIdx] == Profile::SCALABLEREXT )
+#else
     else if( m_profileList[layerPTLIdx] == Profile::MAINREXT )
+#endif
     {
       if( m_apcLayerCfg[layer]->m_bitDepthConstraint == 0 && tmpConstraintChromaFormat == 0 )
@@ -1923,4 +1985,24 @@
       m_apcLayerCfg[layer]->m_bitDepthConstraint = (m_profileList[layerPTLIdx] == Profile::MAIN10 || m_profileList[layerPTLIdx] == Profile::SCALABLEMAIN10) ? 10 : 8;
     }
+#if FORMATIDX_CHECK
+    for(Int compareLayer = layer+1; compareLayer < m_numLayers; compareLayer++ )
+    {
+      if(m_apcLayerCfg[layer]->m_repFormatIdx == m_apcLayerCfg[compareLayer]->m_repFormatIdx && (
+           m_apcLayerCfg[layer]->m_chromaFormatIDC != m_apcLayerCfg[compareLayer]->m_chromaFormatIDC
+           // separate_colour_plane_flag not supported yet but if supported insert check here
+           || m_apcLayerCfg[layer]->m_iSourceWidth != m_apcLayerCfg[compareLayer]->m_iSourceWidth
+           || m_apcLayerCfg[layer]->m_iSourceHeight != m_apcLayerCfg[compareLayer]->m_iSourceHeight
+           || m_apcLayerCfg[layer]->m_internalBitDepth != m_apcLayerCfg[compareLayer]->m_internalBitDepth
+           || m_apcLayerCfg[layer]->m_confWinLeft != m_apcLayerCfg[compareLayer]->m_confWinLeft
+           || m_apcLayerCfg[layer]->m_confWinRight != m_apcLayerCfg[compareLayer]->m_confWinRight
+           || m_apcLayerCfg[layer]->m_confWinTop != m_apcLayerCfg[compareLayer]->m_confWinTop
+           || m_apcLayerCfg[layer]->m_confWinBottom != m_apcLayerCfg[compareLayer]->m_confWinBottom
+        ))
+      {
+        fprintf(stderr, "Error: Two layers using the same FormatIdx value must share the same values of the related parameters\n");
+        exit(EXIT_FAILURE);
+      }
+    }
+#endif
   }
 #else
@@ -2558,8 +2640,15 @@
     ChromaFormat& m_chromaFormatIDC = m_apcLayerCfg[layer]->m_chromaFormatIDC;
 
+#if SCALABLE_REXT
+    Int& m_confWinLeft              = m_apcLayerCfg[layer]->m_confWinLeft;
+    Int& m_confWinRight             = m_apcLayerCfg[layer]->m_confWinRight;
+    Int& m_confWinTop               = m_apcLayerCfg[layer]->m_confWinTop;
+    Int& m_confWinBottom            = m_apcLayerCfg[layer]->m_confWinBottom;
+#else
     Int& m_confWinLeft              = m_apcLayerCfg[layer]->m_confWinLeft;
     Int& m_confWinRight             = m_apcLayerCfg[layer]->m_confWinLeft;
     Int& m_confWinTop               = m_apcLayerCfg[layer]->m_confWinLeft;
     Int& m_confWinBottom            = m_apcLayerCfg[layer]->m_confWinLeft;
+#endif
     Int* m_aiPad                    = m_apcLayerCfg[layer]->m_aiPad;
     Int* m_aidQP                    = m_apcLayerCfg[layer]->m_aidQP;
@@ -3110,9 +3199,17 @@
   xConfirmPara(m_chromaFormatConstraint<m_chromaFormatIDC, "The chroma format used must not be greater than the chromaFormatConstraint value");
 
+#if SCALABLE_REXT
+  if (m_profile==Profile::MAINREXT || m_profile==Profile::HIGHTHROUGHPUTREXT || m_profile==Profile::SCALABLEREXT)
+#else
   if (m_profile==Profile::MAINREXT || m_profile==Profile::HIGHTHROUGHPUTREXT)
+#endif
   {
     xConfirmPara(m_lowerBitRateConstraintFlag==false && m_intraConstraintFlag==false, "The lowerBitRateConstraint flag cannot be false when intraConstraintFlag is false");
     xConfirmPara(m_cabacBypassAlignmentEnabledFlag && m_profile!=Profile::HIGHTHROUGHPUTREXT, "AlignCABACBeforeBypass must not be enabled unless the high throughput profile is being used.");
+#if SCALABLE_REXT
+    if (m_profile == Profile::MAINREXT || m_profile==Profile::SCALABLEREXT)
+#else
     if (m_profile == Profile::MAINREXT)
+#endif
     {
       const UInt intraIdx = m_intraConstraintFlag ? 1:0;
@@ -3162,4 +3259,22 @@
     xConfirmPara(m_bitDepthConstraint!=((m_profile==Profile::MAIN10)?10:8), "BitDepthConstraint must be 8 for MAIN profile and 10 for MAIN10 profile.");
 #endif
+#if SCALABLE_REXT // changes below are only about displayed text
+    xConfirmPara(m_chromaFormatConstraint!=CHROMA_420, "ChromaFormatConstraint must be 420 for non main-RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_intraConstraintFlag==true, "IntraConstraintFlag must be false for non main_RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_lowerBitRateConstraintFlag==false, "LowerBitrateConstraintFlag must be true for non main-RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_profile == Profile::MAINSTILLPICTURE && m_framesToBeEncoded > 1, "Number of frames to be encoded must be 1 when main still picture profile is used.");
+
+    xConfirmPara(m_crossComponentPredictionEnabledFlag==true, "CrossComponentPrediction must not be used for non main-RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_log2MaxTransformSkipBlockSize!=2, "Transform Skip Log2 Max Size must be 2 for V1 profiles.");
+    xConfirmPara(m_transformSkipRotationEnabledFlag==true, "UseResidualRotation must not be enabled for non main-RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_transformSkipContextEnabledFlag==true, "UseSingleSignificanceMapContext must not be enabled for non main-RExt nand on scalable-Rext profiles.");
+    xConfirmPara(m_rdpcmEnabledFlag[RDPCM_SIGNAL_IMPLICIT]==true, "ImplicitResidualDPCM must not be enabled for non main-RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_rdpcmEnabledFlag[RDPCM_SIGNAL_EXPLICIT]==true, "ExplicitResidualDPCM must not be enabled for non main-RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_persistentRiceAdaptationEnabledFlag==true, "GolombRiceParameterAdaption must not be enabled for non main-RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_extendedPrecisionProcessingFlag==true, "UseExtendedPrecision must not be enabled for non main-RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_highPrecisionOffsetsEnabledFlag==true, "UseHighPrecisionPredictionWeighting must not be enabled for non main-RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_enableIntraReferenceSmoothing==false, "EnableIntraReferenceSmoothing must be enabled for non main-RExt and non scalable-Rext profiles.");
+    xConfirmPara(m_cabacBypassAlignmentEnabledFlag, "AlignCABACBeforeBypass cannot be enabled for non main-RExt and non scalable-Rext profiles.");
+#else
     xConfirmPara(m_chromaFormatConstraint!=CHROMA_420, "ChromaFormatConstraint must be 420 for non main-RExt profiles.");
     xConfirmPara(m_intraConstraintFlag==true, "IntraConstraintFlag must be false for non main_RExt profiles.");
@@ -3178,4 +3293,5 @@
     xConfirmPara(m_enableIntraReferenceSmoothing==false, "EnableIntraReferenceSmoothing must be enabled for non main-RExt profiles.");
     xConfirmPara(m_cabacBypassAlignmentEnabledFlag, "AlignCABACBeforeBypass cannot be enabled for non main-RExt profiles.");
+#endif
   }
 
@@ -4029,8 +4145,15 @@
     UInt& m_uiMaxCUDepth                   = m_apcLayerCfg[layerIdx]->m_uiMaxCUDepth;
 
+#if SCALABLE_REXT
+    Int& m_confWinLeft                     = m_apcLayerCfg[layerIdx]->m_confWinLeft;
+    Int& m_confWinRight                    = m_apcLayerCfg[layerIdx]->m_confWinRight;
+    Int& m_confWinTop                      = m_apcLayerCfg[layerIdx]->m_confWinTop;
+    Int& m_confWinBottom                   = m_apcLayerCfg[layerIdx]->m_confWinBottom;
+#else
     Int& m_confWinLeft                     = m_apcLayerCfg[layerIdx]->m_confWinLeft;
     Int& m_confWinRight                    = m_apcLayerCfg[layerIdx]->m_confWinLeft;
     Int& m_confWinTop                      = m_apcLayerCfg[layerIdx]->m_confWinLeft;
     Int& m_confWinBottom                   = m_apcLayerCfg[layerIdx]->m_confWinLeft;
+#endif
 
     Int& m_iSourceWidth                    = m_apcLayerCfg[layerIdx]->m_iSourceWidth;
Index: branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 1486)
+++ branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 1487)
@@ -49,4 +49,58 @@
 //! \ingroup TAppEncoder
 //! \{
+
+#if SCALABLE_REXT
+enum ExtendedProfileName // this is used for determining profile strings, where multiple profiles map to a single profile idc with various constraint flag combinations
+{
+  NONE = 0,
+  MAIN = 1,
+  MAIN10 = 2,
+  MAINSTILLPICTURE = 3,
+  MAINREXT = 4,
+  HIGHTHROUGHPUTREXT = 5, // Placeholder profile for development
+#if SVC_EXTENSION
+  MULTIVIEWMAIN = 6,
+  SCALABLEMAIN = 7,
+  SCALABLEMAIN10 = 8,
+#if SCALABLE_REXT
+  SCALABLEREXT = 10,
+#endif
+#endif
+  // The following are RExt profiles, which would map to the MAINREXT profile idc.
+  // The enumeration indicates the bit-depth constraint in the bottom 2 digits
+  //                           the chroma format in the next digit
+  //                           the intra constraint in the next digit
+  //                           If it is a RExt still picture, there is a '1' for the next digit,
+  //                           If it is a Scalable Rext profile, there is a '1' for the top digit.
+  MONOCHROME_8      = 1008,
+  MONOCHROME_12     = 1012,
+  MONOCHROME_16     = 1016,
+  MAIN_12           = 1112,
+  MAIN_422_10       = 1210,
+  MAIN_422_12       = 1212,
+  MAIN_444          = 1308,
+  MAIN_444_10       = 1310,
+  MAIN_444_12       = 1312,
+  MAIN_444_16       = 1316, // non-standard profile definition, used for development purposes
+  MAIN_INTRA        = 2108,
+  MAIN_10_INTRA     = 2110,
+  MAIN_12_INTRA     = 2112,
+  MAIN_422_10_INTRA = 2210,
+  MAIN_422_12_INTRA = 2212,
+  MAIN_444_INTRA    = 2308,
+  MAIN_444_10_INTRA = 2310,
+  MAIN_444_12_INTRA = 2312,
+  MAIN_444_16_INTRA = 2316,
+  MAIN_444_STILL_PICTURE = 11308,
+  MAIN_444_16_STILL_PICTURE = 12316
+#if SCALABLE_REXT
+  ,
+  SCALABLE_MONOCHROME_8   = 101008,
+  SCALABLE_MONOCHROME_12  = 101012,
+  SCALABLE_MONOCHROME_16  = 101016,
+  SCALABLE_MAIN_444       = 101308
+#endif
+};
+#endif
 
 // ====================================================================================================================
@@ -583,4 +637,22 @@
   Bool scanStringToArrayNumEntries(string const cfgString, Int &numEntries, const char* logString, std::vector<Int> &  returnVector);
   Void cfgStringToArrayNumEntries(Int **arr, string const cfgString, Int &numEntries, const char* logString);
+
+#if SCALABLE_REXT
+  Profile::Name extendedToShortProfileName(ExtendedProfileName uiExtendedProfileName)
+  {
+    if(uiExtendedProfileName < MONOCHROME_8)
+    {
+      return Profile::Name(uiExtendedProfileName);
+    }
+    else if(uiExtendedProfileName < SCALABLE_MONOCHROME_8)
+    {
+      return Profile::MAINREXT;
+    }
+    else
+    {
+      return Profile::SCALABLEREXT;
+    }
+  }
+#endif
 #endif
 };// END CLASS DEFINITION TAppEncCfg
Index: branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 1486)
+++ branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 1487)
@@ -50,4 +50,10 @@
   ::memset(m_phaseHorChroma, 0, sizeof(m_phaseHorChroma));
   ::memset(m_phaseVerChroma, 0, sizeof(m_phaseVerChroma));
+#if SCALABLE_REXT
+  // variables uninitialized otherwise
+  m_intraConstraintFlag = false;
+  m_lowerBitRateConstraintFlag = false;
+  m_onePictureOnlyConstraintFlag = false; 
+#endif
 }
 
Index: branches/SHM-dev/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 1487)
@@ -292,4 +292,31 @@
 Void TComPic::copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut)
 {
+#if SCALABLE_REXT
+  Int upsampledRowWidthLuma = pcPicYuvOut->getStride(COMPONENT_Y); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth(); 
+  copyOnetoOnePicture(
+    pcPicYuvIn->getAddr(COMPONENT_Y),        
+    pcPicYuvOut->getAddr(COMPONENT_Y),      
+    pcPicYuvOut->getWidth(COMPONENT_Y), 
+    pcPicYuvOut->getHeight(COMPONENT_Y),
+    upsampledRowWidthLuma);
+
+  if(pcPicYuvOut->getChromaFormat() != CHROMA_400)
+  {
+    Int upsampledRowWidthChroma = pcPicYuvOut->getStride(COMPONENT_Cb); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1);
+
+    copyOnetoOnePicture(
+      pcPicYuvIn->getAddr(COMPONENT_Cr),        
+      pcPicYuvOut->getAddr(COMPONENT_Cr),      
+      pcPicYuvOut->getWidth(COMPONENT_Cr), 
+      pcPicYuvOut->getHeight(COMPONENT_Cr),
+      upsampledRowWidthChroma);
+    copyOnetoOnePicture(
+      pcPicYuvIn->getAddr(COMPONENT_Cb),        
+      pcPicYuvOut->getAddr(COMPONENT_Cb),      
+      pcPicYuvOut->getWidth(COMPONENT_Cb), 
+      pcPicYuvOut->getHeight(COMPONENT_Cb),
+      upsampledRowWidthChroma);
+  }
+#else
   Int upsampledRowWidthLuma = pcPicYuvOut->getStride(COMPONENT_Y); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth(); 
   Int upsampledRowWidthCroma = pcPicYuvOut->getStride(COMPONENT_Cb); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1);
@@ -313,4 +340,5 @@
     pcPicYuvOut->getHeight(COMPONENT_Y)>>1,
     upsampledRowWidthCroma);
+#endif
 }
 
Index: branches/SHM-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 1487)
@@ -85,6 +85,17 @@
   if( !resamplingPhase.phasePresentFlag )
   {
+#if SCALABLE_REXT
+    if(chromaFormatIdc == 3)
+    {
+      phaseVerChroma = 0;
+    }
+    else
+    {
+#endif
     Int refRegionHeight = heightBL - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
     phaseVerChroma = (4 * heightEL + (refRegionHeight >> 1)) / refRegionHeight - 4;
+#if SCALABLE_REXT
+    }
+#endif
   }
 
@@ -139,4 +150,8 @@
     }
 
+#if SCALABLE_REXT
+  if(chromaFormatIdc != 0)
+  {
+#endif
     widthEL  >>= 1;
     heightEL >>= 1;
@@ -177,4 +192,7 @@
       piDstV += strideEL;
     }
+#if SCALABLE_REXT
+  }
+#endif
   }
   else // general resampling process
@@ -290,4 +308,8 @@
     //========== UV component upsampling ===========
 
+#if SCALABLE_REXT
+  if(chromaFormatIdc != 0)
+  {
+#endif
     widthEL  >>= 1;
     heightEL >>= 1;
@@ -396,4 +418,7 @@
       }
     }
+#if SCALABLE_REXT
+    }
+#endif
   }
     pcUsPic->setBorderExtension(false);
Index: branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h	(revision 1487)
@@ -48,4 +48,7 @@
 
 #if SVC_EXTENSION
+#define SCALABLE_REXT                    1
+#define FORMATIDX_CHECK                  1
+
 #define MAX_LAYERS                       8      ///< max number of layers the codec is supposed to handle
 
@@ -197,5 +200,5 @@
 // This can be enabled by the makefile
 #ifndef RExt__HIGH_BIT_DEPTH_SUPPORT
-#define RExt__HIGH_BIT_DEPTH_SUPPORT                      0 ///< 0 (default) use data type definitions for 8-10 bit video, 1 = use larger data types to allow for up to 16-bit video (originally developed as part of N0188)
+#define RExt__HIGH_BIT_DEPTH_SUPPORT                      1 ///< 0 (default) use data type definitions for 8-10 bit video, 1 = use larger data types to allow for up to 16-bit video (originally developed as part of N0188)
 #endif
 
@@ -644,4 +647,7 @@
     SCALABLEMAIN = 7,
     SCALABLEMAIN10 = 8,
+#if SCALABLE_REXT
+    SCALABLEREXT = 10
+#endif
 #endif
   };
Index: branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1487)
@@ -681,5 +681,9 @@
 }
 
+#if SCALABLE_REXT
+Void TDecCavlc::parseSPS(TComSPS* pcSPS, ParameterSetManager* pcParamSetManager)
+#else
 Void TDecCavlc::parseSPS(TComSPS* pcSPS)
+#endif
 {
 #if ENC_DEC_TRACE
@@ -689,5 +693,7 @@
   UInt  uiCode;
   READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
-
+#if SCALABLE_REXT
+  const TComVPS* pTmpVPS = pcParamSetManager->getVPS(pcSPS->getVPSId()); 
+#endif
 #if SVC_EXTENSION
   UInt uiTmp = 0;
@@ -742,4 +748,23 @@
       pcSPS->setUpdateRepFormatIndex(uiCode);
     }
+#if SCALABLE_REXT
+    // If update_rep_format_flag is equal to 0, the variable repFormatIdx is set equal to vps_rep_format_idx[ LayerIdxInVps[ layerIdCurr ] ].
+    else
+    {
+      Int iVPSRepFormatIdx = pTmpVPS->getVpsRepFormatIdx( pTmpVPS->getLayerIdxInVps( pcSPS->getLayerId() ) );
+      pcSPS->setUpdateRepFormatIndex( iVPSRepFormatIdx );
+
+      pcSPS->setChromaFormatIdc(              pTmpVPS->getVpsRepFormat(iVPSRepFormatIdx)->getChromaFormatVpsIdc() );
+      pcSPS->setPicWidthInLumaSamples(        pTmpVPS->getVpsRepFormat(iVPSRepFormatIdx)->getPicWidthVpsInLumaSamples() );
+      pcSPS->setPicHeightInLumaSamples(       pTmpVPS->getVpsRepFormat(iVPSRepFormatIdx)->getPicHeightVpsInLumaSamples() );
+      pcSPS->setBitDepth(CHANNEL_TYPE_LUMA,   pTmpVPS->getVpsRepFormat(iVPSRepFormatIdx)->getBitDepthVpsLuma() );
+      pcSPS->setBitDepth(CHANNEL_TYPE_CHROMA, pTmpVPS->getVpsRepFormat(iVPSRepFormatIdx)->getBitDepthVpsChroma() );
+      Window &conf = pcSPS->getConformanceWindow();
+      conf.setWindowLeftOffset(               pTmpVPS->getVpsRepFormat(iVPSRepFormatIdx)->getConformanceWindowVps().getWindowLeftOffset() );
+      conf.setWindowRightOffset(              pTmpVPS->getVpsRepFormat(iVPSRepFormatIdx)->getConformanceWindowVps().getWindowRightOffset() );
+      conf.setWindowTopOffset(                pTmpVPS->getVpsRepFormat(iVPSRepFormatIdx)->getConformanceWindowVps().getWindowTopOffset() );
+      conf.setWindowBottomOffset(             pTmpVPS->getVpsRepFormat(iVPSRepFormatIdx)->getConformanceWindowVps().getWindowBottomOffset() );
+    }
+#endif
   }
   else
@@ -2166,5 +2191,9 @@
 
   if (ptl->getProfileIdc() == Profile::MAINREXT           || ptl->getProfileCompatibilityFlag(Profile::MAINREXT) ||
-      ptl->getProfileIdc() == Profile::HIGHTHROUGHPUTREXT || ptl->getProfileCompatibilityFlag(Profile::HIGHTHROUGHPUTREXT))
+      ptl->getProfileIdc() == Profile::HIGHTHROUGHPUTREXT || ptl->getProfileCompatibilityFlag(Profile::HIGHTHROUGHPUTREXT
+#if SCALABLE_REXT
+      || ptl->getProfileIdc() == Profile::SCALABLEREXT
+#endif
+      ))
   {
     UInt maxBitDepth=16;
@@ -2979,5 +3008,10 @@
             ProfileTierLevel* ptl = vps->getPTL(vps->getProfileLevelTierIdx(i, j))->getGeneralPTL();
             numIncludedLayers++;
+#if SCALABLE_REXT
+            // if scalable profile is Scalable Main 10 or Scalable Rext, dimension_id = 2
+            const Profile::Name profileName = ( ptl->getProfileIdc() == Profile::SCALABLEMAIN10 || ptl->getProfileIdc() == Profile::SCALABLEREXT ) ? Profile::SCALABLEMAIN : ptl->getProfileIdc();
+#else
             const Profile::Name profileName = ptl->getProfileIdc() == Profile::SCALABLEMAIN10 ? Profile::SCALABLEMAIN : ptl->getProfileIdc();
+#endif
 
             for( Int p = 0; p < profiles.size(); p++ )
Index: branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 1487)
@@ -76,5 +76,9 @@
   Void  parseQtRootCbf      ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
   Void  parseVPS            ( TComVPS* pcVPS );
+#if SCALABLE_REXT
+  Void  parseSPS            ( TComSPS* pcSPS, ParameterSetManager* pcParamSetManager );
+#else
   Void  parseSPS            ( TComSPS* pcSPS );
+#endif
 #if !SVC_EXTENSION
   Void  parsePPS            ( TComPPS* pcPPS );
Index: branches/SHM-dev/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibDecoder/TDecEntropy.h	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibDecoder/TDecEntropy.h	(revision 1487)
@@ -70,5 +70,9 @@
 
   virtual Void  parseVPS                  ( TComVPS* pcVPS )     = 0;
+#if SCALABLE_REXT
+  virtual Void  parseSPS                  ( TComSPS* pcSPS, ParameterSetManager* pcParamSetManager )     = 0;
+#else
   virtual Void  parseSPS                  ( TComSPS* pcSPS )     = 0;
+#endif
 #if CGS_3D_ASYMLUT
   virtual Void  parsePPS                  ( TComPPS* pcPPS, TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID )     = 0;
@@ -143,5 +147,9 @@
 
   Void    decodeVPS                   ( TComVPS* pcVPS ) { m_pcEntropyDecoderIf->parseVPS(pcVPS); }
+#if SCALABLE_REXT
+  Void    decodeSPS                   ( TComSPS* pcSPS, ParameterSetManager* pcParamSetManager ) { m_pcEntropyDecoderIf->parseSPS(pcSPS, pcParamSetManager); }
+#else
   Void    decodeSPS                   ( TComSPS* pcSPS ) { m_pcEntropyDecoderIf->parseSPS(pcSPS); }
+#endif
 
 #if CGS_3D_ASYMLUT
Index: branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.h	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.h	(revision 1487)
@@ -78,5 +78,9 @@
   Void  setBitstream              ( TComInputBitstream* p  ) { m_pcBitstream = p; m_pcTDecBinIf->init( p ); }
   Void  parseVPS                  ( TComVPS* /*pcVPS*/ ) {}
+#if SCALABLE_REXT
+  Void  parseSPS                  (TComSPS*  /*pcSPS*/, ParameterSetManager* /*pcParamSetManager*/ ) {}
+#else
   Void  parseSPS                  ( TComSPS* /*pcSPS*/ ) {}
+#endif
 #if CGS_3D_ASYMLUT
   Void  parsePPS                  ( TComPPS* /*pcPPS*/, TCom3DAsymLUT * /*pc3DAsymLUT*/, Int /*nLayerID*/ ) {}
Index: branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1487)
@@ -1939,5 +1939,9 @@
   sps->setLayerId(m_layerId);
 #endif
+#if SCALABLE_REXT
+  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManager );
+#else
   m_cEntropyDecoder.decodeSPS( sps );
+#endif
   m_parameterSetManager.storeSPS(sps, naluData);
 }
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp	(revision 1487)
@@ -218,13 +218,25 @@
         if( rCuboidColorInfo.N > 0 )
         {
+#if SCALABLE_REXT
+          dErrorLuma += xCalEstPelDist( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
+            rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y );
+#else
           dErrorLuma += xCalEstDist( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
             rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y );
+#endif
         }
         if( rCuboidColorInfoC.N > 0 )
         {
+#if SCALABLE_REXT
+          dErrorChroma += xCalEstPelDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
+            rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U );
+          dErrorChroma += xCalEstPelDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
+            rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V );
+#else
           dErrorChroma += xCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
             rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U );
           dErrorChroma += xCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
             rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V );
+#endif
         }
       }
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.h	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.h	(revision 1487)
@@ -175,7 +175,13 @@
 
   inline Double xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Double a, Double b, Double c, Double d );
-
+#if SCALABLE_REXT
+/* 
+former xCalEstDist(Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Pel, Pel, Pel, Pel)
+replaced by this fucntion because behaving differently than other xCalEstDist and was conflicting with xCalEstDist when RExt__HIGH_BIT_DEPTH_SUPPORT = 1
+*/
+  inline Double xCalEstPelDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 );
+#else
   inline Double xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 );
-
+#endif
 #if R0179_ENC_OPT_3DLUT_SIZE
   Void    xConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize );
@@ -202,5 +208,11 @@
 };
 
-Double TEnc3DAsymLUT::xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 )  
+
+#if SCALABLE_REXT
+/* 
+former xCalEstDist(Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Pel, Pel, Pel, Pel)
+replaced by this fucntion because behaving differently than other xCalEstDist and was conflicting with xCalEstDist when RExt__HIGH_BIT_DEPTH_SUPPORT = 1
+*/
+Double TEnc3DAsymLUT::xCalEstPelDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 )  
 {
   const Int nOne = xGetNormCoeffOne();
@@ -212,6 +224,18 @@
   return( dError );
 };
-
-#endif
-
-#endif
+#else
+Double TEnc3DAsymLUT::xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 )  
+{
+  const Int nOne = xGetNormCoeffOne();
+  Double a = 1.0 * nP0 / nOne;
+  Double b = 1.0 * nP1 / nOne;
+  Double c = 1.0 * nP3 / nOne;
+  Double d = nP7;
+  Double dError = N * d * d + 2 * b * c * uv + 2 * a * c * yv + 2 * a * b * yu - 2 * c * Yv - 2 * b * Yu - 2 * a * Yy + 2 * c * d * vs + 2 * b * d * us + 2 * a * d * ys + a * a * yy + c * c * vv + b * b * uu - 2 * d * Ys + YY;
+  return( dError );
+};
+#endif
+
+#endif
+
+#endif
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1487)
@@ -1412,5 +1412,9 @@
   WRITE_FLAG(ptl->getFrameOnlyConstraintFlag(), PTL_TRACE_TEXT("frame_only_constraint_flag"      ));
 
-  if (ptl->getProfileIdc() == Profile::MAINREXT || ptl->getProfileIdc() == Profile::HIGHTHROUGHPUTREXT )
+  if (ptl->getProfileIdc() == Profile::MAINREXT || ptl->getProfileIdc() == Profile::HIGHTHROUGHPUTREXT 
+#if SCALABLE_REXT
+    || ptl->getProfileIdc() == Profile::SCALABLEREXT
+#endif
+    )
   {
     const UInt         bitDepthConstraint=ptl->getBitDepthConstraint();
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1487)
@@ -5960,5 +5960,9 @@
                                            TComMv& rcMvHalf,
                                            TComMv& rcMvQter,
-                                           UInt& ruiCost     )                                           
+#if SCALABLE_REXT
+                                           Distortion& ruiCost     )
+#else
+                                           UInt& ruiCost     )
+#endif
 {
   assert(pcMvInt->getHor() == 0 && pcMvInt->getVer() == 0);
@@ -5995,7 +5999,13 @@
   UInt          uiLastMode = 0;
 
+#if SCALABLE_REXT
+  Distortion    uiCost[2]   = { MAX_UINT, MAX_UINT };     //uni, rdCost
+  Distortion    uiCostTemp;
+  Distortion    biPDistTemp = MAX_INT;
+#else
   UInt          uiCost[2]   = { MAX_UINT, MAX_UINT };     //uni, rdCost
   UInt          uiCostTemp;
   UInt          biPDistTemp = MAX_INT;
+#endif
   UInt          uiBitsTemp;
 
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.h	(revision 1486)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.h	(revision 1487)
@@ -480,5 +480,9 @@
                                    TComMv&       rcMvHalf,
                                    TComMv&       rcMvQter,
+#if SCALABLE_REXT
+                                   Distortion&   ruiCost     );
+#else
                                    UInt&         ruiCost     );
+#endif
 #endif //SVC_EXTENSION  
 
