Index: branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 468)
+++ branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 475)
@@ -602,5 +602,9 @@
   {
 #endif
+#if AUXILIARY_PICTURES
+    READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( ChromaFormat(uiCode) );
+#else
     READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
+#endif
     assert(uiCode <= 3);
     // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
@@ -1049,5 +1053,7 @@
     {
       READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
+#if !AUXILIARY_PICTURES
       assert( uiCode <= vps->getMaxLayerId() );
+#endif
     }
   }
@@ -1306,6 +1312,10 @@
 {
   UInt uiCode;
+#if AUXILIARY_PICTURES
+  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
+#else
   READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
-
+#endif
+  
   if( repFormat->getChromaFormatVpsIdc() == 3 )
   {
@@ -1808,5 +1818,29 @@
     {
       READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
+#if AUXILIARY_PICTURES
+      ChromaFormat format;
+#if REPN_FORMAT_IN_VPS
+      if( ( sps->getLayerId() == 0 ) || sps->getUpdateRepFormatFlag() )
+      {
+        format = sps->getChromaFormatIdc();
+      }
+      else
+      {
+        format = rpcSlice->getVPS()->getVpsRepFormat( rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
+      }
+#else
+      format = sps->getChromaFormatIdc();
+#endif
+      if (format != CHROMA_400)
+      {
+#endif
       READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
+#if AUXILIARY_PICTURES
+      }
+      else
+      {
+        rpcSlice->setSaoEnabledFlagChroma(false);
+      }
+#endif
     }
 
@@ -2411,4 +2445,10 @@
 
   Int iDeltaDenom;
+#if AUXILIARY_PICTURES
+  if (pcSlice->getChromaFormatIdc() == CHROMA_400)
+  {
+    bChroma = false;
+  }
+#endif
   // decode delta_luma_log2_weight_denom :
   READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
@@ -2430,6 +2470,18 @@
 
       wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
+#if AUXILIARY_PICTURES
+      if (!bChroma)
+      {
+        wp[1].uiLog2WeightDenom = 0;
+        wp[2].uiLog2WeightDenom = 0;
+      }
+      else
+      {
+#endif
       wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
       wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
+#if AUXILIARY_PICTURES
+      }
+#endif
 
       UInt  uiCode;
Index: branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 468)
+++ branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 475)
@@ -356,4 +356,8 @@
     uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
     uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
+#if AUXILIARY_PICTURES
+    ChromaFormat format = pcCU->getSlice()->getChromaFormatIdc();
+    UInt uiGrayVal = 1 << (uiSampleBits - 1);
+#endif
 
     for(uiY = 0; uiY < uiHeight; uiY++)
@@ -362,4 +366,9 @@
       {
         UInt uiSample;
+#if AUXILIARY_PICTURES
+        if (format == CHROMA_400)
+          uiSample = uiGrayVal;
+        else
+#endif
         m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
         piPCMSample[uiX] = uiSample;
@@ -378,4 +387,9 @@
       {
         UInt uiSample;
+#if AUXILIARY_PICTURES
+        if (format == CHROMA_400)
+          uiSample = uiGrayVal;
+        else
+#endif
         m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
         piPCMSample[uiX] = uiSample;
@@ -665,4 +679,12 @@
   UInt uiSymbol;
 
+#if AUXILIARY_PICTURES
+  if ( pcCU->getSlice()->getChromaFormatIdc() == CHROMA_400 )
+  {
+    uiSymbol = DC_IDX;
+  }
+  else
+  {
+#endif
   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
 
@@ -681,4 +703,7 @@
     }
   }
+#if AUXILIARY_PICTURES
+  }
+#endif
   pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
   return;
@@ -885,5 +910,16 @@
   UInt uiSymbol;
   const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
+#if AUXILIARY_PICTURES
+  if (pcCU->getSlice()->getChromaFormatIdc() == CHROMA_400 && (eType == TEXT_CHROMA_U || eType == TEXT_CHROMA_V))
+  {
+    uiSymbol = 0;
+  }
+  else
+  {
+#endif
   m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
+#if AUXILIARY_PICTURES
+  }
+#endif
   
   DTRACE_CABAC_VL( g_nSymbolCounter++ )
Index: branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 468)
+++ branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 475)
@@ -179,4 +179,19 @@
 
         m_cIlpPic[j] = new  TComPic;
+#if AUXILIARY_PICTURES
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
+#else
+        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
+#if SVC_UPSAMPLING
+        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
+#else
+        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#endif
+#else
 #if REPN_FORMAT_IN_VPS
 #if SVC_UPSAMPLING
@@ -190,4 +205,5 @@
 #else
         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
 #endif
 #endif
@@ -291,4 +307,23 @@
 #endif
     
+#if AUXILIARY_PICTURES
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+#else
+    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
+#if SVC_UPSAMPLING
+    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+#else
+    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#endif
+#else
 #if REPN_FORMAT_IN_VPS
 #if SVC_UPSAMPLING
@@ -308,4 +343,5 @@
 #endif
 #endif
+#endif
 
     rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
@@ -348,4 +384,25 @@
   rpcPic->destroy();
 
+#if AUXILIARY_PICTURES
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+
+#else
+  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
+#if SVC_UPSAMPLING
+  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+
+#else
+  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#endif
+#else
 #if REPN_FORMAT_IN_VPS
 #if SVC_UPSAMPLING
@@ -365,4 +422,5 @@
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
 #endif
 #endif
@@ -1526,7 +1584,17 @@
           Window &conformanceWindow = sps->getConformanceWindow();
           Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
+#if AUXILIARY_PICTURES
 #if SVC_UPSAMPLING
 #if AVC_SYNTAX
-
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
+#else
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
+#endif
+#else
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
+#if SVC_UPSAMPLING
+#if AVC_SYNTAX
           pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
 #else
@@ -1535,4 +1603,5 @@
 #else
           pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
 #endif
         }
