Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 815)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 906)
@@ -67,9 +67,15 @@
 : m_pBitstreamFile()
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+, m_nonHEVCBaseLayerFlag(0)
+#else
 , m_avcBaseLayerFlag(0)
 #endif
+#endif
 , m_maxTidRefPresentFlag(1)
-, m_pColumnWidth()
-, m_pRowHeight()
+#if OUTPUT_LAYER_SETS_CONFIG
+, m_defaultTargetOutputLayerIdc (-1)
+, m_numOutputLayerSets          (-1)
+#endif
 , m_scalingListFile()
 , m_elRapSliceBEnabled(0)
@@ -87,6 +93,4 @@
 , m_pchReconFile()
 , m_pchdQPFile()
-, m_pColumnWidth()
-, m_pRowHeight()
 , m_scalingListFile()
 {
@@ -95,4 +99,13 @@
   m_codedPivotValue = NULL;
   m_targetPivotValue = NULL;
+#if Q0074_COLOUR_REMAPPING_SEI
+  for( Int c=0 ; c<3 ; c++)
+  {
+    m_colourRemapSEIPreLutCodedValue[c]   = NULL;
+    m_colourRemapSEIPreLutTargetValue[c]  = NULL;
+    m_colourRemapSEIPostLutCodedValue[c]  = NULL;
+    m_colourRemapSEIPostLutTargetValue[c] = NULL;
+  }
+#endif
 }
 #endif
@@ -101,5 +114,9 @@
 {
 #if SVC_EXTENSION
-  free(m_pBitstreamFile);
+  if( m_pBitstreamFile )
+  {
+    free(m_pBitstreamFile);
+    m_pBitstreamFile = NULL;
+  }
 #else  
   if ( m_aidQP )
@@ -128,7 +145,26 @@
   free(m_pchReconFile);
   free(m_pchdQPFile);
-#endif
-  free(m_pColumnWidth);
-  free(m_pRowHeight);
+#if Q0074_COLOUR_REMAPPING_SEI
+  for( Int c=0 ; c<3 ; c++)
+  {
+    if ( m_colourRemapSEIPreLutCodedValue[c] )
+    {
+      delete[] m_colourRemapSEIPreLutCodedValue[c];
+    }
+    if ( m_colourRemapSEIPreLutTargetValue[c] )
+    {
+      delete[] m_colourRemapSEIPreLutTargetValue[c];
+    }
+    if ( m_colourRemapSEIPostLutCodedValue[c] )
+    {
+      delete[] m_colourRemapSEIPostLutCodedValue[c];
+    }
+    if ( m_colourRemapSEIPostLutTargetValue[c] )
+    {
+      delete[] m_colourRemapSEIPostLutTargetValue[c];
+    }
+  }
+#endif
+#endif
   free(m_scalingListFile);
 }
@@ -337,8 +373,4 @@
   string* cfg_ReconFile      [MAX_LAYERS];
   Double* cfg_fQP            [MAX_LAYERS];
-#if Q0074_SEI_COLOR_MAPPING
-  string* cfg_seiColorMappingFile[MAX_LAYERS];
-#endif
-
 #if REPN_FORMAT_IN_VPS
   Int*    cfg_repFormatIdx  [MAX_LAYERS];
@@ -386,6 +418,22 @@
   string    cfg_scaledRefLayerBottomOffset [MAX_LAYERS];
   Int*      cfg_numScaledRefLayerOffsets[MAX_LAYERS];
+#if REF_REGION_OFFSET
+  string    cfg_scaledRefLayerOffsetPresentFlag [MAX_LAYERS];
+  string    cfg_refRegionOffsetPresentFlag      [MAX_LAYERS];
+  string    cfg_refRegionLeftOffset   [MAX_LAYERS];
+  string    cfg_refRegionTopOffset    [MAX_LAYERS];
+  string    cfg_refRegionRightOffset  [MAX_LAYERS];
+  string    cfg_refRegionBottomOffset [MAX_LAYERS];
+#endif
+#if R0209_GENERIC_PHASE
+  string    cfg_resamplePhaseSetPresentFlag [MAX_LAYERS];
+  string    cfg_phaseHorLuma   [MAX_LAYERS];
+  string    cfg_phaseVerLuma   [MAX_LAYERS];
+  string    cfg_phaseHorChroma [MAX_LAYERS];
+  string    cfg_phaseVerChroma [MAX_LAYERS];
+#else
 #if P0312_VERT_PHASE_ADJ
   string    cfg_vertPhasePositionEnableFlag[MAX_LAYERS];
+#endif
 #endif
 
@@ -397,4 +445,19 @@
   string*    cfg_scaledRefLayerRightOffsetPtr  [MAX_LAYERS];
   string*    cfg_scaledRefLayerBottomOffsetPtr [MAX_LAYERS];
+#if REF_REGION_OFFSET
+  string*    cfg_scaledRefLayerOffsetPresentFlagPtr [MAX_LAYERS];
+  string*    cfg_refRegionOffsetPresentFlagPtr      [MAX_LAYERS];
+  string*    cfg_refRegionLeftOffsetPtr   [MAX_LAYERS];
+  string*    cfg_refRegionTopOffsetPtr    [MAX_LAYERS];
+  string*    cfg_refRegionRightOffsetPtr  [MAX_LAYERS];
+  string*    cfg_refRegionBottomOffsetPtr [MAX_LAYERS];
+#endif
+#if R0209_GENERIC_PHASE
+  string*    cfg_resamplePhaseSetPresentFlagPtr [MAX_LAYERS];
+  string*    cfg_phaseHorLumaPtr   [MAX_LAYERS];
+  string*    cfg_phaseVerLumaPtr   [MAX_LAYERS];
+  string*    cfg_phaseHorChromaPtr [MAX_LAYERS];
+  string*    cfg_phaseVerChromaPtr [MAX_LAYERS];
+#endif
 #if P0312_VERT_PHASE_ADJ
   string*    cfg_vertPhasePositionEnableFlagPtr[MAX_LAYERS];
@@ -419,4 +482,9 @@
 #endif
   Int*    cfg_maxTidIlRefPicsPlus1[MAX_LAYERS]; 
+#if Q0074_COLOUR_REMAPPING_SEI
+  string* cfg_colourRemapSEIFile[MAX_LAYERS];
+#endif
+  Int*    cfg_waveFrontSynchro[MAX_LAYERS];
+
   for(UInt layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -424,4 +492,7 @@
     cfg_ReconFile[layer]    = &m_acLayerCfg[layer].m_cReconFile;
     cfg_fQP[layer]          = &m_acLayerCfg[layer].m_fQP;
+#if Q0074_COLOUR_REMAPPING_SEI
+    cfg_colourRemapSEIFile[layer] = &m_acLayerCfg[layer].m_colourRemapSEIFile;
+#endif
 #if REPN_FORMAT_IN_VPS
     cfg_repFormatIdx[layer] = &m_acLayerCfg[layer].m_repFormatIdx;
@@ -432,7 +503,4 @@
     cfg_IntraPeriod[layer]  = &m_acLayerCfg[layer].m_iIntraPeriod; 
     cfg_conformanceMode[layer] = &m_acLayerCfg[layer].m_conformanceMode;
-#if Q0074_SEI_COLOR_MAPPING
-    cfg_seiColorMappingFile[layer] = &m_acLayerCfg[layer].m_cSeiColorMappingFile;
-#endif
 #if LAYER_CTB
     // coding unit (CU) definition
@@ -457,4 +525,5 @@
 #endif
     cfg_numScaledRefLayerOffsets [layer] = &m_acLayerCfg[layer].m_numScaledRefLayerOffsets;
+    cfg_waveFrontSynchro[layer]  = &m_acLayerCfg[layer].m_waveFrontSynchro;
     for(Int i = 0; i < MAX_LAYERS; i++)
     {
@@ -468,4 +537,19 @@
 #if P0312_VERT_PHASE_ADJ
       cfg_vertPhasePositionEnableFlagPtr[layer] = &cfg_vertPhasePositionEnableFlag[layer];
+#endif
+#if REF_REGION_OFFSET
+      cfg_scaledRefLayerOffsetPresentFlagPtr [layer] = &cfg_scaledRefLayerOffsetPresentFlag [layer];
+      cfg_refRegionOffsetPresentFlagPtr      [layer] = &cfg_refRegionOffsetPresentFlag      [layer];
+      cfg_refRegionLeftOffsetPtr  [layer] = &cfg_refRegionLeftOffset  [layer];
+      cfg_refRegionTopOffsetPtr   [layer] = &cfg_refRegionTopOffset   [layer];
+      cfg_refRegionRightOffsetPtr [layer] = &cfg_refRegionRightOffset [layer];
+      cfg_refRegionBottomOffsetPtr[layer] = &cfg_refRegionBottomOffset[layer];
+#endif
+#if R0209_GENERIC_PHASE
+      cfg_resamplePhaseSetPresentFlagPtr [layer] = &cfg_resamplePhaseSetPresentFlag [layer];
+      cfg_phaseHorLumaPtr   [layer] = &cfg_phaseHorLuma   [layer];
+      cfg_phaseVerLumaPtr   [layer] = &cfg_phaseVerLuma   [layer];
+      cfg_phaseHorChromaPtr [layer] = &cfg_phaseHorChroma [layer];
+      cfg_phaseVerChromaPtr [layer] = &cfg_phaseVerChroma [layer];
 #endif
     }
@@ -507,9 +591,11 @@
   }
 #endif
+#if OUTPUT_LAYER_SETS_CONFIG
+  string* cfg_numLayersInOutputLayerSet = new string;
+  string* cfg_listOfOutputLayers     = new string[MAX_VPS_OUTPUT_LAYER_SETS_PLUS1];
+  string* cfg_outputLayerSetIdx      = new string;
+#endif
 #if AVC_BASE
   string  cfg_BLInputFile;
-#endif
-#if AVC_SYNTAX
-  string  cfg_BLSyntaxFile;
 #endif
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
@@ -521,7 +607,10 @@
   string cfg_ReconFile;
   string cfg_dQPFile;
+#if Q0074_COLOUR_REMAPPING_SEI
+  string cfg_colourRemapSEIFile;
+#endif
 #endif //SVC_EXTENSION
-  string cfg_ColumnWidth;
-  string cfg_RowHeight;
+  string cfgColumnWidth;
+  string cfgRowHeight;
   string cfg_ScalingListFile;
   string cfg_startOfCodedInterval;
@@ -532,4 +621,5 @@
   string cfg_kneeSEIOutputKneePointValue;
 #endif
+
   po::Options opts;
   opts.addOptions()
@@ -562,5 +652,9 @@
   ("NumLayers",               m_numLayers, 1, "Number of layers to code")
 #if Q0078_ADD_LAYER_SETS
+#if OUTPUT_LAYER_SETS_CONFIG
+  ("NumLayerSets",            m_numLayerSets, 1, "Number of layer sets")
+#else
   ("NumLayerSets",            m_numLayerSets, 0, "Number of layer sets")
+#endif
   ("NumLayerInIdList%d",      cfg_numLayerInIdList, 0, MAX_VPS_LAYER_ID_PLUS1, "Number of layers in the set")
   ("LayerSetLayerIdList%d",   cfg_layerSetLayerIdListPtr, string(""), MAX_VPS_LAYER_ID_PLUS1, "Layer IDs for the set")
@@ -568,4 +662,11 @@
   ("NumHighestLayerIdx%d",    cfg_numHighestLayerIdx, 0, MAX_VPS_LAYER_ID_PLUS1, "Number of highest layer idx")
   ("HighestLayerIdx%d",       cfg_highestLayerIdxPtr, string(""), MAX_VPS_LAYER_ID_PLUS1, "Highest layer idx for an additional layer set")
+#endif
+#if OUTPUT_LAYER_SETS_CONFIG
+  ("DefaultTargetOutputLayerIdc",    m_defaultTargetOutputLayerIdc, 1, "Default target output layers. 0: All layers are output layer, 1: Only highest layer is output layer, 2 or 3: No default output layers")
+  ("NumOutputLayerSets",            m_numOutputLayerSets, 1, "Number of output layer sets excluding the 0-th output layer set")
+  ("NumLayersInOutputLayerSet",   cfg_numLayersInOutputLayerSet, string(""), 1 , "List containing number of output layers in the output layer sets")
+  ("ListOfOutputLayers%d",          cfg_listOfOutputLayers, string(""), MAX_VPS_LAYER_ID_PLUS1, "Layer IDs for the set, in terms of layer ID in the output layer set Range: [0..NumLayersInOutputLayerSet-1]")
+  ("OutputLayerSetIdx",            cfg_outputLayerSetIdx, string(""), 1, "Corresponding layer set index, only for non-default output layer sets")
 #endif
 #if AUXILIARY_PICTURES
@@ -602,6 +703,28 @@
   ("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 REF_REGION_OFFSET
+  ("ScaledRefLayerOffsetPresentFlag%d",      cfg_scaledRefLayerOffsetPresentFlagPtr,     string(""), MAX_LAYERS, "presense flag of scaled reference layer offsets")
+  ("RefRegionOffsetPresentFlag%d",           cfg_refRegionOffsetPresentFlagPtr,          string(""), MAX_LAYERS, "presense flag of reference region offsets")
+  ("RefRegionLeftOffset%d",   cfg_refRegionLeftOffsetPtr,  string(""), MAX_LAYERS, "Horizontal offset of top-left luma sample of ref region with respect to"
+                                                                 " top-left luma sample of the BL picture, in units of two luma samples")
+  ("RefRegionTopOffset%d",    cfg_refRegionTopOffsetPtr,   string(""), MAX_LAYERS,   "Vertical offset of top-left luma sample of ref region with respect to"
+                                                                 " top-left luma sample of the BL picture, in units of two luma samples")
+  ("RefRegionRightOffset%d",  cfg_refRegionRightOffsetPtr, string(""), MAX_LAYERS, "Horizontal offset of bottom-right luma sample of ref region with respect to"
+                                                                 " bottom-right luma sample of the BL picture, in units of two luma samples")
+  ("RefRegionBottomOffset%d", cfg_refRegionBottomOffsetPtr,string(""), MAX_LAYERS, "Vertical offset of bottom-right luma sample of ref region with respect to"
+                                                                 " bottom-right luma sample of the BL picture, in units of two luma samples")
+#endif
+#if R0209_GENERIC_PHASE
+  ("ResamplePhaseSetPresentFlag%d",  cfg_resamplePhaseSetPresentFlagPtr, string(""), MAX_LAYERS, "presense flag of resample phase set")
+  ("PhaseHorLuma%d",   cfg_phaseHorLumaPtr,   string(""), MAX_LAYERS, "luma shift in the horizontal direction used in resampling proces")
+  ("PhaseVerLuma%d",   cfg_phaseVerLumaPtr,   string(""), MAX_LAYERS, "luma shift in the vertical   direction used in resampling proces")
+  ("PhaseHorChroma%d", cfg_phaseHorChromaPtr, string(""), MAX_LAYERS, "chroma shift in the horizontal direction used in resampling proces")
+  ("PhaseVerChroma%d", cfg_phaseVerChromaPtr, string(""), MAX_LAYERS, "chroma shift in the vertical   direction used in resampling proces")
+#endif
 #if P0312_VERT_PHASE_ADJ
   ("VertPhasePositionEnableFlag%d", cfg_vertPhasePositionEnableFlagPtr,string(""), MAX_LAYERS, "VertPhasePositionEnableFlag for layer %d")
+#endif
+#if Q0074_COLOUR_REMAPPING_SEI
+  ("SEIColourRemappingInfoFile%d", cfg_colourRemapSEIFile, string(""), MAX_LAYERS, "Colour Remapping Information SEI parameters file name for layer %d")
 #endif
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
@@ -627,14 +750,12 @@
 #endif
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+  ("NonHEVCBase,-nonhevc",            m_nonHEVCBaseLayerFlag,     0, "BL is available but not internal")
+#else
   ("AvcBase,-avc",            m_avcBaseLayerFlag,     0, "avc_base_layer_flag")
+#endif
   ("InputBLFile,-ibl",        cfg_BLInputFile,     string(""), "Base layer rec YUV input file name")
-#if AVC_SYNTAX
-  ("InputBLSyntaxFile,-ibs",  cfg_BLSyntaxFile,     string(""), "Base layer syntax input file name")
-#endif
 #endif
   ("EnableElRapB,-use-rap-b",  m_elRapSliceBEnabled, 0, "Set ILP over base-layer I picture to B picture (default is P picture)")
-#if Q0074_SEI_COLOR_MAPPING
-  ("SEIColorMappingFile%d", cfg_seiColorMappingFile, string(""), MAX_LAYERS, "File Containing SEI Color Mapping data")
-#endif
 #else //SVC_EXTENSION
   ("InputFile,i",           cfg_InputFile,     string(""), "Original YUV input file name")
@@ -654,12 +775,20 @@
   ("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")
-  ("VerticalPadding,-pdy",  m_aiPad[1],            0, "Vertical source padding for conformance window mode 2")
-  ("ConfLeft",              m_confLeft,            0, "Left offset for window conformance mode 3")
-  ("ConfRight",             m_confRight,           0, "Right offset for window conformance mode 3")
-  ("ConfTop",               m_confTop,             0, "Top offset for window conformance mode 3")
-  ("ConfBottom",            m_confBottom,          0, "Bottom offset for window conformance mode 3")
+  ("ConformanceMode",       m_conformanceWindowMode,  0, "Deprecated alias of ConformanceWindowMode")
+  ("ConformanceWindowMode", m_conformanceWindowMode,  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")
+  ("VerticalPadding,-pdy",  m_aiPad[1],               0, "Vertical source padding for conformance window mode 2")
+  ("ConfLeft",              m_confWinLeft,            0, "Deprecated alias of ConfWinLeft")
+  ("ConfRight",             m_confWinRight,           0, "Deprecated alias of ConfWinRight")
+  ("ConfTop",               m_confWinTop,             0, "Deprecated alias of ConfWinTop")
+  ("ConfBottom",            m_confWinBottom,          0, "Deprecated alias of ConfWinBottom")
+  ("ConfWinLeft",           m_confWinLeft,            0, "Left offset for window conformance mode 3")
+  ("ConfWinRight",          m_confWinRight,           0, "Right offset for window conformance mode 3")
+  ("ConfWinTop",            m_confWinTop,             0, "Top offset for window conformance mode 3")
+  ("ConfWinBottom",         m_confWinBottom,          0, "Bottom offset for window conformance mode 3")
   ("FrameRate,-fr",         m_iFrameRate,          0, "Frame rate")
+#if Q0074_COLOUR_REMAPPING_SEI
+  ("SEIColourRemappingInfoFile", cfg_colourRemapSEIFile, string(""), "Colour Remapping Information SEI parameters file name")
+#endif
 #endif //SVC_EXTENSION
   ("FrameSkip,-fs",         m_FrameSkip,          0u, "Number of frames to skip at start of input YUV")
@@ -821,11 +950,21 @@
   ("WeightedPredB,-wpB",          m_useWeightedBiPred,             false,      "Use weighted (bidirectional) prediction in B slices")
   ("Log2ParallelMergeLevel",      m_log2ParallelMergeLevel,     2u,          "Parallel merge estimation region")
-  ("UniformSpacingIdc",           m_iUniformSpacingIdr,            0,          "Indicates if the column and row boundaries are distributed uniformly")
-  ("NumTileColumnsMinus1",        m_iNumColumnsMinus1,             0,          "Number of columns in a picture minus 1")
-  ("ColumnWidthArray",            cfg_ColumnWidth,                 string(""), "Array containing ColumnWidth values in units of LCU")
-  ("NumTileRowsMinus1",           m_iNumRowsMinus1,                0,          "Number of rows in a picture minus 1")
-  ("RowHeightArray",              cfg_RowHeight,                   string(""), "Array containing RowHeight values in units of LCU")
+
+  //deprecated copies of renamed tile parameters
+  ("UniformSpacingIdc",           m_tileUniformSpacingFlag,        false,      "deprecated alias of TileUniformSpacing")
+  ("ColumnWidthArray",            cfgColumnWidth,                  string(""), "deprecated alias of TileColumnWidthArray")
+  ("RowHeightArray",              cfgRowHeight,                    string(""), "deprecated alias of TileRowHeightArray")
+
+  ("TileUniformSpacing",          m_tileUniformSpacingFlag,        false,      "Indicates that tile columns and rows are distributed uniformly")
+  ("NumTileColumnsMinus1",        m_numTileColumnsMinus1,          0,          "Number of tile columns in a picture minus 1")
+  ("NumTileRowsMinus1",           m_numTileRowsMinus1,             0,          "Number of rows in a picture minus 1")
+  ("TileColumnWidthArray",        cfgColumnWidth,                  string(""), "Array containing tile column width values in units of LCU")
+  ("TileRowHeightArray",          cfgRowHeight,                    string(""), "Array containing tile row height values in units of LCU")
   ("LFCrossTileBoundaryFlag",      m_bLFCrossTileBoundaryFlag,             true,          "1: cross-tile-boundary loop filtering. 0:non-cross-tile-boundary loop filtering")
+#if SVC_EXTENSION
+  ("WaveFrontSynchro%d",          cfg_waveFrontSynchro,             0,  MAX_LAYERS,          "0: no synchro; 1 synchro with TR; 2 TRR etc")
+#else
   ("WaveFrontSynchro",            m_iWaveFrontSynchro,             0,          "0: no synchro; 1 synchro with TR; 2 TRR etc")
+#endif
   ("ScalingList",                 m_useScalingListId,              0,          "0: no scaling list, 1: default scaling lists, 2: scaling lists specified in ScalingListFile")
   ("ScalingListFile",             cfg_ScalingListFile,             string(""), "Scaling list file name")
@@ -884,5 +1023,5 @@
   ("ColourDescriptionPresent",       m_colourDescriptionPresentFlag,       false, "Signals whether colour_primaries, transfer_characteristics and matrix_coefficients are present")
   ("ColourPrimaries",                m_colourPrimaries,                        2, "Indicates chromaticity coordinates of the source primaries")
-  ("TransferCharateristics",         m_transferCharacteristics,                2, "Indicates the opto-electronic transfer characteristics of the source")
+  ("TransferCharacteristics",        m_transferCharacteristics,                2, "Indicates the opto-electronic transfer characteristics of the source")
   ("MatrixCoefficients",             m_matrixCoefficients,                     2, "Describes the matrix coefficients used in deriving luma and chroma from RGB primaries")
   ("ChromaLocInfoPresent",           m_chromaLocInfoPresentFlag,           false, "Signals whether chroma_sample_loc_type_top_field and chroma_sample_loc_type_bottom_field are present")
@@ -1004,4 +1143,10 @@
   ("CGSMaxYPartNumLog",  m_nCGSMaxYPartNumLog2 , 2, "max Y part number ")
   ("CGSLUTBit",     m_nCGSLUTBit , 12, "bit depth of CGS LUT")
+#if R0151_CGS_3D_ASYMLUT_IMPROVE
+  ("CGSAdaptC",     m_nCGSAdaptiveChroma , 1, "adaptive chroma partition (only for the case of two chroma partitions)")
+#endif
+#if R0179_ENC_OPT_3DLUT_SIZE
+  ("CGSSizeRDO",     m_nCGSLutSizeRDO , 0, "RDOpt selection of best table size (effective when large maximum table size such as 8x8x8 is used)")
+#endif
 #endif
 #if Q0108_TSA_STSA
@@ -1089,5 +1234,9 @@
 #if SVC_EXTENSION
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+  if( m_nonHEVCBaseLayerFlag )
+#else
   if( m_avcBaseLayerFlag )
+#endif
   {
     *cfg_InputFile[0] = cfg_BLInputFile;
@@ -1095,7 +1244,4 @@
 #endif
   m_pBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
-#if AVC_SYNTAX
-  m_BLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
-#endif
 #else //SVC_EXTENSION
   m_pchInputFile = cfg_InputFile.empty() ? NULL : strdup(cfg_InputFile.c_str());
@@ -1103,26 +1249,31 @@
   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 
-
-  Char* pColumnWidth = cfg_ColumnWidth.empty() ? NULL: strdup(cfg_ColumnWidth.c_str());
-  Char* pRowHeight = cfg_RowHeight.empty() ? NULL : strdup(cfg_RowHeight.c_str());
-  if( m_iUniformSpacingIdr == 0 && m_iNumColumnsMinus1 > 0 )
-  {
-    char *columnWidth;
+#if Q0074_COLOUR_REMAPPING_SEI
+  m_colourRemapSEIFile = cfg_colourRemapSEIFile.empty() ? NULL : strdup(cfg_colourRemapSEIFile.c_str());
+#endif
+#endif //SVC_EXTENSION
+
+
+  Char* pColumnWidth = cfgColumnWidth.empty() ? NULL: strdup(cfgColumnWidth.c_str());
+  Char* pRowHeight = cfgRowHeight.empty() ? NULL : strdup(cfgRowHeight.c_str());
+
+  if( !m_tileUniformSpacingFlag && m_numTileColumnsMinus1 > 0 )
+  {
+    char *str;
     int  i=0;
-    m_pColumnWidth = new UInt[m_iNumColumnsMinus1];
-    columnWidth = strtok(pColumnWidth, " ,-");
-    while(columnWidth!=NULL)
-    {
-      if( i>=m_iNumColumnsMinus1 )
+    m_tileColumnWidth.resize( m_numTileColumnsMinus1 );
+    str = strtok(pColumnWidth, " ,-");
+    while(str!=NULL)
+    {
+      if( i >= m_numTileColumnsMinus1 )
       {
         printf( "The number of columns whose width are defined is larger than the allowed number of columns.\n" );
         exit( EXIT_FAILURE );
       }
-      *( m_pColumnWidth + i ) = atoi( columnWidth );
-      columnWidth = strtok(NULL, " ,-");
+      m_tileColumnWidth[i] = atoi( str );
+      str = strtok(NULL, " ,-");
       i++;
     }
-    if( i<m_iNumColumnsMinus1 )
+    if( i < m_numTileColumnsMinus1 )
     {
       printf( "The width of some columns is not defined.\n" );
@@ -1132,25 +1283,25 @@
   else
   {
-    m_pColumnWidth = NULL;
-  }
-
-  if( m_iUniformSpacingIdr == 0 && m_iNumRowsMinus1 > 0 )
-  {
-    char *rowHeight;
+    m_tileColumnWidth.clear();
+  }
+
+  if( !m_tileUniformSpacingFlag && m_numTileRowsMinus1 > 0 )
+  {
+    char *str;
     int  i=0;
-    m_pRowHeight = new UInt[m_iNumRowsMinus1];
-    rowHeight = strtok(pRowHeight, " ,-");
-    while(rowHeight!=NULL)
-    {
-      if( i>=m_iNumRowsMinus1 )
+    m_tileRowHeight.resize(m_numTileRowsMinus1);
+    str = strtok(pRowHeight, " ,-");
+    while(str!=NULL)
+    {
+      if( i>=m_numTileRowsMinus1 )
       {
         printf( "The number of rows whose height are defined is larger than the allowed number of rows.\n" );
         exit( EXIT_FAILURE );
       }
-      *( m_pRowHeight + i ) = atoi( rowHeight );
-      rowHeight = strtok(NULL, " ,-");
+      m_tileRowHeight[i] = atoi( str );
+      str = strtok(NULL, " ,-");
       i++;
     }
-    if( i<m_iNumRowsMinus1 )
+    if( i < m_numTileRowsMinus1 )
     {
       printf( "The height of some rows is not defined.\n" );
@@ -1160,7 +1311,19 @@
   else
   {
-    m_pRowHeight = NULL;
+    m_tileRowHeight.clear();
   }
 #if SVC_EXTENSION
+  if( pColumnWidth )
+  {
+    free( pColumnWidth );
+    pColumnWidth = NULL;
+  }
+
+  if( pRowHeight )
+  {
+    free( pRowHeight );
+    pRowHeight = NULL;
+  }
+
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -1171,4 +1334,26 @@
       assert( strcmp(cfg_scaledRefLayerId[layer].c_str(),  ""));
 #endif
+#if REF_REGION_OFFSET
+      Bool srloFlag =
+        strcmp(cfg_scaledRefLayerLeftOffset   [layer].c_str(), "") ||
+        strcmp(cfg_scaledRefLayerRightOffset  [layer].c_str(), "") ||
+        strcmp(cfg_scaledRefLayerTopOffset    [layer].c_str(), "") ||
+        strcmp(cfg_scaledRefLayerBottomOffset [layer].c_str(), "");
+      Bool rroFlag =
+        strcmp(cfg_refRegionLeftOffset   [layer].c_str(), "") ||
+        strcmp(cfg_refRegionRightOffset  [layer].c_str(), "") ||
+        strcmp(cfg_refRegionTopOffset    [layer].c_str(), "") ||
+        strcmp(cfg_refRegionBottomOffset [layer].c_str(), "");
+#if R0209_GENERIC_PHASE
+      Bool phaseSetFlag =
+        strcmp(cfg_phaseHorLuma   [layer].c_str(), "") ||
+        strcmp(cfg_phaseVerLuma  [layer].c_str(), "") ||
+        strcmp(cfg_phaseHorChroma    [layer].c_str(), "") ||
+        strcmp(cfg_phaseVerChroma [layer].c_str(), "");
+      assert( srloFlag || rroFlag || phaseSetFlag);
+#else
+      assert( srloFlag || rroFlag );
+#endif
+#else
 #if P0312_VERT_PHASE_ADJ
       assert( strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  "") ||
@@ -1183,4 +1368,5 @@
               strcmp(cfg_scaledRefLayerBottomOffset[layer].c_str(),"") ); 
 #endif
+#endif
     }
 
@@ -1203,4 +1389,20 @@
 #endif
 
+#if REF_REGION_OFFSET
+    // Presense Flag //
+    if(strcmp(cfg_scaledRefLayerOffsetPresentFlag[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_scaledRefLayerOffsetPresentFlag[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "ScaledRefLayerOffsetPresentFlag");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_scaledRefLayerOffsetPresentFlag[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+#endif
+
     // Left offset //
     if(strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  ""))
@@ -1273,5 +1475,150 @@
     }
 #endif
-  }
+#if REF_REGION_OFFSET
+    // Presense Flag //
+    if(strcmp(cfg_refRegionOffsetPresentFlag[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_refRegionOffsetPresentFlag[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RefRegionOffsetPresentFlag");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_refRegionOffsetPresentFlag[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Left offset //
+    if(strcmp(cfg_refRegionLeftOffset[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_refRegionLeftOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RefRegionLeftOffset");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_refRegionLeftOffset[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Top offset //
+    if(strcmp(cfg_refRegionTopOffset[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_refRegionTopOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RefRegionTopOffset");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_refRegionTopOffset[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Right offset //
+    if(strcmp(cfg_refRegionRightOffset[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_refRegionRightOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RefRegionRightOffset");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_refRegionRightOffset[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Bottom offset //
+    if(strcmp(cfg_refRegionBottomOffset[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_refRegionBottomOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RefRegionBottomOffset");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_refRegionBottomOffset[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+#endif
+#if R0209_GENERIC_PHASE
+    Int numPhaseSet = m_acLayerCfg[layer].m_numScaledRefLayerOffsets;
+
+    // Presense Flag //
+    if(strcmp(cfg_resamplePhaseSetPresentFlag[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_resamplePhaseSetPresentFlag[layer], numPhaseSet, "resamplePhaseSetPresentFlag");
+      if(tempArray)
+      {
+        for(Int i = 0; i < numPhaseSet; i++)
+        {
+          m_acLayerCfg[layer].m_resamplePhaseSetPresentFlag[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Luma horizontal phase //
+    if(strcmp(cfg_phaseHorLuma[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_phaseHorLuma[layer], numPhaseSet, "phaseHorLuma");
+      if(tempArray)
+      {
+        for(Int i = 0; i < numPhaseSet; i++)
+        {
+          m_acLayerCfg[layer].m_phaseHorLuma[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Luma vertical phase //
+    if(strcmp(cfg_phaseVerLuma[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_phaseVerLuma[layer], numPhaseSet, "phaseVerLuma");
+      if(tempArray)
+      {
+        for(Int i = 0; i < numPhaseSet; i++)
+        {
+          m_acLayerCfg[layer].m_phaseVerLuma[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Chroma horizontal phase //
+    if(strcmp(cfg_phaseHorChroma[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_phaseHorChroma[layer], numPhaseSet, "phaseHorChroma");
+      if(tempArray)
+      {
+        for(Int i = 0; i < numPhaseSet; i++)
+        {
+          m_acLayerCfg[layer].m_phaseHorChroma[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Chroma vertical phase //
+    if(strcmp(cfg_phaseVerChroma[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_phaseVerChroma[layer], numPhaseSet, "phaseVerChroma");
+      if(tempArray)
+      {
+        for(Int i = 0; i < numPhaseSet; i++)
+        {
+          m_acLayerCfg[layer].m_phaseVerChroma[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+#endif
+  }
+
 #if VPS_EXTN_DIRECT_REF_LAYERS
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
@@ -1305,4 +1652,10 @@
       m_acLayerCfg[layer].m_samplePredRefLayerIds = NULL;
     }
+
+    if( pSamplePredRefLayerIds )
+    {
+      free( pSamplePredRefLayerIds );
+      pSamplePredRefLayerIds = NULL;
+    }
   }
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
@@ -1336,4 +1689,10 @@
       m_acLayerCfg[layer].m_motionPredRefLayerIds = NULL;
     }
+
+    if( pMotionPredRefLayerIds )
+    {
+      free( pMotionPredRefLayerIds );
+      pMotionPredRefLayerIds = NULL;
+    }
   }
 
@@ -1375,7 +1734,19 @@
       m_acLayerCfg[layer].m_predLayerIds = NULL;
     }
+
+    if( pPredLayerIds )
+    {
+      free( pPredLayerIds );
+      pPredLayerIds = NULL;
+    }
   }
 #endif
 #if Q0078_ADD_LAYER_SETS
+#if OUTPUT_LAYER_SETS_CONFIG
+  for (Int layerSet = 1; layerSet < m_numLayerSets; layerSet++)
+  {
+    // Simplifying the code in the #else section, and allowing 0-th layer set t
+    assert( scanStringToArray( cfg_layerSetLayerIdList[layerSet], m_numLayerInIdList[layerSet], "NumLayerInIdList", m_layerSetLayerIdList[layerSet] ) );
+#else
   for (Int layerSet = 0; layerSet < m_numLayerSets; layerSet++)
   {
@@ -1396,8 +1767,19 @@
         i++;
       }
-    }
+
+      if( layerSetLayerIdListDup )
+      {
+        free( layerSetLayerIdListDup );
+        layerSetLayerIdListDup = NULL;
+      }
+    }
+#endif
   }
   for (Int addLayerSet = 0; addLayerSet < m_numAddLayerSets; addLayerSet++)
   {
+#if OUTPUT_LAYER_SETS_CONFIG
+    // Simplifying the code in the #else section
+    assert( scanStringToArray( cfg_layerSetLayerIdList[addLayerSet], m_numLayerInIdList[addLayerSet], "NumLayerInIdList",  m_highestLayerIdx[addLayerSet] ) );
+#else
     if (m_numHighestLayerIdx[addLayerSet] > 0)
     {
@@ -1416,6 +1798,61 @@
         i++;
       }
-    }
-  }
+
+      if( highestLayrIdxListDup )
+      {
+        free( highestLayrIdxListDup );
+        highestLayrIdxListDup = NULL;
+      }
+    }
+#endif
+  }
+#endif
+#if OUTPUT_LAYER_SETS_CONFIG
+  if( m_defaultTargetOutputLayerIdc != -1 )
+  {
+    assert( m_defaultTargetOutputLayerIdc >= 0 && m_defaultTargetOutputLayerIdc <= 3 );
+  }
+  assert( m_numOutputLayerSets != 0 );
+  assert( m_numOutputLayerSets >= m_numLayerSets + m_numAddLayerSets ); // Number of output layer sets must be at least as many as layer sets.
+
+  // If output layer Set Idx is specified, only specify it for the non-default output layer sets
+  Int numNonDefaultOls = m_numOutputLayerSets - (m_numLayerSets + m_numAddLayerSets);
+  if( numNonDefaultOls )
+  {
+    assert( scanStringToArray( *cfg_outputLayerSetIdx, numNonDefaultOls, "OutputLayerSetIdx", m_outputLayerSetIdx ) ); 
+    for(Int i = 0; i < numNonDefaultOls; i++)
+    {
+      assert( m_outputLayerSetIdx[i] >= 0 && m_outputLayerSetIdx[i] < (m_numLayerSets + m_numAddLayerSets) );
+    }
+  }
+
+  // Number of output layers in output layer sets
+  scanStringToArray( *cfg_numLayersInOutputLayerSet, m_numOutputLayerSets - 1, "NumLayersInOutputLayerSets", m_numLayersInOutputLayerSet );
+  m_numLayersInOutputLayerSet.insert(m_numLayersInOutputLayerSet.begin(), 1);
+  // Layers in the output layer set
+  m_listOfOutputLayers.resize(m_numOutputLayerSets);
+  Int startOlsCtr = 1;
+  if( m_defaultTargetOutputLayerIdc == 0 || m_defaultTargetOutputLayerIdc == 1 )
+  {
+    // Default output layer sets defined
+    startOlsCtr = m_numLayerSets + m_numAddLayerSets;
+  }
+  for( Int olsCtr = 1; olsCtr < m_numOutputLayerSets; olsCtr++ )
+  {
+    if( olsCtr < startOlsCtr )
+    {
+      if(scanStringToArray( cfg_listOfOutputLayers[olsCtr], m_numLayersInOutputLayerSet[olsCtr], "ListOfOutputLayers", m_listOfOutputLayers[olsCtr] ) )
+      {
+        std::cout << "Default OLS defined. Ignoring ListOfOutputLayers" << olsCtr << endl;
+      }
+    }
+    else
+    {
+      assert( scanStringToArray( cfg_listOfOutputLayers[olsCtr], m_numLayersInOutputLayerSet[olsCtr], "ListOfOutputLayers", m_listOfOutputLayers[olsCtr] ) );
+    }
+  }
+  delete cfg_numLayersInOutputLayerSet;
+  delete [] cfg_listOfOutputLayers;
+  delete cfg_outputLayerSetIdx;
 #endif
 #endif //SVC_EXTENSION
@@ -1442,10 +1879,10 @@
 #if !SVC_EXTENSION
   // TODO:ChromaFmt assumes 4:2:0 below
-  switch (m_conformanceMode)
+  switch (m_conformanceWindowMode)
   {
   case 0:
     {
       // no conformance or padding
-      m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
+      m_confWinLeft = m_confWinRight = m_confWinTop = m_confWinBottom = 0;
       m_aiPad[1] = m_aiPad[0] = 0;
       break;
@@ -1457,15 +1894,15 @@
       if (m_iSourceWidth % minCuSize)
       {
-        m_aiPad[0] = m_confRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
-        m_iSourceWidth  += m_confRight;
+        m_aiPad[0] = m_confWinRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
+        m_iSourceWidth  += m_confWinRight;
       }
       if (m_iSourceHeight % minCuSize)
       {
-        m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
-        m_iSourceHeight += m_confBottom;
+        m_aiPad[1] = m_confWinBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
+        m_iSourceHeight += m_confWinBottom;
         if ( m_isField )
         {
-          m_iSourceHeightOrg += m_confBottom << 1;
-          m_aiPad[1] = m_confBottom << 1;
+          m_iSourceHeightOrg += m_confWinBottom << 1;
+          m_aiPad[1] = m_confWinBottom << 1;
         }
       }
@@ -1487,6 +1924,6 @@
       m_iSourceWidth  += m_aiPad[0];
       m_iSourceHeight += m_aiPad[1];
-      m_confRight  = m_aiPad[0];
-      m_confBottom = m_aiPad[1];
+      m_confWinRight  = m_aiPad[0];
+      m_confWinBottom = m_aiPad[1];
       break;
     }
@@ -1494,5 +1931,5 @@
     {
       // conformance
-      if ((m_confLeft == 0) && (m_confRight == 0) && (m_confTop == 0) && (m_confBottom == 0))
+      if ((m_confWinLeft == 0) && (m_confWinRight == 0) && (m_confWinTop == 0) && (m_confWinBottom == 0))
       {
         fprintf(stderr, "Warning: Conformance window enabled, but all conformance window parameters set to zero\n");
@@ -1601,4 +2038,22 @@
       m_targetPivotValue = NULL;
     }
+
+    if( pcStartOfCodedInterval )
+    {
+      free( pcStartOfCodedInterval );
+      pcStartOfCodedInterval = NULL;
+    }
+
+    if( pcCodedPivotValue )
+    {
+      free( pcCodedPivotValue );
+      pcCodedPivotValue = NULL;
+    }
+
+    if( pcTargetPivotValue )
+    {
+      free( pcTargetPivotValue );
+      pcTargetPivotValue = NULL;
+    }
   }
 #if P0050_KNEE_FUNCTION_SEI
@@ -1626,11 +2081,181 @@
       i++;
     }
-  }
-#endif
-
+
+    if( pcInputKneePointValue )
+    {
+      free( pcInputKneePointValue );
+      pcInputKneePointValue = NULL;
+    }
+
+    if( pcOutputKneePointValue )
+    {
+      free( pcOutputKneePointValue );
+      pcOutputKneePointValue = NULL;
+    }
+  }
+#endif
+#if Q0074_COLOUR_REMAPPING_SEI
+#if !SVC_EXTENSION
+  // reading external Colour Remapping Information SEI message parameters from file
+  if( m_colourRemapSEIFile.size() > 0 )
+  {
+    FILE* fic;
+    Int retval;
+    if((fic = fopen(m_colourRemapSEIFile.c_str(),"r")) == (FILE*)NULL)
+    {
+      fprintf(stderr, "Can't open Colour Remapping Information SEI parameters file %s\n", m_colourRemapSEIFile.c_str());
+      exit(EXIT_FAILURE);
+    }
+
+    retval = fscanf( fic, "%d", &m_colourRemapSEIId );
+    retval = fscanf( fic, "%d", &m_colourRemapSEICancelFlag );
+    if( !m_colourRemapSEICancelFlag )
+    {
+      retval = fscanf( fic, "%d", &m_colourRemapSEIPersistenceFlag );
+      retval = fscanf( fic, "%d", &m_colourRemapSEIVideoSignalInfoPresentFlag);
+      if( m_colourRemapSEIVideoSignalInfoPresentFlag )
+      {
+        retval = fscanf( fic, "%d", &m_colourRemapSEIFullRangeFlag  );
+        retval = fscanf( fic, "%d", &m_colourRemapSEIPrimaries );
+        retval = fscanf( fic, "%d", &m_colourRemapSEITransferFunction );
+        retval = fscanf( fic, "%d", &m_colourRemapSEIMatrixCoefficients );
+      }
+
+      retval = fscanf( fic, "%d", &m_colourRemapSEIInputBitDepth );
+      retval = fscanf( fic, "%d", &m_colourRemapSEIBitDepth );
+  
+      for( Int c=0 ; c<3 ; c++ )
+      {
+        retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutNumValMinus1[c] );
+        if( m_colourRemapSEIPreLutNumValMinus1[c]>0 )
+        {
+          m_colourRemapSEIPreLutCodedValue[c]  = new Int[m_colourRemapSEIPreLutNumValMinus1[c]+1];
+          m_colourRemapSEIPreLutTargetValue[c] = new Int[m_colourRemapSEIPreLutNumValMinus1[c]+1];
+          for( Int i=0 ; i<=m_colourRemapSEIPreLutNumValMinus1[c] ; i++ )
+          {
+            retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutCodedValue[c][i] );
+            retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutTargetValue[c][i] );
+          }
+        }
+      }
+
+      retval = fscanf( fic, "%d", &m_colourRemapSEIMatrixPresentFlag );
+      if( m_colourRemapSEIMatrixPresentFlag )
+      {
+        retval = fscanf( fic, "%d", &m_colourRemapSEILog2MatrixDenom );
+        for( Int c=0 ; c<3 ; c++ )
+          for( Int i=0 ; i<3 ; i++ )
+            retval = fscanf( fic, "%d", &m_colourRemapSEICoeffs[c][i] );
+      }
+
+      for( Int c=0 ; c<3 ; c++ )
+      {
+        retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutNumValMinus1[c] );
+        if( m_colourRemapSEIPostLutNumValMinus1[c]>0 )
+        {
+          m_colourRemapSEIPostLutCodedValue[c]  = new Int[m_colourRemapSEIPostLutNumValMinus1[c]+1];
+          m_colourRemapSEIPostLutTargetValue[c] = new Int[m_colourRemapSEIPostLutNumValMinus1[c]+1];
+          for( Int i=0 ; i<=m_colourRemapSEIPostLutNumValMinus1[c] ; i++ )
+          {
+            retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutCodedValue[c][i] );
+            retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutTargetValue[c][i] );
+          }
+        }
+      }
+    }
+
+    fclose( fic );
+    if( retval != 1 )
+    {
+      fprintf(stderr, "Error while reading Colour Remapping Information SEI parameters file\n");
+      exit(EXIT_FAILURE);
+    }
+  }
+#else
+   // Reading external Colour Remapping Information SEI message parameters from file
+  // It seems that TAppEncLayerCfg::parseCfg is not used
+  for(UInt layer = 0; layer < m_numLayers; layer++)
+  {
+    if( cfg_colourRemapSEIFile[layer]->length() )
+    {
+      FILE* fic;
+      Int retval;
+      if((fic = fopen(cfg_colourRemapSEIFile[layer]->c_str(),"r")) == (FILE*)NULL)
+      {
+        fprintf(stderr, "Can't open Colour Remapping Information SEI parameters file %s\n", cfg_colourRemapSEIFile[layer]->c_str());
+        exit(EXIT_FAILURE);
+      }
+      Int tempCode;
+      retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIId );
+      retval = fscanf( fic, "%d", &tempCode ); m_acLayerCfg[layer].m_colourRemapSEICancelFlag = tempCode ? 1 : 0;
+      if( !m_acLayerCfg[layer].m_colourRemapSEICancelFlag )
+      {
+        retval = fscanf( fic, "%d", &tempCode ); m_acLayerCfg[layer].m_colourRemapSEIPersistenceFlag = tempCode ? 1 : 0;
+        retval = fscanf( fic, "%d", &tempCode ); m_acLayerCfg[layer].m_colourRemapSEIVideoSignalInfoPresentFlag = tempCode ? 1 : 0;
+        if( m_acLayerCfg[layer].m_colourRemapSEIVideoSignalInfoPresentFlag )
+        {
+          retval = fscanf( fic, "%d", &tempCode ); m_acLayerCfg[layer].m_colourRemapSEIFullRangeFlag = tempCode ? 1 : 0;
+          retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIPrimaries );
+          retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEITransferFunction );
+          retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIMatrixCoefficients );
+        }
+
+        retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIInputBitDepth );
+        retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIBitDepth );
+  
+        for( Int c=0 ; c<3 ; c++ )
+        {
+          retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIPreLutNumValMinus1[c] );
+          if( m_acLayerCfg[layer].m_colourRemapSEIPreLutNumValMinus1[c]>0 )
+          {
+            m_acLayerCfg[layer].m_colourRemapSEIPreLutCodedValue[c]  = new Int[m_acLayerCfg[layer].m_colourRemapSEIPreLutNumValMinus1[c]+1];
+            m_acLayerCfg[layer].m_colourRemapSEIPreLutTargetValue[c] = new Int[m_acLayerCfg[layer].m_colourRemapSEIPreLutNumValMinus1[c]+1];
+            for( Int i=0 ; i<=m_acLayerCfg[layer].m_colourRemapSEIPreLutNumValMinus1[c] ; i++ )
+            {
+              retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIPreLutCodedValue[c][i] );
+              retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIPreLutTargetValue[c][i] );
+            }
+          }
+        }
+
+        retval = fscanf( fic, "%d", &tempCode ); m_acLayerCfg[layer].m_colourRemapSEIMatrixPresentFlag = tempCode ? 1 : 0;
+        if( m_acLayerCfg[layer].m_colourRemapSEIMatrixPresentFlag )
+        {
+          retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEILog2MatrixDenom );
+          for( Int c=0 ; c<3 ; c++ )
+            for( Int i=0 ; i<3 ; i++ )
+              retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEICoeffs[c][i] );
+        }
+
+        for( Int c=0 ; c<3 ; c++ )
+        {
+          retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIPostLutNumValMinus1[c] );
+          if( m_acLayerCfg[layer].m_colourRemapSEIPostLutNumValMinus1[c]>0 )
+          {
+            m_acLayerCfg[layer].m_colourRemapSEIPostLutCodedValue[c]  = new Int[m_acLayerCfg[layer].m_colourRemapSEIPostLutNumValMinus1[c]+1];
+            m_acLayerCfg[layer].m_colourRemapSEIPostLutTargetValue[c] = new Int[m_acLayerCfg[layer].m_colourRemapSEIPostLutNumValMinus1[c]+1];
+            for( Int i=0 ; i<=m_acLayerCfg[layer].m_colourRemapSEIPostLutNumValMinus1[c] ; i++ )
+            {
+              retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIPostLutCodedValue[c][i] );
+              retval = fscanf( fic, "%d", &m_acLayerCfg[layer].m_colourRemapSEIPostLutTargetValue[c][i] );
+            }
+          }
+        }
+      }
+
+      fclose( fic );
+      if( retval != 1 )
+      {
+        fprintf(stderr, "Error while reading Colour Remapping Information SEI parameters file\n");
+        exit(EXIT_FAILURE);
+      }
+    }
+  }
+#endif
+#endif
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
   if (m_interLayerConstrainedTileSetsSEIEnabled)
   {
-    if (m_iNumColumnsMinus1 == 0 && m_iNumRowsMinus1 == 0)
+    if (m_numTileColumnsMinus1 == 0 && m_numTileRowsMinus1 == 0)
     {
       printf( "Tiles are not defined (needed for inter-layer comnstrained tile sets SEI).\n" );
@@ -1671,4 +2296,10 @@
     }
     m_skippedTileSetPresentFlag = false;
+
+    if( pTileSets )
+    {
+      free( pTileSets );
+      pTileSets = NULL;
+    }
   }
 #endif
@@ -1837,9 +2468,9 @@
   }
   
-  Bool tileFlag = (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0 );
+#if !SVC_EXTENSION
+  Bool tileFlag = (m_numTileColumnsMinus1 > 0 || m_numTileRowsMinus1 > 0 );
   xConfirmPara( tileFlag && m_iWaveFrontSynchro,            "Tile and Wavefront can not be applied together");
 
   //TODO:ChromaFmt assumes 4:2:0 below
-#if !SVC_EXTENSION
   xConfirmPara( m_iSourceWidth  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling");
   xConfirmPara( m_iSourceHeight % TComSPS::getWinUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling");
@@ -1848,8 +2479,18 @@
   xConfirmPara( m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling");
 
-  xConfirmPara( m_confLeft   % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left conformance window offset must be an integer multiple of the specified chroma subsampling");
-  xConfirmPara( m_confRight  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right conformance window offset must be an integer multiple of the specified chroma subsampling");
-  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");
+  xConfirmPara( m_confWinLeft   % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left conformance window offset must be an integer multiple of the specified chroma subsampling");
+  xConfirmPara( m_confWinRight  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right conformance window offset must be an integer multiple of the specified chroma subsampling");
+  xConfirmPara( m_confWinTop    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling");
+  xConfirmPara( m_confWinBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling");
+
+  xConfirmPara( m_defaultDisplayWindowFlag && !m_vuiParametersPresentFlag, "VUI needs to be enabled for default display window");
+
+  if (m_defaultDisplayWindowFlag)
+  {
+    xConfirmPara( m_defDispWinLeftOffset   % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left default display window offset must be an integer multiple of the specified chroma subsampling");
+    xConfirmPara( m_defDispWinRightOffset  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right default display window offset must be an integer multiple of the specified chroma subsampling");
+    xConfirmPara( m_defDispWinTopOffset    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top default display window offset must be an integer multiple of the specified chroma subsampling");
+    xConfirmPara( m_defDispWinBottomOffset % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom default display window offset must be an integer multiple of the specified chroma subsampling");
+  }
 #endif
 
@@ -1955,5 +2596,9 @@
   
   // it can be updated after AVC BL support will be added to the WD
+#if VPS_AVC_BL_FLAG_REMOVAL
+  if( m_nonHEVCBaseLayerFlag )
+#else
   if( m_avcBaseLayerFlag )
+#endif
   {
     m_crossLayerIrapAlignFlag = false;
@@ -2593,5 +3238,10 @@
     Int m_uiMaxCUHeight = m_acLayerCfg[layer].m_uiMaxCUHeight;
 #endif
-#endif
+
+    Bool tileFlag = (m_numTileColumnsMinus1 > 0 || m_numTileRowsMinus1 > 0 );
+    Int m_iWaveFrontSynchro = m_acLayerCfg[layer].m_waveFrontSynchro;
+    xConfirmPara( tileFlag && m_iWaveFrontSynchro,            "Tile and Wavefront can not be applied together");
+#endif
+
   if(m_vuiParametersPresentFlag && m_bitstreamRestrictionFlag)
   { 
@@ -2603,11 +3253,11 @@
       Int widthInCU = (m_iSourceWidth % m_uiMaxCUWidth) ? m_iSourceWidth/m_uiMaxCUWidth + 1: m_iSourceWidth/m_uiMaxCUWidth;
       Int heightInCU = (m_iSourceHeight % m_uiMaxCUHeight) ? m_iSourceHeight/m_uiMaxCUHeight + 1: m_iSourceHeight/m_uiMaxCUHeight;
-      if(m_iUniformSpacingIdr)
-      {
-        maxTileWidth = m_uiMaxCUWidth*((widthInCU+m_iNumColumnsMinus1)/(m_iNumColumnsMinus1+1));
-        maxTileHeight = m_uiMaxCUHeight*((heightInCU+m_iNumRowsMinus1)/(m_iNumRowsMinus1+1));
+      if(m_tileUniformSpacingFlag)
+      {
+        maxTileWidth = m_uiMaxCUWidth*((widthInCU+m_numTileColumnsMinus1)/(m_numTileColumnsMinus1+1));
+        maxTileHeight = m_uiMaxCUHeight*((heightInCU+m_numTileRowsMinus1)/(m_numTileRowsMinus1+1));
         // if only the last tile-row is one treeblock higher than the others 
         // the maxTileHeight becomes smaller if the last row of treeblocks has lower height than the others
-        if(!((heightInCU-1)%(m_iNumRowsMinus1+1)))
+        if(!((heightInCU-1)%(m_numTileRowsMinus1+1)))
         {
           maxTileHeight = maxTileHeight - m_uiMaxCUHeight + (m_iSourceHeight % m_uiMaxCUHeight);
@@ -2615,5 +3265,5 @@
         // if only the last tile-column is one treeblock wider than the others 
         // the maxTileWidth becomes smaller if the last column of treeblocks has lower width than the others   
-        if(!((widthInCU-1)%(m_iNumColumnsMinus1+1)))
+        if(!((widthInCU-1)%(m_numTileColumnsMinus1+1)))
         {
           maxTileWidth = maxTileWidth - m_uiMaxCUWidth + (m_iSourceWidth % m_uiMaxCUWidth);
@@ -2622,5 +3272,5 @@
       else // not uniform spacing
       {
-        if(m_iNumColumnsMinus1<1)
+        if(m_numTileColumnsMinus1<1)
         {
           maxTileWidth = m_iSourceWidth;
@@ -2629,12 +3279,12 @@
         {
           Int accColumnWidth = 0;
-          for(Int col=0; col<(m_iNumColumnsMinus1); col++)
+          for(Int col=0; col<(m_numTileColumnsMinus1); col++)
           {
-            maxTileWidth = m_pColumnWidth[col]>maxTileWidth ? m_pColumnWidth[col]:maxTileWidth;
-            accColumnWidth += m_pColumnWidth[col];
+            maxTileWidth = m_tileColumnWidth[col]>maxTileWidth ? m_tileColumnWidth[col]:maxTileWidth;
+            accColumnWidth += m_tileColumnWidth[col];
           }
           maxTileWidth = (widthInCU-accColumnWidth)>maxTileWidth ? m_uiMaxCUWidth*(widthInCU-accColumnWidth):m_uiMaxCUWidth*maxTileWidth;
         }
-        if(m_iNumRowsMinus1<1)
+        if(m_numTileRowsMinus1<1)
         {
           maxTileHeight = m_iSourceHeight;
@@ -2643,8 +3293,8 @@
         {
           Int accRowHeight = 0;
-          for(Int row=0; row<(m_iNumRowsMinus1); row++)
+          for(Int row=0; row<(m_numTileRowsMinus1); row++)
           {
-            maxTileHeight = m_pRowHeight[row]>maxTileHeight ? m_pRowHeight[row]:maxTileHeight;
-            accRowHeight += m_pRowHeight[row];
+            maxTileHeight = m_tileRowHeight[row]>maxTileHeight ? m_tileRowHeight[row]:maxTileHeight;
+            accRowHeight += m_tileRowHeight[row];
           }
           maxTileHeight = (heightInCU-accRowHeight)>maxTileHeight ? m_uiMaxCUHeight*(heightInCU-accRowHeight):m_uiMaxCUHeight*maxTileHeight;
@@ -2670,6 +3320,6 @@
   }
 #endif
+#if !SVC_EXTENSION
   xConfirmPara( m_iWaveFrontSynchro < 0, "WaveFrontSynchro cannot be negative" );
-#if !SVC_EXTENSION
   xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
   xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_iWaveFrontSynchro, "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
@@ -2703,4 +3353,37 @@
   }
 #endif
+#if Q0074_COLOUR_REMAPPING_SEI
+#if !SVC_EXTENSION
+  if ( ( m_colourRemapSEIFile.size() > 0 ) && !m_colourRemapSEICancelFlag )
+  {
+    xConfirmPara( m_colourRemapSEIInputBitDepth < 8 || m_colourRemapSEIInputBitDepth > 16 , "colour_remap_input_bit_depth shall be in the range of 8 to 16, inclusive");
+    xConfirmPara( m_colourRemapSEIBitDepth < 8 || m_colourRemapSEIBitDepth > 16, "colour_remap_bit_depth shall be in the range of 8 to 16, inclusive");
+    for( Int c=0 ; c<3 ; c++)
+    {
+      xConfirmPara( m_colourRemapSEIPreLutNumValMinus1[c] < 0 || m_colourRemapSEIPreLutNumValMinus1[c] > 32, "pre_lut_num_val_minus1[c] shall be in the range of 0 to 32, inclusive");
+      if( m_colourRemapSEIPreLutNumValMinus1[c]>0 )
+        for( Int i=0 ; i<=m_colourRemapSEIPreLutNumValMinus1[c] ; i++)
+        {
+          xConfirmPara( m_colourRemapSEIPreLutCodedValue[c][i] < 0 || m_colourRemapSEIPreLutCodedValue[c][i] > ((1<<m_colourRemapSEIInputBitDepth)-1), "pre_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_input_bit_depth)-1, inclusive");
+          xConfirmPara( m_colourRemapSEIPreLutTargetValue[c][i] < 0 || m_colourRemapSEIPreLutTargetValue[c][i] > ((1<<m_colourRemapSEIBitDepth)-1), "pre_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_bit_depth)-1, inclusive");
+        }
+      xConfirmPara( m_colourRemapSEIPostLutNumValMinus1[c] < 0 || m_colourRemapSEIPostLutNumValMinus1[c] > 32, "post_lut_num_val_minus1[c] shall be in the range of 0 to 32, inclusive");
+      if( m_colourRemapSEIPostLutNumValMinus1[c]>0 )
+        for( Int i=0 ; i<=m_colourRemapSEIPostLutNumValMinus1[c] ; i++)
+        {
+          xConfirmPara( m_colourRemapSEIPostLutCodedValue[c][i] < 0 || m_colourRemapSEIPostLutCodedValue[c][i] > ((1<<m_colourRemapSEIBitDepth)-1), "post_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_bit_depth)-1, inclusive");
+          xConfirmPara( m_colourRemapSEIPostLutTargetValue[c][i] < 0 || m_colourRemapSEIPostLutTargetValue[c][i] > ((1<<m_colourRemapSEIBitDepth)-1), "post_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_bit_depth)-1, inclusive");
+        }
+    }
+    if ( m_colourRemapSEIMatrixPresentFlag )
+    {
+      xConfirmPara( m_colourRemapSEILog2MatrixDenom < 0 || m_colourRemapSEILog2MatrixDenom > 15, "log2_matrix_denom shall be in the range of 0 to 15, inclusive");
+      for( Int c=0 ; c<3 ; c++)
+        for( Int i=0 ; i<3 ; i++)
+          xConfirmPara( m_colourRemapSEICoeffs[c][i] < -32768 || m_colourRemapSEICoeffs[c][i] > 32767, "colour_remap_coeffs[c][i] shall be in the range of -32768 and 32767, inclusive");
+    }
+  }
+#endif
+#endif
 
 #if RC_SHVC_HARMONIZATION
@@ -2909,5 +3592,9 @@
   printf("Scalable                      : %d\n", m_scalabilityMask[SCALABILITY_ID] );
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+  printf("Base layer                    : %s\n", m_nonHEVCBaseLayerFlag ? "Non-HEVC" : "HEVC");
+#else
   printf("Base layer                    : %s\n", m_avcBaseLayerFlag ? "AVC" : "HEVC");
+#endif
 #endif
 #if AUXILIARY_PICTURES
@@ -2933,20 +3620,16 @@
   {
     printf("=== Layer %d settings === \n", layer);
-#if AVC_SYNTAX
-    m_acLayerCfg[layer].xPrintParameter( layer );
-#else
     m_acLayerCfg[layer].xPrintParameter();
-#endif
     printf("\n");
   }
   printf("=== Common configuration settings === \n");
   printf("Bitstream      File          : %s\n", m_pBitstreamFile      );
-#else
+#else //SVC_EXTENSION
   printf("Input          File          : %s\n", m_pchInputFile          );
   printf("Bitstream      File          : %s\n", m_pchBitstreamFile      );
   printf("Reconstruction File          : %s\n", m_pchReconFile          );
-  printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
+  printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_confWinLeft - m_confWinRight, m_iSourceHeight - m_confWinTop - m_confWinBottom, m_iFrameRate );
   printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
-#endif
+#endif //SVC_EXTENSION
   if (m_isField)
   {
@@ -3084,4 +3767,11 @@
   printf("CGS: %d CGSMaxOctantDepth: %d CGSMaxYPartNumLog2: %d CGSLUTBit:%d " , m_nCGSFlag , m_nCGSMaxOctantDepth , m_nCGSMaxYPartNumLog2 , m_nCGSLUTBit );
 #endif
+#if R0151_CGS_3D_ASYMLUT_IMPROVE
+  printf("CGSAdaptC:%d " , m_nCGSAdaptiveChroma );
+#endif
+#if R0179_ENC_OPT_3DLUT_SIZE
+  printf("CGSSizeRDO:%d " , m_nCGSLutSizeRDO );
+#endif
+
   printf("\n\n");
   
@@ -3099,5 +3789,9 @@
 
 #if SVC_EXTENSION
+#if OUTPUT_LAYER_SETS_CONFIG
+Void TAppEncCfg::cfgStringToArray(Int **arr, string const cfgString, Int const numEntries, const char* logString)
+#else
 Void TAppEncCfg::cfgStringToArray(Int **arr, string cfgString, Int numEntries, const char* logString)
+#endif
 {
   Char *tempChar = cfgString.empty() ? NULL : strdup(cfgString.c_str());
@@ -3108,5 +3802,16 @@
     *arr = new Int[numEntries];
 
+#if OUTPUT_LAYER_SETS_CONFIG
+    if( tempChar == NULL )
+    {
+      arrayEntry = NULL;
+    }
+    else
+    {
+      arrayEntry = strtok( tempChar, " ,");
+    }
+#else
     arrayEntry = strtok( tempChar, " ,");
+#endif
     while(arrayEntry != NULL)
     {
@@ -3130,6 +3835,47 @@
     *arr = NULL;
   }
+
+  if( tempChar )
+  {
+    free( tempChar );
+    tempChar = NULL;
+  }
 }
 
+#if OUTPUT_LAYER_SETS_CONFIG
+Bool TAppEncCfg::scanStringToArray(string const cfgString, Int const numEntries, const char* logString, Int * const returnArray)
+{
+  Int *tempArray = NULL;
+  // For all layer sets
+  cfgStringToArray( &tempArray, cfgString, numEntries, logString );
+  if(tempArray)
+  {
+    for(Int i = 0; i < numEntries; i++)
+    {
+      returnArray[i] = tempArray[i];
+    }
+    delete [] tempArray; tempArray = NULL;
+    return true;
+  }
+  return false;
+}
+Bool TAppEncCfg::scanStringToArray(string const cfgString, Int const numEntries, const char* logString, std::vector<Int> & returnVector)
+{
+  Int *tempArray = NULL;
+  // For all layer sets
+  cfgStringToArray( &tempArray, cfgString, numEntries, logString );
+  if(tempArray)
+  {
+    returnVector.empty();
+    for(Int i = 0; i < numEntries; i++)
+    {
+      returnVector.push_back(tempArray[i]);
+    }
+    delete [] tempArray; tempArray = NULL;
+    return true;
+  }
+  return false;
+}
+#endif
 #endif //SVC_EXTENSION
 //! \}
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 815)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 906)
@@ -46,4 +46,5 @@
 #endif
 #include <sstream>
+#include <vector>
 //! \ingroup TAppEncoder
 //! \{
@@ -68,8 +69,9 @@
   Int       m_framesToBeEncoded;                              ///< number of encoded frames
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+  Int       m_nonHEVCBaseLayerFlag;                           ///< non HEVC BL
+#else
   Int       m_avcBaseLayerFlag;                               ///< avc_baselayer_flag
 #endif
-#if AVC_SYNTAX
-  Char*     m_BLSyntaxFile;                                   ///< input syntax file
 #endif
   Bool      m_maxTidRefPresentFlag; 
@@ -81,4 +83,11 @@
   Int       m_numHighestLayerIdx[MAX_VPS_LAYER_SETS_PLUS1];
   Int       m_highestLayerIdx[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+#endif
+#if OUTPUT_LAYER_SETS_CONFIG
+  std::vector<Int>                m_outputLayerSetIdx;
+  Int       m_defaultTargetOutputLayerIdc;
+  Int       m_numOutputLayerSets;
+  std::vector<Int>                m_numLayersInOutputLayerSet;
+  std::vector< std::vector<Int> > m_listOfOutputLayers;
 #endif
 #else
@@ -96,9 +105,9 @@
   
   
-  Int       m_conformanceMode;
-  Int       m_confLeft;
-  Int       m_confRight;
-  Int       m_confTop;
-  Int       m_confBottom;
+  Int       m_conformanceWindowMode;
+  Int       m_confWinLeft;
+  Int       m_confWinRight;
+  Int       m_confWinTop;
+  Int       m_confWinBottom;
   Int       m_framesToBeEncoded;                              ///< number of encoded frames
   Int       m_aiPad[2];                                       ///< number of padded pixels for width and height
@@ -222,5 +231,5 @@
   Bool      m_useRDOQ;                                       ///< flag for using RD optimized quantization
   Bool      m_useRDOQTS;                                     ///< flag for using RD optimized quantization for transform skip
-  Int      m_rdPenalty;                                      ///< RD-penalty for 32x32 TU for intra in non-intra slices (0: no RD-penalty, 1: RD-penalty, 2: maximum RD-penalty) 
+  Int       m_rdPenalty;                                      ///< RD-penalty for 32x32 TU for intra in non-intra slices (0: no RD-penalty, 1: RD-penalty, 2: maximum RD-penalty) 
   Int       m_iFastSearch;                                    ///< ME mode, 0 = full, 1 = diamond, 2 = PMVFAST
   Int       m_iSearchRange;                                   ///< ME search range
@@ -243,18 +252,14 @@
   Bool      m_bLFCrossSliceBoundaryFlag;  ///< 1: filter across slice boundaries 0: do not filter across slice boundaries
   Bool      m_bLFCrossTileBoundaryFlag;   ///< 1: filter across tile boundaries  0: do not filter across tile boundaries
-  Int       m_iUniformSpacingIdr;
-  Int       m_iNumColumnsMinus1;
-  Char*     m_pchColumnWidth;
-  Int       m_iNumRowsMinus1;
-  Char*     m_pchRowHeight;
-  UInt*     m_pColumnWidth;
-  UInt*     m_pRowHeight;
+  Bool      m_tileUniformSpacingFlag;
+  Int       m_numTileColumnsMinus1;
+  Int       m_numTileRowsMinus1;
+  std::vector<Int> m_tileColumnWidth;
+  std::vector<Int> m_tileRowHeight;
+#if !SVC_EXTENSION
   Int       m_iWaveFrontSynchro; //< 0: no WPP. >= 1: WPP is enabled, the "Top right" from which inheritance occurs is this LCU offset in the line above the current.
-#if !SVC_EXTENSION
   Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
 #endif
-
   Bool      m_bUseConstrainedIntraPred;                       ///< flag for using constrained intra prediction
-  
   Int       m_decodedPictureHashSEIEnabled;                    ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
   Int       m_recoveryPointSEIEnabled;
@@ -288,7 +293,4 @@
   Int*      m_codedPivotValue;
   Int*      m_targetPivotValue;
-#if Q0074_SEI_COLOR_MAPPING
-  Char*     m_pchSEIColorMappingFile;             ///< SEI Color Mapping File (initialized from external file)
-#endif
   Int       m_framePackingSEIEnabled;
   Int       m_framePackingSEIType;
@@ -377,4 +379,28 @@
   Int       m_elRapSliceBEnabled;
 #endif
+#if Q0074_COLOUR_REMAPPING_SEI
+#if !SVC_EXTENSION
+  string    m_colourRemapSEIFile;
+  Int       m_colourRemapSEIId;
+  Bool      m_colourRemapSEICancelFlag;
+  Bool      m_colourRemapSEIPersistenceFlag;
+  Bool      m_colourRemapSEIVideoSignalInfoPresentFlag;
+  Bool      m_colourRemapSEIFullRangeFlag;
+  Int       m_colourRemapSEIPrimaries;
+  Int       m_colourRemapSEITransferFunction;
+  Int       m_colourRemapSEIMatrixCoefficients;
+  Int       m_colourRemapSEIInputBitDepth;
+  Int       m_colourRemapSEIBitDepth;
+  Int       m_colourRemapSEIPreLutNumValMinus1[3];
+  Int*      m_colourRemapSEIPreLutCodedValue[3];
+  Int*      m_colourRemapSEIPreLutTargetValue[3];
+  Bool      m_colourRemapSEIMatrixPresentFlag;
+  Int       m_colourRemapSEILog2MatrixDenom;
+  Int       m_colourRemapSEICoeffs[3][3];
+  Int       m_colourRemapSEIPostLutNumValMinus1[3];
+  Int*      m_colourRemapSEIPostLutCodedValue[3];
+  Int*      m_colourRemapSEIPostLutTargetValue[3];
+#endif
+#endif
   // internal member functions
 #if LAYER_CTB
@@ -439,5 +465,11 @@
   Int  m_nCGSMaxYPartNumLog2;
   Int  m_nCGSLUTBit;
-#endif
+#if R0151_CGS_3D_ASYMLUT_IMPROVE
+  Int  m_nCGSAdaptiveChroma;
+#endif
+#if R0179_ENC_OPT_3DLUT_SIZE
+  Int  m_nCGSLutSizeRDO;
+#endif
+#endif 
 #endif //SVC_EXTENSION
 public:
@@ -468,10 +500,13 @@
 #endif
   Int  getDecodingRefreshType()    {return m_iDecodingRefreshType; }
-  Int  getWaveFrontSynchro()        { return m_iWaveFrontSynchro; }
+  Int  getWaveFrontSynchro(Int layerId)        { return m_acLayerCfg[layerId].m_waveFrontSynchro; }
   Void getDirFilename(string& filename, string& dir, const string path);
-#if AVC_SYNTAX
-  Char* getBLSyntaxFile()           { return m_BLSyntaxFile;      }
-#endif
+#if OUTPUT_LAYER_SETS_CONFIG
+  Bool scanStringToArray(string const cfgString, Int const numEntries, const char* logString, Int * const returnArray);
+  Bool scanStringToArray(string const cfgString, Int const numEntries, const char* logString, std::vector<Int> &  returnVector);
+  Void cfgStringToArray(Int **arr, string const cfgString, Int const numEntries, const char* logString);
+#else
   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]; }
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 815)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 906)
@@ -49,6 +49,18 @@
 , m_repFormatIdx (-1)
 #endif
-{
-  m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
+#if Q0074_COLOUR_REMAPPING_SEI
+,  m_colourRemapSEIFile(string(""))
+#endif
+{
+#if Q0074_COLOUR_REMAPPING_SEI
+  for( Int c=0 ; c<3 ; c++)
+  {
+    m_colourRemapSEIPreLutCodedValue[c]   = NULL;
+    m_colourRemapSEIPreLutTargetValue[c]  = NULL;
+    m_colourRemapSEIPostLutCodedValue[c]  = NULL;
+    m_colourRemapSEIPostLutTargetValue[c] = NULL;
+  }
+#endif
+  m_confWinLeft = m_confWinRight = m_confWinTop = m_confWinBottom = 0;
   m_aiPad[1] = m_aiPad[0] = 0;
   m_numScaledRefLayerOffsets = 0;
@@ -60,7 +72,23 @@
   ::memset(m_scaledRefLayerRightOffset,  0, sizeof(m_scaledRefLayerRightOffset));
   ::memset(m_scaledRefLayerBottomOffset, 0, sizeof(m_scaledRefLayerBottomOffset));
+#if REF_REGION_OFFSET
+  ::memset(m_scaledRefLayerOffsetPresentFlag, 0, sizeof(m_scaledRefLayerOffsetPresentFlag));
+  ::memset(m_refRegionOffsetPresentFlag, 0, sizeof(m_refRegionOffsetPresentFlag));
+  ::memset(m_refRegionLeftOffset,   0, sizeof(m_refRegionLeftOffset));
+  ::memset(m_refRegionTopOffset,    0, sizeof(m_refRegionTopOffset));
+  ::memset(m_refRegionRightOffset,  0, sizeof(m_refRegionRightOffset));
+  ::memset(m_refRegionBottomOffset, 0, sizeof(m_refRegionBottomOffset));
+#endif
+#if R0209_GENERIC_PHASE
+  ::memset(m_resamplePhaseSetPresentFlag, 0, sizeof(m_resamplePhaseSetPresentFlag));
+  ::memset(m_phaseHorLuma,   0, sizeof(m_phaseHorLuma));
+  ::memset(m_phaseVerLuma,   0, sizeof(m_phaseVerLuma));
+  ::memset(m_phaseHorChroma, 0, sizeof(m_phaseHorChroma));
+  ::memset(m_phaseVerChroma, 0, sizeof(m_phaseVerChroma));
+#else
 #if P0312_VERT_PHASE_ADJ 
   ::memset(m_vertPhasePositionEnableFlag, 0, sizeof(m_vertPhasePositionEnableFlag));
 #endif
+#endif
 }
 
@@ -71,4 +99,25 @@
     delete[] m_aidQP;
   }
+#if Q0074_COLOUR_REMAPPING_SEI
+  for( Int c=0 ; c<3 ; c++)
+  {
+    if ( m_colourRemapSEIPreLutCodedValue[c] )
+    {
+      delete[] m_colourRemapSEIPreLutCodedValue[c];
+    }
+    if ( m_colourRemapSEIPreLutTargetValue[c] )
+    {
+      delete[] m_colourRemapSEIPreLutTargetValue[c];
+    }
+    if ( m_colourRemapSEIPostLutCodedValue[c] )
+    {
+      delete[] m_colourRemapSEIPostLutCodedValue[c];
+    }
+    if ( m_colourRemapSEIPostLutTargetValue[c] )
+    {
+      delete[] m_colourRemapSEIPostLutTargetValue[c];
+    }
+  }
+#endif
 }
 
@@ -98,4 +147,7 @@
   Int tmpInputChromaFormat;
   Int tmpChromaFormat;
+#endif
+#if Q0074_COLOUR_REMAPPING_SEI
+  string  cfg_colourRemapSEIFile;
 #endif
 
@@ -114,8 +166,12 @@
     ("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")
-    ("CropTop",               m_confTop,       0, "Top cropping/padding for cropping mode 3")
-    ("CropBottom",            m_confBottom,    0, "Bottom cropping/padding for cropping mode 3")
+    ("ConfLeft",              m_confWinLeft,            0, "Deprecated alias of ConfWinLeft")
+    ("ConfRight",             m_confWinRight,           0, "Deprecated alias of ConfWinRight")
+    ("ConfTop",               m_confWinTop,             0, "Deprecated alias of ConfWinTop")
+    ("ConfBottom",            m_confWinBottom,          0, "Deprecated alias of ConfWinBottom")
+    ("ConfWinLeft",           m_confWinLeft,            0, "Left offset for window conformance mode 3")
+    ("ConfWinRight",          m_confWinRight,           0, "Right offset for window conformance mode 3")
+    ("ConfWinTop",            m_confWinTop,             0, "Top offset for window conformance mode 3")
+    ("ConfWinBottom",         m_confWinBottom,          0, "Bottom offset for window conformance mode 3")
     ("HorizontalPadding,-pdx",m_aiPad[0],      0, "horizontal source padding for cropping mode 2")
     ("VerticalPadding,-pdy",  m_aiPad[1],      0, "vertical source padding for cropping mode 2")
@@ -124,5 +180,8 @@
     ("dQPFile,m",             cfg_dQPFile, string(""), "dQP file name")
     ("QP,q",                  m_fQP,          30.0, "Qp value, if value is float, QP is switched once during encoding")
-    ;
+#if Q0074_COLOUR_REMAPPING_SEI
+    ("SEIColourRemappingInfoFile", cfg_colourRemapSEIFile, string(""), "Colour Remapping Information SEI parameters file name")
+#endif
+  ;
 
   po::setDefaults(opts);
@@ -136,4 +195,7 @@
   m_chromaFormatIDC   = ((tmpChromaFormat == 0) ? (m_InputChromaFormat) : (numberToChromaFormat(tmpChromaFormat)));
 #endif
+#if Q0074_COLOUR_REMAPPING_SEI
+  m_colourRemapSEIFile = cfg_colourRemapSEIFile.empty() ? NULL : strdup(cfg_colourRemapSEIFile.c_str());
+#endif
 
   // reading external dQP description from file
@@ -154,25 +216,94 @@
     }
   }
+
+#if Q0074_COLOUR_REMAPPING_SEI
+  if( m_colourRemapSEIFile.size() > 0 )
+  {
+    FILE* fic;
+    Int retval;
+    if((fic = fopen(m_colourRemapSEIFile.c_str(),"r")) == (FILE*)NULL)
+    {
+      fprintf(stderr, "Can't open Colour Remapping Information SEI parameters file %s\n", m_colourRemapSEIFile.c_str());
+      exit(EXIT_FAILURE);
+    }
+
+    Int tempCode;
+    retval = fscanf( fic, "%d", &m_colourRemapSEIId );
+    retval = fscanf( fic, "%d", &tempCode );m_colourRemapSEICancelFlag = tempCode ? 1 : 0; 
+    if( !m_colourRemapSEICancelFlag )
+    {
+      retval = fscanf( fic, "%d", &tempCode );m_colourRemapSEIPersistenceFlag = tempCode ? 1 : 0; 
+      retval = fscanf( fic, "%d", &tempCode );m_colourRemapSEIVideoSignalInfoPresentFlag = tempCode ? 1 : 0; 
+      if( m_colourRemapSEIVideoSignalInfoPresentFlag )
+      {
+        retval = fscanf( fic, "%d", &tempCode );m_colourRemapSEIFullRangeFlag = tempCode ? 1 : 0; 
+        retval = fscanf( fic, "%d", &m_colourRemapSEIPrimaries );
+        retval = fscanf( fic, "%d", &m_colourRemapSEITransferFunction );
+        retval = fscanf( fic, "%d", &m_colourRemapSEIMatrixCoefficients );
+      }
+
+      retval = fscanf( fic, "%d", &m_colourRemapSEIInputBitDepth );
+      retval = fscanf( fic, "%d", &m_colourRemapSEIBitDepth );
+  
+      for( Int c=0 ; c<3 ; c++ )
+      {
+        retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutNumValMinus1[c] );
+        if( m_colourRemapSEIPreLutNumValMinus1[c]>0 )
+        {
+          m_colourRemapSEIPreLutCodedValue[c]  = new Int[m_colourRemapSEIPreLutNumValMinus1[c]+1];
+          m_colourRemapSEIPreLutTargetValue[c] = new Int[m_colourRemapSEIPreLutNumValMinus1[c]+1];
+          for( Int i=0 ; i<=m_colourRemapSEIPreLutNumValMinus1[c] ; i++ )
+          {
+            retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutCodedValue[c][i] );
+            retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutTargetValue[c][i] );
+          }
+        }
+      }
+
+      retval = fscanf( fic, "%d", &tempCode );m_colourRemapSEIMatrixPresentFlag = tempCode ? 1 : 0; 
+      if( m_colourRemapSEIMatrixPresentFlag )
+      {
+        retval = fscanf( fic, "%d", &m_colourRemapSEILog2MatrixDenom );
+        for( Int c=0 ; c<3 ; c++ )
+          for( Int i=0 ; i<3 ; i++ )
+            retval = fscanf( fic, "%d", &m_colourRemapSEICoeffs[c][i] );
+      }
+
+      for( Int c=0 ; c<3 ; c++ )
+      {
+        retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutNumValMinus1[c] );
+        if( m_colourRemapSEIPostLutNumValMinus1[c]>0 )
+        {
+          m_colourRemapSEIPostLutCodedValue[c]  = new Int[m_colourRemapSEIPostLutNumValMinus1[c]+1];
+          m_colourRemapSEIPostLutTargetValue[c] = new Int[m_colourRemapSEIPostLutNumValMinus1[c]+1];
+          for( Int i=0 ; i<=m_colourRemapSEIPostLutNumValMinus1[c] ; i++ )
+          {
+            retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutCodedValue[c][i] );
+            retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutTargetValue[c][i] );
+          }
+        }
+      }
+    }
+
+    fclose( fic );
+    if( retval != 1 )
+    {
+      fprintf(stderr, "Error while reading Colour Remapping Information SEI parameters file\n");
+      exit(EXIT_FAILURE);
+    }
+  }
+#endif
+
   return true;
 }
 
-#if AVC_SYNTAX
-Void TAppEncLayerCfg::xPrintParameter( UInt layerId )
-#else
 Void TAppEncLayerCfg::xPrintParameter()
-#endif
 {
   printf("Input File                    : %s\n", m_cInputFile.c_str()  );
   printf("Reconstruction File           : %s\n", m_cReconFile.c_str()  );
-#if AVC_SYNTAX
-  if( layerId == 0 )
-  {
-    printf("Base layer syntax file        : %s\n", m_cAppEncCfg->getBLSyntaxFile() );
-  }
-#endif
 #if REPN_FORMAT_IN_VPS
-  printf("Real     Format               : %dx%d %dHz\n", m_iSourceWidth - ( m_confLeft + m_confRight ) * TComSPS::getWinUnitX( m_chromaFormatIDC ), m_iSourceHeight - ( m_confTop + m_confBottom ) * TComSPS::getWinUnitY( m_chromaFormatIDC ), m_iFrameRate );
+  printf("Real     Format               : %dx%d %dHz\n", m_iSourceWidth - ( m_confWinLeft + m_confWinRight ) * TComSPS::getWinUnitX( m_chromaFormatIDC ), m_iSourceHeight - ( m_confWinTop + m_confWinBottom ) * TComSPS::getWinUnitY( m_chromaFormatIDC ), m_iFrameRate );
 #else
-  printf("Real     Format               : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
+  printf("Real     Format               : %dx%d %dHz\n", m_iSourceWidth - m_confWinLeft - m_confWinRight, m_iSourceHeight - m_confWinTop - m_confWinBottom, m_iFrameRate );
 #endif
   printf("Internal Format               : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
@@ -202,5 +333,5 @@
   }
 #endif
-  printf("WaveFrontSynchro:%d WaveFrontSubstreams:%d", m_cAppEncCfg->getWaveFrontSynchro(), m_iWaveFrontSubstreams);
+  printf("WaveFrontSynchro:%d WaveFrontSubstreams:%d", m_waveFrontSynchro, m_iWaveFrontSubstreams);
 #if LAYER_CTB
   printf("PCM:%d ", (m_cAppEncCfg->getUsePCM() && (1<<m_cAppEncCfg->getPCMLog2MinSize()) <= m_uiMaxCUWidth)? 1 : 0);
@@ -217,5 +348,5 @@
     {
       // no cropping or padding
-      m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
+      m_confWinLeft = m_confWinRight = m_confWinTop = m_confWinBottom = 0;
       m_aiPad[1] = m_aiPad[0] = 0;
       break;
@@ -231,21 +362,21 @@
       if (m_iSourceWidth % minCuSize)
       {
-        m_aiPad[0] = m_confRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
-        m_iSourceWidth  += m_confRight;
+        m_aiPad[0] = m_confWinRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
+        m_iSourceWidth  += m_confWinRight;
 #if REPN_FORMAT_IN_VPS
-        m_confRight /= TComSPS::getWinUnitX( m_chromaFormatIDC );
+        m_confWinRight /= TComSPS::getWinUnitX( m_chromaFormatIDC );
 #endif
       }
       if (m_iSourceHeight % minCuSize)
       {
-        m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
-        m_iSourceHeight += m_confBottom;
+        m_aiPad[1] = m_confWinBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
+        m_iSourceHeight += m_confWinBottom;
         if ( isField )
         {
-          m_iSourceHeightOrg += m_confBottom << 1;
-          m_aiPad[1] = m_confBottom << 1;
+          m_iSourceHeightOrg += m_confWinBottom << 1;
+          m_aiPad[1] = m_confWinBottom << 1;
         }
 #if REPN_FORMAT_IN_VPS
-        m_confBottom /= TComSPS::getWinUnitY( m_chromaFormatIDC );
+        m_confWinBottom /= TComSPS::getWinUnitY( m_chromaFormatIDC );
 #endif
       }
@@ -257,9 +388,9 @@
       m_iSourceWidth  += m_aiPad[0];
       m_iSourceHeight += m_aiPad[1];
-      m_confRight  = m_aiPad[0];
-      m_confBottom = m_aiPad[1];
+      m_confWinRight  = m_aiPad[0];
+      m_confWinBottom = m_aiPad[1];
 #if REPN_FORMAT_IN_VPS
-      m_confRight /= TComSPS::getWinUnitX( m_chromaFormatIDC );
-      m_confBottom /= TComSPS::getWinUnitY( m_chromaFormatIDC );
+      m_confWinRight /= TComSPS::getWinUnitX( m_chromaFormatIDC );
+      m_confWinBottom /= TComSPS::getWinUnitY( m_chromaFormatIDC );
 #endif
       break;
@@ -268,5 +399,5 @@
     {
       // conformance
-      if ((m_confLeft == 0) && (m_confRight == 0) && (m_confTop == 0) && (m_confBottom == 0))
+      if ((m_confWinLeft == 0) && (m_confWinRight == 0) && (m_confWinTop == 0) && (m_confWinBottom == 0))
       {
         fprintf(stderr, "Warning: Cropping enabled, but all cropping parameters set to zero\n");
@@ -333,8 +464,8 @@
 #endif
 
-
-  m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + maxCUHeight - 1) / maxCUHeight : 1;
+  m_iWaveFrontSubstreams = m_waveFrontSynchro ? (m_iSourceHeight + maxCUHeight - 1) / maxCUHeight : 1;
+  xConfirmPara( m_waveFrontSynchro < 0, "WaveFrontSynchro cannot be negative" );
   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" );
+  xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_waveFrontSynchro, "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
 
   //chekc parameters
@@ -386,4 +517,35 @@
   }
 #endif
+#if Q0074_COLOUR_REMAPPING_SEI
+  if ( ( m_colourRemapSEIFile.size() > 0 ) && !m_colourRemapSEICancelFlag )
+  {
+    xConfirmPara( m_colourRemapSEIInputBitDepth < 8 || m_colourRemapSEIInputBitDepth > 16 , "colour_remap_input_bit_depth shall be in the range of 8 to 16, inclusive");
+    xConfirmPara( m_colourRemapSEIBitDepth < 8 || m_colourRemapSEIBitDepth > 16, "colour_remap_bit_depth shall be in the range of 8 to 16, inclusive");
+    for( Int c=0 ; c<3 ; c++)
+    {
+      xConfirmPara( m_colourRemapSEIPreLutNumValMinus1[c] < 0 || m_colourRemapSEIPreLutNumValMinus1[c] > 32, "pre_lut_num_val_minus1[c] shall be in the range of 0 to 32, inclusive");
+      if( m_colourRemapSEIPreLutNumValMinus1[c]>0 )
+        for( Int i=0 ; i<=m_colourRemapSEIPreLutNumValMinus1[c] ; i++)
+        {
+          xConfirmPara( m_colourRemapSEIPreLutCodedValue[c][i] < 0 || m_colourRemapSEIPreLutCodedValue[c][i] > ((1<<m_colourRemapSEIInputBitDepth)-1), "pre_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_input_bit_depth)-1, inclusive");
+          xConfirmPara( m_colourRemapSEIPreLutTargetValue[c][i] < 0 || m_colourRemapSEIPreLutTargetValue[c][i] > ((1<<m_colourRemapSEIBitDepth)-1), "pre_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_bit_depth)-1, inclusive");
+        }
+      xConfirmPara( m_colourRemapSEIPostLutNumValMinus1[c] < 0 || m_colourRemapSEIPostLutNumValMinus1[c] > 32, "post_lut_num_val_minus1[c] shall be in the range of 0 to 32, inclusive");
+      if( m_colourRemapSEIPostLutNumValMinus1[c]>0 )
+        for( Int i=0 ; i<=m_colourRemapSEIPostLutNumValMinus1[c] ; i++)
+        { 
+          xConfirmPara( m_colourRemapSEIPostLutCodedValue[c][i] < 0 || m_colourRemapSEIPostLutCodedValue[c][i] > ((1<<m_colourRemapSEIBitDepth)-1), "post_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_bit_depth)-1, inclusive");
+          xConfirmPara( m_colourRemapSEIPostLutTargetValue[c][i] < 0 || m_colourRemapSEIPostLutTargetValue[c][i] > ((1<<m_colourRemapSEIBitDepth)-1), "post_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_bit_depth)-1, inclusive");
+        }
+    }
+    if( m_colourRemapSEIMatrixPresentFlag )
+    {
+      xConfirmPara( m_colourRemapSEILog2MatrixDenom < 0 || m_colourRemapSEILog2MatrixDenom > 15, "log2_matrix_denom shall be in the range of 0 to 15, inclusive");
+      for( Int c=0 ; c<3 ; c++)
+        for( Int i=0 ; i<3 ; i++)
+          xConfirmPara( m_colourRemapSEICoeffs[c][i] < -32768 || m_colourRemapSEICoeffs[c][i] > 32767, "colour_remap_coeffs[c][i] shall be in the range of -32768 and 32767, inclusive");
+    }
+  }
+#endif
 
 #undef xConfirmPara
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 815)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 906)
@@ -35,8 +35,8 @@
   Int       m_iSourceHeightOrg;                               ///< original source height in pixel (when interlaced = frame height)
   Int       m_conformanceMode;
-  Int       m_confLeft;
-  Int       m_confRight;
-  Int       m_confTop;
-  Int       m_confBottom;
+  Int       m_confWinLeft;
+  Int       m_confWinRight;
+  Int       m_confWinTop;
+  Int       m_confWinBottom;
   Int       m_aiPad[2];                                       ///< number of padded pixels for width and height
   Int       m_iIntraPeriod;                                   ///< period of I-slice (random access period)
@@ -54,7 +54,4 @@
   Int       *m_predLayerIds;
   Int       m_numActiveRefLayers;
-#endif
-#if Q0074_SEI_COLOR_MAPPING
-  string    m_cSeiColorMappingFile;
 #endif
 
@@ -84,5 +81,6 @@
 
   Int       m_maxTidIlRefPicsPlus1;
-  Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
+  Int       m_waveFrontSynchro;                   ///< 0: no WPP. >= 1: WPP is enabled, the "Top right" from which inheritance occurs is this LCU offset in the line above the current.
+  Int       m_iWaveFrontSubstreams;               ///< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
 
   Int       m_iQP;                                            ///< QP value of key-picture (integer)
@@ -98,6 +96,21 @@
   Int       m_scaledRefLayerRightOffset [MAX_LAYERS];
   Int       m_scaledRefLayerBottomOffset[MAX_LAYERS];
-#if P0312_VERT_PHASE_ADJ 
+#if REF_REGION_OFFSET
+  Bool      m_scaledRefLayerOffsetPresentFlag [MAX_LAYERS];
+  Bool      m_refRegionOffsetPresentFlag      [MAX_LAYERS];
+  Int       m_refRegionLeftOffset  [MAX_LAYERS];
+  Int       m_refRegionTopOffset   [MAX_LAYERS];
+  Int       m_refRegionRightOffset [MAX_LAYERS];
+  Int       m_refRegionBottomOffset[MAX_LAYERS];
+#endif
+#if P0312_VERT_PHASE_ADJ
   Bool      m_vertPhasePositionEnableFlag[MAX_LAYERS];
+#endif
+#if R0209_GENERIC_PHASE
+  Int       m_phaseHorLuma  [MAX_LAYERS];
+  Int       m_phaseVerLuma  [MAX_LAYERS];
+  Int       m_phaseHorChroma[MAX_LAYERS];
+  Int       m_phaseVerChroma[MAX_LAYERS];
+  Bool      m_resamplePhaseSetPresentFlag [MAX_LAYERS];
 #endif
 
@@ -113,4 +126,27 @@
   Int       m_repFormatIdx;
 #endif
+#if Q0074_COLOUR_REMAPPING_SEI
+  string    m_colourRemapSEIFile;                           ///< Colour Remapping Information SEI message parameters file
+  Int       m_colourRemapSEIId;
+  Bool      m_colourRemapSEICancelFlag;
+  Bool      m_colourRemapSEIPersistenceFlag;
+  Bool      m_colourRemapSEIVideoSignalInfoPresentFlag;
+  Bool      m_colourRemapSEIFullRangeFlag;
+  Int       m_colourRemapSEIPrimaries;
+  Int       m_colourRemapSEITransferFunction;
+  Int       m_colourRemapSEIMatrixCoefficients;
+  Int       m_colourRemapSEIInputBitDepth;
+  Int       m_colourRemapSEIBitDepth;
+  Int       m_colourRemapSEIPreLutNumValMinus1[3];
+  Int*      m_colourRemapSEIPreLutCodedValue[3];
+  Int*      m_colourRemapSEIPreLutTargetValue[3];
+  Bool      m_colourRemapSEIMatrixPresentFlag;
+  Int       m_colourRemapSEILog2MatrixDenom;
+  Int       m_colourRemapSEICoeffs[3][3];
+  Int       m_colourRemapSEIPostLutNumValMinus1[3];
+  Int*      m_colourRemapSEIPostLutCodedValue[3];
+  Int*      m_colourRemapSEIPostLutTargetValue[3];
+#endif
+
 public:
   TAppEncLayerCfg();
@@ -122,9 +158,5 @@
   bool  parseCfg  ( const string& cfgFileName );              ///< parse layer configuration file to fill member variables
 
-#if AVC_SYNTAX
-  Void  xPrintParameter( UInt layerId );
-#else
   Void  xPrintParameter();
-#endif
   Bool  xCheckParameter( Bool isField );
 
@@ -140,8 +172,8 @@
   Int*    getPad()                    {return m_aiPad;            }
   Double  getFloatQP()                {return m_fQP;              }
-  Int     getConfLeft()               {return m_confLeft;         }
-  Int     getConfRight()              {return m_confRight;        }
-  Int     getConfTop()                {return m_confTop;          }
-  Int     getConfBottom()             {return m_confBottom;       }
+  Int     getConfWinLeft()            {return m_confWinLeft;         }
+  Int     getConfWinRight()           {return m_confWinRight;        }
+  Int     getConfWinTop()             {return m_confWinTop;          }
+  Int     getConfWinBottom()          {return m_confWinBottom;       }
 #if AUXILIARY_PICTURES
   ChromaFormat getInputChromaFormat()   {return m_InputChromaFormat;}
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 815)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 906)
@@ -77,4 +77,7 @@
   TComVPS* vps = m_acTEncTop[0].getVPS();
 
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  vps->setVpsPocLsbAlignedFlag(false);
+#endif
   vps->setMaxTLayers                       ( m_maxTempLayer );
   if (m_maxTempLayer == 1)
@@ -181,4 +184,13 @@
     repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC()                        );  // Need modification to change for each layer
 #endif
+
+#if R0156_CONF_WINDOW_IN_REP_FORMAT
+    repFormat->getConformanceWindowVps().setWindow(
+      m_acLayerCfg[mapIdxToLayer[idx]].m_confWinLeft, 
+      m_acLayerCfg[mapIdxToLayer[idx]].m_confWinRight, 
+      m_acLayerCfg[mapIdxToLayer[idx]].m_confWinTop,
+      m_acLayerCfg[mapIdxToLayer[idx]].m_confWinBottom );
+#endif
+
 #if HIGHER_LAYER_IRAP_SKIP_FLAG
     m_acTEncTop[mapIdxToLayer[idx]].setSkipPictureAtArcSwitch( m_skipPictureAtArcSwitch );
@@ -213,6 +225,5 @@
     m_acTEncTop[layer].setSourceWidth                  ( m_acLayerCfg[layer].getSourceWidth() );
     m_acTEncTop[layer].setSourceHeight                 ( m_acLayerCfg[layer].getSourceHeight() );
-    m_acTEncTop[layer].setConformanceMode              ( m_acLayerCfg[layer].getConformanceMode() );
-    m_acTEncTop[layer].setConformanceWindow            ( m_acLayerCfg[layer].m_confLeft, m_acLayerCfg[layer].m_confRight, m_acLayerCfg[layer].m_confTop, m_acLayerCfg[layer].m_confBottom );
+    m_acTEncTop[layer].setConformanceWindow            ( m_acLayerCfg[layer].m_confWinLeft, m_acLayerCfg[layer].m_confWinRight, m_acLayerCfg[layer].m_confWinTop, m_acLayerCfg[layer].m_confWinBottom );
     m_acTEncTop[layer].setFramesToBeEncoded            ( m_framesToBeEncoded );
 
@@ -226,5 +237,9 @@
 #if REF_IDX_MFM
 #if AVC_BASE
-    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_avcBaseLayerFlag ? AVC_SYNTAX : true ) && m_acLayerCfg[layer].getNumMotionPredRefLayers());
+#if VPS_AVC_BL_FLAG_REMOVAL
+    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_nonHEVCBaseLayerFlag ? false : true ) && m_acLayerCfg[layer].getNumMotionPredRefLayers());
+#else
+    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_avcBaseLayerFlag ? false : true ) && m_acLayerCfg[layer].getNumMotionPredRefLayers());
+#endif
 #else
     m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_acLayerCfg[layer].getNumMotionPredRefLayers() > 0 ) );
@@ -352,4 +367,25 @@
         }
       }
+#if REF_REGION_OFFSET
+      for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+      {
+#if AUXILIARY_PICTURES
+        Int cf = m_acLayerCfg[i].m_chromaFormatIDC;
+        Int rlSubWidthC  = ( cf == CHROMA_420 || cf == CHROMA_422 ) ? 2 : 1;
+        Int rlSubHeightC = ( cf == CHROMA_420 ) ? 2 : 1;
+#else
+        Int rlSubWidthC  = 2;
+        Int rlSubHeightC = 2;
+#endif
+        m_acTEncTop[layer].setRefRegionOffsetPresentFlag( i, m_acLayerCfg[layer].m_refRegionOffsetPresentFlag );
+        m_acTEncTop[layer].getRefLayerWindow(i).setWindow( rlSubWidthC  * m_acLayerCfg[layer].m_refRegionLeftOffset[i], rlSubWidthC  * m_acLayerCfg[layer].m_refRegionRightOffset[i],
+                                                           rlSubHeightC * m_acLayerCfg[layer].m_refRegionTopOffset[i],  rlSubHeightC * m_acLayerCfg[layer].m_refRegionBottomOffset[i]);
+      }
+#endif
+    }
+    else
+    {
+      assert( layer == 0 );
+      m_acTEncTop[layer].setNumDirectRefLayers(0);
     }
 #endif //VPS_EXTN_DIRECT_REF_LAYERS
@@ -514,6 +550,25 @@
     m_acTEncTop[layer].setKneeSEIOutputKneePoint                    ( m_kneeSEIOutputKneePoint );
 #endif
-#if Q0074_SEI_COLOR_MAPPING
-    m_acTEncTop[layer].setColorMappingInfoSEIFile                   ( m_acLayerCfg[layer].m_cSeiColorMappingFile.empty() ? NULL : const_cast<Char *>(m_acLayerCfg[layer].m_cSeiColorMappingFile.c_str()) );
+#if Q0074_COLOUR_REMAPPING_SEI
+    m_acTEncTop[layer].setCRISEIFile                                ( const_cast<Char*>(m_acLayerCfg[layer].m_colourRemapSEIFile.c_str()) );
+    m_acTEncTop[layer].setCRISEIId                                  ( m_acLayerCfg[layer].m_colourRemapSEIId );
+    m_acTEncTop[layer].setCRISEICancelFlag                          ( m_acLayerCfg[layer].m_colourRemapSEICancelFlag );
+    m_acTEncTop[layer].setCRISEIPersistenceFlag                     ( m_acLayerCfg[layer].m_colourRemapSEIPersistenceFlag );
+    m_acTEncTop[layer].setCRISEIVideoSignalInfoPresentFlag          ( m_acLayerCfg[layer].m_colourRemapSEIVideoSignalInfoPresentFlag );
+    m_acTEncTop[layer].setCRISEIFullRangeFlag                       ( m_acLayerCfg[layer].m_colourRemapSEIFullRangeFlag );
+    m_acTEncTop[layer].setCRISEIPrimaries                           ( m_acLayerCfg[layer].m_colourRemapSEIPrimaries );
+    m_acTEncTop[layer].setCRISEITransferFunction                    ( m_acLayerCfg[layer].m_colourRemapSEITransferFunction );
+    m_acTEncTop[layer].setCRISEIMatrixCoefficients                  ( m_acLayerCfg[layer].m_colourRemapSEIMatrixCoefficients );
+    m_acTEncTop[layer].setCRISEIInputBitDepth                       ( m_acLayerCfg[layer].m_colourRemapSEIInputBitDepth );
+    m_acTEncTop[layer].setCRISEIBitDepth                            ( m_acLayerCfg[layer].m_colourRemapSEIBitDepth );
+    m_acTEncTop[layer].setCRISEIPreLutNumValMinus1                  ( m_acLayerCfg[layer].m_colourRemapSEIPreLutNumValMinus1 );
+    m_acTEncTop[layer].setCRISEIPreLutCodedValue                    ( m_acLayerCfg[layer].m_colourRemapSEIPreLutCodedValue );
+    m_acTEncTop[layer].setCRISEIPreLutTargetValue                   ( m_acLayerCfg[layer].m_colourRemapSEIPreLutTargetValue );
+    m_acTEncTop[layer].setCRISEIMatrixPresentFlag                   ( m_acLayerCfg[layer].m_colourRemapSEIMatrixPresentFlag );
+    m_acTEncTop[layer].setCRISEILog2MatrixDenom                     ( m_acLayerCfg[layer].m_colourRemapSEILog2MatrixDenom );
+    m_acTEncTop[layer].setCRISEICoeffs                              ( m_acLayerCfg[layer].m_colourRemapSEICoeffs );
+    m_acTEncTop[layer].setCRISEIPostLutNumValMinus1                 ( m_acLayerCfg[layer].m_colourRemapSEIPostLutNumValMinus1 );
+    m_acTEncTop[layer].setCRISEIPostLutCodedValue                   ( m_acLayerCfg[layer]. m_colourRemapSEIPostLutCodedValue );
+    m_acTEncTop[layer].setCRISEIPostLutTargetValue                  ( m_acLayerCfg[layer].m_colourRemapSEIPostLutTargetValue );
 #endif
     m_acTEncTop[layer].setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
@@ -542,14 +597,14 @@
     m_acTEncTop[layer].setIlcIdc( m_ilcIdc );
 #endif
-    m_acTEncTop[layer].setUniformSpacingIdr          ( m_iUniformSpacingIdr );
-    m_acTEncTop[layer].setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
-    m_acTEncTop[layer].setNumRowsMinus1              ( m_iNumRowsMinus1 );
-    if(m_iUniformSpacingIdr==0)
-    {
-      m_acTEncTop[layer].setColumnWidth              ( m_pColumnWidth );
-      m_acTEncTop[layer].setRowHeight                ( m_pRowHeight );
+    m_acTEncTop[layer].setTileUniformSpacingFlag     ( m_tileUniformSpacingFlag );
+    m_acTEncTop[layer].setNumColumnsMinus1           ( m_numTileColumnsMinus1 );
+    m_acTEncTop[layer].setNumRowsMinus1              ( m_numTileRowsMinus1 );
+    if(!m_tileUniformSpacingFlag)
+    {
+      m_acTEncTop[layer].setColumnWidth              ( m_tileColumnWidth );
+      m_acTEncTop[layer].setRowHeight                ( m_tileRowHeight );
     }
     m_acTEncTop[layer].xCheckGSParameters();
-    Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
+    Int uiTilesCount = (m_numTileRowsMinus1+1) * (m_numTileColumnsMinus1+1);
     if(uiTilesCount == 1)
     {
@@ -557,5 +612,5 @@
     }
     m_acTEncTop[layer].setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
-    m_acTEncTop[layer].setWaveFrontSynchro           ( m_iWaveFrontSynchro );
+    m_acTEncTop[layer].setWaveFrontSynchro           ( m_acLayerCfg[layer].m_waveFrontSynchro );
     m_acTEncTop[layer].setWaveFrontSubstreams        ( m_acLayerCfg[layer].m_iWaveFrontSubstreams );
     m_acTEncTop[layer].setTMVPModeId ( m_TMVPModeId );
@@ -586,4 +641,5 @@
     m_acTEncTop[layer].setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
     m_acTEncTop[layer].setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
+    m_acTEncTop[layer].setAspectRatioInfoPresentFlag( m_aspectRatioInfoPresentFlag);
     m_acTEncTop[layer].setAspectRatioIdc( m_aspectRatioIdc );
     m_acTEncTop[layer].setSarWidth( m_sarWidth );
@@ -617,4 +673,14 @@
     if( layer > 0 )
     {
+#if REF_REGION_OFFSET
+#if AUXILIARY_PICTURES
+      Int cf = m_acLayerCfg[layer].m_chromaFormatIDC;
+      Int subWidthC  = ( cf == CHROMA_420 || cf == CHROMA_422 ) ? 2 : 1;
+      Int subHeightC = ( cf == CHROMA_420 ) ? 2 : 1;
+#else
+      Int subWidthC  = 2;
+      Int subHeightC = 2;
+#endif
+#endif
       m_acTEncTop[layer].setNumScaledRefLayerOffsets( m_acLayerCfg[layer].m_numScaledRefLayerOffsets );
       for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
@@ -623,4 +689,9 @@
         m_acTEncTop[layer].setScaledRefLayerId(i, m_acLayerCfg[layer].m_scaledRefLayerId[i]);
 #endif
+#if REF_REGION_OFFSET
+        m_acTEncTop[layer].setScaledRefLayerOffsetPresentFlag( i, m_acLayerCfg[layer].m_scaledRefLayerOffsetPresentFlag[i] );
+        m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( subWidthC  * m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], subWidthC  * m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
+                                                                 subHeightC * m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i],  subHeightC * m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);
+#else
 #if P0312_VERT_PHASE_ADJ
         m_acTEncTop[layer].setVertPhasePositionEnableFlag( i, m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i] );
@@ -630,4 +701,12 @@
         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
+#endif
+#if R0209_GENERIC_PHASE
+        m_acTEncTop[layer].setResamplePhaseSetPresentFlag( i, m_acLayerCfg[layer].m_resamplePhaseSetPresentFlag[i] );
+        m_acTEncTop[layer].setPhaseHorLuma( i, m_acLayerCfg[layer].m_phaseHorLuma[i] );
+        m_acTEncTop[layer].setPhaseVerLuma( i, m_acLayerCfg[layer].m_phaseVerLuma[i] );
+        m_acTEncTop[layer].setPhaseHorChroma( i, m_acLayerCfg[layer].m_phaseHorChroma[i] );
+        m_acTEncTop[layer].setPhaseVerChroma( i, m_acLayerCfg[layer].m_phaseVerChroma[i] );
 #endif
       }
@@ -650,4 +729,10 @@
     m_acTEncTop[layer].setCGSMaxYPartNumLog2( m_nCGSMaxYPartNumLog2 );
     m_acTEncTop[layer].setCGSLUTBit( m_nCGSLUTBit );
+#if R0151_CGS_3D_ASYMLUT_IMPROVE
+    m_acTEncTop[layer].setCGSAdaptChroma( m_nCGSAdaptiveChroma );
+#endif
+#if R0179_ENC_OPT_3DLUT_SIZE
+    m_acTEncTop[layer].setCGSLutSizeRDO( m_nCGSLutSizeRDO );
+#endif
 #endif
 #if Q0078_ADD_LAYER_SETS
@@ -685,5 +770,5 @@
   m_cTEncTop.setSourceWidth                  ( m_iSourceWidth );
   m_cTEncTop.setSourceHeight                 ( m_iSourceHeight );
-  m_cTEncTop.setConformanceWindow            ( m_confLeft, m_confRight, m_confTop, m_confBottom );
+  m_cTEncTop.setConformanceWindow            ( m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom );
   m_cTEncTop.setFramesToBeEncoded            ( m_framesToBeEncoded );
 
@@ -853,6 +938,25 @@
   m_cTEncTop.setKneeSEIOutputKneePoint      ( m_kneeSEIOutputKneePoint );
 #endif
-#if Q0074_SEI_COLOR_MAPPING
-  m_cTEncTop.setColorMappingInfoSEIFile                   ( m_pchSEIColorMappingFile );
+#if Q0074_COLOUR_REMAPPING_SEI
+  m_cTEncTop.setCRISEIFile                       ( const_cast<Char*>(m_colourRemapSEIFile.c_str()) );
+  m_cTEncTop.setCRISEIId                         ( m_colourRemapSEIId );
+  m_cTEncTop.setCRISEICancelFlag                 ( m_colourRemapSEICancelFlag );
+  m_cTEncTop.setCRISEIPersistenceFlag            ( m_colourRemapSEIPersistenceFlag );
+  m_cTEncTop.setCRISEIVideoSignalInfoPresentFlag ( m_colourRemapSEIVideoSignalInfoPresentFlag );
+  m_cTEncTop.setCRISEIFullRangeFlag              ( m_colourRemapSEIFullRangeFlag );
+  m_cTEncTop.setCRISEIPrimaries                  ( m_colourRemapSEIPrimaries );
+  m_cTEncTop.setCRISEITransferFunction           ( m_colourRemapSEITransferFunction );
+  m_cTEncTop.setCRISEIMatrixCoefficients         ( m_colourRemapSEIMatrixCoefficients );
+  m_cTEncTop.setCRISEIInputBitDepth              ( m_colourRemapSEIInputBitDepth );
+  m_cTEncTop.setCRISEIBitDepth                   ( m_colourRemapSEIBitDepth );
+  m_cTEncTop.setCRISEIPreLutNumValMinus1         ( m_colourRemapSEIPreLutNumValMinus1 );
+  m_cTEncTop.setCRISEIPreLutCodedValue           ( m_colourRemapSEIPreLutCodedValue );
+  m_cTEncTop.setCRISEIPreLutTargetValue          ( m_colourRemapSEIPreLutTargetValue );
+  m_cTEncTop.setCRISEIMatrixPresentFlag          ( m_colourRemapSEIMatrixPresentFlag );
+  m_cTEncTop.setCRISEILog2MatrixDenom            ( m_colourRemapSEILog2MatrixDenom );
+  m_cTEncTop.setCRISEICoeffs                     ( m_colourRemapSEICoeffs );
+  m_cTEncTop.setCRISEIPostLutNumValMinus1        ( m_colourRemapSEIPostLutNumValMinus1 );
+  m_cTEncTop.setCRISEIPostLutCodedValue          ( m_colourRemapSEIPostLutCodedValue );
+  m_cTEncTop.setCRISEIPostLutTargetValue         ( m_colourRemapSEIPostLutTargetValue );
 #endif
   m_cTEncTop.setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
@@ -870,14 +974,14 @@
   m_cTEncTop.setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
   m_cTEncTop.setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled );
-  m_cTEncTop.setUniformSpacingIdr          ( m_iUniformSpacingIdr );
-  m_cTEncTop.setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
-  m_cTEncTop.setNumRowsMinus1              ( m_iNumRowsMinus1 );
-  if(m_iUniformSpacingIdr==0)
-  {
-    m_cTEncTop.setColumnWidth              ( m_pColumnWidth );
-    m_cTEncTop.setRowHeight                ( m_pRowHeight );
+  m_cTEncTop.setTileUniformSpacingFlag     ( m_tileUniformSpacingFlag );
+  m_cTEncTop.setNumColumnsMinus1           ( m_numTileColumnsMinus1 );
+  m_cTEncTop.setNumRowsMinus1              ( m_numTileRowsMinus1 );
+  if(!m_tileUniformSpacingFlag)
+  {
+    m_cTEncTop.setColumnWidth              ( m_tileColumnWidth );
+    m_cTEncTop.setRowHeight                ( m_tileRowHeight );
   }
   m_cTEncTop.xCheckGSParameters();
-  Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
+  Int uiTilesCount          = (m_numTileRowsMinus1+1) * (m_numTileColumnsMinus1+1);
   if(uiTilesCount == 1)
   {
@@ -904,4 +1008,5 @@
   m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
   m_cTEncTop.setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
+  m_cTEncTop.setAspectRatioInfoPresentFlag( m_aspectRatioInfoPresentFlag);
   m_cTEncTop.setAspectRatioIdc( m_aspectRatioIdc );
   m_cTEncTop.setSarWidth( m_sarWidth );
@@ -1056,7 +1161,13 @@
 
 #if Q0078_ADD_LAYER_SETS
+#if OUTPUT_LAYER_SETS_CONFIG
+  if (m_numLayerSets > 1)
+  {
+    vps->setNumLayerSets(m_numLayerSets);
+#else
   if (m_numLayerSets > 0)
   {
     vps->setNumLayerSets(m_numLayerSets+1);
+#endif
     for (Int setId = 1; setId < vps->getNumLayerSets(); setId++)
     {
@@ -1068,8 +1179,13 @@
     for (Int setId = 1; setId < vps->getNumLayerSets(); setId++)
     {
+#if OUTPUT_LAYER_SETS_CONFIG
+      for (Int i = 0; i < m_numLayerInIdList[setId]; i++)
+      {
+        Int layerId = m_layerSetLayerIdList[setId][i];
+#else
       for (Int i = 0; i < m_numLayerInIdList[setId-1]; i++)
       {
         Int layerId = m_layerSetLayerIdList[setId-1][i];
-
+#endif
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
         //4
@@ -1133,5 +1249,13 @@
   UInt i = 0, dimIdLen = 0;
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+  vps->setNonHEVCBaseLayerFlag( m_nonHEVCBaseLayerFlag );
+  if ( m_nonHEVCBaseLayerFlag )
+  {
+    vps->setBaseLayerInternalFlag (false);
+  }
+#else
   vps->setAvcBaseLayerFlag(m_avcBaseLayerFlag);
+#endif
 #else
   vps->setAvcBaseLayerFlag(false);
@@ -1200,10 +1324,10 @@
 #endif
 #if VPS_TSLAYERS
-    vps->setMaxTSLayersPresentFlag(true);
-
-    for( i = 0; i < vps->getMaxLayers(); i++ )
-    {
-      vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
-    }
+  vps->setMaxTSLayersPresentFlag(true);
+
+  for( i = 0; i < vps->getMaxLayers(); i++ )
+  {
+    vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
+  }
 #endif
   vps->setMaxTidRefPresentFlag(m_maxTidRefPresentFlag);
@@ -1238,4 +1362,26 @@
     vps->setIlpSshSignalingEnabledFlag(false);
 #if VPS_EXTN_PROFILE_INFO
+
+#if LIST_OF_PTL
+  vps->getPTLForExtnPtr()->resize(1);   // Dummy object - unused.
+  for(i = 0; i < vps->getMaxLayers(); i++)
+  {
+    // TODO: The profile tier level have to be given support to be included in the configuration files
+    if(i == 0)
+    {
+      if( vps->getBaseLayerInternalFlag() && vps->getMaxLayers() > 1 )
+      {
+        vps->setProfilePresentFlag(1, false);
+        vps->getPTLForExtnPtr()->push_back( *(m_acTEncTop[0].getSPS()->getPTL()) );
+      }
+    }
+    else  // i > 0
+    {
+      vps->setProfilePresentFlag(i, true);
+      // Note - may need to be changed for other layer structures.
+      vps->getPTLForExtnPtr()->push_back( *(m_acTEncTop[0].getSPS()->getPTL()) );
+    }
+  }
+#else
   vps->getPTLForExtnPtr()->resize(vps->getNumLayerSets());
   for(Int setId = 1; setId < vps->getNumLayerSets(); setId++)
@@ -1245,4 +1391,5 @@
     *(vps->getPTLForExtn(setId)) = *(m_acTEncTop[setId].getSPS()->getPTL());
   }
+#endif
 #endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
@@ -1317,7 +1464,38 @@
 #endif
 #endif
+#if OUTPUT_LAYER_SETS_CONFIG
+
+  vps->setDefaultTargetOutputLayerIdc( m_defaultTargetOutputLayerIdc ); // As per configuration file
+
+  if( m_numOutputLayerSets == -1 )  // # of output layer sets not specified in the configuration file
+  {
+    vps->setNumOutputLayerSets(vps->getNumLayerSets());
+
+    for(i = 1; i < vps->getNumLayerSets(); i++)
+    {
+        vps->setOutputLayerSetIdx(i, i);
+    }
+  }
+  else
+  {
+    vps->setNumOutputLayerSets( m_numOutputLayerSets );
+    for( Int olsCtr = 0; olsCtr < vps->getNumLayerSets(); olsCtr ++ ) // Default output layer sets
+    {
+      vps->setOutputLayerSetIdx(olsCtr, olsCtr);
+    }
+    for( Int olsCtr = vps->getNumLayerSets(); olsCtr < vps->getNumOutputLayerSets(); olsCtr ++ )  // Non-default output layer sets
+    {
+      vps->setOutputLayerSetIdx(olsCtr, m_outputLayerSetIdx[olsCtr - vps->getNumLayerSets()]);
+    }
+  }
+#endif
   // Target output layer
+#if LIST_OF_PTL
+  vps->setNumProfileTierLevel( vps->getPTLForExtnPtr()->size() ); // +1 for the base VPS PTL()
+#else
   vps->setNumOutputLayerSets(vps->getNumLayerSets());
   vps->setNumProfileTierLevel(vps->getNumLayerSets());
+#endif
+#if !OUTPUT_LAYER_SETS_CONFIG // Taken care by configuration file parameter
 #if P0295_DEFAULT_OUT_LAYER_IDC
   vps->setDefaultTargetOutputLayerIdc(1);
@@ -1329,9 +1507,14 @@
 #endif
 #endif
+#endif
+#if !PER_LAYER_PTL
   for(i = 1; i < vps->getNumLayerSets(); i++)
   {
     vps->setProfileLevelTierIdx(i, i);
+#if !OUTPUT_LAYER_SETS_CONFIG
     vps->setOutputLayerSetIdx(i, i);
+#endif
   }  
+#endif
 #endif
  #if VPS_DPB_SIZE_TABLE
@@ -1347,5 +1530,7 @@
 
   // derive OutputLayerFlag[i][j] 
+#if !OUTPUT_LAYER_SETS_CONFIG
   if( vps->getDefaultTargetOutputLayerIdc() == 1 )
+#endif
   {
     // default_output_layer_idc equal to 1 specifies that only the layer with the highest value of nuh_layer_id such that nuh_layer_id equal to nuhLayerIdA and 
@@ -1360,10 +1545,33 @@
         if( vps->getLayerIdIncludedFlag(lsIdx, layer) )      
 #endif
-        {        
+        {
+#if OUTPUT_LAYER_SETS_CONFIG
+          switch(vps->getDefaultTargetOutputLayerIdc())
+          {
+            case 0: vps->setOutputLayerFlag( lsIdx, layer, 1 );
+              break;
+            case 1: vps->setOutputLayerFlag( lsIdx, layer, layer == vps->getNumLayersInIdList(lsIdx) - 1 );
+              break;
+            case 2:
+            case 3: vps->setOutputLayerFlag( lsIdx, layer, std::find( m_listOfOutputLayers[lsIdx].begin(), m_listOfOutputLayers[lsIdx].end(), layer) != m_listOfOutputLayers[lsIdx].end() );
+              break;
+          }
+#else
           vps->setOutputLayerFlag( lsIdx, layer, layer == vps->getNumLayersInIdList(lsIdx) - 1 );
+#endif
         }
       }
     }
-  }
+#if OUTPUT_LAYER_SETS_CONFIG
+    for( Int olsIdx = vps->getNumLayerSets(); olsIdx < vps->getNumOutputLayerSets(); olsIdx++ )
+    {
+      for( UInt layer = 0; layer < vps->getNumLayersInIdList(vps->getOutputLayerSetIdx(olsIdx)); layer++ )
+      {
+        vps->setOutputLayerFlag( olsIdx, layer, std::find( m_listOfOutputLayers[olsIdx].begin(), m_listOfOutputLayers[olsIdx].end(), layer) != m_listOfOutputLayers[olsIdx].end());
+      }
+    }
+#endif
+  }
+#if !OUTPUT_LAYER_SETS_CONFIG
   else
   {
@@ -1371,5 +1579,33 @@
     assert(!"default_output_layer_idc not equal to 1 is not yet supported");
   }
-
+#endif
+#if NECESSARY_LAYER_FLAG
+  vps->deriveNecessaryLayerFlag();
+  vps->checkNecessaryLayerFlagCondition();
+#endif
+#if PER_LAYER_PTL
+  vps->getProfileLevelTierIdx()->resize(vps->getNumOutputLayerSets());
+  vps->getProfileLevelTierIdx(0)->push_back( vps->getBaseLayerInternalFlag() && vps->getMaxLayers() > 1 ? 1 : 0 ); // Default 0-th output layer set
+  for(i = 1; i < vps->getNumOutputLayerSets(); i++)
+  {
+    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
+    Int numLayerInLayerSet = vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet );
+    for(Int j = 0; j < numLayerInLayerSet; j++)
+    {
+      Int layerIdxInVps = vps->getLayerIdInVps( vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, j) );
+      if( vps->getNecessaryLayerFlag(i, j) )
+      {
+        vps->getProfileLevelTierIdx(i)->push_back( vps->getBaseLayerInternalFlag() && vps->getMaxLayers() > 1 ? layerIdxInVps + 1 : layerIdxInVps);
+      }
+      else
+      {
+        vps->getProfileLevelTierIdx(i)->push_back( -1 );
+      }
+    }
+  }
+#endif
+#if SUB_LAYERS_IN_LAYER_SET
+  vps->calculateMaxSLInLayerSets();
+#endif
   // Initialize dpb_size_table() for all ouput layer sets in the VPS extension
   for(i = 1; i < vps->getNumOutputLayerSets(); i++)
@@ -1501,4 +1737,84 @@
 #endif
 
+#if VPS_VUI_BSP_HRD_PARAMS
+  vps->setVpsVuiBspHrdPresentFlag(false);
+  TEncTop *pcCfg = &m_acTEncTop[0];
+  if( pcCfg->getBufferingPeriodSEIEnabled() )
+  {
+    Int j;
+    vps->setVpsVuiBspHrdPresentFlag(true);
+    vps->setVpsNumAddHrdParams( vps->getMaxLayers() );
+    vps->createBspHrdParamBuffer(vps->getVpsNumAddHrdParams() + 1);
+    for( i = vps->getNumHrdParameters(), j = 0; i < vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams(); i++, j++ )
+    {
+      vps->setCprmsAddPresentFlag( j, true );
+      vps->setNumSubLayerHrdMinus1( j, vps->getMaxTLayers() - 1 );
+
+      UInt layerId = j;
+      TEncTop *pcCfgLayer = &m_acTEncTop[layerId];
+
+      Int iPicWidth         = pcCfgLayer->getSourceWidth();
+      Int iPicHeight        = pcCfgLayer->getSourceHeight();
+#if LAYER_CTB
+      UInt uiWidthInCU       = ( iPicWidth  % m_acLayerCfg[layerId].m_uiMaxCUWidth  ) ? iPicWidth  / m_acLayerCfg[layerId].m_uiMaxCUWidth  + 1 : iPicWidth  / m_acLayerCfg[layerId].m_uiMaxCUWidth;
+      UInt uiHeightInCU      = ( iPicHeight % m_acLayerCfg[layerId].m_uiMaxCUHeight ) ? iPicHeight / m_acLayerCfg[layerId].m_uiMaxCUHeight + 1 : iPicHeight / m_acLayerCfg[layerId].m_uiMaxCUHeight;
+      UInt maxCU = pcCfgLayer->getSliceArgument() >> ( m_acLayerCfg[layerId].m_uiMaxCUDepth << 1);
+#else
+      UInt uiWidthInCU       = ( iPicWidth %m_uiMaxCUWidth  ) ? iPicWidth /m_uiMaxCUWidth  + 1 : iPicWidth /m_uiMaxCUWidth;
+      UInt uiHeightInCU      = ( iPicHeight%m_uiMaxCUHeight ) ? iPicHeight/m_uiMaxCUHeight + 1 : iPicHeight/m_uiMaxCUHeight;
+      UInt maxCU = pcCfgLayer->getSliceArgument() >> ( m_uiMaxCUDepth << 1);
+#endif
+      UInt uiNumCUsInFrame   = uiWidthInCU * uiHeightInCU;
+
+      UInt numDU = ( pcCfgLayer->getSliceMode() == 1 ) ? ( uiNumCUsInFrame / maxCU ) : ( 0 );
+      if( uiNumCUsInFrame % maxCU != 0 || numDU == 0 )
+      {
+        numDU ++;
+      }
+      vps->getBspHrd(i)->setNumDU( numDU );
+      vps->setBspHrdParameters( i, pcCfgLayer->getFrameRate(), numDU, pcCfgLayer->getTargetBitrate(), ( pcCfgLayer->getIntraPeriod() > 0 ) );
+    }
+
+    // Signalling of additional partitioning schemes
+    for(Int h = 1; h < vps->getNumOutputLayerSets(); h++)
+    {
+      Int lsIdx = vps->getOutputLayerSetIdx( h );
+      vps->setNumSignalledPartitioningSchemes(h, 1);  // Only the default per-layer partitioning scheme
+      for( j = 1; j < vps->getNumSignalledPartitioningSchemes(h); j++ )
+      {
+        // ToDo: Add code for additional partitioning schemes here
+        // ToDo: Initialize num_partitions_in_scheme_minus1 and layer_included_in_partition_flag
+      }
+
+      for( i = 0; i < vps->getNumSignalledPartitioningSchemes(h); i++ )
+      {
+        if( i == 0 )
+        {
+          for(Int t = 0; t <= vps->getMaxSLayersInLayerSetMinus1( lsIdx ); t++)
+          {
+            vps->setNumBspSchedulesMinus1( h, i, t, 0 );
+            for( j = 0; j <= vps->getNumBspSchedulesMinus1(h, i, t); j++ )
+            {
+              for( Int k = 0; k <= vps->getNumPartitionsInSchemeMinus1(h, i); k++ )
+              {
+                // Only for the default partition
+                Int nuhlayerId = vps->getLayerSetLayerIdList( lsIdx, k);
+                Int layerIdxInVps = vps->getLayerIdInVps( nuhlayerId );
+                vps->setBspHrdIdx(h, i, t, j, k, layerIdxInVps + vps->getNumHrdParameters());
+
+                vps->setBspSchedIdx(h, i, t, j, k, 0);
+              }
+            }
+          }
+        }
+        else
+        {
+          assert(0);    // Need to add support for additional partitioning schemes.
+        }
+      }
+    }
+  }
+#else
+
 #if O0164_MULTI_LAYER_HRD
   vps->setVpsVuiBspHrdPresentFlag(false);
@@ -1572,4 +1888,5 @@
     }
   }
+#endif
 #endif
 
@@ -1669,23 +1986,4 @@
   }
 
-#if AVC_SYNTAX
-  fstream streamSyntaxFile;
-  if( m_acTEncTop[0].getVPS()->getAvcBaseLayerFlag() )
-  {
-    if( !m_BLSyntaxFile )
-    {
-      printf( "Wrong base layer syntax input file\n" );
-      exit(EXIT_FAILURE);
-    }
-    streamSyntaxFile.open( m_BLSyntaxFile, fstream::in | fstream::binary );
-    if( !streamSyntaxFile.good() )
-    {
-      printf( "Base layer syntax input reading error\n" );
-      exit(EXIT_FAILURE);
-    }
-    m_acTEncTop[0].setBLSyntaxFile( &streamSyntaxFile );
-  }
-#endif
-
   Bool bFirstFrame = true;
   while ( !bEos )
@@ -1816,4 +2114,31 @@
       }
     }
+#if R0247_SEI_ACTIVE
+    if(bFirstFrame)
+    {
+      list<AccessUnit>::iterator first_au = outputAccessUnits.begin();
+      AccessUnit::iterator it_sps;
+      for (it_sps = first_au->begin(); it_sps != first_au->end(); it_sps++)
+      {
+        if( (*it_sps)->m_nalUnitType == NAL_UNIT_SPS )
+        {
+          break;
+        }
+      }
+
+      for (list<AccessUnit>::iterator it_au = ++outputAccessUnits.begin(); it_au != outputAccessUnits.end(); it_au++)
+      {
+        for (AccessUnit::iterator it_nalu = it_au->begin(); it_nalu != it_au->end(); it_nalu++)
+        {
+          if( (*it_nalu)->m_nalUnitType == NAL_UNIT_SPS )
+          {
+            first_au->insert(++it_sps, *it_nalu);
+            it_nalu = it_au->erase(it_nalu);
+          }
+        }
+      }
+    }
+
+#endif
 
 #if RC_SHVC_HARMONIZATION
@@ -1858,5 +2183,9 @@
 
         AccessUnit& accessUnit = outputAccessUnits.back();
+#if T_ID_EOB_BUG_FIX
+        nalu.m_temporalId = 0;
+#else
         nalu.m_temporalId = accessUnit.front()->m_temporalId;
+#endif
         accessUnit.push_back(new NALUnitEBSP(nalu));
       }
@@ -1884,11 +2213,4 @@
     m_acTEncTop[layer].deletePicBuffer();
   }
-
-#if AVC_SYNTAX
-  if( streamSyntaxFile.is_open() )
-  {
-    streamSyntaxFile.close();
-  }
-#endif
 
   // delete buffers & classes
@@ -2154,8 +2476,8 @@
       {
 #if REPN_FORMAT_IN_VPS
-        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, m_acLayerCfg[layer].getConfLeft() * xScal, m_acLayerCfg[layer].getConfRight() * xScal, 
-          m_acLayerCfg[layer].getConfTop() * yScal, m_acLayerCfg[layer].getConfBottom() * yScal, m_isTopFieldFirst );
-#else
-        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom(), m_isTopFieldFirst );
+        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, m_acLayerCfg[layer].getConfWinLeft() * xScal, m_acLayerCfg[layer].getConfWinRight() * xScal, 
+          m_acLayerCfg[layer].getConfWinTop() * yScal, m_acLayerCfg[layer].getConfWinBottom() * yScal, m_isTopFieldFirst );
+#else
+        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, m_acLayerCfg[layer].getConfWinLeft(), m_acLayerCfg[layer].getConfWinRight(), m_acLayerCfg[layer].getConfWinTop(), m_acLayerCfg[layer].getConfWinBottom(), m_isTopFieldFirst );
 #endif
       }
@@ -2183,9 +2505,9 @@
       {
 #if REPN_FORMAT_IN_VPS
-        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft() * xScal, m_acLayerCfg[layer].getConfRight() * xScal,
-          m_acLayerCfg[layer].getConfTop() * yScal, m_acLayerCfg[layer].getConfBottom() * yScal );
-#else
-        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(),
-          m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
+        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfWinLeft() * xScal, m_acLayerCfg[layer].getConfWinRight() * xScal,
+          m_acLayerCfg[layer].getConfWinTop() * yScal, m_acLayerCfg[layer].getConfWinBottom() * yScal );
+#else
+        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfWinLeft(), m_acLayerCfg[layer].getConfWinRight(),
+          m_acLayerCfg[layer].getConfWinTop(), m_acLayerCfg[layer].getConfWinBottom() );
 #endif
       }
@@ -2295,5 +2617,5 @@
       if (m_pchReconFile)
       {
-        m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst );
+        m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, m_isTopFieldFirst );
       }
 
@@ -2310,5 +2632,4 @@
   {
     Int i;
-
     TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
     list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
@@ -2324,7 +2645,5 @@
       if (m_pchReconFile)
       {
-#if SYNTAX_OUTPUT
-        m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
-#endif
+        m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom );
       }
 
