Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 442)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 494)
@@ -130,5 +130,14 @@
 extern Int g_bitDepthY;
 extern Int g_bitDepthC;
-
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+extern Int  g_bitDepthYLayer[MAX_LAYERS];
+extern Int  g_bitDepthCLayer[MAX_LAYERS];
+
+extern UInt g_uiPCMBitDepthLumaDec[MAX_LAYERS];    // PCM bit-depth
+extern UInt g_uiPCMBitDepthChromaDec[MAX_LAYERS];    // PCM bit-depth
+#endif
+#if O0194_WEIGHTED_PREDICTION_CGS
+extern void* g_refWeightACDCParam; //type:wpACDCParam
+#endif
 /** clip x, such that 0 <= x <= #g_maxLumaVal */
 template <typename T> inline T ClipY(T x) { return std::min<T>(T((1 << g_bitDepthY)-1), std::max<T>( T(0), x)); }
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 494)
@@ -1872,4 +1872,24 @@
 #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 )
 {
@@ -4004,15 +4024,12 @@
   uiPelY = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getHeight() - 1, uiPelY);
 
+#if !LAYER_CTB
   UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
-
-#if SCALED_REF_LAYER_OFFSETS
+#endif
+
   Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowLeftOffset();
   Int topStartL  = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowTopOffset();
   Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
   Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
-#else
-  Int iBX = (uiPelX*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
-  Int iBY = (uiPelY*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
-#endif
 
 #if N0139_POSITION_ROUNDING_OFFSET
@@ -4024,22 +4041,32 @@
 #endif
 
-#if SCALED_REF_LAYER_OFFSETS
   if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight() ||
        iBX < 0                                        || iBY < 0                                           )
+  {
+    return NULL;
+  }
+
+#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() );
 #else
-  if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight())
+  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
 #endif
-  {
-    return NULL;
-  }
-
-  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
 
   assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
 
+#if LAYER_CTB
+  UInt uiRasterAddrBase = ( iBY - (iBY/baseMaxCUHeight)*baseMaxCUHeight ) / baseMinUnitSize * cBaseColPic->getNumPartInWidth() + ( iBX - (iBX/baseMaxCUWidth)*baseMaxCUWidth ) / baseMinUnitSize;
+  
+  uiAbsPartIdxBase = g_auiLayerRasterToZscan[cBaseColPic->getLayerId()][uiRasterAddrBase];
+#else
   UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
     + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
 
   uiAbsPartIdxBase = g_auiRasterToZscan[uiRasterAddrBase];
+#endif
 
   return cBaseColPic->getCU(uiCUAddrBase);
Index: trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 494)
@@ -492,4 +492,7 @@
   Bool          isSkipped ( UInt uiPartIdx );                                                     ///< SKIP (no residual)
   Bool          isBipredRestriction( UInt puIdx );
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool          isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1);
+#endif
 
   // -------------------------------------------------------------------------------------------------------------------
Index: trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 494)
@@ -79,14 +79,26 @@
 }
 #if SVC_UPSAMPLING
+#if AUXILIARY_PICTURES
+Void TComPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
+                      Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
+#else
 Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
                       Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
-
+#endif
 {
   m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
   if (!bIsVirtual)
   {
+#if AUXILIARY_PICTURES
+    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+#else
     m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
-  }
+#endif
+  }
+#if AUXILIARY_PICTURES
+  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+#else
   m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+#endif
 
   for( Int i = 0; i < MAX_LAYERS; i++ )
@@ -94,5 +106,9 @@
     if( m_bSpatialEnhLayer[i] )
     {
+#if AUXILIARY_PICTURES
+      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+#else
       m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+#endif
     }
   }
@@ -407,5 +423,10 @@
   {
     m_pNDBFilterYuvTmp = new TComPicYuv();
+#if AUXILIARY_PICTURES
+    m_pNDBFilterYuvTmp->create(picWidth, picHeight, getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
+#else
     m_pNDBFilterYuvTmp->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
+#endif
+
   }
 
@@ -801,4 +822,45 @@
 #endif
 
+#if MFM_ENCCONSTRAINT
+Bool TComPic::checkSameRefInfo()
+{
+  Bool bSameRefInfo = true;
+  TComSlice * pSlice0 = getSlice( 0 );
+  for( UInt uSliceID = getNumAllocatedSlice() - 1 ; bSameRefInfo && uSliceID > 0 ; uSliceID-- )
+  {
+    TComSlice * pSliceN = getSlice( uSliceID );
+    if( pSlice0->getSliceType() != pSliceN->getSliceType() )
+    {
+      bSameRefInfo = false;
+    }
+    else if( pSlice0->getSliceType() != I_SLICE )
+    {
+      Int nListNum = pSlice0->getSliceType() == B_SLICE ? 2 : 1;
+      for( Int nList = 0 ; nList < nListNum ; nList++ )
+      {
+        RefPicList eRefList = ( RefPicList )nList;
+        if( pSlice0->getNumRefIdx( eRefList ) == pSliceN->getNumRefIdx( eRefList ) )
+        {
+          for( Int refIdx = pSlice0->getNumRefIdx( eRefList ) - 1 ; refIdx >= 0 ; refIdx-- )
+          {
+            if( pSlice0->getRefPic( eRefList , refIdx ) != pSliceN->getRefPic( eRefList , refIdx ) )
+            {
+              bSameRefInfo = false;
+              break;
+            }
+          }
+        }
+        else
+        {
+          bSameRefInfo = false;
+          break;
+        }
+      }
+    }
+  }
+
+  return( bSameRefInfo );  
+}
+#endif
 
 //! \}
Index: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 494)
@@ -102,4 +102,13 @@
   virtual ~TComPic();
   
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+  Void          create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
+                        Int *numReorderPics, TComSPS* pcSps = NULL, Bool bIsVirtual = false );
+#else
+  Void          create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
+                        Int *numReorderPics, Bool bIsVirtual = false );                        
+#endif
+#else
 #if SVC_UPSAMPLING
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
@@ -109,4 +118,5 @@
                         Int *numReorderPics, Bool bIsVirtual = false );                        
 #endif
+#endif
   virtual Void  destroy();
   
@@ -128,4 +138,7 @@
   Void          copyUpsampledMvField  ( UInt refLayerIdc, TComPic* pcPicBase );
   Void          initUpsampledMvField  ();
+#endif
+#if MFM_ENCCONSTRAINT
+  Bool          checkSameRefInfo();
 #endif
 
@@ -163,4 +176,7 @@
   
   Int           getStride()           { return m_apcPicYuv[1]->getStride(); }
+#if AUXILIARY_PICTURES
+  ChromaFormat  getChromaFormat() const { return m_apcPicYuv[1]->getChromaFormat(); }
+#endif
   Int           getCStride()          { return m_apcPicYuv[1]->getCStride(); }
   
Index: trunk/source/Lib/TLibCommon/TComPicSym.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 494)
@@ -126,4 +126,9 @@
   TComDataCU*&  getCU( UInt uiCUAddr )  { return m_apcTComDataCU[uiCUAddr];     }
   
+#if LAYER_CTB
+  UInt        getMaxCUWidth()           { return m_uiMaxCUWidth;                }
+  UInt        getMaxCUHeight()          { return m_uiMaxCUHeight;               }
+#endif
+
 #if AVC_SYNTAX
   UInt        getMaxCUWidth()           { return m_uiMaxCUWidth;                }
Index: trunk/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 494)
@@ -67,8 +67,16 @@
 {
 }
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps )
+#else
+Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth )
+#endif
+#else
 #if SVC_UPSAMPLING
 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps )
 #else
 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth )
+#endif
 #endif
 {
@@ -86,10 +94,18 @@
   m_iCuWidth        = uiMaxCUWidth;
   m_iCuHeight       = uiMaxCUHeight;
+#if AUXILIARY_PICTURES
+  m_chromaFormatIDC = chromaFormatIDC;
+#endif
 
   Int numCuInWidth  = m_iPicWidth  / m_iCuWidth  + (m_iPicWidth  % m_iCuWidth  != 0);
   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_iChromaMarginX  = m_iLumaMarginX>>1;
@@ -234,4 +250,18 @@
 }
 
+#if AUXILIARY_PICTURES
+Void TComPicYuv::convertToMonochrome()
+{
+  Int numPix = ((m_iPicWidth >> 1) + (m_iChromaMarginX << 1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY << 1));
+  Pel grayVal = (1 << (g_bitDepthC - 1));
+
+  for (UInt i = 0; i < numPix; i++)
+  {
+    m_apiPicBufU[i] = grayVal;
+    m_apiPicBufV[i] = grayVal;
+  }
+}
+#endif
+
 Void TComPicYuv::extendPicBorder ()
 {
Index: trunk/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 494)
@@ -75,4 +75,7 @@
   Int   m_iPicWidth;            ///< Width of picture
   Int   m_iPicHeight;           ///< Height of picture
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatIDC; ////< Chroma Format
+#endif
   
   Int   m_iCuWidth;             ///< Width of Coding Unit (CU)
@@ -108,4 +111,11 @@
   //  Memory management
   // ------------------------------------------------------------------------------------------------
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+  Void  create      ( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps = NULL);
+#else
+  Void  create      ( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
+#endif  
+#else
 #if SVC_UPSAMPLING
   Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps = NULL);
@@ -113,4 +123,5 @@
   Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
 #endif  
+#endif
   
   Void  destroy     ();
@@ -125,4 +136,7 @@
   Int   getWidth    ()     { return  m_iPicWidth;    }
   Int   getHeight   ()     { return  m_iPicHeight;   }
+#if AUXILIARY_PICTURES
+  ChromaFormat  getChromaFormat   ()                     const { return m_chromaFormatIDC; }
+#endif
   
 #if SVC_EXTENSION
@@ -184,4 +198,8 @@
 #endif
 
+#if AUXILIARY_PICTURES
+  Void convertToMonochrome();
+#endif
+
   // Set border extension flag
   Void  setBorderExtension(Bool b) { m_bIsBorderExtended = b; }
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 494)
@@ -765,14 +765,28 @@
 
 #if SVC_UPSAMPLING
-#if SCALED_REF_LAYER_OFFSETS
+#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 );
+}
+#else
+Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
+{
+  m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, phaseAlignFlag );
+}
+#endif
+#else
+#if O0194_JOINT_US_BITSHIFT
+Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
+{
+  m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window);
+}
+#else
 Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
 {
   m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window);
 }
-#else
-Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic)
-{
-  m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic);
-}
+#endif
 #endif
 #endif
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 494)
@@ -120,11 +120,19 @@
 #if SVC_EXTENSION
 #if SVC_UPSAMPLING
-#if SCALED_REF_LAYER_OFFSETS
+#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 );
+#else
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag );
+#endif
+#else
+#if O0194_JOINT_US_BITSHIFT
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+#else
   Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
-#else
-  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
 #endif
 #endif
 #endif
+#endif //SVC_EXTENSION
 };
 
Index: trunk/source/Lib/TLibCommon/TComRdCost.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 494)
@@ -2,5 +2,5 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
  * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -61,5 +61,5 @@
   Double dRdCost = 0.0;
   Double dLambda = 0.0;
-  
+
   switch ( eDFunc )
   {
@@ -80,5 +80,5 @@
       break;
   }
-  
+
   if (bFlag)
   {
@@ -107,5 +107,5 @@
     }
   }
-  
+
   return dRdCost;
 }
@@ -115,5 +115,5 @@
   Double dRdCost = 0.0;
   Double dLambda = 0.0;
-  
+
   switch ( eDFunc )
   {
@@ -134,5 +134,5 @@
       break;
   }
-  
+
   if (bFlag)
   {
@@ -161,5 +161,5 @@
     }
   }
-  
+
   return dRdCost;
 }
@@ -178,5 +178,5 @@
 {
   m_afpDistortFunc[0]  = NULL;                  // for DF_DEFAULT
-  
+
   m_afpDistortFunc[1]  = TComRdCost::xGetSSE;
   m_afpDistortFunc[2]  = TComRdCost::xGetSSE4;
@@ -186,5 +186,5 @@
   m_afpDistortFunc[6]  = TComRdCost::xGetSSE64;
   m_afpDistortFunc[7]  = TComRdCost::xGetSSE16N;
-  
+
   m_afpDistortFunc[8]  = TComRdCost::xGetSAD;
   m_afpDistortFunc[9]  = TComRdCost::xGetSAD4;
@@ -194,5 +194,5 @@
   m_afpDistortFunc[13] = TComRdCost::xGetSAD64;
   m_afpDistortFunc[14] = TComRdCost::xGetSAD16N;
-  
+
   m_afpDistortFunc[15] = TComRdCost::xGetSAD;
   m_afpDistortFunc[16] = TComRdCost::xGetSAD4;
@@ -202,5 +202,5 @@
   m_afpDistortFunc[20] = TComRdCost::xGetSAD64;
   m_afpDistortFunc[21] = TComRdCost::xGetSAD16N;
-  
+
 #if AMP_SAD
   m_afpDistortFunc[43] = TComRdCost::xGetSAD12;
@@ -219,5 +219,5 @@
   m_afpDistortFunc[27] = TComRdCost::xGetHADs;
   m_afpDistortFunc[28] = TComRdCost::xGetHADs;
-  
+
 #if !FIX203
   m_puiComponentCostOriginP = NULL;
@@ -239,16 +239,16 @@
   iSubPelSearchLimit += 4;
   iSubPelSearchLimit *= 8;
-  
+
   if( m_iSearchLimit != iSubPelSearchLimit )
   {
     xUninit();
-    
+
     m_iSearchLimit = iSubPelSearchLimit;
-    
+
     m_puiComponentCostOriginP = new UInt[ 4 * iSubPelSearchLimit ];
     iSubPelSearchLimit *= 2;
-    
+
     m_puiComponentCost = m_puiComponentCostOriginP + iSubPelSearchLimit;
-    
+
     for( Int n = -iSubPelSearchLimit; n < iSubPelSearchLimit; n++)
     {
@@ -272,7 +272,7 @@
   UInt uiLength = 1;
   UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
-  
+
   assert ( uiTemp );
-  
+
   while ( 1 != uiTemp )
   {
@@ -280,5 +280,5 @@
     uiLength += 2;
   }
-  
+
   return uiLength;
 }
@@ -290,5 +290,5 @@
   rcDistParam.iRows    = uiBlkHeight;
   rcDistParam.DistFunc = m_afpDistortFunc[eDFunc + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ];
-  
+
   // initialize
   rcDistParam.iSubShift  = 0;
@@ -301,13 +301,13 @@
   rcDistParam.pOrg = pcPatternKey->getROIY();
   rcDistParam.pCur = piRefY;
-  
+
   rcDistParam.iStrideOrg = pcPatternKey->getPatternLStride();
   rcDistParam.iStrideCur = iRefStride;
-  
+
   // set Block Width / Height
   rcDistParam.iCols    = pcPatternKey->getROIYWidth();
   rcDistParam.iRows    = pcPatternKey->getROIYHeight();
   rcDistParam.DistFunc = m_afpDistortFunc[DF_SAD + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ];
-  
+
 #if AMP_SAD
   if (rcDistParam.iCols == 12)
@@ -336,14 +336,18 @@
 #endif
 {
+#if O0194_WEIGHTED_PREDICTION_CGS
+  // Bug fix: The correct bit depth has not been used for weighted cost calculation
+  rcDistParam.bitDepth = g_bitDepthY;
+#endif
   // set Original & Curr Pointer / Stride
   rcDistParam.pOrg = pcPatternKey->getROIY();
   rcDistParam.pCur = piRefY;
-  
+
   rcDistParam.iStrideOrg = pcPatternKey->getPatternLStride();
   rcDistParam.iStrideCur = iRefStride * iStep;
-  
+
   // set Step for interpolated buffer
   rcDistParam.iStep = iStep;
-  
+
   // set Block Width / Height
   rcDistParam.iCols    = pcPatternKey->getROIYWidth();
@@ -352,5 +356,5 @@
   rcDistParam.bUseNSHAD = bUseNSHAD;
 #endif
-  
+
   // set distortion function
   if ( !bHADME )
@@ -376,5 +380,5 @@
     rcDistParam.DistFunc = m_afpDistortFunc[DF_HADS + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ];
   }
-  
+
   // initialize
   rcDistParam.iSubShift  = 0;
@@ -407,5 +411,5 @@
   UInt uiSum = 0;
   Int x, y;
-  
+
   if ( ( (iWidth % 8) == 0 ) && ( (iHeight % 8) == 0 ) )
   {
@@ -444,5 +448,5 @@
     }
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
 
@@ -523,7 +527,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur;
   Int  iStrideOrg = pcDtParam->iStrideOrg;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-- )
   {
@@ -535,5 +539,5 @@
     piCur += iStrideCur;
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
@@ -541,5 +545,5 @@
 UInt TComRdCost::xGetSAD4( DistParam* pcDtParam )
 {
-  if ( pcDtParam->bApplyWeight ) 
+  if ( pcDtParam->bApplyWeight )
   {
     return xGetSADw( pcDtParam );
@@ -552,7 +556,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -561,9 +565,9 @@
     uiSum += abs( piOrg[2] - piCur[2] );
     uiSum += abs( piOrg[3] - piCur[3] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -583,7 +587,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -596,9 +600,9 @@
     uiSum += abs( piOrg[6] - piCur[6] );
     uiSum += abs( piOrg[7] - piCur[7] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -618,7 +622,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -639,9 +643,9 @@
     uiSum += abs( piOrg[14] - piCur[14] );
     uiSum += abs( piOrg[15] - piCur[15] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -662,7 +666,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -679,9 +683,9 @@
     uiSum += abs( piOrg[10] - piCur[10] );
     uiSum += abs( piOrg[11] - piCur[11] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -699,7 +703,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -726,5 +730,5 @@
     piCur += iStrideCur;
   }
-  
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -744,7 +748,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -781,9 +785,9 @@
     uiSum += abs( piOrg[30] - piCur[30] );
     uiSum += abs( piOrg[31] - piCur[31] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -804,7 +808,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -833,9 +837,9 @@
     uiSum += abs( piOrg[22] - piCur[22] );
     uiSum += abs( piOrg[23] - piCur[23] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -857,7 +861,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -926,9 +930,9 @@
     uiSum += abs( piOrg[62] - piCur[62] );
     uiSum += abs( piOrg[63] - piCur[63] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -949,7 +953,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -1002,9 +1006,9 @@
     uiSum += abs( piOrg[46] - piCur[46] );
     uiSum += abs( piOrg[47] - piCur[47] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -1028,10 +1032,10 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
@@ -1044,5 +1048,5 @@
     piCur += iStrideCur;
   }
-  
+
   return ( uiSum );
 }
@@ -1060,22 +1064,22 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
-    
+
     iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1093,10 +1097,10 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
@@ -1109,9 +1113,9 @@
     iTemp = piOrg[6] - piCur[6]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[7] - piCur[7]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1129,13 +1133,13 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
-    
+
     iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
@@ -1154,9 +1158,9 @@
     iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1174,14 +1178,14 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
     for (Int n = 0; n < iCols; n+=16 )
     {
-      
+
       iTemp = piOrg[n+ 0] - piCur[n+ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
       iTemp = piOrg[n+ 1] - piCur[n+ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
@@ -1200,10 +1204,10 @@
       iTemp = piOrg[n+14] - piCur[n+14]; uiSum += ( iTemp * iTemp ) >> uiShift;
       iTemp = piOrg[n+15] - piCur[n+15]; uiSum += ( iTemp * iTemp ) >> uiShift;
-      
-    }
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    }
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1221,12 +1225,12 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
-    
+
     iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
@@ -1261,9 +1265,9 @@
     iTemp = piOrg[30] - piCur[30]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[31] - piCur[31]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1281,9 +1285,9 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
@@ -1352,9 +1356,9 @@
     iTemp = piOrg[62] - piCur[62]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[63] - piCur[63]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1376,10 +1380,10 @@
   m[2] = diff[0] - diff[2];
   m[3] = diff[1] - diff[3];
-  
+
   satd += abs(m[0] + m[1]);
   satd += abs(m[0] - m[1]);
   satd += abs(m[2] + m[3]);
   satd += abs(m[2] - m[3]);
-  
+
   return satd;
 }
@@ -1388,5 +1392,5 @@
 {
   Int k, satd = 0, diff[16], m[16], d[16];
-  
+
   assert( iStep == 1 );
   for( k = 0; k < 16; k+=4 )
@@ -1396,9 +1400,9 @@
     diff[k+2] = piOrg[2] - piCur[2];
     diff[k+3] = piOrg[3] - piCur[3];
-    
-    piCur += iStrideCur;
-    piOrg += iStrideOrg;
-  }
-  
+
+    piCur += iStrideCur;
+    piOrg += iStrideOrg;
+  }
+
   /*===== hadamard transform =====*/
   m[ 0] = diff[ 0] + diff[12];
@@ -1418,5 +1422,5 @@
   m[14] = diff[ 2] - diff[14];
   m[15] = diff[ 3] - diff[15];
-  
+
   d[ 0] = m[ 0] + m[ 4];
   d[ 1] = m[ 1] + m[ 5];
@@ -1435,5 +1439,5 @@
   d[14] = m[14] - m[10];
   d[15] = m[15] - m[11];
-  
+
   m[ 0] = d[ 0] + d[ 3];
   m[ 1] = d[ 1] + d[ 2];
@@ -1452,5 +1456,5 @@
   m[14] = d[13] - d[14];
   m[15] = d[12] - d[15];
-  
+
   d[ 0] = m[ 0] + m[ 1];
   d[ 1] = m[ 0] - m[ 1];
@@ -1469,5 +1473,5 @@
   d[14] = m[14] + m[15];
   d[15] = m[15] - m[14];
-  
+
   for (k=0; k<16; ++k)
   {
@@ -1475,5 +1479,5 @@
   }
   satd = ((satd+1)>>1);
-  
+
   return satd;
 }
@@ -1494,9 +1498,9 @@
     diff[k+6] = piOrg[6] - piCur[6];
     diff[k+7] = piOrg[7] - piCur[7];
-    
-    piCur += iStrideCur;
-    piOrg += iStrideOrg;
-  }
-  
+
+    piCur += iStrideCur;
+    piOrg += iStrideOrg;
+  }
+
   //horizontal
   for (j=0; j < 8; j++)
@@ -1511,5 +1515,5 @@
     m2[j][6] = diff[jj+2] - diff[jj+6];
     m2[j][7] = diff[jj+3] - diff[jj+7];
-    
+
     m1[j][0] = m2[j][0] + m2[j][2];
     m1[j][1] = m2[j][1] + m2[j][3];
@@ -1520,5 +1524,5 @@
     m1[j][6] = m2[j][4] - m2[j][6];
     m1[j][7] = m2[j][5] - m2[j][7];
-    
+
     m2[j][0] = m1[j][0] + m1[j][1];
     m2[j][1] = m1[j][0] - m1[j][1];
@@ -1530,5 +1534,5 @@
     m2[j][7] = m1[j][6] - m1[j][7];
   }
-  
+
   //vertical
   for (i=0; i < 8; i++)
@@ -1542,5 +1546,5 @@
     m3[6][i] = m2[2][i] - m2[6][i];
     m3[7][i] = m2[3][i] - m2[7][i];
-    
+
     m1[0][i] = m3[0][i] + m3[2][i];
     m1[1][i] = m3[1][i] + m3[3][i];
@@ -1551,5 +1555,5 @@
     m1[6][i] = m3[4][i] - m3[6][i];
     m1[7][i] = m3[5][i] - m3[7][i];
-    
+
     m2[0][i] = m1[0][i] + m1[1][i];
     m2[1][i] = m1[0][i] - m1[1][i];
@@ -1561,5 +1565,5 @@
     m2[7][i] = m1[6][i] - m1[7][i];
   }
-  
+
   for (i = 0; i < 8; i++)
   {
@@ -1569,7 +1573,7 @@
     }
   }
-  
+
   sad=((sad+2)>>2);
-  
+
   return sad;
 }
@@ -1681,5 +1685,5 @@
   //vertical
   for (i=0; i < 16; i++)
-  {    
+  {
     m2[0][i] = m1[0][i] + m1[2][i];
     m2[1][i] = m1[1][i] + m1[3][i];
@@ -1838,7 +1842,7 @@
   Int  iOffsetOrg = iStrideOrg<<2;
   Int  iOffsetCur = iStrideCur<<2;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for ( y=0; y<iRows; y+= 4 )
   {
@@ -1847,5 +1851,5 @@
     piCur += iOffsetCur;
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
@@ -1864,7 +1868,7 @@
   Int  iStep  = pcDtParam->iStep;
   Int  y;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   if ( iRows == 4 )
   {
@@ -1883,5 +1887,5 @@
     }
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
@@ -1900,9 +1904,9 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStep  = pcDtParam->iStep;
-  
+
   Int  x, y;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
 #if NS_HAD
   if( ( ( iRows % 8 == 0) && (iCols % 8 == 0) && ( iRows == iCols ) ) || ( ( iRows % 8 == 0 ) && (iCols % 8 == 0) && !pcDtParam->bUseNSHAD ) )
@@ -1924,5 +1928,5 @@
   }
 #if NS_HAD
-  else if ( ( iCols > 8 ) && ( iCols > iRows ) && pcDtParam->bUseNSHAD ) 
+  else if ( ( iCols > 8 ) && ( iCols > iRows ) && pcDtParam->bUseNSHAD )
   {
     Int  iOffsetOrg = iStrideOrg<<2;
@@ -1938,5 +1942,5 @@
     }
   }
-  else if ( ( iRows > 8 ) && ( iCols < iRows ) && pcDtParam->bUseNSHAD ) 
+  else if ( ( iRows > 8 ) && ( iCols < iRows ) && pcDtParam->bUseNSHAD )
   {
     Int  iOffsetOrg = iStrideOrg<<4;
@@ -1957,5 +1961,5 @@
     Int  iOffsetOrg = iStrideOrg<<2;
     Int  iOffsetCur = iStrideCur<<2;
-    
+
     for ( y=0; y<iRows; y+= 4 )
     {
@@ -1986,5 +1990,5 @@
     assert(false);
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
Index: trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 494)
@@ -86,5 +86,14 @@
 // Data structure related table & variable
 // ====================================================================================================================
-
+#if LAYER_CTB
+UInt g_auiLayerMaxCUWidth[MAX_LAYERS];
+UInt g_auiLayerMaxCUHeight[MAX_LAYERS];
+UInt g_auiLayerMaxCUDepth[MAX_LAYERS];
+UInt g_auiLayerAddCUDepth[MAX_LAYERS];
+UInt g_auiLayerZscanToRaster[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+UInt g_auiLayerRasterToZscan[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+UInt g_auiLayerRasterToPelX[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+UInt g_auiLayerRasterToPelY[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+#endif
 UInt g_uiMaxCUWidth  = MAX_CU_SIZE;
 UInt g_uiMaxCUHeight = MAX_CU_SIZE;
@@ -312,5 +321,14 @@
 UInt g_uiPCMBitDepthLuma     = 8;    // PCM bit-depth
 UInt g_uiPCMBitDepthChroma   = 8;    // PCM bit-depth
-
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+Int  g_bitDepthYLayer[MAX_LAYERS];
+Int  g_bitDepthCLayer[MAX_LAYERS];
+
+UInt g_uiPCMBitDepthLumaDec[MAX_LAYERS];    // PCM bit-depth
+UInt g_uiPCMBitDepthChromaDec[MAX_LAYERS];    // PCM bit-depth
+#endif
+#if O0194_WEIGHTED_PREDICTION_CGS
+void * g_refWeightACDCParam; // type=wpACDCParam
+#endif
 // ====================================================================================================================
 // Misc.
Index: trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.h	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComRom.h	(revision 494)
@@ -81,4 +81,14 @@
 
 // global variable (LCU width/height, max. CU depth)
+#if LAYER_CTB
+extern       UInt g_auiLayerMaxCUWidth[MAX_LAYERS];
+extern       UInt g_auiLayerMaxCUHeight[MAX_LAYERS];
+extern       UInt g_auiLayerMaxCUDepth[MAX_LAYERS];
+extern       UInt g_auiLayerAddCUDepth[MAX_LAYERS];
+extern       UInt g_auiLayerZscanToRaster[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+extern       UInt g_auiLayerRasterToZscan[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+extern       UInt g_auiLayerRasterToPelX[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+extern       UInt g_auiLayerRasterToPelY[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+#endif
 extern       UInt g_uiMaxCUWidth;
 extern       UInt g_uiMaxCUHeight;
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 494)
@@ -75,10 +75,4 @@
 , m_iDepth                        ( 0 )
 , m_bRefenced                     ( false )
-#if POC_RESET_FLAG
-, m_bPocResetFlag                 ( false )
-#endif
-#if SH_DISCARDABLE_FLAG
-, m_bDiscardableFlag              ( false )
-#endif
 , m_pcSPS                         ( NULL )
 , m_pcPPS                         ( NULL )
@@ -93,7 +87,4 @@
 #endif
 , m_uiTLayer                      ( 0 )
-#if SVC_EXTENSION
-, m_layerId                     ( 0 )
-#endif
 , m_bTLayerSwitchingFlag          ( false )
 , m_sliceMode                   ( 0 )
@@ -118,4 +109,14 @@
 , m_temporalLayerNonReferenceFlag ( false )
 , m_enableTMVPFlag                ( true )
+#if SVC_EXTENSION
+, m_layerId                     ( 0 )
+#if REF_IDX_MFM
+, m_bMFMEnabledFlag               ( false )
+#endif
+#if POC_RESET_FLAG
+, m_bPocResetFlag                 ( false )
+#endif
+, m_bDiscardableFlag              ( false )
+#endif //SVC_EXTENSION
 {
   m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0;
@@ -138,5 +139,5 @@
   m_interLayerSamplePredOnlyFlag = false;
 #endif
-#endif
+#endif //SVC_EXTENSION
 
   initEqualRef();
@@ -455,11 +456,10 @@
     UInt refLayerIdc = m_interLayerPredLayerIdc[i];
     //inter-layer reference picture
-
-#if ILR_RESTR
+#if O0225_MAX_TID_FOR_REF_LAYERS
+    Int maxTidIlRefPicsPlus1 = ( m_layerId > 0 && m_activeNumILRRefIdx > 0)? m_pcVPS->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId) : 0;
+#else
     Int maxTidIlRefPicsPlus1 = ( m_layerId > 0 && m_activeNumILRRefIdx > 0)? m_pcVPS->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId()) : 0;
+#endif 
     if( m_layerId > 0 && m_activeNumILRRefIdx > 0 && ( ( (Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=  maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )  ) 
-#else //#if ILR_RESTR
-    if( m_layerId > 0 && m_activeNumILRRefIdx > 0 )
-#endif //#if ILR_RESTR
     {
 #if REF_IDX_MFM
@@ -485,5 +485,4 @@
   TComPic*  rpsCurrList1[MAX_NUM_REF+1];
 #if SVC_EXTENSION
-#if ILR_RESTR
   Int numInterLayerRPSPics = 0;
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -495,5 +494,9 @@
     for( i=0; i < m_pcVPS->getNumDirectRefLayers( m_layerId ); i++ )
     {
+#if O0225_MAX_TID_FOR_REF_LAYERS
+      Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[i]->getSlice(0)->getLayerId(),m_layerId);
+#else
       Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[i]->getSlice(0)->getLayerId());
+#endif 
       if( ((Int)(ilpPic[i]->getSlice(0)->getTLayer())<= maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[i]->getSlice(0)->getRapPicFlag() ) )
       {
@@ -574,5 +577,4 @@
 #endif
   }
-#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + m_activeNumILRRefIdx;
@@ -580,7 +582,7 @@
   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + m_numILRRefIdx;
 #endif 
-#else
+#else //SVC_EXTENSION
   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
-#endif
+#endif //SVC_EXTENSION
 #if FIX1071
   if (checkNumPocTotalCurr)
@@ -631,5 +633,5 @@
 #if RPL_INIT_N0316_N0082
     if( m_layerId > 0 )
-    {
+    {      
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
       for( i = 0; i < m_activeNumILRRefIdx && cIdx < numPocTotalCurr; cIdx ++, i ++)      
@@ -639,13 +641,17 @@
       {
         Int refLayerIdc = m_interLayerPredLayerIdc[i];
-#if ILR_RESTR
+#if O0225_MAX_TID_FOR_REF_LAYERS
+        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId);
+#else
         Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+#endif
         if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
-#endif
+        {
           rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
-      }
-    }
-#endif
-#endif 
+        }
+      }
+    }
+#endif
+#endif //SVC_EXTENSION
     for ( i=0; i<NumPocStCurr1; i++, cIdx++)
     {
@@ -667,9 +673,13 @@
       {
         Int refLayerIdc = m_interLayerPredLayerIdc[i];
-#if ILR_RESTR
-         Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+#if O0225_MAX_TID_FOR_REF_LAYERS
+        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId);
+#else
+        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+#endif 
         if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
-#endif
-        rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
+        {
+          rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
+        }
       }
     }
@@ -704,12 +714,16 @@
       {
         Int refLayerIdc = m_interLayerPredLayerIdc[i];
-#if ILR_RESTR
+#if O0225_MAX_TID_FOR_REF_LAYERS
+        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId);
+#else
         Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+#endif 
         if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
-#endif
-        rpsCurrList1[cIdx] = ilpPic[refLayerIdc];
-      }
-    }
-#endif
+        {
+          rpsCurrList1[cIdx] = ilpPic[refLayerIdc];
+        }
+      }
+    }
+#endif //SVC_EXTENSION
 
     assert(cIdx == numPocTotalCurr);
@@ -781,7 +795,4 @@
 #if N0147_IRAP_ALIGN_FLAG
   hasModification = hasModification && ( m_aiNumRefIdx[REF_PIC_LIST_0] > 1 );
-#endif
-#if FINAL_RPL_CHANGE_N0082
-  hasModification = false; //modification is not necessary
 #endif
   refPicListModification->setRefPicListModificationFlagL0(hasModification);
@@ -1133,4 +1144,5 @@
 #if SVC_EXTENSION
   m_pcVPS                = pSrc->m_pcVPS;
+  m_layerId              = pSrc->m_layerId;
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   m_activeNumILRRefIdx         = pSrc->m_activeNumILRRefIdx;
@@ -1847,5 +1859,29 @@
   return retVal;
 }
+#if AUXILIARY_PICTURES
+ChromaFormat TComSlice::getChromaFormatIdc()
+#else
 UInt TComSlice::getChromaFormatIdc()
+#endif
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+#if AUXILIARY_PICTURES
+  ChromaFormat retVal;
+  UInt layerId = getLayerId();
+#else
+  UInt retVal, layerId = getLayerId();
+#endif
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getChromaFormatIdc();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getChromaFormatVpsIdc();
+  }
+  return retVal;
+}
+UInt TComSlice::getBitDepthY()
 {
   TComSPS *sps = getSPS();
@@ -1854,13 +1890,13 @@
   if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
   {
-    retVal = sps->getChromaFormatIdc();
+    retVal = sps->getBitDepthY();
   }
   else
   {
-    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getChromaFormatVpsIdc();
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsLuma();
   }
   return retVal;
 }
-UInt TComSlice::getBitDepthY()
+UInt TComSlice::getBitDepthC()
 {
   TComSPS *sps = getSPS();
@@ -1869,27 +1905,12 @@
   if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
   {
-    retVal = sps->getBitDepthY();
+    retVal = sps->getBitDepthC();
   }
   else
   {
-    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsLuma();
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsChroma();
   }
   return retVal;
 }
-UInt TComSlice::getBitDepthC()
-{
-  TComSPS *sps = getSPS();
-  TComVPS *vps = getVPS();
-  UInt retVal, layerId = getLayerId();
-  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
-  {
-    retVal = sps->getBitDepthC();
-  }
-  else
-  {
-    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsChroma();
-  }
-  return retVal;
-}
 Int TComSlice::getQpBDOffsetY()
 {
@@ -1902,5 +1923,9 @@
 
 RepFormat::RepFormat()
+#if AUXILIARY_PICTURES
+: m_chromaFormatVpsIdc          (CHROMA_420)
+#else
 : m_chromaFormatVpsIdc          (0)
+#endif
 , m_separateColourPlaneVpsFlag  (false)
 , m_picWidthVpsInLumaSamples    (0)
@@ -1914,4 +1939,5 @@
 // Video parameter set (VPS)
 // ------------------------------------------------------------------------------------------------
+#if SVC_EXTENSION
 TComVPS::TComVPS()
 : m_VPSId                     (  0)
@@ -1933,10 +1959,8 @@
 , m_numOutputLayerSets        (0)  
 #endif
-#if VPS_PROFILE_OUTPUT_LAYERS
 , m_numProfileTierLevel       (0)
 , m_moreOutputLayerSetsThanDefaultFlag (false)
 , m_numAddOutputLayerSets     (0)
 , m_defaultOneTargetOutputLayerFlag    (false)
-#endif
 #if VPS_VUI_BITRATE_PICRATE
 , m_bitRatePresentVpsFlag     (false)
@@ -1992,9 +2016,10 @@
   ::memset(m_numLayerInIdList,     0, sizeof(m_numLayerInIdList   )); 
 #endif
-#if VPS_PROFILE_OUTPUT_LAYERS
   ::memset(m_profileLevelTierIdx,  0, sizeof(m_profileLevelTierIdx));
-#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   m_maxOneActiveRefLayerFlag = true;
+#endif
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+  ::memset(m_pocLsbNotPresentFlag, 0, sizeof(m_pocLsbNotPresentFlag));
 #endif
 #if N0147_IRAP_ALIGN_FLAG
@@ -2007,5 +2032,12 @@
   for( Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++)
   {
+#if O0225_MAX_TID_FOR_REF_LAYERS
+  for( Int j = 0; j < MAX_VPS_LAYER_ID_PLUS1; j++)
+  {
+    m_maxTidIlRefPicsPlus1[i][j] = m_uiMaxTLayers + 1;
+  }
+#else
     m_maxTidIlRefPicsPlus1[i] = m_uiMaxTLayers + 1;
+#endif 
   }
 #endif
@@ -2034,4 +2066,24 @@
 #endif
 }
+#else
+TComVPS::TComVPS()
+: m_VPSId                     (  0)
+, m_uiMaxTLayers              (  1)
+, m_uiMaxLayers               (  1)
+, m_bTemporalIdNestingFlag    (false)
+, m_numHrdParameters          (  0)
+, m_maxNuhReservedZeroLayerId (  0)
+, m_hrdParameters             (NULL)
+, m_hrdOpSetIdx               (NULL)
+, m_cprmsPresentFlag          (NULL)
+{
+  for( Int i = 0; i < MAX_TLAYER; i++)
+  {
+    m_numReorderPics[i] = 0;
+    m_uiMaxDecPicBuffering[i] = 1; 
+    m_uiMaxLatencyIncrease[i] = 0;
+  }
+}
+#endif //SVC_EXTENSION
 
 TComVPS::~TComVPS()
@@ -2163,17 +2215,15 @@
 , m_vuiParametersPresentFlag  (false)
 , m_vuiParameters             ()
+#if SVC_EXTENSION
 #if M0463_VUI_EXT_ILP_REF
 , m_interViewMvVertConstraintFlag (false)
 , m_numIlpRestrictedRefLayers ( 0 )
 #endif
-#if SVC_EXTENSION
-, m_layerId(0)
-#endif
-#if SCALED_REF_LAYER_OFFSETS
-, m_numScaledRefLayerOffsets  (0)
-#endif
+, m_layerId                   ( 0 )
+, m_numScaledRefLayerOffsets  ( 0 )
 #if REPN_FORMAT_IN_VPS
 , m_updateRepFormatFlag       (false)
 #endif
+#endif //SVC_EXTENSION
 {
   for ( Int i = 0; i < MAX_TLAYER; i++ )
@@ -3038,5 +3088,15 @@
 #endif
 }
-#endif 
+
+#if MFM_ENCCONSTRAINT
+TComPic* TComSlice::getBaseColPic(  TComList<TComPic*>& rcListPic )
+{
+#if POC_RESET_FLAG
+  return xGetRefPic( rcListPic, m_bPocResetFlag ? 0 : m_iPOC );
+#else
+  return xGetRefPic( rcListPic, m_iPOC );
+#endif
+}
+#endif
 
 #if REF_IDX_MFM
@@ -3085,3 +3145,26 @@
 #endif
 
+Void TComSlice::setILRPic(TComPic **pcIlpPic)
+{
+  for( Int i = 0; i < m_activeNumILRRefIdx; i++ )
+  {
+    Int refLayerIdc = m_interLayerPredLayerIdc[i];
+
+    if( pcIlpPic[refLayerIdc] )
+    {
+      pcIlpPic[refLayerIdc]->copyUpsampledPictureYuv( m_pcPic->getFullPelBaseRec( refLayerIdc ), pcIlpPic[refLayerIdc]->getPicYuvRec() );
+      pcIlpPic[refLayerIdc]->getSlice(0)->setPOC( m_iPOC );
+      pcIlpPic[refLayerIdc]->setLayerId( m_pcBaseColPic[refLayerIdc]->getLayerId() ); //set reference layerId
+      pcIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension( false );
+      pcIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
+      for (Int j=0; j<pcIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)    // set reference CU layerId
+      {
+        pcIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId( pcIlpPic[refLayerIdc]->getLayerId() );
+      }
+    }
+  }
+}
+
+#endif //SVC_EXTENSION
+
 //! \}
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 494)
@@ -436,5 +436,9 @@
 class RepFormat
 {
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatVpsIdc;
+#else
   Int  m_chromaFormatVpsIdc;
+#endif
   Bool m_separateColourPlaneVpsFlag;
   Int  m_picWidthVpsInLumaSamples;
@@ -446,6 +450,11 @@
   RepFormat();
 
+#if AUXILIARY_PICTURES
+  ChromaFormat getChromaFormatVpsIdc()        { return m_chromaFormatVpsIdc; }
+  Void setChromaFormatVpsIdc(ChromaFormat x)  { m_chromaFormatVpsIdc = x;    }
+#else
   Int  getChromaFormatVpsIdc()        { return m_chromaFormatVpsIdc; }
   Void setChromaFormatVpsIdc(Int x)   { m_chromaFormatVpsIdc = x;    }
+#endif
 
   Bool getSeparateColourPlaneVpsFlag()        { return m_separateColourPlaneVpsFlag; }
@@ -484,24 +493,27 @@
   UInt*       m_hrdOpSetIdx;
   Bool*       m_cprmsPresentFlag;
+#if !SVC_EXTENSION
+  UInt        m_numOpSets;
+  Bool        m_layerIdIncludedFlag[MAX_VPS_OP_SETS_PLUS1][MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1];
+#endif
+  TComPTL     m_pcPTL;
+  TimingInfo  m_timingInfo;
+
+#if SVC_EXTENSION
+#if DERIVE_LAYER_ID_LIST_VARIABLES
+  Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
+#if IL_SL_SIGNALLING_N0371
+  Bool        m_scalingListLayerDependency[MAX_LAYERS][MAX_LAYERS];  // layer dependency for scaling list
+#endif
+#if VPS_EXTN_OFFSET
+  UInt        m_extensionOffset;
+#endif
 #if VPS_RENAME
   UInt        m_maxLayerId;
   UInt        m_numLayerSets;
   Bool        m_layerIdIncludedFlag[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
-#else
-  UInt        m_numOpSets;
-  Bool        m_layerIdIncludedFlag[MAX_VPS_OP_SETS_PLUS1][MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1];
-#endif
-#if DERIVE_LAYER_ID_LIST_VARIABLES
-  Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
-  Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
-#endif
-#if IL_SL_SIGNALLING_N0371
-  Bool        m_scalingListLayerDependency[MAX_LAYERS][MAX_LAYERS];  // layer dependency for scaling list
-#endif
-#if VPS_EXTN_OFFSET
-  UInt        m_extensionOffset;
-#endif
-  TComPTL     m_pcPTL;
-  TimingInfo  m_timingInfo;
+#endif
 
   // ------------------------------------------
@@ -546,5 +558,4 @@
 #endif
 #endif
-#if VPS_PROFILE_OUTPUT_LAYERS
   UInt       m_numProfileTierLevel;
   Bool       m_moreOutputLayerSetsThanDefaultFlag;
@@ -552,13 +563,19 @@
   Bool       m_defaultOneTargetOutputLayerFlag;
   Int        m_profileLevelTierIdx[64];     
-#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   Bool       m_maxOneActiveRefLayerFlag;
 #endif
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+  Bool       m_pocLsbNotPresentFlag[MAX_VPS_LAYER_ID_PLUS1];
+#endif
 #if N0147_IRAP_ALIGN_FLAG
   Bool       m_crossLayerIrapAlignFlag;
 #endif
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
+#if O0225_MAX_TID_FOR_REF_LAYERS
+  UInt       m_maxTidIlRefPicsPlus1[MAX_VPS_LAYER_ID_PLUS1 - 1][MAX_VPS_LAYER_ID_PLUS1];
+#else
   UInt       m_maxTidIlRefPicsPlus1[MAX_VPS_LAYER_ID_PLUS1 - 1];
+#endif
 #endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
@@ -597,4 +614,9 @@
   Int         m_viewIdVal                [MAX_LAYERS];
 #endif
+
+#if O0215_PHASE_ALIGNMENT
+  Bool       m_phaseAlignFlag;
+#endif
+#endif //SVC_EXTENSION
 public:
   TComVPS();
@@ -637,12 +659,6 @@
   UInt    getNumHrdParameters()                                 { return m_numHrdParameters; }
   Void    setNumHrdParameters(UInt v)                           { m_numHrdParameters = v;    }
-
-#if VPS_RENAME
-  UInt    getMaxLayerId()                                       { return m_maxLayerId; }
-  Void    setMaxLayerId(UInt v)                                 { m_maxLayerId = v;    }
-
-  UInt    getNumLayerSets()                                     { return m_numLayerSets; }
-  Void    setNumLayerSets(UInt v)                               { m_numLayerSets = v;    }
-#else
+  
+#if !SVC_EXTENSION
   UInt    getMaxNuhReservedZeroLayerId()                        { return m_maxNuhReservedZeroLayerId; }
   Void    setMaxNuhReservedZeroLayerId(UInt v)                  { m_maxNuhReservedZeroLayerId = v;    }
@@ -653,4 +669,9 @@
   Bool    getLayerIdIncludedFlag(UInt opsIdx, UInt id)          { return m_layerIdIncludedFlag[opsIdx][id]; }
   Void    setLayerIdIncludedFlag(Bool v, UInt opsIdx, UInt id)  { m_layerIdIncludedFlag[opsIdx][id] = v;    }
+
+  TComPTL* getPTL() { return &m_pcPTL; }
+  TimingInfo* getTimingInfo() { return &m_timingInfo; }
+
+#if SVC_EXTENSION
 #if DERIVE_LAYER_ID_LIST_VARIABLES
   Int     getLayerSetLayerIdList(Int set, Int layerId)          { return m_layerSetLayerIdList[set][layerId]; }
@@ -669,6 +690,11 @@
 #endif
 
-  TComPTL* getPTL() { return &m_pcPTL; }
-  TimingInfo* getTimingInfo() { return &m_timingInfo; }
+#if VPS_RENAME
+  UInt    getMaxLayerId()                                       { return m_maxLayerId; }
+  Void    setMaxLayerId(UInt v)                                 { m_maxLayerId = v;    }
+
+  UInt    getNumLayerSets()                                     { return m_numLayerSets; }
+  Void    setNumLayerSets(UInt v)                               { m_numLayerSets = v;    }
+#endif
 #if VPS_EXTN_MASK_AND_DIM_INFO
   Bool   getAvcBaseLayerFlag()                                  { return m_avcBaseLayerFlag;       }
@@ -743,5 +769,4 @@
 #endif
 #endif
-#if VPS_PROFILE_OUTPUT_LAYERS
   UInt   getNumProfileTierLevel()                                { return m_numProfileTierLevel; }
   Void   setNumProfileTierLevel(Int x)                           { m_numProfileTierLevel = x;    }
@@ -758,9 +783,12 @@
   Int    getProfileLevelTierIdx(Int i)                        { return m_profileLevelTierIdx[i]; }
   Void   setProfileLevelTierIdx(Int i, Int x)                 { m_profileLevelTierIdx[i] = x   ; }
-#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   Bool   getMaxOneActiveRefLayerFlag()                                          { return m_maxOneActiveRefLayerFlag;                      }
   Void   setMaxOneActiveRefLayerFlag(Bool x)                                    { m_maxOneActiveRefLayerFlag = x;                         }
-#endif 
+#endif
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+  UInt   getPocLsbNotPresentFlag(Int i)                                         { return m_pocLsbNotPresentFlag[i]; }
+  Void   setPocLsbNotPresentFlag(Int i, Bool x)                                 { m_pocLsbNotPresentFlag[i] = x;    }
+#endif
 #if N0147_IRAP_ALIGN_FLAG
   Bool   getCrossLayerIrapAlignFlag()                                           { return m_crossLayerIrapAlignFlag;                      }
@@ -768,6 +796,11 @@
 #endif 
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
+#if O0225_MAX_TID_FOR_REF_LAYERS
+  UInt   getMaxTidIlRefPicsPlus1(Int layerId, Int refLayerId)                     { return m_maxTidIlRefPicsPlus1[layerId][refLayerId];           }
+  Void   setMaxTidIlRefPicsPlus1(Int layerId, Int refLayerId, UInt maxSublayer)   { m_maxTidIlRefPicsPlus1[layerId][refLayerId] = maxSublayer;    }
+#else
   UInt   getMaxTidIlRefPicsPlus1(Int layerId)                     { return m_maxTidIlRefPicsPlus1[layerId];                   }
   Void   setMaxTidIlRefPicsPlus1(Int layerId, UInt maxSublayer)   { m_maxTidIlRefPicsPlus1[layerId] = maxSublayer;            }
+#endif
 #endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
@@ -847,4 +880,9 @@
   Void    setExtensionOffset( UInt offset )    { m_extensionOffset = offset; }
 #endif
+#if O0215_PHASE_ALIGNMENT
+  Bool   getPhaseAlignFlag()                             { return m_phaseAlignFlag; }
+  Void   setPhaseAlignFlag(Bool x)                       { m_phaseAlignFlag = x;    }
+#endif
+#endif //SVC_EXTENSION
 };
 
@@ -924,8 +962,4 @@
   TComHRD m_hrdParameters;
   TimingInfo m_timingInfo;
-#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
-  Bool m_tileBoundariesAlignedFlag;
-#endif
-
 
 public:
@@ -960,7 +994,4 @@
     ,m_log2MaxMvLengthHorizontal(15)
     ,m_log2MaxMvLengthVertical(15)
-#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
-    ,m_tileBoundariesAlignedFlag(true)
-#endif
   {}
 
@@ -1058,8 +1089,4 @@
   TComHRD* getHrdParameters                 ()             { return &m_hrdParameters; }
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
-#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
-  Bool getTileBoundariesAlignedFlag(  ) { return m_tileBoundariesAlignedFlag; } 
-  Void setTileBoundariesAlignedFlag( Bool flag ) { m_tileBoundariesAlignedFlag = flag; } 
-#endif
 };
 
@@ -1070,5 +1097,9 @@
   Int         m_SPSId;
   Int         m_VPSId;
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatIdc;
+#else
   Int         m_chromaFormatIdc;
+#endif
 
   UInt        m_uiMaxTLayers;           // maximum number of temporal layers
@@ -1143,4 +1174,5 @@
   TComPTL     m_pcPTL;
 
+#if SVC_EXTENSION
 #if M0463_VUI_EXT_ILP_REF
   Bool        m_interViewMvVertConstraintFlag;
@@ -1151,5 +1183,4 @@
 #endif
 
-#if SVC_EXTENSION
   UInt m_layerId;
 
@@ -1161,5 +1192,4 @@
 #endif
 
-#endif
 #if REF_IDX_MFM
 #if !M0457_COL_PICTURE_SIGNALING
@@ -1167,11 +1197,10 @@
 #endif
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   UInt        m_numScaledRefLayerOffsets;
   Window      m_scaledRefLayerWindow[MAX_LAYERS];
-#endif
 #if REPN_FORMAT_IN_VPS
   Bool m_updateRepFormatFlag;
 #endif
+#endif //SVC_EXTENSION
 public:
   TComSPS();
@@ -1182,4 +1211,12 @@
   Int  getSPSId       ()         { return m_SPSId;          }
   Void setSPSId       (Int i)    { m_SPSId = i;             }
+
+#if AUXILIARY_PICTURES
+  ChromaFormat getChromaFormatIdc ()         { return m_chromaFormatIdc;       }
+  Void setChromaFormatIdc (ChromaFormat i)   { m_chromaFormatIdc = i;          }
+
+  static Int getWinUnitX (Int chromaFormatIdc) { assert (chromaFormatIdc >= 0 && chromaFormatIdc <= MAX_CHROMA_FORMAT_IDC); return m_winUnitX[chromaFormatIdc];      }
+  static Int getWinUnitY (Int chromaFormatIdc) { assert (chromaFormatIdc >= 0 && chromaFormatIdc <= MAX_CHROMA_FORMAT_IDC); return m_winUnitY[chromaFormatIdc];      }
+#else
   Int  getChromaFormatIdc ()         { return m_chromaFormatIdc;       }
   Void setChromaFormatIdc (Int i)    { m_chromaFormatIdc = i;          }
@@ -1187,4 +1224,5 @@
   static Int getWinUnitX (Int chromaFormatIdc) { assert (chromaFormatIdc > 0 && chromaFormatIdc <= MAX_CHROMA_FORMAT_IDC); return m_winUnitX[chromaFormatIdc];      }
   static Int getWinUnitY (Int chromaFormatIdc) { assert (chromaFormatIdc > 0 && chromaFormatIdc <= MAX_CHROMA_FORMAT_IDC); return m_winUnitY[chromaFormatIdc];      }
+#endif
   
   // structure
@@ -1334,5 +1372,4 @@
   Void     setLayerId(UInt layerId) { m_layerId = layerId; }
   UInt     getLayerId() { return m_layerId; }
-#endif
 #if REF_IDX_MFM
 #if !M0457_COL_PICTURE_SIGNALING
@@ -1341,13 +1378,12 @@
 #endif
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   UInt     getNumScaledRefLayerOffsets()  { return m_numScaledRefLayerOffsets; }
   Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x; }
   Window&  getScaledRefLayerWindow( Int x )   { return m_scaledRefLayerWindow[x]; }
-#endif
 #if REPN_FORMAT_IN_VPS
   Bool     getUpdateRepFormatFlag()       { return m_updateRepFormatFlag; }
   Void     setUpdateRepFormatFlag(Bool x) { m_updateRepFormatFlag = x;    }
 #endif
+#endif //SVC_EXTENSION
 };
 
@@ -1604,4 +1640,7 @@
   Int64 iAC;
   Int64 iDC;
+#if O0194_WEIGHTED_PREDICTION_CGS
+  Int iSamples;
+#endif
 } wpACDCParam;
 
@@ -1636,16 +1675,4 @@
   Int         m_deblockingFilterBetaOffsetDiv2;    //< beta offset for deblocking filter
   Int         m_deblockingFilterTcOffsetDiv2;      //< tc offset for deblocking filter
-#if JCTVC_M0458_INTERLAYER_RPS_SIG
-  Int         m_activeNumILRRefIdx;        //< Active inter-layer reference pictures
-  Int         m_interLayerPredLayerIdc  [MAX_VPS_LAYER_ID_PLUS1];
-#else
-#if SVC_EXTENSION
-  Int         m_numILRRefIdx;       //< for inter-layer reference picture ser
-#endif
-#endif 
-#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
-  Int         m_numSamplePredRefLayers;
-  Bool        m_interLayerSamplePredOnlyFlag;
-#endif
   Int         m_list1IdxToList0Idx[MAX_NUM_REF];
   Int         m_aiNumRefIdx   [2];    //  for multiple reference of current slice
@@ -1664,12 +1691,5 @@
   // referenced slice?
   Bool        m_bRefenced;
-  
-#if POC_RESET_FLAG
-  Bool        m_bPocResetFlag;
-  Int         m_pocValueBeforeReset;
-#endif  
-#if SH_DISCARDABLE_FLAG
-  Bool        m_bDiscardableFlag;
-#endif
+
   // access channel
   TComVPS*    m_pcVPS;
@@ -1685,5 +1705,4 @@
   UInt        m_maxNumMergeCand;
 
-
 #if SAO_CHROMA_LAMBDA
   Double      m_dLambdaLuma;
@@ -1695,18 +1714,4 @@
   Bool        m_abEqualRef  [2][MAX_NUM_REF][MAX_NUM_REF];
   UInt        m_uiTLayer;
-#if SVC_EXTENSION
-  UInt        m_layerId;
-  TComPic*    m_pcBaseColPic[MAX_LAYERS];
-  TComPicYuv* m_pcFullPelBaseRec[MAX_LAYERS];
-#if M0457_COL_PICTURE_SIGNALING
-  Int         m_numMotionPredRefLayers;
-#if REF_IDX_MFM
-  Bool        m_bMFMEnabledFlag;
-  Int         m_colRefLayerIdx;
-  Bool        m_altColIndicationFlag;
-  TComPic*    m_pcIlpPic;
-#endif
-#endif
-#endif 
   Bool        m_bTLayerSwitchingFlag;
 
@@ -1742,7 +1747,39 @@
 
   Bool       m_enableTMVPFlag;
+
+#if SVC_EXTENSION
+  UInt        m_layerId;
+  TComPic*    m_pcBaseColPic[MAX_LAYERS];
+  TComPicYuv* m_pcFullPelBaseRec[MAX_LAYERS];
+#if M0457_COL_PICTURE_SIGNALING
+  Int         m_numMotionPredRefLayers;
+#if REF_IDX_MFM
+  Bool        m_bMFMEnabledFlag;
+  Int         m_colRefLayerIdx;
+  Bool        m_altColIndicationFlag;
+  TComPic*    m_pcIlpPic;
+#endif
+#endif
+
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
-  Bool       m_interLayerPredEnabledFlag;
+  Bool        m_interLayerPredEnabledFlag;
+  Int         m_activeNumILRRefIdx;        //< Active inter-layer reference pictures
+  Int         m_interLayerPredLayerIdc  [MAX_VPS_LAYER_ID_PLUS1];
+#else
+#if SVC_EXTENSION
+  Int         m_numILRRefIdx;       //< for inter-layer reference picture ser
+#endif
 #endif 
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+  Int         m_numSamplePredRefLayers;
+  Bool        m_interLayerSamplePredOnlyFlag;
+#endif
+#if POC_RESET_FLAG
+  Bool        m_bPocResetFlag;
+  Int         m_pocValueBeforeReset;
+#endif  
+  Bool        m_bDiscardableFlag;
+#endif //SVC_EXTENSION
+
 public:
   TComSlice();
@@ -1818,7 +1855,4 @@
   Bool      getMvdL1ZeroFlag ()                                  { return m_bLMvdL1Zero;    }
   Int       getNumRpsCurrTempList();
-#if RPL_INIT_N0316_N0082
-  Int       getNumNegativeRpsCurrTempList();
-#endif
   Int       getList1IdxToList0Idx ( Int list1Idx )               { return m_list1IdxToList0Idx[list1Idx]; }
   Void      setReferenced(Bool b)                               { m_bRefenced = b; }
@@ -1831,20 +1865,4 @@
   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); }  
-#if RESTR_CHK
-   Bool     isRADL() {  return (m_eNalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || m_eNalUnitType == NAL_UNIT_CODED_SLICE_RADL_R); }
-   Bool     isRASL()   {   return (m_eNalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || m_eNalUnitType == NAL_UNIT_CODED_SLICE_RASL_R); }
-#endif
-
-#if POC_RESET_FLAG
-  Bool      getPocResetFlag  ()                              { return m_bPocResetFlag; }
-  Void      setPocResetFlag  (Bool b)                        { m_bPocResetFlag = b; }
-  Int       getPocValueBeforeReset ()                        { return m_pocValueBeforeReset; }
-  Void      setPocValueBeforeReset (Int x)                   { m_pocValueBeforeReset = x ; }
-#endif
-#if SH_DISCARDABLE_FLAG
-  Bool      getDiscardableFlag  ()                              { return m_bDiscardableFlag; }
-  Void      setDiscardableFlag  (Bool b)                        { m_bDiscardableFlag = b; }
-#endif
-
   Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic);
   Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic);
@@ -2008,4 +2026,7 @@
   TComPic*  getBaseColPic       (UInt refLayerIdc)                { return m_pcBaseColPic[refLayerIdc]; }
   TComPic** getBaseColPic       ()                { return &m_pcBaseColPic[0]; }
+#if MFM_ENCCONSTRAINT
+  TComPic*  getBaseColPic( TComList<TComPic*>& rcListPic );
+#endif
 
   Void      setLayerId (UInt layerId)   { m_layerId = layerId; }
@@ -2063,17 +2084,41 @@
 #endif
 
-TComPic* getRefPic(TComList<TComPic*>& rcListPic, Int poc) { return xGetRefPic( rcListPic, poc ); } 
-
-#endif //SVC_EXTENSION
+  TComPic* getRefPic(TComList<TComPic*>& rcListPic, Int poc) { return xGetRefPic( rcListPic, poc ); } 
+
+#if RESTR_CHK
+  Bool     isRADL() {  return (m_eNalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || m_eNalUnitType == NAL_UNIT_CODED_SLICE_RADL_R); }
+  Bool     isRASL()   {   return (m_eNalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || m_eNalUnitType == NAL_UNIT_CODED_SLICE_RASL_R); }
+#endif
+
+#if POC_RESET_FLAG
+  Bool      getPocResetFlag  ()                              { return m_bPocResetFlag;       }
+  Void      setPocResetFlag  (Bool b)                        { m_bPocResetFlag = b;          }
+  Int       getPocValueBeforeReset ()                        { return m_pocValueBeforeReset; }
+  Void      setPocValueBeforeReset (Int x)                   { m_pocValueBeforeReset = x ;   }
+#endif
+  Bool      getDiscardableFlag  ()                           { return m_bDiscardableFlag;    }
+  Void      setDiscardableFlag  (Bool b)                     { m_bDiscardableFlag = b;       }
+
+#if RPL_INIT_N0316_N0082
+  Int       getNumNegativeRpsCurrTempList();
+#endif
 
 #if REPN_FORMAT_IN_VPS
   UInt getPicWidthInLumaSamples();
   UInt getPicHeightInLumaSamples();
+#if AUXILIARY_PICTURES
+  ChromaFormat getChromaFormatIdc();
+#else
   UInt getChromaFormatIdc();
+#endif
   UInt getBitDepthY();
   UInt getBitDepthC();
-  Int getQpBDOffsetY();
-  Int getQpBDOffsetC();
-#endif
+  Int  getQpBDOffsetY();
+  Int  getQpBDOffsetC();
+#endif
+
+  Void setILRPic(TComPic **pcIlpPic);
+
+#endif //SVC_EXTENSION
 protected:
   TComPic*  xGetRefPic  (TComList<TComPic*>& rcListPic,
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 494)
@@ -17,14 +17,14 @@
   {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
   {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
-#endif
-  { -1, 4, -11, 52, 26,  -8,  3, -1}, // <-> actual phase shift 1/3, used for spatial scalability x1.5      
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+#endif
+  { -1, 4, -11, 52, 26,  -8,  3, -1}, // <-> actual phase shift 1/3, used for spatial scalability x1.5
 #if ARBITRARY_SPATIAL_RATIO
   { -1, 3,  -9, 47, 31, -10,  4, -1},
   { -1, 4, -11, 45, 34, -10,  4, -1},
 #else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //       
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
 #endif
   { -1, 4, -11, 40, 40, -11,  4, -1}, // <-> actual phase shift 1/2, equal to HEVC MC, used for spatial scalability x2
@@ -33,6 +33,6 @@
   { -1,  4, -10, 31, 47,  -9,  3, -1},
 #else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
 #endif
   { -1, 3,  -8, 26, 52, -11, 4, -1}, // <-> actual phase shift 2/3, used for spatial scalability x1.5
@@ -43,8 +43,8 @@
   { 0,  1,  -2,  4, 63,  -3,  1,  0}
 #else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}  // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}  //
 #endif
 };
@@ -60,13 +60,13 @@
   {CNU,CNU,CNU,CNU},//
   {CNU,CNU,CNU,CNU},//
-  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},//
 #endif
   { -4, 54, 16, -2},// <-> actual phase shift 1/4,equal to HEVC MC, used for spatial scalability x1.5 (only for accurate Chroma alignement)
-  { -6, 52, 20, -2},// <-> actual phase shift 1/3, used for spatial scalability x1.5   
-  { -6, 46, 28, -4},// <-> actual phase shift 3/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)      
+  { -6, 52, 20, -2},// <-> actual phase shift 1/3, used for spatial scalability x1.5
+  { -6, 46, 28, -4},// <-> actual phase shift 3/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)
 #if ARBITRARY_SPATIAL_RATIO
   { -4, 42, 30, -4},
 #else
-  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},//
 #endif
   { -4, 36, 36, -4},// <-> actual phase shift 1/2,equal to HEVC MC, used for spatial scalability x2
@@ -75,5 +75,5 @@
   { -4, 28, 46, -6},
 #else
-  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},//
 #endif
   { -2, 20, 52, -6},// <-> actual phase shift 2/3, used for spatial scalability x1.5
@@ -82,8 +82,8 @@
   {-2, 14, 56, -4},
 #else
-  {CNU,CNU,CNU,CNU},// 
-  {CNU,CNU,CNU,CNU},// 
-#endif
-  { -2, 10, 58, -2},// <-> actual phase shift 7/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)  
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},//
+#endif
+  { -2, 10, 58, -2},// <-> actual phase shift 7/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)
   {  0,  4, 62, -2} // <-> actual phase shift 11/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
 };
@@ -97,8 +97,16 @@
 }
 
-#if SCALED_REF_LAYER_OFFSETS
+#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 )
+#endif
+#else
+#if O0194_JOINT_US_BITSHIFT
+Void TComUpsampleFilter::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window )
+#else
 Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window )
-#else
-Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic )
+#endif
 #endif
 {
@@ -109,5 +117,4 @@
 
   //========== Y component upsampling ===========
-#if SCALED_REF_LAYER_OFFSETS
   const Window &scalEL = window;
 
@@ -119,16 +126,5 @@
   Int heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
   Int strideEL  = pcUsPic->getStride();
-#else
-  const Window &confBL = pcBasePic->getConformanceWindow();
-  const Window &confEL = pcUsPic->getConformanceWindow();
-
-  Int widthBL   = pcBasePic->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-  Int heightBL  = pcBasePic->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-  Int strideBL  = pcBasePic->getStride();
-
-  Int widthEL   = pcUsPic->getWidth () - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-  Int heightEL  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-  Int strideEL  = pcUsPic->getStride();
-#endif
+
   Pel* piTempBufY = pcTempPic->getLumaAddr();
   Pel* piSrcBufY  = pcBasePic->getLumaAddr();
@@ -153,4 +149,9 @@
   Int scaleX = g_posScalingFactor[refLayerIdc][0];
   Int scaleY = g_posScalingFactor[refLayerIdc][1];
+
+#if O0194_JOINT_US_BITSHIFT
+  UInt currLayerId = currSlice->getLayerId();
+  UInt refLayerId  = currSlice->getVPS()->getRefLayerId( currLayerId, refLayerIdc );
+#endif
 
   if( scaleX == 65536 && scaleY == 65536 ) // ratio 1x
@@ -194,5 +195,5 @@
     Int refPos16 = 0;
     Int phase    = 0;
-    Int refPos   = 0; 
+    Int refPos   = 0;
     Int* coeff = m_chromaFilter[phase];
     for ( i = 0; i < 16; i++)
@@ -202,5 +203,5 @@
     }
 
-#if ARBITRARY_SPATIAL_RATIO 
+#if ARBITRARY_SPATIAL_RATIO
     assert ( widthEL >= widthBL );
     assert ( heightEL >= heightBL );
@@ -216,6 +217,11 @@
     Int   shiftY = 16;
 
+#if O0215_PHASE_ALIGNMENT //for Luma, if Phase 0, then both PhaseX  and PhaseY should be 0. If symmetric: both PhaseX and PhaseY should be 2
+    Int   phaseX = 2*phaseAlignFlag;
+    Int   phaseY = 2*phaseAlignFlag;
+#else
     Int   phaseX = 0;
     Int   phaseY = 0;
+#endif
 
 #if ROUNDING_OFFSET
@@ -228,5 +234,5 @@
 
     Int   deltaX     = 4 * phaseX;
-    Int   deltaY     = 4 * phaseY;  
+    Int   deltaY     = 4 * phaseY;
 
     Int shiftXM4 = shiftX - 4;
@@ -238,16 +244,18 @@
     widthBL   = pcBasePic->getWidth ();
     heightBL  = min<Int>( pcBasePic->getHeight(), heightEL );
-#if SCALED_REF_LAYER_OFFSETS
+
     Int leftStartL = scalEL.getWindowLeftOffset();
     Int rightEndL  = pcUsPic->getWidth() - scalEL.getWindowRightOffset();
     Int topStartL  = scalEL.getWindowTopOffset();
     Int bottomEndL = pcUsPic->getHeight() - scalEL.getWindowBottomOffset();
-#if BUGFIX_RESAMPLE
     Int leftOffset = leftStartL > 0 ? leftStartL : 0;
-#endif
-#endif
 
 #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;
+#else
     Int shift1 = g_bitDepthY - 8;
+#endif
 #endif
 
@@ -255,10 +263,6 @@
     for( i = 0; i < widthEL; i++ )
     {
-#if SCALED_REF_LAYER_OFFSETS
       Int x = Clip3( leftStartL, rightEndL - 1, i );
       refPos16 = (((x - leftStartL)*scaleX + addX) >> shiftXM4) - deltaX;
-#else
-      refPos16 = ((i*scaleX + addX) >> shiftXM4) - deltaX;
-#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
@@ -287,22 +291,18 @@
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+    Int nShift = 20 - g_bitDepthYLayer[currLayerId];
+#else
     Int nShift = US_FILTER_PREC*2 - shift1;
+#endif
 #else
     const Int nShift = US_FILTER_PREC*2;
 #endif
-    Int iOffset = 1 << (nShift - 1); 
-
-#if SCALED_REF_LAYER_OFFSETS
+    Int iOffset = 1 << (nShift - 1);
+
     for( j = 0; j < pcTempPic->getHeight(); j++ )
-#else
-    for( j = 0; j < heightEL; j++ )
-#endif
-    {
-#if SCALED_REF_LAYER_OFFSETS
+    {
       Int y = Clip3(topStartL, bottomEndL - 1, j);
       refPos16 = ((( y - topStartL )*scaleY + addY) >> shiftYM4) - deltaY;
-#else
-      refPos16 = ((j*scaleY + addY) >> shiftYM4) - deltaY;
-#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
@@ -310,7 +310,5 @@
 
       piSrcY = piTempBufY + (refPos -((NTAPS_US_LUMA>>1) - 1))*strideEL;
-#if SCALED_REF_LAYER_OFFSETS
-#if BUGFIX_RESAMPLE
-      Pel* piDstY0 = piDstBufY + j * strideEL;            
+      Pel* piDstY0 = piDstBufY + j * strideEL;
       piDstY = piDstY0 + leftOffset;
       piSrcY += leftOffset;
@@ -335,58 +333,7 @@
         piDstY++;
       }
-#else
-#if 1 // it should provide identical result
-      Pel* piDstY0 = piDstBufY + j * strideEL;            
-      piDstY = piDstY0 + ( leftStartL > 0 ? leftStartL : 0 );
-
-      for( i = min<Int>(rightEndL, pcTempPic->getWidth()) - max<Int>(0, leftStartL); i > 0; i-- )
-      {
-        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
-        piSrcY++;
-        piDstY++;
-      }
-
-      for( i = rightEndL; i < pcTempPic->getWidth(); i++ )
-      {
-        *piDstY = piDstY0[rightEndL-1];
-        piDstY++;
-      }
-
-      piDstY = piDstY0;
-      for( i = 0; i < leftStartL; i++ )
-      {
-        *piDstY = piDstY0[leftStartL];
-        piDstY++;
-      }
-#else
-      piDstY = piDstBufY + j * strideEL;
-
-      for( i = 0; i < pcTempPic->getWidth(); i++ )
-      {
-        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
-
-        // Only increase the x position of reference upsample picture when within the window
-        // "-2" to ensure that pointer doesn't go beyond the boundary rightEndL-1
-        if( (i >= leftStartL) && (i <= rightEndL-2) )
-        {
-          piSrcY++;
-        }
-        piDstY++;
-      }
-#endif
-#endif
-#else
-      piDstY = piDstBufY + j * strideEL;
-
-      for( i = 0; i < widthEL; i++ )
-      {
-        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
-        piSrcY++;
-        piDstY++;
-      }
-#endif
-    }
-
-#if SCALED_REF_LAYER_OFFSETS
+
+    }
+
     widthBL   = pcBasePic->getWidth ();
     heightBL  = pcBasePic->getHeight();
@@ -394,11 +341,4 @@
     widthEL   = pcUsPic->getWidth () - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
     heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
-#else
-    widthBL   = pcBasePic->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-    heightBL  = pcBasePic->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-
-    widthEL   = pcUsPic->getWidth () - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-    heightEL  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#endif
 
     //========== UV component upsampling ===========
@@ -412,17 +352,29 @@
     strideBL  = pcBasePic->getCStride();
     strideEL  = pcUsPic->getCStride();
-#if SCALED_REF_LAYER_OFFSETS
+
     Int leftStartC = scalEL.getWindowLeftOffset() >> 1;
     Int rightEndC  = (pcUsPic->getWidth() >> 1) - (scalEL.getWindowRightOffset() >> 1);
     Int topStartC  = scalEL.getWindowTopOffset() >> 1;
     Int bottomEndC = (pcUsPic->getHeight() >> 1) - (scalEL.getWindowBottomOffset() >> 1);
-#if BUGFIX_RESAMPLE
     leftOffset = leftStartC > 0 ? leftStartC : 0;
-#endif
-#endif
 
     shiftX = 16;
     shiftY = 16;
 
+#if O0215_PHASE_ALIGNMENT
+    Int phaseXC = 0;
+    Int phaseYC = 1;
+
+#if ROUNDING_OFFSET
+    addX       = ( ( (phaseXC+phaseAlignFlag) * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
+    addY       = ( ( (phaseYC+phaseAlignFlag) * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
+#else
+    addX       = ( ( ( widthBL * (phaseXC+phaseAlignFlag) ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
+    addY       = ( ( ( heightBL * (phaseYC+phaseAlignFlag) ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
+#endif
+
+    deltaX     = 4 * (phaseXC+phaseAlignFlag);
+    deltaY     = 4 * (phaseYC+phaseAlignFlag);
+#else
     phaseX = 0;
     phaseY = 1;
@@ -438,4 +390,5 @@
     deltaX     = 4 * phaseX;
     deltaY     = 4 * phaseY;
+#endif
 
     shiftXM4 = shiftX - 4;
@@ -449,5 +402,10 @@
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+    // g_bitDepthC was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
+    shift1 = g_bitDepthCLayer[refLayerId] - 8;
+#else
     shift1 = g_bitDepthC - 8;
+#endif
 #endif
 
@@ -455,10 +413,6 @@
     for( i = 0; i < widthEL; i++ )
     {
-#if SCALED_REF_LAYER_OFFSETS
       Int x = Clip3(leftStartC, rightEndC - 1, i);
       refPos16 = (((x - leftStartC)*scaleX + addX) >> shiftXM4) - deltaX;
-#else
-      refPos16 = ((i*scaleX + addX) >> shiftXM4) - deltaX;
-#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
@@ -494,28 +448,23 @@
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+    nShift = 20 - g_bitDepthCLayer[refLayerId];
+#else
     nShift = US_FILTER_PREC*2 - shift1;
-    iOffset = 1 << (nShift - 1); 
-#endif
-
-#if SCALED_REF_LAYER_OFFSETS
+#endif
+    iOffset = 1 << (nShift - 1);
+#endif
+
     for( j = 0; j < pcTempPic->getHeight() >> 1; j++ )
-#else
-    for( j = 0; j < heightEL; j++ )
-#endif
-    {
-#if SCALED_REF_LAYER_OFFSETS
+    {
       Int y = Clip3(topStartC, bottomEndC - 1, j);
       refPos16 = (((y - topStartC)*scaleY + addY) >> shiftYM4) - deltaY;
-#else
-      refPos16 = ((j*scaleY + addY) >> shiftYM4) - deltaY;
-#endif
       phase    = refPos16 & 15;
-      refPos   = refPos16 >> 4; 
+      refPos   = refPos16 >> 4;
       coeff = m_chromaFilter[phase];
-      
+
       piSrcU = piTempBufU  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*strideEL;
       piSrcV = piTempBufV  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*strideEL;
-#if SCALED_REF_LAYER_OFFSETS
-#if BUGFIX_RESAMPLE
+
       Pel* piDstU0 = piDstBufU + j*strideEL;
       Pel* piDstV0 = piDstBufV + j*strideEL;
@@ -552,74 +501,5 @@
         piDstV++;
       }
-#else
-#if 1 // it should provide identical result
-      Pel* piDstU0 = piDstBufU + j*strideEL;
-      Pel* piDstV0 = piDstBufV + j*strideEL;
-      piDstU = piDstU0 + ( leftStartC > 0 ? leftStartC : 0 );
-      piDstV = piDstV0 + ( leftStartC > 0 ? leftStartC : 0 );
-
-      for( i = min<Int>(rightEndC, pcTempPic->getWidth() >> 1) - max<Int>(0, leftStartC); i > 0; i-- )
-      {
-        *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
-        *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
-        piSrcU++;
-        piSrcV++;
-        piDstU++;
-        piDstV++;
-      }
-
-      for( i = rightEndC; i < pcTempPic->getWidth() >> 1; i++ )
-      {
-        *piDstU = piDstU0[rightEndC-1];
-        *piDstV = piDstV0[rightEndC-1];
-        piDstU++;
-        piDstV++;
-      }
-
-      piDstU = piDstU0;
-      piDstV = piDstV0;
-      for( i = 0; i < leftStartC; i++ )
-      {
-        *piDstU = piDstU0[leftStartC];
-        *piDstV = piDstV0[leftStartC];
-        piDstU++;
-        piDstV++;
-      }
-#else
-      piDstU = piDstBufU + j*strideEL;
-      piDstV = piDstBufV + j*strideEL;
-
-      for( i = 0; i < pcTempPic->getWidth() >> 1; i++ )
-      {
-        *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
-        *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
-
-        // Only increase the x position of reference upsample picture when within the window
-        // "-2" to ensure that pointer doesn't go beyond the boundary rightEndC-1
-        if( (i >= leftStartC) && (i <= rightEndC-2) )
-        {
-          piSrcU++;
-          piSrcV++;
-        }
-
-        piDstU++;
-        piDstV++;
-      }
-#endif
-#endif
-#else
-      piDstU = piDstBufU + j*strideEL;
-      piDstV = piDstBufV + j*strideEL;
-
-      for( i = 0; i < widthEL; i++ )
-      {
-        *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
-        *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
-        piSrcU++;
-        piSrcV++;
-        piDstU++;
-        piDstV++;
-      }
-#endif
+
     }
   }
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 442)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 494)
@@ -43,9 +43,18 @@
   ~TComUpsampleFilter(void);
 
-#if SCALED_REF_LAYER_OFFSETS
+#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 );
+#else
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag );
+#endif
+#else
+#if O0194_JOINT_US_BITSHIFT
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+#else
   Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
-#else
- Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
 #endif
+#endif
+
 };
 
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 442)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 494)
@@ -45,6 +45,13 @@
 #define RANDOM_ACCESS_SEI_FIX            1
 #if SVC_EXTENSION
+#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+
+#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)
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+#define O0194_JOINT_US_BITSHIFT          1      ///< JCTVC-O0194: Joint Upsampling and bit-shift
+#endif
+#define O0194_WEIGHTED_PREDICTION_CGS    1      ///< JCTVC-O0194: Weighted prediciton for color gamut scalability
+#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
-#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
 #define POC_RESET_FLAG                   1      ///< JCTVC-N0244: POC reset flag for  layer pictures.
 #define ALIGN_TSA_STSA_PICS              1      ///< JCTVC-N0084: Alignment of TSA and STSA pictures across AU.
@@ -52,18 +59,16 @@
 #define TIMING_INFO_NONZERO_LAYERID_SPS  1      ///< JCTVC-N0085: Semantics of vui_timing_info_present_flag to always set that flag to zero for non-zero layer ID SPS 
 #define RPL_INIT_N0316_N0082             1      ///< JCTVC-N0316, JCTVC-N0082: initial reference picture list construction 
-#define FINAL_RPL_CHANGE_N0082           1      ///< JCTVC-N0082: final ref picture list change (encoder)
-#if FINAL_RPL_CHANGE_N0082
-#define EXTERNAL_USEDBYCURR_N0082        1      ///< JCTVC-N0082: final ref picture list change (encoder) //dev ver.
-#define TEMP_SCALABILITY_FIX             1      ///< fix for temporal scalability
-#endif
+
 #define IL_SL_SIGNALLING_N0371           0      ///< JCTVC-N0371: inter-layer scaling list
-#define M0464_TILE_BOUNDARY_ALIGNED_FLAG 0      ///< JCTVC-M0464: VUI flag to indicate tile boundary alignment
 #define M0463_VUI_EXT_ILP_REF            0      ///< JCTVC-M0463: VUI extension inter-layer dependency offset signalling
 #define SPS_EXTENSION                    1      ///< Define sps_extension() syntax structure
-#define SCALED_REF_LAYER_OFFSETS         1      ///< JCTVC-M0309: Signal scaled reference layer offsets in SPS
 #define VERT_MV_CONSTRAINT               1      ///< Vertical MV component constraint flag
 #define SCALABILITY_MASK_E0104           1      ///< JCT3V-E0104: scalability mask for depth
+#define LAYER_CTB                        0      ///< enable layer-specific CTB structure
 
 #define ILP_SSH_SIG                      1      ///< JCTVC-N0195 proposal 2, JCTVC-N0118: add presence flag in VPS ext to condition inter-layer prediction signaling in slice segment header
+#if ILP_SSH_SIG
+#define ILP_SSH_SIG_FIX                  1      ///< fix for SHM ticket #5
+#endif 
 #define SPL_FLG_CHK                      1      ///< JCTVC-N0195 proposal 5, JCTVC-N0085: constrain sum of lengths to be less than or equal to 6
 #define ILP_NUM_REF_CHK                  1      ///< JCTVC-N0195 proposal 1, JCTVC-N0081, JCTVC-N0154, JCTVC-N0217: a condition on signaling inter_layer_pred_layer_idc[ i ], to avoid sending when NumDirectRefLayers equals NumActiveRefLayerPics, and instead infer values
@@ -76,9 +81,4 @@
 #define VPS_EXTN_PROFILE_INFO            1      ///< Include profile information for layer sets in VPS extension
 #define VPS_EXTN_DIRECT_REF_LAYERS       1      ///< Include indication of direct dependency of layers in VPS extension
-#define VPS_OUTPUT_LAYER_SET_IDX         1      ///< JCTVC-M0268: Signal output_layer_set_idx[i] as output_layer_set_idx_minus1[i]
-#define VPS_MOVE_DIR_DEPENDENCY_FLAG     1      ///< JCTVC-M0268: Move the syntax element direct_dependency_flag to follow the syntax element dimension_id
-#define VPS_PROFILE_OUTPUT_LAYERS        1      ///< JCTVC-M0268: Signal profile information and output layer information as in Sec. 3 of M0268v2
-#define SPS_SUB_LAYER_INFO               1      ///< JCTVC-M0268: Do not signal sps_max_sub_layers_minus1 and sps_temporal_id_nesting_flag for nuh_layer_id greater than 0
-#define VPS_SPLIT_FLAG                   1      ///< JCTVC-M0163: Do not signal dimension_id and the last dimension_id_len_minus1, when splitting_flag is equal to 1. 
 #define M0457_PREDICTION_INDICATIONS     1
 #define M0040_ADAPTIVE_RESOLUTION_CHANGE 1
@@ -89,6 +89,4 @@
 #define N0160_VUI_EXT_ILP_REF            1      ///< VUI extension inter-layer dependency offset signalling
 #define VPS_VUI_BITRATE_PICRATE          1      ///< JCTVC-N0085: Signal bit rate and picture in VPS VUI
-#else
-#define M0464_TILE_BOUNDARY_ALIGNED_FLAG 0      ///< VUI flag to indicate tile boundary alignment
 #endif //VPS_VUI
 
@@ -96,6 +94,6 @@
 
 #define VPS_EXTN_OFFSET                  1      ///< implementation of vps_extension_offset syntax element
+#define VPS_EXTN_OFFSET_CALC             1      ///< Calculation of VPS extension offset
 #define SPS_PTL_FIX                      1      ///< remove profile_tier_level from enhancement layer SPS
-#define SH_DISCARDABLE_FLAG              1      ///< JCTVC-M0152: Use one reserved flag in the slice header for discardable flag
 
 #define DERIVE_LAYER_ID_LIST_VARIABLES   1      ///< Derived variables based on the variables in VPS - for use in syntax table parsing
@@ -104,6 +102,5 @@
 #define ROUNDING_OFFSET                  1      ///< JCTVC-N0111: upsampling rounding offset using scalling factors
 #define N0214_INTERMEDIATE_BUFFER_16BITS 1      ///< JCTVC-N0214: support base layer input more than 8 bits
-#define ARBITRARY_SPATIAL_RATIO          0      ///< JCTVC-N0219, JCTVC-N0273: Support arbitrary spatial ratio
-#define BUGFIX_RESAMPLE                  1      ///< JCTVC-N0055: resampling bug fix for positive left scalled offset
+#define ARBITRARY_SPATIAL_RATIO          1      ///< JCTVC-N0219, JCTVC-N0273: Support arbitrary spatial ratio
 
 #define JCTVC_M0259_LAMBDAREFINEMENT     1      ///< JCTVC-M0259: lambda refinement (encoder only optimization)
@@ -126,9 +123,8 @@
 #define JCTVC_M0203_INTERLAYER_PRED_IDC  1      ///< JCTVC-M0203: implementation of Inter-layer Prediction Indication
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
-#define ILR_RESTR                        1      ///< JCTVC-M0209: Inter-layer RPS and RPL
-#define ILR_RESTR_FIX                    1      ///< Fix encoder crash when temporal layers are used with scalable coding
 #define EARLY_REF_PIC_MARKING            1      ///< Decoded picture marking of sub-layer non-reference pictures
 #define N0120_MAX_TID_REF_PRESENT_FLAG   1      ///< JCTVC-N0120: max_tid_ref_pics_plus1_present_flag
 #define N0120_MAX_TID_REF_CFG            1      ///< set max_tid_il_ref_pics_plus1 and max_tid_ref_present_flag in the config. file (configuration setting)
+#define O0225_MAX_TID_FOR_REF_LAYERS     1
 #endif
 #if REF_IDX_MFM
@@ -145,4 +141,8 @@
 
 #define N0147_IRAP_ALIGN_FLAG            1      ///< a flag to indicatate whether IRAPs are aligned across layers
+#if N0147_IRAP_ALIGN_FLAG
+#define O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS  1  ///< Remove IRAP align depedency constraints on poc_Reset_flag.
+#define IRAP_ALIGN_FLAG_IN_VPS_VUI       1       ///< Move IRAP align flag to VPS VUI 
+#endif 
 #if !N0147_IRAP_ALIGN_FLAG
 #define IDR_ALIGNMENT                    1      ///< align IDR picures across layers : As per JCTVC-N0373, IDR are not required to be aligned.
@@ -159,4 +159,11 @@
 #define N0383_IL_CONSTRAINED_TILE_SETS_SEI  1
 #define N0065_LAYER_POC_ALIGNMENT        1
+
+#define O0215_PHASE_ALIGNMENT            1      ///< JCTVC_O0215: signal a flag to specify phase alignment case, 0: zero-position-aligned, 1: central-position-aligned,
+#define AUXILIARY_PICTURES               1      ///< JCTVC-O0041: auxiliary picture layers
+
+#define O0062_POC_LSB_NOT_PRESENT_FLAG   1      ///< JCTVC-O0062: signal poc_lsb_not_present_flag for each layer in VPS extension
+#define SHM_FIX7                         1      ///< fix for SHVC WD ticket #7
+
 #else
 #define SYNTAX_OUTPUT                    0
@@ -469,4 +476,7 @@
   CHROMA_422  = 2,
   CHROMA_444  = 3
+#if AUXILIARY_PICTURES
+  ,NUM_CHROMA_FORMAT = 4
+#endif
 };
 
