Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 442)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 494)
@@ -221,18 +221,20 @@
   }
 #endif
-#if EXTERNAL_USEDBYCURR_N0082
-  if(entry.m_numRefPics>0){
-    in>>entry.m_UseExtusedByCurrPic;
-    if(entry.m_UseExtusedByCurrPic)
-    {
-      for ( Int i = 0; i < entry.m_numRefPics; i++ )
-      {
-        in>>entry.m_ExtusedByCurrPic[i];
-      }
-    }
-  }
-#endif
   return in;
 }
+
+#if AUXILIARY_PICTURES
+static inline ChromaFormat numberToChromaFormat(const Int val)
+{
+  switch (val)
+  {
+    case 400: return CHROMA_400; break;
+    case 420: return CHROMA_420; break;
+    case 422: return CHROMA_422; break;
+    case 444: return CHROMA_444; break;
+    default:  return NUM_CHROMA_FORMAT;
+  }
+}
+#endif
 
 #if SVC_EXTENSION
@@ -362,4 +364,22 @@
   Int*    cfg_IntraPeriod   [MAX_LAYERS];
   Int*    cfg_conformanceMode  [MAX_LAYERS];
+#if LAYER_CTB
+  // coding unit (CU) definition
+  UInt*      cfg_uiMaxCUWidth[MAX_LAYERS];                                   ///< max. CU width in pixel
+  UInt*      cfg_uiMaxCUHeight[MAX_LAYERS];                                  ///< max. CU height in pixel
+  UInt*      cfg_uiMaxCUDepth[MAX_LAYERS];                                   ///< max. CU depth
+  
+  // transfom unit (TU) definition
+  UInt*      cfg_uiQuadtreeTULog2MaxSize[MAX_LAYERS];
+  UInt*      cfg_uiQuadtreeTULog2MinSize[MAX_LAYERS];
+  
+  UInt*      cfg_uiQuadtreeTUMaxDepthInter[MAX_LAYERS];
+  UInt*      cfg_uiQuadtreeTUMaxDepthIntra[MAX_LAYERS];
+#endif
+#if AUXILIARY_PICTURES
+  Int      cfg_tmpChromaFormatIDC  [MAX_LAYERS];
+  Int      cfg_tmpInputChromaFormat[MAX_LAYERS];
+  Int*     cfg_auxId               [MAX_LAYERS];
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -379,5 +399,4 @@
   string* cfg_predLayerIdsPtr    [MAX_LAYERS];
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   string    cfg_scaledRefLayerLeftOffset [MAX_LAYERS];
   string    cfg_scaledRefLayerTopOffset [MAX_LAYERS];
@@ -390,5 +409,4 @@
   string*    cfg_scaledRefLayerRightOffsetPtr  [MAX_LAYERS];
   string*    cfg_scaledRefLayerBottomOffsetPtr [MAX_LAYERS];
-#endif
 #if RC_SHVC_HARMONIZATION
   Bool*   cfg_RCEnableRateControl  [MAX_LAYERS];
@@ -400,4 +418,12 @@
   Bool*   cfg_RCForceIntraQP       [MAX_LAYERS];
 #endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  Int*    cfg_InputBitDepthY    [MAX_LAYERS];
+  Int*    cfg_InternalBitDepthY [MAX_LAYERS];
+  Int*    cfg_InputBitDepthC    [MAX_LAYERS];
+  Int*    cfg_InternalBitDepthC [MAX_LAYERS];
+  Int*    cfg_OutputBitDepthY   [MAX_LAYERS];
+  Int*    cfg_OutputBitDepthC   [MAX_LAYERS];
+#endif
 #if N0120_MAX_TID_REF_CFG
   Int*    cfg_maxTidIlRefPicsPlus1[MAX_LAYERS]; 
@@ -416,4 +442,17 @@
     cfg_IntraPeriod[layer]  = &m_acLayerCfg[layer].m_iIntraPeriod; 
     cfg_conformanceMode[layer] = &m_acLayerCfg[layer].m_conformanceMode;
+#if LAYER_CTB
+    // coding unit (CU) definition
+    cfg_uiMaxCUWidth[layer]  = &m_acLayerCfg[layer].m_uiMaxCUWidth;
+    cfg_uiMaxCUHeight[layer] = &m_acLayerCfg[layer].m_uiMaxCUHeight;
+    cfg_uiMaxCUDepth[layer]  = &m_acLayerCfg[layer].m_uiMaxCUDepth;
+
+    // transfom unit (TU) definition.
+    cfg_uiQuadtreeTULog2MaxSize[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTULog2MaxSize;
+    cfg_uiQuadtreeTULog2MinSize[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTULog2MinSize;
+
+    cfg_uiQuadtreeTUMaxDepthInter[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthInter;
+    cfg_uiQuadtreeTUMaxDepthIntra[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthIntra;
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -429,5 +468,4 @@
     cfg_predLayerIdsPtr     [layer]  = &cfg_predLayerIds[layer];
 #endif
-#if SCALED_REF_LAYER_OFFSETS
     cfg_numScaledRefLayerOffsets [layer] = &m_acLayerCfg[layer].m_numScaledRefLayerOffsets;
     for(Int i = 0; i < MAX_LAYERS; i++)
@@ -438,5 +476,4 @@
       cfg_scaledRefLayerBottomOffsetPtr[layer] = &cfg_scaledRefLayerBottomOffset[layer];
     }
-#endif
 #if RC_SHVC_HARMONIZATION
     cfg_RCEnableRateControl[layer]   = &m_acLayerCfg[layer].m_RCEnableRateControl;
@@ -448,7 +485,18 @@
     cfg_RCForceIntraQP[layer]        = &m_acLayerCfg[layer].m_RCForceIntraQP;
 #endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  cfg_InputBitDepthY   [layer] = &m_acLayerCfg[layer].m_inputBitDepthY;
+  cfg_InternalBitDepthY[layer] = &m_acLayerCfg[layer].m_internalBitDepthY;
+  cfg_InputBitDepthC   [layer] = &m_acLayerCfg[layer].m_inputBitDepthC;
+  cfg_InternalBitDepthC[layer] = &m_acLayerCfg[layer].m_internalBitDepthC;
+  cfg_OutputBitDepthY  [layer] = &m_acLayerCfg[layer].m_outputBitDepthY;
+  cfg_OutputBitDepthC  [layer] = &m_acLayerCfg[layer].m_outputBitDepthC;
+#endif
 #if N0120_MAX_TID_REF_CFG
     cfg_maxTidIlRefPicsPlus1[layer] = &m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1; 
 #endif 
+#if AUXILIARY_PICTURES
+    cfg_auxId[layer]                = &m_acLayerCfg[layer].m_auxId; 
+#endif
   }
 #if AVC_BASE
@@ -461,10 +509,10 @@
   string  cfg_tileSets;
 #endif
-#else
+#else //SVC_EXTENSION
   string cfg_InputFile;
   string cfg_BitstreamFile;
   string cfg_ReconFile;
   string cfg_dQPFile;
-#endif
+#endif //SVC_EXTENSION
   string cfg_ColumnWidth;
   string cfg_RowHeight;
@@ -487,4 +535,7 @@
   ("FrameRate%d,-fr%d",       cfg_FrameRate,  0, MAX_LAYERS, "Frame rate for layer %d")
   ("LambdaModifier%d,-LM%d",  m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
+#if O0215_PHASE_ALIGNMENT
+  ("PhaseAlignment",          m_phaseAlignFlag, false, "indicate the sample location alignment between layers (0: zero position aligned, 1: central position aligned)")
+#endif
 #if REPN_FORMAT_IN_VPS
   ("RepFormatIdx%d",          cfg_repFormatIdx, -1, MAX_LAYERS, "Index to the representation format structure used from the VPS")
@@ -504,8 +555,16 @@
 #endif
   ("NumLayers",               m_numLayers, 1, "Number of layers to code")
+#if AUXILIARY_PICTURES
+  ("InputChromaFormat%d",     cfg_tmpInputChromaFormat,  420, MAX_LAYERS, "InputChromaFormatIDC for layer %d")
+  ("ChromaFormatIDC%d,-cf",   cfg_tmpChromaFormatIDC,    420, MAX_LAYERS, "ChromaFormatIDC (400|420|422|444 or set 0 (default) for same as InputChromaFormat) for layer %d")
+  ("AuxId%d",                 cfg_auxId,                 0,   MAX_LAYERS, "Auxilary picture ID for layer %d (0: Not aux pic, 1: Alpha plane, 2: Depth picture, 3: Cb enh, 4: Cr enh")
+#endif
   ("ConformanceMode%d",       cfg_conformanceMode,0, MAX_LAYERS, "Window conformance mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
 #if SCALABILITY_MASK_E0104
   ("ScalabilityMask1",        m_scalabilityMask[1], 0, "scalability_mask[1] (multiview)")
   ("ScalabilityMask2",        m_scalabilityMask[2], 1, "scalability_mask[2] (scalable)" )
+#if AUXILIARY_PICTURES
+  ("ScalabilityMask3",        m_scalabilityMask[3], 0, "scalability_mask[3] (auxiliary pictures)" )
+#endif
 #else
   ("ScalabilityMask0",        m_scalabilityMask[0], 0, "scalability_mask[0] (multiview)")
@@ -513,4 +572,5 @@
 #endif
   ("BitstreamFile,b",         cfg_BitstreamFile, string(""), "Bitstream output file name")
+#if !O0194_DIFFERENT_BITDEPTH_EL_BL
   ("InputBitDepth",           m_inputBitDepthY,    8, "Bit-depth of input file")
   ("OutputBitDepth",          m_outputBitDepthY,   0, "Bit-depth of output file (default:InternalBitDepth)")
@@ -520,5 +580,5 @@
   ("OutputBitDepthC",         m_outputBitDepthC,   0, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
   ("InternalBitDepthC",       m_internalBitDepthC, 0, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth)")
-#if SCALED_REF_LAYER_OFFSETS
+#endif
   ("NumScaledRefLayerOffsets%d",    cfg_numScaledRefLayerOffsets,     0, MAX_LAYERS,  "Number of scaled offset layer sets ")
   ("ScaledRefLayerLeftOffset%d",   cfg_scaledRefLayerLeftOffsetPtr,  string(""), MAX_LAYERS, "Horizontal offset of top-left luma sample of scaled base layer picture with respect to"
@@ -530,4 +590,12 @@
   ("ScaledRefLayerBottomOffset%d", cfg_scaledRefLayerBottomOffsetPtr,string(""), MAX_LAYERS, "Vertical offset of bottom-right luma sample of scaled base layer picture with respect to"
                                                                  " bottom-right luma sample of the EL picture, in units of two luma samples")
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  ("InputBitDepth%d",       cfg_InputBitDepthY,    8, MAX_LAYERS, "Bit-depth of input file for layer %d")
+  ("InternalBitDepth%d",    cfg_InternalBitDepthY, 0, MAX_LAYERS, "Bit-depth the codec operates at. (default:InputBitDepth) for layer %d ")
+//                                                       "If different to InputBitDepth, source data will be converted")
+  ("InputBitDepthC%d",      cfg_InputBitDepthC,    0, MAX_LAYERS, "As per InputBitDepth but for chroma component. (default:InputBitDepth) for layer %d")
+  ("InternalBitDepthC%d",   cfg_InternalBitDepthC, 0, MAX_LAYERS, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth) for layer %d")
+  ("OutputBitDepth%d",      cfg_OutputBitDepthY,   0, MAX_LAYERS, "Bit-depth of output file (default:InternalBitDepth)")
+  ("OutputBitDepthC%d",     cfg_OutputBitDepthC,   0, MAX_LAYERS, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
 #endif
 #if N0120_MAX_TID_REF_CFG
@@ -546,5 +614,5 @@
   ("IlSampleOnlyPred%d",       m_ilSampleOnlyPred, 0, MAX_LAYERS, "Set inter_layer_sample_pred_only_flag for all slices")
 #endif
-#else
+#else //SVC_EXTENSION
   ("InputFile,i",           cfg_InputFile,     string(""), "Original YUV input file name")
   ("BitstreamFile,b",       cfg_BitstreamFile, string(""), "Bitstream output file name")
@@ -559,4 +627,8 @@
   ("OutputBitDepthC",       m_outputBitDepthC,   0, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
   ("InternalBitDepthC",     m_internalBitDepthC, 0, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth)")
+#if AUXILIARY_PICTURES
+  ("InputChromaFormat",     tmpInputChromaFormat,                       420, "InputChromaFormatIDC")
+  ("ChromaFormatIDC,-cf",   tmpChromaFormat,                             0, "ChromaFormatIDC (400|420|422|444 or set 0 (default) for same as InputChromaFormat)")
+#endif
   ("ConformanceMode",       m_conformanceMode,     0, "Window conformance mode (0: no window, 1:automatic padding, 2:padding, 3:conformance")
   ("HorizontalPadding,-pdx",m_aiPad[0],            0, "Horizontal source padding for conformance window mode 2")
@@ -567,5 +639,5 @@
   ("ConfBottom",            m_confBottom,          0, "Bottom offset for window conformance mode 3")
   ("FrameRate,-fr",         m_iFrameRate,          0, "Frame rate")
-#endif
+#endif //SVC_EXTENSION
 
   //Field coding parameters
@@ -574,5 +646,4 @@
   ("FrameSkip,-fs",         m_FrameSkip,          0u, "Number of frames to skip at start of input YUV")
   ("FramesToBeEncoded,f",   m_framesToBeEncoded,   0, "Number of frames to be encoded (default=all)")
-  
   // Profile and level
   ("Profile", m_profile,   Profile::NONE, "Profile to be used when encoding (Incomplete)")
@@ -585,4 +656,34 @@
   ("FrameOnly",         m_frameOnlyConstraintFlag, false, "Indicate that the bitstream contains only frames")
 
+#if LAYER_CTB
+  // Unit definition parameters
+  ("MaxCUWidth%d",              cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU width")
+  ("MaxCUHeight%d",             cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU height")
+  // todo: remove defaults from MaxCUSize
+  ("MaxCUSize%d,s%d",           cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU size")
+  ("MaxCUSize%d,s%d",           cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU size")
+  ("MaxPartitionDepth%d,h%d",   cfg_uiMaxCUDepth,              4u, MAX_LAYERS, "CU depth")
+  
+  ("QuadtreeTULog2MaxSize%d",   cfg_uiQuadtreeTULog2MaxSize,   6u, MAX_LAYERS, "Maximum TU size in logarithm base 2")
+  ("QuadtreeTULog2MinSize%d",   cfg_uiQuadtreeTULog2MinSize,   2u, MAX_LAYERS, "Minimum TU size in logarithm base 2")
+  
+  ("QuadtreeTUMaxDepthIntra%d", cfg_uiQuadtreeTUMaxDepthIntra, 1u, MAX_LAYERS, "Depth of TU tree for intra CUs")
+  ("QuadtreeTUMaxDepthInter%d", cfg_uiQuadtreeTUMaxDepthInter, 2u, MAX_LAYERS, "Depth of TU tree for inter CUs")
+
+
+  // set the same CU realted settings across all the layers if config file parameters are not layer specific
+  ("MaxCUWidth",              cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU width")
+  ("MaxCUHeight",             cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU height")
+  // todo: remove defaults from MaxCUSize
+  ("MaxCUSize,s",             cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU size")
+  ("MaxCUSize,s",             cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU size")
+  ("MaxPartitionDepth,h",     cfg_uiMaxCUDepth,              4u, MAX_LAYERS, "CU depth")
+  
+  ("QuadtreeTULog2MaxSize",   cfg_uiQuadtreeTULog2MaxSize,   6u, MAX_LAYERS, "Maximum TU size in logarithm base 2")
+  ("QuadtreeTULog2MinSize",   cfg_uiQuadtreeTULog2MinSize,   2u, MAX_LAYERS, "Minimum TU size in logarithm base 2")
+  
+  ("QuadtreeTUMaxDepthIntra", cfg_uiQuadtreeTUMaxDepthIntra, 1u, MAX_LAYERS, "Depth of TU tree for intra CUs")
+  ("QuadtreeTUMaxDepthInter", cfg_uiQuadtreeTUMaxDepthInter, 2u, MAX_LAYERS, "Depth of TU tree for inter CUs")
+#else
   // Unit definition parameters
   ("MaxCUWidth",              m_uiMaxCUWidth,             64u)
@@ -598,4 +699,5 @@
   ("QuadtreeTUMaxDepthIntra", m_uiQuadtreeTUMaxDepthIntra, 1u, "Depth of TU tree for intra CUs")
   ("QuadtreeTUMaxDepthInter", m_uiQuadtreeTUMaxDepthInter, 2u, "Depth of TU tree for inter CUs")
+#endif
   
   // Coding structure paramters
@@ -864,11 +966,4 @@
     opts.addOptions()(cOSS.str(), m_GOPList[i-1], GOPEntry());
   }
-#if FINAL_RPL_CHANGE_N0082
-  for(Int i=1; i<MAX_GOP+1; i++) {
-    std::ostringstream cOSS;
-    cOSS<<"FrameEL"<<i;
-    opts.addOptions()(cOSS.str(), m_acLayerCfg[1].m_GOPListLayer[i-1], GOPEntry());
-  }
-#endif
   po::setDefaults(opts);
   const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
@@ -921,10 +1016,10 @@
   m_BLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
 #endif
-#else
+#else //SVC_EXTENSION
   m_pchInputFile = cfg_InputFile.empty() ? NULL : strdup(cfg_InputFile.c_str());
   m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
   m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
   m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
-#endif  
+#endif //SVC_EXTENSION 
 
   Char* pColumnWidth = cfg_ColumnWidth.empty() ? NULL: strdup(cfg_ColumnWidth.c_str());
@@ -985,5 +1080,5 @@
     m_pRowHeight = NULL;
   }
-#if SCALED_REF_LAYER_OFFSETS
+#if SVC_EXTENSION
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -1055,5 +1150,4 @@
     }
   }
-#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -1153,4 +1247,11 @@
   }
 #endif
+#if AUXILIARY_PICTURES
+  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    m_acLayerCfg[layer].m_InputChromaFormat =  numberToChromaFormat(cfg_tmpChromaFormatIDC[layer]);
+    m_acLayerCfg[layer].m_chromaFormatIDC = ((cfg_tmpChromaFormatIDC[layer] == 0) ? (m_acLayerCfg[layer].m_InputChromaFormat ) : (numberToChromaFormat(cfg_tmpChromaFormatIDC[layer])));
+  }
+#endif
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -1185,14 +1286,18 @@
   }
 #endif
+#endif //SVC_EXTENSION
   m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str());
 
-#if REPN_FORMAT_IN_VPS_123
+  /* rules for input, output and internal bitdepths as per help text */
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
   {
-    m_acLayerCfg[layer].setSourceHeight( m_repFormatCfg[ m_acLayerCfg[layer].getRepFormatIdx() ].m_picHeightInLumaSamples);
-    m_acLayerCfg[layer].setSourceWidth ( m_repFormatCfg[ m_acLayerCfg[layer].getRepFormatIdx() ].m_picWidthInLumaSamples );
-  }
-#endif
-  /* rules for input, output and internal bitdepths as per help text */
+    if (!m_acLayerCfg[layer].m_internalBitDepthY) { m_acLayerCfg[layer].m_internalBitDepthY = m_acLayerCfg[layer].m_inputBitDepthY; }
+    if (!m_acLayerCfg[layer].m_internalBitDepthC) { m_acLayerCfg[layer].m_internalBitDepthC = m_acLayerCfg[layer].m_internalBitDepthY; }
+    if (!m_acLayerCfg[layer].m_inputBitDepthC) { m_acLayerCfg[layer].m_inputBitDepthC = m_acLayerCfg[layer].m_inputBitDepthY; }
+    if (!m_acLayerCfg[layer].m_outputBitDepthY) { m_acLayerCfg[layer].m_outputBitDepthY = m_acLayerCfg[layer].m_internalBitDepthY; }
+    if (!m_acLayerCfg[layer].m_outputBitDepthC) { m_acLayerCfg[layer].m_outputBitDepthC = m_acLayerCfg[layer].m_internalBitDepthC; }
+  }
+#else
   if (!m_internalBitDepthY) { m_internalBitDepthY = m_inputBitDepthY; }
   if (!m_internalBitDepthC) { m_internalBitDepthC = m_internalBitDepthY; }
@@ -1200,4 +1305,5 @@
   if (!m_outputBitDepthY) { m_outputBitDepthY = m_internalBitDepthY; }
   if (!m_outputBitDepthC) { m_outputBitDepthC = m_internalBitDepthC; }
+#endif
 
 #if !SVC_EXTENSION
@@ -1411,5 +1517,12 @@
   
   // set global varibles
+#if LAYER_CTB
+  for(Int layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    xSetGlobal(layer);
+  }
+#else
   xSetGlobal();
+#endif
   
   // print-out parameters
@@ -1450,6 +1563,14 @@
 #define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
   // check range of parameters
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    xConfirmPara( m_acLayerCfg[layer].m_inputBitDepthY < 8,                                                     "InputBitDepth must be at least 8" );
+    xConfirmPara( m_acLayerCfg[layer].m_inputBitDepthC < 8,                                                     "InputBitDepthC must be at least 8" );
+  }
+#else
   xConfirmPara( m_inputBitDepthY < 8,                                                     "InputBitDepth must be at least 8" );
   xConfirmPara( m_inputBitDepthC < 8,                                                     "InputBitDepthC must be at least 8" );
+#endif
 #if !SVC_EXTENSION  
   xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
@@ -1471,5 +1592,12 @@
   xConfirmPara( m_bipredSearchRange < 0 ,                                                   "Search Range must be more than 0" );
   xConfirmPara( m_iMaxDeltaQP > 7,                                                          "Absolute Delta QP exceeds supported range (0 to 7)" );
+#if LAYER_CTB
+  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    xConfirmPara( m_iMaxCuDQPDepth > m_acLayerCfg[layer].m_uiMaxCUDepth - 1,                "Absolute depth for a minimum CuDQP exceeds maximum coding unit depth" );
+  }
+#else
   xConfirmPara( m_iMaxCuDQPDepth > m_uiMaxCUDepth - 1,                                          "Absolute depth for a minimum CuDQP exceeds maximum coding unit depth" );
+#endif
 
   xConfirmPara( m_cbQpOffset < -12,   "Min. Chroma Cb QP Offset is -12" );
@@ -1485,8 +1613,10 @@
   }
 #endif
+#if !LAYER_CTB
   xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
   xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
   xConfirmPara( m_uiMaxCUWidth < 16,                                                        "Maximum partition width size should be larger than or equal to 16");
   xConfirmPara( m_uiMaxCUHeight < 16,                                                       "Maximum partition height size should be larger than or equal to 16");
+#endif
 #if !SVC_EXTENSION
   xConfirmPara( (m_iSourceWidth  % (m_uiMaxCUWidth  >> (m_uiMaxCUDepth-1)))!=0,             "Resulting coded frame width must be a multiple of the minimum CU size");
@@ -1494,4 +1624,5 @@
 #endif
   
+#if !LAYER_CTB
   xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
   xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5,                                        "QuadtreeTULog2MaxSize must be 5 or smaller.");
@@ -1507,4 +1638,5 @@
   xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1,                                                         "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" );
   xConfirmPara( m_uiMaxCUWidth < ( 1 << (m_uiQuadtreeTULog2MinSize + m_uiQuadtreeTUMaxDepthIntra - 1) ), "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1" );
+#endif
   
   xConfirmPara(  m_maxNumMergeCand < 1,  "MaxNumMergeCand must be 1 or greater.");
@@ -1554,4 +1686,5 @@
 #endif
 
+#if !LAYER_CTB
   // max CU width and height should be power of 2
   UInt ui = m_uiMaxCUWidth;
@@ -1569,5 +1702,5 @@
       xConfirmPara( ui != 1 , "Height should be 2^n");
   }
-
+#endif
 
   /* if this is an intra-only sequence, ie IntraPeriod=1, don't verify the GOP structure
@@ -1590,12 +1723,9 @@
 #endif
   
-#if EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
+
   Bool verifiedGOP=false;
-#endif
   Bool errorGOP=false;
-#if  EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
   Int checkGOP=1;
   Int numRefs = m_isField ? 2 : 1;
-#endif
   Int refList[MAX_NUM_REF_PICS+1];
   refList[0]=0;
@@ -1609,7 +1739,5 @@
     isOK[i]=false;
   }
-#if  EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
   Int numOK=0;
-#endif
 #if !SVC_EXTENSION
   xConfirmPara( m_iIntraPeriod >=0&&(m_iIntraPeriod%m_iGOPSize!=0), "Intra period must be a multiple of GOPSize, or -1" );
@@ -1654,31 +1782,5 @@
   }
 #endif
-#if FINAL_RPL_CHANGE_N0082
-  for(UInt layer=0; layer<m_numLayers; layer++)
-  {
-    if (m_acLayerCfg[layer].m_GOPListLayer[0].m_POC<0)
-    {
-      memcpy( m_acLayerCfg[layer].m_GOPListLayer, m_GOPList, sizeof(GOPEntry)*MAX_GOP );
-    }
-    errorGOP = xconfirmExtraGOP( m_acLayerCfg[layer].m_GOPListLayer );
-    xConfirmPara(errorGOP,"Invalid GOP structure given");
-  }
-#if TEMP_SCALABILITY_FIX
-  if( m_acLayerCfg[1].m_GOPListLayer[5].m_POC == 6  && m_acLayerCfg[1].m_GOPListLayer[7].m_POC == 7  && 
-    m_acLayerCfg[1].m_GOPListLayer[5].m_temporalId == 0 && m_acLayerCfg[1].m_GOPListLayer[7].m_temporalId == 0)
-#else
-  //tentative for encoder
-  if( m_acLayerCfg[1].m_GOPListLayer[5].m_POC == 6  && m_acLayerCfg[1].m_GOPListLayer[7].m_POC == 7 )
-#endif
-  {
-    //RA, POC5
-    m_acLayerCfg[1].m_GOPListLayer[5].m_usedByCurrPic[2] = 0;
-    m_acLayerCfg[1].m_GOPListLayer[5].m_refIdc[2] = 0;
-    //RA, POC7
-    m_acLayerCfg[1].m_GOPListLayer[7].m_usedByCurrPic[2] = 0;
-    m_acLayerCfg[1].m_GOPListLayer[7].m_refIdc[2] = 0;
-  }
-#endif
-#if  EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
+
   m_extraRPSs=0;
   //start looping through frames in coding order until we can verify that the GOP structure is correct.
@@ -1876,20 +1978,5 @@
   }
   xConfirmPara(errorGOP,"Invalid GOP structure given");
-#endif
-#if EXTERNAL_USEDBYCURR_N0082
-  for(UInt layer=0; layer<m_numLayers; layer++)
-  {
-    for (Int i=0; i< m_iGOPSize; i++){
-      if (m_acLayerCfg[layer].m_GOPListLayer[i].m_UseExtusedByCurrPic == 1 )
-      {
-        for(Int j=0; j<m_acLayerCfg[layer].m_GOPListLayer[i].m_numRefPics; j++ )
-        {
-          m_acLayerCfg[layer].m_GOPListLayer[i].m_usedByCurrPic[j] = m_acLayerCfg[layer].m_GOPListLayer[i].m_ExtusedByCurrPic[j];
-          m_acLayerCfg[layer].m_GOPListLayer[i].m_refIdc[j] = m_acLayerCfg[layer].m_GOPListLayer[i].m_ExtusedByCurrPic[j];
-        }
-      }
-    }
-  }
-#endif
+
   m_maxTempLayer = 1;
   for(Int i=0; i<m_iGOPSize; i++) 
@@ -1966,4 +2053,8 @@
     Int m_iSourceWidth = m_acLayerCfg[layer].m_iSourceWidth;
     Int m_iSourceHeight = m_acLayerCfg[layer].m_iSourceHeight;
+#if LAYER_CTB
+    Int m_uiMaxCUWidth = m_acLayerCfg[layer].m_uiMaxCUWidth;
+    Int m_uiMaxCUHeight = m_acLayerCfg[layer].m_uiMaxCUHeight;
+#endif
 #endif
   if(m_vuiParametersPresentFlag && m_bitstreamRestrictionFlag)
@@ -2201,4 +2292,11 @@
   }
 #endif 
+#if AUXILIARY_PICTURES
+  for (UInt layer=0; layer < MAX_LAYERS-1; layer++)
+  {
+    xConfirmPara(m_acLayerCfg[layer].m_auxId < 0 || m_acLayerCfg[layer].m_auxId > 4, "AuxId must be in range 0 to 4");
+    xConfirmPara(m_acLayerCfg[layer].m_auxId > 0 && m_acLayerCfg[layer].m_chromaFormatIDC != CHROMA_400, "Auxiliary picture must be monochrome picture");
+  }
+#endif 
 #undef xConfirmPara
   if (check_failed)
@@ -2210,4 +2308,36 @@
 /** \todo use of global variables should be removed later
  */
+#if LAYER_CTB
+Void TAppEncCfg::xSetGlobal(UInt layerId)
+{
+  // set max CU width & height
+  g_auiLayerMaxCUWidth[layerId]  = m_acLayerCfg[layerId].m_uiMaxCUWidth;
+  g_auiLayerMaxCUHeight[layerId] = m_acLayerCfg[layerId].m_uiMaxCUHeight;
+  
+  // compute actual CU depth with respect to config depth and max transform size
+  g_auiLayerAddCUDepth[layerId]  = 0;
+  while( (m_acLayerCfg[layerId].m_uiMaxCUWidth>>m_acLayerCfg[layerId].m_uiMaxCUDepth) > ( 1 << ( m_acLayerCfg[layerId].m_uiQuadtreeTULog2MinSize + g_auiLayerAddCUDepth[layerId] )  ) ) g_auiLayerAddCUDepth[layerId]++;
+  
+  m_acLayerCfg[layerId].m_uiMaxCUDepth += g_auiLayerAddCUDepth[layerId];
+  g_auiLayerAddCUDepth[layerId]++;
+  g_auiLayerMaxCUDepth[layerId] = m_acLayerCfg[layerId].m_uiMaxCUDepth;
+  
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  // set internal bit-depth to constant value to make sure to be updated later
+  g_bitDepthY = -1;
+  g_bitDepthC = -1;
+  
+  g_uiPCMBitDepthLuma = -1;
+  g_uiPCMBitDepthChroma = -1;
+#else
+  // set internal bit-depth and constants
+  g_bitDepthY = m_internalBitDepthY;
+  g_bitDepthC = m_internalBitDepthC;
+  
+  g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_inputBitDepthY : m_internalBitDepthY;
+  g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_inputBitDepthC : m_internalBitDepthC;
+#endif
+}
+#else
 Void TAppEncCfg::xSetGlobal()
 {
@@ -2224,5 +2354,12 @@
   g_uiMaxCUDepth = m_uiMaxCUDepth;
   
-  // set internal bit-depth and constants
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  // set internal bit-depth to constant value to make sure to be updated later
+  g_bitDepthY = -1;
+  g_bitDepthC = -1;
+  
+  g_uiPCMBitDepthLuma = -1;
+  g_uiPCMBitDepthChroma = -1;
+#else
   g_bitDepthY = m_internalBitDepthY;
   g_bitDepthC = m_internalBitDepthC;
@@ -2230,5 +2367,7 @@
   g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_inputBitDepthY : m_internalBitDepthY;
   g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_inputBitDepthC : m_internalBitDepthC;
+#endif
 }
+#endif
 
 Void TAppEncCfg::xPrintParameter()
@@ -2240,4 +2379,7 @@
   printf("Multiview                     : %d\n", m_scalabilityMask[1] );
   printf("Scalable                      : %d\n", m_scalabilityMask[2] );
+#if AUXILIARY_PICTURES
+  printf("Auxiliary pictures            : %d\n", m_scalabilityMask[3] );
+#endif
 #else
   printf("Multiview                     : %d\n", m_scalabilityMask[0] );
@@ -2284,8 +2426,10 @@
     printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
   }
+#if !LAYER_CTB
   printf("CU size / depth              : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
   printf("RQT trans. size (min / max)  : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
   printf("Max RQT depth inter          : %d\n", m_uiQuadtreeTUMaxDepthInter);
   printf("Max RQT depth intra          : %d\n", m_uiQuadtreeTUMaxDepthIntra);
+#endif
   printf("Min PCM size                 : %d\n", 1 << m_uiPCMLog2MinSize);
   printf("Motion search range          : %d\n", m_iSearchRange );
@@ -2304,6 +2448,11 @@
   printf("QP adaptation                : %d (range=%d)\n", m_bUseAdaptiveQP, (m_bUseAdaptiveQP ? m_iQPAdaptationRange : 0) );
   printf("GOP size                     : %d\n", m_iGOPSize );
+#if !O0194_DIFFERENT_BITDEPTH_EL_BL
   printf("Internal bit depth           : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC );
   printf("PCM sample bit depth         : (Y:%d, C:%d)\n", g_uiPCMBitDepthLuma, g_uiPCMBitDepthChroma );
+#endif
+#if O0215_PHASE_ALIGNMENT
+  printf("cross-layer sample alignment : %d\n", m_phaseAlignFlag);
+#endif
 #if RATE_CONTROL_LAMBDA_DOMAIN
 #if !RC_SHVC_HARMONIZATION
@@ -2331,5 +2480,7 @@
   
   printf("TOOL CFG: ");
+#if !O0194_DIFFERENT_BITDEPTH_EL_BL
   printf("IBD:%d ", g_bitDepthY > m_inputBitDepthY || g_bitDepthC > m_inputBitDepthC);
+#endif
   printf("HAD:%d ", m_bUseHADME           );
   printf("SRD:%d ", m_bUseSBACRD          );
@@ -2362,5 +2513,7 @@
   printf("CIP:%d ", m_bUseConstrainedIntraPred);
   printf("SAO:%d ", (m_bUseSAO)?(1):(0));
+#if !LAYER_CTB
   printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
+#endif
   printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0));
 
@@ -2394,4 +2547,7 @@
   printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 );
 #endif
+  printf("O0194_DIFFERENT_BITDEPTH_EL_BL: %d ", O0194_DIFFERENT_BITDEPTH_EL_BL);
+  printf("O0194_JOINT_US_BITSHIFT: %d ", O0194_JOINT_US_BITSHIFT);
+  printf("O0194_WEIGHTED_PREDICTION_CGS: %d ",O0194_WEIGHTED_PREDICTION_CGS);
   printf("\n\n");
   
@@ -2408,5 +2564,5 @@
 }
 
-#if SCALED_REF_LAYER_OFFSETS
+#if SVC_EXTENSION
 Void TAppEncCfg::cfgStringToArray(Int **arr, string cfgString, Int numEntries, const char* logString)
 {
@@ -2441,219 +2597,5 @@
   }
 }
-#endif
-
-#if FINAL_RPL_CHANGE_N0082
-Bool  TAppEncCfg::xconfirmExtraGOP (GOPEntry * ge)
-{
-  Bool verifiedGOP=false;
-  Bool errorGOP=false;
-  Int checkGOP=1;
-  Int numRefs = 1;
-  Int refList[MAX_NUM_REF_PICS+1];
-  refList[0]=0;
-  Bool isOK[MAX_GOP];
-  for(Int i=0; i<MAX_GOP; i++) 
-  {
-    isOK[i]=false;
-  }
-  Int numOK=0;
-
-  m_extraRPSs=0;
-  //start looping through frames in coding order until we can verify that the GOP structure is correct.
-  while(!verifiedGOP&&!errorGOP) 
-  {
-    Int curGOP = (checkGOP-1)%m_iGOPSize;
-    Int curPOC = ((checkGOP-1)/m_iGOPSize)*m_iGOPSize + ge[curGOP].m_POC;    
-    if(ge[curGOP].m_POC<0) 
-    {
-      printf("\nError: found fewer Reference Picture Sets than GOPSize\n");
-      errorGOP=true;
-    }
-    else 
-    {
-      //check that all reference pictures are available, or have a POC < 0 meaning they might be available in the next GOP.
-      Bool beforeI = false;
-      for(Int i = 0; i< ge[curGOP].m_numRefPics; i++) 
-      {
-        Int absPOC = curPOC+ge[curGOP].m_referencePics[i];
-        if(absPOC < 0)
-        {
-          beforeI=true;
-        }
-        else 
-        {
-          Bool found=false;
-          for(Int j=0; j<numRefs; j++) 
-          {
-            if(refList[j]==absPOC) 
-            {
-              found=true;
-              for(Int k=0; k<m_iGOPSize; k++)
-              {
-                if(absPOC%m_iGOPSize == ge[k].m_POC%m_iGOPSize)
-                {
-                  if(ge[k].m_temporalId==ge[curGOP].m_temporalId)
-                  {
-                    ge[k].m_refPic = true;
-                  }
-                  ge[curGOP].m_usedByCurrPic[i]=ge[k].m_temporalId<=ge[curGOP].m_temporalId;
-                }
-              }
-            }
-          }
-          if(!found)
-          {
-            printf("\nError: ref pic %d is not available for GOP frame %d\n",ge[curGOP].m_referencePics[i],curGOP+1);
-            errorGOP=true;
-          }
-        }
-      }
-      if(!beforeI&&!errorGOP)
-      {
-        //all ref frames were present
-        if(!isOK[curGOP]) 
-        {
-          numOK++;
-          isOK[curGOP]=true;
-          if(numOK==m_iGOPSize)
-          {
-            verifiedGOP=true;
-          }
-        }
-      }
-      else 
-      {
-        //create a new GOPEntry for this frame containing all the reference pictures that were available (POC > 0)
-        ge[m_iGOPSize+m_extraRPSs]=ge[curGOP];
-        Int newRefs=0;
-        for(Int i = 0; i< ge[curGOP].m_numRefPics; i++) 
-        {
-          Int absPOC = curPOC+ge[curGOP].m_referencePics[i];
-          if(absPOC>=0)
-          {
-            ge[m_iGOPSize+m_extraRPSs].m_referencePics[newRefs]=ge[curGOP].m_referencePics[i];
-            ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[newRefs]=ge[curGOP].m_usedByCurrPic[i];
-            newRefs++;
-          }
-        }
-        Int numPrefRefs = ge[curGOP].m_numRefPicsActive;
-        
-        for(Int offset = -1; offset>-checkGOP; offset--)
-        {
-          //step backwards in coding order and include any extra available pictures we might find useful to replace the ones with POC < 0.
-          Int offGOP = (checkGOP-1+offset)%m_iGOPSize;
-          Int offPOC = ((checkGOP-1+offset)/m_iGOPSize)*m_iGOPSize + ge[offGOP].m_POC;
-          if(offPOC>=0&&ge[offGOP].m_temporalId<=ge[curGOP].m_temporalId)
-          {
-            Bool newRef=false;
-            for(Int i=0; i<numRefs; i++)
-            {
-              if(refList[i]==offPOC)
-              {
-                newRef=true;
-              }
-            }
-            for(Int i=0; i<newRefs; i++) 
-            {
-              if(ge[m_iGOPSize+m_extraRPSs].m_referencePics[i]==offPOC-curPOC)
-              {
-                newRef=false;
-              }
-            }
-            if(newRef) 
-            {
-              Int insertPoint=newRefs;
-              //this picture can be added, find appropriate place in list and insert it.
-              if(ge[offGOP].m_temporalId==ge[curGOP].m_temporalId)
-              {
-                ge[offGOP].m_refPic = true;
-              }
-              for(Int j=0; j<newRefs; j++)
-              {
-                if(ge[m_iGOPSize+m_extraRPSs].m_referencePics[j]<offPOC-curPOC||ge[m_iGOPSize+m_extraRPSs].m_referencePics[j]>0)
-                {
-                  insertPoint = j;
-                  break;
-                }
-              }
-              Int prev = offPOC-curPOC;
-              Int prevUsed = ge[offGOP].m_temporalId<=ge[curGOP].m_temporalId;
-              for(Int j=insertPoint; j<newRefs+1; j++)
-              {
-                Int newPrev = ge[m_iGOPSize+m_extraRPSs].m_referencePics[j];
-                Int newUsed = ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j];
-                ge[m_iGOPSize+m_extraRPSs].m_referencePics[j]=prev;
-                ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j]=prevUsed;
-                prevUsed=newUsed;
-                prev=newPrev;
-              }
-              newRefs++;
-            }
-          }
-          if(newRefs>=numPrefRefs)
-          {
-            break;
-          }
-        }
-        ge[m_iGOPSize+m_extraRPSs].m_numRefPics=newRefs;
-        ge[m_iGOPSize+m_extraRPSs].m_POC = curPOC;
-        if (m_extraRPSs == 0)
-        {
-          ge[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 0;
-          ge[m_iGOPSize+m_extraRPSs].m_numRefIdc = 0;
-        }
-        else
-        {
-          Int rIdx =  m_iGOPSize + m_extraRPSs - 1;
-          Int refPOC = ge[rIdx].m_POC;
-          Int refPics = ge[rIdx].m_numRefPics;
-          Int newIdc=0;
-          for(Int i = 0; i<= refPics; i++) 
-          {
-            Int deltaPOC = ((i != refPics)? ge[rIdx].m_referencePics[i] : 0);  // check if the reference abs POC is >= 0
-            Int absPOCref = refPOC+deltaPOC;
-            Int refIdc = 0;
-            for (Int j = 0; j < ge[m_iGOPSize+m_extraRPSs].m_numRefPics; j++)
-            {
-              if ( (absPOCref - curPOC) == ge[m_iGOPSize+m_extraRPSs].m_referencePics[j])
-              {
-                if (ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j])
-                {
-                  refIdc = 1;
-                }
-                else
-                {
-                  refIdc = 2;
-                }
-              }
-            }
-            ge[m_iGOPSize+m_extraRPSs].m_refIdc[newIdc]=refIdc;
-            newIdc++;
-          }
-          ge[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 1;  
-          ge[m_iGOPSize+m_extraRPSs].m_numRefIdc = newIdc;
-          ge[m_iGOPSize+m_extraRPSs].m_deltaRPS = refPOC - ge[m_iGOPSize+m_extraRPSs].m_POC; 
-        }
-        curGOP=m_iGOPSize+m_extraRPSs;
-        m_extraRPSs++;
-      }
-      numRefs=0;
-      for(Int i = 0; i< ge[curGOP].m_numRefPics; i++) 
-      {
-        Int absPOC = curPOC+ge[curGOP].m_referencePics[i];
-        if(absPOC >= 0) 
-        {
-          refList[numRefs]=absPOC;
-          numRefs++;
-        }
-      }
-      refList[numRefs]=curPOC;
-      numRefs++;
-    }
-    checkGOP++;
-  }
-
-  return errorGOP; //update
-}
-#endif
+
+#endif //SVC_EXTENSION
 //! \}
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 442)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 494)
@@ -101,5 +101,7 @@
   Int       m_aiPad[2];                                       ///< number of padded pixels for width and height
 #endif  
-
+#if AUXILIARY_PICTURES
+  ChromaFormat m_InputChromaFormatIDC;
+#endif
   Bool      m_isField;                                        ///< enable field coding
   Bool      m_isTopFieldFirst;
@@ -150,4 +152,5 @@
   Int       m_maxTempLayer;                                  ///< Max temporal layer
 
+#if !LAYER_CTB
   // coding unit (CU) definition
   UInt      m_uiMaxCUWidth;                                   ///< max. CU width in pixel
@@ -161,6 +164,8 @@
   UInt      m_uiQuadtreeTUMaxDepthInter;
   UInt      m_uiQuadtreeTUMaxDepthIntra;
+#endif
   
   // coding tools (bit-depth)
+#if !O0194_DIFFERENT_BITDEPTH_EL_BL
   Int       m_inputBitDepthY;                               ///< bit-depth of input file (luma component)
   Int       m_inputBitDepthC;                               ///< bit-depth of input file (chroma component)
@@ -169,4 +174,8 @@
   Int       m_internalBitDepthY;                            ///< bit-depth codec operates at in luma (input/output files will be converted)
   Int       m_internalBitDepthC;                            ///< bit-depth codec operates at in chroma (input/output files will be converted)
+#endif
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatIDC;
+#endif
 
   // coding tools (PCM bit-depth)
@@ -354,11 +363,12 @@
 #endif
   // internal member functions
+#if LAYER_CTB
+  Void  xSetGlobal      (UInt layerId);                       ///< set global variables
+#else
   Void  xSetGlobal      ();                                   ///< set global variables
+#endif
   Void  xCheckParameter ();                                   ///< check validity of configuration values
   Void  xPrintParameter ();                                   ///< print configuration values
   Void  xPrintUsage     ();                                   ///< print usage
-#if FINAL_RPL_CHANGE_N0082
-  Bool  xconfirmExtraGOP (GOPEntry * ge);
-#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Int       m_adaptiveResolutionChange;                       ///< Indicate adaptive resolution change frame
@@ -375,4 +385,7 @@
   UInt      m_ilcIdc[1024];
 #endif
+#if O0215_PHASE_ALIGNMENT
+  bool m_phaseAlignFlag;
+#endif
 public:
   TAppEncCfg();
@@ -388,9 +401,17 @@
   Int  getNumLayer()               {return m_numLayers;        }
   Int  getGOPSize()                {return m_iGOPSize;          }
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  UInt getInternalBitDepthY(Int iLayer)      {return m_acLayerCfg[iLayer].m_internalBitDepthY; }
+  UInt getInternalBitDepthC(Int iLayer)      {return m_acLayerCfg[iLayer].m_internalBitDepthC; }
+  Bool getPCMInputBitDepthFlag()             {return m_bPCMInputBitDepthFlag;                  }
+#else
   UInt getInternalBitDepthY()      {return m_internalBitDepthY; }
   UInt getInternalBitDepthC()      {return m_internalBitDepthC; }
+#endif
+#if !LAYER_CTB
   UInt getMaxCUWidth()             {return m_uiMaxCUWidth;      }
   UInt getMaxCUHeight()            {return m_uiMaxCUHeight;     }
   UInt getMaxCUDepth()             {return m_uiMaxCUDepth;      }
+#endif
   Int  getDecodingRefreshType()    {return m_iDecodingRefreshType; }
   Int  getWaveFrontSynchro()        { return m_iWaveFrontSynchro; }
@@ -399,10 +420,12 @@
   Char* getBLSyntaxFile()           { return m_BLSyntaxFile;      }
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   Void cfgStringToArray(Int **arr, string cfgString, Int numEntries, const char* logString);
-#endif
 #if REPN_FORMAT_IN_VPS
   RepFormatCfg* getRepFormatCfg(Int i)  { return &m_repFormatCfg[i]; }
 #endif
+#if LAYER_CTB
+  Bool getUsePCM()                  { return m_usePCM;               }
+  UInt getPCMLog2MinSize  ()        { return  m_uiPCMLog2MinSize;    }
+#endif
 #endif
 };// END CLASS DEFINITION TAppEncCfg
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 442)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 494)
@@ -22,4 +22,18 @@
 //! \{
 
+
+#if AUXILIARY_PICTURES
+static inline ChromaFormat numberToChromaFormat(const Int val)
+{
+  switch (val)
+  {
+    case 400: return CHROMA_400; break;
+    case 420: return CHROMA_420; break;
+    case 422: return CHROMA_422; break;
+    case 444: return CHROMA_444; break;
+    default:  return NUM_CHROMA_FORMAT;
+  }
+}
+#endif
 
 // ====================================================================================================================
@@ -38,5 +52,4 @@
   m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
   m_aiPad[1] = m_aiPad[0] = 0;
-#if SCALED_REF_LAYER_OFFSETS
   m_numScaledRefLayerOffsets = 0;
   ::memset(m_scaledRefLayerLeftOffset,   0, sizeof(m_scaledRefLayerLeftOffset));
@@ -44,5 +57,4 @@
   ::memset(m_scaledRefLayerRightOffset,  0, sizeof(m_scaledRefLayerRightOffset));
   ::memset(m_scaledRefLayerBottomOffset, 0, sizeof(m_scaledRefLayerBottomOffset));
-#endif
 }
 
@@ -77,4 +89,9 @@
   string cfg_ReconFile;
   string cfg_dQPFile;
+#if AUXILIARY_PICTURES
+  Int tmpInputChromaFormat;
+  Int tmpChromaFormat;
+#endif
+
   po::Options opts;
   opts.addOptions()
@@ -87,4 +104,8 @@
     ("SourceHeight,-hgt",     m_iSourceHeight, 0, "Source picture height")
     ("CroppingMode",          m_conformanceMode,  0, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
+#if AUXILIARY_PICTURES
+    ("InputChromaFormat",     tmpInputChromaFormat,  420, "InputChromaFormatIDC")
+    ("ChromaFormatIDC",       tmpChromaFormat,    420, "ChromaFormatIDC (400|420|422|444 or set 0 (default) for same as InputChromaFormat)")
+#endif
     ("CropLeft",              m_confLeft,      0, "Left cropping/padding for cropping mode 3")
     ("CropRight",             m_confRight,     0, "Right cropping/padding for cropping mode 3")
@@ -105,4 +126,8 @@
   m_cReconFile = cfg_ReconFile;
   m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
+#if AUXILIARY_PICTURES
+  m_InputChromaFormat = numberToChromaFormat(tmpInputChromaFormat);
+  m_chromaFormatIDC   = ((tmpChromaFormat == 0) ? (m_InputChromaFormat) : (numberToChromaFormat(tmpChromaFormat)));
+#endif
 
   // reading external dQP description from file
@@ -142,4 +167,15 @@
   printf("Real     Format               : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
   printf("Internal Format               : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  printf("Input bit depth               : (Y:%d, C:%d)\n", m_inputBitDepthY   , m_inputBitDepthC    );
+  printf("Internal bit depth            : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC );
+  printf("PCM sample bit depth          : (Y:%d, C:%d)\n", m_cAppEncCfg->getPCMInputBitDepthFlag() ? m_inputBitDepthY : m_internalBitDepthY, m_cAppEncCfg->getPCMInputBitDepthFlag() ? m_inputBitDepthC : m_internalBitDepthC );
+#endif
+#if LAYER_CTB
+  printf("CU size / depth               : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
+  printf("RQT trans. size (min / max)   : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
+  printf("Max RQT depth inter           : %d\n", m_uiQuadtreeTUMaxDepthInter);
+  printf("Max RQT depth intra           : %d\n", m_uiQuadtreeTUMaxDepthIntra);
+#endif
   printf("QP                            : %5.2f\n", m_fQP );
   printf("Intra period                  : %d\n", m_iIntraPeriod );
@@ -157,4 +193,7 @@
 #endif
   printf("WaveFrontSynchro:%d WaveFrontSubstreams:%d", m_cAppEncCfg->getWaveFrontSynchro(), m_iWaveFrontSubstreams);
+#if LAYER_CTB
+  printf("PCM:%d ", (m_cAppEncCfg->getUsePCM() && (1<<m_cAppEncCfg->getPCMLog2MinSize()) <= m_uiMaxCUWidth)? 1 : 0);
+#endif
 }
 
@@ -175,5 +214,9 @@
     {
       // automatic padding to minimum CU size
+#if LAYER_CTB
+      Int minCuSize = m_uiMaxCUHeight >> (m_uiMaxCUDepth - 1);
+#else
       Int minCuSize = m_cAppEncCfg->getMaxCUHeight() >> (m_cAppEncCfg->getMaxCUDepth() - 1);
+#endif
       if (m_iSourceWidth % minCuSize)
       {
@@ -240,7 +283,13 @@
   }
 
+#if LAYER_CTB
+  UInt maxCUWidth = m_uiMaxCUWidth;
+  UInt maxCUHeight = m_uiMaxCUHeight;
+  UInt maxCUDepth = m_uiMaxCUDepth;
+#else
   UInt maxCUWidth = m_cAppEncCfg->getMaxCUWidth();
   UInt maxCUHeight = m_cAppEncCfg->getMaxCUHeight();
   UInt maxCUDepth = m_cAppEncCfg->getMaxCUDepth();
+#endif
   bool check_failed = false; /* abort if there is a fatal configuration problem */
 #define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
@@ -255,8 +304,15 @@
   }
 
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    xConfirmPara( m_iQP <  -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY(layer) - 8) || m_iQP > 51,                "QP exceeds supported range (-QpBDOffsety to 51)" );
+  }
+#else
   xConfirmPara( m_iQP <  -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY() - 8) || m_iQP > 51,                "QP exceeds supported range (-QpBDOffsety to 51)" );
-
-
-  m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + m_cAppEncCfg->getMaxCUHeight() - 1) / m_cAppEncCfg->getMaxCUHeight() : 1;
+#endif
+
+
+  m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + maxCUHeight - 1) / maxCUHeight : 1;
   xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
   xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_cAppEncCfg->getWaveFrontSynchro(), "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
@@ -273,9 +329,45 @@
   xConfirmPara( m_confTop    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling");
   xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling");
+
+#if LAYER_CTB  
+  xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
+  xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
+  xConfirmPara( m_uiMaxCUWidth < 16,                                                        "Maximum partition width size should be larger than or equal to 16");
+  xConfirmPara( m_uiMaxCUHeight < 16,                                                       "Maximum partition height size should be larger than or equal to 16");
+  xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
+  xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5,                                        "QuadtreeTULog2MaxSize must be 5 or smaller.");
+  xConfirmPara( (1<<m_uiQuadtreeTULog2MaxSize) > m_uiMaxCUWidth,                                        "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");
+  xConfirmPara( m_uiQuadtreeTULog2MaxSize < m_uiQuadtreeTULog2MinSize,                "QuadtreeTULog2MaxSize must be greater than or equal to m_uiQuadtreeTULog2MinSize.");
+  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
+  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
+  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUWidth  >> m_uiMaxCUDepth ), "Minimum CU width must be greater than minimum transform size." );
+  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUHeight >> m_uiMaxCUDepth ), "Minimum CU height must be greater than minimum transform size." );
+  xConfirmPara( m_uiQuadtreeTUMaxDepthInter < 1,                                                         "QuadtreeTUMaxDepthInter must be greater than or equal to 1" );
+  xConfirmPara( m_uiMaxCUWidth < ( 1 << (m_uiQuadtreeTULog2MinSize + m_uiQuadtreeTUMaxDepthInter - 1) ), "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1" );
+  xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1,                                                         "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" );
+  xConfirmPara( m_uiMaxCUWidth < ( 1 << (m_uiQuadtreeTULog2MinSize + m_uiQuadtreeTUMaxDepthIntra - 1) ), "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1" );
+
+  // max CU width and height should be power of 2
+  UInt ui = m_uiMaxCUWidth;
+  while(ui)
+  {
+    ui >>= 1;
+    if( (ui & 1) == 1)
+      xConfirmPara( ui != 1 , "Width should be 2^n");
+  }
+  ui = m_uiMaxCUHeight;
+  while(ui)
+  {
+    ui >>= 1;
+    if( (ui & 1) == 1)
+      xConfirmPara( ui != 1 , "Height should be 2^n");
+  }
+#endif
+
 #undef xConfirmPara
   return check_failed;
 }
 
-#endif
+#endif //SVC_EXTENSION
 
 
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 442)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 494)
@@ -6,4 +6,5 @@
 #define __TAPPENCLAYERCFG__
 
+#if SVC_EXTENSION
 #include "TLibCommon/CommonDef.h"
 #include "TLibEncoder/TEncCfg.h"
@@ -11,7 +12,5 @@
 
 using namespace std;
-#if SVC_EXTENSION
 class TAppEncCfg;
-#endif
 //! \ingroup TAppEncoder
 //! \{
@@ -43,4 +42,9 @@
   Int       m_iIntraPeriod;                                   ///< period of I-slice (random access period)
   Double    m_fQP;                                            ///< QP value of key-picture (floating point)
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatIDC;
+  ChromaFormat m_InputChromaFormat;
+  Int          m_auxId;
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -55,4 +59,18 @@
   Int       *m_predLayerIds;
   Int       m_numActiveRefLayers;
+#endif
+
+#if LAYER_CTB
+  // coding unit (CU) definition
+  UInt      m_uiMaxCUWidth;                                   ///< max. CU width in pixel
+  UInt      m_uiMaxCUHeight;                                  ///< max. CU height in pixel
+  UInt      m_uiMaxCUDepth;                                   ///< max. CU depth
+  
+  // transfom unit (TU) definition
+  UInt      m_uiQuadtreeTULog2MaxSize;
+  UInt      m_uiQuadtreeTULog2MinSize;
+  
+  UInt      m_uiQuadtreeTUMaxDepthInter;
+  UInt      m_uiQuadtreeTUMaxDepthIntra;
 #endif
 
@@ -70,7 +88,5 @@
   Int       m_maxTidIlRefPicsPlus1;
 #endif 
-#if SVC_EXTENSION
   Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
-#endif
 
   Int       m_iQP;                                            ///< QP value of key-picture (integer)
@@ -78,5 +94,4 @@
   Int*      m_aidQP;                                          ///< array of slice QP values
   TAppEncCfg* m_cAppEncCfg;                                   ///< pointer to app encoder config
-#if SCALED_REF_LAYER_OFFSETS
   Int       m_numScaledRefLayerOffsets  ;
   Int       m_scaledRefLayerLeftOffset  [MAX_LAYERS];
@@ -84,7 +99,11 @@
   Int       m_scaledRefLayerRightOffset [MAX_LAYERS];
   Int       m_scaledRefLayerBottomOffset[MAX_LAYERS];
-#endif  
-#if FINAL_RPL_CHANGE_N0082
-  GOPEntry  m_GOPListLayer[MAX_GOP];                            ///< for layer
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  Int       m_inputBitDepthY;                               ///< bit-depth of input file (luma component)
+  Int       m_inputBitDepthC;                               ///< bit-depth of input file (chroma component)
+  Int       m_internalBitDepthY;                            ///< bit-depth codec operates at in luma (input/output files will be converted)
+  Int       m_internalBitDepthC;                            ///< bit-depth codec operates at in chroma (input/output files will be converted)
+  Int       m_outputBitDepthY;                              ///< bit-depth of output file (luma component)
+  Int       m_outputBitDepthC;                              ///< bit-depth of output file (chroma component)
 #endif
 #if REPN_FORMAT_IN_VPS
@@ -122,4 +141,9 @@
   Int     getConfTop()                {return m_confTop;          }
   Int     getConfBottom()             {return m_confBottom;       }
+#if AUXILIARY_PICTURES
+  ChromaFormat getInputChromaFormat()   {return m_InputChromaFormat;}
+  ChromaFormat getChromaFormatIDC()     {return m_chromaFormatIDC;  }
+  Int          getAuxId()               {return m_auxId;            }
+#endif
 
   Int     getIntQP()                  {return m_iQP;              } 
@@ -152,7 +176,4 @@
   Bool    getRCForceIntraQP()         {return m_RCForceIntraQP;        }
 #endif
-#if FINAL_RPL_CHANGE_N0082
-  GOPEntry getGOPEntry(Int i )        {return m_GOPListLayer[i];  }
-#endif
 #if REPN_FORMAT_IN_VPS
   Int     getRepFormatIdx()           { return m_repFormatIdx;  }
@@ -164,5 +185,12 @@
   Int     getMaxTidIlRefPicsPlus1()   { return m_maxTidIlRefPicsPlus1; }
 #endif 
+#if LAYER_CTB
+  UInt    getMaxCUWidth()             {return m_uiMaxCUWidth;      }
+  UInt    getMaxCUHeight()            {return m_uiMaxCUHeight;     }
+  UInt    getMaxCUDepth()             {return m_uiMaxCUDepth;      }
+#endif
 }; // END CLASS DEFINITION TAppEncLayerCfg
+
+#endif //SVC_EXTENSION
 
 //! \}
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 442)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 494)
@@ -2,5 +2,5 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
  * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -98,10 +98,16 @@
     // Auto generation of the format index
     if( m_acLayerCfg[layer].getRepFormatIdx() == -1 )
-    {
-      // Currently only picture width and height are considred. It has to be updated if different chroma format and bit-depth will are used.
+    {      
       Bool found = false;
       for( UInt idx = 0; idx < layer; idx++ )
       {
-        if( m_acLayerCfg[layer].getSourceWidth() == m_acLayerCfg[idx].getSourceWidth() && m_acLayerCfg[layer].getSourceHeight() == m_acLayerCfg[idx].getSourceHeight() )
+        if( m_acLayerCfg[layer].getSourceWidth() == m_acLayerCfg[idx].getSourceWidth() && m_acLayerCfg[layer].getSourceHeight() == m_acLayerCfg[idx].getSourceHeight()
+#if AUXILIARY_PICTURES
+          && m_acLayerCfg[layer].getChromaFormatIDC() == m_acLayerCfg[idx].getChromaFormatIDC()
+#endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+          && m_acLayerCfg[layer].m_internalBitDepthY == m_acLayerCfg[idx].m_internalBitDepthY && m_acLayerCfg[layer].m_internalBitDepthC == m_acLayerCfg[idx].m_internalBitDepthC
+#endif
+          )
         {
           found = true;
@@ -117,5 +123,5 @@
     }
 
-    assert( m_acLayerCfg[layer].getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a layer" );   
+    assert( m_acLayerCfg[layer].getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a layer" );
     vps->setVpsRepFormatIdx( layer, m_acLayerCfg[layer].getRepFormatIdx() );
     maxRepFormatIdx = std::max( m_acLayerCfg[layer].getRepFormatIdx(), maxRepFormatIdx );
@@ -141,11 +147,20 @@
   for(UInt idx=0; idx < vps->getVpsNumRepFormats(); idx++)
   {
-    RepFormat *repFormat = vps->getVpsRepFormat( idx );    
+    RepFormat *repFormat = vps->getVpsRepFormat( idx );
     repFormat->setPicWidthVpsInLumaSamples  ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceWidth()   );
     repFormat->setPicHeightVpsInLumaSamples ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceHeight()  );
+#if AUXILIARY_PICTURES
+    repFormat->setChromaFormatVpsIdc        ( m_acLayerCfg[mapIdxToLayer[idx]].getChromaFormatIDC() );
+#else
     repFormat->setChromaFormatVpsIdc        ( 1                                             );  // Need modification to change for each layer - corresponds to 420
+#endif
     repFormat->setSeparateColourPlaneVpsFlag( 0                                             );  // Need modification to change for each layer
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY(mapIdxToLayer[idx])      );  // Need modification to change for each layer
+    repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC(mapIdxToLayer[idx])      );  // Need modification to change for each layer
+#else
     repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY()                        );  // Need modification to change for each layer
     repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC()                        );  // Need modification to change for each layer
+#endif
   }
   delete [] mapIdxToLayer;
@@ -153,4 +168,16 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    //1
+    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+
+    // Set this to be used in Upsampling filter in function "TComUpsampleFilter::upsampleBasePic"
+    g_bitDepthYLayer[layer] = g_bitDepthY;
+    g_bitDepthCLayer[layer] = g_bitDepthC;
+#endif
     //m_acTEncTop[layer].setVPS(&vps);
     m_acTEncTop[layer].setFrameRate                    ( m_acLayerCfg[layer].getFrameRate() );
@@ -187,6 +214,6 @@
 #endif
 #endif
-    // set layer ID 
-    m_acTEncTop[layer].setLayerId ( layer ); 
+    // set layer ID
+    m_acTEncTop[layer].setLayerId ( layer );
     m_acTEncTop[layer].setNumLayer ( m_numLayers );
     m_acTEncTop[layer].setLayerEnc(m_apcTEncTop);
@@ -196,9 +223,6 @@
     m_acTEncTop[layer].setDecodingRefreshType          ( m_iDecodingRefreshType );
     m_acTEncTop[layer].setGOPSize                      ( m_iGOPSize );
-#if FINAL_RPL_CHANGE_N0082
-    m_acTEncTop[layer].setGopList                      ( m_acLayerCfg[layer].m_GOPListLayer );
-#else
     m_acTEncTop[layer].setGopList                      ( m_GOPList );
-#endif
+
     m_acTEncTop[layer].setExtraRPSs                    ( m_extraRPSs );
     for(Int i = 0; i < MAX_TLAYER; i++)
@@ -220,7 +244,7 @@
     if (layer<m_numLayers-1)
     {
-       m_acTEncTop[layer].setMaxTidIlRefPicsPlus1 ( m_acLayerCfg[layer].getMaxTidIlRefPicsPlus1()); 
-    }
-#endif 
+       m_acTEncTop[layer].setMaxTidIlRefPicsPlus1 ( m_acLayerCfg[layer].getMaxTidIlRefPicsPlus1());
+    }
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
     if(layer)
@@ -241,10 +265,10 @@
       else
       {
-        m_acTEncTop[layer].setNumSamplePredRefLayers   ( m_acLayerCfg[layer].getNumSamplePredRefLayers() );      
+        m_acTEncTop[layer].setNumSamplePredRefLayers   ( m_acLayerCfg[layer].getNumSamplePredRefLayers() );
         for(Int i = 0; i < m_acTEncTop[layer].getNumSamplePredRefLayers(); i++)
         {
           m_acTEncTop[layer].setSamplePredRefLayerId   ( i, m_acLayerCfg[layer].getSamplePredRefLayerId(i));
           m_acTEncTop[layer].setSamplePredEnabledFlag  (m_acLayerCfg[layer].getSamplePredRefLayerId(i), true);
-        }        
+        }
       }
       if(m_acLayerCfg[layer].getNumMotionPredRefLayers() == -1)
@@ -257,10 +281,10 @@
       else
       {
-        m_acTEncTop[layer].setNumMotionPredRefLayers   ( m_acLayerCfg[layer].getNumMotionPredRefLayers() );      
+        m_acTEncTop[layer].setNumMotionPredRefLayers   ( m_acLayerCfg[layer].getNumMotionPredRefLayers() );
         for(Int i = 0; i < m_acTEncTop[layer].getNumMotionPredRefLayers(); i++)
         {
           m_acTEncTop[layer].setMotionPredRefLayerId   ( i, m_acLayerCfg[layer].getMotionPredRefLayerId(i));
           m_acTEncTop[layer].setMotionPredEnabledFlag  (m_acLayerCfg[layer].getMotionPredRefLayerId(i), true);
-        }        
+        }
       }
       Int numDirectRefLayers = 0;
@@ -283,5 +307,5 @@
       else
       {
-        m_acTEncTop[layer].setNumDirectRefLayers       ( m_acLayerCfg[layer].getNumDirectRefLayers() );      
+        m_acTEncTop[layer].setNumDirectRefLayers       ( m_acLayerCfg[layer].getNumDirectRefLayers() );
         for(Int i = 0; i < m_acTEncTop[layer].getNumDirectRefLayers(); i++)
         {
@@ -304,5 +328,5 @@
       else
       {
-        m_acTEncTop[layer].setNumActiveRefLayers       ( m_acLayerCfg[layer].getNumActiveRefLayers() );      
+        m_acTEncTop[layer].setNumActiveRefLayers       ( m_acLayerCfg[layer].getNumActiveRefLayers() );
         for(Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++)
         {
@@ -358,10 +382,17 @@
     m_acTEncTop[layer].setUseRDOQTS                    ( m_useRDOQTS   );
     m_acTEncTop[layer].setRDpenalty                    ( m_rdPenalty );
+#if LAYER_CTB
+    m_acTEncTop[layer].setQuadtreeTULog2MaxSize        ( m_acLayerCfg[layer].m_uiQuadtreeTULog2MaxSize );
+    m_acTEncTop[layer].setQuadtreeTULog2MinSize        ( m_acLayerCfg[layer].m_uiQuadtreeTULog2MinSize );
+    m_acTEncTop[layer].setQuadtreeTUMaxDepthInter      ( m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthInter );
+    m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra      ( m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthIntra );
+#else
     m_acTEncTop[layer].setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
     m_acTEncTop[layer].setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
     m_acTEncTop[layer].setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
     m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
+#endif
     m_acTEncTop[layer].setUseFastEnc                   ( m_bUseFastEnc  );
-    m_acTEncTop[layer].setUseEarlyCU                   ( m_bUseEarlyCU  ); 
+    m_acTEncTop[layer].setUseEarlyCU                   ( m_bUseEarlyCU  );
     m_acTEncTop[layer].setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
     m_acTEncTop[layer].setUseCbfFastMode               ( m_bUseCbfFastMode  );
@@ -383,4 +414,12 @@
     m_acTEncTop[layer].setUseWP                   ( m_useWeightedPred      );
     m_acTEncTop[layer].setWPBiPred                ( m_useWeightedBiPred   );
+#if O0194_WEIGHTED_PREDICTION_CGS
+    if (layer!=0)
+    {
+      // Enable weighted prediction for enhancement layer
+      m_acTEncTop[layer].setUseWP                 ( true   );
+      m_acTEncTop[layer].setWPBiPred              ( true   );
+    }
+#endif
     //====== Parallel Merge Estimation ========
     m_acTEncTop[layer].setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
@@ -393,5 +432,9 @@
     m_acTEncTop[layer].setSliceSegmentMode        ( m_sliceSegmentMode         );
     m_acTEncTop[layer].setSliceSegmentArgument    ( m_sliceSegmentArgument     );
+#if LAYER_CTB
+    Int iNumPartInCU = 1<<(m_acLayerCfg[layer].m_uiMaxCUDepth<<1);
+#else
     Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
+#endif
     if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU)
     {
@@ -417,6 +460,6 @@
     m_acTEncTop[layer].setSaoLcuBoundary (m_saoLcuBoundary);
     m_acTEncTop[layer].setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
-    m_acTEncTop[layer].setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
-    m_acTEncTop[layer].setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
+    m_acTEncTop[layer].setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
+    m_acTEncTop[layer].setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
 
     m_acTEncTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
@@ -483,5 +526,5 @@
     if(uiTilesCount == 1)
     {
-      m_bLFCrossTileBoundaryFlag = true; 
+      m_bLFCrossTileBoundaryFlag = true;
     }
     m_acTEncTop[layer].setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
@@ -519,5 +562,5 @@
     m_acTEncTop[layer].setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
     m_acTEncTop[layer].setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
-    m_acTEncTop[layer].setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); 
+    m_acTEncTop[layer].setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
     m_acTEncTop[layer].setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
     m_acTEncTop[layer].setAspectRatioIdc( m_aspectRatioIdc );
@@ -550,5 +593,4 @@
     m_acTEncTop[layer].setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
     m_acTEncTop[layer].setElRapSliceTypeB(layer == 0? 0 : m_elRapSliceBEnabled);
-#if SCALED_REF_LAYER_OFFSETS
     if( layer > 0 )
     {
@@ -557,14 +599,16 @@
       {
         m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( 2*m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
-                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);  
-      }
-    }
-#endif
+                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);
+      }
+    }
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
     m_acTEncTop[layer].setAdaptiveResolutionChange( m_adaptiveResolutionChange );
 #endif
+#if AUXILIARY_PICTURES
+    m_acTEncTop[layer].setChromaFormatIDC( m_acLayerCfg[layer].m_chromaFormatIDC );
+#endif
   }
 }
-#else
+#else //SVC_EXTENSION
 Void TAppEncTop::xInitLibCfg()
 {
@@ -671,5 +715,5 @@
   m_cTEncTop.setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
   m_cTEncTop.setUseFastEnc                   ( m_bUseFastEnc  );
-  m_cTEncTop.setUseEarlyCU                   ( m_bUseEarlyCU  ); 
+  m_cTEncTop.setUseEarlyCU                   ( m_bUseEarlyCU  );
   m_cTEncTop.setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
   m_cTEncTop.setUseCbfFastMode            ( m_bUseCbfFastMode  );
@@ -725,6 +769,6 @@
   m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary);
   m_cTEncTop.setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
-  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
-  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
+  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
+  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
 
   m_cTEncTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
@@ -783,5 +827,5 @@
   if(uiTilesCount == 1)
   {
-    m_bLFCrossTileBoundaryFlag = true; 
+    m_bLFCrossTileBoundaryFlag = true;
   }
   m_cTEncTop.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
@@ -809,5 +853,5 @@
   m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
   m_cTEncTop.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
-  m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); 
+  m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
   m_cTEncTop.setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
   m_cTEncTop.setAspectRatioIdc( m_aspectRatioIdc );
@@ -840,5 +884,5 @@
   m_cTEncTop.setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
 }
-#endif
+#endif //SVC_EXTENSION
 
 Void TAppEncTop::xCreateLib()
@@ -851,15 +895,37 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    //2
+    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
+#if LAYER_CTB
+    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
+    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
+    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
+    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
+#endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_acLayerCfg[layer].m_inputBitDepthY, m_acLayerCfg[layer].m_inputBitDepthC, m_acLayerCfg[layer].m_internalBitDepthY, m_acLayerCfg[layer].m_internalBitDepthC );  // read  mode
+#else
     m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
+#endif
     m_acTVideoIOYuvInputFile[layer].skipFrames(m_FrameSkip, m_acLayerCfg[layer].getSourceWidth() - m_acLayerCfg[layer].getPad()[0], m_acLayerCfg[layer].getSourceHeight() - m_acLayerCfg[layer].getPad()[1]);
 
     if (!m_acLayerCfg[layer].getReconFile().empty())
     {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+      m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_acLayerCfg[layer].m_outputBitDepthY, m_acLayerCfg[layer].m_outputBitDepthC, m_acLayerCfg[layer].m_internalBitDepthY, m_acLayerCfg[layer].m_internalBitDepthC );  // write mode
+#else
       m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // write mode
+#endif
     }
 
     m_acTEncTop[layer].create();
   }
-#else
+#else //SVC_EXTENSION
   m_cTVideoIOYuvInputFile.open( m_pchInputFile,     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
   m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
@@ -870,5 +936,5 @@
   // Neo Decoder
   m_cTEncTop.create();
-#endif
+#endif //SVC_EXTENSION
 }
 
@@ -882,4 +948,11 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
+#if LAYER_CTB
+    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
+    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
+    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
+    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
+#endif
+
     m_acTVideoIOYuvInputFile[layer].close();
     m_acTVideoIOYuvReconFile[layer].close();
@@ -887,5 +960,5 @@
     m_acTEncTop[layer].destroy();
   }
-#else
+#else //SVC_EXTENSION
   m_cTVideoIOYuvInputFile.close();
   m_cTVideoIOYuvReconFile.close();
@@ -893,5 +966,5 @@
   // Neo Decoder
   m_cTEncTop.destroy();
-#endif
+#endif //SVC_EXTENSION
 }
 
@@ -901,4 +974,23 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    //3
+    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
+#if LAYER_CTB
+    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
+    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
+    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
+    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
+
+    memcpy( g_auiZscanToRaster, g_auiLayerZscanToRaster[layer], sizeof( g_auiZscanToRaster ) );
+    memcpy( g_auiRasterToZscan, g_auiLayerRasterToZscan[layer], sizeof( g_auiRasterToZscan ) );
+    memcpy( g_auiRasterToPelX,  g_auiLayerRasterToPelX[layer],  sizeof( g_auiRasterToPelX ) );
+    memcpy( g_auiRasterToPelY,  g_auiLayerRasterToPelY[layer],  sizeof( g_auiRasterToPelY ) );
+#endif
     m_acTEncTop[layer].init(isFieldCoding);
   }
@@ -915,4 +1007,12 @@
     for(Int layerId = 0; layerId <= vps->getMaxLayerId(); layerId++)
     {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+      //4
+      g_bitDepthY = m_acLayerCfg[layerId].m_internalBitDepthY;
+      g_bitDepthC = m_acLayerCfg[layerId].m_internalBitDepthC;
+
+      g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthY : m_acLayerCfg[layerId].m_internalBitDepthY;
+      g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthC : m_acLayerCfg[layerId].m_internalBitDepthC;
+#endif
       vps->setLayerIdIncludedFlag(true, setId, layerId);
     }
@@ -930,5 +1030,5 @@
     vps->setScalabilityMask(i, false);
   }
-  if(m_numLayers > 1) 
+  if(m_numLayers > 1)
   {
     Int scalabilityTypes = 0;
@@ -938,5 +1038,9 @@
       scalabilityTypes += m_scalabilityMask[i];
     }
+#if AUXILIARY_PICTURES
+    assert( scalabilityTypes <= 2 );
+#else
     assert( scalabilityTypes == 1 );
+#endif
     vps->setNumScalabilityTypes(scalabilityTypes);
   }
@@ -959,32 +1063,80 @@
     vps->setDimensionId(i, 0, i);
   }
+#if AUXILIARY_PICTURES
+  if (m_scalabilityMask[3])
+  {
+    UInt maxAuxId = 0;
+    UInt auxDimIdLen = 0;
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      if (m_acLayerCfg[i].getAuxId() > maxAuxId)
+      {
+        maxAuxId = m_acLayerCfg[i].getAuxId();
+      }
+    }
+    while((1 << auxDimIdLen) < (maxAuxId + 1))
+    {
+      auxDimIdLen++;
+    }
+    vps->setDimensionIdLen(1, auxDimIdLen);
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      vps->setDimensionId(i, 1, m_acLayerCfg[i].getAuxId());
+    }
+  }
+#endif
 #endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
 #if N0120_MAX_TID_REF_CFG
   vps->setMaxTidRefPresentFlag(m_maxTidRefPresentFlag);
-#else 
+#else
   vps->setMaxTidRefPresentFlag(true);
+#endif
+  if (vps->getMaxTidRefPresentFlag())
+  {
+    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
+    {
+#if N0120_MAX_TID_REF_CFG
+#if O0225_MAX_TID_FOR_REF_LAYERS
+      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
+      {
+        vps->setMaxTidIlRefPicsPlus1(i, j, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
+      }
+#else
+      vps->setMaxTidIlRefPicsPlus1(i, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
 #endif 
-  if (vps->getMaxTidRefPresentFlag())
+#else
+#if O0225_MAX_TID_FOR_REF_LAYERS
+      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
+      {
+        vps->setMaxTidIlRefPicsPlus1(i, j, vps->getMaxTLayers()+1);
+      }
+#else
+      vps->setMaxTidIlRefPicsPlus1(i, vps->getMaxTLayers()+1);
+#endif
+#endif
+    }
+  }
+  else
   {
     for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
     {
-#if N0120_MAX_TID_REF_CFG
-      vps->setMaxTidIlRefPicsPlus1(i, m_acTEncTop[i].getMaxTidIlRefPicsPlus1()); 
-#else 
-      vps->setMaxTidIlRefPicsPlus1(i, vps->getMaxTLayers()+1);
+#if O0225_MAX_TID_FOR_REF_LAYERS
+      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
+      {
+        vps->setMaxTidIlRefPicsPlus1(i, j, 7);
+      }
+#else
+      vps->setMaxTidIlRefPicsPlus1(i, 7);
 #endif 
     }
   }
-  else
-  {
-    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
-    {
-      vps->setMaxTidIlRefPicsPlus1(i, 7);
-    }
-  }
-#endif 
+#endif
 #if ILP_SSH_SIG
+#if ILP_SSH_SIG_FIX
+    vps->setIlpSshSignalingEnabledFlag(false);
+#else
     vps->setIlpSshSignalingEnabledFlag(true);
+#endif
 #endif
 #if VPS_EXTN_PROFILE_INFO
@@ -998,21 +1150,16 @@
 #endif
   // Target output layer
-#if VPS_PROFILE_OUTPUT_LAYERS
-  vps->setNumOutputLayerSets(vps->getNumLayerSets());    
-  vps->setNumProfileTierLevel(vps->getNumLayerSets());   
+  vps->setNumOutputLayerSets(vps->getNumLayerSets());
+  vps->setNumProfileTierLevel(vps->getNumLayerSets());
   vps->setDefaultOneTargetOutputLayerFlag(true);
   for(i = 1; i < vps->getNumLayerSets(); i++)
   {
     vps->setProfileLevelTierIdx(i, i);
-    vps->setOutputLayerSetIdx(i, i); 
-  }
-#else
-  vps->setNumOutputLayerSets(1);
-  Int lsIdx = 1;
-  vps->setOutputLayerSetIdx(0, lsIdx); // Because only one layer set
-#endif
+    vps->setOutputLayerSetIdx(i, i);
+  }
+
   for(Int lsIdx = 1; lsIdx < vps->getNumLayerSets(); lsIdx++)
   {
-    // Include the highest layer as output layer 
+    // Include the highest layer as output layer
     for(UInt layer=0; layer <= vps->getMaxLayerId() ; layer++)
     {
@@ -1073,9 +1220,18 @@
 #endif
 #endif
-#if JCTVC_M0458_INTERLAYER_RPS_SIG        
-    vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true); 
-#endif 
-#if N0147_IRAP_ALIGN_FLAG    
-    vps->setCrossLayerIrapAlignFlag(true); 
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+    vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true);
+#endif
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+    for(i = 1; i< vps->getMaxLayers(); i++)
+    {
+      if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0  )
+      {
+        vps->setPocLsbNotPresentFlag(i, false);
+      }
+    }
+#endif
+#if N0147_IRAP_ALIGN_FLAG
+    vps->setCrossLayerIrapAlignFlag(true);
     for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
     {
@@ -1083,5 +1239,5 @@
       {
         if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
-        {          
+        {
           if(m_acTEncTop[layerCtr].getIntraPeriod() !=  m_acTEncTop[refLayerCtr].getIntraPeriod())
           {
@@ -1097,12 +1253,19 @@
       vps->setCrossLayerIrapAlignFlag(false);
     }
-#endif 
+#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   vps->setSingleLayerForNonIrapFlag(m_adaptiveResolutionChange > 0 ? true : false);
 #endif
+#if !VPS_EXTN_OFFSET_CALC
 #if VPS_EXTN_OFFSET
   // to be updated according to the current semantics
   vps->setExtensionOffset( 0xffff );
 #endif
+#endif
+
+#if O0215_PHASE_ALIGNMENT
+  vps->setPhaseAlignFlag( m_phaseAlignFlag );
+#endif
+
 #else //SVC_EXTENSION
   m_cTEncTop.init(isFieldCoding);
@@ -1148,4 +1311,12 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    //5
+    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
     // allocate original YUV buffer
     pcPicYuvOrg[layer] = new TComPicYuv;
@@ -1153,5 +1324,17 @@
     {
 #if SVC_UPSAMPLING
+#if LAYER_CTB
+#if AUXILIARY_PICTURES
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#else
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#endif
+#else
+#if AUXILIARY_PICTURES
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#else
       pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#endif
+#endif
 #else
       pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
@@ -1161,5 +1344,17 @@
     {
 #if SVC_UPSAMPLING
+#if LAYER_CTB
+#if AUXILIARY_PICTURES
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#else
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#endif
+#else
+#if AUXILIARY_PICTURES
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#else
       pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#endif
+#endif
 #else
       pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
@@ -1190,5 +1385,5 @@
   while ( !bEos )
   {
-    // Read enough frames 
+    // Read enough frames
     Bool bFramesReadyToCode = false;
     while(!bFramesReadyToCode)
@@ -1196,4 +1391,19 @@
       for(UInt layer=0; layer<m_numLayers; layer++)
       {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+        //6
+        g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+        g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+        g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+        g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
+#if LAYER_CTB
+        g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
+        g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
+        g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
+        g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
+#endif
+
         // get buffers
         xGetBuffer(pcPicYuvRec, layer);
@@ -1201,4 +1411,11 @@
         // read input YUV file
         m_acTVideoIOYuvInputFile[layer].read( pcPicYuvOrg[layer], m_acLayerCfg[layer].getPad() );
+
+#if AUXILIARY_PICTURES
+        if (m_acLayerCfg[layer].getChromaFormatIDC() == CHROMA_400)
+        {
+          pcPicYuvOrg[layer]->convertToMonochrome();
+        }
+#endif
 
         if(layer == m_numLayers-1)
@@ -1257,5 +1474,5 @@
 #endif
 
-    // loop through frames in one GOP 
+    // loop through frames in one GOP
     for ( UInt iPicIdInGOP=0; iPicIdInGOP < (bFirstFrame? 1:m_iGOPSize); iPicIdInGOP++ )
     {
@@ -1263,4 +1480,23 @@
       for(UInt layer=0; layer<m_numLayers; layer++)
       {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+        //7
+        g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+        g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+        g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+        g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
+#if LAYER_CTB
+        g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
+        g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
+        g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
+        g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
+
+        memcpy( g_auiZscanToRaster, g_auiLayerZscanToRaster[layer], sizeof( g_auiZscanToRaster ) );
+        memcpy( g_auiRasterToZscan, g_auiLayerRasterToZscan[layer], sizeof( g_auiRasterToZscan ) );
+        memcpy( g_auiRasterToPelX,  g_auiLayerRasterToPelX[layer],  sizeof( g_auiRasterToPelX ) );
+        memcpy( g_auiRasterToPelY,  g_auiLayerRasterToPelY[layer],  sizeof( g_auiRasterToPelY ) );
+#endif
         // call encoding function for one frame
         if ( m_isField )
@@ -1288,4 +1524,12 @@
     for(UInt layer=0; layer<m_numLayers; layer++)
     {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+      //8
+      g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+      g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+      g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+      g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
       // write bistream to file if necessary
       iNumEncoded = m_acTEncTop[layer].getNumPicRcvd();
@@ -1528,5 +1772,17 @@
 
 #if SVC_UPSAMPLING
+#if LAYER_CTB
+#if AUXILIARY_PICTURES
+    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#else
+    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#endif
+#else
+#if AUXILIARY_PICTURES
+    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#else
     rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#endif
+#endif
 #else
     rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
@@ -1551,5 +1807,5 @@
       delete pcPicYuvRec; pcPicYuvRec = NULL;
     }
-  }  
+  }
 }
 
@@ -1602,5 +1858,5 @@
 #endif
       {
-        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), 
+        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(),
           m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
       }
@@ -1622,5 +1878,5 @@
     for ( i = 0; i < iNumEncoded/2; i++ )
 #endif
-    {      
+    {
       const AccessUnit& auTop = *(iterBitstream++);
       const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
