Index: trunk/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 649)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 713)
@@ -92,6 +92,8 @@
 #if AVC_BASE
   ("BLReconFile,-ibl",    cfg_BLReconFile,  string(""), "BL reconstructed YUV input file name")
+#if !REPN_FORMAT_IN_VPS
   ("BLSourceWidth,-wdt",    m_iBLSourceWidth,        0, "BL source picture width")
   ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
+#endif
 #if AVC_SYNTAX
   ("BLSyntaxFile,-ibs",    cfg_BLSyntaxFile,  string(""), "BL syntax input file name")  
Index: trunk/source/App/TAppDecoder/TAppDecCfg.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.h	(revision 649)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.h	(revision 713)
@@ -74,6 +74,8 @@
 #if AVC_BASE
   Char*         m_pchBLReconFile;                     ///< input BL reconstruction file name
+#if !REPN_FORMAT_IN_VPS
   Int           m_iBLSourceWidth;
   Int           m_iBLSourceHeight;
+#endif
 #if AVC_SYNTAX
   Char*         m_pchBLSyntaxFile;                     ///< input BL syntax file name  
@@ -84,6 +86,8 @@
 #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
@@ -108,5 +112,5 @@
 #if SVC_EXTENSION
   , m_tgtLayerId(0)
-#if AVC_BASE
+#if AVC_BASE && !REPN_FORMAT_IN_VPS
   , m_iBLSourceWidth(0)
   , m_iBLSourceHeight(0)
Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 649)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 713)
@@ -163,5 +163,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 );
@@ -257,5 +259,5 @@
       Bool outputPicturesFlag = true;  
 #if NO_OUTPUT_OF_PRIOR_PICS
-      if( m_acTDecTop[nalu.m_layerId].getNoOutputOfPriorPicsFlags() )
+      if( m_acTDecTop[nalu.m_layerId].getNoOutputPriorPicsFlag() )
       {
         outputPicturesFlag = false;
@@ -449,4 +451,12 @@
       loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
     }
+#if !FIX_WRITING_OUTPUT
+#if SETTING_NO_OUT_PIC_PRIOR
+    if (bNewPicture && m_cTDecTop.getNoOutputPriorPicsFlag())
+    {
+      m_cTDecTop.checkNoOutputPriorPics( pcListPic );
+    }
+#endif
+#endif
 
     if( pcListPic )
@@ -460,4 +470,18 @@
         openedReconFile = true;
       }
+#if FIX_WRITING_OUTPUT
+      // write reconstruction to file
+      if( bNewPicture )
+      {
+        xWriteOutput( pcListPic, nalu.m_temporalId );
+      }
+#if SETTING_NO_OUT_PIC_PRIOR
+      if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_cTDecTop.getNoOutputPriorPicsFlag() )
+      {
+        m_cTDecTop.checkNoOutputPriorPics( pcListPic );
+        m_cTDecTop.setNoOutputPriorPicsFlag (false);
+      }
+#endif
+#endif
       if ( bNewPicture &&
            (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
@@ -471,8 +495,16 @@
       if (nalu.m_nalUnitType == NAL_UNIT_EOS)
       {
+#if FIX_OUTPUT_EOS
+        xWriteOutput( pcListPic, nalu.m_temporalId );
+#else
         xFlushOutput( pcListPic );        
-      }
-      // write reconstruction to file
+#endif
+      }
+      // write reconstruction to file -- for additional bumping as defined in C.5.2.3
+#if FIX_WRITING_OUTPUT
+      if(!bNewPicture && nalu.m_nalUnitType >= NAL_UNIT_CODED_SLICE_TRAIL_N && nalu.m_nalUnitType <= NAL_UNIT_RESERVED_VCL31)
+#else
       if(bNewPicture)
+#endif
       {
         xWriteOutput( pcListPic, nalu.m_temporalId );
@@ -586,4 +618,24 @@
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
   Int numPicsNotYetDisplayed = 0;
+  Int dpbFullness = 0;
+#if SVC_EXTENSION
+TComSPS* activeSPS = m_acTDecTop[layerId].getActiveSPS();
+#else
+  TComSPS* activeSPS = m_cTDecTop.getActiveSPS();
+#endif
+  UInt numReorderPicsHighestTid;
+  UInt maxDecPicBufferingHighestTid;
+  UInt maxNrSublayers = activeSPS->getMaxTLayers();
+
+  if(m_iMaxTemporalLayer == -1 || m_iMaxTemporalLayer >= maxNrSublayers)
+  {
+    numReorderPicsHighestTid = activeSPS->getNumReorderPics(maxNrSublayers-1);
+    maxDecPicBufferingHighestTid =  activeSPS->getMaxDecPicBuffering(maxNrSublayers-1); 
+  }
+  else
+  {
+    numReorderPicsHighestTid = activeSPS->getNumReorderPics(m_iMaxTemporalLayer);
+    maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer); 
+  }
 
   while (iterPic != pcListPic->end())
@@ -597,4 +649,9 @@
     {
       numPicsNotYetDisplayed++;
+      dpbFullness++;
+    }
+    else if(pcPic->getSlice( 0 )->isReferenced())
+    {
+      dpbFullness++;
     }
     iterPic++;
@@ -619,9 +676,13 @@
 
 #if SVC_EXTENSION
-      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
-        && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_aiPOCLastDisplay[layerId]+1 || m_aiPOCLastDisplay[layerId]<0)))
-#else
-      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
-        && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay<0)))
+      if( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() &&
+        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) &&
+        (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) &&        
+        (pcPicTop->getPOC() == m_aiPOCLastDisplay[layerId]+1 || m_aiPOCLastDisplay[layerId]<0) )
+#else
+      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() &&
+          (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) &&
+          (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) &&
+          (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay < 0))
 #endif
       {
@@ -634,36 +695,281 @@
           const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
           const Bool isTff = pcPicTop->isTopField();
+          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();
           Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
-          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+
+          m_acTVideoIOYuvReconFile[layerId].write( pPicCYuvRecTop, pPicCYuvRecBot,
             conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
             conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
             conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
             conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset(), isTff );
-
-#else
-#if O0194_DIFFERENT_BITDEPTH_EL_BL
-          // Compile time bug-fix
-          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
-#else
-          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
-#endif
+#else
+          m_acTVideoIOYuvReconFile[layerId].write( pPicCYuvRecTop, pPicCYuvRecBot,
+            conf.getWindowLeftOffset()   + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset()  + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset()    + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
+#endif
+        }
+
+        // update POC of display order
+        m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC();
+#else
+        if ( m_pchReconFile )
+        {
+          const Window &conf = pcPicTop->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
+          const Bool isTff = pcPicTop->isTopField();
+          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(),
             conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
             conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
             conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
-#endif
         }
 
         // update POC of display order
-        m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC();
+        m_iPOCLastDisplay = pcPicBottom->getPOC();
+#endif
+
+        // erase non-referenced picture in the reference picture list after display
+        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPicTop->setReconMark(false);
+
+          // mark it should be extended later
+          pcPicTop->getPicYuvRec()->setBorderExtension( false );
+
+#else
+          pcPicTop->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPicBottom->setReconMark(false);
+
+          // mark it should be extended later
+          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
+
+#else
+          pcPicBottom->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        pcPicTop->setOutputMark(false);
+        pcPicBottom->setOutputMark(false);
+      }
+    }
+  }
+  else if (!pcPic->isField()) //Frame Decoding
+  {
+    iterPic = pcListPic->begin();
+    while (iterPic != pcListPic->end())
+    {
+      pcPic = *(iterPic);
+
+#if SVC_EXTENSION
+      if( pcPic->getOutputMark() && pcPic->getPOC() > m_aiPOCLastDisplay[layerId] &&
+        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) )
+#else
+      if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay &&
+        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid))
+#endif
+      {
+        // write to file
+        numPicsNotYetDisplayed--;
+        if(pcPic->getSlice(0)->isReferenced() == false)
+        {
+          dpbFullness--;
+        }
+#if SVC_EXTENSION
+        if( m_pchReconFile[layerId] )
+        {
+          const Window &conf = pcPic->getConformanceWindow();
+          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();
+          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+
+          m_acTVideoIOYuvReconFile[layerId].write( pPicCYuvRec,
+            conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() );
+#else
+          m_acTVideoIOYuvReconFile[layerId].write( pPicCYuvRec,
+            conf.getWindowLeftOffset()   + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset()  + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset()    + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+#endif
+        }
+
+        // update POC of display order
+        m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
 #else
         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
+        }
+
+        // update POC of display order
+        m_iPOCLastDisplay = pcPic->getPOC();
+#endif
+
+        // erase non-referenced picture in the reference picture list after display
+        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPic->setReconMark(false);
+
+          // mark it should be extended later
+          pcPic->getPicYuvRec()->setBorderExtension( false );
+
+#else
+          pcPic->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        pcPic->setOutputMark(false);
+      }
+
+      iterPic++;
+    }
+  }
+}
+
+/** \param pcListPic list of pictures to be written to file
+    \todo            DYN_REF_FREE should be revised
+ */
+#if SVC_EXTENSION
+Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, UInt layerId )
+#else
+Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic )
+#endif
+{
+  if(!pcListPic || pcListPic->empty())
+  {
+    return;
+  }
+  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
+
+  iterPic   = pcListPic->begin();
+  TComPic* pcPic = *(iterPic);
+
+  if (pcPic->isField()) //Field Decoding
+  {
+    TComList<TComPic*>::iterator endPic   = pcListPic->end();
+    endPic--;
+    TComPic *pcPicTop, *pcPicBottom = NULL;
+    while (iterPic != endPic)
+    {
+      pcPicTop = *(iterPic);
+      iterPic++;
+      pcPicBottom = *(iterPic);
+
+      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) )
+      {
+        // write to file
+#if SVC_EXTENSION
+        if ( m_pchReconFile[layerId] )
         {
           const Window &conf = pcPicTop->getConformanceWindow();
           const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
           const Bool isTff = pcPicTop->isTopField();
-          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+          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();
+          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+
+          m_acTVideoIOYuvReconFile[layerId].write( pPicCYuvRecTop, pPicCYuvRecBot,
+            conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset(), isTff );
+#else
+          m_acTVideoIOYuvReconFile[layerId].write( pPicCYuvRecTop, pPicCYuvRecBot,
+            conf.getWindowLeftOffset()   + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset()  + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset()    + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
+#endif
+        }
+
+        // update POC of display order
+        m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC();
+#else
+        if ( m_pchReconFile )
+        {
+          const Window &conf = pcPicTop->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
+          const Bool isTff = pcPicTop->isTopField();
+          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(),
             conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
@@ -709,22 +1015,31 @@
         pcPicTop->setOutputMark(false);
         pcPicBottom->setOutputMark(false);
-      }
-    }
-  }
-  else if (!pcPic->isField()) //Frame Decoding
-  {
-    iterPic = pcListPic->begin();
+
+#if !DYN_REF_FREE
+        if(pcPicTop)
+        {
+          pcPicTop->destroy();
+          delete pcPicTop;
+          pcPicTop = NULL;
+        }
+#endif
+      }
+    }
+    if(pcPicBottom)
+    {
+      pcPicBottom->destroy();
+      delete pcPicBottom;
+      pcPicBottom = NULL;
+    }
+  }
+  else //Frame decoding
+  {
     while (iterPic != pcListPic->end())
     {
       pcPic = *(iterPic);
 
-#if SVC_EXTENSION
-      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_aiPOCLastDisplay[layerId]))
-#else
-      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
-#endif
+      if ( pcPic->getOutputMark() )
       {
         // write to file
-        numPicsNotYetDisplayed--;
 #if SVC_EXTENSION
         if ( m_pchReconFile[layerId] )
@@ -732,225 +1047,25 @@
           const Window &conf = pcPic->getConformanceWindow();
           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();
           Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
-          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
-            conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
-            conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
-            conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
-            conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() );
-
-#else
-          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
-            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
-#endif
-        }
-
-        // update POC of display order
-        m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
-#else
-        if ( m_pchReconFile )
-        {
-#if SYNTAX_OUTPUT
-          const Window &conf = pcPic->getConformanceWindow();
-          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
-            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
-#endif
-        }
-
-        // update POC of display order
-        m_iPOCLastDisplay = pcPic->getPOC();
-#endif
-
-        // erase non-referenced picture in the reference picture list after display
-        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
-        {
-#if !DYN_REF_FREE
-          pcPic->setReconMark(false);
-
-          // mark it should be extended later
-          pcPic->getPicYuvRec()->setBorderExtension( false );
-
-#else
-          pcPic->destroy();
-          pcListPic->erase( iterPic );
-          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
-          continue;
-#endif
-        }
-        pcPic->setOutputMark(false);
-      }
-
-      iterPic++;
-    }
-  }
-}
-
-/** \param pcListPic list of pictures to be written to file
-    \todo            DYN_REF_FREE should be revised
- */
-#if SVC_EXTENSION
-Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, UInt layerId )
-#else
-Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic )
-#endif
-{
-  if(!pcListPic || pcListPic->empty())
-  {
-    return;
-  }
-  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
-
-  iterPic   = pcListPic->begin();
-  TComPic* pcPic = *(iterPic);
-
-  if (pcPic->isField()) //Field Decoding
-  {
-    TComList<TComPic*>::iterator endPic   = pcListPic->end();
-    endPic--;
-    TComPic *pcPicTop, *pcPicBottom = NULL;
-    while (iterPic != endPic)
-    {
-      pcPicTop = *(iterPic);
-      iterPic++;
-      pcPicBottom = *(iterPic);
-
-      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) )
-      {
-        // write to file
-#if SVC_EXTENSION
-        if ( m_pchReconFile[layerId] )
-        {
-          const Window &conf = pcPicTop->getConformanceWindow();
-          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
-          const Bool isTff = pcPicTop->isTopField();
-#if REPN_FORMAT_IN_VPS
-          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
-          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
-          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
-            conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
-            conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
-            conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
-            conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset(), isTff );
-
-#else
-#if O0194_DIFFERENT_BITDEPTH_EL_BL
-          // Compile time bug-fix
-          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
-#else
-          m_cTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
-#endif
-            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
-#endif
-        }
-
-        // update POC of display order
-        m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC();
-#else
-        if ( m_pchReconFile )
-        {
-          const Window &conf = pcPicTop->getConformanceWindow();
-          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
-          const Bool isTff = pcPicTop->isTopField();
-          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
-            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
-        }
-
-        // update POC of display order
-        m_iPOCLastDisplay = pcPicBottom->getPOC();
-#endif
-
-        // erase non-referenced picture in the reference picture list after display
-        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
-        {
-#if !DYN_REF_FREE
-          pcPicTop->setReconMark(false);
-
-          // mark it should be extended later
-          pcPicTop->getPicYuvRec()->setBorderExtension( false );
-
-#else
-          pcPicTop->destroy();
-          pcListPic->erase( iterPic );
-          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
-          continue;
-#endif
-        }
-        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
-        {
-#if !DYN_REF_FREE
-          pcPicBottom->setReconMark(false);
-
-          // mark it should be extended later
-          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
-
-#else
-          pcPicBottom->destroy();
-          pcListPic->erase( iterPic );
-          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
-          continue;
-#endif
-        }
-        pcPicTop->setOutputMark(false);
-        pcPicBottom->setOutputMark(false);
-
-#if !DYN_REF_FREE
-        if(pcPicTop)
-        {
-          pcPicTop->destroy();
-          delete pcPicTop;
-          pcPicTop = NULL;
-        }
-#endif
-      }
-    }
-    if(pcPicBottom)
-    {
-      pcPicBottom->destroy();
-      delete pcPicBottom;
-      pcPicBottom = NULL;
-    }
-  }
-  else //Frame decoding
-  {
-    while (iterPic != pcListPic->end())
-    {
-      pcPic = *(iterPic);
-
-      if ( pcPic->getOutputMark() )
-      {
-        // write to file
-#if SVC_EXTENSION
-        if ( m_pchReconFile[layerId] )
-        {
-          const Window &conf = pcPic->getConformanceWindow();
-          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-#if REPN_FORMAT_IN_VPS
-          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
-          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
-          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
+
+          m_acTVideoIOYuvReconFile[layerId].write( pPicCYuvRec,
             conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
             conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
             conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
             conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset() );
-
-#else
-          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
-            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+#else
+          m_acTVideoIOYuvReconFile[layerId].write( pPicCYuvRec,
+            conf.getWindowLeftOffset()   + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset()  + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset()    + defDisp.getWindowTopOffset(),
             conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
 #endif
@@ -964,5 +1079,12 @@
           const Window &conf = pcPic->getConformanceWindow();
           const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
+          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(),
             conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
@@ -1045,5 +1167,9 @@
     yScal = TComSPS::getWinUnitY( chromaFormatIdc );
 #endif
-    m_acTVideoIOYuvReconFile[layerIdx].write( pic->getPicYuvRec(),
+    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(),
       conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 649)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 713)
@@ -339,4 +339,7 @@
   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
@@ -433,4 +436,7 @@
     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
@@ -616,4 +622,7 @@
 #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")
@@ -710,5 +719,9 @@
   ("IntraPeriod,-ip",         m_iIntraPeriod,              -1, "Intra period in frames, (-1: only first frame)")
 #endif
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  ("DecodingRefreshType,-dr", m_iDecodingRefreshType,       0, "Intra refresh type (0:none 1:CRA 2:IDR 3:RecPointSEI)")
+#else
   ("DecodingRefreshType,-dr", m_iDecodingRefreshType,       0, "Intra refresh type (0:none 1:CRA 2:IDR)")
+#endif
   ("GOPSize,g",               m_iGOPSize,                   1, "GOP size of temporal structure")
   // motion options
@@ -905,4 +918,6 @@
   ("SEIToneMapCameraIsoSpeedIdc",                     m_cameraIsoSpeedIdc,                        0, "Indicates the camera ISO speed for daylight illumination")
   ("SEIToneMapCameraIsoSpeedValue",                   m_cameraIsoSpeedValue,                    400, "Specifies the camera ISO speed for daylight illumination of Extended_ISO")
+  ("SEIToneMapExposureIndexIdc",                      m_exposureIndexIdc,                         0, "Indicates the exposure index setting of the camera")
+  ("SEIToneMapExposureIndexValue",                    m_exposureIndexValue,                     400, "Specifies the exposure index setting of the cameran of Extended_ISO")
   ("SEIToneMapExposureCompensationValueSignFlag",     m_exposureCompensationValueSignFlag,        0, "Specifies the sign of ExposureCompensationValue")
   ("SEIToneMapExposureCompensationValueNumerator",    m_exposureCompensationValueNumerator,       0, "Specifies the numerator of ExposureCompensationValue")
@@ -955,4 +970,10 @@
   ("CrossLayerBLAFlag",                m_crossLayerBLAFlag,                       false, "Specifies the value of cross_layer_bla_flag in VPS")
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  ("CGS",     m_nCGSFlag , 0, "whether CGS is enabled")
+  ("CGSMaxOctantDepth", m_nCGSMaxOctantDepth , 1, "max octant depth")
+  ("CGSMaxYPartNumLog",  m_nCGSMaxYPartNumLog2 , 2, "max Y part number ")
+  ("CGSLUTBit",     m_nCGSLUTBit , 12, "bit depth of CGS LUT")
+#endif
   ;
   
@@ -1202,5 +1223,5 @@
         if( i >= m_acLayerCfg[layer].m_numSamplePredRefLayers )
         {
-          printf( "NumSamplePredRefLayers: The number of columns whose width are defined is larger than the allowed number of columns.\n" );
+          printf( "NumSamplePredRefLayers%d: The number of columns whose width are defined is larger than the allowed number of columns.\n", layer );
           exit( EXIT_FAILURE );
         }
@@ -1211,5 +1232,5 @@
       if( i < m_acLayerCfg[layer].m_numSamplePredRefLayers )
       {
-        printf( "NumSamplePredRefLayers: The width of some columns is not defined.\n" );
+        printf( "NumSamplePredRefLayers%d: The width of some columns is not defined.\n", layer );
         exit( EXIT_FAILURE );
       }
@@ -1233,5 +1254,5 @@
         if( i >= m_acLayerCfg[layer].m_numMotionPredRefLayers )
         {
-          printf( "NumMotionPredRefLayers: The number of columns whose width are defined is larger than the allowed number of columns.\n" );
+          printf( "NumMotionPredRefLayers%d: The number of columns whose width are defined is larger than the allowed number of columns.\n", layer );
           exit( EXIT_FAILURE );
         }
@@ -1242,5 +1263,5 @@
       if( i < m_acLayerCfg[layer].m_numMotionPredRefLayers )
       {
-        printf( "NumMotionPredRefLayers: The width of some columns is not defined.\n" );
+        printf( "NumMotionPredRefLayers%d: The width of some columns is not defined.\n", layer );
         exit( EXIT_FAILURE );
       }
@@ -1272,5 +1293,5 @@
         if( i >= m_acLayerCfg[layer].m_numActiveRefLayers )
         {
-          printf( "NumActiveRefLayers: The number of columns whose width are defined is larger than the allowed number of columns.\n" );
+          printf( "NumActiveRefLayers%d: The number of columns whose width are defined is larger than the allowed number of columns.\n", layer );
           exit( EXIT_FAILURE );
         }
@@ -1281,5 +1302,5 @@
       if( i < m_acLayerCfg[layer].m_numActiveRefLayers )
       {
-        printf( "NumActiveRefLayers: The width of some columns is not defined.\n" );
+        printf( "NumActiveRefLayers%d: The width of some columns is not defined.\n", layer );
         exit( EXIT_FAILURE );
       }
@@ -1474,4 +1495,5 @@
     }
   }
+
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
   if (m_interLayerConstrainedTileSetsSEIEnabled)
@@ -1587,5 +1609,13 @@
   xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < m_iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
 #endif
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 3,                   "Decoding Refresh Type must be comprised between 0 and 3 included" );
+  if(m_iDecodingRefreshType == 3)
+  {
+    xConfirmPara( !m_recoveryPointSEIEnabled,                                               "When using RecoveryPointSEI messages as RA points, recoveryPointSEI must be enabled" );
+  }
+#else
   xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2,                   "Decoding Refresh Type must be equal to 0, 1 or 2" );
+#endif
 #if !SVC_EXTENSION
   xConfirmPara( m_iQP <  -6 * (m_internalBitDepthY - 8) || m_iQP > 51,                    "QP exceeds supported range (-QpBDOffsety to 51)" );
@@ -2160,4 +2190,5 @@
     xConfirmPara( m_toneMapModelId < 0 || m_toneMapModelId > 4 , "SEIToneMapModelId must be in rage 0 to 4");
     xConfirmPara( m_cameraIsoSpeedValue == 0, "SEIToneMapCameraIsoSpeedValue shall not be equal to 0");
+    xConfirmPara( m_exposureIndexValue  == 0, "SEIToneMapExposureIndexValue shall not be equal to 0");
     xConfirmPara( m_extendedRangeWhiteLevel < 100, "SEIToneMapExtendedRangeWhiteLevel should be greater than or equal to 100");
     xConfirmPara( m_nominalBlackLevelLumaCodeValue >= m_nominalWhiteLevelLumaCodeValue, "SEIToneMapNominalWhiteLevelLumaCodeValue shall be greater than SEIToneMapNominalBlackLevelLumaCodeValue");
@@ -2286,4 +2317,7 @@
   }
 #endif 
+#if Q0048_CGS_3D_ASYMLUT
+  xConfirmPara( m_nCGSFlag < 0 || m_nCGSFlag > 1 , "0<=CGS<=1" );
+#endif
 #undef xConfirmPara
   if (check_failed)
@@ -2545,4 +2579,7 @@
   printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 );
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  printf("CGS: %d CGSMaxOctantDepth: %d CGSMaxYPartNumLog2: %d CGSLUTBit:%d " , m_nCGSFlag , m_nCGSMaxOctantDepth , m_nCGSMaxYPartNumLog2 , m_nCGSLUTBit );
+#endif
   printf("\n\n");
   
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 649)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 713)
@@ -255,4 +255,6 @@
   Int       m_cameraIsoSpeedIdc;
   Int       m_cameraIsoSpeedValue;
+  Int       m_exposureIndexIdc;
+  Int       m_exposureIndexValue;
   Int       m_exposureCompensationValueSignFlag;
   Int       m_exposureCompensationValueNumerator;
@@ -266,4 +268,7 @@
   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;
@@ -393,4 +398,10 @@
   Bool      m_useInterLayerWeightedPred;
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  Int  m_nCGSFlag;
+  Int  m_nCGSMaxOctantDepth;
+  Int  m_nCGSMaxYPartNumLog2;
+  Int  m_nCGSLUTBit;
+#endif
 public:
   TAppEncCfg();
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 649)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 713)
@@ -171,5 +171,9 @@
   }
 #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 );
+#else
   printf("Real     Format               : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
+#endif
   printf("Internal Format               : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
@@ -229,4 +233,7 @@
         m_aiPad[0] = m_confRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
         m_iSourceWidth  += m_confRight;
+#if REPN_FORMAT_IN_VPS
+        m_confRight /= TComSPS::getWinUnitX( m_chromaFormatIDC );
+#endif
       }
       if (m_iSourceHeight % minCuSize)
@@ -239,4 +246,7 @@
           m_aiPad[1] = m_confBottom << 1;
         }
+#if REPN_FORMAT_IN_VPS
+        m_confBottom /= TComSPS::getWinUnitY( m_chromaFormatIDC );
+#endif
       }
       break;
@@ -249,4 +259,8 @@
       m_confRight  = m_aiPad[0];
       m_confBottom = m_aiPad[1];
+#if REPN_FORMAT_IN_VPS
+      m_confRight /= TComSPS::getWinUnitX( m_chromaFormatIDC );
+      m_confBottom /= TComSPS::getWinUnitY( m_chromaFormatIDC );
+#endif
       break;
     }
@@ -331,8 +345,10 @@
   xConfirmPara( m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling");
 
+#if !REPN_FORMAT_IN_VPS
   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");
+#endif
 
 #if LAYER_CTB  
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 649)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 713)
@@ -54,4 +54,7 @@
   Int       *m_predLayerIds;
   Int       m_numActiveRefLayers;
+#endif
+#if Q0074_SEI_COLOR_MAPPING
+  string    m_cSeiColorMappingFile;
 #endif
 
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 649)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 713)
@@ -91,6 +91,5 @@
   }
 
-#if REPN_FORMAT_IN_VPS
-  vps->setRepFormatIdxPresentFlag( true );   // Could be disabled to optimize in some cases.
+#if REPN_FORMAT_IN_VPS  
   Int maxRepFormatIdx = -1;
   Int formatIdx = -1;
@@ -125,9 +124,14 @@
 
     assert( m_acLayerCfg[layer].getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a layer" );
+
     vps->setVpsRepFormatIdx( layer, m_acLayerCfg[layer].getRepFormatIdx() );
+
     maxRepFormatIdx = std::max( m_acLayerCfg[layer].getRepFormatIdx(), maxRepFormatIdx );
   }
+
   assert( vps->getVpsRepFormatIdx( 0 ) == 0 );  // Base layer should point to the first one.
+
   Int* mapIdxToLayer = new Int[maxRepFormatIdx + 1];
+
   // Check that all the indices from 0 to maxRepFormatIdx are used in the VPS
   for(Int i = 0; i <= maxRepFormatIdx; i++)
@@ -145,5 +149,14 @@
     assert( layer != m_numLayers );   // One of the VPS Rep format indices not set
   }
+
   vps->setVpsNumRepFormats( maxRepFormatIdx + 1 );
+
+#if Q0195_REP_FORMAT_CLEANUP
+  // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
+  vps->setRepFormatIdxPresentFlag( vps->getVpsNumRepFormats() > 1 ? true : false );
+#else
+  vps->setRepFormatIdxPresentFlag( true );
+#endif
+
   for(UInt idx=0; idx < vps->getVpsNumRepFormats(); idx++)
   {
@@ -467,4 +480,7 @@
     m_acTEncTop[layer].setTMISEINominalWhiteLevelLumaCodeValue      ( m_nominalWhiteLevelLumaCodeValue );
     m_acTEncTop[layer].setTMISEIExtendedWhiteLevelLumaCodeValue     ( m_extendedWhiteLevelLumaCodeValue );
+#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()) );
+#endif
     m_acTEncTop[layer].setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
     m_acTEncTop[layer].setFramePackingArrangementSEIType( m_framePackingSEIType );
@@ -592,4 +608,10 @@
     m_acTEncTop[layer].setCrossLayerBLAFlag( m_crossLayerBLAFlag );
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+    m_acTEncTop[layer].setCGSFlag( layer == 0 ? 0 : m_nCGSFlag );
+    m_acTEncTop[layer].setCGSMaxOctantDepth( m_nCGSMaxOctantDepth );
+    m_acTEncTop[layer].setCGSMaxYPartNumLog2( m_nCGSMaxYPartNumLog2 );
+    m_acTEncTop[layer].setCGSLUTBit( m_nCGSLUTBit );
+#endif
   }
 }
@@ -767,4 +789,6 @@
   m_cTEncTop.setTMISEICameraIsoSpeedIdc                   ( m_cameraIsoSpeedIdc );
   m_cTEncTop.setTMISEICameraIsoSpeedValue                 ( m_cameraIsoSpeedValue );
+  m_cTEncTop.setTMISEIExposureIndexIdc                    ( m_exposureIndexIdc );
+  m_cTEncTop.setTMISEIExposureIndexValue                  ( m_exposureIndexValue );
   m_cTEncTop.setTMISEIExposureCompensationValueSignFlag   ( m_exposureCompensationValueSignFlag );
   m_cTEncTop.setTMISEIExposureCompensationValueNumerator  ( m_exposureCompensationValueNumerator );
@@ -775,4 +799,7 @@
   m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue      ( m_nominalWhiteLevelLumaCodeValue );
   m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue     ( m_extendedWhiteLevelLumaCodeValue );
+#if Q0074_SEI_COLOR_MAPPING
+  m_cTEncTop.setColorMappingInfoSEIFile                   ( m_pchSEIColorMappingFile );
+#endif
   m_cTEncTop.setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
   m_cTEncTop.setFramePackingArrangementSEIType( m_framePackingSEIType );
@@ -974,4 +1001,6 @@
   vps->setMaxLayerId(m_numLayers - 1);    // Set max-layer ID
 
+  vps->setVpsExtensionFlag( m_numLayers > 1 ? true : false );
+
   vps->setNumLayerSets(m_numLayers);
   for(Int setId = 1; setId < vps->getNumLayerSets(); setId++)
@@ -1068,7 +1097,7 @@
 #if VPS_TSLAYERS
     vps->setMaxTSLayersPresentFlag(true);
-    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
-    {
-        vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
+    for( i = 0; i < vps->getMaxLayers(); i++ )
+    {
+      vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
     }
 #endif
@@ -1081,9 +1110,9 @@
   if (vps->getMaxTidRefPresentFlag())
   {
-    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
+    for( i = 0; i < vps->getMaxLayers() - 1; i++ )
     {
 #if N0120_MAX_TID_REF_CFG
 #if O0225_MAX_TID_FOR_REF_LAYERS
-      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
+      for( Int j = i+1; j < vps->getMaxLayers(); j++)
       {
         vps->setMaxTidIlRefPicsPlus1(i, j, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
@@ -1094,5 +1123,5 @@
 #else
 #if O0225_MAX_TID_FOR_REF_LAYERS
-      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
+      for( Int j = i+1; j < vps->getMaxLayers(); j++)
       {
         vps->setMaxTidIlRefPicsPlus1(i, j, vps->getMaxTLayers()+1);
@@ -1106,8 +1135,8 @@
   else
   {
-    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
+    for( i = 0; i < vps->getMaxLayers() - 1; i++ )
     {
 #if O0225_MAX_TID_FOR_REF_LAYERS
-      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
+      for( Int j = i+1; j < vps->getMaxLayers(); j++)
       {
         vps->setMaxTidIlRefPicsPlus1(i, j, 7);
@@ -1297,5 +1326,5 @@
   if(vps->getMaxLayers() > MAX_REF_LAYERS)
   {
-    for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+    for(UInt layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
     {
       assert( vps->getNumRefLayers(vps->getLayerIdInNuh(layerCtr)) <= MAX_REF_LAYERS);
@@ -1400,9 +1429,18 @@
       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;
+#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;
+#endif
       UInt uiNumCUsInFrame   = uiWidthInCU * uiHeightInCU;
 
+#if LAYER_CTB
+      UInt maxCU = pcCfgLayer->getSliceArgument() >> ( m_acLayerCfg[layerId].m_uiMaxCUDepth << 1);
+#else
       UInt maxCU = pcCfgLayer->getSliceArgument() >> ( m_uiMaxCUDepth << 1);
+#endif
       UInt numDU = ( pcCfgLayer->getSliceMode() == 1 ) ? ( uiNumCUsInFrame / maxCU ) : ( 0 );
       if( uiNumCUsInFrame % maxCU != 0 || numDU == 0 )
Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 649)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 713)
@@ -58,7 +58,7 @@
 #if SVC_EXTENSION
 #include <vector>
-#define NV_VERSION        "5.1 (HM-13.0)"                 ///< Current software version
+#define NV_VERSION        "6.0 (HM-14.0)"                 ///< Current software version
 #else
-#define NV_VERSION        "13.0"                ///< Current software version
+#define NV_VERSION        "14.0"                ///< Current software version
 #endif
 
Index: trunk/source/Lib/TLibCommon/SEI.h
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.h	(revision 649)
+++ trunk/source/Lib/TLibCommon/SEI.h	(revision 713)
@@ -79,13 +79,16 @@
 #endif
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-    INTER_LAYER_CONSTRAINED_TILE_SETS    = 138
+    INTER_LAYER_CONSTRAINED_TILE_SETS    = 138,
 #endif
 #if SUB_BITSTREAM_PROPERTY_SEI
-   ,SUB_BITSTREAM_PROPERTY               = 139    // Final PayloadType to be defined after finalization
+    SUB_BITSTREAM_PROPERTY               = 139,    // Final PayloadType to be defined after finalization
 #endif
 #if O0164_MULTI_LAYER_HRD
-   ,BSP_NESTING                          = 140
-   ,BSP_INITIAL_ARRIVAL_TIME             = 141
-   ,BSP_HRD                              = 142
+    BSP_NESTING                          = 140,
+    BSP_INITIAL_ARRIVAL_TIME             = 141,
+    BSP_HRD                              = 142,
+#endif
+#if Q0074_SEI_COLOR_MAPPING
+    COLOR_MAPPING_INFO                   = 143,
 #endif
   };
@@ -142,6 +145,6 @@
   SEIActiveParameterSets() 
     : activeVPSId            (0)
-    , m_fullRandomAccessFlag (false)
-    , m_noParamSetUpdateFlag (false)
+    , m_selfContainedCvsFlag (false)
+    , m_noParameterSetUpdateFlag (false)
     , numSpsIdsMinus1        (0)
   {}
@@ -149,8 +152,8 @@
 
   Int activeVPSId; 
-  Bool m_fullRandomAccessFlag;
-  Bool m_noParamSetUpdateFlag;
+  Bool m_selfContainedCvsFlag;
+  Bool m_noParameterSetUpdateFlag;
   Int numSpsIdsMinus1;
-  std::vector<Int> activeSeqParamSetId; 
+  std::vector<Int> activeSeqParameterSetId; 
 };
 
@@ -393,4 +396,6 @@
   Int    m_cameraIsoSpeedIdc;
   Int    m_cameraIsoSpeedValue;
+  Int    m_exposureIndexIdc;
+  Int    m_exposureIndexValue;
   Int    m_exposureCompensationValueSignFlag;
   Int    m_exposureCompensationValueNumerator;
@@ -402,4 +407,40 @@
   Int    m_extendedWhiteLevelLumaCodeValue;
 };
+
+#if Q0074_SEI_COLOR_MAPPING
+class SEIColorMappingInfo : public SEI
+{
+public:
+  PayloadType payloadType() const { return COLOR_MAPPING_INFO; }
+  SEIColorMappingInfo() {
+  }
+  virtual ~SEIColorMappingInfo() {}
+
+  Int   m_colorMapId;
+  Bool  m_colorMapCancelFlag;
+  Bool  m_colorMapPersistenceFlag;
+  Bool  m_colorMap_video_signal_type_present_flag;
+  Bool  m_colorMap_video_full_range_flag;
+  Int   m_colorMap_primaries;
+  Int   m_colorMap_transfer_characteristics;
+  Int   m_colorMap_matrix_coeffs;
+  Int   m_colorMapModelId;
+
+  Int   m_colour_map_coded_data_bit_depth;
+  Int   m_colour_map_target_bit_depth;
+
+  Int   m_num_input_pivots[3];
+  Int*  m_coded_input_pivot_value[3];
+  Int*  m_target_input_pivot_value[3];
+  
+  Bool  m_matrix_flag;
+  Int   m_log2_matrix_denom;
+  Int   m_matrix_coef[3][3];
+
+  Int   m_num_output_pivots[3];
+  Int*  m_coded_output_pivot_value[3];
+  Int*  m_target_output_pivot_value[3];
+};
+#endif
 
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
Index: trunk/source/Lib/TLibCommon/TCom3DAsymLUT.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TCom3DAsymLUT.cpp	(revision 713)
+++ trunk/source/Lib/TLibCommon/TCom3DAsymLUT.cpp	(revision 713)
@@ -0,0 +1,279 @@
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cmath>
+#include <algorithm>
+
+#include "TypeDef.h"
+#include "TCom3DAsymLUT.h"
+#include "TComPicYuv.h"
+
+#if Q0048_CGS_3D_ASYMLUT
+
+const Int TCom3DAsymLUT::m_nVertexIdxOffset[4][3] = { { 0 , 0 , 0 } , { 0 , 1 , 0 } , { 0 , 1 , 1 } , { 1 , 1 , 1 } };
+
+TCom3DAsymLUT::TCom3DAsymLUT()
+{
+  m_pCuboid = NULL;
+  m_nResQuanBit = 0;
+}
+
+TCom3DAsymLUT::~TCom3DAsymLUT()
+{
+  destroy();
+}
+
+Void TCom3DAsymLUT::create( Int nMaxOctantDepth , Int nInputBitDepth , Int nInputBitDepthC , Int nOutputBitDepth , Int nOutputBitDepthC , Int nMaxYPartNumLog2 )
+{
+  m_nMaxOctantDepth = nMaxOctantDepth;
+  m_nInputBitDepthY = nInputBitDepth;
+  m_nOutputBitDepthY = nOutputBitDepth;
+  m_nInputBitDepthC = nInputBitDepthC;
+  m_nOutputBitDepthC = nOutputBitDepthC;
+  m_nDeltaBitDepthC = m_nOutputBitDepthC - m_nInputBitDepthC;
+  m_nDeltaBitDepth = m_nOutputBitDepthY - m_nInputBitDepthY;
+  m_nMaxYPartNumLog2 = nMaxYPartNumLog2;
+  m_nMaxPartNumLog2 = 3 * m_nMaxOctantDepth + m_nMaxYPartNumLog2;
+
+  xUpdatePartitioning( nMaxOctantDepth , nMaxYPartNumLog2 );
+
+  m_nYSize = 1 << ( m_nMaxOctantDepth + m_nMaxYPartNumLog2 );
+  m_nUSize = 1 << m_nMaxOctantDepth;
+  m_nVSize = 1 << m_nMaxOctantDepth;
+  assert( m_nYSize > 0 && m_nUSize > 0 && m_nVSize > 0 );
+
+  if( m_pCuboid != NULL )
+    destroy();
+  xAllocate3DArray( m_pCuboid , m_nYSize , m_nUSize , m_nVSize );
+}
+
+Void TCom3DAsymLUT::destroy()
+{
+  xFree3DArray( m_pCuboid );
+}
+
+Void TCom3DAsymLUT::xUpdatePartitioning( Int nCurOctantDepth , Int nCurYPartNumLog2 )
+{
+  assert( nCurOctantDepth <= m_nMaxOctantDepth );
+  assert( nCurYPartNumLog2 <= m_nMaxYPartNumLog2 );
+
+  m_nCurOctantDepth = nCurOctantDepth;
+  m_nCurYPartNumLog2 = nCurYPartNumLog2;
+  m_nYShift2Idx = m_nInputBitDepthY - m_nCurOctantDepth - m_nCurYPartNumLog2;
+  m_nUShift2Idx = m_nVShift2Idx = m_nInputBitDepthC - m_nCurOctantDepth;
+  m_nMappingShift = m_nYShift2Idx + m_nUShift2Idx;
+  m_nMappingOffset = 1 << ( m_nMappingShift - 1 );
+}
+
+Void TCom3DAsymLUT::colorMapping( TComPicYuv * pcPic, TComPicYuv * pcPicDst )
+{
+  Int nWidth = pcPic->getWidth();
+  Int nHeight = pcPic->getHeight();
+  Int nStrideY = pcPic->getStride();
+  Int nStrideC = pcPic->getCStride();
+  Pel * pY = pcPic->getLumaAddr();
+  Pel * pU = pcPic->getCbAddr();
+  Pel * pV = pcPic->getCrAddr();
+
+  Int nDstStrideY = pcPicDst->getStride();
+  Int nDstStrideC = pcPicDst->getCStride();
+  Pel * pYDst = pcPicDst->getLumaAddr();
+  Pel * pUDst = pcPicDst->getCbAddr();
+  Pel * pVDst = pcPicDst->getCrAddr();
+
+  Pel *pUPrev = pU;
+  Pel *pVPrev = pV;
+  Pel *pUNext = pU+nStrideC;
+  Pel *pVNext = pV+nStrideC;
+
+  // alignment padding
+  pU += (nWidth>>1);
+  pV += (nWidth>>1);
+  for( Int y = 0 ; y < (nHeight>>1) ; y ++ )
+  {
+    *pU = pU[-1];
+    *pV = pV[-1];
+    pU += nStrideC;
+    pV += nStrideC;
+  }
+  memcpy(pU-(nWidth>>1), pU-(nWidth>>1)-nStrideC, ((nWidth>>1)+1)*sizeof(Pel));
+  memcpy(pV-(nWidth>>1), pV-(nWidth>>1)-nStrideC, ((nWidth>>1)+1)*sizeof(Pel));
+  pU = pcPic->getCbAddr();
+  pV = pcPic->getCrAddr();
+
+  Pel iMaxValY = (1<<getOutputBitDepthY())-1;
+  Pel iMaxValC = (1<<getOutputBitDepthC())-1;
+  for( Int y = 0 ; y < nHeight ; y += 2 )
+  {
+    for( Int xY = 0 , xC = 0 ; xY < nWidth ; xY += 2 , xC++ )
+    {
+      Pel srcY00 = pY[xY];
+      Pel srcY01 = pY[xY+1];
+      Pel srcY10 = pY[xY+nStrideY];
+      Pel srcY11 = pY[xY+nStrideY+1];
+      Pel srcYaver;
+      Pel srcU = pU[xC];
+      Pel srcV = pV[xC];
+      Pel dstY00, dstY01, dstY10, dstY11;
+
+      // alignment
+      srcYaver =  (srcY00 + srcY10 + 1 ) >> 1;
+      Pel srcUP0 = pUPrev[xC];
+      Pel srcVP0 = pVPrev[xC];        
+      Pel tmpU =  (srcUP0 + srcU + (srcU<<1) + 2 ) >> 2;
+      Pel tmpV =  (srcVP0 + srcV + (srcV<<1) + 2 ) >> 2;
+      dstY00 = xMapY( srcY00 , tmpU , tmpV );
+      Pel a = pU[xC+1] + srcU;
+      tmpU =  ((a<<1) + a + srcUP0 + pUPrev[xC+1] + 4 ) >> 3;
+      Pel b = pV[xC+1] + srcV;
+      tmpV =  ((b<<1) + b + srcVP0 + pVPrev[xC+1] + 4 ) >> 3;
+      dstY01 = xMapY( srcY01 , tmpU , tmpV );
+
+      srcUP0 = pUNext[xC];
+      srcVP0 = pVNext[xC];
+      tmpU =  (srcUP0 + srcU + (srcU<<1) + 2 ) >> 2;
+      tmpV =  (srcVP0 + srcV + (srcV<<1) + 2 ) >> 2;
+      dstY10 = xMapY( srcY10 , tmpU , tmpV );
+      tmpU =  ((a<<1) + a + srcUP0 + pUNext[xC+1] + 4 ) >> 3;
+      tmpV =  ((b<<1) + b + srcVP0 + pVNext[xC+1] + 4 ) >> 3;
+      dstY11 = xMapY( srcY11 , tmpU , tmpV );
+
+      SYUVP dstUV = xMapUV( srcYaver , srcU , srcV );
+      pYDst[xY] = Clip3((Pel)0, iMaxValY, dstY00 );
+      pYDst[xY+1] = Clip3((Pel)0, iMaxValY, dstY01 );
+      pYDst[xY+nDstStrideY] = Clip3((Pel)0, iMaxValY, dstY10 );
+      pYDst[xY+nDstStrideY+1] = Clip3((Pel)0, iMaxValY, dstY11 );
+      pUDst[xC] = Clip3((Pel)0, iMaxValC, dstUV.U );
+      pVDst[xC] = Clip3((Pel)0, iMaxValC, dstUV.V );
+    }
+    pY += nStrideY + nStrideY;
+
+    // alignment
+    pUPrev = pU;
+    pVPrev = pV;
+    pU = pUNext;
+    pV = pVNext;
+    pUNext += nStrideC;
+    pVNext += nStrideC;
+
+    pYDst += nDstStrideY + nDstStrideY;
+    pUDst += nDstStrideC;
+    pVDst += nDstStrideC;
+  }
+}
+
+SYUVP TCom3DAsymLUT::xGetCuboidVertexPredA( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx )
+{
+  assert( nVertexIdx < 4 );
+  
+  SYUVP sPred;
+  sPred.Y = ( yIdx + m_nVertexIdxOffset[nVertexIdx][0] ) << ( m_nYShift2Idx + m_nDeltaBitDepth );
+  sPred.U = ( uIdx + m_nVertexIdxOffset[nVertexIdx][1] ) << ( m_nUShift2Idx + m_nDeltaBitDepthC );
+  sPred.V = ( vIdx + m_nVertexIdxOffset[nVertexIdx][2] ) << ( m_nVShift2Idx + m_nDeltaBitDepthC );
+  return( sPred );
+}
+
+SYUVP  TCom3DAsymLUT::xGetCuboidVertexPredAll( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx , SCuboid *** pCurCuboid )
+{
+  SCuboid***  pCuboid = pCurCuboid ? pCurCuboid : m_pCuboid ;
+
+  // PredA
+  SYUVP sPredA = xGetCuboidVertexPredA( yIdx , uIdx , vIdx , nVertexIdx );
+
+  // PredB
+  SYUVP sPredB; 
+  memset( &sPredB , 0 , sizeof( sPredB ) );
+  if( yIdx > 0 )
+  {
+    SYUVP & recNeighborP = pCuboid[yIdx-1][uIdx][vIdx].P[nVertexIdx];
+    SYUVP sPredNeighbor = xGetCuboidVertexPredA( yIdx - 1 , uIdx , vIdx , nVertexIdx );
+    sPredB.Y += recNeighborP.Y - sPredNeighbor.Y ;
+    sPredB.U += recNeighborP.U - sPredNeighbor.U ;
+    sPredB.V += recNeighborP.V - sPredNeighbor.V ;
+
+    Pel min = - ( 1 << ( getOutputBitDepthY() - 2 ) );
+    Pel max =  - min;
+    sPredB.Y = Clip3( min , max , sPredB.Y );
+    min = - ( 1 << ( getOutputBitDepthC() - 2 ) );
+    max =  - min;
+    sPredB.U = Clip3( min , max , sPredB.U );
+    sPredB.V = Clip3( min , max , sPredB.V );
+  }
+
+  SYUVP sPred;
+  sPred.Y = sPredA.Y + sPredB.Y;
+  sPred.U = sPredA.U + sPredB.U;
+  sPred.V = sPredA.V + sPredB.V;
+
+  return sPred ;
+}
+
+SYUVP TCom3DAsymLUT::getCuboidVertexResTree( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx )
+{
+  const SYUVP & rYUVP = m_pCuboid[yIdx][uIdx][vIdx].P[nVertexIdx];
+  SYUVP sPred = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , nVertexIdx );
+
+  SYUVP sResidue;
+  sResidue.Y = ( rYUVP.Y - sPred.Y ) >> m_nResQuanBit;
+  sResidue.U = ( rYUVP.U - sPred.U ) >> m_nResQuanBit;
+  sResidue.V = ( rYUVP.V - sPred.V ) >> m_nResQuanBit;
+  return( sResidue );
+}
+
+Void TCom3DAsymLUT::setCuboidVertexResTree( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx , Int deltaY , Int deltaU , Int deltaV )
+{
+  SYUVP & rYUVP = m_pCuboid[yIdx][uIdx][vIdx].P[nVertexIdx];
+  SYUVP sPred = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , nVertexIdx );
+
+  rYUVP.Y = sPred.Y + ( deltaY << m_nResQuanBit );
+  rYUVP.U = sPred.U + ( deltaU << m_nResQuanBit );
+  rYUVP.V = sPred.V + ( deltaV << m_nResQuanBit );
+}
+
+Pel TCom3DAsymLUT::xMapY( Pel y , Pel u , Pel v )
+{
+  const SCuboid & rCuboid = m_pCuboid[y>>m_nYShift2Idx][u>>m_nUShift2Idx][v>>m_nVShift2Idx];
+  Pel dstY = rCuboid.P[0].Y;
+  Int deltaY = y - ( y >> m_nYShift2Idx << m_nYShift2Idx );
+  Int deltaU = u - ( u >> m_nUShift2Idx << m_nUShift2Idx );
+  Int deltaV = v - ( v >> m_nVShift2Idx << m_nVShift2Idx );
+  dstY += ( Pel )( ( ( ( deltaY * ( rCuboid.P[3].Y - rCuboid.P[2].Y ) ) << m_nUShift2Idx ) 
+                   + ( ( deltaU * ( rCuboid.P[1].Y - rCuboid.P[0].Y ) ) << m_nYShift2Idx )
+                   + ( ( deltaV * ( rCuboid.P[2].Y - rCuboid.P[1].Y ) ) << m_nYShift2Idx ) 
+                   + m_nMappingOffset ) >> m_nMappingShift );
+  return( dstY );
+}
+
+SYUVP TCom3DAsymLUT::xMapUV( Pel y , Pel u , Pel v )
+{
+  const SCuboid & rCuboid = m_pCuboid[y>>m_nYShift2Idx][u>>m_nUShift2Idx][v>>m_nVShift2Idx];
+  SYUVP dst = rCuboid.P[0];
+  Int deltaY = y - ( y >> m_nYShift2Idx << m_nYShift2Idx );
+  Int deltaU = u - ( u >> m_nUShift2Idx << m_nUShift2Idx );
+  Int deltaV = v - ( v >> m_nVShift2Idx << m_nVShift2Idx );
+  dst.U += ( Pel )( ( ( ( deltaY * ( rCuboid.P[3].U - rCuboid.P[2].U ) ) << m_nUShift2Idx ) 
+                    + ( ( deltaU * ( rCuboid.P[1].U - rCuboid.P[0].U ) ) << m_nYShift2Idx )
+                    + ( ( deltaV * ( rCuboid.P[2].U - rCuboid.P[1].U ) ) << m_nYShift2Idx ) 
+                    + m_nMappingOffset ) >> m_nMappingShift );
+  dst.V += ( Pel )( ( ( ( deltaY * ( rCuboid.P[3].V - rCuboid.P[2].V ) ) << m_nUShift2Idx ) 
+                    + ( ( deltaU * ( rCuboid.P[1].V - rCuboid.P[0].V ) ) << m_nYShift2Idx )
+                    + ( ( deltaV * ( rCuboid.P[2].V - rCuboid.P[1].V ) ) << m_nYShift2Idx ) 
+                    + m_nMappingOffset ) >> m_nMappingShift );
+  return( dst );
+}
+
+Void TCom3DAsymLUT::xSaveCuboids( SCuboid *** pSrcCuboid )
+{
+  memcpy( m_pCuboid[0][0] , pSrcCuboid[0][0] , sizeof( SCuboid ) * m_nYSize * m_nUSize * m_nVSize );
+}
+
+Void TCom3DAsymLUT::copy3DAsymLUT( TCom3DAsymLUT * pSrc )
+{
+  assert( pSrc->getMaxOctantDepth() == getMaxOctantDepth() && pSrc->getMaxYPartNumLog2() == getMaxYPartNumLog2() );
+  xUpdatePartitioning( pSrc->getCurOctantDepth() , pSrc->getCurYPartNumLog2() );
+  setResQuantBit( pSrc->getResQuantBit() );
+  xSaveCuboids( pSrc->m_pCuboid );
+}
+
+#endif
+
Index: trunk/source/Lib/TLibCommon/TCom3DAsymLUT.h
===================================================================
--- trunk/source/Lib/TLibCommon/TCom3DAsymLUT.h	(revision 713)
+++ trunk/source/Lib/TLibCommon/TCom3DAsymLUT.h	(revision 713)
@@ -0,0 +1,135 @@
+
+#ifndef __TCOM3DASYMLUT__
+#define __TCOM3DASYMLUT__
+
+#include "TypeDef.h"
+
+#if Q0048_CGS_3D_ASYMLUT
+
+typedef struct _SYUVP
+{
+  Pel   Y , U , V;
+}SYUVP;
+
+typedef struct _SCuboid // vertexes for tetrahedral interpolation
+{
+  SYUVP P[4];     // YUV: P0(0,0,0), P1(0,1,0), P3(0,1,1), P7(1,1,1)
+}SCuboid;
+
+class TComPicYuv;
+
+class TCom3DAsymLUT
+{
+public:
+  TCom3DAsymLUT();
+  virtual ~TCom3DAsymLUT();
+
+  virtual Void  create( Int nMaxOctantDepth , Int nInputBitDepth , Int nInputBitDepthC , Int nOutputBitDepth , Int nOutputBitDepthC , Int nMaxYPartNumLog2 );
+  virtual Void  destroy();
+
+  Int   getMaxOctantDepth() { return m_nMaxOctantDepth; }
+  Int   getCurOctantDepth() { return m_nCurOctantDepth; }
+  Int   getInputBitDepthY()  { return m_nInputBitDepthY;  }
+  Int   getOutputBitDepthY()  { return m_nOutputBitDepthY;  }
+  Int   getInputBitDepthC()  { return m_nInputBitDepthC;  }
+  Int   getOutputBitDepthC()  { return m_nOutputBitDepthC;  }
+  Int   getResQuantBit()     { return m_nResQuanBit; }
+  Void  setResQuantBit(Int n){ m_nResQuanBit = n; }
+  Int   getMaxYPartNumLog2() { return m_nMaxYPartNumLog2; }
+  Int   getCurYPartNumLog2() { return m_nCurYPartNumLog2; }
+
+  Void  colorMapping( TComPicYuv * pcPicSrc,  TComPicYuv * pcPicDst );
+  Void  copy3DAsymLUT( TCom3DAsymLUT * pSrc );
+
+  SYUVP xGetCuboidVertexPredAll( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx , SCuboid *** pCurCuboid=NULL );
+  SYUVP getCuboidVertexResTree( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx );
+  Void  setCuboidVertexResTree( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx , Int deltaY , Int deltaU , Int deltaV );
+
+
+private:
+  Int   m_nMaxOctantDepth;
+  Int   m_nCurOctantDepth;
+  Int   m_nInputBitDepthY;
+  Int   m_nOutputBitDepthY;
+  Int   m_nInputBitDepthC;
+  Int   m_nOutputBitDepthC;
+  Int   m_nDeltaBitDepthC;
+  Int   m_nDeltaBitDepth;
+  Int   m_nMaxYPartNumLog2;
+  Int   m_nCurYPartNumLog2;
+  Int   m_nMaxPartNumLog2;
+  Int   m_nYSize;
+  Int   m_nUSize;
+  Int   m_nVSize;
+  Int   m_nYShift2Idx;
+  Int   m_nUShift2Idx;
+  Int   m_nVShift2Idx;
+  Int   m_nMappingShift;
+  Int   m_nMappingOffset;
+  Int   m_nResQuanBit;
+  SCuboid *** m_pCuboid;
+  const static Int m_nVertexIdxOffset[4][3];
+
+protected:
+  template <class T> 
+  Void xAllocate3DArray( T*** &p , Int xSize , Int ySize , Int zSize );
+  template <class T> 
+  Void xReset3DArray( T*** &p , Int xSize , Int ySize , Int zSize );
+  template <class T>
+  Void xFree3DArray( T *** &p );
+
+  Void  xUpdatePartitioning( Int nCurOctantDepth , Int nCurYPartNumLog2 );
+  SYUVP xGetCuboidVertexPredA( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx );
+  Pel   xMapY( Pel y , Pel u , Pel v );
+  SYUVP xMapUV( Pel y , Pel u , Pel v );
+  Int   xGetMaxPartNumLog2()  { return m_nMaxPartNumLog2; }
+  Int   xGetYSize()  { return m_nYSize;  }
+  Int   xGetUSize()  { return m_nUSize;  }
+  Int   xGetVSize()  { return m_nVSize;  }
+  Int   xGetYShift2Idx() { return m_nYShift2Idx; }
+  Int   xGetUShift2Idx() { return m_nUShift2Idx; }
+  Int   xGetVShift2Idx() { return m_nVShift2Idx; } 
+  SCuboid & xGetCuboid( Int yIdx , Int uIdx , Int vIdx ){ return m_pCuboid[yIdx][uIdx][vIdx];  }
+  Void  xSaveCuboids( SCuboid *** pSrcCuboid );
+};
+
+template <class T> 
+Void TCom3DAsymLUT::xAllocate3DArray( T *** &p , Int xSize , Int ySize , Int zSize )
+{
+  p = new T**[xSize];
+  p[0] = new T*[xSize*ySize];
+  for( Int x = 1 ; x < xSize ; x++ )
+    p[x] = p[x-1] + ySize;
+  p[0][0] = new T[xSize*ySize*zSize];
+  for( Int x = 0 ; x < xSize ; x++ )
+  {
+    for( Int y = 0 ; y < ySize ; y++ )
+      p[x][y] = p[0][0] + x * ySize * zSize + y * zSize;
+  }
+}
+
+template <class T>
+Void TCom3DAsymLUT::xFree3DArray( T *** &p )
+{
+  if( p != NULL )
+  {
+    if( p[0] != NULL )
+    {
+      if( p[0][0] != NULL )
+        delete [] p[0][0];
+      delete [] p[0];
+    }
+    delete [] p;
+    p = NULL;
+  }
+}
+
+template <class T>
+Void TCom3DAsymLUT::xReset3DArray( T*** &p , Int xSize , Int ySize , Int zSize )
+{
+  memset( p[0][0] , 0 , sizeof( T ) * xSize * ySize * zSize );
+}
+
+#endif
+
+#endif
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 713)
@@ -172,12 +172,18 @@
     memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
     memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
-#if ADAPTIVE_QP_SELECTION    
+#if ADAPTIVE_QP_SELECTION
     if( bGlobalRMARLBuffer )
     {
       if( m_pcGlbArlCoeffY == NULL )
       {
+#if LAYER_CTB
+        m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, MAX_CU_SIZE * MAX_CU_SIZE);
+        m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, MAX_CU_SIZE * MAX_CU_SIZE/4);
+        m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, MAX_CU_SIZE * MAX_CU_SIZE/4);
+#else
         m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
         m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
         m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
+#endif
       }
       m_pcArlCoeffY        = m_pcGlbArlCoeffY;
@@ -1690,68 +1696,4 @@
 }
 
-
-#if FAST_INTRA_SHVC
-/** generate limited set of remaining modes
-*\param   uiAbsPartIdx
-*\param   uiIntraDirPred  pointer to the array for MPM storage
-*\returns Number of intra coding modes (nb of remaining modes + 3 MPMs)
-*/
-Int TComDataCU::reduceSetOfIntraModes( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes )
-{
-  // check BL mode
-  UInt          uiCUAddrBase = 0, uiAbsPartAddrBase = 0;
-  // the right reference layerIdc should be specified, currently it is set to m_layerId-1
-  TComDataCU*   pcTempCU = getBaseColCU(m_layerId - 1, uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase, 0 );
-
-  if( pcTempCU->getPredictionMode( uiAbsPartAddrBase ) != MODE_INTRA )
-  {
-    return( NUM_INTRA_MODE-1 );
-  }
-
-  // compute set of enabled modes g_reducedSetIntraModes[...]
-  Int authorizedMode[NUM_INTRA_MODE-1]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
-  Int nbModes;
-  for (nbModes=0; nbModes<3; nbModes++)  // add 3 MPMs 1st
-  {
-    g_reducedSetIntraModes[nbModes] = uiIntraDirPred[nbModes];
-    authorizedMode[ uiIntraDirPred[nbModes] ] = 0;
-  }
-
-  Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
-  if ( authorizedMode[iColBaseDir] )  //possibly add BL mode
-  {
-    g_reducedSetIntraModes[nbModes++] = iColBaseDir;
-    authorizedMode[ iColBaseDir ] = 0;
-  }
-
-  Int iRefMode = ( iColBaseDir > 1 ) ? iColBaseDir : uiIntraDirPred[0];
-  if ( iRefMode > 1 )    //add neighboring modes of refMode
-  {
-    UInt Left  = iRefMode;
-    UInt Right = iRefMode;
-    while ( nbModes < NB_REMAIN_MODES+3 )
-    {
-      Left = ((Left + 29) % 32) + 2;
-      Right = ((Right - 1 ) % 32) + 2;
-      if ( authorizedMode[Left] )   g_reducedSetIntraModes[nbModes++] = Left;
-      if ( authorizedMode[Right] )  g_reducedSetIntraModes[nbModes++] = Right;
-    }
-  }
-  else      //add pre-defined modes
-  {
-    Int  idx = 0;
-    while ( nbModes < NB_REMAIN_MODES+3 )
-    {
-      UInt mode = g_predefSetIntraModes[idx++];
-      if ( authorizedMode[mode] )   g_reducedSetIntraModes[nbModes++] = mode;
-    }
-  }
-
-  fullSetOfModes = 0;
-  return ( nbModes );
-}
-#endif
-
-
 UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
 {
@@ -1809,67 +1751,4 @@
   return log2MinTUSizeInCU;
 }
-
-#if REF_IDX_ME_ZEROMV
-Bool TComDataCU::xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
-{
-  Bool checkZeroMVILR = true;
-
-  if(uhInterDir&0x1)  //list0
-  {
-    Int refIdxL0 = cMvFieldL0.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId))
-    {
-      checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
-    }
-  }
-  if(uhInterDir&0x2)  //list1
-  {
-    Int refIdxL1  = cMvFieldL1.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId))
-    {
-      checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
-    }
-  }
-
-  return checkZeroMVILR;
-}
-
-Bool TComDataCU::xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx)
-{
-  RefPicList eRefPicList = iRefList > 0? REF_PIC_LIST_1: REF_PIC_LIST_0;
-  assert(eRefPicList == REF_PIC_LIST_1);
-
-  Bool checkZeroMVILR = true;
-
-  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(m_layerId))
-  {
-    AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
-    TComMv    cMv        = pcAMVPInfo->m_acMvCand[MvpIdx];
-    checkZeroMVILR &= (cMv.getHor() == 0 && cMv.getVer() == 0);
-  }
-
-  return checkZeroMVILR;
-}
-#endif
-
-#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-Bool TComDataCU::isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
-{
-  Bool checkILR = false;
-
-  if(uhInterDir&0x1)  //list0
-  {
-    Int refIdxL0 = cMvFieldL0.getRefIdx();
-    checkILR = getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId);
-  }
-  if(uhInterDir&0x2)  //list1
-  {
-    Int refIdxL1  = cMvFieldL1.getRefIdx();
-    checkILR = checkILR || getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId);
-  }
-
-  return checkILR;
-}
-#endif
 
 UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
@@ -2168,5 +2047,5 @@
 }
 
-UChar TComDataCU::getNumPartInter()
+UChar TComDataCU::getNumPartitions()
 {
   UChar iNumPart = 0;
@@ -3612,5 +3491,5 @@
 TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping )
 {
-  TComPic* cBaseColPic = m_pcSlice->getBaseColPic(refLayerIdc);
+  TComPic* baseColPic = m_pcSlice->getBaseColPic(refLayerIdc);
 
   uiPelX = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getWidth() - 1, uiPelX);
@@ -3622,23 +3501,30 @@
 
 #if O0098_SCALED_REF_LAYER_ID
-  Int leftStartL = getSlice()->getSPS()->getScaledRefLayerWindowForLayer(getSlice()->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowLeftOffset();
-  Int topStartL  = getSlice()->getSPS()->getScaledRefLayerWindowForLayer(getSlice()->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowTopOffset();
+  Int leftStartL = baseColPic->getSlice(0)->getSPS()->getScaledRefLayerWindowForLayer(baseColPic->getSlice(0)->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowLeftOffset();
+  Int topStartL  = baseColPic->getSlice(0)->getSPS()->getScaledRefLayerWindowForLayer(baseColPic->getSlice(0)->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowTopOffset();
 #else
-  Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowLeftOffset();
-  Int topStartL  = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowTopOffset();
-#endif
+  Int leftStartL = baseColPic->getSlice(0)->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowLeftOffset();
+  Int topStartL  = baseColPic->getSlice(0)->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowTopOffset();
+#endif
+
+#if Q0200_CONFORMANCE_BL_SIZE
+  Int chromaFormatIdc = baseColPic->getSlice(0)->getChromaFormatIdc();
+  Int iBX = (((uiPelX - leftStartL)*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16) + baseColPic->getConformanceWindow().getWindowLeftOffset() * TComSPS::getWinUnitX( chromaFormatIdc );
+  Int iBY = (((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16) + baseColPic->getConformanceWindow().getWindowTopOffset() * TComSPS::getWinUnitY( chromaFormatIdc );
+#else
   Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
   Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
+#endif
 
 #if N0139_POSITION_ROUNDING_OFFSET
   if( iMotionMapping == 1 )
   {
-    iBX += 4;
-    iBY += 4;
-  }
-#endif
-
-  if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight() ||
-       iBX < 0                                        || iBY < 0                                           )
+    // actually, motion field compression is performed in the Void TComPic::compressMotion() function, but with (+4) the rounding may have effect on the picture boundary check.
+    iBX = ( ( iBX + 4 ) >> 4 ) << 4;
+    iBY = ( ( iBY + 4 ) >> 4 ) << 4;
+  }
+#endif
+
+  if ( iBX < 0 || iBX >= baseColPic->getPicYuvRec()->getWidth() || iBY < 0 || iBY >= baseColPic->getPicYuvRec()->getHeight() )
   {
     return NULL;
@@ -3646,21 +3532,21 @@
 
 #if LAYER_CTB
-  UInt baseMaxCUHeight = cBaseColPic->getPicSym()->getMaxCUHeight();
-  UInt baseMaxCUWidth  = cBaseColPic->getPicSym()->getMaxCUWidth();
-  UInt baseMinUnitSize = cBaseColPic->getMinCUWidth();
-  
-  uiCUAddrBase = ( iBY / cBaseColPic->getPicSym()->getMaxCUHeight() ) * cBaseColPic->getFrameWidthInCU() + ( iBX / cBaseColPic->getPicSym()->getMaxCUWidth() );
+  UInt baseMaxCUHeight = baseColPic->getPicSym()->getMaxCUHeight();
+  UInt baseMaxCUWidth  = baseColPic->getPicSym()->getMaxCUWidth();
+  UInt baseMinUnitSize = baseColPic->getMinCUWidth();
+  
+  uiCUAddrBase = ( iBY / baseMaxCUHeight ) * baseColPic->getFrameWidthInCU() + ( iBX / baseMaxCUWidth );
 #else
-  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
-#endif
-
-  assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
+  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*baseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
+#endif
+
+  assert(uiCUAddrBase < baseColPic->getNumCUsInFrame());
 
 #if LAYER_CTB
-  UInt uiRasterAddrBase = ( iBY - (iBY/baseMaxCUHeight)*baseMaxCUHeight ) / baseMinUnitSize * cBaseColPic->getNumPartInWidth() + ( iBX - (iBX/baseMaxCUWidth)*baseMaxCUWidth ) / baseMinUnitSize;
-  
-  uiAbsPartIdxBase = g_auiLayerRasterToZscan[cBaseColPic->getLayerId()][uiRasterAddrBase];
+  UInt uiRasterAddrBase = ( iBY - (iBY/baseMaxCUHeight)*baseMaxCUHeight ) / baseMinUnitSize * baseColPic->getNumPartInWidth() + ( iBX - (iBX/baseMaxCUWidth)*baseMaxCUWidth ) / baseMinUnitSize;
+  
+  uiAbsPartIdxBase = g_auiLayerRasterToZscan[baseColPic->getLayerId()][uiRasterAddrBase];
 #else
-  UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
+  UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*baseColPic->getNumPartInWidth()
     + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
 
@@ -3668,5 +3554,5 @@
 #endif
 
-  return cBaseColPic->getCU(uiCUAddrBase);
+  return baseColPic->getCU(uiCUAddrBase);
 }
 
@@ -3680,4 +3566,130 @@
   rcMvFieldEnhance.setMvField( cMv, rcMvFieldBase.getRefIdx() );
 }
+
+#if FAST_INTRA_SHVC
+/** generate limited set of remaining modes
+*\param   uiAbsPartIdx
+*\param   uiIntraDirPred  pointer to the array for MPM storage
+*\returns Number of intra coding modes (nb of remaining modes + 3 MPMs)
+*/
+Int TComDataCU::reduceSetOfIntraModes( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes )
+{
+  // check BL mode
+  UInt          uiCUAddrBase = 0, uiAbsPartAddrBase = 0;
+  // the right reference layerIdc should be specified, currently it is set to m_layerId-1
+  TComDataCU*   pcTempCU = getBaseColCU(m_layerId - 1, uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase, 0 );
+
+  if( pcTempCU->getPredictionMode( uiAbsPartAddrBase ) != MODE_INTRA )
+  {
+    return( NUM_INTRA_MODE-1 );
+  }
+
+  // compute set of enabled modes g_reducedSetIntraModes[...]
+  Int authorizedMode[NUM_INTRA_MODE-1]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
+  Int nbModes;
+  for (nbModes=0; nbModes<3; nbModes++)  // add 3 MPMs 1st
+  {
+    g_reducedSetIntraModes[nbModes] = uiIntraDirPred[nbModes];
+    authorizedMode[ uiIntraDirPred[nbModes] ] = 0;
+  }
+
+  Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
+  if ( authorizedMode[iColBaseDir] )  //possibly add BL mode
+  {
+    g_reducedSetIntraModes[nbModes++] = iColBaseDir;
+    authorizedMode[ iColBaseDir ] = 0;
+  }
+
+  Int iRefMode = ( iColBaseDir > 1 ) ? iColBaseDir : uiIntraDirPred[0];
+  if ( iRefMode > 1 )    //add neighboring modes of refMode
+  {
+    UInt Left  = iRefMode;
+    UInt Right = iRefMode;
+    while ( nbModes < NB_REMAIN_MODES+3 )
+    {
+      Left = ((Left + 29) % 32) + 2;
+      Right = ((Right - 1 ) % 32) + 2;
+      if ( authorizedMode[Left] )   g_reducedSetIntraModes[nbModes++] = Left;
+      if ( authorizedMode[Right] )  g_reducedSetIntraModes[nbModes++] = Right;
+    }
+  }
+  else      //add pre-defined modes
+  {
+    Int  idx = 0;
+    while ( nbModes < NB_REMAIN_MODES+3 )
+    {
+      UInt mode = g_predefSetIntraModes[idx++];
+      if ( authorizedMode[mode] )   g_reducedSetIntraModes[nbModes++] = mode;
+    }
+  }
+
+  fullSetOfModes = 0;
+  return ( nbModes );
+}
+#endif
+
+#if REF_IDX_ME_ZEROMV
+Bool TComDataCU::xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
+{
+  Bool checkZeroMVILR = true;
+
+  if(uhInterDir&0x1)  //list0
+  {
+    Int refIdxL0 = cMvFieldL0.getRefIdx();
+    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId))
+    {
+      checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
+    }
+  }
+  if(uhInterDir&0x2)  //list1
+  {
+    Int refIdxL1  = cMvFieldL1.getRefIdx();
+    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId))
+    {
+      checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
+    }
+  }
+
+  return checkZeroMVILR;
+}
+
+Bool TComDataCU::xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx)
+{
+  RefPicList eRefPicList = iRefList > 0? REF_PIC_LIST_1: REF_PIC_LIST_0;
+  assert(eRefPicList == REF_PIC_LIST_1);
+
+  Bool checkZeroMVILR = true;
+
+  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(m_layerId))
+  {
+    AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
+    TComMv    cMv        = pcAMVPInfo->m_acMvCand[MvpIdx];
+    checkZeroMVILR &= (cMv.getHor() == 0 && cMv.getVer() == 0);
+  }
+
+  return checkZeroMVILR;
+}
+#endif
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+Bool TComDataCU::isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
+{
+  Bool checkILR = false;
+
+  if(uhInterDir&0x1)  //list0
+  {
+    Int refIdxL0 = cMvFieldL0.getRefIdx();
+    checkILR = getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId);
+  }
+  if(uhInterDir&0x2)  //list1
+  {
+    Int refIdxL1  = cMvFieldL1.getRefIdx();
+    checkILR = checkILR || getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId);
+  }
+
+  return checkILR;
+}
+#endif
+
 #endif //SVC_EXTENSION
 //! \}
Index: trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 713)
@@ -352,5 +352,5 @@
   
   Void          getPartIndexAndSize   ( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight );
-  UChar         getNumPartInter       ();
+  UChar         getNumPartitions       ();
   Bool          isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth);
   
Index: trunk/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 713)
@@ -141,9 +141,4 @@
   Void    setAllMvField( TComMvField const & mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 );
 
-#if AVC_SYNTAX
-  Void           setMv    (TComMv cMv,  Int iIdx )         { m_pcMv    [iIdx] = cMv; }
-  Void           setRefIdx(Int iRefIdx, Int iIdx   )       { m_piRefIdx[iIdx] =  iRefIdx; }
-#endif
-
   Void setNumPartition( Int iNumPart )
   {
@@ -159,4 +154,9 @@
   
   Void compress(Char* pePredMode, Int scale); 
+
+#if AVC_SYNTAX
+  Void           setMv    (TComMv cMv,  Int iIdx )         { m_pcMv    [iIdx] = cMv; }
+  Void           setRefIdx(Int iRefIdx, Int iIdx   )       { m_piRefIdx[iIdx] =  iRefIdx; }
+#endif
 
 #if REF_IDX_MFM
Index: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 713)
@@ -89,4 +89,7 @@
   TComPicYuv*           m_pcFullPelBaseRec[MAX_LAYERS];    // upsampled base layer recontruction for difference domain inter prediction
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  Int                   m_nFrameBit;
+#endif
 
 public:
@@ -115,4 +118,5 @@
   UInt          getTLayer()                { return m_uiTLayer;   }
   Void          setTLayer( UInt uiTLayer ) { m_uiTLayer = uiTLayer; }
+
   Bool          getUsedByCurr()             { return m_bUsedByCurr; }
   Void          setUsedByCurr( Bool bUsed ) { m_bUsedByCurr = bUsed; }
@@ -219,4 +223,8 @@
 #endif
 
+#if Q0048_CGS_3D_ASYMLUT
+  Void  setFrameBit( Int n )  { m_nFrameBit = n;    }
+  Int   getFrameBit()         { return m_nFrameBit; }
+#endif
 };// END CLASS DEFINITION TComPic
 
Index: trunk/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 713)
@@ -174,6 +174,11 @@
   Int numCuInHeight = m_iPicHeight / m_iCuHeight + (m_iPicHeight % m_iCuHeight != 0);
   
+#if LAYER_CTB
+  m_iLumaMarginX    = uiMaxCUWidth  + 16; // for 16-byte alignment
+  m_iLumaMarginY    = uiMaxCUHeight + 16;  // margin for 8-tap filter and infinite padding
+#else
   m_iLumaMarginX    = g_uiMaxCUWidth  + 16; // for 16-byte alignment
   m_iLumaMarginY    = g_uiMaxCUHeight + 16;  // margin for 8-tap filter and infinite padding
+#endif
   
   m_apiPicBufY      = (Pel*)xMalloc( Pel, ( m_iPicWidth       + (m_iLumaMarginX  <<1)) * ( m_iPicHeight       + (m_iLumaMarginY  <<1)));
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 713)
@@ -447,5 +447,5 @@
   }
 
-  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
+  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ )
   {
     pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
@@ -768,7 +768,7 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag )
-{
-  m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, phaseAlignFlag );
+Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, Bool phaseAlignFlag )
+{
+  m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic, phaseAlignFlag );
 }
 #else
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 713)
@@ -121,5 +121,5 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, Bool phaseAlignFlag );
 #else
   Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
Index: trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 713)
@@ -112,6 +112,7 @@
     m_offsetClipTable[compIdx] = NULL;
   }
+#if !SAO_SGN_FUNC
   m_signTable = NULL; 
-
+#endif
   
   m_lineBufWidth = 0;
@@ -169,5 +170,8 @@
   }
 
+#if !SAO_SGN_FUNC
   //look-up table for clipping
+  Int overallMaxSampleValue=0;
+#endif
   for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
   {
@@ -179,4 +183,7 @@
     Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]); 
 #endif
+#if !SAO_SGN_FUNC
+    if (maxSampleValue>overallMaxSampleValue) overallMaxSampleValue=maxSampleValue;
+#endif
 
     m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0
@@ -194,18 +201,17 @@
       *(offsetClipPtr -k -1 )              = 0;
     }
-    if(compIdx == SAO_Y) //g_bitDepthY is always larger than or equal to g_bitDepthC
-    {
-      m_signTable = new Short[ 2*(maxSampleValue-1) + 1 ];
-      m_sign = &(m_signTable[maxSampleValue-1]);
-
-      m_sign[0] = 0;
-      for(Int k=1; k< maxSampleValue; k++)
-      {
-        m_sign[k] = 1;
-        m_sign[-k]= -1;
-      }
-    }
-  }  
-
+  }
+
+#if !SAO_SGN_FUNC
+  m_signTable = new Short[ 2*(overallMaxSampleValue-1) + 1 ];
+  m_sign = &(m_signTable[overallMaxSampleValue-1]);
+
+  m_sign[0] = 0;
+  for(Int k=1; k< overallMaxSampleValue; k++)
+  {
+    m_sign[k] = 1;
+    m_sign[-k]= -1;
+  }
+#endif
 }
 
@@ -226,8 +232,10 @@
     }
   }
+#if !SAO_SGN_FUNC
   if( m_signTable )
   {
     delete[] m_signTable; m_signTable = NULL;
   }
+#endif
 }
 
@@ -406,8 +414,16 @@
       for (y=0; y< height; y++)
       {
+#if SAO_SGN_FUNC
+        signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
+#else
         signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
+#endif
         for (x=startX; x< endX; x++)
         {
+#if SAO_SGN_FUNC
+          signRight = (Char)sgn(srcLine[x] - srcLine[x+1]); 
+#else
           signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 
+#endif
           edgeType =  signRight + signLeft;
           signLeft  = -signRight;
@@ -437,5 +453,9 @@
       for (x=0; x< width; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]);
+#else
         signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
+#endif
       }
 
@@ -447,5 +467,9 @@
         for (x=0; x< width; x++)
         {
+#if SAO_SGN_FUNC
+          signDown  = (Char)sgn(srcLine[x] - srcLineBelow[x]);
+#else
           signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 
+#endif
           edgeType = signDown + signUpLine[x];
           signUpLine[x]= -signDown;
@@ -474,5 +498,9 @@
       for (x=startX; x< endX+1; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x- 1]);
+#else
         signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x- 1]];
+#endif
       }
 
@@ -483,5 +511,9 @@
       for(x= firstLineStartX; x< firstLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType  =  sgn(srcLine[x] - srcLineAbove[x- 1]) - signUpLine[x+1];
+#else
         edgeType  =  m_sign[srcLine[x] - srcLineAbove[x- 1]] - signUpLine[x+1];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
       }
@@ -497,5 +529,9 @@
         for (x=startX; x<endX; x++)
         {
+#if SAO_SGN_FUNC
+          signDown =  (Char)sgn(srcLine[x] - srcLineBelow[x+ 1]);
+#else
           signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x+ 1]] ;
+#endif
           edgeType =  signDown + signUpLine[x];
           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
@@ -503,5 +539,9 @@
           signDownLine[x+1] = -signDown; 
         }
+#if SAO_SGN_FUNC
+        signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]);
+#else
         signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
+#endif
 
         signTmpLine  = signUpLine;
@@ -519,5 +559,9 @@
       for(x= lastLineStartX; x< lastLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType =  sgn(srcLine[x] - srcLineBelow[x+ 1]) + signUpLine[x];
+#else
         edgeType =  m_sign[srcLine[x] - srcLineBelow[x+ 1]] + signUpLine[x];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
 
@@ -537,5 +581,9 @@
       for (x=startX-1; x< endX; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]);
+#else
         signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
+#endif
       }
 
@@ -547,5 +595,9 @@
       for(x= firstLineStartX; x< firstLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) -signUpLine[x-1];
+#else
         edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] -signUpLine[x-1];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
       }
@@ -560,10 +612,18 @@
         for(x= startX; x< endX; x++)
         {
+#if SAO_SGN_FUNC
+          signDown =  (Char)sgn(srcLine[x] - srcLineBelow[x-1]);
+#else
           signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
+#endif
           edgeType =  signDown + signUpLine[x];
           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
           signUpLine[x-1] = -signDown; 
         }
+#if SAO_SGN_FUNC
+        signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]);
+#else
         signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
+#endif
         srcLine  += srcStride;
         resLine += resStride;
@@ -576,5 +636,9 @@
       for(x= lastLineStartX; x< lastLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + signUpLine[x];
+#else
         edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + signUpLine[x];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
 
Index: trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 713)
@@ -56,4 +56,10 @@
 extern UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
 #endif
+#if SAO_SGN_FUNC
+template <typename T> int sgn(T val) 
+{
+  return (T(0) < val) - (val < T(0));
+}
+#endif
 
 class TComSampleAdaptiveOffset
@@ -88,5 +94,7 @@
   UInt m_offsetStepLog2[NUM_SAO_COMPONENTS]; //offset step  
   Int* m_offsetClip[NUM_SAO_COMPONENTS]; //clip table for fast operation
+#if !SAO_SGN_FUNC
   Short* m_sign; //sign table for fast operation
+#endif
   TComPicYuv*   m_tempPicYuv; //temporary buffer
   Int m_picWidth;
@@ -105,5 +113,7 @@
   Bool m_picSAOEnabled[NUM_SAO_COMPONENTS];
   Int*   m_offsetClipTable[NUM_SAO_COMPONENTS];
+#if !SAO_SGN_FUNC
   Short* m_signTable;
+#endif
 #if SVC_EXTENSION
   UInt m_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 713)
@@ -75,4 +75,9 @@
 , m_pcPic                         ( NULL )
 , m_colFromL0Flag                 ( 1 )
+#if SETTING_NO_OUT_PIC_PRIOR
+, m_noOutputPriorPicsFlag         ( false )
+, m_noRaslOutputFlag              ( false )
+, m_handleCraAsBlaFlag            ( false )
+#endif
 , m_colRefIdx                     ( 0 )
 , m_uiTLayer                      ( 0 )
@@ -111,9 +116,4 @@
 , m_bCrossLayerBLAFlag            ( false )
 #endif
-#if NO_OUTPUT_OF_PRIOR_PICS
-, m_noOutputOfPriorPicsFlag       ( false )
-, m_noRaslOutputFlag              ( false )
-, m_handleCraAsBlaFlag            ( false )
-#endif
 #if POC_RESET_IDC_SIGNALLING
 , m_pocResetIdc                   ( 0 )
@@ -536,7 +536,8 @@
       {
         UInt refLayerIdc = m_interLayerPredLayerIdc[i];
+        UInt refLayerId = m_pcVPS->getRefLayerId( m_layerId, refLayerIdc );
 #if RESAMPLING_CONSTRAINT_BUG_FIX
 #if O0098_SCALED_REF_LAYER_ID
-        const Window &scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_pcVPS->getRefLayerId( m_layerId, m_interLayerPredLayerIdc[i] ));
+        const Window &scalEL = getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
 #else
         const Window &scalEL = getSPS()->getScaledRefLayerWindow(m_interLayerPredLayerIdc[i]);
@@ -548,8 +549,18 @@
                             );
 #endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+        Int sameBitDepth = g_bitDepthYLayer[m_layerId] - g_bitDepthYLayer[refLayerId] + g_bitDepthCLayer[m_layerId] - g_bitDepthCLayer[refLayerId];
+
+        if( !( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) || !scalingOffset || !sameBitDepth 
+#if Q0048_CGS_3D_ASYMLUT
+          || getPPS()->getCGSFlag()
+#endif
+          ) // ratio 1x
+#else
         if(!( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) || (!scalingOffset)) // ratio 1x
+#endif
         {
 #if MOTION_RESAMPLING_CONSTRAINT
-          UInt predType = m_pcVPS->getDirectDependencyType( m_layerId, m_pcVPS->getRefLayerId( m_layerId, refLayerIdc ) ) + 1;
+          UInt predType = m_pcVPS->getDirectDependencyType( m_layerId, refLayerId ) + 1;
 
           if( predType & 0x1 )
@@ -596,10 +607,10 @@
     // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
 #if SVC_EXTENSION    // inter-layer prediction is allowed for BLA, CRA pictures of nuh_layer_id>0
-    // – If the current picture is a BLA or CRA picture with nuh_layer_id equal to 0, the value of NumPocTotalCurr shall be equal to 0.
-    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // - If the current picture is a BLA or CRA picture with nuh_layer_id equal to 0, the value of NumPocTotalCurr shall be equal to 0.
+    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if (getRapPicFlag() && getLayerId()==0)
 #else
-    // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // - If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if (getRapPicFlag())
 #endif
@@ -1008,4 +1019,49 @@
  */
 #if NO_CLRAS_OUTPUT_FLAG
+Void TComSlice::decodingRefreshMarking( TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag )
+{
+  if( !isIRAP() )
+  {
+    return;
+  }
+
+  Int pocCurr = getPOC();
+  TComPic* rpcPic = NULL;
+
+  // When the current picture is an IRAP picture with nuh_layer_id equal to 0 and NoClrasOutputFlag is equal to 1, 
+  // all reference pictures with any value of nuh_layer_id currently in the DPB (if any) are marked as "unused for reference".
+  if( m_layerId == 0 && noClrasOutputFlag )
+  {
+    // mark all pictures for all layers as not used for reference
+    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
+    while( iterPic != rcListPic.end() )
+    {
+      rpcPic = *(iterPic);
+      if( rpcPic->getPOC() != pocCurr )
+      {
+        rpcPic->getSlice(0)->setReferenced(false);
+      }
+      iterPic++;
+    }
+  }
+
+  // When the current picture is an IRAP picture with NoRaslOutputFlag equal to 1, 
+  // all reference pictures with nuh_layer_id equal to currPicLayerId currently in the DPB (if any) are marked as "unused for reference".
+  if( m_noRaslOutputFlag )
+  {
+    // mark all pictures of a current layer as not used for reference
+    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
+    while( iterPic != rcListPic.end() )
+    {
+      rpcPic = *(iterPic);
+      if( rpcPic->getPOC() != pocCurr && rpcPic->getLayerId() == m_layerId )
+      {
+        rpcPic->getSlice(0)->setReferenced(false);
+      }
+      iterPic++;
+    }
+  }
+}
+
 Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag)
 #else
@@ -1051,7 +1107,31 @@
       pocCRA = pocCurr;
     }
+#if EFFICIENT_FIELD_IRAP
+    bRefreshPending = true;
+#endif
   }
   else // CRA or No DR
   {
+#if EFFICIENT_FIELD_IRAP
+    if(getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
+    {
+      if (bRefreshPending==true && pocCurr > m_iLastIDR) // IDR reference marking pending 
+      {
+        TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
+        while (iterPic != rcListPic.end())
+        {
+          rpcPic = *(iterPic);
+          if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != m_iLastIDR)
+          {
+            rpcPic->getSlice(0)->setReferenced(false);
+          }
+          iterPic++;
+        }
+        bRefreshPending = false; 
+      }
+    }
+    else
+    {
+#endif
     if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending 
     {
@@ -1068,4 +1148,7 @@
       bRefreshPending = false; 
     }
+#if EFFICIENT_FIELD_IRAP
+    }
+#endif
     if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
     {
@@ -1323,5 +1406,9 @@
     // in decoding order shall precede the IRAP picture in output order.
     // (Note that any picture following in output order would be present in the DPB)
+#if !SETTING_NO_OUT_PIC_PRIOR
     if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
+#else
+    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1 && !this->getNoOutputPriorPicsFlag())
+#endif
     {
       if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
@@ -1502,6 +1589,14 @@
 /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
 */
+#if ALLOW_RECOVERY_POINT_AS_RAP
+Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess, Bool bUseRecoveryPoint)
+#else
 Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess)
-{
+#endif
+{
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int atLeastOneUnabledByRecoveryPoint = 0;
+  Int atLeastOneFlushedByPreviousIDR = 0;
+#endif
   TComPic* rpcPic;
   Int i, isAvailable;
@@ -1524,5 +1619,16 @@
         if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
+        }
+#else
+          isAvailable = 1;
+#endif
         }
       }
@@ -1534,5 +1640,16 @@
         if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
+        }
+#else
+          isAvailable = 1;
+#endif
         }
       }
@@ -1557,7 +1674,20 @@
         if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
           rpcPic->setIsLongTerm(1);
           break;
+        }
+#else
+          isAvailable = 1;
+          rpcPic->setIsLongTerm(1);
+          break;
+#endif
         }
       }
@@ -1587,4 +1717,14 @@
         }
       }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+      {
+        atLeastOneUnabledByRecoveryPoint = 1;
+      }
+      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
+      {
+        atLeastOneFlushedByPreviousIDR = 1;
+      }
+#endif
     }
   }  
@@ -1602,5 +1742,16 @@
       if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
       {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+        if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+        {
+          isAvailable = 0;
+        }
+        else
+        {
         isAvailable = 1;
+      }
+#else
+        isAvailable = 1;
+#endif
       }
     }
@@ -1629,6 +1780,22 @@
         }
       }
-    }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+      {
+        atLeastOneUnabledByRecoveryPoint = 1;
+      }
+      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
+      {
+        atLeastOneFlushedByPreviousIDR = 1;
+      }
+#endif
+    }
+    }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(atLeastOneUnabledByRecoveryPoint || atLeastOneFlushedByPreviousIDR)
+  {
+    return -1;
   }    
+#endif
   if(atLeastOneLost)
   {
@@ -1647,5 +1814,9 @@
 /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
 */
+#if ALLOW_RECOVERY_POINT_AS_RAP
+Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess, Bool bUseRecoveryPoint)
+#else
 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
+#endif
 {
   TComPic* rpcPic;
@@ -1673,4 +1844,7 @@
         pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
         pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
+#if ALLOW_RECOVERY_POINT_AS_RAP
+        pcRPS->setUsed(k, pcRPS->getUsed(k) && !(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess) ); 
+#endif
         if(pcRPS->getDeltaPOC(k) < 0)
         {
@@ -1685,4 +1859,24 @@
     }
   }
+#if EFFICIENT_FIELD_IRAP
+  Bool useNewRPS = false;
+  // if current picture is complimentary field associated to IRAP, add the IRAP to its RPS. 
+  if(m_pcPic->isField())
+  {
+    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
+    while ( iterPic != rcListPic.end())
+    {
+      rpcPic = *(iterPic++);
+      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getAssociatedIRAPPOC() && this->getAssociatedIRAPPOC() == this->getPOC()+1)
+      {
+        pcRPS->setDeltaPOC(k, 1);
+        pcRPS->setUsed(k, true);
+        nrOfPositivePictures++;
+        k ++;
+        useNewRPS = true;
+      }
+    }
+  }
+#endif
   pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
   pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
@@ -1691,5 +1885,9 @@
   // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
   // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
-  if (!pReferencePictureSet->getInterRPSPrediction())
+  if (!pReferencePictureSet->getInterRPSPrediction()
+#if EFFICIENT_FIELD_IRAP
+    || useNewRPS
+#endif
+    )
   {
     pcRPS->setInterRPSPrediction(false);
@@ -1888,5 +2086,12 @@
   if( layerId == 0 )
   {
-    retVal = sps->getChromaFormatIdc();
+    if( vps->getAvcBaseLayerFlag() )
+    {
+      retVal = vps->getVpsRepFormat(layerId)->getChromaFormatVpsIdc();
+    }
+    else
+    {
+      retVal = sps->getChromaFormatIdc();
+    }
   }
   else
@@ -2034,5 +2239,9 @@
 #endif
 #if REPN_FORMAT_IN_VPS
+#if Q0195_REP_FORMAT_CLEANUP
+, m_repFormatIdxPresentFlag   (false)
+#else
 , m_repFormatIdxPresentFlag   (true)
+#endif
 , m_vpsNumRepFormats          (1)
 #endif
@@ -2306,11 +2515,11 @@
 Void TComVPS::setRefLayersFlags(Int currLayerId)
 {
-  for (Int i = 0; i < getNumDirectRefLayers(currLayerId); i++)
+  for (Int i = 0; i < m_numDirectRefLayers[currLayerId]; i++)
   {
     UInt refLayerId = getRefLayerId(currLayerId, i);
-    setRecursiveRefLayerFlag(currLayerId, refLayerId, true);
+    m_recursiveRefLayerFlag[currLayerId][refLayerId] = true;
     for (Int k = 0; k < MAX_NUM_LAYER_IDS; k++)
     {
-      setRecursiveRefLayerFlag(currLayerId, k, (getRecursiveRefLayerFlag(currLayerId, k) | getRecursiveRefLayerFlag(refLayerId, k)));
+      m_recursiveRefLayerFlag[currLayerId][k] = m_recursiveRefLayerFlag[currLayerId][k] | m_recursiveRefLayerFlag[refLayerId][k];
     }
   }
@@ -2319,11 +2528,11 @@
 Void TComVPS::setNumRefLayers(Int currLayerId)
 {
-  for (Int i = 0; i <= getMaxLayers(); i++)
-  {
-    UInt iNuhLId = getLayerIdInNuh(i);
+  for (Int i = 0; i < m_uiMaxLayers; i++)
+  {
+    UInt iNuhLId = m_layerIdInNuh[i];
     setRefLayersFlags(iNuhLId);
     for (UInt j = 0; j < MAX_NUM_LAYER_IDS; j++)
     {
-      m_numberRefLayers[iNuhLId] += (getRecursiveRefLayerFlag(iNuhLId, j) == true ? 1 : 0);
+      m_numberRefLayers[iNuhLId] += (m_recursiveRefLayerFlag[iNuhLId][j] == true ? 1 : 0);
     }
   }
@@ -3526,4 +3735,5 @@
 
     TComPic* pcRefPicBL = pcRefPicRL[refLayerIdc];
+
     //set reference picture POC of each ILP reference 
     Int thePoc = ilpPic[refLayerIdc]->getPOC(); 
@@ -3532,6 +3742,12 @@
     ilpPic[refLayerIdc]->getSlice(0)->setBaseColPic( refLayerIdc, pcRefPicBL );
 
-    //copy reference pictures marking from the reference layer
-    ilpPic[refLayerIdc]->getSlice(0)->copySliceInfo(pcRefPicBL->getSlice(0));
+    //copy layer id from the reference layer    
+    ilpPic[refLayerIdc]->setLayerId( pcRefPicBL->getLayerId() );
+
+    //copy slice type from the reference layer
+    ilpPic[refLayerIdc]->getSlice(0)->setSliceType( pcRefPicBL->getSlice(0)->getSliceType() );
+
+    //copy "used for reference"
+    ilpPic[refLayerIdc]->getSlice(0)->setReferenced( pcRefPicBL->getSlice(0)->isReferenced() );
 
     for( Int refList = 0; refList < 2; refList++ )
@@ -3555,4 +3771,10 @@
         ilpPic[refLayerIdc]->getSlice(0)->setRefPOC(0, refPicList, refIdx); 
         ilpPic[refLayerIdc]->getSlice(0)->setRefPic(NULL, refPicList, refIdx); 
+      }
+
+      //copy reference pictures' marking from the reference layer
+      for(Int j = 0; j < MAX_NUM_REF + 1; j++)
+      {
+        ilpPic[refLayerIdc]->getSlice(0)->setIsUsedAsLongTerm(refList, j, pcRefPicBL->getSlice(0)->getIsUsedAsLongTerm(refList, j));
       }
     }
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 713)
@@ -231,5 +231,5 @@
 {
   ProfileTierLevel m_generalPTL;
-  ProfileTierLevel m_subLayerPTL    [MAX_TLAYER-1];      // max. value of max_sub_layers_minus1 is MAX_TLAYER-1 ( = 6 )
+  ProfileTierLevel m_subLayerPTL    [MAX_TLAYER-1];      // max. value of max_sub_layers_minus1 is MAX_TLAYER-1 (= 6)
   Bool m_subLayerProfilePresentFlag [MAX_TLAYER-1];
   Bool m_subLayerLevelPresentFlag   [MAX_TLAYER-1];
@@ -581,5 +581,5 @@
 #if VPS_TSLAYERS
   Bool       m_maxTSLayersPresentFlag;
-  UInt       m_maxTSLayerMinus1[MAX_VPS_LAYER_ID_PLUS1 - 1];
+  UInt       m_maxTSLayerMinus1[MAX_LAYERS];
 #endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -684,4 +684,5 @@
   Bool       m_vpsVuiPresentFlag;
 #endif
+  Bool       m_vpsExtensionFlag;
 
 #if O0164_MULTI_LAYER_HRD
@@ -1131,7 +1132,9 @@
 
 #if O0109_MOVE_VPS_VUI_FLAG
-  Bool   getVpsVuiPresentFlag()                                 { return m_vpsVuiPresentFlag; }
-  Void   setVpsVuiPresentFlag(Bool x)                           { m_vpsVuiPresentFlag = x; }
-#endif
+  Bool   getVpsVuiPresentFlag()                        { return m_vpsVuiPresentFlag; }
+  Void   setVpsVuiPresentFlag(Bool x)                  { m_vpsVuiPresentFlag = x;    }
+#endif
+  Bool   getVpsExtensionFlag()                         { return m_vpsExtensionFlag;  }
+  Void   setVpsExtensionFlag(Bool x)                   { m_vpsExtensionFlag = x;     }
 
 #if !P0307_REMOVE_VPS_VUI_OFFSET
@@ -1741,4 +1744,9 @@
   Bool     m_pocResetInfoPresentFlag;
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  Int      m_nCGSFlag;
+  Int      m_nCGSOutputBitDepthY; // not for syntax
+  Int      m_nCGSOutputBitDepthC; // not for syntax
+#endif
 #endif
 
@@ -1881,4 +1889,12 @@
   Bool getPocResetInfoPresentFlag   ()                    { return m_pocResetInfoPresentFlag; }
   Void setPocResetInfoPresentFlag   (const Bool val)      { m_pocResetInfoPresentFlag = val; }
+#endif
+#if Q0048_CGS_3D_ASYMLUT
+  Int     getCGSFlag()                { return m_nCGSFlag;  }
+  Void    setCGSFlag(Int n)           { m_nCGSFlag = n;     }
+  Int     getCGSOutputBitDepthY()     { return m_nCGSOutputBitDepthY;  }
+  Void    setCGSOutputBitDepthY(Int n){ m_nCGSOutputBitDepthY = n;     }
+  Int     getCGSOutputBitDepthC()     { return m_nCGSOutputBitDepthC;  }
+  Void    setCGSOutputBitDepthC(Int n){ m_nCGSOutputBitDepthC = n;     }
 #endif
 };
@@ -1963,4 +1979,10 @@
   UInt        m_colFromL0Flag;  // collocated picture from List0 flag
   
+#if SETTING_NO_OUT_PIC_PRIOR
+  Bool        m_noOutputPriorPicsFlag;
+  Bool        m_noRaslOutputFlag;
+  Bool        m_handleCraAsBlaFlag;
+#endif
+  
   UInt        m_colRefIdx;
   UInt        m_maxNumMergeCand;
@@ -2030,9 +2052,4 @@
   Bool        m_bCrossLayerBLAFlag;
 #endif
-#if NO_OUTPUT_OF_PRIOR_PICS
-  Bool        m_noOutputOfPriorPicsFlag;
-  Bool        m_noRaslOutputFlag;
-  Bool        m_handleCraAsBlaFlag;
-#endif
 #if POC_RESET_IDC_SIGNALLING
   Int         m_pocResetIdc;
@@ -2043,4 +2060,7 @@
   Bool        m_pocMsbValRequiredFlag;
   Bool        m_pocMsbValPresentFlag;
+#endif
+#if Q0048_CGS_3D_ASYMLUT
+  Int        m_nCGSOverWritePPS;  // for optimization, not output to bitstream
 #endif
 #endif //SVC_EXTENSION
@@ -2130,12 +2150,9 @@
   NalUnitType getNalUnitType    () const                        { return m_eNalUnitType;        }
   Bool      getRapPicFlag       ();  
-#if NO_OUTPUT_OF_PRIOR_PICS
-  Bool      getBlaPicFlag       ();
-  Bool      getCraPicFlag       ();
-#endif
   Bool      getIdrPicFlag       ()                              { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
   Bool      isIRAP              () const                        { return (getNalUnitType() >= 16) && (getNalUnitType() <= 23); }  
   Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic);
 #if NO_CLRAS_OUTPUT_FLAG
+  Void      decodingRefreshMarking( TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag );
   Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag);
 #else
@@ -2163,4 +2180,8 @@
 #if SVC_EXTENSION
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false, TComPic** ilpPic = NULL );
+#if Q0048_CGS_3D_ASYMLUT
+  Int       getCGSOverWritePPS()              { return m_nCGSOverWritePPS;    }
+  Void      setCGSOverWritePPS(Int n)         { m_nCGSOverWritePPS = n;       }
+#endif
 #else
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false );
@@ -2203,9 +2224,25 @@
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
   Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic );
-  Int       checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0);
-  Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP);
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int  checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0, Bool bUseRecoveryPoint = false);
+  Void createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess = 0, Bool bUseRecoveryPoint = false);
+#else
+  Int  checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0);
+  Void createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP);
+#endif
 
   Void setMaxNumMergeCand               (UInt val )         { m_maxNumMergeCand = val;                    }
   UInt getMaxNumMergeCand               ()                  { return m_maxNumMergeCand;                   }
+
+#if SETTING_NO_OUT_PIC_PRIOR
+  Void setNoOutputPriorPicsFlag         ( Bool val )        { m_noOutputPriorPicsFlag = val;                    }
+  Bool getNoOutputPriorPicsFlag         ()                  { return m_noOutputPriorPicsFlag;                   }
+
+  Void setNoRaslOutputFlag              ( Bool val )        { m_noRaslOutputFlag = val;                    }
+  Bool getNoRaslOutputFlag              ()                  { return m_noRaslOutputFlag;                   }
+
+  Void setHandleCraAsBlaFlag            ( Bool val )        { m_handleCraAsBlaFlag = val;                    }
+  Bool getHandleCraAsBlaFlag            ()                  { return m_handleCraAsBlaFlag;                   }
+#endif
 
   Void setSliceMode                     ( UInt uiMode )     { m_sliceMode = uiMode;                     }
@@ -2360,15 +2397,4 @@
 
   Void setILRPic(TComPic **pcIlpPic);
-#if NO_OUTPUT_OF_PRIOR_PICS
-  Void setNoOutputOfPriorPicsFlag(const Bool x)   { m_noOutputOfPriorPicsFlag = x;    }
-  Bool getNoOutputOfPriorPicsFlag()               { return m_noOutputOfPriorPicsFlag; }
-
-  Void setNoRaslOutputFlag    ( const Bool val )   { m_noRaslOutputFlag = val;  }
-  Bool getNoRaslOutputFlag    ()                   { return m_noRaslOutputFlag; }
-
-  Void setHandleCraAsBlaFlag  ( const Bool val )   { m_handleCraAsBlaFlag = val;  }
-  Bool getHandleCraAsBlaFlag  ()                   { return m_handleCraAsBlaFlag; }
-
-#endif
 #if POC_RESET_IDC_SIGNALLING
   Int       getPocResetIdc       ()                              { return m_pocResetIdc;       }
@@ -2388,4 +2414,9 @@
 #endif
 
+#if NO_OUTPUT_OF_PRIOR_PICS
+  Bool      getBlaPicFlag       ();
+  Bool      getCraPicFlag       ();
+#endif
+
 #endif //SVC_EXTENSION
 protected:
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 713)
@@ -99,7 +99,7 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-Void TComUpsampleFilter::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
-#else
-Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
+Void TComUpsampleFilter::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, Bool phaseAlignFlag )
+#else
+Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag )
 #endif
 #else
@@ -116,7 +116,16 @@
   Int i, j;
 
+#if O0194_JOINT_US_BITSHIFT
+  UInt currLayerId = currSlice->getLayerId();
+  UInt refLayerId  = currSlice->getVPS()->getRefLayerId( currLayerId, refLayerIdc );
+#endif
+
+#if O0098_SCALED_REF_LAYER_ID
+  const Window &scalEL = currSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
+#else
+  const Window &scalEL = currSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
+#endif
+
   //========== Y component upsampling ===========
-  const Window &scalEL = window;
-
   Int widthBL   = pcBasePic->getWidth ();
   Int heightBL  = pcBasePic->getHeight();
@@ -127,4 +136,10 @@
   Int strideEL  = pcUsPic->getStride();
 
+#if Q0200_CONFORMANCE_BL_SIZE
+  Int chromaFormatIdc = currSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getChromaFormatIdc();
+  const Window &confBL = currSlice->getBaseColPic(refLayerIdc)->getConformanceWindow();
+  Int xScal = TComSPS::getWinUnitX( chromaFormatIdc );
+  Int yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+#endif
 #if P0312_VERT_PHASE_ADJ
   Bool vertPhasePositionEnableFlag = scalEL.getVertPhasePositionEnableFlag();
@@ -159,9 +174,4 @@
   Int scaleY = g_posScalingFactor[refLayerIdc][1];
 
-#if O0194_JOINT_US_BITSHIFT
-  UInt currLayerId = currSlice->getLayerId();
-  UInt refLayerId  = currSlice->getVPS()->getRefLayerId( currLayerId, refLayerIdc );
-#endif
-
   // non-normative software optimization for certain simple resampling cases
   if( scaleX == 65536 && scaleY == 65536 ) // ratio 1x
@@ -172,4 +182,11 @@
 #if O0194_JOINT_US_BITSHIFT
     Int shift = g_bitDepthYLayer[currLayerId] - g_bitDepthYLayer[refLayerId];
+#if Q0048_CGS_3D_ASYMLUT
+    if( currSlice->getPPS()->getCGSFlag() )
+    {
+      shift = g_bitDepthYLayer[currLayerId] - currSlice->getPPS()->getCGSOutputBitDepthY();
+    }
+    assert( shift >= 0 );
+#endif
 #endif
 
@@ -205,4 +222,10 @@
 #if O0194_JOINT_US_BITSHIFT
     shift = g_bitDepthCLayer[currLayerId] - g_bitDepthCLayer[refLayerId];
+#if Q0048_CGS_3D_ASYMLUT
+    if( currSlice->getPPS()->getCGSFlag() )
+    {
+      shift = g_bitDepthCLayer[currLayerId] - currSlice->getPPS()->getCGSOutputBitDepthC();
+    }
+#endif
 #endif
 
@@ -254,5 +277,9 @@
     Int   phaseX = 2*phaseAlignFlag;
 #if P0312_VERT_PHASE_ADJ
+#if Q0120_PHASE_CALCULATION
+    Int   phaseY = 2*phaseAlignFlag;
+#else
     Int   phaseY = vertPhasePositionEnableFlag ? ( vertPhasePositionFlag * 4 ) : ( 2 * phaseAlignFlag );
+#endif
 #else
     Int   phaseY = 2*phaseAlignFlag;
@@ -261,29 +288,43 @@
     Int   phaseX = 0;
 #if P0312_VERT_PHASE_ADJ
+#if Q0120_PHASE_CALCULATION
+    Int   phaseY = 0;
+#else
     Int   phaseY = (vertPhasePositionEnableFlag?(vertPhasePositionFlag *4):(0));
+#endif
 #else
     Int   phaseY = 0;
 #endif
 #endif
-
+ 
 #if ROUNDING_OFFSET
     Int   addX = ( ( phaseX * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
     Int   addY = ( ( phaseY * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
 #else
-    Int   addX       = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
-    Int   addY       = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
-#endif
-
-    Int   deltaX     = 4 * phaseX;
-    Int   deltaY     = 4 * phaseY;
+    Int   addX = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
+    Int   addY = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
+#endif
+
+#if Q0120_PHASE_CALCULATION
+    Int   deltaX = (Int)phaseAlignFlag <<3;
+    Int   deltaY = (((Int)phaseAlignFlag <<3)>>(Int)vertPhasePositionEnableFlag) + ((Int)vertPhasePositionFlag<<3);
+#else
+    Int   deltaX = 4 * phaseX;
+    Int   deltaY = 4 * phaseY;
+#endif
+
+#if Q0200_CONFORMANCE_BL_SIZE
+    deltaX -= ( confBL.getWindowLeftOffset() * xScal ) << 4;
+    deltaY -= ( confBL.getWindowTopOffset() * yScal ) << 4;
+#endif
 
     Int shiftXM4 = shiftX - 4;
     Int shiftYM4 = shiftY - 4;
 
-    widthEL   = pcUsPic->getWidth ();
-    heightEL  = pcUsPic->getHeight();
-
-    widthBL   = pcBasePic->getWidth ();
-    heightBL  = min<Int>( pcBasePic->getHeight(), heightEL );
+    widthEL  = pcUsPic->getWidth ();
+    heightEL = pcUsPic->getHeight();
+
+    widthBL  = pcBasePic->getWidth ();
+    heightBL = min<Int>( pcBasePic->getHeight(), heightEL );
 
     Int leftStartL = scalEL.getWindowLeftOffset();
@@ -292,9 +333,14 @@
     Int bottomEndL = pcUsPic->getHeight() - scalEL.getWindowBottomOffset();
     Int leftOffset = leftStartL > 0 ? leftStartL : 0;
-
 #if N0214_INTERMEDIATE_BUFFER_16BITS
 #if O0194_JOINT_US_BITSHIFT
     // g_bitDepthY was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
     Int shift1 = g_bitDepthYLayer[refLayerId] - 8;
+#if Q0048_CGS_3D_ASYMLUT
+    if( currSlice->getPPS()->getCGSFlag() )
+    {
+      shift1 = currSlice->getPPS()->getCGSOutputBitDepthY() - 8;
+    }
+#endif
 #else
     Int shift1 = g_bitDepthY - 8;
@@ -380,5 +426,4 @@
     widthBL   = pcBasePic->getWidth ();
     heightBL  = pcBasePic->getHeight();
-
     widthEL   = pcUsPic->getWidth () - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
     heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
@@ -400,5 +445,4 @@
     Int bottomEndC = (pcUsPic->getHeight() >> 1) - (scalEL.getWindowBottomOffset() >> 1);
     leftOffset = leftStartC > 0 ? leftStartC : 0;
-
     shiftX = 16;
     shiftY = 16;
@@ -407,5 +451,9 @@
     Int phaseXC = phaseAlignFlag;
 #if P0312_VERT_PHASE_ADJ
+#if Q0120_PHASE_CALCULATION
+    Int phaseYC = phaseAlignFlag + 1;
+#else
     Int phaseYC = vertPhasePositionEnableFlag ? ( vertPhasePositionFlag * 4 ) : ( phaseAlignFlag + 1 );
+#endif
 #else
     Int phaseYC = phaseAlignFlag + 1;
@@ -414,5 +462,9 @@
     Int phaseXC = 0;
 #if P0312_VERT_PHASE_ADJ
+#if Q0120_PHASE_CALCULATION
+    Int phaseYC = 1;
+#else
     Int phaseYC = vertPhasePositionEnableFlag ? (vertPhasePositionFlag * 4): 1;
+#endif
 #else
     Int phaseYC = 1;
@@ -428,6 +480,16 @@
 #endif
 
+#if Q0120_PHASE_CALCULATION
+    deltaX     = (Int)phaseAlignFlag << 2;
+    deltaY     = ((( (Int)phaseAlignFlag +1)<<2)>>(Int)vertPhasePositionEnableFlag)+((Int)vertPhasePositionFlag<<3);
+#else
     deltaX     = 4 * phaseXC;
     deltaY     = 4 * phaseYC;
+#endif
+
+#if Q0200_CONFORMANCE_BL_SIZE
+    deltaX -= ( ( confBL.getWindowLeftOffset() * xScal ) >> 1 ) << 4;
+    deltaY  -= ( ( confBL.getWindowTopOffset() * yScal ) >> 1 ) << 4;
+#endif
 
     shiftXM4 = shiftX - 4;
@@ -444,4 +506,10 @@
     // g_bitDepthC was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
     shift1 = g_bitDepthCLayer[refLayerId] - 8;
+#if Q0048_CGS_3D_ASYMLUT
+    if( currSlice->getPPS()->getCGSFlag() )
+    {
+      shift1 = currSlice->getPPS()->getCGSOutputBitDepthC() - 8;
+    }
+#endif
 #else
     shift1 = g_bitDepthC - 8;
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 649)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 713)
@@ -45,5 +45,5 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, Bool phaseAlignFlag );
 #else
   Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 649)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 713)
@@ -42,5 +42,4 @@
 
 #define SYNTAX_BYTES                     10      ///< number of bytes taken by syntaxes per 4x4 block [RefIdxL0(1byte), RefIdxL1(1byte), MVxL0(2bytes), MVyL0(2bytes), MVxL1(2bytes), MVyL1(2bytes)]
-
 #if SVC_EXTENSION
 #define MAX_LAYERS                       8      ///< max number of layers the codec is supposed to handle
@@ -50,5 +49,9 @@
 #define O0137_MAX_LAYERID                1      ///< JCTVC-O0137, JCTVC-O0200, JCTVC-O0223: restrict nuh_layer_id and vps_max_layers_minus1
 
+#define Q0200_CONFORMANCE_BL_SIZE        1       ///< JCTVC-Q0200; use conformance picture size in re-sampling processs
 #define P0312_VERT_PHASE_ADJ             1      ///< JCTVC-P0312: vertical phase adjustment in re-sampling process (BoG report)
+#if P0312_VERT_PHASE_ADJ
+#define Q0120_PHASE_CALCULATION          1      ///< JCTVC-Q0120 phase offset derivation for combination of spatial scalibility and field coding.
+#endif
 #define P0130_EOB                        1      ///< JCTVC-P0130, set layer Id of EOB NALU to be fixed to 0
 #define P0307_REMOVE_VPS_VUI_OFFSET      1      ///< JCTVC-P0307, remove implementation related to VPS VUI offset signalling
@@ -81,4 +84,5 @@
 
 #define O0164_MULTI_LAYER_HRD            1      ///< JCTVC-O0164: Multi-layer HRD operation
+#define Q0074_SEI_COLOR_MAPPING          1      ///< JCTVC-Q0074, SEI Color Mapping
 
 #define O0194_DIFFERENT_BITDEPTH_EL_BL   1      ///< JCTVC-O0194: Support for different bitdepth values for BL and EL, add required configuration parameters (and Some bugfixes when REPN_FORMAT_IN_VPS (JCTVC-N0092) is enabled)
@@ -86,5 +90,10 @@
 #define O0194_JOINT_US_BITSHIFT          1      ///< JCTVC-O0194: Joint Upsampling and bit-shift
 #endif
+#define Q0048_CGS_3D_ASYMLUT             1      ///< JCTVC-Q0048: Colour gamut scalability with look-up table
+#if Q0048_CGS_3D_ASYMLUT
+#define O0194_WEIGHTED_PREDICTION_CGS    0
+#else
 #define O0194_WEIGHTED_PREDICTION_CGS    1      ///< JCTVC-O0194: Weighted prediciton for color gamut scalability
+#endif
 #define MFM_ENCCONSTRAINT                1      ///< JCTVC-O0216: Encoder constraint for motion field mapping
 #define VPS_NUH_LAYER_ID                 1      ///< JCTVC-N0085: Assert that the nuh_layer_id of VPS NAL unit should be 0
@@ -185,4 +194,5 @@
 #define TSLAYERS_IL_RPS                  1      ///< JCTVC-O0120 IL RPS based on max temporal sub-layers
 #define P0079_DERIVE_NUMACTIVE_REF_PICS  1      ///< JCTVC-P0079 Modification of derivation of variable NumActiveRefLayerPics
+#define Q0060_MAX_TID_REF_EQUAL_TO_ZERO  1      ///< JCTVC-Q0060 handling the case max_tid_il_ref_pics_plus1 is equal to 0.
 #if REF_IDX_MFM
 #define N0139_POSITION_ROUNDING_OFFSET   1      ///< JCTVC-N0139: offset for collocated block in motion mapping
@@ -226,4 +236,7 @@
 #define O0096_DEFAULT_DEPENDENCY_TYPE    1      ///< JCTVC-O0096: specify default dependency type for all direct reference layers
 
+#define Q0195_REP_FORMAT_CLEANUP         1      ///< JCTVC-Q0195: restructureing of rep_format() signaling
+#define REP_FORMAT_FIX                   1      ///< update_rep_format_flag should be inferred to be equal to 0
+
 #define RESAMPLING_CONSTRAINT_BUG_FIX    1
 #define O0098_SCALED_REF_LAYER_ID        1      ///< JCTVC-O0098: signal scaled reference id
@@ -231,4 +244,7 @@
 #define O0153_ALT_OUTPUT_LAYER_FLAG      1      ///< JCTVC-O0153: alt output layer flag
 #define P0300_ALT_OUTPUT_LAYER_FLAG      1      ///< JCTVC-P0300: alt output layer flag
+
+#define Q0165_OUTPUT_LAYER_SET           1      ///< JCTVC-Q0165: add a constraint to disallow an empty output layer set
+#define Q0165_NUM_ADD_OUTPUT_LAYER_SETS  1      ///< JCTVC-Q0165: signal num_add_output_layer_set and default_target_output_layer_idc when vps_num_layer_sets_minus1 is greater than 0
 
 #define VPS_DPB_SIZE_TABLE               1      ///< JCTVC-O0217: DPB operations: signaling DPB-related parameters
@@ -264,8 +280,22 @@
 //! \ingroup TLibCommon
 //! \{
+#define HARMONIZE_GOP_FIRST_FIELD_COUPLE  1
+#define FIX_FIELD_DEPTH                 1
+#define EFFICIENT_FIELD_IRAP            1
+#define ALLOW_RECOVERY_POINT_AS_RAP     1
 #define BUGFIX_INTRAPERIOD 1
 #define SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1
 
+#define SAO_SGN_FUNC 1
+
 #define FIX1172 1 ///< fix ticket #1172
+
+#define SETTING_PIC_OUTPUT_MARK     1
+#define SETTING_NO_OUT_PIC_PRIOR    1
+#define FIX_EMPTY_PAYLOAD_NAL       1
+#define FIX_WRITING_OUTPUT          1
+#define FIX_OUTPUT_EOS              1
+
+#define FIX_POC_CRA_NORASL_OUTPUT   1
 
 #define MAX_NUM_PICS_IN_SOP           1024
Index: trunk/source/Lib/TLibDecoder/AnnexBread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/AnnexBread.h	(revision 649)
+++ trunk/source/Lib/TLibDecoder/AnnexBread.h	(revision 713)
@@ -65,5 +65,5 @@
   , m_Input(istream)
   {
-    istream.exceptions(std::istream::eofbit);
+    istream.exceptions(std::istream::eofbit | std::istream::badbit);
   }
 
Index: trunk/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 649)
+++ trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 713)
@@ -93,4 +93,9 @@
     fprintf( g_hTrace, "===========Tone Mapping Info SEI message ===========\n");
     break;
+#if Q0074_SEI_COLOR_MAPPING
+  case SEI::COLOR_MAPPING_INFO:
+    fprintf( g_hTrace, "===========Color Mapping Info SEI message ===========\n");
+    break;
+#endif
   case SEI::SOP_DESCRIPTION:
     fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
@@ -280,4 +285,10 @@
       xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
       break;
+#if Q0074_SEI_COLOR_MAPPING
+    case SEI::COLOR_MAPPING_INFO:
+      sei = new SEIColorMappingInfo;
+      xParseSEIColorMappingInfo((SEIColorMappingInfo&) *sei, payloadSize);
+      break;
+#endif
     case SEI::SOP_DESCRIPTION:
       sei = new SEISOPDescription;
@@ -518,21 +529,16 @@
 {
   UInt val; 
-  READ_CODE(4, val, "active_vps_id");      sei.activeVPSId = val; 
-  READ_FLAG( val, "full_random_access_flag");  sei.m_fullRandomAccessFlag = val ? true : false;
-  READ_FLAG( val, "no_param_set_update_flag"); sei.m_noParamSetUpdateFlag = val ? true : false;
+  READ_CODE(4, val, "active_video_parameter_set_id");   sei.activeVPSId = val; 
+  READ_FLAG(   val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag = val ? true : false;
+  READ_FLAG(   val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = val ? true : false;
   READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
 
-  sei.activeSeqParamSetId.resize(sei.numSpsIdsMinus1 + 1);
+  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
   for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
   {
-    READ_UVLC(val, "active_seq_param_set_id");  sei.activeSeqParamSetId[i] = val; 
-  }
-
-  UInt uibits = m_pcBitstream->getNumBitsUntilByteAligned(); 
-  
-  while(uibits--)
-  {
-    READ_FLAG(val, "alignment_bit");
-  }
+    READ_UVLC(val, "active_seq_parameter_set_id");      sei.activeSeqParameterSetId[i] = val; 
+  }
+
+  xParseByteAlign();
 }
 
@@ -812,8 +818,13 @@
     case 4:
       {
-        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedValue = val;
-        if( sei.m_cameraIsoSpeedValue == 255) //Extended_ISO
+        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
+        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
         {
           READ_CODE( 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
+        }
+        READ_CODE( 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
+        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
+        {
+          READ_CODE( 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
         }
         READ_FLAG( val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
@@ -837,4 +848,91 @@
   xParseByteAlign();
 }
+
+#if Q0074_SEI_COLOR_MAPPING
+Void SEIReader::xParseSEIColorMappingInfo(SEIColorMappingInfo& sei, UInt /*payloadSize*/)
+{
+  UInt  uiVal;
+  Int   iVal;
+
+  READ_UVLC( uiVal, "colour_map_id" );          sei.m_colorMapId = uiVal;
+  READ_FLAG( uiVal, "colour_map_cancel_flag" ); sei.m_colorMapCancelFlag = uiVal;
+  if( !sei.m_colorMapCancelFlag ) 
+  {
+    READ_FLAG( uiVal, "colour_map_persistence_flag" );                sei.m_colorMapPersistenceFlag = uiVal;
+    READ_FLAG( uiVal, "colour_map_video_signal_type_present_flag" );  sei.m_colorMap_video_signal_type_present_flag = uiVal;
+    if ( sei.m_colorMap_video_signal_type_present_flag ) {
+      READ_FLAG( uiVal,     "colour_map_video_full_range_flag" );     sei.m_colorMap_video_full_range_flag = uiVal;
+      READ_CODE( 8, uiVal,  "colour_map_primaries" );                 sei.m_colorMap_primaries = uiVal;
+      READ_CODE( 8, uiVal,  "colour_map_transfer_characteristics" );  sei.m_colorMap_transfer_characteristics = uiVal;
+      READ_CODE( 8, uiVal,  "colour_map_matrix_coeffs" );             sei.m_colorMap_matrix_coeffs = uiVal;
+    }
+  }
+
+  READ_CODE( 5, uiVal,  "colour_map_coded_data_bit_depth" );  sei.m_colour_map_coded_data_bit_depth = uiVal;
+  READ_CODE( 5, uiVal,  "colour_map_target_bit_depth" );      sei.m_colour_map_target_bit_depth = uiVal;
+  READ_UVLC( uiVal, "colour_map_model_id" );                  sei.m_colorMapModelId = uiVal;
+
+  assert( sei.m_colorMapModelId == 0 );
+  
+  for( Int i=0 ; i<3 ; i++ )
+  {
+    READ_CODE( 8, uiVal, "num_input_pivots_minus1[i]" ); sei.m_num_input_pivots[i] = (uiVal==0) ? 2 : (uiVal + 1) ;
+    sei.m_coded_input_pivot_value[i]   = new Int[ sei.m_num_input_pivots[i] ];
+    sei.m_target_input_pivot_value[i]  = new Int[ sei.m_num_input_pivots[i] ];
+    if( uiVal > 0 )
+    {
+      for ( Int j=0 ; j<sei.m_num_input_pivots[i] ; j++ )
+      {
+        READ_CODE( (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, uiVal, "coded_input_pivot_value[i][j]" );  sei.m_coded_input_pivot_value[i][j] = uiVal;
+        READ_CODE( (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, uiVal, "target_input_pivot_value[i][j]" ); sei.m_target_input_pivot_value[i][j] = uiVal;
+      }
+    }
+    else
+    {
+      sei.m_coded_input_pivot_value[i][0]  = 0;
+      sei.m_target_input_pivot_value[i][0] = 0;
+      sei.m_coded_input_pivot_value[i][1]  = (1 << sei.m_colour_map_coded_data_bit_depth) - 1 ;
+      sei.m_target_input_pivot_value[i][1] = (1 << sei.m_colour_map_target_bit_depth) - 1 ;
+    }
+  }
+
+  READ_FLAG( uiVal,           "matrix_flag" ); sei.m_matrix_flag = uiVal;
+  if( sei.m_matrix_flag )
+  {
+    READ_CODE( 4, uiVal,         "log2_matrix_denom" ); sei.m_log2_matrix_denom = uiVal;
+    for ( Int i=0 ; i<3 ; i++ )
+    {
+      for ( Int j=0 ; j<3 ; j++ )
+      {
+        READ_SVLC( iVal,        "matrix_coef[i][j]" ); sei.m_matrix_coef[i][j] = iVal;
+      }
+    }
+  }
+
+  for ( Int i=0 ; i<3 ; i++ )
+  {
+    READ_CODE( 8, uiVal, "num_output_pivots_minus1[i]" ); sei.m_num_output_pivots[i] = (uiVal==0) ? 2 : (uiVal + 1) ;
+    sei.m_coded_output_pivot_value[i]   = new Int[ sei.m_num_output_pivots[i] ];
+    sei.m_target_output_pivot_value[i]  = new Int[ sei.m_num_output_pivots[i] ];
+    if( uiVal > 0 )
+    {
+      for ( Int j=0 ; j<sei.m_num_output_pivots[i] ; j++ )
+      {
+        READ_CODE( (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, uiVal, "coded_output_pivot_value[i][j]" );  sei.m_coded_output_pivot_value[i][j] = uiVal;
+        READ_CODE( (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, uiVal, "target_output_pivot_value[i][j]" ); sei.m_target_output_pivot_value[i][j] = uiVal;
+      }
+    }
+    else
+    {
+      sei.m_coded_output_pivot_value[i][0]  = 0;
+      sei.m_target_output_pivot_value[i][0] = 0;
+      sei.m_coded_output_pivot_value[i][1]  = (1 << sei.m_colour_map_coded_data_bit_depth) - 1 ;
+      sei.m_target_output_pivot_value[i][1] = (1 << sei.m_colour_map_target_bit_depth) - 1 ;
+    }
+  }
+
+  xParseByteAlign();
+}
+#endif
 
 Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize)
Index: trunk/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.h	(revision 649)
+++ trunk/source/Lib/TLibDecoder/SEIread.h	(revision 713)
@@ -90,4 +90,7 @@
   Void xParseSEIGradualDecodingRefreshInfo (SEIGradualDecodingRefreshInfo &sei, UInt payloadSize);
   Void xParseSEIToneMappingInfo       (SEIToneMappingInfo& sei, UInt payloadSize);
+#if Q0074_SEI_COLOR_MAPPING
+  Void xParseSEIColorMappingInfo      (SEIColorMappingInfo& sei, UInt payloadSize);
+#endif
   Void xParseSEISOPDescription        (SEISOPDescription &sei, UInt payloadSize);
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 649)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 713)
@@ -39,4 +39,7 @@
 #include "SEIread.h"
 #include "TDecSlice.h"
+#if Q0048_CGS_3D_ASYMLUT
+#include "../TLibCommon/TCom3DAsymLUT.h"
+#endif
 
 //! \ingroup TLibDecoder
@@ -175,5 +178,9 @@
 }
 
-Void TDecCavlc::parsePPS(TComPPS* pcPPS)
+Void TDecCavlc::parsePPS(TComPPS* pcPPS
+#if Q0048_CGS_3D_ASYMLUT
+  , TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID
+#endif
+  )
 {
 #if ENC_DEC_TRACE
@@ -348,4 +355,14 @@
       READ_FLAG( uiCode, "poc_reset_info_present_flag" );
       pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
+#if Q0048_CGS_3D_ASYMLUT
+      READ_FLAG( uiCode , "colour_mapping_enabled_flag" ); 
+      pcPPS->setCGSFlag( uiCode );
+      if( pcPPS->getCGSFlag() )
+      {
+        xParse3DAsymLUT( pc3DAsymLUT );
+        pcPPS->setCGSOutputBitDepthY( pc3DAsymLUT->getOutputBitDepthY() );
+        pcPPS->setCGSOutputBitDepthC( pc3DAsymLUT->getOutputBitDepthC() );
+      }
+#endif
 #endif
     }
@@ -599,5 +616,9 @@
   else
   {
+#if REP_FORMAT_FIX
+    pcSPS->setUpdateRepFormatFlag( false );
+#else
     pcSPS->setUpdateRepFormatFlag( true );
+#endif
   }
 #if O0096_REP_FORMAT_INDEX
@@ -681,9 +702,9 @@
     for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
     {
-      READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
+      READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
       pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
-      READ_UVLC ( uiCode, "sps_num_reorder_pics" );
+      READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
       pcSPS->setNumReorderPics(uiCode, i);
-      READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
+      READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
       pcSPS->setMaxLatencyIncrease( uiCode, i );
 
@@ -887,5 +908,5 @@
   READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
 #endif
-  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 ); assert(uiCode <= 6);
+  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 ); assert(uiCode+1 <= MAX_TLAYER);
   READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
   assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
@@ -973,8 +994,16 @@
     }
   }
-  READ_FLAG( uiCode,  "vps_extension_flag" );
-  if (uiCode)
-  {
+
 #if VPS_EXTNS
+  READ_FLAG( uiCode,  "vps_extension_flag" );      pcVPS->setVpsExtensionFlag( uiCode ? true : false );
+
+  // When MaxLayersMinus1 is greater than 0, vps_extension_flag shall be equal to 1.
+  if( pcVPS->getMaxLayers() > 1 )
+  {
+    assert( pcVPS->getVpsExtensionFlag() == true );
+  }
+
+  if( pcVPS->getVpsExtensionFlag()  )
+  {
     while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
     {
@@ -990,11 +1019,20 @@
       }
     }
-#else
+  }
+  else
+  {
+    // set default parameters when syntax elements are not present
+    defaultVPSExtension(pcVPS);    
+  }
+#else
+  READ_FLAG( uiCode,  "vps_extension_flag" );
+  if (uiCode)
+  {
     while ( xMoreRbspData() )
     {
       READ_FLAG( uiCode, "vps_extension_data_flag");
     }
-#endif
-  }
+  }
+#endif
 
   return;
@@ -1129,19 +1167,20 @@
 #endif
 #if VPS_TSLAYERS
-    READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag"); vps->setMaxTSLayersPresentFlag(uiCode ? true : false);
-    if (vps->getMaxTSLayersPresentFlag())
-    {
-        for(i = 0; i < vps->getMaxLayers(); i++)
-        {
-            READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1[i]" ); vps->setMaxTSLayersMinus1(i, uiCode);
-        }
-    }
-    else
-    {
-        for( i = 0; i < vps->getMaxLayers(); i++)
-        {
-            vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
-        }
-    }
+  READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag"); vps->setMaxTSLayersPresentFlag(uiCode ? true : false);
+
+  if (vps->getMaxTSLayersPresentFlag())
+  {
+    for(i = 0; i < vps->getMaxLayers(); i++)
+    {
+      READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1[i]" ); vps->setMaxTSLayersMinus1(i, uiCode);
+    }
+  }
+  else
+  {
+    for( i = 0; i < vps->getMaxLayers(); i++)
+    {
+      vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
+    }
+  }
 #endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
@@ -1250,13 +1289,32 @@
   }
 #else
+
+#if Q0165_NUM_ADD_OUTPUT_LAYER_SETS
+  if( vps->getNumLayerSets() > 1 )
+  {
+    READ_UVLC( uiCode, "num_add_output_layer_sets" );            vps->setNumAddOutputLayerSets( uiCode );
+    READ_CODE( 2, uiCode, "default_target_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
+  }
+  else
+  {
+    vps->setNumAddOutputLayerSets( 0 );
+  }
+#else
   READ_UVLC( uiCode, "num_add_output_layer_sets" );          vps->setNumAddOutputLayerSets( uiCode );
+#endif
+
+  // The value of num_add_output_layer_sets shall be in the range of 0 to 1023, inclusive.
+  assert( vps->getNumAddOutputLayerSets() >= 0 && vps->getNumAddOutputLayerSets() < 1024 );
+
   Int numOutputLayerSets = vps->getNumLayerSets() + vps->getNumAddOutputLayerSets();
 #endif
 
 #if P0295_DEFAULT_OUT_LAYER_IDC
+#if !Q0165_NUM_ADD_OUTPUT_LAYER_SETS
   if( numOutputLayerSets > 1 )
   {
     READ_CODE( 2, uiCode, "default_target_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
   }
+#endif
   vps->setNumOutputLayerSets( numOutputLayerSets );
 
@@ -1330,4 +1388,8 @@
       vps->setAltOuputLayerFlag(i, uiCode ? true : false);
     }
+#if Q0165_OUTPUT_LAYER_SET
+    assert( NumOutputLayersInOutputLayerSet[i]>0 );
+#endif
+
 #endif
   }
@@ -1431,4 +1493,53 @@
 
 #if REPN_FORMAT_IN_VPS
+#if Q0195_REP_FORMAT_CLEANUP
+  READ_UVLC( uiCode, "vps_num_rep_formats_minus1" );
+  vps->setVpsNumRepFormats( uiCode + 1 );
+
+  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
+  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
+
+  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
+  {
+    // Read rep_format_structures
+    parseRepFormat( vps->getVpsRepFormat(i), i > 0 ? vps->getVpsRepFormat(i-1) : 0 );
+  }
+
+  // Default assignment for layer 0
+  vps->setVpsRepFormatIdx( 0, 0 );
+
+  if( vps->getVpsNumRepFormats() > 1 )
+  {
+    READ_FLAG( uiCode, "rep_format_idx_present_flag");
+    vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
+  }
+  else
+  {
+    // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
+    vps->setRepFormatIdxPresentFlag( false );
+  }
+
+  if( vps->getRepFormatIdxPresentFlag() )
+  {
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      Int numBits = 1;
+      while ((1 << numBits) < (vps->getVpsNumRepFormats()))
+      {
+        numBits++;
+      }
+      READ_CODE( numBits, uiCode, "vps_rep_format_idx[i]" );
+      vps->setVpsRepFormatIdx( i, uiCode );
+    }
+  }
+  else
+  {
+    // When not present, the value of vps_rep_format_idx[ i ] is inferred to be equal to Min (i, vps_num_rep_formats_minus1)
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      vps->setVpsRepFormatIdx( i, min( (Int)i, vps->getVpsNumRepFormats()-1 ) );
+    }
+  }
+#else
   READ_FLAG( uiCode, "rep_format_idx_present_flag");
   vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
@@ -1453,8 +1564,12 @@
     vps->setVpsNumRepFormats( vps->getMaxLayers() );
   }
+
+  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
+  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
+
   for(i = 0; i < vps->getVpsNumRepFormats(); i++)
   {
     // Read rep_format_structures
-    parseRepFormat( vps->getVpsRepFormat(i) );
+    parseRepFormat( vps->getVpsRepFormat(i), i > 0 ? vps->getVpsRepFormat(i-1) : 0 );
   }
 
@@ -1498,4 +1613,5 @@
     }
   }
+#endif
 #endif
 #if RESOLUTION_BASED_DPB
@@ -1578,4 +1694,8 @@
 #if P0307_VPS_NON_VUI_EXTENSION
   READ_UVLC( uiCode,           "vps_non_vui_extension_length"); vps->setVpsNonVuiExtLength((Int)uiCode);
+
+  // The value of vps_non_vui_extension_length shall be in the range of 0 to 4096, inclusive.
+  assert( vps->getVpsNonVuiExtLength() >= 0 && vps->getVpsNonVuiExtLength() <= 4096 );
+
 #if P0307_VPS_NON_VUI_EXT_UPDATE
   Int nonVuiExtByte = uiCode;
@@ -1620,31 +1740,156 @@
 #endif
   }
-}
-#endif
+  else
+  {
+    // set default values for VPS VUI
+    defaultVPSVUI( vps );
+  }
+}
+
+Void TDecCavlc::defaultVPSExtension( TComVPS* vps )
+{
+  // set default parameters when they are not present
+  Int i, j;
+
+  // When layer_id_in_nuh[ i ] is not present, the value is inferred to be equal to i.
+  for(i = 0; i < vps->getMaxLayers(); i++)
+  {
+    vps->setLayerIdInNuh(i, i);
+    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
+  }
+
+  // When not present, sub_layers_vps_max_minus1[ i ] is inferred to be equal to vps_max_sub_layers_minus1.
+  for( i = 0; i < vps->getMaxLayers(); i++)
+  {
+    vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
+  }
+
+  // When not present, max_tid_il_ref_pics_plus1[ i ][ j ] is inferred to be equal to 7.
+  for( i = 0; i < vps->getMaxLayers() - 1; i++ )
+  {
+#if O0225_MAX_TID_FOR_REF_LAYERS
+    for( j = i + 1; j < vps->getMaxLayers(); j++ )
+    {
+      vps->setMaxTidIlRefPicsPlus1(i, j, 7);
+    }
+#else
+    vps->setMaxTidIlRefPicsPlus1(i, 7);
+#endif
+  }
+  
+  // When not present, the value of num_add_output_layer_sets is inferred to be equal to 0.
+  // NumOutputLayerSets = num_add_output_layer_sets + vps_num_layer_sets_minus1 + 1
+  vps->setNumOutputLayerSets( vps->getNumLayerSets() );
+
+  // For i in the range of 0 to NumOutputLayerSets-1, inclusive, the variable LayerSetIdxForOutputLayerSet[ i ] is derived as specified in the following: 
+  // LayerSetIdxForOutputLayerSet[ i ] = ( i <= vps_number_layer_sets_minus1 ) ? i : output_layer_set_idx_minus1[ i ] + 1
+  for( i = 1; i < vps->getNumOutputLayerSets(); i++ )
+  {
+    vps->setOutputLayerSetIdx( i, i );
+    Int lsIdx = vps->getOutputLayerSetIdx(i);
+
+    for( j = 0; j < vps->getNumLayersInIdList(lsIdx); j++ )
+    {
+    vps->setOutputLayerFlag(i, j, 1);
+    }
+  }
+
+  // The value of sub_layer_dpb_info_present_flag[ i ][ 0 ] for any possible value of i is inferred to be equal to 1
+  // When not present, the value of sub_layer_dpb_info_present_flag[ i ][ j ] for j greater than 0 and any possible value of i, is inferred to be equal to be equal to 0.
+  for( i = 1; i < vps->getNumOutputLayerSets(); i++ )
+  {
+    vps->setSubLayerDpbInfoPresentFlag( i, 0, true );
+  }
+  
+  // When not present, the value of vps_num_rep_formats_minus1 is inferred to be equal to MaxLayersMinus1.
+  vps->setVpsNumRepFormats( vps->getMaxLayers() );
+
+  // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
+  vps->setRepFormatIdxPresentFlag( false );
+
+  if( !vps->getRepFormatIdxPresentFlag() )
+  {
+    // When not present, the value of vps_rep_format_idx[ i ] is inferred to be equal to Min(i, vps_num_rep_formats_minus1). 
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      vps->setVpsRepFormatIdx( i, min( (Int)i, vps->getVpsNumRepFormats() - 1 ) );
+    }
+  }
+
+  // vps_poc_lsb_aligned_flag
+  // When not present, vps_poc_lsb_aligned_flag is inferred to be equal to 0.
+  
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+  // When not present, poc_lsb_not_present_flag[ i ] is inferred to be equal to 0.
+  for(i = 1; i< vps->getMaxLayers(); i++)
+  {
+    vps->setPocLsbNotPresentFlag(i, 0);
+  }
+#endif
+
+  // set default values for VPS VUI
+  defaultVPSVUI( vps );
+}
+
+Void TDecCavlc::defaultVPSVUI( TComVPS* vps )
+{
+#if N0147_IRAP_ALIGN_FLAG
+  // When not present, the value of all_layers_idr_aligned_flag is inferred to be equal to 0.
+  vps->setCrossLayerIrapAlignFlag( false );
+#endif
+
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+  // When single_layer_for_non_irap_flag is not present, it is inferred to be equal to 0.
+  vps->setSingleLayerForNonIrapFlag( false );
+#endif
+
+#if HIGHER_LAYER_IRAP_SKIP_FLAG
+  // When higher_layer_irap_skip_flag is not present it is inferred to be equal to 0
+  vps->setHigherLayerIrapSkipFlag( false );
+#endif
+}
+#endif
+
 #if REPN_FORMAT_IN_VPS
-Void  TDecCavlc::parseRepFormat      ( RepFormat *repFormat )
+Void  TDecCavlc::parseRepFormat( RepFormat *repFormat, RepFormat *repFormatPrev )
 {
   UInt uiCode;
-#if REPN_FORMAT_CONTROL_FLAG
-  READ_FLAG ( uiCode, "chroma_and_bit_depth_vps_present_flag");   repFormat->setChromaAndBitDepthVpsPresentFlag(uiCode ? true : false); 
-  READ_CODE ( 16, uiCode, "pic_width_in_luma_samples" );          repFormat->setPicWidthVpsInLumaSamples ( uiCode );
-  READ_CODE ( 16, uiCode, "pic_height_in_luma_samples" );         repFormat->setPicHeightVpsInLumaSamples( uiCode );
+#if REPN_FORMAT_CONTROL_FLAG  
+  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );        repFormat->setPicWidthVpsInLumaSamples ( uiCode );
+  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" );       repFormat->setPicHeightVpsInLumaSamples( uiCode );
+  READ_FLAG( uiCode, "chroma_and_bit_depth_vps_present_flag" );    repFormat->setChromaAndBitDepthVpsPresentFlag( uiCode ? true : false ); 
+
+  if( !repFormatPrev )
+  {
+    // The value of chroma_and_bit_depth_vps_present_flag of the first rep_format( ) syntax structure in the VPS shall be equal to 1
+    assert( repFormat->getChromaAndBitDepthVpsPresentFlag() );
+  }
 
   if( repFormat->getChromaAndBitDepthVpsPresentFlag() )
   {
+    READ_CODE( 2, uiCode, "chroma_format_vps_idc" );
 #if AUXILIARY_PICTURES
-    READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
-#else
-    READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
+    repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
+#else
+    repFormat->setChromaFormatVpsIdc( uiCode );
 #endif
 
     if( repFormat->getChromaFormatVpsIdc() == 3 )
     {
-      READ_FLAG( uiCode, "separate_colour_plane_flag");        repFormat->setSeparateColourPlaneVpsFlag(uiCode ? true : false);
-    }
-
-
-    READ_CODE( 4, uiCode, "bit_depth_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
-    READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
+      READ_FLAG( uiCode, "separate_colour_plane_vps_flag" );       repFormat->setSeparateColourPlaneVpsFlag( uiCode ? true : false );
+    }
+
+    READ_CODE( 4, uiCode, "bit_depth_vps_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
+    READ_CODE( 4, uiCode, "bit_depth_vps_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
+  }
+  else if( repFormatPrev )
+  {
+    // chroma_and_bit_depth_vps_present_flag equal to 0 specifies that the syntax elements, chroma_format_vps_idc, separate_colour_plane_vps_flag, bit_depth_vps_luma_minus8, and 
+    // bit_depth_vps_chroma_minus8 are not present and inferred from the previous rep_format( ) syntax structure in the VPS.
+
+    repFormat->setChromaFormatVpsIdc        ( repFormatPrev->getChromaFormatVpsIdc() );
+    repFormat->setSeparateColourPlaneVpsFlag( repFormatPrev->getSeparateColourPlaneVpsFlag() );
+    repFormat->setBitDepthVpsLuma           ( repFormatPrev->getBitDepthVpsLuma() );
+    repFormat->setBitDepthVpsChroma         ( repFormatPrev->getBitDepthVpsChroma() );
   }
 #else 
@@ -1700,5 +1945,5 @@
     READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
 #if DPB_PARAMS_MAXTLAYERS
-      for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ i ]; j++)
+    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ i ]; j++)
 #else
     for(Int j = 0; j <= vps->getMaxTLayers(); j++)
@@ -1820,5 +2065,5 @@
         if( parseFlag && vps->getBitRatePresentVpsFlag() )
         {
-          READ_FLAG( uiCode,        "bit_rate_present_vps_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
+          READ_FLAG( uiCode,        "bit_rate_present_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
         }
         else
@@ -1828,5 +2073,5 @@
         if( parseFlag && vps->getPicRatePresentVpsFlag() )
         {
-          READ_FLAG( uiCode,        "pic_rate_present_vps_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
+          READ_FLAG( uiCode,        "pic_rate_present_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
         }
         else
@@ -1868,5 +2113,4 @@
     vps->setNumVideoSignalInfo(vps->getMaxLayers());
   }
-
 
   for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
@@ -1954,4 +2198,10 @@
 #if HIGHER_LAYER_IRAP_SKIP_FLAG
   READ_FLAG(uiCode, "higher_layer_irap_skip_flag" ); vps->setHigherLayerIrapSkipFlag(uiCode == 1 ? true : false);
+
+  // When single_layer_for_non_irap_flag is equal to 0, higher_layer_irap_skip_flag shall be equal to 0
+  if( !vps->getSingleLayerForNonIrapFlag() )
+  {
+    assert( !vps->getHigherLayerIrapSkipFlag() );
+  }
 #endif
 #endif
@@ -2102,8 +2352,9 @@
   if( rpcSlice->getRapPicFlag())
   {
-#if !NO_OUTPUT_OF_PRIOR_PICS
-    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
-#else
-    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  rpcSlice->setNoOutputOfPriorPicsFlag( uiCode ? true : false );
+    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
+#if SETTING_NO_OUT_PIC_PRIOR
+    rpcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
+#else
+    rpcSlice->setNoOutputPicPrior( false );
 #endif
   }
@@ -2305,5 +2556,5 @@
         else
         {
-          uiCode = 0;
+          uiCode = 0;       
         }
         *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
@@ -2453,6 +2704,11 @@
             for( Int i = 0; i < rpcSlice->getNumILRRefIdx(); i++ ) 
             {
+#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
+              if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
+                (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
+#else 
               if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
                 (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
+#endif 
               {          
                 rpcSlice->setActiveNumILRRefIdx(1);
@@ -2487,6 +2743,11 @@
         {
 #if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
+#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
+          if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
+            (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
+#else
           if( (rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer()) &&
              (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
+#endif 
         {
 #endif
@@ -2514,6 +2775,11 @@
       for(i = 0, numRefLayerPics = 0;  i < rpcSlice->getNumILRRefIdx(); i++ ) 
       {
+#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
+        if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
+          (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
+#else 
         if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
            (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
+#endif 
         {          
           refLayerPicIdc[ numRefLayerPics++ ] = i;
@@ -2560,4 +2826,7 @@
       {
         format = rpcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
+#if Q0195_REP_FORMAT_CLEANUP
+         assert( (sps->getUpdateRepFormatFlag()==false && rpcSlice->getVPS()->getVpsNumRepFormats()==1) || rpcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
+#endif
       }
 #else
@@ -3468,4 +3737,65 @@
 }
 
+#if Q0048_CGS_3D_ASYMLUT
+Void TDecCavlc::xParse3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT )
+{
+  UInt uiCurOctantDepth , uiCurPartNumLog2 , uiInputBitDepthM8 , uiOutputBitDepthM8 , uiResQaunBit;
+  READ_CODE( 2 , uiCurOctantDepth , "cm_octant_depth" ); 
+  READ_CODE( 2 , uiCurPartNumLog2 , "cm_y_part_num_log2" );     
+  READ_CODE( 3 , uiInputBitDepthM8 , "cm_input_bit_depth_minus8" );
+  Int iInputBitDepthCDelta;
+  READ_SVLC(iInputBitDepthCDelta, "cm_input_bit_depth_chroma delta");
+  READ_CODE( 3 , uiOutputBitDepthM8 , "cm_output_bit_depth_minus8" ); 
+  Int iOutputBitDepthCDelta;
+  READ_SVLC(iOutputBitDepthCDelta, "cm_output_bit_depth_chroma_delta");
+  READ_CODE( 2 , uiResQaunBit , "cm_res_quant_bit" );
+  pc3DAsymLUT->destroy();
+  pc3DAsymLUT->create( uiCurOctantDepth , uiInputBitDepthM8 + 8 ,  uiInputBitDepthM8 + 8 + iInputBitDepthCDelta, uiOutputBitDepthM8 + 8 , uiOutputBitDepthM8 + 8 + iOutputBitDepthCDelta ,uiCurPartNumLog2 );
+  pc3DAsymLUT->setResQuantBit( uiResQaunBit );
+
+  xParse3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() );
+}
+
+Void TDecCavlc::xParse3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength )
+{
+  UInt uiOctantSplit = nDepth < pc3DAsymLUT->getCurOctantDepth();
+  if( nDepth < pc3DAsymLUT->getCurOctantDepth() )
+    READ_FLAG( uiOctantSplit , "split_octant_flag" );
+  Int nYPartNum = 1 << pc3DAsymLUT->getCurYPartNumLog2();
+  if( uiOctantSplit )
+  {
+    Int nHalfLength = nLength >> 1;
+    for( Int l = 0 ; l < 2 ; l++ )
+    {
+      for( Int m = 0 ; m < 2 ; m++ )
+      {
+        for( Int n = 0 ; n < 2 ; n++ )
+        {
+          xParse3DAsymLUTOctant( pc3DAsymLUT , nDepth + 1 , yIdx + l * nHalfLength * nYPartNum , uIdx + m * nHalfLength , vIdx + n * nHalfLength , nHalfLength );
+        }
+      }
+    }
+  }
+  else
+  {
+    for( Int l = 0 ; l < nYPartNum ; l++ )
+    {
+      for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
+      {
+        UInt uiCodeVertex = 0;
+        Int deltaY = 0 , deltaU = 0 , deltaV = 0;
+        READ_FLAG( uiCodeVertex , "coded_vertex_flag" );
+        if( uiCodeVertex )
+        {
+          READ_SVLC( deltaY , "resY" );
+          READ_SVLC( deltaU , "resU" );
+          READ_SVLC( deltaV , "resV" );
+        }
+        pc3DAsymLUT->setCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx , deltaY , deltaU , deltaV );
+      }
+    }
+  }
+}
+#endif
 //! \}
 
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 649)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 713)
@@ -46,4 +46,7 @@
 #include "SyntaxElementParser.h"
 
+#if Q0048_CGS_3D_ASYMLUT
+class TCom3DAsymLUT;
+#endif
 //! \ingroup TLibDecoder
 //! \{
@@ -75,11 +78,13 @@
 #if VPS_EXTNS
   Void  parseVPSExtension   ( TComVPS* pcVPS );
+  Void  defaultVPSExtension ( TComVPS* pcVPS );
 #endif
 
 #if VPS_VUI
   Void  parseVPSVUI   ( TComVPS* pcVPS );
+  Void  defaultVPSVUI ( TComVPS* pcVPS );
 #endif 
 #if REPN_FORMAT_IN_VPS
-  Void  parseRepFormat      ( RepFormat *repFormat );
+  Void  parseRepFormat      ( RepFormat *repFormat, RepFormat *repFormatPrev );
 #endif
 #if VPS_DPB_SIZE_TABLE
@@ -95,5 +100,9 @@
   Void  parseSPS            ( TComSPS* pcSPS );
 #endif //SVC_EXTENSION
-  Void  parsePPS            ( TComPPS* pcPPS);
+  Void  parsePPS            ( TComPPS* pcPPS
+#if Q0048_CGS_3D_ASYMLUT
+    , TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID
+#endif
+    );
   Void  parseVUI            ( TComVUI* pcVUI, TComSPS* pcSPS );
   Void  parseSEI            ( SEIMessages& );
@@ -135,4 +144,9 @@
 protected:
   Bool  xMoreRbspData();
+
+#if Q0048_CGS_3D_ASYMLUT
+  Void xParse3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT );
+  Void xParse3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength );
+#endif
 };
 
Index: trunk/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 649)
+++ trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 713)
@@ -73,4 +73,11 @@
     m_ppcCU     [ui]->setLayerId(layerId);
   }
+  
+#if LAYER_CTB
+  memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) );
+  memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) );
+  memcpy(g_auiLayerRasterToPelX[m_layerId],  g_auiRasterToPelX,  sizeof( g_auiRasterToPelX ) );
+  memcpy(g_auiLayerRasterToPelY[m_layerId],  g_auiRasterToPelY,  sizeof( g_auiRasterToPelY ) );
+#endif
 }
 #else
@@ -715,5 +722,5 @@
 {
   UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
-  UInt  uiNumPart     = pcCU->getNumPartInter();
+  UInt  uiNumPart     = pcCU->getNumPartitions();
   UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
   
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 649)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 713)
@@ -49,4 +49,7 @@
 class TDecCavlc;
 class ParameterSetManagerDecoder;
+#if Q0048_CGS_3D_ASYMLUT
+class TCom3DAsymLUT;
+#endif
 
 //! \ingroup TLibDecoder
@@ -71,5 +74,9 @@
   virtual Void  parseSPS                  ( TComSPS* pcSPS )                                      = 0;
 #endif
-  virtual Void  parsePPS                  ( TComPPS* pcPPS )                                      = 0;
+  virtual Void  parsePPS                  ( TComPPS* pcPPS 
+#if Q0048_CGS_3D_ASYMLUT
+    , TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID
+#endif
+    )                                      = 0;
 
   virtual Void parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)       = 0;
@@ -138,5 +145,10 @@
   Void    decodeSPS                   ( TComSPS* pcSPS     )    { m_pcEntropyDecoderIf->parseSPS(pcSPS);                    }
 #endif
-  Void    decodePPS                   ( TComPPS* pcPPS )    { m_pcEntropyDecoderIf->parsePPS(pcPPS);                    }
+
+#if Q0048_CGS_3D_ASYMLUT
+  Void    decodePPS                   ( TComPPS* pcPPS, TCom3DAsymLUT * pc3DAsymLUT, Int nLayerID )    { m_pcEntropyDecoderIf->parsePPS(pcPPS, pc3DAsymLUT , nLayerID );                     }
+#else
+  Void    decodePPS                   ( TComPPS* pcPPS )    { m_pcEntropyDecoderIf->parsePPS(pcPPS );  }
+#endif
   Void    decodeSliceHeader           ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)  { m_pcEntropyDecoderIf->parseSliceHeader(rpcSlice, parameterSetManager);         }
 
Index: trunk/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 649)
+++ trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 713)
@@ -248,5 +248,9 @@
   }
 
+#if SETTING_PIC_OUTPUT_MARK
+  rpcPic->setOutputMark(rpcPic->getSlice(0)->getPicOutputFlag() ? true : false);
+#else
   rpcPic->setOutputMark(true);
+#endif
   rpcPic->setReconMark(true);
 }
Index: trunk/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 649)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 713)
@@ -81,5 +81,9 @@
   Void  parseSPS                  ( TComSPS* /*pcSPS*/ ) {}
 #endif
-  Void  parsePPS                  ( TComPPS* /*pcPPS*/ ) {}
+  Void  parsePPS                  ( TComPPS* /*pcPPS*/ 
+#if Q0048_CGS_3D_ASYMLUT
+    , TCom3DAsymLUT * /*pc3DAsymLUT*/ , Int /*nLayerID*/
+#endif
+    ) {}
 
   Void  parseSliceHeader          ( TComSlice*& /*rpcSlice*/, ParameterSetManagerDecoder* /*parameterSetManager*/) {}
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 649)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 713)
@@ -79,14 +79,25 @@
   m_prevSliceSkipped = false;
   m_skippedPOC = 0;
+#if SETTING_NO_OUT_PIC_PRIOR
+  m_bFirstSliceInBitstream  = true;
+  m_lastPOCNoOutputPriorPics = -1;
+  m_craNoRaslOutputFlag = false;
+  m_isNoOutputPriorPics = false;
+#endif
 #if NO_CLRAS_OUTPUT_FLAG
   m_noClrasOutputFlag          = false;
   m_layerInitializedFlag       = false;
-  m_firstPicInLayerDecodedFlag = false;
-  m_noOutputOfPriorPicsFlags   = false;
-  m_bRefreshPending            = false;
+  m_firstPicInLayerDecodedFlag = false;  
 #endif
 #if RESOLUTION_BASED_DPB
   m_subDpbIdx = -1;
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  m_pColorMappedPic = NULL;
+#endif
+
+#if Q0074_SEI_COLOR_MAPPING
+  m_ColorMapping = new TDecColorMapping();
+#endif
 }
 
@@ -95,4 +106,15 @@
 #if ENC_DEC_TRACE
   fclose( g_hTrace );
+#endif
+#if Q0048_CGS_3D_ASYMLUT
+  if(m_pColorMappedPic)
+  {
+    m_pColorMappedPic->destroy();
+    delete m_pColorMappedPic;
+    m_pColorMappedPic = NULL;
+  }
+#endif
+#if Q0074_SEI_COLOR_MAPPING
+  if ( m_ColorMapping )  delete m_ColorMapping;
 #endif
 }
@@ -353,5 +375,12 @@
         Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
 
-        if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets || !sameBitDepths )
+        if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets || !sameBitDepths
+#if Q0048_CGS_3D_ASYMLUT
+          || pcSlice->getPPS()->getCGSFlag() > 0
+#endif
+#if LAYER_CTB
+          || pcTDecTopBase->getActiveSPS()->getMaxCUWidth() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUWidth() || pcTDecTopBase->getActiveSPS()->getMaxCUHeight() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUHeight() || pcTDecTopBase->getActiveSPS()->getMaxCUDepth() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUDepth()
+#endif
+          )
 #else
         if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets )
@@ -503,5 +532,4 @@
 
   // Execute Deblock + Cleanup
-
   m_cGopDecoder.filterPicture(pcPic);
 
@@ -517,4 +545,22 @@
   return;
 }
+
+#if SETTING_NO_OUT_PIC_PRIOR
+Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic)
+{
+  if (!rpcListPic || !m_isNoOutputPriorPics) return;
+
+  TComList<TComPic*>::iterator  iterPic   = rpcListPic->begin();
+
+  while (iterPic != rpcListPic->end())
+  {
+    TComPic*& pcPicTmp = *(iterPic++);
+    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
+    {
+      pcPicTmp->setOutputMark(false);
+    }
+  }
+}
+#endif
 
 #if EARLY_REF_PIC_MARKING
@@ -733,4 +779,49 @@
 #endif
 
+#if AVC_BASE
+  if( activeVPS->getAvcBaseLayerFlag() )
+  {
+    TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
+    if( m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
+    {
+      UInt refLayerId = 0;
+      RepFormat* repFormat = activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(refLayerId) );
+
+      Int  numReorderPics[MAX_TLAYER];
+      Window conformanceWindow;
+      Window defaultDisplayWindow;
+
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+#if AVC_SYNTAX
+      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, activeSPS, true);
+#else
+      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
+#endif
+#else
+      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
+#if SVC_UPSAMPLING
+#if AVC_SYNTAX
+      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, activeSPS, true);
+#else
+      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
+#endif
+#else
+      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#endif
+      // it is needed where the VPS is accessed through the slice
+      pBLPic->getSlice(0)->setVPS( activeVPS );
+
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+      g_bitDepthYLayer[0] = repFormat->getBitDepthVpsLuma();
+      g_bitDepthCLayer[0] = repFormat->getBitDepthVpsChroma();
+#endif
+    }
+  }
+#endif
+
 #if P0312_VERT_PHASE_ADJ
   if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
@@ -808,4 +899,11 @@
   g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
 
+#if Q0074_SEI_COLOR_MAPPING
+  for(Int compID=0; compID<3; compID++)
+  {
+    m_ColorMapping->setColorMapping( compID ? g_bitDepthC : g_bitDepthY, compID );
+  }
+#endif
+
   for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
   {
@@ -843,9 +941,4 @@
   TComPic*&   pcPic         = m_pcPic;
 #if SVC_EXTENSION
-#if !NO_OUTPUT_OF_PRIOR_PICS
-#if NO_CLRAS_OUTPUT_FLAG
-  Bool bFirstSliceInSeq;
-#endif
-#endif
   m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getPrefetchedVPS(0) );
 #if OUTPUT_LAYER_SET_INDEX
@@ -900,18 +993,57 @@
   m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
 
-#if NO_OUTPUT_OF_PRIOR_PICS
-  // Infer the value of NoOutputOfPriorPicsFlag
-  if( m_apcSlicePilot->getRapPicFlag() )
-  {
-    if ( m_apcSlicePilot->getBlaPicFlag() || m_apcSlicePilot->getIdrPicFlag()  || 
-        (m_apcSlicePilot->getCraPicFlag() && m_bFirstSliceInSequence) ||
-        (m_apcSlicePilot->getCraPicFlag() && m_apcSlicePilot->getHandleCraAsBlaFlag()))
-    {
-      m_apcSlicePilot->setNoRaslOutputFlag( true );
+#if SETTING_NO_OUT_PIC_PRIOR
+  //For inference of NoOutputOfPriorPicsFlag
+  if (m_apcSlicePilot->getRapPicFlag())
+  {
+    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
+        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
+        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
+    {
+      m_apcSlicePilot->setNoRaslOutputFlag(true);
+    }
+    //the inference for NoOutputPriorPicsFlag
+    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
+    {
+      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
+      {
+        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
+      }
     }
     else
     {
-      m_apcSlicePilot->setNoRaslOutputFlag( false );
-    }
+      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
+    }
+
+    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
+    {
+      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
+    }
+  }
+  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
+  {
+    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
+    m_isNoOutputPriorPics = true;
+  }
+  else
+  {
+    m_isNoOutputPriorPics = false;
+  }
+
+  //For inference of PicOutputFlag
+  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
+  {
+    if ( m_craNoRaslOutputFlag )
+    {
+      m_apcSlicePilot->setPicOutputFlag(false);
+    }
+  }
+#endif
+
+#if FIX_POC_CRA_NORASL_OUTPUT
+  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
+  {
+    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
+    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
   }
 #endif
@@ -967,5 +1099,5 @@
   }
 
-  m_apcSlicePilot->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, m_cListPic, getNoClrasOutputFlag());
+  m_apcSlicePilot->decodingRefreshMarking( m_cListPic, m_noClrasOutputFlag );
 #endif
 
@@ -975,9 +1107,9 @@
     if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() )
     {
-      this->setNoOutputOfPriorPicsFlags( true );
+      this->setNoOutputPriorPicsFlag( true );
     }
     else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() )
     {
-      this->setNoOutputOfPriorPicsFlags( m_apcSlicePilot->getNoOutputOfPriorPicsFlag() );
+      this->setNoOutputPriorPicsFlag( m_apcSlicePilot->getNoOutputPriorPicsFlag() );
     }
     else
@@ -985,5 +1117,5 @@
       if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() )
       {
-        this->setNoOutputOfPriorPicsFlags( true );
+        this->setNoOutputPriorPicsFlag( true );
       }
     }
@@ -1006,5 +1138,5 @@
 #else
   //we should only get a different poc for a new picture (with CTU address==0)
-  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
+  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
   {
     printf ("Warning, the first slice of a picture might have been lost!\n");
@@ -1050,10 +1182,8 @@
 #endif
   }
-#if !NO_OUTPUT_OF_PRIOR_PICS
-#if NO_CLRAS_OUTPUT_FLAG
-  bFirstSliceInSeq = m_bFirstSliceInSequence;
-#endif
-#endif
   m_bFirstSliceInSequence = false;
+#if SETTING_NO_OUT_PIC_PRIOR  
+  m_bFirstSliceInBitstream  = false;
+#endif
 #if POC_RESET_FLAG
   // This operation would do the following:
@@ -1216,50 +1346,5 @@
 #endif
 
-#if !NO_OUTPUT_OF_PRIOR_PICS
-#if NO_CLRAS_OUTPUT_FLAG
-    if (m_layerId == 0 &&
-        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
-      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
-      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
-      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
-      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
-    {
-      if (bFirstSliceInSeq)
-      {
-        setNoClrasOutputFlag(true);
-      }
-      else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-            || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
-            || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP)
-      {
-        setNoClrasOutputFlag(true);
-      }
-#if O0149_CROSS_LAYER_BLA_FLAG
-      else if ((m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP) &&
-               m_apcSlicePilot->getCrossLayerBLAFlag())
-      {
-        setNoClrasOutputFlag(true);
-      }
-#endif
-      else
-      {
-        setNoClrasOutputFlag(false);
-      }
-      if (getNoClrasOutputFlag())
-      {
-        for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getMaxLayers(); i++)
-        {
-          m_ppcTDecTop[i]->setLayerInitializedFlag(false);
-          m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false);
-        }
-      }
-    }
-#endif
-
-#if NO_CLRAS_OUTPUT_FLAG
-    m_apcSlicePilot->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, m_cListPic, getNoClrasOutputFlag());
-#endif
-#else
+#if NO_OUTPUT_OF_PRIOR_PICS
     if ( m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() && getNoClrasOutputFlag() )
     {
@@ -1273,8 +1358,8 @@
     // Buffer initialize for prediction.
     m_cPrediction.initTempBuff();
-#if !ALIGNED_BUMPING
+#if ALIGNED_BUMPING
+    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
+#else
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
-#else
-    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
 #endif
     //  Get a new picture buffer
@@ -1515,5 +1600,10 @@
         Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
         Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
-
+#if Q0200_CONFORMANCE_BL_SIZE
+        Int chromaFormatIdc = pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getChromaFormatIdc();
+        const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getConformanceWindow(); 
+        widthBL  -= ( confBL.getWindowLeftOffset() + confBL.getWindowRightOffset() ) * TComSPS::getWinUnitX( chromaFormatIdc );
+        heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
+#endif
         Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
         Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
@@ -1525,23 +1615,46 @@
         g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
 
+#if Q0048_CGS_3D_ASYMLUT 
+        TComPicYuv* pBaseColRec = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
+        if( pcSlice->getPPS()->getCGSFlag() )
+        {
+          if(!m_pColorMappedPic)
+          {
+            initAsymLut(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0));
+          }
+          m_c3DAsymLUTPPS.colorMapping( pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(),  m_pColorMappedPic );
+          pBaseColRec = m_pColorMappedPic;
+        }
+#endif
 #if SVC_UPSAMPLING
         if( pcPic->isSpatialEnhLayer(refLayerIdc) )
         {    
-/*#if O0098_SCALED_REF_LAYER_ID
-          Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
-#else
-          Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
-#endif*/
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
+#if Q0048_CGS_3D_ASYMLUT 
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
+#endif
+#else
+#if Q0048_CGS_3D_ASYMLUT 
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
 #else
           m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
 #endif
+#endif
 #else
 #if O0194_JOINT_US_BITSHIFT
+#if Q0048_CGS_3D_ASYMLUT 
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#else
           m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+#endif
+#else
+#if Q0048_CGS_3D_ASYMLUT 
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
 #else
           m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+#endif
 #endif
 #endif
@@ -1755,5 +1868,9 @@
 }
 
-Void TDecTop::xDecodePPS()
+Void TDecTop::xDecodePPS(
+#if Q0048_CGS_3D_ASYMLUT
+  TCom3DAsymLUT * pc3DAsymLUT
+#endif
+  )
 {
   TComPPS* pps = new TComPPS();
@@ -1763,5 +1880,9 @@
 #endif
 
-  m_cEntropyDecoder.decodePPS( pps );
+  m_cEntropyDecoder.decodePPS( pps 
+#if Q0048_CGS_3D_ASYMLUT
+    , pc3DAsymLUT , m_layerId 
+#endif
+    );
   m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
 
@@ -1809,10 +1930,13 @@
       SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
       m_parameterSetManagerDecoder.applyPrefetchedPS();
-      assert(seiAps->activeSeqParamSetId.size()>0);
-      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParamSetId[0] ) )
+      assert(seiAps->activeSeqParameterSetId.size()>0);
+      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
       {
         printf ("Warning SPS activation with Active parameter set SEI failed");
       }
     }
+#if Q0074_SEI_COLOR_MAPPING
+    m_ColorMapping->setColorMapping( m_SEIs );
+#endif
   }
 #else
@@ -1837,6 +1961,6 @@
       SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
       m_parameterSetManagerDecoder.applyPrefetchedPS();
-      assert(seiAps->activeSeqParamSetId.size()>0);
-      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
+      assert(seiAps->activeSeqParameterSetId.size()>0);
+      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
       {
         printf ("Warning SPS activation with Active parameter set SEI failed");
@@ -1897,49 +2021,12 @@
     case NAL_UNIT_SPS:
       xDecodeSPS();
-#if AVC_BASE
-      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
-      {
-        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
-        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
-        {
-          // using EL SPS with spsId = 1
-          TComSPS* sps = m_parameterSetManagerDecoder.getPrefetchedSPS(1);
-          Int  numReorderPics[MAX_TLAYER];
-          Window &conformanceWindow = sps->getConformanceWindow();
-          Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
-#if AUXILIARY_PICTURES
-#if SVC_UPSAMPLING
-#if AVC_SYNTAX
-          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
-#else
-          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
-#endif
-#else
-          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
-#if AVC_SYNTAX
-          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
-#else
-          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
-#endif
-#else
-          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#endif
-
-#if O0194_DIFFERENT_BITDEPTH_EL_BL
-          // set AVC BL bit depth, can be an input parameter from the command line
-          g_bitDepthYLayer[0] = 8;
-          g_bitDepthCLayer[0] = 8;
-#endif
-        }
-      }
-#endif
       return false;
 
     case NAL_UNIT_PPS:
-      xDecodePPS();
+      xDecodePPS(
+#if Q0048_CGS_3D_ASYMLUT
+        &m_c3DAsymLUTPPS
+#endif
+        );
       return false;
       
@@ -1997,4 +2084,6 @@
       return false;
       
+    case NAL_UNIT_FILLER_DATA:
+      return false;
       
     case NAL_UNIT_RESERVED_VCL_N10:
@@ -2017,5 +2106,4 @@
     case NAL_UNIT_RESERVED_VCL31:
       
-    case NAL_UNIT_FILLER_DATA:
     case NAL_UNIT_RESERVED_NVCL41:
     case NAL_UNIT_RESERVED_NVCL42:
@@ -2304,4 +2392,324 @@
 }
 #endif
+
+#if Q0048_CGS_3D_ASYMLUT
+Void TDecTop::initAsymLut(TComSlice *pcSlice)
+{
+  if(m_layerId>0)
+  {
+    if(!m_pColorMappedPic)
+    {
+      Int picWidth    = pcSlice->getPicWidthInLumaSamples();
+      Int picHeight   = pcSlice->getPicHeightInLumaSamples();
+      m_pColorMappedPic = new TComPicYuv;
+      m_pColorMappedPic->create( picWidth, picHeight, pcSlice->getChromaFormatIdc()/*CHROMA_420*/, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
+    }
+  }
+}
+#endif
+
 #endif //SVC_EXTENSION
+
+#if Q0074_SEI_COLOR_MAPPING
+TDecColorMapping::TDecColorMapping()
+{
+  m_pcColorMappingPic[0]   = NULL;
+  m_pcColorMappingPic[1]   = NULL;
+
+  m_colorMapCancelFlag  = true;
+
+  for( Int i=0 ; i<3 ; i++ )
+  {
+    m_lut1d_computed[i]             = false;
+    m_lut1d_input[i]                = NULL;
+    m_coded_input_pivot_value[i]    = NULL;
+    m_target_input_pivot_value[i]   = NULL;
+  }
+  for( Int i=0 ; i<3 ; i++ )
+  {
+    m_lut1d_output[i]               = NULL;
+    m_coded_output_pivot_value[i]   = NULL;
+    m_target_output_pivot_value[i]  = NULL;
+  }
+}
+
+TDecColorMapping::~TDecColorMapping()
+{
+  if ( m_pcColorMappingPic[0] )  delete m_pcColorMappingPic[0];
+  if ( m_pcColorMappingPic[1] )  delete m_pcColorMappingPic[1];
+
+  for( Int i=0 ; i<3 ; i++ )
+  {
+    if ( m_lut1d_input[i] )               delete  m_lut1d_input[i];
+    if ( m_coded_input_pivot_value[i] )   delete  m_coded_input_pivot_value[i];
+    if ( m_target_input_pivot_value[i] )  delete  m_target_input_pivot_value[i];
+  }
+  for( Int i=0 ; i<3 ; i++ )
+  {
+    if ( m_lut1d_output[i] )               delete  m_lut1d_output[i];
+    if ( m_coded_output_pivot_value[i] )   delete  m_coded_output_pivot_value[i];
+    if ( m_target_output_pivot_value[i] )  delete  m_target_output_pivot_value[i];
+  }
+}
+
+Void  TDecColorMapping::setColorMapping( SEIMessages m_SEIs )
+{
+  SEIMessages colorMappingInfo = getSeisByType(m_SEIs, SEI::COLOR_MAPPING_INFO) ;
+  SEIColorMappingInfo *seiColorMappingInfo = NULL;
+  if (colorMappingInfo.size() !=0)
+  {
+    seiColorMappingInfo = (SEIColorMappingInfo*)(*colorMappingInfo.begin());
+
+    m_colorMapId                              = seiColorMappingInfo->m_colorMapId;
+    m_colorMapCancelFlag                      = seiColorMappingInfo->m_colorMapCancelFlag;
+    if( !m_colorMapCancelFlag )
+    {
+      m_colorMapPersistenceFlag                 = seiColorMappingInfo->m_colorMapPersistenceFlag;
+      m_colorMap_video_signal_type_present_flag = seiColorMappingInfo->m_colorMap_video_signal_type_present_flag;
+      m_colorMap_video_full_range_flag          = seiColorMappingInfo->m_colorMap_video_full_range_flag;
+      m_colorMap_primaries                      = seiColorMappingInfo->m_colorMap_primaries;
+      m_colorMap_transfer_characteristics       = seiColorMappingInfo->m_colorMap_transfer_characteristics;
+      m_colorMap_matrix_coeffs                  = seiColorMappingInfo->m_colorMap_matrix_coeffs;
+      m_colorMapModelId                         = seiColorMappingInfo->m_colorMapModelId;
+
+      m_colour_map_coded_data_bit_depth         = seiColorMappingInfo->m_colour_map_coded_data_bit_depth;
+      m_colour_map_target_bit_depth             = seiColorMappingInfo->m_colour_map_target_bit_depth;
+
+      for( Int i=0 ; i<3 ; i++ )
+      {
+        m_num_input_pivots[i]                 = seiColorMappingInfo->m_num_input_pivots[i];
+        if ( m_coded_input_pivot_value[i] )   delete  m_coded_input_pivot_value[i];
+        if ( m_target_input_pivot_value[i] )  delete  m_target_input_pivot_value[i];
+        m_coded_input_pivot_value[i]          = new Int[ m_num_input_pivots[i] ];
+        m_target_input_pivot_value[i]         = new Int[ m_num_input_pivots[i] ];
+        for( Int j=0 ; j<m_num_input_pivots[i] ; j++ )
+        {
+          m_coded_input_pivot_value[i][j]     = seiColorMappingInfo->m_coded_input_pivot_value[i][j];
+          m_target_input_pivot_value[i][j]    = seiColorMappingInfo->m_target_input_pivot_value[i][j];
+        }
+      }
+
+      m_matrix_flag       = seiColorMappingInfo->m_matrix_flag;
+      m_log2_matrix_denom = m_matrix_flag ? (seiColorMappingInfo->m_log2_matrix_denom) : (0) ;
+      for( Int i=0 ; i<3 ; i++ )
+      {
+        for( Int j=0 ; j<3 ; j++ )
+        {
+          m_matrix_coef[i][j]  = seiColorMappingInfo->m_matrix_coef[i][j];
+        }
+      }
+
+      for( Int i=0 ; i<3 ; i++ )
+      {
+        m_num_output_pivots[i]                 = seiColorMappingInfo->m_num_output_pivots[i];
+        if ( m_coded_output_pivot_value[i] )   delete  m_coded_output_pivot_value[i];
+        if ( m_target_output_pivot_value[i] )  delete  m_target_output_pivot_value[i];
+        m_coded_output_pivot_value[i]          = new Int[ m_num_output_pivots[i] ];
+        m_target_output_pivot_value[i]         = new Int[ m_num_output_pivots[i] ];
+        for( Int j=0 ; j<m_num_output_pivots[i] ; j++ )
+        {
+          m_coded_output_pivot_value[i][j]     = seiColorMappingInfo->m_coded_output_pivot_value[i][j];
+          m_target_output_pivot_value[i][j]    = seiColorMappingInfo->m_target_output_pivot_value[i][j];
+        }
+      }
+
+      memset( m_lut1d_computed, 0, sizeof( m_lut1d_computed ) );
+    }
+  }
+
+}
+
+Void  TDecColorMapping::setColorMapping( Int bitDepth, Int iComp )
+{
+  if( !m_colorMapCancelFlag && !m_lut1d_computed[iComp] )
+  {
+
+    if ( m_lut1d_input[iComp] )   delete m_lut1d_input[iComp];
+    if ( m_lut1d_output[iComp] )  delete m_lut1d_output[iComp];
+
+    m_lut1d_input[iComp]  = new Int[ 1 << bitDepth ];
+    m_lut1d_output[iComp] = new Int[ 1 << bitDepth ];
+
+    Int iShift      = (m_colour_map_coded_data_bit_depth >= bitDepth) ? (m_colour_map_coded_data_bit_depth - bitDepth) : (0);
+    Int iShiftPivot = (m_colour_map_coded_data_bit_depth >= bitDepth) ? (0) : (bitDepth - m_colour_map_coded_data_bit_depth);
+
+    for( Int k=0 ; k<(1<<bitDepth) ; k++ )
+    {
+      Int iSample = k << iShift ;
+      if( m_num_input_pivots[iComp] > 1 )
+      {
+        for( Int iPivot=0 ; iPivot<m_num_input_pivots[iComp] ; iPivot++ )
+        {
+          Int iCodedPrev  = m_coded_input_pivot_value[iComp][iPivot]     << iShiftPivot;
+          Int iCodedNext  = m_coded_input_pivot_value[iComp][iPivot+1]   << iShiftPivot;
+          Int iTargetPrev = m_target_input_pivot_value[iComp][iPivot]    << iShiftPivot;
+          Int iTargetNext = m_target_input_pivot_value[iComp][iPivot+1]  << iShiftPivot;
+          if ( iCodedPrev <= iSample && iSample < iCodedNext )
+          {
+            Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) / (Float)(iCodedNext - iCodedPrev) ;
+            m_lut1d_input[iComp][k]  = (Int)( 0.5 + fInterpol );
+            iPivot = m_num_input_pivots[iComp]; // stop
+          }
+        }
+      }
+      else
+      {
+        m_lut1d_input[iComp][k]  = k;
+      }
+    }
+
+    iShift      = ( (m_colour_map_coded_data_bit_depth >= bitDepth) ? (m_colour_map_coded_data_bit_depth - bitDepth) : (0) );
+    Int iOffset = iShift ? (1 << (iShift - 1)) : (0) ;
+    iShiftPivot = (m_colour_map_target_bit_depth >= bitDepth) ? (0) : (bitDepth - m_colour_map_target_bit_depth) ;
+    for( Int k=0 ; k<(1<<bitDepth) ; k++ )
+    {
+      Int iSample = k << iShift;
+      if ( m_num_output_pivots[iComp]>1 )
+      {
+        for( Int iPivot=0 ; iPivot<m_num_output_pivots[iComp] ; iPivot++ )
+        {
+          Int iCodedPrev  = m_coded_output_pivot_value[iComp][iPivot]     << iShiftPivot;
+          Int iCodedNext  = m_coded_output_pivot_value[iComp][iPivot+1]   << iShiftPivot;
+          Int iTargetPrev = m_target_output_pivot_value[iComp][iPivot]    << iShiftPivot;
+          Int iTargetNext = m_target_output_pivot_value[iComp][iPivot+1]  << iShiftPivot;
+          if ( iCodedPrev <= iSample && iSample < iCodedNext )
+          {
+            Float fInterpol =  (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) / (Float)(iCodedNext - iCodedPrev) ;
+            m_lut1d_output[iComp][k]  = ( (Int)(0.5 + fInterpol) + iOffset ) >> iShift ;
+            iPivot = m_num_output_pivots[iComp]; // stop
+          }
+        }
+      }
+      else
+      {
+        m_lut1d_output[iComp][k]  = k;
+      }
+    }
+
+    m_lut1d_computed[iComp] = true;
+  }
+
+}
+
+TComPicYuv* TDecColorMapping::getColorMapping( TComPicYuv* pPicYuvRec, Int iTop, Int curlayerId )
+{
+  if( !m_colorMapCancelFlag )
+  {
+    if( !m_pcColorMappingPic[iTop] )
+    {
+      m_pcColorMappingPic[iTop] = new TComPicYuv;
+#if SVC_EXTENSION
+      m_pcColorMappingPic[iTop]->create( pPicYuvRec->getWidth(), pPicYuvRec->getHeight(), pPicYuvRec->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#else
+      m_pcColorMappingPic[iTop]->create( pPicYuvRec->getWidth(), pPicYuvRec->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#endif
+    }
+
+    Int iHeight   = pPicYuvRec->getHeight();
+    Int iWidth    = pPicYuvRec->getWidth();
+    Int iStride   = pPicYuvRec->getStride();
+    Int iCStride  = pPicYuvRec->getCStride();
+
+    Pel* Lum0   = pPicYuvRec->getLumaAddr();
+    Pel* Cb0    = pPicYuvRec->getCbAddr();
+    Pel* Cr0    = pPicYuvRec->getCrAddr();
+    Pel* Lum1   = m_pcColorMappingPic[iTop]->getLumaAddr();
+    Pel* Cb1    = m_pcColorMappingPic[iTop]->getCbAddr();
+    Pel* Cr1    = m_pcColorMappingPic[iTop]->getCrAddr();
+
+#if SVC_EXTENSION
+    Int bitDepthY = g_bitDepthYLayer[curlayerId];
+    Int bitDepthC = g_bitDepthCLayer[curlayerId];
+
+    assert( g_bitDepthY == bitDepthY );
+    assert( g_bitDepthC == bitDepthC );
+#else
+    Int bitDepthY = g_bitDepthY;
+    Int bitDepthC = g_bitDepthC;
+#endif
+
+    Int iYShift = (m_colour_map_target_bit_depth >= bitDepthY) ? (m_colour_map_target_bit_depth - bitDepthY) : (0) ;
+    Int iCShift = (m_colour_map_target_bit_depth >= bitDepthC) ? (m_colour_map_target_bit_depth - bitDepthC) : (0) ;
+    Int offsetY = (1 << (m_log2_matrix_denom+iYShift - 1));
+    Int offsetC = (1 << (m_log2_matrix_denom+iCShift - 1));
+
+    Int   cShift  = 1 ;
+
+    //Pel*  LumPrev0 = Lum0;
+    for( Int y = 0; y < iHeight ; y++ )
+    {
+      Bool  bDoChroma = (y % 2);
+      for( Int x = 0; x < iWidth ; x++ )
+      {
+        Int s1Y = m_lut1d_input[0][ Lum0[x]   ];
+        Int s1U = m_lut1d_input[1][ Cb0[x>>1] ];
+        Int s1V = m_lut1d_input[2][ Cr0[x>>1] ];
+
+        Int s2Y, s2U, s2V;
+        if( m_matrix_flag )
+        {
+          s2Y = ( m_matrix_coef[0][0]*s1Y + m_matrix_coef[0][1]*s1U + m_matrix_coef[0][2]*s1V + offsetY ) >> ( m_log2_matrix_denom + iYShift );
+          //s2Y = ClipBD( s2Y , bitDepthY );
+          s2Y = ClipY( s2Y );
+          Lum1[x]   = m_lut1d_output[0][ s2Y ];
+        }
+        else
+        {
+          s1Y       = ( s1Y + offsetY ) >> iYShift ;
+          //s1Y = ClipBD( s1Y , bitDepthY );
+          s1Y = ClipY( s1Y );
+          Lum1[x]   = m_lut1d_output[0][ s1Y ];
+        }
+
+        if( bDoChroma && (x%2) )
+        {
+          if( m_matrix_flag )
+          {
+            //s1Y = ( m_lut1d_input[0][ Lum0[x] ] + m_lut1d_input[0][ Lum0[x+1] ] + m_lut1d_input[0][ LumPrev0[x] ] + m_lut1d_input[0][ LumPrev0[x+1] ] + 2 ) >> 2 ; 
+            //s1Y = m_lut1d_input[0][ (Lum0[x] + Lum0[x+1] + LumPrev0[x] + LumPrev0[x+1] + 2)>>2 ] ; 
+            s1Y = m_lut1d_input[0][ Lum0[x] ];
+
+            s2U = ( m_matrix_coef[1][0]*s1Y + m_matrix_coef[1][1]*s1U + m_matrix_coef[1][2]*s1V + offsetC ) >> ( m_log2_matrix_denom + iCShift ) ;
+            s2V = ( m_matrix_coef[2][0]*s1Y + m_matrix_coef[2][1]*s1U + m_matrix_coef[2][2]*s1V + offsetC ) >> ( m_log2_matrix_denom + iCShift ) ;
+            //s2U = ClipBD( s2U , bitDepthC );
+            //s2V = ClipBD( s2V , bitDepthC );
+            s2U = ClipC( s2U );
+            s2V = ClipC( s2V );
+            Cb1[x>>cShift] = m_lut1d_output[1][ s2U ];
+            Cr1[x>>cShift] = m_lut1d_output[2][ s2V ];
+          }
+          else
+          {
+            s1U       = ( s1U + offsetC ) >> iCShift ;
+            s1V       = ( s1V + offsetC ) >> iCShift ;
+            //s1U = ClipBD( s1U , bitDepthC );
+            //s1V = ClipBD( s1V , bitDepthC );
+            s1U = ClipC( s1U );
+            s1V = ClipC( s1V );
+            Cb1[x>>cShift] = m_lut1d_output[1][ s1U ];
+            Cr1[x>>cShift] = m_lut1d_output[2][ s1V ];
+          }
+        }
+
+      }
+
+      //LumPrev0 = Lum0;
+      Lum0  += iStride;
+      Lum1  += iStride;
+      if( bDoChroma )
+      {
+        Cb0 += iCStride;
+        Cr0 += iCStride;
+        Cb1 += iCStride;
+        Cr1 += iCStride;
+      }
+    }
+
+    return m_pcColorMappingPic[iTop];
+  }
+
+  return pPicYuvRec; 
+}
+#endif
+
 //! \}
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 649)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 713)
@@ -45,4 +45,7 @@
 #include "TLibCommon/TComTrQuant.h"
 #include "TLibCommon/SEI.h"
+#if Q0048_CGS_3D_ASYMLUT
+#include "TLibCommon/TCom3DAsymLUT.h"
+#endif
 
 #include "TDecGop.h"
@@ -61,4 +64,49 @@
 // ====================================================================================================================
 
+#if Q0074_SEI_COLOR_MAPPING
+class TDecColorMapping
+{
+  Int   m_colorMapId;
+  Bool  m_colorMapCancelFlag;
+  Bool  m_colorMapPersistenceFlag;
+  Bool  m_colorMap_video_signal_type_present_flag;
+  Bool  m_colorMap_video_full_range_flag;
+  Int   m_colorMap_primaries;
+  Int   m_colorMap_transfer_characteristics;
+  Int   m_colorMap_matrix_coeffs;
+  Int   m_colorMapModelId;
+
+  Int   m_colour_map_coded_data_bit_depth;
+  Int   m_colour_map_target_bit_depth;
+
+  Int   m_num_input_pivots[3];
+  Int*  m_coded_input_pivot_value[3];
+  Int*  m_target_input_pivot_value[3];
+  
+  Bool  m_matrix_flag;
+  Int   m_log2_matrix_denom;
+  Int   m_matrix_coef[3][3];
+
+  Int   m_num_output_pivots[3];
+  Int*  m_coded_output_pivot_value[3];
+  Int*  m_target_output_pivot_value[3];
+
+  Bool  m_lut1d_computed[3];
+  Int*  m_lut1d_input[3];
+  Int*  m_lut1d_output[3];
+  TComPicYuv* m_pcColorMappingPic[2];
+
+public:
+  TDecColorMapping();
+  ~TDecColorMapping();
+
+  Bool        getColorMappingFlag()                     { return(!m_colorMapCancelFlag);};
+
+  Void        setColorMapping( SEIMessages m_SEIs );
+  Void        setColorMapping( Int bitDepthY, Int bitDepthC );
+  TComPicYuv* getColorMapping( TComPicYuv* pPicYuvRec, Int iTop=0, Int curlayerId=0 );
+};// END CLASS DEFINITION TDecColorMapping
+#endif
+
 /// decoder class
 class TDecTop
@@ -79,4 +127,8 @@
   // functional classes
   TComPrediction          m_cPrediction;
+#if Q0048_CGS_3D_ASYMLUT
+  TCom3DAsymLUT           m_c3DAsymLUTPPS;
+  TComPicYuv*             m_pColorMappedPic;
+#endif
   TComTrQuant             m_cTrQuant;
   TDecGop                 m_cGopDecoder;
@@ -104,4 +156,10 @@
   Bool                    m_prevSliceSkipped;
   Int                     m_skippedPOC;
+#if SETTING_NO_OUT_PIC_PRIOR  
+  Bool                    m_bFirstSliceInBitstream;
+  Int                     m_lastPOCNoOutputPriorPics;
+  Bool                    m_isNoOutputPriorPics;
+  Bool                    m_craNoRaslOutputFlag;    //value of variable NoRaslOutputFlag of the last CRA pic
+#endif
 
 #if SVC_EXTENSION
@@ -114,6 +172,8 @@
 #if AVC_BASE
   fstream*                m_pBLReconFile;
+#if !REPN_FORMAT_IN_VPS
   Int                     m_iBLSourceWidth;
-  Int                     m_iBLSourceHeight;  
+  Int                     m_iBLSourceHeight;
+#endif
 #endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
@@ -136,17 +196,18 @@
 #endif
 
-#if NO_CLRAS_OUTPUT_FLAG
+#if NO_CLRAS_OUTPUT_FLAG  
   Bool                    m_noClrasOutputFlag;
   Bool                    m_layerInitializedFlag;
   Bool                    m_firstPicInLayerDecodedFlag;
-  Bool                    m_noOutputOfPriorPicsFlags;
-
-  Bool                   m_bRefreshPending;
 #endif
 #if RESOLUTION_BASED_DPB
-  Int                    m_subDpbIdx;     // Index to the sub-DPB that the layer belongs to.
-                                          // When new VPS is activated, this should be re-initialized to -1
+  Int                     m_subDpbIdx;     // Index to the sub-DPB that the layer belongs to.
+                                           // When new VPS is activated, this should be re-initialized to -1
 #endif
 public:
+#if Q0074_SEI_COLOR_MAPPING
+  TDecColorMapping* m_ColorMapping;
+#endif
+
   TDecTop();
   virtual ~TDecTop();
@@ -166,5 +227,15 @@
   Void  deletePicBuffer();
 
+  
+  TComSPS* getActiveSPS() { return m_parameterSetManagerDecoder.getActiveSPS(); }
+
+
   Void executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic);
+#if SETTING_NO_OUT_PIC_PRIOR  
+  Void  checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic);
+  Bool  getNoOutputPriorPicsFlag ()         { return m_isNoOutputPriorPics; }
+  Void  setNoOutputPriorPicsFlag (Bool val) { m_isNoOutputPriorPics = val; }
+#endif
+
 #if SVC_EXTENSION
 #if EARLY_REF_PIC_MARKING
@@ -212,7 +283,9 @@
   Void      setBLReconFile( fstream* pFile ) { m_pBLReconFile = pFile; }
   fstream*  getBLReconFile() { return m_pBLReconFile; }
+#if !REPN_FORMAT_IN_VPS
   Void      setBLsize( Int iWidth, Int iHeight ) { m_iBLSourceWidth = iWidth; m_iBLSourceHeight = iHeight; }
   Int       getBLWidth() { return  m_iBLSourceWidth; }
   Int       getBLHeight() { return  m_iBLSourceHeight; }
+#endif
 #endif
 #if REPN_FORMAT_IN_VPS
@@ -238,10 +311,4 @@
   Void      setBLSyntaxFile( fstream* pFile ) { m_pBLSyntaxFile = pFile; }
   fstream* getBLSyntaxFile() { return m_pBLSyntaxFile; }
-#endif
-#if NO_OUTPUT_OF_PRIOR_PICS
-#if NO_CLRAS_OUTPUT_FLAG
-  Bool getNoOutputOfPriorPicsFlags()         { return m_noOutputOfPriorPicsFlags;}
-  Void setNoOutputOfPriorPicsFlags(Bool x)   { m_noOutputOfPriorPicsFlags = x;   }
-#endif
 #endif
 protected:
@@ -261,5 +328,9 @@
   Void      xDecodeVPS();
   Void      xDecodeSPS();
-  Void      xDecodePPS();
+  Void      xDecodePPS(
+#if Q0048_CGS_3D_ASYMLUT
+    TCom3DAsymLUT * pc3DAsymLUT
+#endif
+    );
   Void      xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType );
 
@@ -271,8 +342,7 @@
   Int  getFirstPicInLayerDecodedFlag()       { return m_firstPicInLayerDecodedFlag;}
   Void setFirstPicInLayerDecodedFlag(Bool x) { m_firstPicInLayerDecodedFlag = x;   }
-#if !NO_OUTPUT_OF_PRIOR_PICS
-  Int  getNoOutputOfPriorPicsFlags()         { return m_noOutputOfPriorPicsFlags;}
-  Void setNoOutputOfPriorPicsFlags(Bool x)   { m_noOutputOfPriorPicsFlags = x;   }
-#endif
+#endif
+#if Q0048_CGS_3D_ASYMLUT
+  Void initAsymLut(TComSlice *pcSlice);
 #endif
 };// END CLASS DEFINITION TDecTop
Index: trunk/source/Lib/TLibEncoder/AnnexBwrite.h
===================================================================
--- trunk/source/Lib/TLibEncoder/AnnexBwrite.h	(revision 649)
+++ trunk/source/Lib/TLibEncoder/AnnexBwrite.h	(revision 713)
@@ -58,5 +58,5 @@
 
     static const Char start_code_prefix[] = {0,0,0,1};
-    if (it == au.begin() || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)
+    if (it == au.begin() || nalu.m_nalUnitType == NAL_UNIT_VPS || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)
     {
       /* From AVC, When any of the following conditions are fulfilled, the
Index: trunk/source/Lib/TLibEncoder/NALwrite.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/NALwrite.cpp	(revision 649)
+++ trunk/source/Lib/TLibEncoder/NALwrite.cpp	(revision 713)
@@ -91,7 +91,8 @@
   vector<uint8_t>& rbsp   = nalu.m_Bitstream.getFIFO();
 
-#if P0130_EOB
-  if (rbsp.size() == 0) return;
-#endif
+  if (rbsp.size() == 0)
+  {
+    return;
+  }
 
   for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();)
Index: trunk/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 649)
+++ trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 713)
@@ -87,4 +87,9 @@
     fprintf( g_hTrace, "=========== Tone Mapping Info SEI message ===========\n");
     break;
+#if Q0074_SEI_COLOR_MAPPING
+  case SEI::COLOR_MAPPING_INFO:
+    fprintf( g_hTrace, "=========== Color Mapping Info SEI message ===========\n");
+    break;
+#endif
   case SEI::SOP_DESCRIPTION:
     fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
@@ -172,4 +177,9 @@
     xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
     break;
+#if Q0074_SEI_COLOR_MAPPING
+  case SEI::COLOR_MAPPING_INFO:
+    xWriteSEIColorMappingInfo(*static_cast<const SEIColorMappingInfo*>(&sei));
+    break;
+#endif
   case SEI::SOP_DESCRIPTION:
     xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
@@ -333,27 +343,16 @@
 Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
 {
-  WRITE_CODE(sei.activeVPSId,     4, "active_vps_id");
-  WRITE_FLAG(sei.m_fullRandomAccessFlag, "full_random_access_flag");
-  WRITE_FLAG(sei.m_noParamSetUpdateFlag, "no_param_set_update_flag");
+  WRITE_CODE(sei.activeVPSId,     4,         "active_video_parameter_set_id");
+  WRITE_FLAG(sei.m_selfContainedCvsFlag,     "self_contained_cvs_flag");
+  WRITE_FLAG(sei.m_noParameterSetUpdateFlag, "no_parameter_set_update_flag");
   WRITE_UVLC(sei.numSpsIdsMinus1,    "num_sps_ids_minus1");
 
-  assert (sei.activeSeqParamSetId.size() == (sei.numSpsIdsMinus1 + 1));
-
-  for (Int i = 0; i < sei.activeSeqParamSetId.size(); i++)
-  {
-    WRITE_UVLC(sei.activeSeqParamSetId[i], "active_seq_param_set_id"); 
-  }
-
-  UInt uiBits = m_pcBitIf->getNumberOfWrittenBits();
-  UInt uiAlignedBits = ( 8 - (uiBits&7) ) % 8;  
-  if(uiAlignedBits) 
-  {
-    WRITE_FLAG(1, "alignment_bit" );
-    uiAlignedBits--; 
-    while(uiAlignedBits--)
-    {
-      WRITE_FLAG(0, "alignment_bit" );
-    }
-  }
+  assert (sei.activeSeqParameterSetId.size() == (sei.numSpsIdsMinus1 + 1));
+
+  for (Int i = 0; i < sei.activeSeqParameterSetId.size(); i++)
+  {
+    WRITE_UVLC(sei.activeSeqParameterSetId[i], "active_seq_parameter_set_id"); 
+  }
+  xWriteByteAlign();
 }
 
@@ -550,4 +549,9 @@
         {
           WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
+        }
+        WRITE_CODE( sei.m_exposureIndexIdc,     8,    "exposure_index_idc" );
+        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
+        {
+          WRITE_CODE( sei.m_exposureIndexValue,     32,    "exposure_index_value" );
         }
         WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
@@ -572,4 +576,65 @@
 }
 
+#if Q0074_SEI_COLOR_MAPPING
+Void SEIWriter::xWriteSEIColorMappingInfo(const SEIColorMappingInfo& sei)
+{
+  WRITE_UVLC( sei.m_colorMapId,                    "colour_map_id" );
+  WRITE_FLAG( sei.m_colorMapCancelFlag,            "colour_map_cancel_flag" );
+  if( !sei.m_colorMapCancelFlag ) 
+  {
+    WRITE_FLAG( sei.m_colorMapPersistenceFlag,            "colour_map_persistence_flag" );
+    WRITE_FLAG( sei.m_colorMap_video_signal_type_present_flag,            "colour_map_video_signal_type_present_flag" );
+    if ( sei.m_colorMap_video_signal_type_present_flag )
+    {
+      WRITE_FLAG( sei.m_colorMap_video_full_range_flag,       "colour_map_video_full_range_flag" );
+      WRITE_CODE( sei.m_colorMap_primaries,                 8,      "colour_map_primaries" );
+      WRITE_CODE( sei.m_colorMap_transfer_characteristics,  8,      "colour_map_transfer_characteristics" );
+      WRITE_CODE( sei.m_colorMap_matrix_coeffs,             8,      "colour_map_matrix_coeffs" );
+    }
+  }
+
+  WRITE_CODE( sei.m_colour_map_coded_data_bit_depth,  5,  "colour_map_coded_data_bit_depth" );
+  WRITE_CODE( sei.m_colour_map_target_bit_depth,  5,      "colour_map_target_bit_depth" );
+  WRITE_UVLC( sei.m_colorMapModelId,                      "colour_map_model_id" );
+
+  assert( sei.m_colorMapModelId == 0 );
+  
+  for( Int i=0 ; i<3 ; i++ )
+  {
+    WRITE_CODE( sei.m_num_input_pivots[i] - 1,         8,      "num_input_pivots_minus1[i]" );
+    for( Int j=0 ; j<sei.m_num_input_pivots[i] ; j++ )
+    {
+      WRITE_CODE( sei.m_coded_input_pivot_value[i][j],  (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "coded_input_pivot_value[i][j]" );
+      WRITE_CODE( sei.m_target_input_pivot_value[i][j], (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "target_input_pivot_value[i][j]" );
+    }
+  }
+
+  WRITE_FLAG( sei.m_matrix_flag,            "matrix_flag" );
+  if( sei.m_matrix_flag )
+  {
+    WRITE_CODE( sei.m_log2_matrix_denom, 4, "log2_matrix_denom" );
+    for( Int i=0 ; i<3 ; i++ )
+    {
+      for( Int j=0 ; j<3 ; j++ )
+      {
+        WRITE_SVLC( sei.m_matrix_coef[i][j],  "matrix_coef[i][j]" );
+      }
+    }
+  }
+
+  for( Int i=0 ; i<3 ; i++ )
+  {
+    WRITE_CODE( sei.m_num_output_pivots[i] - 1,         8,      "num_output_pivots_minus1[i]" );
+    for( Int j=0 ; j<sei.m_num_output_pivots[i] ; j++ )
+    {
+      WRITE_CODE( sei.m_coded_output_pivot_value[i][j],  (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "coded_output_pivot_value[i][j]" );
+      WRITE_CODE( sei.m_target_output_pivot_value[i][j], (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "target_output_pivot_value[i][j]" );
+    }
+  }
+
+  xWriteByteAlign();
+}
+#endif
+
 Void SEIWriter::xWriteSEIDisplayOrientation(const SEIDisplayOrientation &sei)
 {
@@ -633,4 +698,5 @@
     for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
     {
+      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
       WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id"       );
       WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
Index: trunk/source/Lib/TLibEncoder/SEIwrite.h
===================================================================
--- trunk/source/Lib/TLibEncoder/SEIwrite.h	(revision 649)
+++ trunk/source/Lib/TLibEncoder/SEIwrite.h	(revision 713)
@@ -72,4 +72,7 @@
   Void xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei);
   Void xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei);
+#if Q0074_SEI_COLOR_MAPPING
+  Void xWriteSEIColorMappingInfo(const SEIColorMappingInfo& sei);
+#endif
   Void xWriteSEISOPDescription(const SEISOPDescription& sei);
 #if O0164_MULTI_LAYER_HRD
Index: trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp	(revision 713)
+++ trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp	(revision 713)
@@ -0,0 +1,470 @@
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cmath>
+#include <algorithm>
+
+#include "TEnc3DAsymLUT.h"
+
+#if Q0048_CGS_3D_ASYMLUT
+
+TEnc3DAsymLUT::TEnc3DAsymLUT()
+{
+  m_pColorInfo = NULL;
+  m_pColorInfoC = NULL;
+  m_pEncCuboid = NULL;
+  m_pBestEncCuboid = NULL;
+  memset( m_nPrevFrameBit , 0 , sizeof( m_nPrevFrameBit ) );
+  memset( m_nPrevFrameCGSBit , 0 , sizeof( m_nPrevFrameCGSBit ) );
+  memset( m_nPrevFrameCGSPartNumLog2 , 0 , sizeof( m_nPrevFrameCGSPartNumLog2 ) );
+  memset( m_nPrevFrameOverWritePPS , 0 , sizeof( m_nPrevFrameOverWritePPS ) );
+  m_dTotalFrameBit = 0;
+  m_nTotalCGSBit = 0;
+  m_nPPSBit = 0;
+  m_pDsOrigPic = NULL;
+}
+
+Void TEnc3DAsymLUT::create( Int nMaxOctantDepth , Int nInputBitDepth , Int nInputBitDepthC , Int nOutputBitDepth , Int nOutputBitDepthC , Int nMaxYPartNumLog2 )
+{
+  if( m_pColorInfo != NULL )
+  {
+    destroy();
+  }
+
+  TCom3DAsymLUT::create( nMaxOctantDepth , nInputBitDepth , nInputBitDepthC, nOutputBitDepth , nOutputBitDepthC, nMaxYPartNumLog2 );
+  xAllocate3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() );
+  xAllocate3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() );
+  xAllocate3DArray( m_pEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() );
+  xAllocate3DArray( m_pBestEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() );
+}
+
+Void TEnc3DAsymLUT::destroy()
+{
+  xFree3DArray( m_pColorInfo );
+  xFree3DArray( m_pColorInfoC );
+  xFree3DArray( m_pEncCuboid );
+  xFree3DArray( m_pBestEncCuboid );
+  TCom3DAsymLUT::destroy();
+}
+
+TEnc3DAsymLUT::~TEnc3DAsymLUT()
+{
+  if( m_dTotalFrameBit != 0 )
+  {
+    printf( "\nTotal CGS bit: %d, %.2lf%%" , m_nTotalCGSBit , m_nTotalCGSBit * 100 / m_dTotalFrameBit );
+  }
+
+  destroy();
+}
+
+Double TEnc3DAsymLUT::xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
+  Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV ,
+  Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit )
+{
+  Int nInitP0 = rP0;
+  Int nInitP1 = rP1;
+  Int nInitP3 = rP3;
+  Int nInitP7 = rP7;
+
+  Double dNorm = (N * yy * vv * uu - N * yy * uv * uv - N * yv * yv * uu - N * vv * yu * yu + 2 * N * yv * uv * yu - yy * vs * vs * uu + 2 * yy * vs * uv * us - yy * vv * us * us - 2 * vs * uv * yu * ys + uv * uv * ys * ys + vs * vs * yu * yu - 2 * yv * vs * us * yu + 2 * yv * vs * ys * uu - 2 * yv * uv * us * ys + 2 * vv * yu * ys * us - vv * uu * ys * ys + yv * yv * us * us);
+  if( N > 16 && dNorm != 0 )
+  {
+    Double dInitA = (-N * uu * yv * Yv + N * uu * Yy * vv - N * Yy * uv * uv + N * yv * uv * Yu - N * yu * Yu * vv + N * yu * uv * Yv + yu * us * Ys * vv - vs * ys * uv * Yu - yu * vs * us * Yv - yv * uv * us * Ys - yv * vs * us * Yu - yu * uv * vs * Ys - ys * us * uv * Yv + ys * us * Yu * vv + 2 * Yy * vs * uv * us + uu * yv * vs * Ys - uu * ys * Ys * vv + uu * vs * ys * Yv + ys * Ys * uv * uv - Yy * vv * us * us + yu * Yu * vs * vs + yv * Yv * us * us - uu * Yy * vs * vs) / dNorm;
+    Double dInitB = (N * yy * Yu * vv - N * yy * uv * Yv - N * Yu * yv * yv - N * yu * Yy * vv + N * uv * yv * Yy + N * yv * yu * Yv - yy * us * Ys * vv + yy * uv * vs * Ys - yy * Yu * vs * vs + yy * vs * us * Yv - uv * vs * ys * Yy - yv * yu * vs * Ys + yu * Yy * vs * vs + yu * ys * Ys * vv - uv * yv * ys * Ys + 2 * Yu * yv * vs * ys + us * ys * Yy * vv - vs * ys * yu * Yv + uv * ys * ys * Yv + us * Ys * yv * yv - Yu * ys * ys * vv - yv * ys * us * Yv - vs * us * yv * Yy) / dNorm;
+    Double dInitC = -(-N * yy * Yv * uu + N * yy * uv * Yu - N * yv * yu * Yu - N * uv * yu * Yy + N * Yv * yu * yu + N * yv * Yy * uu - yy * uv * us * Ys + yy * Yv * us * us + yy * vs * Ys * uu - yy * vs * us * Yu + yv * ys * us * Yu - vs * Ys * yu * yu - yv * ys * Ys * uu + vs * us * yu * Yy + vs * ys * yu * Yu - uv * Yu * ys * ys + Yv * uu * ys * ys - yv * Yy * us * us - 2 * Yv * yu * ys * us - vs * ys * Yy * uu + uv * us * ys * Yy + uv * yu * ys * Ys + yv * yu * us * Ys) / dNorm;
+    Double dInitD = (-uu * yy * vs * Yv + uu * yy * Ys * vv + uu * vs * yv * Yy - uu * ys * Yy * vv + uu * ys * yv * Yv - uu * Ys * yv * yv + yy * vs * uv * Yu + yy * us * uv * Yv - yy * Ys * uv * uv - yy * us * Yu * vv + ys * yu * Yu * vv + vs * Yv * yu * yu + ys * Yy * uv * uv - us * yu * yv * Yv + us * yu * Yy * vv + 2 * Ys * yv * uv * yu - vs * uv * yu * Yy - vs * yv * yu * Yu - Ys * vv * yu * yu - us * uv * yv * Yy - ys * yv * uv * Yu - ys * yu * uv * Yv + us * Yu * yv * yv) / dNorm;
+    nInitP0 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 , u0 , v0 ) >> nResQuantBit  << nResQuantBit ; 
+    nInitP1 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 , u0 + nLengthUV , v0 ) >> nResQuantBit  << nResQuantBit ;
+    nInitP3 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 , u0 + nLengthUV , v0 + nLengthUV ) >> nResQuantBit  << nResQuantBit ;
+    nInitP7 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 + nLengthY , u0 + nLengthUV , v0 + nLengthUV ) >> nResQuantBit  << nResQuantBit ;
+  }
+
+  Int nMin = - ( 1 << ( m_nLUTBitDepth - 1 ) );
+  Int nMax = - nMin - ( 1 << nResQuantBit  );
+  Int nMask = ( 1 << nResQuantBit ) - 1;
+
+  Double dMinError = MAX_DOUBLE;
+  Int testRange = 2;
+  for( Int i = - testRange , nDeltaP01 = nInitP1 - nInitP0 - testRange * ( 1 << nResQuantBit  ) ; i <= testRange ; i++ , nDeltaP01 += ( 1 << nResQuantBit  ) )
+  {
+    for( Int j = - testRange , nDeltaP13 = nInitP3 - nInitP1 - testRange * ( 1 << nResQuantBit  ) ; j <= testRange ; j++ , nDeltaP13 += ( 1 << nResQuantBit  ) )
+    {
+      for( Int k = - testRange , nDeltaP37 = nInitP7 - nInitP3 - testRange * ( 1 << nResQuantBit  ) ; k <= testRange ; k++ , nDeltaP37 += ( 1 << nResQuantBit  ) )
+      {
+        Double a = 1.0 * nDeltaP37 / nLengthY;
+        Double b = 1.0 * nDeltaP01 / nLengthUV;
+        Double c = 1.0 * nDeltaP13 / nLengthUV;
+        Double d = ( Ys - a * ys - b * us - c * vs ) / N;
+        Int nP0 = xxCoeff2Vertex( a , b , c , d , y0 , u0 , v0 ) >> nResQuantBit  << nResQuantBit ;
+        nP0 = Clip3( nMin , nMax , nP0 );
+        Int nP1 = Clip3( nMin , nMax , nP0 + nDeltaP01 );
+        Int nP3 = Clip3( nMin , nMax , nP1 + nDeltaP13 );
+        Int nP7 = Clip3( nMin , nMax , nP3 + nDeltaP37 );
+        if ( nP0 & nMask )
+        {
+          nP0 -= ( nP0 & nMask );
+        }
+        if ( nP1 & nMask )
+        {
+          nP1 -= ( nP1 & nMask );
+        }
+        if ( nP3 & nMask )
+        {
+          nP3 -= ( nP3 & nMask );
+        }
+        if ( nP7 & nMask )
+        {
+          nP7 -= ( nP7 & nMask );
+        }
+        assert( !( nP0 & nMask ) && !( nP1 & nMask ) && !( nP3 & nMask ) && !( nP7 & nMask ) );
+        Double dError = xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , y0 , u0 , v0 , nLengthY , nLengthUV , nP0 , nP1 , nP3 , nP7 );
+        if( dError < dMinError )
+        {
+          dMinError = dError;
+          rP0 = ( Pel )nP0;
+          rP1 = ( Pel )nP1;
+          rP3 = ( Pel )nP3;
+          rP7 = ( Pel )nP7;
+          assert( nMin <= rP0 && rP0 <= nMax && nMin <= rP1 && rP1 <= nMax  && nMin <= rP3 && rP3 <= nMax && nMin <= rP7 && rP7 <= nMax );
+        }
+      }
+    }
+  }
+
+  return( dMinError );
+}
+
+Double TEnc3DAsymLUT::estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc )
+{
+  xxCollectData( pCurPic , refLayerIdc );
+
+  Double dErrorLuma = 0 , dErrorChroma = 0;
+  Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() );
+  Int nUVSize = 1 << getCurOctantDepth();
+  Int nLengthY = 1 << ( getInputBitDepthY() - getCurOctantDepth() - getCurYPartNumLog2() );
+  Int nLengthUV = 1 << ( getInputBitDepthC() - getCurOctantDepth() );
+  for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ )
+  {
+    for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ )
+    {
+      for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ )
+      {
+        SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx];
+        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx];
+        SCuboid & rCuboid = xGetCuboid( yIdx , uIdx , vIdx );
+        Int y0 = yIdx << xGetYShift2Idx();
+        Int u0 = uIdx << xGetUShift2Idx();
+        Int v0 = vIdx << xGetVShift2Idx();
+        if( rCuboidColorInfo.N > 0 )
+        {
+          dErrorLuma += xxCalEstDist( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
+            y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y );
+        }
+        if( rCuboidColorInfoC.N > 0 )
+        {
+          dErrorChroma += xxCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
+            y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U );
+          dErrorChroma += xxCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
+            y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V );
+        }
+      }
+    }
+  }
+
+  return( dErrorLuma + dErrorChroma);
+}
+
+Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB )
+{
+  m_nLUTBitDepth = pCfg->getCGSLUTBit();
+  Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0; 
+  xxDerivePartNumLog2( pSlice , pCfg , nCurOctantDepth , nCurYPartNumLog2 , bSignalPPS , bElRapSliceTypeB );
+  xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 );
+  xxCollectData( pCurPic , refLayerIdc );
+  Int nBestResQuanBit = 0;
+  Double dError0 = xxDeriveVertexes( nBestResQuanBit , m_pBestEncCuboid );
+  Double dCurError = dError0;
+  Double dFactor = 1 + 0.001 * ( pSlice->getDepth() + 1 );
+  for( Int nResQuanBit = 1 ; nResQuanBit < 4 ; nResQuanBit++ )
+  {
+    Double dError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid );
+    if( dError < dError0 * dFactor )
+    {
+      nBestResQuanBit = nResQuanBit;
+      SCuboid *** tmp = m_pBestEncCuboid;
+      m_pBestEncCuboid = m_pEncCuboid;
+      m_pEncCuboid = tmp;
+      dCurError = dError;
+    }
+    else
+    {
+      break;
+    }
+  }
+  setResQuantBit( nBestResQuanBit );
+  xSaveCuboids( m_pBestEncCuboid );
+
+  return( dCurError );
+}
+
+Double TEnc3DAsymLUT::xxDeriveVertexes( Int nResQuanBit , SCuboid *** pCurCuboid )
+{
+  Double dErrorLuma = 0 , dErrorChroma = 0;
+  Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() );
+  Int nUVSize = 1 << getCurOctantDepth();
+  Int nLengthY = 1 << ( getInputBitDepthY() - getCurOctantDepth() - getCurYPartNumLog2() );
+  Int nLengthUV = 1 << ( getInputBitDepthC() - getCurOctantDepth() );
+  for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ )
+  {
+    for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ )
+    {
+      for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ )
+      {
+        SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx];
+        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx];
+        SCuboid & rCuboid = pCurCuboid[yIdx][uIdx][vIdx];
+        Int y0 = yIdx << xGetYShift2Idx();
+        Int u0 = uIdx << xGetUShift2Idx();
+        Int v0 = vIdx << xGetVShift2Idx();
+        for( Int idxVertex = 0 ; idxVertex < 4 ; idxVertex++ )
+        {
+          rCuboid.P[idxVertex] = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , idxVertex , pCurCuboid );
+        }
+
+        if( rCuboidColorInfo.N > 0 )
+        {
+          dErrorLuma += xxDeriveVertexPerColor( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
+            y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y , nResQuanBit );
+        }
+        if( rCuboidColorInfoC.N > 0 )
+        {
+          dErrorChroma += xxDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
+            y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U , nResQuanBit );
+          dErrorChroma += xxDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
+            y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V , nResQuanBit );
+        }
+
+        if( nResQuanBit > 0 )
+        {
+          // check quantization
+          for( Int idxVertex = 0 ; idxVertex < 4 ; idxVertex++ )
+          {
+            SYUVP sPred = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , idxVertex , pCurCuboid );
+            assert( ( ( rCuboid.P[idxVertex].Y - sPred.Y ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].Y - sPred.Y );
+            assert( ( ( rCuboid.P[idxVertex].U - sPred.U ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].U - sPred.U );
+            assert( ( ( rCuboid.P[idxVertex].V - sPred.V ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].V - sPred.V );
+          }
+        }
+      }
+    }
+  }
+
+  return( dErrorLuma + dErrorChroma );
+}
+
+Void TEnc3DAsymLUT::xxCollectData( TComPic * pCurPic , UInt refLayerIdc )
+{
+  Pel * pSrcY = m_pDsOrigPic->getLumaAddr();
+  Pel * pSrcU = m_pDsOrigPic->getCbAddr();
+  Pel * pSrcV = m_pDsOrigPic->getCrAddr();
+  Int nStrideSrcY = m_pDsOrigPic->getStride();
+  Int nStrideSrcC = m_pDsOrigPic->getCStride();
+  TComPicYuv *pRecPic = pCurPic->getSlice(pCurPic->getCurrSliceIdx())->getBaseColPic(refLayerIdc)->getPicYuvRec();
+  Pel * pIRLY = pRecPic->getLumaAddr();
+  Pel * pIRLU = pRecPic->getCbAddr();
+  Pel * pIRLV = pRecPic->getCrAddr();
+  Int nStrideILRY = pRecPic->getStride();
+  Int nStrideILRC = pRecPic->getCStride();
+  Int nWidth = m_pDsOrigPic->getWidth();   //should exclude the padding;
+  Int nHeight= m_pDsOrigPic->getHeight();
+  xReset3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() );
+  xReset3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() );
+
+  //alignment padding
+  Pel *pU = pRecPic->getCbAddr();
+  Pel *pV = pRecPic->getCrAddr();
+  pU[(nWidth>>1)] = pU[(nWidth>>1)-1];
+  pV[(nWidth>>1)] = pV[(nWidth>>1)-1];
+  memcpy(pU-nStrideILRC, pU, ((nWidth>>1)+1)*sizeof(Pel));
+  memcpy(pV-nStrideILRC, pV, ((nWidth>>1)+1)*sizeof(Pel));
+  pU += nStrideILRC+ (nWidth>>1);
+  pV += nStrideILRC+ (nWidth>>1);
+
+  for( Int y = 1 ; y < (nHeight>>1) ; y ++ )
+  {
+    *pU = pU[-1];
+    *pV = pV[-1];
+    pU += nStrideILRC;
+    pV += nStrideILRC;
+  }
+  memcpy(pU-(nWidth>>1), pU-(nWidth>>1)-nStrideILRC, ((nWidth>>1)+1)*sizeof(Pel));
+  memcpy(pV-(nWidth>>1), pV-(nWidth>>1)-nStrideILRC, ((nWidth>>1)+1)*sizeof(Pel));
+
+  for( Int i = 0 ; i < nHeight ; i++ )
+  {
+    Int posSrcY = i * nStrideSrcY;
+    Int posIRLY = i * nStrideILRY;
+    Int posSrcUV = ( i >> 1 ) * nStrideSrcC;
+    Int posIRLUV = ( i >> 1 ) * nStrideILRC;
+    for( Int j = 0 ; j < nWidth ; j++ , posSrcY++ , posIRLY++ , posSrcUV += !( j & 0x01 ) , posIRLUV += !( j & 0x01 ) )
+    {
+      Int Y = pSrcY[posSrcY];
+      Int y = pIRLY[posIRLY];
+      Int U = pSrcU[posSrcUV];
+      Int u = pIRLU[posIRLUV];
+      Int V = pSrcV[posSrcUV];
+      Int v = pIRLV[posIRLUV];
+
+      // alignment
+      //filtering u, v for luma;
+      Int posIRLUVN =  posIRLUV + ((i&1)? nStrideILRC : -nStrideILRC);
+      if((j&1))
+      {
+        u = (pIRLU[posIRLUVN] + pIRLU[posIRLUVN+1] +(u + pIRLU[posIRLUV+1])*3 +4)>>3;
+        v = (pIRLV[posIRLUVN] + pIRLV[posIRLUVN+1] +(v + pIRLV[posIRLUV+1])*3 +4)>>3;
+      }
+      else
+      { 
+        u = (pIRLU[posIRLUVN] +u*3 +2)>>2;
+        v = (pIRLV[posIRLUVN] +v*3 +2)>>2;
+      }
+
+      SColorInfo sColorInfo;
+      SColorInfo & rCuboidColorInfo = m_pColorInfo[y>>xGetYShift2Idx()][u>>xGetUShift2Idx()][v>>xGetVShift2Idx()];
+      memset(&sColorInfo, 0, sizeof(SColorInfo));
+      sColorInfo.Ys = Y;
+      sColorInfo.ys = y;
+      sColorInfo.us = u;
+      sColorInfo.vs = v;
+      sColorInfo.Yy = Y * y;
+      sColorInfo.Yu = Y * u;
+      sColorInfo.Yv = Y * v;
+      sColorInfo.yy = y * y;
+      sColorInfo.yu = y * u;
+      sColorInfo.yv = y * v;
+      sColorInfo.uu = u * u;
+      sColorInfo.uv = u * v;
+      sColorInfo.vv = v * v;
+      sColorInfo.YY = Y * Y;
+      sColorInfo.N  = 1;
+
+      rCuboidColorInfo += sColorInfo;
+
+      if(!((i&1) || (j&1)))
+      {
+        // alignment
+        y =  (pIRLY[posIRLY] + pIRLY[posIRLY+nStrideILRY] + 1)>>1;
+
+        u = pIRLU[posIRLUV];
+        v = pIRLV[posIRLUV];
+        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[y>>xGetYShift2Idx()][u>>xGetUShift2Idx()][v>>xGetVShift2Idx()];
+        sColorInfo.Us = U;
+        sColorInfo.Vs = V;
+        sColorInfo.ys = y;
+        sColorInfo.us = u;
+        sColorInfo.vs = v;
+
+        sColorInfo.Uy = U * y;
+        sColorInfo.Uu = U * u;
+        sColorInfo.Uv = U * v;
+        sColorInfo.Vy = V * y;
+        sColorInfo.Vu = V * u;
+        sColorInfo.Vv = V * v;
+        sColorInfo.yy = y * y;
+        sColorInfo.yu = y * u;
+        sColorInfo.yv = y * v;
+        sColorInfo.uu = u * u;
+        sColorInfo.uv = u * v;
+        sColorInfo.vv = v * v;
+        sColorInfo.UU = U * U;
+        sColorInfo.VV = V * V;
+        sColorInfo.N  = 1;
+
+        rCuboidColorInfoC += sColorInfo;
+      }
+    }
+  }
+}
+
+Void TEnc3DAsymLUT::xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB )
+{
+  Int nSliceType = pSlice->getSliceType();
+  // update slice type as what will be done later
+  if( pSlice->getActiveNumILRRefIdx() == 0 && pSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
+  {
+    nSliceType = I_SLICE;
+  }
+  else if( !bElRapSliceTypeB )
+  {
+    if( (pSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
+      (pSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
+      pSlice->getSliceType() == B_SLICE )
+    {
+      nSliceType = P_SLICE;
+    }
+  }
+
+  const Int nSliceTempLevel = pSlice->getDepth();
+  Int nPartNumLog2 = 4;
+  if( pSlice->getBaseColPic( pSlice->getInterLayerPredLayerIdc( 0 ) )->getSlice( 0 )->isIntra() )
+  {
+    nPartNumLog2 = xGetMaxPartNumLog2();
+  }
+  if( m_nPrevFrameBit[nSliceType][nSliceTempLevel] && pSlice->getPPS()->getCGSFlag() ) 
+  {
+    Double dBitCost = 1.0 * m_nPrevFrameCGSBit[nSliceType][nSliceTempLevel] / m_nPrevFrameBit[nSliceType][nSliceTempLevel];
+    nPartNumLog2 = m_nPrevFrameCGSPartNumLog2[nSliceType][nSliceTempLevel];
+    Double dBitCostT = 0.03;
+    if( dBitCost < dBitCostT / 6.0 )
+    {
+      nPartNumLog2++;
+    }
+    else if( dBitCost >= dBitCostT )
+    {
+      nPartNumLog2--;
+    }
+  }
+  else
+  {
+    nPartNumLog2 -= nSliceTempLevel;
+  }
+  nPartNumLog2 = Clip3( 0 , xGetMaxPartNumLog2() , nPartNumLog2 );
+  xxMapPartNum2DepthYPart( nPartNumLog2 , rOctantDepth , rYPartNumLog2 );
+}
+
+Void TEnc3DAsymLUT::xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 )
+{
+  for( Int y = getMaxYPartNumLog2() ; y >= 0 ; y-- )
+  {
+    for( Int depth = ( nPartNumLog2 - y ) >> 1 ; depth >= 0 ; depth-- )
+    {
+      if( y + 3 * depth == nPartNumLog2 )
+      {
+        rOctantDepth = depth;
+        rYPartNumLog2 = y;
+        return;
+      }
+    }
+  }
+  rOctantDepth = min( getMaxOctantDepth() , nPartNumLog2 / 3 );
+  rYPartNumLog2 = min( getMaxYPartNumLog2() , nPartNumLog2 - 3 * rOctantDepth );
+}
+
+Void TEnc3DAsymLUT::updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit )
+{
+  const Int nSliceType = pcSlice->getSliceType();
+  const Int nSliceTempLevel = pcSlice->getDepth();
+
+  for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
+  {
+    UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
+    m_nPrevFrameBit[nSliceType][nSliceTempLevel] = pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit();
+    m_dTotalFrameBit += pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit();
+  }
+  m_nPrevFrameOverWritePPS[nSliceType][nSliceTempLevel] = pcSlice->getCGSOverWritePPS();
+  m_nPrevFrameCGSBit[nSliceType][nSliceTempLevel] = nPPSBit;
+  m_nTotalCGSBit += nPPSBit;
+  m_nPrevFrameCGSPartNumLog2[nSliceType][nSliceTempLevel] = getCurOctantDepth() * 3 + getCurYPartNumLog2();
+}
+
+#endif
Index: trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.h	(revision 713)
+++ trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.h	(revision 713)
@@ -0,0 +1,122 @@
+
+#ifndef __TENC3DASYMLUT__
+#define __TENC3DASYMLUT__
+
+#include "../TLibCommon/TCom3DAsymLUT.h"
+#include "../TLibCommon/TComSlice.h"
+#include "../TLibCommon/CommonDef.h"
+#include "../TLibCommon/TComPic.h"
+#include "TEncCfg.h"
+
+#if Q0048_CGS_3D_ASYMLUT
+
+typedef struct _ColorInfo
+{
+  Double YY , UU , VV;
+  Double Ys , Us , Vs;  // sum of enhancement
+  Double ys , us , vs;  // sum of base
+  Double Yy , Yu , Yv;  // product of enhancement and base
+  Double Uy , Uu , Uv;
+  Double Vy , Vu , Vv;
+  Double yy , yu , yv , uu , uv , vv; // product of base
+  Double N; // number of pixel
+
+public:
+  _ColorInfo & operator += ( const _ColorInfo & rColorInfo )
+  {
+    YY += rColorInfo.YY;
+    UU += rColorInfo.UU;
+    VV += rColorInfo.VV;
+    Ys += rColorInfo.Ys;
+    Us += rColorInfo.Us;
+    Vs += rColorInfo.Vs;
+    ys += rColorInfo.ys;
+    us += rColorInfo.us;
+    vs += rColorInfo.vs;
+    Yy += rColorInfo.Yy;
+    Yu += rColorInfo.Yu;
+    Yv += rColorInfo.Yv;
+    Uy += rColorInfo.Uy;
+    Uu += rColorInfo.Uu;
+    Uv += rColorInfo.Uv;
+    Vy += rColorInfo.Vy;
+    Vu += rColorInfo.Vu;
+    Vv += rColorInfo.Vv;
+    yy += rColorInfo.yy;
+    yu += rColorInfo.yu;
+    yv += rColorInfo.yv;
+    uu += rColorInfo.uu;
+    uv += rColorInfo.uv;
+    vv += rColorInfo.vv;
+    N  += rColorInfo.N; 
+    return *this;
+  }
+
+}SColorInfo;
+
+
+class TEnc3DAsymLUT : public TCom3DAsymLUT
+{
+public:
+  TEnc3DAsymLUT();
+  virtual ~TEnc3DAsymLUT();
+
+  virtual Void  create( Int nMaxOctantDepth , Int nInputBitDepth , Int nInputBitDepthC , Int nOutputBitDepth , Int nOutputBitDepthC , Int nMaxYPartNumLog2 );
+  virtual Void  destroy();
+  Double derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB );
+  Double estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc );
+
+  Void  updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit );
+  Void  setPPSBit(Int n)  { m_nPPSBit = n;  }
+  Int   getPPSBit()       { return m_nPPSBit;}
+  Void  setDsOrigPic(TComPicYuv *pPicYuv) { m_pDsOrigPic = pPicYuv; };
+
+protected:
+  SColorInfo *** m_pColorInfo;
+  SColorInfo *** m_pColorInfoC;
+  TComPicYuv* m_pDsOrigPic;
+  SCuboid *** m_pEncCuboid;
+  SCuboid *** m_pBestEncCuboid;
+  Int   m_nPrevFrameBit[3][MAX_TLAYER];                  // base + enhancement layer
+  Int   m_nPrevFrameCGSBit[3][MAX_TLAYER];
+  Int   m_nPrevFrameCGSPartNumLog2[3][MAX_TLAYER];
+  Int   m_nPrevFrameOverWritePPS[3][MAX_TLAYER];
+  Double m_dTotalFrameBit;
+  Int   m_nTotalCGSBit;
+  Int   m_nPPSBit;
+  Int   m_nLUTBitDepth;
+
+private:
+  Double  xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
+    Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV ,
+    Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit );
+  Void    xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB );
+  Void    xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 );
+  Int     xxCoeff2Vertex( Double a , Double b , Double c , Double d , Int y , Int u , Int v ) { return ( ( Int )( a * y + b * u + c * v + d + 0.5 ) ); }
+  Void    xxCollectData( TComPic * pCurPic , UInt refLayerIdc );
+  Double  xxDeriveVertexes( Int nResQuantBit , SCuboid *** pCurCuboid );
+  inline Double  xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
+    Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV , Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 );
+  inline Double  xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
+    Double a , Double b , Double c , Double d );
+};
+
+Double TEnc3DAsymLUT::xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
+  Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV , Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 )
+{
+  Double a = 1.0 * ( nP7 - nP3 ) / nLengthY;
+  Double b = 1.0 * ( nP1 - nP0 ) / nLengthUV;
+  Double c = 1.0 * ( nP3 - nP1 ) / nLengthUV;
+  Double d = ( ( nP0 * nLengthUV + u0 * nP0 + ( v0 - u0 ) * nP1 - v0 * nP3 ) * nLengthY + y0 * nLengthUV * ( nP3 - nP7 ) ) / nLengthUV / nLengthY;
+  return( xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , d ) );
+}
+
+Double TEnc3DAsymLUT::xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
+  Double a , Double b , Double c , Double d )
+{
+  Double dError = N * d * d + 2 * b * c * uv + 2 * a * c * yv + 2 * a * b * yu - 2 * c * Yv - 2 * b * Yu - 2 * a * Yy + 2 * c * d * vs + 2 * b * d * us + 2 * a * d * ys + a * a * yy + c * c * vv + b * b * uu - 2 * d * Ys + YY;
+  return( dError );
+};
+#endif
+
+#endif
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 713)
@@ -154,5 +154,9 @@
 
 
-Void TEncCavlc::codePPS( TComPPS* pcPPS )
+Void TEncCavlc::codePPS( TComPPS* pcPPS 
+#if Q0048_CGS_3D_ASYMLUT
+  , TEnc3DAsymLUT * pc3DAsymLUT
+#endif
+  )
 {
 #if ENC_DEC_TRACE  
@@ -268,4 +272,14 @@
     {
       WRITE_FLAG( pcPPS->getPocResetInfoPresentFlag() ? 1 : 0, "poc_reset_info_present_flag" );
+#if Q0048_CGS_3D_ASYMLUT
+      UInt uiPos = getNumberOfWrittenBits();
+      WRITE_FLAG( pcPPS->getCGSFlag() , "colour_mapping_enabled_flag" );
+      if( pcPPS->getCGSFlag() )
+      {
+        assert( pc3DAsymLUT != NULL );
+        xCode3DAsymLUT( pc3DAsymLUT );
+      }
+      pc3DAsymLUT->setPPSBit( getNumberOfWrittenBits() - uiPos );
+#endif
 #endif
     }
@@ -495,8 +509,15 @@
   if (conf.getWindowEnabledFlag())
   {
+#if REPN_FORMAT_IN_VPS
+    WRITE_UVLC( conf.getWindowLeftOffset(),   "conf_win_left_offset"   );
+    WRITE_UVLC( conf.getWindowRightOffset(),  "conf_win_right_offset"  );
+    WRITE_UVLC( conf.getWindowTopOffset(),    "conf_win_top_offset"    );
+    WRITE_UVLC( conf.getWindowBottomOffset(), "conf_win_bottom_offset" );
+#else
     WRITE_UVLC( conf.getWindowLeftOffset()   / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_left_offset" );
     WRITE_UVLC( conf.getWindowRightOffset()  / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_right_offset" );
     WRITE_UVLC( conf.getWindowTopOffset()    / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_top_offset" );
     WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" );
+#endif
   }
 
@@ -777,9 +798,14 @@
     }
   }
-#if !VPS_EXTNS
-  WRITE_FLAG( 0,                     "vps_extension_flag" );
-#else
-  WRITE_FLAG( 1,                     "vps_extension_flag" );
-  if(1) // Should be conditioned on the value of vps_extension_flag
+#if VPS_EXTNS
+  // When MaxLayersMinus1 is greater than 0, vps_extension_flag shall be equal to 1.
+  if( pcVPS->getMaxLayers() > 1 )
+  {
+    assert( pcVPS->getVpsExtensionFlag() == true );
+  }
+
+  WRITE_FLAG( pcVPS->getVpsExtensionFlag() ? 1 : 0,                     "vps_extension_flag" );
+
+  if( pcVPS->getVpsExtensionFlag() )
   {
     while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
@@ -797,4 +823,6 @@
     WRITE_FLAG( 0,                     "vps_extension2_flag" );   // Flag value of 1 reserved
   }
+#else
+  WRITE_FLAG( 0,                     "vps_extension_flag" );
 #endif  
   //future extensions here..
@@ -996,8 +1024,22 @@
   }
 #else
-  Int numOutputLayerSets = vps->getNumOutputLayerSets() ;
-  assert( numOutputLayerSets - (Int)vps->getNumLayerSets() >= 0 );
+  Int numOutputLayerSets = vps->getNumOutputLayerSets();
+  Int numAddOutputLayerSets = numOutputLayerSets - (Int)vps->getNumLayerSets();
+
+  // The value of num_add_output_layer_sets shall be in the range of 0 to 1023, inclusive.
+  assert( numAddOutputLayerSets >= 0 && numAddOutputLayerSets < 1024 );
+
+#if Q0165_NUM_ADD_OUTPUT_LAYER_SETS
+  if( vps->getNumLayerSets() > 1 )
+  {
+    WRITE_UVLC( numAddOutputLayerSets, "num_add_output_layer_sets" );
+    WRITE_CODE( vps->getDefaultTargetOutputLayerIdc(), 2, "default_target_output_layer_idc" );
+  }
+#else
   WRITE_UVLC( numOutputLayerSets - vps->getNumLayerSets(), "num_add_output_layer_sets" );
 #endif
+#endif
+
+#if !Q0165_NUM_ADD_OUTPUT_LAYER_SETS
   if( numOutputLayerSets > 1 )
   {
@@ -1012,4 +1054,5 @@
 #endif
   }
+#endif
 
   for(i = 1; i < numOutputLayerSets; i++)
@@ -1059,4 +1102,9 @@
       WRITE_FLAG(vps->getAltOuputLayerFlag(i), "alt_output_layer_flag[i]");
     }
+
+#if Q0165_OUTPUT_LAYER_SET
+    assert( NumOutputLayersInOutputLayerSet[i]>0 );
+#endif
+
 #endif
   }
@@ -1072,8 +1120,46 @@
 
 #if REPN_FORMAT_IN_VPS
+#if Q0195_REP_FORMAT_CLEANUP  
+  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
+  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
+  
+  WRITE_UVLC( vps->getVpsNumRepFormats() - 1, "vps_num_rep_formats_minus1" );
+
+  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
+  {
+    // Write rep_format_structures
+    codeRepFormat( vps->getVpsRepFormat(i) );
+  }
+
+  if( vps->getVpsNumRepFormats() > 1 )
+  {
+    WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag"); 
+  }
+  else
+  {
+    // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
+    assert( !vps->getRepFormatIdxPresentFlag() );
+  }
+
+  if( vps->getRepFormatIdxPresentFlag() )
+  {
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      Int numBits = 1;
+      while ((1 << numBits) < (vps->getVpsNumRepFormats()))
+      {
+        numBits++;
+      }
+      WRITE_CODE( vps->getVpsRepFormatIdx(i), numBits, "vps_rep_format_idx[i]" );
+    }
+  }
+#else
   WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag"); 
 
   if( vps->getRepFormatIdxPresentFlag() )
   {
+    // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
+    assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
+
 #if O0096_REP_FORMAT_INDEX
 #if !VPS_EXTN_UEV_CODING
@@ -1115,4 +1201,5 @@
     }
   }
+#endif
 #endif
 
@@ -1181,4 +1268,7 @@
 
 #if P0307_VPS_NON_VUI_EXTENSION
+  // The value of vps_non_vui_extension_length shall be in the range of 0 to 4096, inclusive.
+  assert( vps->getVpsNonVuiExtLength() >= 0 && vps->getVpsNonVuiExtLength() <= 4096 );
+
   WRITE_UVLC( vps->getVpsNonVuiExtLength(), "vps_non_vui_extension_length" );
 #if P0307_VPS_NON_VUI_EXT_UPDATE
@@ -1216,6 +1306,6 @@
 #else
 #if P0307_REMOVE_VPS_VUI_OFFSET
-  WRITE_FLAG( 1,                     "vps_vui_present_flag" );
   vps->setVpsVuiPresentFlag(true);
+  WRITE_FLAG( vps->getVpsVuiPresentFlag() ? 1 : 0,                     "vps_vui_present_flag" );
 #endif
   if(vps->getVpsVuiPresentFlag())   // Should be conditioned on the value of vps_vui_present_flag
@@ -1238,26 +1328,25 @@
 #endif
 #if REPN_FORMAT_IN_VPS
-Void  TEncCavlc::codeRepFormat      ( RepFormat *repFormat )
+Void  TEncCavlc::codeRepFormat( RepFormat *repFormat )
 {
 #if REPN_FORMAT_CONTROL_FLAG
-   WRITE_FLAG ( repFormat->getChromaAndBitDepthVpsPresentFlag(), "chroma_and_bit_depth_vps_presenet_flag"); 
-
-   WRITE_CODE ( repFormat->getPicWidthVpsInLumaSamples (), 16, "pic_width_in_luma_samples" );    
-   WRITE_CODE ( repFormat->getPicHeightVpsInLumaSamples(), 16, "pic_height_in_luma_samples" );  
-
-   if ( repFormat->getChromaAndBitDepthVpsPresentFlag() )
-   {
-     WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" );   
-
-     if( repFormat->getChromaFormatVpsIdc() == 3 )
-     {
-       WRITE_FLAG( repFormat->getSeparateColourPlaneVpsFlag(), "separate_colour_plane_flag");      
-     }
-
-     assert( repFormat->getBitDepthVpsLuma() >= 8 );
-     assert( repFormat->getBitDepthVpsChroma() >= 8 );
-     WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8,   4, "bit_depth_luma_minus8" );           
-     WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );
-   }
+  WRITE_CODE( repFormat->getPicWidthVpsInLumaSamples (), 16, "pic_width_vps_in_luma_samples" );    
+  WRITE_CODE( repFormat->getPicHeightVpsInLumaSamples(), 16, "pic_height_vps_in_luma_samples" );  
+  WRITE_FLAG( repFormat->getChromaAndBitDepthVpsPresentFlag(), "chroma_and_bit_depth_vps_present_flag" );
+
+  if( repFormat->getChromaAndBitDepthVpsPresentFlag() )
+  {
+    WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_vps_idc" );   
+
+    if( repFormat->getChromaFormatVpsIdc() == 3 )
+    {
+      WRITE_FLAG( repFormat->getSeparateColourPlaneVpsFlag(), "separate_colour_plane_vps_flag" );      
+    }
+
+    assert( repFormat->getBitDepthVpsLuma() >= 8 );
+    assert( repFormat->getBitDepthVpsChroma() >= 8 );
+    WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8,   4, "bit_depth_vps_luma_minus8" );           
+    WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_vps_chroma_minus8" );
+  }
 #else 
   WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" );    
@@ -1275,6 +1364,5 @@
   WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8,   4, "bit_depth_luma_minus8" );           
   WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );
-#endif 
-
+#endif
 }
 #endif
@@ -1375,9 +1463,9 @@
         if( vps->getBitRatePresentVpsFlag() )
         {
-          WRITE_FLAG( vps->getBitRatePresentFlag( i, j),        "bit_rate_present_vps_flag[i][j]" );
+          WRITE_FLAG( vps->getBitRatePresentFlag( i, j),        "bit_rate_present_flag[i][j]" );
         }
         if( vps->getPicRatePresentVpsFlag() )
         {
-          WRITE_FLAG( vps->getPicRatePresentFlag( i, j),        "pic_rate_present_vps_flag[i][j]" );
+          WRITE_FLAG( vps->getPicRatePresentFlag( i, j),        "pic_rate_present_flag[i][j]" );
         }
         if( vps->getBitRatePresentFlag(i, j) )
@@ -1466,4 +1554,10 @@
 #endif
 #if HIGHER_LAYER_IRAP_SKIP_FLAG
+  // When single_layer_for_non_irap_flag is equal to 0, higher_layer_irap_skip_flag shall be equal to 0
+  if( !vps->getSingleLayerForNonIrapFlag() )
+  {
+    assert( !vps->getHigherLayerIrapSkipFlag() );
+  }
+
   WRITE_FLAG(vps->getHigherLayerIrapSkipFlag(), "higher_layer_irap_skip_flag" );
 #endif
@@ -1564,10 +1658,9 @@
     for(i = 1; i < vps->getMaxLayers(); i++)
     {
-      if(vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0) 
-      {
-        if ((vps->getSPSId(i) == 0) && (vps->getPPSId(i) == 0))
+      if( vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0 ) 
+      {
+        if( (vps->getSPSId(i) == 0) && (vps->getPPSId(i) == 0) )
         {
           vps->setBaseLayerPSCompatibilityFlag(i, 1);
-          WRITE_FLAG(vps->getBaseLayerPSCompatibilityFlag(i), "base_layer_parameter_set_compatibility_flag" );
         }
         else
@@ -1575,4 +1668,5 @@
           vps->setBaseLayerPSCompatibilityFlag(i, 0);
         }
+        WRITE_FLAG(vps->getBaseLayerPSCompatibilityFlag(i), "base_layer_parameter_set_compatibility_flag" );
       }
     }
@@ -1612,6 +1706,6 @@
   if ( pcSlice->getRapPicFlag() )
   {
-#if NO_OUTPUT_OF_PRIOR_PICS
-    WRITE_FLAG( pcSlice->getNoOutputOfPriorPicsFlag(), "no_output_of_prior_pics_flag" );
+#if SETTING_NO_OUT_PIC_PRIOR
+    WRITE_FLAG( pcSlice->getNoOutputPriorPicsFlag() ? 1 : 0, "no_output_of_prior_pics_flag" );
 #else
     WRITE_FLAG( 0, "no_output_of_prior_pics_flag" );
@@ -2616,3 +2710,63 @@
   return true;
 }
+
+#if Q0048_CGS_3D_ASYMLUT
+Void TEncCavlc::xCode3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT )
+{
+  assert( pc3DAsymLUT->getCurOctantDepth() < 4 );
+  WRITE_CODE( pc3DAsymLUT->getCurOctantDepth() , 2 , "cm_octant_depth" );
+  assert( pc3DAsymLUT->getCurYPartNumLog2() < 4 );
+  WRITE_CODE( pc3DAsymLUT->getCurYPartNumLog2() , 2 , "cm_y_part_num_log2" );
+  assert( pc3DAsymLUT->getInputBitDepthY() < 16 );
+  WRITE_CODE( pc3DAsymLUT->getInputBitDepthY() - 8 , 3 , "cm_input_bit_depth_minus8" );
+  WRITE_SVLC(pc3DAsymLUT->getInputBitDepthC()-pc3DAsymLUT->getInputBitDepthY(), "cm_input_bit_depth_chroma delta");
+  assert( pc3DAsymLUT->getOutputBitDepthY() < 16 );
+  WRITE_CODE( pc3DAsymLUT->getOutputBitDepthY() - 8 , 3 , "cm_output_bit_depth_minus8" );
+  WRITE_SVLC(pc3DAsymLUT->getOutputBitDepthC()-pc3DAsymLUT->getOutputBitDepthY(), "cm_output_bit_depth_chroma_delta");
+  assert( pc3DAsymLUT->getResQuantBit() < 4 );
+  WRITE_CODE( pc3DAsymLUT->getResQuantBit() , 2 , "cm_res_quant_bit" );
+
+  xCode3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() );
+}
+
+Void TEncCavlc::xCode3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength )
+{
+  UInt uiOctantSplit = nDepth < pc3DAsymLUT->getCurOctantDepth();
+  if( nDepth < pc3DAsymLUT->getCurOctantDepth() )
+    WRITE_FLAG( uiOctantSplit , "split_octant_flag" );
+  Int nYPartNum = 1 << pc3DAsymLUT->getCurYPartNumLog2();
+  if( uiOctantSplit )
+  {
+    Int nHalfLength = nLength >> 1;
+    for( Int l = 0 ; l < 2 ; l++ )
+    {
+      for( Int m = 0 ; m < 2 ; m++ )
+      {
+        for( Int n = 0 ; n < 2 ; n++ )
+        {
+          xCode3DAsymLUTOctant( pc3DAsymLUT , nDepth + 1 , yIdx + l * nHalfLength * nYPartNum , uIdx + m * nHalfLength , vIdx + n * nHalfLength , nHalfLength );
+        }
+      }
+    }
+  }
+  else
+  {
+    for( Int l = 0 ; l < nYPartNum ; l++ )
+    {
+      for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
+      {
+        SYUVP sRes = pc3DAsymLUT->getCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx );
+        UInt uiCodeVertex = sRes.Y != 0 || sRes.U != 0 || sRes.V != 0;
+        WRITE_FLAG( uiCodeVertex , "coded_vertex_flag" );
+        if( uiCodeVertex )
+        {
+          WRITE_SVLC( sRes.Y , "resY" );
+          WRITE_SVLC( sRes.U , "resU" );
+          WRITE_SVLC( sRes.V , "resV" );
+        }
+      }
+    }
+  }
+}
+#endif
 //! \}
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 713)
@@ -48,4 +48,8 @@
 #include "TEncEntropy.h"
 #include "SyntaxElementWriter.h"
+#if Q0048_CGS_3D_ASYMLUT
+#include "../TLibCommon/TCom3DAsymLUT.h"
+#include "TEnc3DAsymLUT.h"
+#endif
 
 //! \ingroup TLibEncoder
@@ -53,4 +57,7 @@
 
 class TEncTop;
+#if Q0048_CGS_3D_ASYMLUT
+class TCom3DAsymLUT;
+#endif
 
 // ====================================================================================================================
@@ -90,5 +97,9 @@
   Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
   Void  codeSPS                 ( TComSPS* pcSPS );
-  Void  codePPS                 ( TComPPS* pcPPS );
+  Void  codePPS                 ( TComPPS* pcPPS 
+#if Q0048_CGS_3D_ASYMLUT
+    , TEnc3DAsymLUT * pc3DAsymLUT
+#endif
+    );
   Void  codeSliceHeader         ( TComSlice* pcSlice );
   Void  codePTL                 ( TComPTL* pcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1);
@@ -162,4 +173,9 @@
   Void  codeVpsDpbSizeTable      (TComVPS *vps);
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+protected:
+  Void xCode3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT );
+  Void xCode3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength );
+#endif
 #endif //SVC_EXTENSION
 
Index: trunk/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 713)
@@ -235,4 +235,6 @@
   Int       m_cameraIsoSpeedIdc;
   Int       m_cameraIsoSpeedValue;
+  Int       m_exposureIndexIdc;
+  Int       m_exposureIndexValue;
   Int       m_exposureCompensationValueSignFlag;
   Int       m_exposureCompensationValueNumerator;
@@ -246,4 +248,7 @@
   Int*      m_codedPivotValue;
   Int*      m_targetPivotValue;
+#if Q0074_SEI_COLOR_MAPPING
+  Char*     m_seiColorMappingFile;
+#endif
   Int       m_framePackingSEIEnabled;
   Int       m_framePackingSEIType;
@@ -362,4 +367,10 @@
   UInt      m_bottomRightTileIndex[1024];
   UInt      m_ilcIdc[1024];
+#endif
+#if Q0048_CGS_3D_ASYMLUT
+  Int  m_nCGSFlag;
+  Int  m_nCGSMaxOctantDepth;
+  Int  m_nCGSMaxYPartNumLog2;
+  Int  m_nCGSLUTBit;
 #endif
 #endif //SVC_EXTENSION
@@ -639,4 +650,8 @@
   Void  setTMISEICameraIsoSpeedValue(Int b)                  {  m_cameraIsoSpeedValue = b;  }
   Int   getTMISEICameraIsoSpeedValue()                       {  return m_cameraIsoSpeedValue;  }
+  Void  setTMISEIExposureIndexIdc(Int b)                     {  m_exposureIndexIdc = b;  }
+  Int   getTMISEIExposurIndexIdc()                           {  return m_exposureIndexIdc;  }
+  Void  setTMISEIExposureIndexValue(Int b)                   {  m_exposureIndexValue = b;  }
+  Int   getTMISEIExposurIndexValue()                         {  return m_exposureIndexValue;  }
   Void  setTMISEIExposureCompensationValueSignFlag(Int b)    {  m_exposureCompensationValueSignFlag = b;  }
   Int   getTMISEIExposureCompensationValueSignFlag()         {  return m_exposureCompensationValueSignFlag;  }
@@ -655,4 +670,8 @@
   Void  setTMISEIExtendedWhiteLevelLumaCodeValue(Int b)      {  m_extendedWhiteLevelLumaCodeValue =b;  }
   Int   getTMISEIExtendedWhiteLevelLumaCodeValue()           {  return m_extendedWhiteLevelLumaCodeValue;  }
+#if Q0074_SEI_COLOR_MAPPING
+  Void  setColorMappingInfoSEIFile( Char* nameFile )         {  m_seiColorMappingFile = nameFile; }
+  Char* getColorMappingInfoSEIFile()                         {  return m_seiColorMappingFile; }
+#endif
   Void  setFramePackingArrangementSEIEnabled(Int b)      { m_framePackingSEIEnabled = b; }
   Int   getFramePackingArrangementSEIEnabled()           { return m_framePackingSEIEnabled; }
@@ -898,4 +917,14 @@
   UInt  getIlcIdc(UInt b)                                  { return m_ilcIdc[b]; }
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  Void      setCGSFlag(Int n)             { m_nCGSFlag = n;    }
+  Int       getCGSFlag()                  { return m_nCGSFlag; }
+  Void      setCGSMaxOctantDepth(Int n)   { m_nCGSMaxOctantDepth = n;    }
+  Int       getCGSMaxOctantDepth()        { return m_nCGSMaxOctantDepth; }
+  Void      setCGSMaxYPartNumLog2(Int n)  { m_nCGSMaxYPartNumLog2 = n;    }
+  Int       getCGSMaxYPartNumLog2()       { return m_nCGSMaxYPartNumLog2; }
+  Void      setCGSLUTBit(Int n)           { m_nCGSLUTBit = n;    }
+  Int       getCGSLUTBit()                { return m_nCGSLUTBit; }
+#endif
 #endif
 };
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 713)
@@ -79,4 +79,11 @@
 }
 
+#if Q0048_CGS_3D_ASYMLUT
+Void TEncEntropy::encodePPS( TComPPS* pcPPS, TEnc3DAsymLUT * pc3DAsymLUT  )
+{
+  m_pcEntropyCoderIf->codePPS( pcPPS, pc3DAsymLUT );
+  return;
+}
+#else
 Void TEncEntropy::encodePPS( TComPPS* pcPPS )
 {
@@ -84,4 +91,5 @@
   return;
 }
+#endif
 
 Void TEncEntropy::encodeSPS( TComSPS* pcSPS )
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 713)
@@ -50,4 +50,7 @@
 class TEncCavlc;
 class SEI;
+#if Q0048_CGS_3D_ASYMLUT
+class TEnc3DAsymLUT;
+#endif
 
 // ====================================================================================================================
@@ -70,5 +73,9 @@
   virtual Void  codeVPS                 ( TComVPS* pcVPS )                                      = 0;
   virtual Void  codeSPS                 ( TComSPS* pcSPS )                                      = 0;
-  virtual Void  codePPS                 ( TComPPS* pcPPS )                                      = 0;
+  virtual Void  codePPS                 ( TComPPS* pcPPS 
+#if Q0048_CGS_3D_ASYMLUT
+    , TEnc3DAsymLUT * pc3DAsymLUT
+#endif
+    )                                      = 0;
   virtual Void  codeSliceHeader         ( TComSlice* pcSlice )                                  = 0;
 
@@ -156,5 +163,9 @@
   // SPS
   Void encodeSPS               ( TComSPS* pcSPS );
-  Void encodePPS               ( TComPPS* pcPPS );
+  Void encodePPS               ( TComPPS* pcPPS 
+#if Q0048_CGS_3D_ASYMLUT
+    , TEnc3DAsymLUT * pc3DAsymLUT
+#endif
+    );
   Void encodeSplitFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD = false );
   Void encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 713)
@@ -75,4 +75,7 @@
   m_iNumPicCoded        = 0; //Niko
   m_bFirst              = true;
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  m_iLastRecoveryPicPOC = 0;
+#endif
   
   m_pcCfg               = NULL;
@@ -103,4 +106,8 @@
   m_pcPredSearch        = NULL;
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  m_temp = NULL;
+  m_pColorMappedPic = NULL;
+#endif
   return;
 }
@@ -108,4 +115,17 @@
 TEncGOP::~TEncGOP()
 {
+#if Q0048_CGS_3D_ASYMLUT
+  if(m_pColorMappedPic)
+  {
+    m_pColorMappedPic->destroy();
+    delete m_pColorMappedPic;
+    m_pColorMappedPic = NULL;                
+  }
+  if(m_temp)
+  {
+    free_mem2DintWithPad(m_temp, m_iTap>>1, 0);
+    m_temp = NULL;
+  }
+#endif
 }
 
@@ -157,4 +177,16 @@
   m_pcPredSearch         = pcTEncTop->getPredSearch();                       ///< encoder search class
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  if( pcTEncTop->getLayerId() )
+  {
+    m_Enc3DAsymLUTPicUpdate.create( m_pcCfg->getCGSMaxOctantDepth() , g_bitDepthYLayer[pcTEncTop->getLayerId()-1] , g_bitDepthCLayer[pcTEncTop->getLayerId()-1] , g_bitDepthYLayer[pcTEncTop->getLayerId()] , g_bitDepthCLayer[pcTEncTop->getLayerId()] , m_pcCfg->getCGSMaxYPartNumLog2() /*, m_pcCfg->getCGSPhaseAlignment()*/ );
+    m_Enc3DAsymLUTPPS.create(   m_pcCfg->getCGSMaxOctantDepth() , g_bitDepthYLayer[pcTEncTop->getLayerId()-1] , g_bitDepthCLayer[pcTEncTop->getLayerId()-1] , g_bitDepthYLayer[pcTEncTop->getLayerId()] , g_bitDepthCLayer[pcTEncTop->getLayerId()] , m_pcCfg->getCGSMaxYPartNumLog2() /*, m_pcCfg->getCGSPhaseAlignment()*/ );
+    if(!m_pColorMappedPic)
+    {
+      m_pColorMappedPic = new TComPicYuv;
+      m_pColorMappedPic->create( m_ppcTEncTop[0]->getSourceWidth(), m_ppcTEncTop[0]->getSourceHeight(), CHROMA_420, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
+    }
+  }
+#endif
 }
 
@@ -163,12 +195,11 @@
   SEIActiveParameterSets *seiActiveParameterSets = new SEIActiveParameterSets(); 
   seiActiveParameterSets->activeVPSId = m_pcCfg->getVPS()->getVPSId(); 
-  seiActiveParameterSets->m_fullRandomAccessFlag = false;
-  seiActiveParameterSets->m_noParamSetUpdateFlag = false;
+  seiActiveParameterSets->m_selfContainedCvsFlag = false;
+  seiActiveParameterSets->m_noParameterSetUpdateFlag = false;
   seiActiveParameterSets->numSpsIdsMinus1 = 0;
-  seiActiveParameterSets->activeSeqParamSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); 
-  seiActiveParameterSets->activeSeqParamSetId[0] = sps->getSPSId();
+  seiActiveParameterSets->activeSeqParameterSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); 
+  seiActiveParameterSets->activeSeqParameterSetId[0] = sps->getSPSId();
   return seiActiveParameterSets;
 }
-
 
 SEIFramePacking* TEncGOP::xCreateSEIFramePacking()
@@ -271,4 +302,7 @@
        seiToneMappingInfo->m_cameraIsoSpeedValue = m_pcCfg->getTMISEICameraIsoSpeedValue();
        assert( seiToneMappingInfo->m_cameraIsoSpeedValue !=0 );
+       seiToneMappingInfo->m_exposureIndexIdc = m_pcCfg->getTMISEIExposurIndexIdc();
+       seiToneMappingInfo->m_exposureIndexValue = m_pcCfg->getTMISEIExposurIndexValue();
+       assert( seiToneMappingInfo->m_exposureIndexValue !=0 );
        seiToneMappingInfo->m_exposureCompensationValueSignFlag = m_pcCfg->getTMISEIExposureCompensationValueSignFlag();
        seiToneMappingInfo->m_exposureCompensationValueNumerator = m_pcCfg->getTMISEIExposureCompensationValueNumerator();
@@ -293,4 +327,88 @@
 }
 
+#if Q0074_SEI_COLOR_MAPPING
+SEIColorMappingInfo*  TEncGOP::xCreateSEIColorMappingInfo( Char* file )
+{
+  SEIColorMappingInfo *seiColorMappingInfo = new SEIColorMappingInfo();
+
+  FILE* fic = fopen( file, "r" );
+
+  Int iVal, retval;
+
+  retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colorMapId );
+  retval = fscanf( fic, "%d", &iVal );
+  seiColorMappingInfo->m_colorMapCancelFlag = iVal;
+  if( !seiColorMappingInfo->m_colorMapCancelFlag )
+  {
+    retval = fscanf( fic, "%d", &iVal );
+    seiColorMappingInfo->m_colorMapPersistenceFlag = iVal;
+    retval = fscanf( fic, "%d", &iVal );
+    seiColorMappingInfo->m_colorMap_video_signal_type_present_flag = iVal;
+    if( seiColorMappingInfo->m_colorMap_video_signal_type_present_flag )
+    {
+      retval = fscanf( fic, "%d", &iVal );
+      seiColorMappingInfo->m_colorMap_video_full_range_flag = iVal;
+      retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colorMap_primaries );
+      retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colorMap_transfer_characteristics );
+      retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colorMap_matrix_coeffs );
+    }
+  }
+
+  retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colour_map_coded_data_bit_depth );
+  retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colour_map_target_bit_depth );
+  retval = fscanf( fic, "%d", &iVal );
+  seiColorMappingInfo->m_colorMapModelId = iVal;
+
+  assert( seiColorMappingInfo->m_colorMapModelId == 0 );
+  
+  for( Int i=0 ; i<3 ; i++ )
+  {
+    retval = fscanf( fic, "%d", &seiColorMappingInfo->m_num_input_pivots[i] );
+    seiColorMappingInfo->m_coded_input_pivot_value[i]   = new Int[ seiColorMappingInfo->m_num_input_pivots[i] ];
+    seiColorMappingInfo->m_target_input_pivot_value[i]  = new Int[ seiColorMappingInfo->m_num_input_pivots[i] ];
+    for( Int j=0 ; j<seiColorMappingInfo->m_num_input_pivots[i] ; j++ )
+    {
+      retval = fscanf( fic, "%d", &seiColorMappingInfo->m_coded_input_pivot_value[i][j] );
+      retval = fscanf( fic, "%d", &seiColorMappingInfo->m_target_input_pivot_value[i][j] );
+    }
+  }
+
+  retval = fscanf( fic, "%d", &iVal );
+  seiColorMappingInfo->m_matrix_flag = iVal;
+  if( seiColorMappingInfo->m_matrix_flag )
+  {
+    retval = fscanf( fic, "%d", &seiColorMappingInfo->m_log2_matrix_denom );
+    for( Int i=0 ; i<3 ; i++ )
+    {
+      for( Int j=0 ; j<3 ; j++ )
+      {
+        retval = fscanf( fic, "%d", &seiColorMappingInfo->m_matrix_coef[i][j] );
+      }
+    }
+  }
+
+  for( Int i=0 ; i<3 ; i++ )
+  {
+    retval = fscanf( fic, "%d", &seiColorMappingInfo->m_num_output_pivots[i] );
+    seiColorMappingInfo->m_coded_output_pivot_value[i]   = new Int[ seiColorMappingInfo->m_num_output_pivots[i] ];
+    seiColorMappingInfo->m_target_output_pivot_value[i]  = new Int[ seiColorMappingInfo->m_num_output_pivots[i] ];
+    for( Int j=0 ; j<seiColorMappingInfo->m_num_output_pivots[i] ; j++ )
+    {
+      retval = fscanf( fic, "%d", &seiColorMappingInfo->m_coded_output_pivot_value[i][j] );
+      retval = fscanf( fic, "%d", &seiColorMappingInfo->m_target_output_pivot_value[i][j] );
+    }
+  }
+
+  fclose( fic );
+
+  if( retval != 1 )
+  {
+    printf("Error: can't read color mapping information\n");
+  }
+
+  return seiColorMappingInfo;
+}
+#endif
+
 Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps)
 {
@@ -359,4 +477,25 @@
     delete sei;
   }
+#if Q0074_SEI_COLOR_MAPPING
+  if(m_pcCfg->getColorMappingInfoSEIFile())
+  {
+    SEIColorMappingInfo *sei = xCreateSEIColorMappingInfo( m_pcCfg->getColorMappingInfoSEIFile() );
+      
+#if SVC_EXTENSION
+    nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, m_layerId);  // temporalId = 0 ?
+#else
+    nalu = NALUnit(NAL_UNIT_PREFIX_SEI);
+#endif
+    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+#if O0164_MULTI_LAYER_HRD
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, m_pcEncTop->getVPS(), sps); 
+#else
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); 
+#endif
+    writeRBSPTrailingBits(nalu.m_Bitstream);
+    accessUnit.push_back(new NALUnitEBSP(nalu));
+    delete sei;
+  }
+#endif
 
 #if SVC_EXTENSION
@@ -435,4 +574,54 @@
   UInt *accumNalsDU = NULL;
   SEIDecodingUnitInfo decodingUnitInfoSEI;
+#if EFFICIENT_FIELD_IRAP
+  Int IRAPGOPid = -1;
+  Bool IRAPtoReorder = false;
+  Bool swapIRAPForward = false;
+  if(isField)
+  {
+    Int pocCurr;
+#if SVC_EXTENSION
+    for ( Int iGOPid=iPicIdInGOP; iGOPid < iPicIdInGOP+1; iGOPid++ )
+#else
+    for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ )
+#endif    
+    {
+      // determine actual POC
+      if(iPOCLast == 0) //case first frame or first top field
+      {
+        pocCurr=0;
+      }
+      else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value
+      {
+        pocCurr = 1;
+      }
+      else
+      {
+        pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField;
+      }
+
+      // check if POC corresponds to IRAP
+      NalUnitType tmpUnitType = getNalUnitType(pocCurr, m_iLastIDR, isField);
+      if(tmpUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && tmpUnitType <= NAL_UNIT_CODED_SLICE_CRA) // if picture is an IRAP
+      {
+        if(pocCurr%2 == 0 && iGOPid < m_iGopSize-1 && m_pcCfg->getGOPEntry(iGOPid).m_POC == m_pcCfg->getGOPEntry(iGOPid+1).m_POC-1)
+        { // if top field and following picture in enc order is associated bottom field
+          IRAPGOPid = iGOPid;
+          IRAPtoReorder = true;
+          swapIRAPForward = true; 
+          break;
+        }
+        if(pocCurr%2 != 0 && iGOPid > 0 && m_pcCfg->getGOPEntry(iGOPid).m_POC == m_pcCfg->getGOPEntry(iGOPid-1).m_POC+1)
+        {
+          // if picture is an IRAP remember to process it first
+          IRAPGOPid = iGOPid;
+          IRAPtoReorder = true;
+          swapIRAPForward = false; 
+          break;
+        }
+      }
+    }
+  }
+#endif
 #if SVC_EXTENSION
   for ( Int iGOPid=iPicIdInGOP; iGOPid < iPicIdInGOP+1; iGOPid++ )
@@ -441,4 +630,31 @@
 #endif
   {
+#if EFFICIENT_FIELD_IRAP
+    if(IRAPtoReorder)
+    {
+      if(swapIRAPForward)
+      {
+        if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid +1;
+        }
+        else if(iGOPid == IRAPGOPid +1)
+        {
+          iGOPid = IRAPGOPid;
+        }
+      }
+      else
+      {
+        if(iGOPid == IRAPGOPid -1)
+        {
+          iGOPid = IRAPGOPid;
+        }
+        else if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid -1;
+        }
+      }
+    }
+#endif
     UInt uiColDir = 1;
     //-- For time output for each slice
@@ -510,4 +726,33 @@
     if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
     {
+#if EFFICIENT_FIELD_IRAP
+      if(IRAPtoReorder)
+      {
+        if(swapIRAPForward)
+        {
+          if(iGOPid == IRAPGOPid)
+          {
+            iGOPid = IRAPGOPid +1;
+            IRAPtoReorder = false;
+          }
+          else if(iGOPid == IRAPGOPid +1)
+          {
+            iGOPid --;
+          }
+        }
+        else
+        {
+          if(iGOPid == IRAPGOPid)
+          {
+            iGOPid = IRAPGOPid -1;
+          }
+          else if(iGOPid == IRAPGOPid -1)
+          {
+            iGOPid = IRAPGOPid;
+            IRAPtoReorder = false;
+          }
+        }
+      }
+#endif
       continue;
     }
@@ -803,5 +1048,10 @@
         Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
         Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
-
+#if Q0200_CONFORMANCE_BL_SIZE
+        Int chromaFormatIdc = pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getChromaFormatIdc();
+        const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getConformanceWindow();
+        widthBL  -= ( confBL.getWindowLeftOffset() + confBL.getWindowRightOffset() ) * TComSPS::getWinUnitX( chromaFormatIdc );
+        heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
+#endif
         Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
         Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
@@ -813,12 +1063,32 @@
         g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
 
+#if Q0048_CGS_3D_ASYMLUT 
+        TComPicYuv* pBaseColRec = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
+        if( pcSlice->getPPS()->getCGSFlag() )
+        {
+          if(g_posScalingFactor[refLayerIdc][0] < (1<<16) || g_posScalingFactor[refLayerIdc][1] < (1<<16)) //if(pcPic->isSpatialEnhLayer(refLayerIdc))
+          {
+            //downsampling;
+            downScalePic(pcPic->getPicYuvOrg(), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvOrg());
+            //pcSlice->getBaseColPic(refLayerIdc)->getPicYuvOrg()->dump("ds.yuv", true, true);
+            m_Enc3DAsymLUTPPS.setDsOrigPic(pcSlice->getBaseColPic(refLayerIdc)->getPicYuvOrg());
+            m_Enc3DAsymLUTPicUpdate.setDsOrigPic(pcSlice->getBaseColPic(refLayerIdc)->getPicYuvOrg());
+          }
+          else
+          {
+            m_Enc3DAsymLUTPPS.setDsOrigPic(pcPic->getPicYuvOrg());
+            m_Enc3DAsymLUTPicUpdate.setDsOrigPic(pcPic->getPicYuvOrg());
+          }
+
+          Bool bSignalPPS = m_bSeqFirst;
+          bSignalPPS |= m_pcCfg->getGOPSize() > 1 ? pocCurr % m_pcCfg->getIntraPeriod() == 0 : pocCurr % m_pcCfg->getFrameRate() == 0;
+          xDetermin3DAsymLUT( pcSlice , pcPic , refLayerIdc , m_pcCfg , bSignalPPS );
+          m_Enc3DAsymLUTPPS.colorMapping( pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(),  m_pColorMappedPic );
+          pBaseColRec = m_pColorMappedPic;
+        }
+#endif
 #if SVC_UPSAMPLING
         if( pcPic->isSpatialEnhLayer(refLayerIdc))
         {
-/*#if O0098_SCALED_REF_LAYER_ID
-          Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
-#else
-          Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
-#endif*/
 #if P0312_VERT_PHASE_ADJ
           //when PhasePositionEnableFlag is equal to 1, set vertPhasePositionFlag to 0 if BL is top field and 1 if bottom
@@ -830,19 +1100,39 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
+#if Q0048_CGS_3D_ASYMLUT 
+          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
+#endif
+#else
+#if Q0048_CGS_3D_ASYMLUT
+          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
 #else
           m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
 #endif
+#endif
 #else
 #if O0194_JOINT_US_BITSHIFT
+#if Q0048_CGS_3D_ASYMLUT 
+          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#else
           m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+#endif
+#else
+#if Q0048_CGS_3D_ASYMLUT 
+          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
 #else
           m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
 #endif
 #endif
+#endif
         }
         else
         {
+#if Q0048_CGS_3D_ASYMLUT 
+          pcPic->setFullPelBaseRec( refLayerIdc, pBaseColRec );
+#else
           pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
+#endif
         }
         pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
@@ -856,5 +1146,5 @@
       }
 
-#if !O0225_TID_BASED_IL_RPS_DERIV
+#if !O0225_TID_BASED_IL_RPS_DERIV || Q0060_MAX_TID_REF_EQUAL_TO_ZERO
       pcSlice->setActiveNumILRRefIdx( activeNumILRRefIdxTmp );
 #endif 
@@ -932,12 +1222,5 @@
     }
 
-    // Do decoding refresh marking if any 
-#if NO_CLRAS_OUTPUT_FLAG
-    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic, m_pcEncTop->getNoClrasOutputFlag());
-#else
-    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic);
-#endif
-    m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
-    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
+#if EFFICIENT_FIELD_IRAP
 #if FIX1172
     if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
@@ -954,9 +1237,46 @@
     pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC);
 #endif
-
+#endif
+    // Do decoding refresh marking if any 
+#if NO_CLRAS_OUTPUT_FLAG
+    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic, m_pcEncTop->getNoClrasOutputFlag());
+#else
+    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic);
+#endif
+    m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
+    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
+#if EFFICIENT_FIELD_IRAP
+#else
+#if FIX1172
+    if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )  // IRAP picture
+    {
+      m_associatedIRAPType = pcSlice->getNalUnitType();
+      m_associatedIRAPPOC = pocCurr;
+    }
+    pcSlice->setAssociatedIRAPType(m_associatedIRAPType);
+    pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC);
+#endif
+#endif
+
+#if ALLOW_RECOVERY_POINT_AS_RAP
+    if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false, m_iLastRecoveryPicPOC, m_pcCfg->getDecodingRefreshType() == 3) != 0) || (pcSlice->isIRAP()) 
+#if EFFICIENT_FIELD_IRAP
+      || (isField && pcSlice->getAssociatedIRAPType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getAssociatedIRAPType() <= NAL_UNIT_CODED_SLICE_CRA && pcSlice->getAssociatedIRAPPOC() == pcSlice->getPOC()+1)
+#endif
+      )
+    {
+      pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP(), m_iLastRecoveryPicPOC, m_pcCfg->getDecodingRefreshType() == 3);
+    }
+#else
     if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP()))
     {
       pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP());
     }
+#endif
 #if ALIGNED_BUMPING
     pcSlice->checkLeadingPictureRestrictions(rcListPic);
@@ -1743,5 +2063,9 @@
       assert( pcSlice->getPPS()->getPPSId() == 0 || pcSlice->getPPS()->getPPSId() == m_layerId || m_pcEncTop->getVPS()->getRecursiveRefLayerFlag(m_layerId, pcSlice->getPPS()->getPPSId()) );
 #endif
-      m_pcEntropyCoder->encodePPS(pcSlice->getPPS());
+      m_pcEntropyCoder->encodePPS(pcSlice->getPPS()
+#if Q0048_CGS_3D_ASYMLUT
+        , & m_Enc3DAsymLUTPPS
+#endif
+        );
       writeRBSPTrailingBits(nalu.m_Bitstream);
       accessUnit.push_back(new NALUnitEBSP(nalu));
@@ -1776,4 +2100,17 @@
       m_bSeqFirst = false;
     }
+#if Q0048_CGS_3D_ASYMLUT
+    else if( m_pcCfg->getCGSFlag() && pcSlice->getLayerId() && pcSlice->getCGSOverWritePPS() )
+    {
+#if SVC_EXTENSION
+      OutputNALUnit nalu(NAL_UNIT_PPS, 0, m_layerId);
+#endif
+
+      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+      m_pcEntropyCoder->encodePPS(pcSlice->getPPS() , &m_Enc3DAsymLUTPPS );
+      writeRBSPTrailingBits(nalu.m_Bitstream);
+      accessUnit.push_back(new NALUnitEBSP(nalu));
+    }
+#endif
 
     if (writeSOP) // write SOP description SEI (if enabled) at the beginning of GOP
@@ -1849,7 +2186,14 @@
       pictureTimingSEI.m_auCpbRemovalDelay = std::min<Int>(std::max<Int>(1, m_totalCoded - m_lastBPSEI), static_cast<Int>(pow(2, static_cast<double>(pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getCpbRemovalDelayLengthMinus1()+1)))); // Syntax element signalled as minus, hence the .
 #if POC_RESET_FLAG
-      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pocCurr - m_totalCoded;
-#else
-      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
+      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(pcSlice->getSPS()->getMaxTLayers()-1) + pocCurr - m_totalCoded;
+#else
+      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(pcSlice->getSPS()->getMaxTLayers()-1) + pcSlice->getPOC() - m_totalCoded;
+#endif
+#if EFFICIENT_FIELD_IRAP
+      if(IRAPGOPid > 0 && IRAPGOPid < m_iGopSize)
+      {
+        // if pictures have been swapped there is likely one more picture delay on their tid. Very rough approximation
+        pictureTimingSEI.m_picDpbOutputDelay ++;
+      }
 #endif
       Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
@@ -1975,4 +2319,10 @@
 #endif
       sei_recovery_point.m_brokenLinkFlag    = false;
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      if(m_pcCfg->getDecodingRefreshType() == 3)
+      {
+        m_iLastRecoveryPicPOC = pocCurr;
+      }
+#endif
 
 #if O0164_MULTI_LAYER_HRD
@@ -2110,4 +2460,23 @@
           }
           m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+
+#if SETTING_NO_OUT_PIC_PRIOR
+          if (pcSlice->isIRAP())
+          {
+            if (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP)
+            {
+              pcSlice->setNoRaslOutputFlag(true);
+            }
+            //the inference for NoOutputPriorPicsFlag
+            if (!m_bFirst && pcSlice->isIRAP() && pcSlice->getNoRaslOutputFlag())
+            {
+              if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
+              {
+                pcSlice->setNoOutputPriorPicsFlag(true);
+              }
+            }
+          }
+#endif
+
           tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits();
           m_pcEntropyCoder->encodeSliceHeader(pcSlice);
@@ -2657,4 +3026,34 @@
 
       delete[] pcSubstreamsOut;
+
+#if EFFICIENT_FIELD_IRAP
+    if(IRAPtoReorder)
+    {
+      if(swapIRAPForward)
+      {
+        if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid +1;
+          IRAPtoReorder = false;
+        }
+        else if(iGOPid == IRAPGOPid +1)
+        {
+          iGOPid --;
+        }
+      }
+      else
+      {
+        if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid -1;
+        }
+        else if(iGOPid == IRAPGOPid -1)
+        {
+          iGOPid = IRAPGOPid;
+          IRAPtoReorder = false;
+        }
+      }
+    }
+#endif
   }
   delete pcBitstreamRedirect;
@@ -2918,5 +3317,7 @@
     case NAL_UNIT_CODED_SLICE_CRA:        return "CRA";
     case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
+    case NAL_UNIT_CODED_SLICE_RADL_N:     return "RADL_N";
     case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
+    case NAL_UNIT_CODED_SLICE_RASL_N:     return "RASL_N";
     case NAL_UNIT_VPS:                    return "VPS";
     case NAL_UNIT_SPS:                    return "SPS";
@@ -3080,5 +3481,5 @@
          pcSlice->getTLayer(),
          c,
-         NaluToStr( pcSlice->getNalUnitType() ).data().
+         NaluToStr( pcSlice->getNalUnitType() ).data(),
          pcSlice->getSliceQp(),
          uibits );
@@ -3134,4 +3535,11 @@
     printf("]");
   }
+#if Q0048_CGS_3D_ASYMLUT
+  pcPic->setFrameBit( (Int)uibits );
+  if( m_layerId && pcSlice->getPPS()->getCGSFlag() )
+  {
+    m_Enc3DAsymLUTPicUpdate.updatePicCGSBits( pcSlice , m_Enc3DAsymLUTPPS.getPPSBit() );
+  }
+#endif
 }
 
@@ -3316,5 +3724,17 @@
     return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
   }
+#if EFFICIENT_FIELD_IRAP
+  if(isField && pocCurr == 1)
+  {
+    // to avoid the picture becoming an IRAP
+    return NAL_UNIT_CODED_SLICE_TRAIL_R;
+  }
+#endif
+
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(m_pcCfg->getDecodingRefreshType() != 3 && (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0)
+#else
   if ((pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0)
+#endif
   {
     if (m_pcCfg->getDecodingRefreshType() == 1)
@@ -3828,4 +4248,223 @@
 #endif
 
+#if Q0048_CGS_3D_ASYMLUT
+Void TEncGOP::xDetermin3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS )
+{
+  Int nCGSFlag = pSlice->getPPS()->getCGSFlag();
+  m_Enc3DAsymLUTPPS.setPPSBit( 0 );
+  Double dErrorUpdatedPPS = 0 , dErrorPPS = 0;
+  dErrorUpdatedPPS = m_Enc3DAsymLUTPicUpdate.derive3DAsymLUT( pSlice , pCurPic , refLayerIdc , pCfg , bSignalPPS , m_pcEncTop->getElRapSliceTypeB() );
+  if( bSignalPPS )
+  {
+    m_Enc3DAsymLUTPPS.copy3DAsymLUT( &m_Enc3DAsymLUTPicUpdate );
+    pSlice->setCGSOverWritePPS( 1 ); // regular PPS update
+  }
+  else if( nCGSFlag )
+  {
+    dErrorPPS = m_Enc3DAsymLUTPPS.estimateDistWithCur3DAsymLUT( pCurPic , refLayerIdc );
+    Double dFactor = pCfg->getIntraPeriod() == 1 ? 0.99 : 0.9;
+    pSlice->setCGSOverWritePPS( dErrorUpdatedPPS < dFactor * dErrorPPS );
+    if( pSlice->getCGSOverWritePPS() )
+    {
+      m_Enc3DAsymLUTPPS.copy3DAsymLUT( &m_Enc3DAsymLUTPicUpdate );
+    }
+  }
+  pSlice->getPPS()->setCGSOutputBitDepthY( m_Enc3DAsymLUTPPS.getOutputBitDepthY() );
+  pSlice->getPPS()->setCGSOutputBitDepthC( m_Enc3DAsymLUTPPS.getOutputBitDepthC() );
+}
+
+Void TEncGOP::downScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest)
+{
+  Int inputBitDepth = g_bitDepthYLayer[m_layerId];
+  Int outputBitDepth = g_bitDepthYLayer[m_layerId];
+  {
+    pcYuvSrc->setBorderExtension(false);
+    pcYuvSrc->extendPicBorder   (); // extend the border.
+    pcYuvSrc->setBorderExtension(false);
+
+    Int iWidth = pcYuvSrc->getWidth();
+    Int iHeight =pcYuvSrc->getHeight(); 
+
+    if(!m_temp)
+      initDs(iWidth, iHeight, m_pcCfg->getIntraPeriod()>1);
+
+    filterImg(pcYuvSrc->getLumaAddr(), pcYuvSrc->getStride(), pcYuvDest->getLumaAddr(), pcYuvDest->getStride(), iHeight, iWidth,  inputBitDepth-outputBitDepth, 0);
+    filterImg(pcYuvSrc->getCbAddr(), pcYuvSrc->getCStride(), pcYuvDest->getCbAddr(), pcYuvDest->getCStride(), iHeight>>1, iWidth>>1, inputBitDepth-outputBitDepth, 1);
+    filterImg(pcYuvSrc->getCrAddr(), pcYuvSrc->getCStride(), pcYuvDest->getCrAddr(), pcYuvDest->getCStride(), iHeight>>1, iWidth>>1, inputBitDepth-outputBitDepth, 2);  
+  }
+}
+const int TEncGOP::m_phase_filter_0_t0[4][13]={
+  {0,  2,  -3,  -9,   6,  39,  58,  39,   6,  -9,  -3,  2,  0},  
+  {0, 0,  0,  -2,  8,-20, 116, 34, -10,  2,  0, 0,  0},                      //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
+  {0,  1,   0,  -7,  -5,  22,  53,  53,  22,  -5,  -7,  0,  1},  
+  {0,  0,   1,  -5,  -7,  13,  47,  57,  31,  -1,  -8,-1,  1}  
+};
+
+const int TEncGOP::m_phase_filter_0_t1[4][13]={
+  {0,  4,  0,  -12, 0,  40,  64,  40, 0, -12,  0,  4,  0},
+  {0, 0,  0,  -2,  8,-20, 116,34,-10,  2,  0, 0,  0},                      //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
+  {0,  1,   0,  -7,  -5,  22,  53,  53,  22,  -5,  -7,  0,  1},  
+  {0,  0,   1,  -5,  -7,  13,  47,  57,  31,  -1,  -8,-1,  1}  
+};
+const int TEncGOP::m_phase_filter_0_t1_chroma[4][13]={
+  {0,  0,  0,   0,  0,   0,  128, 0,  0,  0,  0,  0,  0},
+  {0, 0,  0,  -2,  8,-20, 116,34,-10,  2,  0, 0,  0},                      //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
+  {0,  1,   0,  -7,  -5,  22,  53,  53,  22,  -5,  -7,  0,  1},  
+  {0,  0,   1,  -5,  -7,  13,  47,  57,  31,  -1,  -8,-1,  1}  
+};
+
+const int TEncGOP::m_phase_filter_1[8][13]={
+  {0,   0,  5,  -6,  -10,37,  76,  37,-10,   -6, 5,  0,   0},    
+  {0,  -1,  5,  -3,  -12,29,  75,  45,  -7,   -8, 5,  0,   0},    
+  {0,  -1,  4,  -1,  -13,22,  73,  52,  -3,  -10, 4,  1,   0},    
+  {0,  -1,  4,   1,  -13,14,  70,  59,   2,  -12, 3,  2,  -1},  
+  {0,  -1,  3,   2,  -13, 8,  65,  65,   8,  -13, 2,  3,  -1},    
+  {0,  -1,  2,   3,  -12, 2,  59,  70,  14,  -13, 1,  4,  -1},    
+  {0,   0,  1,   4,  -10,-3,  52,  73,  22,  -13,-1,  4,  -1},    
+  {0,   0,  0,   5,   -8,-7,  45,  75,  29,  -12,-3,  5,  -1}    
+};
+
+Void TEncGOP::filterImg(
+    Pel           *src,
+    Int           iSrcStride,
+    Pel           *dst,
+    Int           iDstStride,
+    Int           height1,  
+    Int           width1,  
+    Int           shift,
+    Int           plane)
+{
+  Int length = m_iTap;
+  Int height2,width2;
+  Int k,iSum;
+  Int i0, div_i0, i1;
+  Int j0, div_j0, j1;
+  const Int *p_filter;
+  Pel *p_src, *p_dst;
+  Pel *p_src_line, *p_dst_line;
+  Int **p_temp, *p_tmp;
+  Int shift2 = 2*7+shift;
+  Int shift_round = (1 << (shift2 - 1));
+  Int iMax = (1<<(g_bitDepthY-shift))-1;
+  height2 = (height1 * m_iM) / m_iN;
+  width2  = (width1  * m_iM) / m_iN;
+
+  m_phase_filter = plane? m_phase_filter_chroma : m_phase_filter_luma;
+
+  // horizontal filtering
+  p_src_line = src;
+  for(j1 = 0; j1 < height1; j1++)
+  {
+    i0=-m_iN;
+    p_tmp = m_temp[j1];
+    
+    for(i1 = 0; i1 < width2; i1++)
+    {
+      i0      += m_iN;
+      div_i0   = (i0 / m_iM);
+      p_src    =  p_src_line + ( div_i0 - (length >> 1));
+      p_filter = m_phase_filter[i0 - div_i0 * m_iM]; // phase_filter[i0 % M]
+      iSum     = 0;
+      for(k = 0; k < length; k++)
+      {
+        iSum += (*p_src++) * (*p_filter++);
+      }
+      *p_tmp++ = iSum;
+    }
+    p_src_line +=  iSrcStride;
+  }
+
+  // pad temp (vertical)
+  for (k=-(length>>1); k<0; k++)
+    memcpy(m_temp[k], m_temp[0], width2*sizeof(int));
+  for (k=height1; k<(height1+(length>>1)); k++)
+    memcpy(m_temp[k], m_temp[k-1], (width2)* sizeof(int));
+
+  // vertical filtering
+  j0 = (plane == 0) ? -m_iN : -(m_iN-1);
+  
+  p_dst_line = dst;
+  for(j1 = 0; j1 < height2; j1++)
+  {
+    j0      += m_iN;
+    div_j0   = (j0 / m_iM);
+    p_dst = p_dst_line;
+    p_temp   = &m_temp[div_j0 - (length>>1)];
+    p_filter = m_phase_filter[j0 - div_j0 * m_iM]; // phase_filter[j0 % M]
+    for(i1 = 0; i1 < width2;i1++)
+    {
+      iSum=0;
+      for(k = 0; k < length; k++)
+      {
+        iSum += p_temp[k][i1] * p_filter[k];
+      }
+      iSum=((iSum + shift_round) >> shift2);
+      *p_dst++ = (short)(iSum > iMax ? iMax : (iSum < 0 ? 0 : iSum));
+    }
+    p_dst_line += iDstStride;
+  }
+}
+
+Void TEncGOP::initDs(Int iWidth, Int iHeight, Int iType)
+{
+  m_iTap = 13;
+  if(g_posScalingFactor[0][0] == (1<<15))
+  {
+    m_iM = 4;
+    m_iN = 8;
+    m_phase_filter_luma = iType? m_phase_filter_0_t1 : m_phase_filter_0_t0;
+    m_phase_filter_chroma = m_phase_filter_0_t1_chroma; 
+  }
+  else
+  {
+    m_iM = 8;
+    m_iN = 12;
+    m_phase_filter_luma = m_phase_filter_chroma =  m_phase_filter_1;
+    m_phase_filter = m_phase_filter_1;
+  }
+
+  get_mem2DintWithPad (&m_temp, iHeight, iWidth*m_iM/m_iN,   m_iTap>>1, 0);
+}
+
+Int TEncGOP::get_mem2DintWithPad(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX)
+{
+  Int i;
+  Int *curr = NULL;
+  Int iHeight, iWidth;
+
+  iHeight = dim0+2*iPadY;
+  iWidth = dim1+2*iPadX;
+  (*array2D) = (Int**)malloc(iHeight*sizeof(Int*));
+  *(*array2D) = (Int* )xMalloc(Int, iHeight*iWidth);
+
+  (*array2D)[0] += iPadX;
+  curr = (*array2D)[0];
+  for(i = 1 ; i < iHeight; i++)
+  {
+    curr += iWidth;
+    (*array2D)[i] = curr;
+  }
+  (*array2D) = &((*array2D)[iPadY]);
+
+  return 0;
+}
+
+Void TEncGOP::free_mem2DintWithPad(Int **array2D, Int iPadY, Int iPadX)
+{
+  if (array2D)
+  {
+    if (*array2D)
+      xFree(array2D[-iPadY]-iPadX);
+    else 
+      printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
+
+    free (&array2D[-iPadY]);
+  } 
+  else
+  {
+    printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
+  }
+}
+#endif
 #endif //SVC_EXTENSION
 
Index: trunk/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 713)
@@ -54,4 +54,7 @@
 #include "TEncSbac.h"
 #include "SEIwrite.h"
+#if Q0048_CGS_3D_ASYMLUT
+#include "TEnc3DAsymLUT.h"
+#endif
 
 #include "TEncAnalyze.h"
@@ -82,4 +85,7 @@
   Int                     m_iNumPicCoded;
   Bool                    m_bFirst;
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int                     m_iLastRecoveryPicPOC;
+#endif
   
   //  Access channel
@@ -132,4 +138,20 @@
   TEncSearch*             m_pcPredSearch;                       ///< encoder search class
 #endif  
+#if Q0048_CGS_3D_ASYMLUT
+  TEnc3DAsymLUT           m_Enc3DAsymLUTPicUpdate;
+  TEnc3DAsymLUT           m_Enc3DAsymLUTPPS;
+  TComPicYuv*             m_pColorMappedPic;
+
+  Int m_iTap;
+  const Int (*m_phase_filter)[13];
+  const Int (*m_phase_filter_luma)[13];
+  const Int (*m_phase_filter_chroma)[13];
+  Int m_iM, m_iN;
+  static const Int m_phase_filter_0_t0[4][13];
+  static const Int m_phase_filter_0_t1[4][13];
+  static const Int m_phase_filter_0_t1_chroma[4][13];
+  static const Int m_phase_filter_1[8][13];
+  Int   **m_temp;
+#endif
 #endif
   
@@ -187,4 +209,7 @@
 
   SEIToneMappingInfo*     xCreateSEIToneMappingInfo();
+#if Q0074_SEI_COLOR_MAPPING
+  SEIColorMappingInfo*    xCreateSEIColorMappingInfo( Char* file );
+#endif
 
   Void xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps);
@@ -214,4 +239,23 @@
   SEIScalableNesting* xCreateBspNestingSEI(TComSlice *pcSlice);
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  Void xDetermin3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS );
+  Void downScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest);
+  Void downScaleComponent2x2( const Pel* pSrc, Pel* pDest, const Int iSrcStride, const Int iDestStride, const Int iSrcWidth, const Int iSrcHeight, const Int inputBitDepth, const Int outputBitDepth );
+  inline Short  xClip( Short x , Int bitdepth );
+  Void initDs(Int iWidth, Int iHeight, Int iType);
+  Void filterImg(
+    Pel           *src,
+    Int           iSrcStride,
+    Pel           *dst,
+    Int           iDstStride,
+    Int           height1,  
+    Int           width1,  
+    Int           shift,
+    Int           plane);
+
+  Int get_mem2DintWithPad(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX);
+  Void free_mem2DintWithPad(Int **array2D, Int iPadY, Int iPadX);
+#endif
 #endif //SVC_EXTENSION
 };// END CLASS DEFINITION TEncGOP
Index: trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 713)
@@ -952,8 +952,16 @@
         for (y=0; y<endY; y++)
         {
+#if SAO_SGN_FUNC
+          signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
+#else
           signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
+#endif
           for (x=startX; x<endX; x++)
           {
+#if SAO_SGN_FUNC
+            signRight =  (Char)sgn(srcLine[x] - srcLine[x+1]);
+#else
             signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]]; 
+#endif
             edgeType  =  signRight + signLeft;
             signLeft  = -signRight;
@@ -975,8 +983,16 @@
             for(y=0; y<skipLinesB[typeIdx]; y++)
             {
+#if SAO_SGN_FUNC
+              signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
+#else
               signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
+#endif
               for (x=startX; x<endX; x++)
               {
+#if SAO_SGN_FUNC
+                signRight =  (Char)sgn(srcLine[x] - srcLine[x+1]);
+#else
                 signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]]; 
+#endif
                 edgeType  =  signRight + signLeft;
                 signLeft  = -signRight;
@@ -1026,5 +1042,9 @@
 #endif
         {
+#if SAO_SGN_FUNC
+          signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]);
+#else
           signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
+#endif
         }
 
@@ -1040,5 +1060,9 @@
 #endif
           {
+#if SAO_SGN_FUNC
+            signDown  = (Char)sgn(srcLine[x] - srcLineBelow[x]); 
+#else
             signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 
+#endif
             edgeType  = signDown + signUpLine[x];
             signUpLine[x]= -signDown;
@@ -1065,5 +1089,9 @@
               for (x=startX; x<endX; x++)
               {
+#if SAO_SGN_FUNC
+                edgeType = sgn(srcLine[x] - srcLineBelow[x]) + sgn(srcLine[x] - srcLineAbove[x]);
+#else
                 edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]];
+#endif
                 diff [edgeType] += (orgLine[x] - srcLine[x]);
                 count[edgeType] ++;
@@ -1108,5 +1136,9 @@
         for (x=startX; x<endX+1; x++)
         {
+#if SAO_SGN_FUNC
+          signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x-1]);
+#else
           signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]];
+#endif
         }
 
@@ -1122,5 +1154,9 @@
         for(x=firstLineStartX; x<firstLineEndX; x++)
         {
+#if SAO_SGN_FUNC
+          edgeType = sgn(srcLine[x] - srcLineAbove[x-1]) - signUpLine[x+1];
+#else
           edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1];
+#endif
           diff [edgeType] += (orgLine[x] - srcLine[x]);
           count[edgeType] ++;
@@ -1137,5 +1173,9 @@
           for (x=startX; x<endX; x++)
           {
+#if SAO_SGN_FUNC
+            signDown = (Char)sgn(srcLine[x] - srcLineBelow[x+1]);
+#else
             signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ;
+#endif
             edgeType = signDown + signUpLine[x];
             diff [edgeType] += (orgLine[x] - srcLine[x]);
@@ -1144,5 +1184,9 @@
             signDownLine[x+1] = -signDown; 
           }
+#if SAO_SGN_FUNC
+          signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]);
+#else
           signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
+#endif
 
           signTmpLine  = signUpLine;
@@ -1168,5 +1212,9 @@
               for (x=startX; x< endX; x++)
               {
+#if SAO_SGN_FUNC
+                edgeType = sgn(srcLine[x] - srcLineBelow[x+1]) + sgn(srcLine[x] - srcLineAbove[x-1]);
+#else
                 edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]];
+#endif
                 diff [edgeType] += (orgLine[x] - srcLine[x]);
                 count[edgeType] ++;
@@ -1206,5 +1254,9 @@
         for (x=startX-1; x<endX; x++)
         {
+#if SAO_SGN_FUNC
+          signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]);
+#else
           signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
+#endif
         }
 
@@ -1225,5 +1277,9 @@
         for(x=firstLineStartX; x<firstLineEndX; x++)
         {
+#if SAO_SGN_FUNC
+          edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) - signUpLine[x-1];
+#else
           edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1];
+#endif
           diff [edgeType] += (orgLine[x] - srcLine[x]);
           count[edgeType] ++;
@@ -1240,5 +1296,9 @@
           for(x=startX; x<endX; x++)
           {
+#if SAO_SGN_FUNC
+            signDown = (Char)sgn(srcLine[x] - srcLineBelow[x-1]);
+#else
             signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
+#endif
             edgeType = signDown + signUpLine[x];
 
@@ -1248,5 +1308,9 @@
             signUpLine[x-1] = -signDown; 
           }
+#if SAO_SGN_FUNC
+          signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]);
+#else
           signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
+#endif
           srcLine  += srcStride;
           orgLine  += orgStride;
@@ -1267,5 +1331,9 @@
               for (x=startX; x<endX; x++)
               {
+#if SAO_SGN_FUNC
+                edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + sgn(srcLine[x] - srcLineAbove[x+1]);
+#else
                 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]];
+#endif
                 diff [edgeType] += (orgLine[x] - srcLine[x]);
                 count[edgeType] ++;
Index: trunk/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 713)
@@ -248,5 +248,9 @@
 }
 
-Void TEncSbac::codePPS( TComPPS* pcPPS )
+Void TEncSbac::codePPS( TComPPS* pcPPS 
+#if Q0048_CGS_3D_ASYMLUT
+  , TEnc3DAsymLUT * pc3DAsymLUT
+#endif
+  )
 {
   assert (0);
Index: trunk/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 713)
@@ -92,10 +92,11 @@
   Void  codeVPS                 ( TComVPS* pcVPS );
   Void  codeSPS                 ( TComSPS* pcSPS     );
-  Void  codePPS                 ( TComPPS* pcPPS     );
+  Void  codePPS                 ( TComPPS* pcPPS     
+#if Q0048_CGS_3D_ASYMLUT
+    , TEnc3DAsymLUT * pc3DAsymLUT
+#endif
+    );
   Void  codeSliceHeader         ( TComSlice* pcSlice );
   Void  codeTilesWPPEntryPoint( TComSlice* pSlice );
-#if POC_RESET_IDC_SIGNALLING
-  Void  codeSliceHeaderExtn     ( TComSlice* pSlice, Int shBitsWrittenTillNow );
-#endif
   Void  codeTerminatingBit      ( UInt uilsLast      );
   Void  codeSliceFinish         ();
@@ -108,4 +109,7 @@
 
 #if SVC_EXTENSION
+#if POC_RESET_IDC_SIGNALLING
+  Void  codeSliceHeaderExtn     ( TComSlice* pSlice, Int shBitsWrittenTillNow );
+#endif
   Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled, UInt* saoMaxOffsetQVal);
   Void codeSAOBlkParam(SAOBlkParam& saoBlkParam
Index: trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 713)
@@ -2398,5 +2398,5 @@
 {
   UInt    uiDepth        = pcCU->getDepth(0);
-  UInt    uiNumPU        = pcCU->getNumPartInter();
+  UInt    uiNumPU        = pcCU->getNumPartitions();
   UInt    uiInitTrDepth  = pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1;
   UInt    uiWidth        = pcCU->getWidth (0) >> uiInitTrDepth;
@@ -3130,5 +3130,5 @@
   TComMv        cMvTemp[2][33];
   
-  Int           iNumPart    = pcCU->getNumPartInter();
+  Int           iNumPart    = pcCU->getNumPartitions();
   Int           iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2;
   
@@ -4612,14 +4612,5 @@
     
     m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
-#if 0 // check
-    {
-      m_pcEntropyCoder->resetBits();
-      m_pcEntropyCoder->encodeCoeff( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0) );
-      const UInt uiBitsForCoeff = m_pcEntropyCoder->getNumberOfWrittenBits();
-      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
-      if( uiBitsForCoeff != uiBits )
-        assert( 0 );
-    }
-#endif
+    
     uiBits = 0;
     {
Index: trunk/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 713)
@@ -225,5 +225,17 @@
   Int depth;
   {
+#if FIX_FIELD_DEPTH    
+    Int poc = rpcSlice->getPOC();
+    if(isField)
+    {
+      poc = (poc/2)%(m_pcCfg->getGOPSize()/2);
+    }
+    else
+    {
+      poc = poc%m_pcCfg->getGOPSize();   
+    }
+#else
     Int poc = rpcSlice->getPOC()%m_pcCfg->getGOPSize();
+#endif
     if ( poc == 0 )
     {
@@ -248,4 +260,17 @@
       }
     }
+#if FIX_FIELD_DEPTH  
+#if HARMONIZE_GOP_FIRST_FIELD_COUPLE
+    if(poc != 0)
+    {
+#endif
+    if(isField && rpcSlice->getPOC()%2 == 1)
+    {
+      depth ++;
+    }
+#if HARMONIZE_GOP_FIRST_FIELD_COUPLE
+  }
+#endif
+#endif
   }
 
@@ -254,5 +279,23 @@
 
   eSliceType=B_SLICE;
+#if EFFICIENT_FIELD_IRAP
+  if(!(isField && pocLast == 1))
+  {
+#endif // EFFICIENT_FIELD_IRAP
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(m_pcCfg->getDecodingRefreshType() == 3)
+  {
+    eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0             || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+  }
+  else
+  {
   eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+  }
+#else
+  eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+#endif
+#if EFFICIENT_FIELD_IRAP
+  }
+#endif
 
   rpcSlice->setSliceType    ( eSliceType );
@@ -423,5 +466,25 @@
 #if HB_LAMBDA_FOR_LDC
   // restore original slice type
+  
+#if EFFICIENT_FIELD_IRAP
+  if(!(isField && pocLast == 1))
+  {
+#endif // EFFICIENT_FIELD_IRAP
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(m_pcCfg->getDecodingRefreshType() == 3)
+  {
+    eSliceType = (pocLast == 0 || (pocCurr)           % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+
+  }
+  else
+  {
   eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+  }
+#else
+  eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+#endif
+#if EFFICIENT_FIELD_IRAP
+  }
+#endif // EFFICIENT_FIELD_IRAP
 
 #if SVC_EXTENSION
@@ -544,5 +607,7 @@
   // store lambda
   slice->setSliceQp( sliceQP );
+#if ADAPTIVE_QP_SELECTION
   slice->setSliceQpBase ( sliceQP );
+#endif
   m_pcRdCost ->setLambda( lambda );
   // for RDO
@@ -1041,5 +1106,7 @@
 
       m_pcRateCtrl->setRCQP( estQP );
+#if ADAPTIVE_QP_SELECTION
       pcCU->getSlice()->setSliceQpBase( estQP );
+#endif
     }
 
Index: trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 713)
@@ -795,5 +795,12 @@
           Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
 
-          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths )
+          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths 
+#if Q0048_CGS_3D_ASYMLUT
+            || m_cPPS.getCGSFlag() > 0
+#endif
+#if LAYER_CTB
+            || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth()
+#endif
+            )
 #else
           if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
@@ -857,5 +864,12 @@
           Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
 
-          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths )
+          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths 
+#if Q0048_CGS_3D_ASYMLUT
+            || m_cPPS.getCGSFlag() > 0
+#endif
+#if LAYER_CTB
+            || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth()
+#endif
+)
 #else
           if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
@@ -1188,4 +1202,7 @@
   }
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  m_cPPS.setCGSFlag( m_nCGSFlag );
+#endif
 }
 
Index: trunk/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 649)
+++ trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 713)
@@ -273,5 +273,5 @@
 
   /// encode several number of pictures until end-of-sequence
-  Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
+  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
               std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff);
 
