Index: trunk/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 815)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 906)
@@ -78,7 +78,5 @@
   string cfg_ReconFile;
 #endif
-#if AVC_SYNTAX || SYNTAX_OUTPUT
-  string cfg_BLSyntaxFile;
-#endif
+
   string cfg_TargetDecLayerIdSetFile;
 
@@ -96,17 +94,8 @@
   ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
 #endif
-#if AVC_SYNTAX
-  ("BLSyntaxFile,-ibs",    cfg_BLSyntaxFile,  string(""), "BL syntax input file name")  
-#endif
 #endif
 #else
   ("ReconFile,o",     cfg_ReconFile,     string(""), "reconstructed YUV output file name\n"
                                                      "YUV writing is skipped if omitted")
-#endif
-#if SYNTAX_OUTPUT
-  ("BLSyntaxFile,-ibs",    cfg_BLSyntaxFile,  string(""), "BL syntax input file name")
-  ("BLSourceWidth,-wdt",    m_iBLSourceWidth,        0, "BL source picture width")
-  ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
-  ("BLFrames,-fr",          m_iBLFrames,       0, "BL number of frames")
 #endif
   ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access")
@@ -126,4 +115,9 @@
   ("TarDecLayerIdSetFile,l", cfg_TargetDecLayerIdSetFile, string(""), "targetDecLayerIdSet file name. The file should include white space separated LayerId values to be decoded. Omitting the option or a value of -1 in the file decodes all layers.")
   ("RespectDefDispWindow,w", m_respectDefDispWindow, 0, "Only output content inside the default display window\n")
+#if Q0074_COLOUR_REMAPPING_SEI
+  ("SEIColourRemappingInfo", m_colourRemapSEIEnabled, false, "Control handling of Colour Remapping Information SEI messages\n"
+                                              "\t1: apply colour remapping on decoded pictures if available in the bitstream\n"
+                                              "\t0: ignore SEI message")
+#endif
   ;
   po::setDefaults(opts);
@@ -163,7 +157,4 @@
 #else
   m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
-#endif
-#if AVC_SYNTAX || SYNTAX_OUTPUT
-  m_pchBLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
 #endif
 
Index: trunk/source/App/TAppDecoder/TAppDecCfg.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.h	(revision 815)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.h	(revision 906)
@@ -69,4 +69,7 @@
   Int           m_iMaxTemporalLayer;                  ///< maximum temporal layer to be decoded
   Int           m_decodedPictureHashSEIEnabled;       ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
+#if Q0074_COLOUR_REMAPPING_SEI
+  Bool          m_colourRemapSEIEnabled;              ///< Enable the Colour Remapping Information SEI message if available (remapping decoded pictures)
+#endif
 
 #if SVC_EXTENSION
@@ -78,17 +81,5 @@
   Int           m_iBLSourceHeight;
 #endif
-#if AVC_SYNTAX
-  Char*         m_pchBLSyntaxFile;                     ///< input BL syntax file name  
 #endif
-#endif
-#endif
-
-#if SYNTAX_OUTPUT
-  Char*         m_pchBLSyntaxFile;                     ///< input BL syntax file name
-#if !REPN_FORMAT_IN_VPS
-  Int           m_iBLSourceWidth;
-  Int           m_iBLSourceHeight;
-#endif
-  Int           m_iBLFrames;
 #endif
 
@@ -110,4 +101,7 @@
   , m_iMaxTemporalLayer(-1)
   , m_decodedPictureHashSEIEnabled(0)
+#if Q0074_COLOUR_REMAPPING_SEI
+  , m_colourRemapSEIEnabled(0)
+#endif
 #if SVC_EXTENSION
   , m_tgtLayerId(0)
@@ -115,9 +109,4 @@
   , m_iBLSourceWidth(0)
   , m_iBLSourceHeight(0)
-#endif
-#if SYNTAX_OUTPUT
-  , m_iBLSourceWidth(0)
-  , m_iBLSourceHeight(0)
-  , m_iBLFrames(0)
 #endif
 #endif
Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 815)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 906)
@@ -102,11 +102,4 @@
   }
 #endif
-#if AVC_SYNTAX || SYNTAX_OUTPUT
-  if( m_pchBLSyntaxFile )
-  {
-    free ( m_pchBLSyntaxFile );
-    m_pchBLSyntaxFile = NULL;
-  }
-#endif
 }
 
@@ -163,18 +156,7 @@
   }
   TComList<TComPic*> *cListPic = m_acTDecTop[0].getListPic();
-#if AVC_SYNTAX || !REPN_FORMAT_IN_VPS
-  m_acTDecTop[0].setBLsize( m_iBLSourceWidth, m_iBLSourceHeight );
-#endif
   m_acTDecTop[0].setBLReconFile( &streamYUV );
   pcBLPic.setLayerId( 0 );
   cListPic->pushBack( &pcBLPic );
-#if AVC_SYNTAX
-  fstream streamSyntaxFile;
-  if( m_pchBLSyntaxFile )
-  {
-    streamSyntaxFile.open( m_pchBLSyntaxFile, fstream::in | fstream::binary );
-  }
-  m_acTDecTop[0].setBLSyntaxFile( &streamSyntaxFile );
-#endif
 #endif
 
@@ -363,10 +345,4 @@
     streamYUV.close();
   }
-#if AVC_SYNTAX
-  if( streamSyntaxFile.is_open() )
-  {
-    streamSyntaxFile.close();
-  }
-#endif
   pcBLPic.destroy();
 
@@ -405,25 +381,4 @@
   Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
   Bool loopFiltered = false;
-
-#if SYNTAX_OUTPUT
-  if( !m_pchBLSyntaxFile )
-  {
-    printf( "Wrong base layer syntax file\n" );
-    exit(EXIT_FAILURE);
-  }
-  fstream streamSyntaxFile( m_pchBLSyntaxFile, fstream::out | fstream::binary );
-  if( !streamSyntaxFile.good() )
-  {
-    printf( "Base layer syntax input reading error\n" );
-    exit(EXIT_FAILURE);
-  }
-  m_cTDecTop.setBLSyntaxFile( &streamSyntaxFile );
-
-  for( Int i = m_iBLFrames * m_iBLSourceWidth * m_iBLSourceHeight * SYNTAX_BYTES / 16; i >= 0; i-- )
-  {
-    streamSyntaxFile.put( 0 );
-  }
-  streamSyntaxFile.seekp( 0 );
-#endif
 
   while (!!bitstreamFile)
@@ -543,11 +498,4 @@
   }
 
-#if SYNTAX_OUTPUT
-  if( streamSyntaxFile.is_open() )
-  {
-    streamSyntaxFile.close();
-  }
-#endif
-
   xFlushOutput( pcListPic );
   // delete buffers
@@ -620,4 +568,7 @@
     m_acTDecTop[layer].init();
     m_acTDecTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
+#if Q0074_COLOUR_REMAPPING_SEI
+    m_acTDecTop[layer].setColourRemappingInfoSEIEnabled(m_colourRemapSEIEnabled);
+#endif
     m_acTDecTop[layer].setNumLayer( m_tgtLayerId + 1 );
 #if OUTPUT_LAYER_SET_INDEX
@@ -625,8 +576,10 @@
 #endif
   }
-
 #else
   m_cTDecTop.init();
   m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
+#if Q0074_COLOUR_REMAPPING_SEI
+  m_cTDecTop.setColourRemappingInfoSEIEnabled(m_colourRemapSEIEnabled);
+#endif
 #endif
 }
@@ -727,11 +680,4 @@
           TComPicYuv* pPicCYuvRecTop = pcPicTop->getPicYuvRec();
           TComPicYuv* pPicCYuvRecBot = pcPicBottom->getPicYuvRec();
-#if Q0074_SEI_COLOR_MAPPING
-          if( m_acTDecTop[layerId].m_ColorMapping->getColorMappingFlag() )
-          {
-            pPicCYuvRecTop = m_acTDecTop[layerId].m_ColorMapping->getColorMapping( pPicCYuvRecTop, 0, layerId );
-            pPicCYuvRecBot = m_acTDecTop[layerId].m_ColorMapping->getColorMapping( pPicCYuvRecBot, 1, layerId );
-          }
-#endif
 #if REPN_FORMAT_IN_VPS
           UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
@@ -762,11 +708,4 @@
           TComPicYuv* pPicCYuvRecTop = pcPicTop->getPicYuvRec();
           TComPicYuv* pPicCYuvRecBot = pcPicBottom->getPicYuvRec();
-#if Q0074_SEI_COLOR_MAPPING
-          if ( m_cTDecTop.m_ColorMapping->getColorMappingFlag() )
-          {
-            pPicCYuvRecTop = m_cTDecTop.m_ColorMapping->getColorMapping( pPicCYuvRecTop, 0 );
-            pPicCYuvRecBot = m_cTDecTop.m_ColorMapping->getColorMapping( pPicCYuvRecBot, 1 );
-          }
-#endif
           m_cTVideoIOYuvReconFile.write( pPicCYuvRecTop, pPicCYuvRecBot,
             conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
@@ -843,11 +782,4 @@
           const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
           TComPicYuv* pPicCYuvRec = pcPic->getPicYuvRec();
-#if Q0074_SEI_COLOR_MAPPING
-          if ( m_acTDecTop[layerId].m_ColorMapping->getColorMappingFlag() )
-          {
-            pPicCYuvRec = m_acTDecTop[layerId].m_ColorMapping->getColorMapping( pPicCYuvRec, 0, layerId );
-          }
-#endif
-
 #if REPN_FORMAT_IN_VPS
           UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
@@ -873,20 +805,11 @@
         if ( m_pchReconFile )
         {
-#if SYNTAX_OUTPUT
-          TComPicYuv* pPicCYuvRec = pcPic->getPicYuvRec();
-#if Q0074_SEI_COLOR_MAPPING
-          if( m_acTDecTop[layerIdx].m_ColorMapping->getColorMappingFlag() )
-          {
-            pPicCYuvRec = m_acTDecTop[layerIdx].m_ColorMapping->getColorMapping( pPicCYuvRec, 0, layerIdx );
-          }
-#endif
           const Window &conf = pcPic->getConformanceWindow();
           const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-          m_cTVideoIOYuvReconFile.write( pPicCYuvRec,
-            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
-#endif
+          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
+                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
         }
 
@@ -959,11 +882,4 @@
           TComPicYuv* pPicCYuvRecTop = pcPicTop->getPicYuvRec();
           TComPicYuv* pPicCYuvRecBot = pcPicBottom->getPicYuvRec();
-#if Q0074_SEI_COLOR_MAPPING
-          if( m_acTDecTop[layerId].m_ColorMapping->getColorMappingFlag() )
-          {
-            pPicCYuvRecTop = m_acTDecTop[layerId].m_ColorMapping->getColorMapping( pPicCYuvRecTop, 0, layerId );
-            pPicCYuvRecBot = m_acTDecTop[layerId].m_ColorMapping->getColorMapping( pPicCYuvRecBot, 1, layerId );
-          }
-#endif
 #if REPN_FORMAT_IN_VPS
           UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
@@ -994,11 +910,4 @@
           TComPicYuv* pPicCYuvRecTop = pcPicTop->getPicYuvRec();
           TComPicYuv* pPicCYuvRecBot = pcPicBottom->getPicYuvRec();
-#if Q0074_SEI_COLOR_MAPPING
-          if( m_cTDecTop.m_ColorMapping->getColorMappingFlag() )
-          {
-            pPicCYuvRecTop = m_cTDecTop.m_ColorMapping->getColorMapping( pPicCYuvRecTop, 0 );
-            pPicCYuvRecBot = m_cTDecTop.m_ColorMapping->getColorMapping( pPicCYuvRecBot, 1 );
-          }
-#endif
           m_cTVideoIOYuvReconFile.write( pPicCYuvRecTop, pPicCYuvRecBot,
             conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
@@ -1078,10 +987,4 @@
           const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
           TComPicYuv* pPicCYuvRec = pcPic->getPicYuvRec();
-#if Q0074_SEI_COLOR_MAPPING
-          if( m_acTDecTop[layerId].m_ColorMapping->getColorMappingFlag() )
-          {
-            pPicCYuvRec = m_acTDecTop[layerId].m_ColorMapping->getColorMapping( pPicCYuvRec, 0, layerId );
-          }
-#endif
 #if REPN_FORMAT_IN_VPS
           UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
@@ -1110,10 +1013,4 @@
           const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
           TComPicYuv* pPicCYuvRec = pcPic->getPicYuvRec();
-#if Q0074_SEI_COLOR_MAPPING
-          if( m_cTDecTop.m_ColorMapping->getColorMappingFlag() )
-          {
-            pPicCYuvRec = m_cTDecTop.m_ColorMapping->getColorMapping( pPicCYuvRec );
-          }
-#endif
           m_cTVideoIOYuvReconFile.write( pPicCYuvRec,
             conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
@@ -1198,7 +1095,4 @@
 #endif
     TComPicYuv* pPicCYuvRec = pic->getPicYuvRec();
-#if Q0074_SEI_COLOR_MAPPING
-    pPicCYuvRec = m_acTDecTop[layerIdx].m_ColorMapping->getColorMapping( pPicCYuvRec, 0, layerIdx );
-#endif
     m_acTVideoIOYuvReconFile[layerIdx].write( pPicCYuvRec,
       conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
@@ -1221,5 +1115,8 @@
     pic->getPicYuvRec()->setBorderExtension( false );
 
+#if RESOLUTION_BASED_DPB
     dpbStatus.m_numPicsInLayer[layerIdx]--;
+#endif
+    dpbStatus.m_numPicsInSubDpb[layerIdx]--;
   }
 }
@@ -1285,5 +1182,5 @@
   for(Int i = 0; i < MAX_LAYERS; i++)
   {
-    m_acTDecTop[i].getListPic()->clear();
+    markAllPicturesAsErased(i);
   }
 }
@@ -1291,4 +1188,28 @@
 Void TAppDecTop::markAllPicturesAsErased(Int layerIdx)
 {
+  TComList<TComPic*>::iterator  iterPic = m_acTDecTop[layerIdx].getListPic()->begin();
+  Int iSize = Int( m_acTDecTop[layerIdx].getListPic()->size() );
+  
+  for (Int i = 0; i < iSize; i++ )
+  {
+    TComPic* pcPic = *(iterPic++);
+
+    if( pcPic )
+    {
+      pcPic->destroy();
+
+      // pcPic is statically created for the external (AVC) base layer, no need to delete it
+#if VPS_AVC_BL_FLAG_REMOVAL
+      if( !m_acTDecTop[layerIdx].getParameterSetManager()->getActiveVPS()->getNonHEVCBaseLayerFlag() || layerIdx )
+#else
+      if( !m_acTDecTop[layerIdx].getParameterSetManager()->getActiveVPS()->getAvcBaseLayerFlag() || layerIdx )
+#endif
+      {
+        delete pcPic;
+        pcPic = NULL;
+      }
+    }
+  }
+
   m_acTDecTop[layerIdx].getListPic()->clear();
 }
@@ -1434,5 +1355,7 @@
       maxDpbLimit.m_maxLatencyPictures = sps->getMaxLatencyIncrease( highestTId ) + sps->getNumReorderPics( highestTId ) - 1;
     }
+#if RESOLUTION_BASED_DPB
     maxDpbLimit.m_numPicsInLayer[0] = sps->getMaxDecPicBuffering( highestTId );
+#endif
     maxDpbLimit.m_numPicsInSubDpb[0] = sps->getMaxDecPicBuffering( highestTId );
   }
@@ -1582,5 +1505,9 @@
           if( pic->getSlice(0)->isReferenced() || pic->getOutputMark() )
           {
+#if RESOLUTION_BASED_DPB
             dpbStatus.m_numPicsInLayer[i]++;  // Count pictures that are "used for reference" or "needed for output"
+#else
+            dpbStatus.m_numPicsInSubDpb[i]++;  // Count pictures that are "used for reference" or "needed for output"
+#endif
           }
 #if POC_RESET_IDC_DECODER
@@ -1607,5 +1534,4 @@
 #if RESOLUTION_BASED_DPB
     dpbStatus.m_numPicsInSubDpb[vps->getSubDpbAssigned(targetLsIdx,i)] += dpbStatus.m_numPicsInLayer[i];
-#else
     dpbStatus.m_numPicsInSubDpb[i] += dpbStatus.m_numPicsInLayer[i];
 #endif
Index: trunk/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 815)
+++ trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 906)
@@ -135,5 +135,7 @@
   Int m_numAUsNotDisplayed;
   Int m_numPicsNotDisplayedInLayer[MAX_LAYERS];
+#if RESOLUTION_BASED_DPB
   Int m_numPicsInLayer[MAX_LAYERS];   // Pictures marked as used_for_reference or needed for output in the layer
+#endif
   Int m_numPicsInSubDpb[MAX_LAYERS];  // Pictures marked as used_for_reference or needed for output in the sub-DPB
   Bool m_maxLatencyIncrease;
@@ -152,5 +154,7 @@
     m_maxLatencyIncrease  = false;
     m_maxLatencyPictures  = 0;
+#if RESOLUTION_BASED_DPB
     ::memset( m_numPicsInLayer,  0, sizeof(m_numPicsInLayer)  );
+#endif
     ::memset( m_numPicsInSubDpb, 0, sizeof(m_numPicsInSubDpb) );
     ::memset(m_numPicsNotDisplayedInLayer, 0, sizeof(m_numPicsNotDisplayedInLayer) );
