Index: branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 464)
+++ branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 466)
@@ -362,17 +362,4 @@
   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 VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -392,4 +379,5 @@
   string* cfg_predLayerIdsPtr    [MAX_LAYERS];
 #endif
+#if SCALED_REF_LAYER_OFFSETS
   string    cfg_scaledRefLayerLeftOffset [MAX_LAYERS];
   string    cfg_scaledRefLayerTopOffset [MAX_LAYERS];
@@ -402,4 +390,5 @@
   string*    cfg_scaledRefLayerRightOffsetPtr  [MAX_LAYERS];
   string*    cfg_scaledRefLayerBottomOffsetPtr [MAX_LAYERS];
+#endif
 #if RC_SHVC_HARMONIZATION
   Bool*   cfg_RCEnableRateControl  [MAX_LAYERS];
@@ -411,4 +400,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]; 
@@ -427,17 +424,4 @@
     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
@@ -453,4 +437,5 @@
     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++)
@@ -461,4 +446,5 @@
       cfg_scaledRefLayerBottomOffsetPtr[layer] = &cfg_scaledRefLayerBottomOffset[layer];
     }
+#endif
 #if RC_SHVC_HARMONIZATION
     cfg_RCEnableRateControl[layer]   = &m_acLayerCfg[layer].m_RCEnableRateControl;
@@ -470,4 +456,12 @@
     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; 
@@ -483,10 +477,10 @@
   string  cfg_tileSets;
 #endif
-#else //SVC_EXTENSION
+#else
   string cfg_InputFile;
   string cfg_BitstreamFile;
   string cfg_ReconFile;
   string cfg_dQPFile;
-#endif //SVC_EXTENSION
+#endif
   string cfg_ColumnWidth;
   string cfg_RowHeight;
@@ -538,4 +532,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)")
@@ -545,4 +540,6 @@
   ("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)")
+#endif
+#if SCALED_REF_LAYER_OFFSETS
   ("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"
@@ -554,4 +551,14 @@
   ("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")
+#endif
+#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
   ("MaxTidRefPresentFlag", m_maxTidRefPresentFlag, true, "max_tid_ref_present_flag (0: not present, 1: present(default)) " )
@@ -569,5 +576,5 @@
   ("IlSampleOnlyPred%d",       m_ilSampleOnlyPred, 0, MAX_LAYERS, "Set inter_layer_sample_pred_only_flag for all slices")
 #endif
-#else //SVC_EXTENSION
+#else
   ("InputFile,i",           cfg_InputFile,     string(""), "Original YUV input file name")
   ("BitstreamFile,b",       cfg_BitstreamFile, string(""), "Bitstream output file name")
@@ -590,5 +597,5 @@
   ("ConfBottom",            m_confBottom,          0, "Bottom offset for window conformance mode 3")
   ("FrameRate,-fr",         m_iFrameRate,          0, "Frame rate")
-#endif //SVC_EXTENSION
+#endif
 
   //Field coding parameters
@@ -607,34 +614,4 @@
   ("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)
@@ -650,5 +627,4 @@
   ("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
@@ -974,10 +950,10 @@
   m_BLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
 #endif
-#else //SVC_EXTENSION
+#else
   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 //SVC_EXTENSION 
+#endif  
 
   Char* pColumnWidth = cfg_ColumnWidth.empty() ? NULL: strdup(cfg_ColumnWidth.c_str());
@@ -1038,5 +1014,5 @@
     m_pRowHeight = NULL;
   }
-#if SVC_EXTENSION
+#if SCALED_REF_LAYER_OFFSETS
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -1108,4 +1084,5 @@
     }
   }
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -1237,8 +1214,16 @@
   }
 #endif
-#endif //SVC_EXTENSION
   m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str());
 
   /* 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++){
+    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; }
@@ -1246,4 +1231,5 @@
   if (!m_outputBitDepthY) { m_outputBitDepthY = m_internalBitDepthY; }
   if (!m_outputBitDepthC) { m_outputBitDepthC = m_internalBitDepthC; }
+#endif
 
 #if !SVC_EXTENSION
@@ -1457,12 +1443,5 @@
   
   // set global varibles
-#if LAYER_CTB
-  for(Int layer = 0; layer < MAX_LAYERS; layer++)
-  {
-    xSetGlobal(layer);
-  }
-#else
   xSetGlobal();
-#endif
   
   // print-out parameters
@@ -1503,6 +1482,13 @@
 #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" );
@@ -1524,12 +1510,5 @@
   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" );
@@ -1545,10 +1524,8 @@
   }
 #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");
@@ -1556,5 +1533,4 @@
 #endif
   
-#if !LAYER_CTB
   xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
   xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5,                                        "QuadtreeTULog2MaxSize must be 5 or smaller.");
@@ -1570,5 +1546,4 @@
   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.");
@@ -1618,5 +1593,4 @@
 #endif
 
-#if !LAYER_CTB
   // max CU width and height should be power of 2
   UInt ui = m_uiMaxCUWidth;
@@ -1634,5 +1608,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
@@ -2031,8 +2005,4 @@
     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)
@@ -2279,27 +2249,4 @@
 /** \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;
-  
-  // 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;
-}
-#else
 Void TAppEncCfg::xSetGlobal()
 {
@@ -2316,5 +2263,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;
@@ -2322,6 +2276,6 @@
   g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_inputBitDepthY : m_internalBitDepthY;
   g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_inputBitDepthC : m_internalBitDepthC;
+#endif
 }
-#endif
 
 Void TAppEncCfg::xPrintParameter()
@@ -2377,10 +2331,8 @@
     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 );
@@ -2399,5 +2351,10 @@
   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 Layer0    : (Y:%d, C:%d)\n", m_acLayerCfg[0].m_internalBitDepthY, m_acLayerCfg[0].m_internalBitDepthC );
+  printf("Internal bit depth Layer1    : (Y:%d, C:%d)\n", m_acLayerCfg[1].m_internalBitDepthY, m_acLayerCfg[1].m_internalBitDepthC );
+#else
   printf("Internal bit depth           : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC );
+#endif
   printf("PCM sample bit depth         : (Y:%d, C:%d)\n", g_uiPCMBitDepthLuma, g_uiPCMBitDepthChroma );
 #if O0215_PHASE_ALIGNMENT
@@ -2429,5 +2386,10 @@
   
   printf("TOOL CFG: ");
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  printf("IBD0:%d ", g_bitDepthY > m_acLayerCfg[0].m_inputBitDepthY || g_bitDepthC > m_acLayerCfg[0].m_inputBitDepthC);
+  printf("IBD1:%d ", g_bitDepthY > m_acLayerCfg[1].m_inputBitDepthY || g_bitDepthC > m_acLayerCfg[1].m_inputBitDepthC);
+#else
   printf("IBD:%d ", g_bitDepthY > m_inputBitDepthY || g_bitDepthC > m_inputBitDepthC);
+#endif
   printf("HAD:%d ", m_bUseHADME           );
   printf("SRD:%d ", m_bUseSBACRD          );
@@ -2460,7 +2422,5 @@
   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));
 
@@ -2494,4 +2454,8 @@
   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("O0194_REPN_FORMAT_IN_VPS_BUGFIX: %d ",O0194_REPN_FORMAT_IN_VPS_BUGFIX);
   printf("\n\n");
   
@@ -2508,5 +2472,5 @@
 }
 
-#if SVC_EXTENSION
+#if SCALED_REF_LAYER_OFFSETS
 Void TAppEncCfg::cfgStringToArray(Int **arr, string cfgString, Int numEntries, const char* logString)
 {
@@ -2541,4 +2505,5 @@
   }
 }
+#endif
 
 #if FINAL_RPL_CHANGE_N0082
@@ -2756,4 +2721,3 @@
 }
 #endif
-#endif //SVC_EXTENSION
 //! \}
Index: branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 464)
+++ branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 466)
@@ -150,5 +150,4 @@
   Int       m_maxTempLayer;                                  ///< Max temporal layer
 
-#if !LAYER_CTB
   // coding unit (CU) definition
   UInt      m_uiMaxCUWidth;                                   ///< max. CU width in pixel
@@ -162,7 +161,7 @@
   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)
@@ -171,5 +170,5 @@
   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
   // coding tools (PCM bit-depth)
   Bool      m_bPCMInputBitDepthFlag;                          ///< 0: PCM bit-depth is internal bit-depth. 1: PCM bit-depth is input bit-depth.
@@ -356,9 +355,5 @@
 #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
@@ -397,11 +392,14 @@
   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; }
+#else
   UInt getInternalBitDepthY()      {return m_internalBitDepthY; }
   UInt getInternalBitDepthC()      {return m_internalBitDepthC; }
-#if !LAYER_CTB
+#endif
   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; }
@@ -410,12 +408,10 @@
   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: branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 464)
+++ branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 466)
@@ -38,4 +38,5 @@
   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));
@@ -43,4 +44,5 @@
   ::memset(m_scaledRefLayerRightOffset,  0, sizeof(m_scaledRefLayerRightOffset));
   ::memset(m_scaledRefLayerBottomOffset, 0, sizeof(m_scaledRefLayerBottomOffset));
+#endif
 }
 
@@ -140,10 +142,4 @@
   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 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 );
@@ -161,7 +157,4 @@
 #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
 }
 
@@ -182,9 +175,5 @@
     {
       // 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)
       {
@@ -251,13 +240,7 @@
   }
 
-#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)
@@ -272,8 +255,14 @@
   }
 
+#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 + maxCUHeight - 1) / maxCUHeight : 1;
+#endif
+
+
+  m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + m_cAppEncCfg->getMaxCUHeight() - 1) / m_cAppEncCfg->getMaxCUHeight() : 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" );
@@ -290,45 +279,9 @@
   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 //SVC_EXTENSION
+#endif
 
 
Index: branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 464)
+++ branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 466)
@@ -43,5 +43,4 @@
   Int       m_iIntraPeriod;                                   ///< period of I-slice (random access period)
   Double    m_fQP;                                            ///< QP value of key-picture (floating point)
-#if SVC_EXTENSION
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -56,18 +55,4 @@
   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
 
@@ -85,6 +70,7 @@
   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 //SVC_EXTENSION
+#endif
 
   Int       m_iQP;                                            ///< QP value of key-picture (integer)
@@ -92,5 +78,5 @@
   Int*      m_aidQP;                                          ///< array of slice QP values
   TAppEncCfg* m_cAppEncCfg;                                   ///< pointer to app encoder config
-#if SVC_EXTENSION
+#if SCALED_REF_LAYER_OFFSETS
   Int       m_numScaledRefLayerOffsets  ;
   Int       m_scaledRefLayerLeftOffset  [MAX_LAYERS];
@@ -98,11 +84,19 @@
   Int       m_scaledRefLayerRightOffset [MAX_LAYERS];
   Int       m_scaledRefLayerBottomOffset[MAX_LAYERS];
+#endif  
 #if FINAL_RPL_CHANGE_N0082
   GOPEntry  m_GOPListLayer[MAX_GOP];                            ///< for layer
+#endif
+#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
   Int       m_repFormatIdx;
 #endif
-#endif //SVC_EXTENSION
 public:
   TAppEncLayerCfg();
@@ -139,5 +133,4 @@
   Int     getIntQP()                  {return m_iQP;              } 
   Int*    getdQPs()                   {return m_aidQP;            }
-#if SVC_EXTENSION
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -178,11 +171,5 @@
 #if N0120_MAX_TID_REF_CFG
   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
-#endif //SVC_EXTENSION
+#endif 
 }; // END CLASS DEFINITION TAppEncLayerCfg
 
Index: branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 464)
+++ branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 466)
@@ -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
@@ -117,5 +117,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 +141,16 @@
   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()  );
     repFormat->setChromaFormatVpsIdc        ( 1                                             );  // Need modification to change for each layer - corresponds to 420
     repFormat->setSeparateColourPlaneVpsFlag( 0                                             );  // Need modification to change for each layer
+#if O0194_REPN_FORMAT_IN_VPS_BUGFIX
+    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 +158,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 +204,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);
@@ -220,7 +237,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 +258,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 +274,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 +300,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 +321,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,17 +375,10 @@
     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  );
@@ -390,4 +400,11 @@
     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 );
@@ -400,9 +417,5 @@
     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)
     {
@@ -428,6 +441,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);
@@ -494,5 +507,5 @@
     if(uiTilesCount == 1)
     {
-      m_bLFCrossTileBoundaryFlag = true; 
+      m_bLFCrossTileBoundaryFlag = true;
     }
     m_acTEncTop[layer].setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
@@ -530,5 +543,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 );
@@ -561,4 +574,5 @@
     m_acTEncTop[layer].setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
     m_acTEncTop[layer].setElRapSliceTypeB(layer == 0? 0 : m_elRapSliceBEnabled);
+#if SCALED_REF_LAYER_OFFSETS
     if( layer > 0 )
     {
@@ -567,7 +581,8 @@
       {
         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]);  
-      }
-    }
+                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);
+      }
+    }
+#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
     m_acTEncTop[layer].setAdaptiveResolutionChange( m_adaptiveResolutionChange );
@@ -575,5 +590,5 @@
   }
 }
-#else //SVC_EXTENSION
+#else
 Void TAppEncTop::xInitLibCfg()
 {
@@ -680,5 +695,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  );
@@ -734,6 +749,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);
@@ -792,5 +807,5 @@
   if(uiTilesCount == 1)
   {
-    m_bLFCrossTileBoundaryFlag = true; 
+    m_bLFCrossTileBoundaryFlag = true;
   }
   m_cTEncTop.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
@@ -818,5 +833,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 );
@@ -849,5 +864,5 @@
   m_cTEncTop.setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
 }
-#endif //SVC_EXTENSION
+#endif
 
 Void TAppEncTop::xCreateLib()
@@ -860,21 +875,31 @@
   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
+#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 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 //SVC_EXTENSION
+#else
   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]);
@@ -885,5 +910,5 @@
   // Neo Decoder
   m_cTEncTop.create();
-#endif //SVC_EXTENSION
+#endif
 }
 
@@ -897,11 +922,4 @@
   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();
@@ -909,5 +927,5 @@
     m_acTEncTop[layer].destroy();
   }
-#else //SVC_EXTENSION
+#else
   m_cTVideoIOYuvInputFile.close();
   m_cTVideoIOYuvReconFile.close();
@@ -915,5 +933,5 @@
   // Neo Decoder
   m_cTEncTop.destroy();
-#endif //SVC_EXTENSION
+#endif
 }
 
@@ -923,14 +941,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];
-        
-    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 ) );
+#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
     m_acTEncTop[layer].init(isFieldCoding);
@@ -948,4 +963,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);
     }
@@ -963,5 +986,5 @@
     vps->setScalabilityMask(i, false);
   }
-  if(m_numLayers > 1) 
+  if(m_numLayers > 1)
   {
     Int scalabilityTypes = 0;
@@ -996,7 +1019,7 @@
 #if N0120_MAX_TID_REF_CFG
   vps->setMaxTidRefPresentFlag(m_maxTidRefPresentFlag);
-#else 
+#else
   vps->setMaxTidRefPresentFlag(true);
-#endif 
+#endif
   if (vps->getMaxTidRefPresentFlag())
   {
@@ -1004,8 +1027,8 @@
     {
 #if N0120_MAX_TID_REF_CFG
-      vps->setMaxTidIlRefPicsPlus1(i, m_acTEncTop[i].getMaxTidIlRefPicsPlus1()); 
-#else 
+      vps->setMaxTidIlRefPicsPlus1(i, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
+#else
       vps->setMaxTidIlRefPicsPlus1(i, vps->getMaxTLayers()+1);
-#endif 
+#endif
     }
   }
@@ -1017,5 +1040,5 @@
     }
   }
-#endif 
+#endif
 #if ILP_SSH_SIG
 #if ILP_SSH_SIG_FIX
@@ -1035,16 +1058,21 @@
 #endif
   // Target output layer
-  vps->setNumOutputLayerSets(vps->getNumLayerSets());    
-  vps->setNumProfileTierLevel(vps->getNumLayerSets());   
+#if VPS_PROFILE_OUTPUT_LAYERS
+  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); 
-  }
-
+    vps->setOutputLayerSetIdx(i, i);
+  }
+#else
+  vps->setNumOutputLayerSets(1);
+  Int lsIdx = 1;
+  vps->setOutputLayerSetIdx(0, lsIdx); // Because only one layer set
+#endif
   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++)
     {
@@ -1105,9 +1133,9 @@
 #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 N0147_IRAP_ALIGN_FLAG
+    vps->setCrossLayerIrapAlignFlag(true);
     for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
     {
@@ -1115,5 +1143,5 @@
       {
         if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
-        {          
+        {
           if(m_acTEncTop[layerCtr].getIntraPeriod() !=  m_acTEncTop[refLayerCtr].getIntraPeriod())
           {
@@ -1129,5 +1157,5 @@
       vps->setCrossLayerIrapAlignFlag(false);
     }
-#endif 
+#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   vps->setSingleLayerForNonIrapFlag(m_adaptiveResolutionChange > 0 ? true : false);
@@ -1187,4 +1215,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;
@@ -1192,9 +1228,5 @@
     {
 #if SVC_UPSAMPLING
-#if LAYER_CTB
-      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 );
-#else
       pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
-#endif
 #else
       pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
@@ -1204,9 +1236,5 @@
     {
 #if SVC_UPSAMPLING
-#if LAYER_CTB
-      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 );
-#else
       pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
-#endif
 #else
       pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
@@ -1237,5 +1265,5 @@
   while ( !bEos )
   {
-    // Read enough frames 
+    // Read enough frames
     Bool bFramesReadyToCode = false;
     while(!bFramesReadyToCode)
@@ -1243,11 +1271,12 @@
       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
-
+#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
         // get buffers
         xGetBuffer(pcPicYuvRec, layer);
@@ -1311,5 +1340,5 @@
 #endif
 
-    // loop through frames in one GOP 
+    // loop through frames in one GOP
     for ( UInt iPicIdInGOP=0; iPicIdInGOP < (bFirstFrame? 1:m_iGOPSize); iPicIdInGOP++ )
     {
@@ -1317,14 +1346,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];
-
-        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 ) );
+#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
         // call encoding function for one frame
@@ -1353,4 +1379,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();
@@ -1593,9 +1627,5 @@
 
 #if SVC_UPSAMPLING
-#if LAYER_CTB
-    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 );
-#else
     rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
-#endif
 #else
     rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
@@ -1620,5 +1650,5 @@
       delete pcPicYuvRec; pcPicYuvRec = NULL;
     }
-  }  
+  }
 }
 
@@ -1671,5 +1701,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() );
       }
@@ -1691,5 +1721,5 @@
     for ( i = 0; i < iNumEncoded/2; i++ )
 #endif
-    {      
+    {
       const AccessUnit& auTop = *(iterBitstream++);
       const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
